|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
#include <Headset.h>
Classes | |
| struct | Eye |
| struct | ImageBuffer |
| struct | WaitFrameResult |
| Result from waitForXrFrame indicating what the main loop should do. More... | |
Public Types | |
| enum class | BeginFrameResult { Error , RenderFully , SkipRender , SkipFully , ComputeOnly } |
Public Member Functions | |
| Headset (const ApplicationContext *context=nullptr) | |
| ~Headset () | |
| void | cleanup () |
| void | updateViewMatrix () |
| Updates the eye matrix for the headset. | |
| WaitFrameResult | waitForXrFrame (Renderer *renderer) |
| First part of frame setup: calls xrWaitFrame. Can be called before previous xrEndFrame completes. Polls events and waits for the next frame to be ready. | |
| BeginFrameResult | beginXrFrameAfterWait (uint32_t &swapchainImageIndex) |
| Second part of frame setup: calls xrBeginFrame, acquires swapchain image. MUST be called after previous frame's xrEndFrame has completed. | |
| BeginFrameResult | beginXrFrame (uint32_t &swapchainImageIndex, Renderer *renderer) |
| Legacy function that combines waitForXrFrame and beginXrFrameAfterWait. Kept for compatibility but prefer using the split functions for better pipelining. | |
| void | endXrFrame () |
| void | endXrFrameNoRender () |
| void | beginXrSession () const |
| VkImage | getSwapchainImage (size_t swapchainImageIndex) const |
| Gets the swapchain image for the given index. | |
| std::vector< RenderTarget > | getSwapchainRenderTargets () |
| void | endXrSession () const |
| ends the xr session and thus terminating the xr window on the headset | |
| void | requestExitSession () |
| Requests the XR runtime to exit the session gracefully. This should be called when the application wants to shut down (e.g., window close). The XR runtime will transition through proper states before exiting. | |
| uint32_t | getEyeCount () const |
| Gets eye count. | |
| VkExtent2D | getEyeResolution (size_t eyeIndex) const |
| Gets eye resolution in x and y for a specified eye index. 0 is left. | |
| VkRenderPass | getRenderPass () const |
| Gets render pass. | |
| glm::mat4 | getEyeViewMatrix (size_t eyeIndex) const |
| Returns the view matrix of the specified eye. | |
| void | setPlayerPosition (const glm::vec3 &position) |
| Sets the player world position offset. This offset is applied to all view matrices. | |
| glm::vec3 | getPlayerPosition () const |
| Gets the current player world position. | |
| glm::mat4 | getEyeProjectionMatrix (size_t eyeIndex) const |
| Gets the projection matrix for an eye. | |
| glm::mat4 | getViewProjectionMatrix (size_t eyeIndex) const |
| Gets you a matrix of the multiplied view and projection matrix. | |
| XrSpace | getReferenceSpace () const |
| Gets reference space for the xr headset. | |
| XrSession | getSession () const |
| Gets the active xr session. | |
| bool | getIsExitRequested () const |
| Gets whether the headset has requested for the application to stop. | |
| XrFrameState | getXrFrameState () const |
| gets the current state of the frame | |
| const RenderTarget * | getRenderTarget (size_t swapchainImageIndex) const |
| VkSampler | getHiZSampler () const |
| VkImage | getDepthBufferImage () const |
| VkImageView | getDepthBufferView () const |
| VkImage | getColorBufferImage () const |
| VkImageView | getColorBufferView () const |
Private Member Functions | |
| void | createHiZSampler (VkDevice device) |
Private Attributes | |
| XrViewState | xrViewState = {} |
| XrFrameState | xrFrameState = {} |
| XrSessionState | xrSessionState = XR_SESSION_STATE_UNKNOWN |
| bool | isExistRequested = false |
| const ApplicationContext * | context = nullptr |
| VkRenderPass | vkRenderPass = VK_NULL_HANDLE |
| The vulkan render pass. | |
| XrSession | xrSession = XR_NULL_HANDLE |
| The xr session. | |
| XrSpace | xrReferenceSpace = XR_NULL_HANDLE |
| The xr reference space. | |
| XrReferenceSpaceType | xrReferenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL |
| Type of the xr reference space, if it is room scale or just sitting vr. | |
| uint32_t | eyeCount = 0u |
| std::vector< XrViewConfigurationView > | eyeImageInfos |
| std::vector< XrView > | eyePoses |
| ImageBuffer | colorBuffer |
| ImageBuffer | depthBuffer |
| VkSampler | hiZSampler_ = VK_NULL_HANDLE |
| XrSwapchain | xrSwapchain = nullptr |
| std::unique_ptr< NamedThreadPool > | xrWaitThreadPool_ |
| std::vector< RenderTarget > | swapchainRenderTargets |
| The swapchain render targets. The images get rendered onto those render targets. | |
| std::vector< XrCompositionLayerProjectionView > | eyeRenderInfos |
| std::vector< Eye > | eyes = {} |
| XrTime | lastUpdateTime = 0 |
| glm::vec3 | playerPosition_ {0.0f, 0.0f, 0.0f} |
|
strong |
| EngineCore::Headset::Headset | ( | const ApplicationContext * | context = nullptr | ) |
create xr session
create xr play space
get number of eyes
allocate eye poses
verify that color format is supported
create the color buffer
create the swapchain
bind swapchain images to multiview
create the eye render targets
Create Hi-Z sampler for occlusion culling (pyramids are now per-frame in RenderProcess)
Definition at line 28 of file Headset.cpp.
References VulkanHelper::beginSingleTimeCommands(), colorBuffer, context, createHiZSampler(), depthBuffer, VulkanHelper::endSingleTimeCommands(), eyeCount, eyeImageInfos, eyePoses, eyeRenderInfos, eyes, VulkanHelper::findSuitableMemoryType(), EngineCore::RenderTarget::framebuffer, getEyeResolution(), EngineCore::RenderTarget::image, EngineCore::RenderTarget::imageView, EngineCore::OpenXrHelper::makeIdentityPose(), VulkanHelper::setObjectName(), swapchainRenderTargets, TRACY_ZONE_SCOPED_FUNCTION, VulkanHelper::transitionImageLayout(), vkRenderPass, xrReferenceSpace, xrSession, xrSwapchain, EngineCore::xrViewType, and xrWaitThreadPool_.
| EngineCore::Headset::~Headset | ( | ) |
Definition at line 521 of file Headset.cpp.
| Headset::BeginFrameResult EngineCore::Headset::beginXrFrame | ( | uint32_t & | swapchainImageIndex, |
| Renderer * | renderer ) |
Legacy function that combines waitForXrFrame and beginXrFrameAfterWait. Kept for compatibility but prefer using the split functions for better pipelining.
Definition at line 853 of file Headset.cpp.
References beginXrFrameAfterWait(), and waitForXrFrame().
| Headset::BeginFrameResult EngineCore::Headset::beginXrFrameAfterWait | ( | uint32_t & | swapchainImageIndex | ) |
Second part of frame setup: calls xrBeginFrame, acquires swapchain image. MUST be called after previous frame's xrEndFrame has completed.
| swapchainImageIndex | Output parameter for the acquired swapchain image index |
Definition at line 814 of file Headset.cpp.
References context, eyeCount, eyePoses, RenderFully, SkipRender, TRACY_ZONE_SCOPED_FUNCTION, updateViewMatrix(), xrFrameState, xrReferenceSpace, xrSession, xrSwapchain, and xrViewState.
Referenced by beginXrFrame().
| void EngineCore::Headset::beginXrSession | ( | ) | const |
Definition at line 911 of file Headset.cpp.
References context, and xrSession.
Referenced by waitForXrFrame().
| void EngineCore::Headset::cleanup | ( | ) |
Definition at line 522 of file Headset.cpp.
References colorBuffer, context, depthBuffer, hiZSampler_, swapchainRenderTargets, vkRenderPass, xrReferenceSpace, xrSession, and xrSwapchain.
|
private |
Definition at line 1023 of file Headset.cpp.
References getEyeResolution(), hiZSampler_, and VulkanHelper::setObjectName().
Referenced by Headset().
| void EngineCore::Headset::endXrFrame | ( | ) |
Definition at line 866 of file Headset.cpp.
References eyeRenderInfos, TRACY_ZONE_SCOPED_NAMED, xrFrameState, xrReferenceSpace, xrSession, xrSwapchain, and xrViewState.
| void EngineCore::Headset::endXrFrameNoRender | ( | ) |
Definition at line 899 of file Headset.cpp.
References xrFrameState, and xrSession.
| void EngineCore::Headset::endXrSession | ( | ) | const |
ends the xr session and thus terminating the xr window on the headset
Definition at line 926 of file Headset.cpp.
References xrSession.
Referenced by waitForXrFrame().
|
inlinenodiscard |
Definition at line 330 of file Headset.h.
References colorBuffer.
|
inlinenodiscard |
Definition at line 331 of file Headset.h.
References colorBuffer.
|
inlinenodiscard |
Definition at line 328 of file Headset.h.
References depthBuffer.
|
inlinenodiscard |
Definition at line 329 of file Headset.h.
References depthBuffer.
|
nodiscard |
Gets eye count.
Definition at line 948 of file Headset.cpp.
References eyeCount.
Referenced by EngineCore::RenderProcess::updateEyeViewProjectionMatrices(), and EngineCore::RenderProcess::updateFrustumUBOData().
|
nodiscard |
Gets the projection matrix for an eye.
| eyeIndex | left or right eye (0, 1) |
Definition at line 989 of file Headset.cpp.
References eyes.
Referenced by getViewProjectionMatrix(), and EngineCore::RenderProcess::updateEyeViewProjectionMatrices().
|
nodiscard |
Gets eye resolution in x and y for a specified eye index. 0 is left.
| eyeIndex | Zero-based index of the eye. |
Definition at line 953 of file Headset.cpp.
References eyeImageInfos.
Referenced by createHiZSampler(), Headset(), and EngineCore::RenderProcess::updateHiZViewProjectionData().
|
nodiscard |
Returns the view matrix of the specified eye.
| eyeIndex | left and right eye |
Definition at line 981 of file Headset.cpp.
References eyes, and playerPosition_.
Referenced by getViewProjectionMatrix().
|
inlinenodiscard |
Definition at line 327 of file Headset.h.
References hiZSampler_.
Referenced by EngineCore::RenderProcess::updateComputeObjectCullingDescriptorSets().
|
nodiscard |
Gets whether the headset has requested for the application to stop.
Definition at line 1009 of file Headset.cpp.
References isExistRequested.
|
inlinenodiscard |
Gets the current player world position.
Definition at line 180 of file Headset.h.
References playerPosition_.
|
nodiscard |
Gets reference space for the xr headset.
Definition at line 999 of file Headset.cpp.
References xrReferenceSpace.
|
nodiscard |
Gets render pass.
Definition at line 959 of file Headset.cpp.
References vkRenderPass.
| const RenderTarget * EngineCore::Headset::getRenderTarget | ( | size_t | swapchainImageIndex | ) | const |
Definition at line 1018 of file Headset.cpp.
References swapchainRenderTargets.
|
nodiscard |
Gets the active xr session.
Definition at line 1004 of file Headset.cpp.
References xrSession.
|
nodiscard |
Gets the swapchain image for the given index.
| swapchainImageIndex | Index of the swapchain image |
Definition at line 918 of file Headset.cpp.
References swapchainRenderTargets.
| std::vector< RenderTarget > EngineCore::Headset::getSwapchainRenderTargets | ( | ) |
Definition at line 922 of file Headset.cpp.
References swapchainRenderTargets.
|
nodiscard |
Gets you a matrix of the multiplied view and projection matrix.
| eyeIndex | The frame index |
Definition at line 994 of file Headset.cpp.
References getEyeProjectionMatrix(), and getEyeViewMatrix().
Referenced by EngineCore::RenderProcess::updateEyeViewProjectionMatrices().
|
nodiscard |
gets the current state of the frame
Definition at line 1013 of file Headset.cpp.
References xrFrameState.
| void EngineCore::Headset::requestExitSession | ( | ) |
Requests the XR runtime to exit the session gracefully. This should be called when the application wants to shut down (e.g., window close). The XR runtime will transition through proper states before exiting.
Definition at line 931 of file Headset.cpp.
References isExistRequested, and xrSession.
|
inline |
Sets the player world position offset. This offset is applied to all view matrices.
| position | The player's world position |
Definition at line 174 of file Headset.h.
References playerPosition_.
| void EngineCore::Headset::updateViewMatrix | ( | ) |
Updates the eye matrix for the headset.
Definition at line 587 of file Headset.cpp.
References EngineCore::OpenXrHelper::createProjectionMatrix(), eyeCount, eyePoses, eyeRenderInfos, eyes, EngineCore::OpenXrHelper::poseToMatrix(), and TRACY_ZONE_SCOPED_NAMED.
Referenced by beginXrFrameAfterWait().
| Headset::WaitFrameResult EngineCore::Headset::waitForXrFrame | ( | Renderer * | renderer | ) |
First part of frame setup: calls xrWaitFrame. Can be called before previous xrEndFrame completes. Polls events and waits for the next frame to be ready.
| renderer | Pointer to renderer (used for Tracy context reset on state transitions) |
Definition at line 604 of file Headset.cpp.
References beginXrSession(), context, endXrSession(), Error, EngineCore::OpenXrHelper::GetXrStructureTypeName(), isExistRequested, RenderFully, EngineCore::Headset::WaitFrameResult::result, EngineCore::OpenXrHelper::sessionStateToString(), EngineCore::Headset::WaitFrameResult::shouldCallBeginFrame, SkipFully, SkipRender, TRACY_ZONE_SCOPED_FUNCTION, TRACY_ZONE_SCOPED_NAMED, xrFrameState, xrSession, xrSessionState, and xrWaitThreadPool_.
Referenced by beginXrFrame().
|
private |
Definition at line 290 of file Headset.h.
Referenced by cleanup(), getColorBufferImage(), getColorBufferView(), and Headset().
|
private |
Definition at line 254 of file Headset.h.
Referenced by beginXrFrameAfterWait(), beginXrSession(), cleanup(), EngineCore::Headset::ImageBuffer::cleanup(), EngineCore::RenderTarget::cleanup(), Headset(), and waitForXrFrame().
|
private |
Definition at line 291 of file Headset.h.
Referenced by cleanup(), getDepthBufferImage(), getDepthBufferView(), and Headset().
|
private |
Definition at line 275 of file Headset.h.
Referenced by beginXrFrameAfterWait(), getEyeCount(), Headset(), and updateViewMatrix().
|
private |
Definition at line 277 of file Headset.h.
Referenced by getEyeResolution(), and Headset().
|
private |
Definition at line 279 of file Headset.h.
Referenced by beginXrFrameAfterWait(), Headset(), and updateViewMatrix().
|
private |
Definition at line 310 of file Headset.h.
Referenced by endXrFrame(), Headset(), and updateViewMatrix().
|
private |
Definition at line 316 of file Headset.h.
Referenced by getEyeProjectionMatrix(), getEyeViewMatrix(), Headset(), and updateViewMatrix().
|
private |
Definition at line 295 of file Headset.h.
Referenced by cleanup(), createHiZSampler(), and getHiZSampler().
|
private |
Definition at line 252 of file Headset.h.
Referenced by getIsExitRequested(), requestExitSession(), and waitForXrFrame().
|
private |
Definition at line 321 of file Headset.h.
Referenced by getEyeViewMatrix(), getPlayerPosition(), and setPlayerPosition().
|
private |
The swapchain render targets. The images get rendered onto those render targets.
Definition at line 308 of file Headset.h.
Referenced by cleanup(), getRenderTarget(), getSwapchainImage(), getSwapchainRenderTargets(), and Headset().
|
private |
The vulkan render pass.
Definition at line 259 of file Headset.h.
Referenced by cleanup(), getRenderPass(), and Headset().
|
private |
Definition at line 248 of file Headset.h.
Referenced by beginXrFrameAfterWait(), endXrFrame(), endXrFrameNoRender(), getXrFrameState(), and waitForXrFrame().
|
private |
The xr reference space.
Definition at line 269 of file Headset.h.
Referenced by beginXrFrameAfterWait(), cleanup(), endXrFrame(), getReferenceSpace(), and Headset().
|
private |
|
private |
The xr session.
Definition at line 264 of file Headset.h.
Referenced by beginXrFrameAfterWait(), beginXrSession(), cleanup(), endXrFrame(), endXrFrameNoRender(), endXrSession(), getSession(), Headset(), requestExitSession(), and waitForXrFrame().
|
private |
Definition at line 250 of file Headset.h.
Referenced by waitForXrFrame().
|
private |
Definition at line 299 of file Headset.h.
Referenced by beginXrFrameAfterWait(), cleanup(), endXrFrame(), and Headset().
|
private |
Definition at line 247 of file Headset.h.
Referenced by beginXrFrameAfterWait(), and endXrFrame().
|
private |
Definition at line 302 of file Headset.h.
Referenced by Headset(), and waitForXrFrame().