HoviTron Video Pipeline
Public Member Functions
SwapchainOpenXR Class Reference

Class that encapsulate an OpenXR Swapchain and functions associated to it. More...

#include <SwapchainOpenXR.h>

Inheritance diagram for SwapchainOpenXR:
SwapchainAbstract

Public Member Functions

 SwapchainOpenXR (int64_t format, const XrViewConfigurationView &vp, WindowAbstract *window, VulkanWrapper *wrapper, XrSession *session)
 
std::tuple< uint32_t, std::optional< vk::Semaphore > > acquireImage () override
 
void presentImage (uint32_t imageIndex, vk::Semaphore &renderingFinnished) override
 
void presentImage (uint32_t imageIndex, vk::Fence &renderingFinnishedFence) override
 
vk::ImageView getSwapchainImageView (int elem) override
 
vk::Image getSwapchainImage (int index) override
 
void cleanup () override
 
int getAttachmentSize () override
 
vk::Image getCurrentImage () override
 
virtual std::tuple< uint32_t, std::optional< vk::Semaphore > > acquireImage ()=0
 
virtual void presentImage (uint32_t imageIndex, vk::Semaphore &renderingFinnished)=0
 
virtual void presentImage (uint32_t imageIndex, vk::Fence &renderingFinnishedFence)=0
 
virtual void cleanup ()=0
 
virtual vk::ImageView getSwapchainImageView (int elem)=0
 
virtual int getAttachmentSize ()=0
 
virtual vk::Image getSwapchainImage (int index)=0
 
virtual vk::Image getCurrentImage ()=0
 

Additional Inherited Members

- Data Fields inherited from SwapchainAbstract
std::variant< vk::SwapchainKHR > handle
 
vk::Extent2D swapchainExtent
 
vk::Format swapchainFormat
 
- Protected Attributes inherited from SwapchainAbstract
std::vector< vk::ImageView > swapchainImageViews
 
VulkanWrapperwraps = nullptr
 
WindowAbstractwindow = nullptr
 

Detailed Description

Class that encapsulate an OpenXR Swapchain and functions associated to it.

Class that encapsulate an OpenXR swapchain and functions associated to it.

Can be used for color or depth swapchain

Definition at line 35 of file SwapchainOpenXR.h.

Constructor & Destructor Documentation

◆ SwapchainOpenXR()

SwapchainOpenXR::SwapchainOpenXR ( int64_t  format,
const XrViewConfigurationView &  vp,
WindowAbstract window,
VulkanWrapper wrapper,
XrSession *  session 
)

Constructor

Definition at line 39 of file SwapchainOpenXR.cpp.

40{
41 this->wraps = wrapper;
42 this->window = window;
43 switch(format) {
44 case VK_FORMAT_D16_UNORM:
45 case VK_FORMAT_D24_UNORM_S8_UINT:
46 case VK_FORMAT_D32_SFLOAT:
47 isDepth = true;
48 break;
49 default:
50 isDepth = false;
51 }
52
53 createSwapchain(vp,session, format);
54 createSwapchainImageViews();
55}
VulkanWrapper * wraps
WindowAbstract * window

Member Function Documentation

◆ acquireImage()

std::tuple< uint32_t, std::optional< vk::Semaphore > > SwapchainOpenXR::acquireImage ( )
overridevirtual

Acquire the next image that will be the rendering target and optionnaly the semaphore signalling when the image is available

Implements SwapchainAbstract.

Definition at line 57 of file SwapchainOpenXR.cpp.

58{
59 XrSwapchainImageAcquireInfo acquireInfo{ XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO };
60
61 uint32_t swapchainImageIndex;
62 CHECK_XRCMD(xrAcquireSwapchainImage(xrswapchain.handle, &acquireInfo, &swapchainImageIndex));
63
64 XrSwapchainImageWaitInfo waitInfo{ XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO };
65 waitInfo.timeout = XR_INFINITE_DURATION;
66 CHECK_XRCMD(xrWaitSwapchainImage(xrswapchain.handle, &waitInfo));
67
68 currentImage = swapchainImageIndex;
69 std::optional<vk::Semaphore> sem;
70 return std::tuple<uint32_t, std::optional<vk::Semaphore>>(swapchainImageIndex,sem);
71}

