Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
EngineCore::Headset Class Reference

#include <Headset.h>

Collaboration diagram for EngineCore::Headset:

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< RenderTargetgetSwapchainRenderTargets ()
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 RenderTargetgetRenderTarget (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 ApplicationContextcontext = 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< NamedThreadPoolxrWaitThreadPool_
std::vector< RenderTargetswapchainRenderTargets
 The swapchain render targets. The images get rendered onto those render targets.
std::vector< XrCompositionLayerProjectionView > eyeRenderInfos
std::vector< Eyeeyes = {}
XrTime lastUpdateTime = 0
glm::vec3 playerPosition_ {0.0f, 0.0f, 0.0f}

Detailed Description

Definition at line 37 of file Headset.h.

Member Enumeration Documentation

◆ BeginFrameResult

Enumerator
Error 
RenderFully 
SkipRender 
SkipFully 
ComputeOnly 

Definition at line 45 of file Headset.h.

Constructor & Destructor Documentation

◆ Headset()

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_.

Here is the call graph for this function:

◆ ~Headset()

EngineCore::Headset::~Headset ( )

Definition at line 521 of file Headset.cpp.

Member Function Documentation

◆ beginXrFrame()

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().

Here is the call graph for this function:

◆ beginXrFrameAfterWait()

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.

Parameters
swapchainImageIndexOutput parameter for the acquired swapchain image index
Returns
BeginFrameResult indicating rendering status

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginXrSession()

void EngineCore::Headset::beginXrSession ( ) const

Definition at line 911 of file Headset.cpp.

References context, and xrSession.

Referenced by waitForXrFrame().

Here is the caller graph for this function:

◆ cleanup()

void EngineCore::Headset::cleanup ( )

◆ createHiZSampler()

void EngineCore::Headset::createHiZSampler ( VkDevice device)
private

Definition at line 1023 of file Headset.cpp.

References getEyeResolution(), hiZSampler_, and VulkanHelper::setObjectName().

Referenced by Headset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endXrFrame()

void EngineCore::Headset::endXrFrame ( )

◆ endXrFrameNoRender()

void EngineCore::Headset::endXrFrameNoRender ( )

Definition at line 899 of file Headset.cpp.

References xrFrameState, and xrSession.

◆ endXrSession()

void EngineCore::Headset::endXrSession ( ) const

ends the xr session and thus terminating the xr window on the headset

Date
2025-03-14
Author
Konstantin Passig

Definition at line 926 of file Headset.cpp.

References xrSession.

Referenced by waitForXrFrame().

Here is the caller graph for this function:

◆ getColorBufferImage()

VkImage EngineCore::Headset::getColorBufferImage ( ) const
inlinenodiscard

Definition at line 330 of file Headset.h.

References colorBuffer.

◆ getColorBufferView()

VkImageView EngineCore::Headset::getColorBufferView ( ) const
inlinenodiscard

Definition at line 331 of file Headset.h.

References colorBuffer.

◆ getDepthBufferImage()

VkImage EngineCore::Headset::getDepthBufferImage ( ) const
inlinenodiscard

Definition at line 328 of file Headset.h.

References depthBuffer.

◆ getDepthBufferView()

VkImageView EngineCore::Headset::getDepthBufferView ( ) const
inlinenodiscard

Definition at line 329 of file Headset.h.

References depthBuffer.

◆ getEyeCount()

uint32_t EngineCore::Headset::getEyeCount ( ) const
nodiscard

Gets eye count.

Returns
The eye count.
Date
2025-02-16
Author
Konstantin Passig

Definition at line 948 of file Headset.cpp.

References eyeCount.

Referenced by EngineCore::RenderProcess::updateEyeViewProjectionMatrices(), and EngineCore::RenderProcess::updateFrustumUBOData().

Here is the caller graph for this function:

◆ getEyeProjectionMatrix()

glm::mat4 EngineCore::Headset::getEyeProjectionMatrix ( size_t eyeIndex) const
nodiscard

Gets the projection matrix for an eye.

Parameters
eyeIndexleft or right eye (0, 1)
Returns
the view matrix
Date
2025-03-14
Author
Konstantin Passig

Definition at line 989 of file Headset.cpp.

References eyes.

Referenced by getViewProjectionMatrix(), and EngineCore::RenderProcess::updateEyeViewProjectionMatrices().

Here is the caller graph for this function:

◆ getEyeResolution()

VkExtent2D EngineCore::Headset::getEyeResolution ( size_t eyeIndex) const
nodiscard

Gets eye resolution in x and y for a specified eye index. 0 is left.

Parameters
eyeIndexZero-based index of the eye.
Returns
The eye resolution.
Date
2025-02-16
Author
Konstantin Passig

Definition at line 953 of file Headset.cpp.

References eyeImageInfos.

Referenced by createHiZSampler(), Headset(), and EngineCore::RenderProcess::updateHiZViewProjectionData().

Here is the caller graph for this function:

◆ getEyeViewMatrix()

glm::mat4 EngineCore::Headset::getEyeViewMatrix ( size_t eyeIndex) const
nodiscard

Returns the view matrix of the specified eye.

Parameters
eyeIndexleft and right eye
Returns
the view matrix of the specified eye
Date
2025-03-14
Author
2002e

Definition at line 981 of file Headset.cpp.

References eyes, and playerPosition_.

Referenced by getViewProjectionMatrix().

Here is the caller graph for this function:

◆ getHiZSampler()

VkSampler EngineCore::Headset::getHiZSampler ( ) const
inlinenodiscard

Definition at line 327 of file Headset.h.

References hiZSampler_.

Referenced by EngineCore::RenderProcess::updateComputeObjectCullingDescriptorSets().

Here is the caller graph for this function:

◆ getIsExitRequested()

bool EngineCore::Headset::getIsExitRequested ( ) const
nodiscard

Gets whether the headset has requested for the application to stop.

Returns
if the exit of the application has been requested by open xr
Date
2025-02-23
Author
Konstantin Passig

Definition at line 1009 of file Headset.cpp.

References isExistRequested.

◆ getPlayerPosition()

glm::vec3 EngineCore::Headset::getPlayerPosition ( ) const
inlinenodiscard

Gets the current player world position.

Returns
The player's world position

Definition at line 180 of file Headset.h.

References playerPosition_.

◆ getReferenceSpace()

XrSpace EngineCore::Headset::getReferenceSpace ( ) const
nodiscard

Gets reference space for the xr headset.

Returns
The reference space.
Date
2025-02-23
Author
Konstantin Passig

Definition at line 999 of file Headset.cpp.

References xrReferenceSpace.

◆ getRenderPass()

VkRenderPass EngineCore::Headset::getRenderPass ( ) const
nodiscard

Gets render pass.

Returns
The render pass.
Date
2025-02-15
Author
Konstantin Passig

Definition at line 959 of file Headset.cpp.

References vkRenderPass.

◆ getRenderTarget()

const RenderTarget * EngineCore::Headset::getRenderTarget ( size_t swapchainImageIndex) const

Definition at line 1018 of file Headset.cpp.

References swapchainRenderTargets.

◆ getSession()

XrSession EngineCore::Headset::getSession ( ) const
nodiscard

Gets the active xr session.

Returns
The xr session.
Date
2025-02-23
Author
Konstantin Passig

Definition at line 1004 of file Headset.cpp.

References xrSession.

◆ getSwapchainImage()

VkImage EngineCore::Headset::getSwapchainImage ( size_t swapchainImageIndex) const
nodiscard

Gets the swapchain image for the given index.

Parameters
swapchainImageIndexIndex of the swapchain image
Returns
The VkImage handle

Definition at line 918 of file Headset.cpp.

References swapchainRenderTargets.

◆ getSwapchainRenderTargets()

std::vector< RenderTarget > EngineCore::Headset::getSwapchainRenderTargets ( )

Definition at line 922 of file Headset.cpp.

References swapchainRenderTargets.

◆ getViewProjectionMatrix()

glm::mat4 EngineCore::Headset::getViewProjectionMatrix ( size_t eyeIndex) const
nodiscard

Gets you a matrix of the multiplied view and projection matrix.

Parameters
eyeIndexThe frame index
Returns
a matrix with the multiplied view and projection matrix
Date
2025-06-17
Author
Konstantin Passig

Definition at line 994 of file Headset.cpp.

References getEyeProjectionMatrix(), and getEyeViewMatrix().

Referenced by EngineCore::RenderProcess::updateEyeViewProjectionMatrices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getXrFrameState()

XrFrameState EngineCore::Headset::getXrFrameState ( ) const
nodiscard

gets the current state of the frame

Returns
the frame state
Date
2025-02-23
Author
Konstantin Passig

Definition at line 1013 of file Headset.cpp.

References xrFrameState.

◆ requestExitSession()

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.

◆ setPlayerPosition()

void EngineCore::Headset::setPlayerPosition ( const glm::vec3 & position)
inline

Sets the player world position offset. This offset is applied to all view matrices.

Parameters
positionThe player's world position

Definition at line 174 of file Headset.h.

References playerPosition_.

◆ updateViewMatrix()

void EngineCore::Headset::updateViewMatrix ( )

Updates the eye matrix for the headset.

Date
2025-06-17
Author
Konstantin Passig

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitForXrFrame()

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.

Parameters
rendererPointer to renderer (used for Tracy context reset on state transitions)
Returns
WaitFrameResult indicating what to do next

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ colorBuffer

ImageBuffer EngineCore::Headset::colorBuffer
private

Definition at line 290 of file Headset.h.

Referenced by cleanup(), getColorBufferImage(), getColorBufferView(), and Headset().

◆ context

◆ depthBuffer

ImageBuffer EngineCore::Headset::depthBuffer
private

Definition at line 291 of file Headset.h.

Referenced by cleanup(), getDepthBufferImage(), getDepthBufferView(), and Headset().

◆ eyeCount

uint32_t EngineCore::Headset::eyeCount = 0u
private

Definition at line 275 of file Headset.h.

Referenced by beginXrFrameAfterWait(), getEyeCount(), Headset(), and updateViewMatrix().

◆ eyeImageInfos

std::vector<XrViewConfigurationView> EngineCore::Headset::eyeImageInfos
private

Definition at line 277 of file Headset.h.

Referenced by getEyeResolution(), and Headset().

◆ eyePoses

std::vector<XrView> EngineCore::Headset::eyePoses
private

Definition at line 279 of file Headset.h.

Referenced by beginXrFrameAfterWait(), Headset(), and updateViewMatrix().

◆ eyeRenderInfos

std::vector<XrCompositionLayerProjectionView> EngineCore::Headset::eyeRenderInfos
private

Definition at line 310 of file Headset.h.

Referenced by endXrFrame(), Headset(), and updateViewMatrix().

◆ eyes

std::vector<Eye> EngineCore::Headset::eyes = {}
private

Definition at line 316 of file Headset.h.

Referenced by getEyeProjectionMatrix(), getEyeViewMatrix(), Headset(), and updateViewMatrix().

◆ hiZSampler_

VkSampler EngineCore::Headset::hiZSampler_ = VK_NULL_HANDLE
private

Definition at line 295 of file Headset.h.

Referenced by cleanup(), createHiZSampler(), and getHiZSampler().

◆ isExistRequested

bool EngineCore::Headset::isExistRequested = false
private

Definition at line 252 of file Headset.h.

Referenced by getIsExitRequested(), requestExitSession(), and waitForXrFrame().

◆ lastUpdateTime

XrTime EngineCore::Headset::lastUpdateTime = 0
private

Definition at line 318 of file Headset.h.

◆ playerPosition_

glm::vec3 EngineCore::Headset::playerPosition_ {0.0f, 0.0f, 0.0f}
private

Definition at line 321 of file Headset.h.

Referenced by getEyeViewMatrix(), getPlayerPosition(), and setPlayerPosition().

◆ swapchainRenderTargets

std::vector<RenderTarget> EngineCore::Headset::swapchainRenderTargets
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().

◆ vkRenderPass

VkRenderPass EngineCore::Headset::vkRenderPass = VK_NULL_HANDLE
private

The vulkan render pass.

Definition at line 259 of file Headset.h.

Referenced by cleanup(), getRenderPass(), and Headset().

◆ xrFrameState

XrFrameState EngineCore::Headset::xrFrameState = {}
private

◆ xrReferenceSpace

XrSpace EngineCore::Headset::xrReferenceSpace = XR_NULL_HANDLE
private

The xr reference space.

Definition at line 269 of file Headset.h.

Referenced by beginXrFrameAfterWait(), cleanup(), endXrFrame(), getReferenceSpace(), and Headset().

◆ xrReferenceSpaceType

XrReferenceSpaceType EngineCore::Headset::xrReferenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL
private

Type of the xr reference space, if it is room scale or just sitting vr.

Definition at line 273 of file Headset.h.

◆ xrSession

XrSession EngineCore::Headset::xrSession = XR_NULL_HANDLE
private

◆ xrSessionState

XrSessionState EngineCore::Headset::xrSessionState = XR_SESSION_STATE_UNKNOWN
private

Definition at line 250 of file Headset.h.

Referenced by waitForXrFrame().

◆ xrSwapchain

XrSwapchain EngineCore::Headset::xrSwapchain = nullptr
private

Definition at line 299 of file Headset.h.

Referenced by beginXrFrameAfterWait(), cleanup(), endXrFrame(), and Headset().

◆ xrViewState

XrViewState EngineCore::Headset::xrViewState = {}
private

Definition at line 247 of file Headset.h.

Referenced by beginXrFrameAfterWait(), and endXrFrame().

◆ xrWaitThreadPool_

std::unique_ptr<NamedThreadPool> EngineCore::Headset::xrWaitThreadPool_
private

Definition at line 302 of file Headset.h.

Referenced by Headset(), and waitForXrFrame().


The documentation for this class was generated from the following files:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Renderer/Headset.h
  • /home/magerbeton/Documents/gl3-vulkan/Engine/src/Engine/Renderer/Headset.cpp