HoviTron Video Pipeline
Public Member Functions
VulkanDrawing Class Reference

The class that manages the drawing operation (manage and record command buffers). More...

#include <VulkanDrawing.h>

Public Member Functions

 VulkanDrawing (VulkanContext *context, VulkanRenderPassAbstract *renderPass, WindowAbstract *window, VulkanWrapper *wraps)
 
void init (InputProvider *inputProvider)
 
void cleanup ()
 
bool isInitialized ()
 
vk::Fence submitDrawCall (std::tuple< int, uint32_t > idImage, const std::vector< vk::Semaphore > &imageAvailableSemaphores, std::vector< vk::Semaphore > &signalSemaphore, uint32_t depthIndex=UINT_MAX)
 

Detailed Description

The class that manages the drawing operation (manage and record command buffers).

The class that manages the drawing operation. It manage, record command buffers and submit command buffer. Command buffer are reset each new frame for each view. It may add some additional operation after a renderpass to copy images if needed.

Definition at line 46 of file VulkanDrawing.h.

Constructor & Destructor Documentation

◆ VulkanDrawing()

VulkanDrawing::VulkanDrawing ( VulkanContext context,
VulkanRenderPassAbstract renderPass,
WindowAbstract window,
VulkanWrapper wraps 
)

COnstructor

Definition at line 34 of file VulkanDrawing.cpp.

35{
36 this->context = context;
37 this->renderPass = renderPass;
38 this->window = window;
39 this->wrapper = wraps;
40
41}

Member Function Documentation

◆ cleanup()

void VulkanDrawing::cleanup ( )

Clean up ressources

Definition at line 60 of file VulkanDrawing.cpp.

60 {
61 for (int view = 0; view < viewNumber; view++) {
62
63 /*if (window->useOpenXR()) {
64 for (size_t i = 0; i < window->getViewNumber(); i++) {
65 //context->device.destroySemaphore(renderFinishedSemaphores[view][i]);
66 context->device.destroyFence(inFlightFences[view][i]);
67 }
68 }
69 else {*/
70 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
71 if (i < wrapper->getAttachmentSize()) {
72 //context->device.destroySemaphore(renderFinishedSemaphores[view][i]);
73 //context->device.destroySemaphore(imageAvailableSemaphores[view][i]);
74 context->device.destroyFence(inFlightFences[view][i]);
75 }
76 }
77 //}
78 }
79 //renderFinishedSemaphores.clear();
80 //execFences.clear();
81 //imageAvailableSemaphores.clear();
82 inFlightFences.clear();
83 imagesInFlight.clear();
84
85
86
87
88 context->device.destroyCommandPool(commandPool); //will automaticly destroy command buffers
89 commandBuffers.clear();
90}
vk::Device device
Definition: VulkanContext.h:87

◆ init()

void VulkanDrawing::init ( InputProvider inputProvider)

Init the needed ressources

Definition at line 43 of file VulkanDrawing.cpp.

44{
45 this->inputProvider = inputProvider;
46 viewNumber = window->getViewNumber(); //get the nb of sawpchain
47 for(int i = 0 ; i < viewNumber; i++){
48 currentFrame.push_back(0);
49 }
50
51 createCommandPool();
52 createCommandBuffers();
53 createSyncObjects();
54 initialized = true;
55
56
57 //streamFrameInfos.resize(inputProvider->enumerateStreamsParameters().size());
58}

◆ isInitialized()

bool VulkanDrawing::isInitialized ( )

Return true if ressources were allocated and need to be cleaned up

Definition at line 473 of file VulkanDrawing.cpp.

473 {
474 return initialized;
475}

◆ submitDrawCall()

vk::Fence VulkanDrawing::submitDrawCall ( std::tuple< int, uint32_t >  idImage,
const std::vector< vk::Semaphore > &  imageAvailableSemaphores,
std::vector< vk::Semaphore > &  signalSemaphore,
uint32_t  depthIndex = UINT_MAX 
)