◆ cleanup()

void SwapchainOpenXR::cleanup ( )
overridevirtual

Clean up allocated ressources

Implements SwapchainAbstract.

Definition at line 116 of file SwapchainOpenXR.cpp.

117{
118 xrDestroySwapchain(xrswapchain.handle);
119}

◆ getAttachmentSize()

int SwapchainOpenXR::getAttachmentSize ( )
overridevirtual

Return the size of the attachment

Implements SwapchainAbstract.

Definition at line 121 of file SwapchainOpenXR.cpp.

122{
123 assert(swapChainImagesXr.size() == xrSwapchainImagesBase.size());
124 return swapChainImagesXr.size();
125}

◆ getCurrentImage()

vk::Image SwapchainOpenXR::getCurrentImage ( )
overridevirtual

Return the current vk::Image in use

Implements SwapchainAbstract.

Definition at line 127 of file SwapchainOpenXR.cpp.

128{
129 return swapChainImagesXr[currentImage].image;
130}

◆ getSwapchainImage()

vk::Image SwapchainOpenXR::getSwapchainImage ( int  index)
overridevirtual

Return vk::Image corresponding to the requested index

Implements SwapchainAbstract.

Definition at line 103 of file SwapchainOpenXR.cpp.

104{
105 assert(index < swapChainImagesXr.size());
106 assert(index < xrSwapchainImagesBase.size());
107 return swapChainImagesXr[index].image;
108}

◆ getSwapchainImageView()

vk::ImageView SwapchainOpenXR::getSwapchainImageView ( int  elem)
overridevirtual

Used to retrieve the vk::ImageView corresponding to the image used

Implements SwapchainAbstract.

Definition at line 97 of file SwapchainOpenXR.cpp.

98{
99 assert(elem < swapchainImageViews.size());
100 return swapchainImageViews[elem];
101}
std::vector< vk::ImageView > swapchainImageViews

◆ presentImage() [1/2]

void SwapchainOpenXR::presentImage ( uint32_t  imageIndex,
vk::Fence &  renderingFinnishedFence 
)
overridevirtual

Called to signal that rendering work have been submitted to the GPU, and that the Fence have to be used for synchronization

Implements SwapchainAbstract.

Definition at line 78 of file SwapchainOpenXR.cpp.

79{
80 assert(fence != (vk::Fence) VK_NULL_HANDLE);
81
82
83 const uint32_t timeoutNs = 1 * 1000 * 1000 * 1000;
84 for (int i = 0; i < 5; ++i) {
85 auto res = wraps->context.device.waitForFences(1, &fence, VK_TRUE, timeoutNs);
86 if (res == vk::Result::eSuccess) {
87 // Buffer can be executed multiple times...
88 break;
89 }
90 PRINT("%s", "Waiting for CmdBuffer fence timed out, retrying...");
91 }
92
93 XrSwapchainImageReleaseInfo releaseInfo{ XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO };
94 CHECK_XRCMD(xrReleaseSwapchainImage(xrswapchain.handle, &releaseInfo));
95}
vk::Device device
Definition: VulkanContext.h:87
VulkanContext context

◆ presentImage() [2/2]

void SwapchainOpenXR::presentImage ( uint32_t  imageIndex,
vk::Semaphore &  renderingFinnished 
)
overridevirtual

Called to signal that rendering work have been submitted to the GPU, and that the Semaphore have to be used for synchronization

Implements SwapchainAbstract.

Definition at line 73 of file SwapchainOpenXR.cpp.

74{
75 throw std::runtime_error("Synchronization with Semaphore is not supported with openxr swapchains");
76}

The documentation for this class was generated from the following files: