OpenXRVkDevice.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/XRDevice.h>
  10. #include <XR/XRSwapChain.h>
  11. #include <OpenXRVk_Platform.h>
  12. namespace OpenXRVk
  13. {
  14. //! Vulkan specific XR device back-end class that will help manage
  15. //! xr specific vulkan native objects related to device.
  16. class Device final
  17. : public XR::Device
  18. {
  19. public:
  20. AZ_CLASS_ALLOCATOR(Device, AZ::SystemAllocator);
  21. AZ_RTTI(Device, "{81FD9B99-EDA5-4381-90EC-335073554379}", XR::Device);
  22. static XR::Ptr<Device> Create();
  23. //////////////////////////////////////////////////////////////////////////
  24. // XR::Device overrides
  25. // Create the xr specific native device object and populate the XRDeviceDescriptor with it.
  26. AZ::RHI::ResultCode InitDeviceInternal(AZ::RHI::XRDeviceDescriptor* instanceDescriptor) override;
  27. //! Get the Fov data of the view specified by view index
  28. AZ::RHI::ResultCode GetViewFov(AZ::u32 viewIndex, AZ::RPI::FovData& outFovData) const override;
  29. //! Get the Pose data of the view specified by view index
  30. AZ::RHI::ResultCode GetViewPose(AZ::u32 viewIndex, AZ::RPI::PoseData& outPoseData) const override;
  31. //////////////////////////////////////////////////////////////////////////
  32. //! Returns true if rendering data is valid for the current frame.
  33. bool ShouldRender() const;
  34. //! Get the native device
  35. VkDevice GetNativeDevice() const;
  36. //! Get glad vulkan context.
  37. const GladVulkanContext& GetContext() const;
  38. //! Reserve space for appropriate number of views
  39. void InitXrViews(uint32_t numViews);
  40. //! Get the anticipated display XrTime for the next application-generated frame.
  41. XrTime GetPredictedDisplayTime() const;
  42. private:
  43. //////////////////////////////////////////////////////////////////////////
  44. // XR::Device overrides
  45. //! Clean native objects.
  46. void ShutdownInternal() override;
  47. //! Inform the drivers that the frame is beginning
  48. bool BeginFrameInternal() override;
  49. //! Release the oldest swapchain image and inform the drivers that the frame is ending
  50. void EndFrameInternal(XR::Ptr<XR::SwapChain>) override;
  51. //! Called after EndFrame has been executed.
  52. void PostFrameInternal() override;
  53. //! Locate views, acquire swapchain image and synchronize gpu with cpu
  54. bool AcquireSwapChainImageInternal(AZ::u32 viewIndex, XR::SwapChain* baseSwapChain) override;
  55. //////////////////////////////////////////////////////////////////////////
  56. VkDevice m_xrVkDevice = VK_NULL_HANDLE;
  57. XrFrameState m_frameState{ XR_TYPE_FRAME_STATE };
  58. AZStd::vector<XrCompositionLayerBaseHeader*> m_xrLayers;
  59. XrCompositionLayerProjection m_xrLayer{ XR_TYPE_COMPOSITION_LAYER_PROJECTION };
  60. AZStd::vector<XrCompositionLayerProjectionView> m_projectionLayerViews;
  61. AZStd::vector<XrView> m_views;
  62. uint32_t m_viewCountOutput = 0;
  63. GladVulkanContext m_context = {};
  64. };
  65. }