Function that is called each frame by the window to render a new frame. Synchronization can be done with semaphore or fence

Definition at line 94 of file VulkanDrawing.cpp.

94 {
95
96 int view;
97 uint32_t imageIndex;
98 std::tie(view, imageIndex) = idImage;
99 currentFrame[view] = imageIndex;
100
101 D(if (wrapper->isDepthOutputRecquired()) { assert(imageIndex == depthIndex); })
102
103 context->device.waitForFences(1, &inFlightFences[view][currentFrame[view]], true, UINT64_MAX);
104
105
106
107 auto streamFrameInfos = wrapper->getFramesInfo(view);
108
109 renderPass->updateBuffer(imageIndex, true, streamFrameInfos,view);
110
111 //if (resetCommandBuffer) {
112 commandBuffers[view][imageIndex].reset(vk::CommandBufferResetFlagBits::eReleaseResources);
113 recordCommandBuffers(commandBuffers[view][imageIndex], view, imageIndex, streamFrameInfos);
114 //}
115
116 if (imagesInFlight[view][imageIndex].has_value()) {
117 context->device.waitForFences(1, &imagesInFlight[view][imageIndex].value(), true, UINT64_MAX);
118 }
119
120 imagesInFlight[view][imageIndex] = inFlightFences[view][currentFrame[view]];
121
122
123 vk::PipelineStageFlags waitDestinationStageMask(vk::PipelineStageFlagBits::eColorAttachmentOutput);
124 context->device.resetFences(1, &inFlightFences[view][currentFrame[view]]);
125 if (window->isSwapChainNeeded() ) {
126 uint32_t semSize = imageAvailableSemaphores.size();
127 vk::SubmitInfo submitInfo(
128 semSize,
129 semSize > 0 ? imageAvailableSemaphores.data() : nullptr,//&imageAvailableSemaphores[view][currentFrame[view]],
130 semSize > 0 ? &waitDestinationStageMask : nullptr,
131 1,
132 &commandBuffers[view][imageIndex],
133 static_cast<uint32_t>(signalSemaphore.size()),
134 signalSemaphore.size() == 0 ? nullptr : signalSemaphore.data()//&renderFinishedSemaphores[view][currentFrame[view]]
135 );
136 context->graphicsQueue.submit(submitInfo, inFlightFences[view][currentFrame[view]]);
137 }
138 else {
139 vk::SubmitInfo submitInfo(
140 0,
141 {},
142 nullptr,
143 1,
144 &commandBuffers[view][imageIndex],
145 0,
146 nullptr
147 );
148 context->graphicsQueue.submit(submitInfo, inFlightFences[view][currentFrame[view]]);
149
150 const uint32_t timeoutNs = 1 * 1000 * 1000 * 1000;
151 for (int i = 0; i < 5; ++i) {
152 auto res = context->device.waitForFences(1, &inFlightFences[view][currentFrame[view]], VK_TRUE, timeoutNs);
153 if (res == vk::Result::eSuccess) {
154 // Buffer can be executed multiple times...
155 break;
156 }
157 std::cout << "Waiting for CmdBuffer fence timed out, retrying..." << std::endl;
158 }
159 }
160
161
162 inputProvider->releaseStreamsFrames();
163 /*
164 std::variant<vk::Semaphore,vk::Fence> res;
165 if (!window->useOpenXR()) {
166 res = renderFinishedSemaphores[view][currentFrame[view]];
167 }
168 else {
169 res =
170 }*/
171
172 //currentFrame[view] = (currentFrame[view] + 1) % MAX_FRAMES_IN_FLIGHT;
173 return inFlightFences[view][currentFrame[view]];
174}
vk::Queue graphicsQueue
Definition: VulkanContext.h:89
bool isDepthOutputRecquired()
bool isSwapChainNeeded()

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