OpenXRVkDevice.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, 0);
  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::RPI::FovData GetViewFov(AZ::u32 viewIndex) const override;
  29. //! Get the Pose data of the view specified by view index
  30. AZ::RPI::PoseData GetViewPose(AZ::u32 viewIndex) 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. //! Reserve space for appropriate number of views
  37. void InitXrViews(uint32_t numViews);
  38. //! Get the anticipated display XrTime for the next application-generated frame.
  39. XrTime GetPredictedDisplayTime() const;
  40. private:
  41. //////////////////////////////////////////////////////////////////////////
  42. // XR::Device overrides
  43. //! Clean native objects.
  44. void ShutdownInternal() override;
  45. //! Inform the drivers that the frame is beginning
  46. bool BeginFrameInternal() override;
  47. //! Release the oldest swapchain image and inform the drivers that the frame is ending
  48. void EndFrameInternal(XR::Ptr<XR::SwapChain>) override;
  49. //! Locate views, acquire swapchain image and synchronize gpu with cpu
  50. bool AcquireSwapChainImageInternal(AZ::u32 viewIndex, XR::SwapChain* baseSwapChain) override;
  51. //////////////////////////////////////////////////////////////////////////
  52. VkDevice m_xrVkDevice = VK_NULL_HANDLE;
  53. XrFrameState m_frameState{ XR_TYPE_FRAME_STATE };
  54. AZStd::vector<XrCompositionLayerBaseHeader*> m_xrLayers;
  55. XrCompositionLayerProjection m_xrLayer{ XR_TYPE_COMPOSITION_LAYER_PROJECTION };
  56. AZStd::vector<XrCompositionLayerProjectionView> m_projectionLayerViews;
  57. AZStd::vector<XrView> m_views;
  58. uint32_t m_viewCountOutput = 0;
  59. };
  60. }