OpenXRVkSwapChain.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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, 0);
  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, 0);
  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, 0);
  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. //! Assign the correct native Swapchain image based on the swapchain index and swapchain image index
  57. AZ::RHI::ResultCode GetSwapChainImage(AZ::RHI::XRSwapChainDescriptor* swapchainDescriptor) const override;
  58. //! Return the recommended swapchain width
  59. AZ::u32 GetSwapChainWidth(AZ::u32 viewIndex) const override;
  60. //! Return the recommended swapchain height
  61. AZ::u32 GetSwapChainHeight(AZ::u32 viewIndex) const override;
  62. //! Get the view configurations supported by the drivers
  63. AZStd::vector<XrViewConfigurationView> GetViewConfigs() const;
  64. private:
  65. //! Initialize all the native SwapChain and SwapChain images per view.
  66. AZ::RHI::ResultCode InitInternal() override;
  67. //! Destroy native objects
  68. void ShutdownInternal() override;
  69. //! Return supported swapchain image format
  70. AZ::s64 SelectColorSwapChainFormat(const AZStd::vector<int64_t>& runtimeFormats) const;
  71. AZStd::vector<XrViewConfigurationView> m_configViews;
  72. AZ::s64 m_colorSwapChainFormat{ -1 };
  73. AZ::u32 m_mipCount = 1;
  74. AZ::u32 m_faceCount = 1;
  75. AZ::u32 m_arraySize = 1;
  76. //Todo: Add support up higher sample counts in case on MSAA pipeline
  77. VkSampleCountFlagBits m_sampleCount = VK_SAMPLE_COUNT_1_BIT;
  78. };
  79. }