OpenXRVkSwapChain.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <XR/XRSwapChain.h>
  10. #include <OpenXRVk_Platform.h>
  11. namespace OpenXRVk
  12. {
  13. //! Class that will help manage native xr swapchains and swapchain images
  14. class SwapChain final
  15. : public XR::SwapChain
  16. {
  17. public:
  18. AZ_CLASS_ALLOCATOR(SwapChain, AZ::SystemAllocator);
  19. AZ_RTTI(SwapChain, "{3DD88236-8C9F-4864-86F5-018C198BC07E}", XR::SwapChain);
  20. static XR::Ptr<SwapChain> Create();
  21. //! This class helps manage the native swapchain image.
  22. class Image final
  23. : public XR::SwapChain::Image
  24. {
  25. public:
  26. AZ_CLASS_ALLOCATOR(Image, AZ::SystemAllocator);
  27. AZ_RTTI(Image, "{717ABDD4-C050-4FDF-8E93-3784F81FE315}", XR::SwapChain::Image);
  28. static XR::Ptr<Image> Create();
  29. AZ::RHI::ResultCode Init(XrSwapchainImageVulkan2KHR swapchainImage);
  30. VkImage GetNativeImage();
  31. private:
  32. XrSwapchainImageVulkan2KHR m_swapchainImage;
  33. };
  34. //! This class helps manage the native swapchain for a given view.
  35. class View final
  36. : public XR::SwapChain::View
  37. {
  38. public:
  39. AZ_CLASS_ALLOCATOR(View, AZ::SystemAllocator);
  40. AZ_RTTI(View, "{F8312427-AC2D-4737-9A8F-A16ADA5319D0}", XR::SwapChain::View);
  41. static XR::Ptr<View> Create();
  42. AZ::RHI::ResultCode Init(XrSwapchain handle, AZ::u32 width, AZ::u32 height);
  43. XrSwapchain GetSwapChainHandle() const;
  44. //! Destroy native swapchain
  45. void Shutdown() override;
  46. //! swapchain specific accessor functions
  47. AZ::u32 GetWidth() const;
  48. AZ::u32 GetHeight() const;
  49. AZ::u32 GetCurrentImageIndex() const override;
  50. //! Native swapChain image data
  51. AZStd::vector<XrSwapchainImageBaseHeader*> m_swapChainImageHeaders;
  52. AZStd::vector<XrSwapchainImageVulkan2KHR> m_swapchainImages;
  53. private:
  54. XrSwapchain m_handle = XR_NULL_HANDLE;
  55. };
  56. // XR::SwapChain overrides...
  57. AZ::RHI::ResultCode GetSwapChainImage(AZ::RHI::XRSwapChainDescriptor* swapchainDescriptor) const override;
  58. AZ::u32 GetSwapChainWidth(AZ::u32 viewIndex) const override;
  59. AZ::u32 GetSwapChainHeight(AZ::u32 viewIndex) const override;
  60. AZ::RHI::Format GetSwapChainFormat(AZ::u32 viewIndex) const override;
  61. //! Get the view configurations supported by the drivers
  62. AZStd::vector<XrViewConfigurationView> GetViewConfigs() const;
  63. private:
  64. //! Initialize all the native SwapChain and SwapChain images per view.
  65. AZ::RHI::ResultCode InitInternal() override;
  66. //! Destroy native objects
  67. void ShutdownInternal() override;
  68. //! Return supported swapchain image format
  69. VkFormat SelectColorSwapChainFormat(const AZStd::vector<int64_t>& runtimeFormats) const;
  70. AZStd::vector<XrViewConfigurationView> m_configViews;
  71. VkFormat m_colorSwapChainFormat{ VK_FORMAT_UNDEFINED };
  72. AZ::u32 m_mipCount = 1;
  73. AZ::u32 m_faceCount = 1;
  74. AZ::u32 m_arraySize = 1;
  75. //Todo: Add support up higher sample counts in case on MSAA pipeline
  76. VkSampleCountFlagBits m_sampleCount = VK_SAMPLE_COUNT_1_BIT;
  77. };
  78. }