21 #ifndef FRAMEWORK_CONTEXT_HPP 22 #define FRAMEWORK_CONTEXT_HPP 24 #include "command_buffer_manager.hpp" 25 #include "fence_manager.hpp" 26 #include "framework/common.hpp" 81 return perFrame[swapchainIndex]->commandManager.requestCommandBuffer();
102 return perFrame[swapchainIndex]->secondaryCommandManagers[threadIndex]->requestCommandBuffer();
107 void submit(VkCommandBuffer cmdBuffer);
131 VkSemaphore
beginFrame(
unsigned index, VkSemaphore acquireSemaphore)
133 swapchainIndex = index;
134 perFrame[swapchainIndex]->beginFrame();
135 return perFrame[swapchainIndex]->setSwapchainAcquireSemaphore(acquireSemaphore);
145 vkQueueWaitIdle(queue);
146 for (
auto &pFrame : perFrame)
147 pFrame->setSecondaryCommandManagersCount(count);
148 renderingThreadCount = count;
156 return perFrame[swapchainIndex]->fenceManager;
164 return perFrame[swapchainIndex]->swapchainAcquireSemaphore;
172 return perFrame[swapchainIndex]->swapchainReleaseSemaphore;
177 VkDevice device = VK_NULL_HANDLE;
178 VkQueue queue = VK_NULL_HANDLE;
179 unsigned swapchainIndex = 0;
180 unsigned renderingThreadCount = 0;
184 PerFrame(VkDevice device,
unsigned graphicsQueueIndex);
188 VkSemaphore setSwapchainAcquireSemaphore(VkSemaphore acquireSemaphore);
189 void setSwapchainReleaseSemaphore(VkSemaphore releaseSemaphore);
190 void setSecondaryCommandManagersCount(
unsigned count);
192 VkDevice device = VK_NULL_HANDLE;
195 std::vector<std::unique_ptr<CommandBufferManager>> secondaryCommandManagers;
196 VkSemaphore swapchainAcquireSemaphore = VK_NULL_HANDLE;
197 VkSemaphore swapchainReleaseSemaphore = VK_NULL_HANDLE;
200 std::vector<std::unique_ptr<PerFrame>> perFrame;
202 void submitCommandBuffer(VkCommandBuffer, VkSemaphore acquireSemaphore, VkSemaphore releaseSemaphore);
The command buffer allocates command buffers and recycles them for us. This gives us a convenient int...
The Context is the primary way for samples to interact with the swapchain and get rendered images to ...
void setRenderingThreadCount(unsigned count)
Sets the number of worker threads which can use secondary command buffers. This call is blocking and ...
VkDevice getDevice()
Get the Vulkan device assigned to the context.
Platform & getPlatform()
Gets the current platform.
void submit(VkCommandBuffer cmdBuffer)
Submit a command buffer to the queue.
VkCommandBuffer requestPrimaryCommandBuffer()
Requests a reset primary command buffer.
Result onPlatformUpdate(Platform *pPlatform)
Called by the platform internally when platform either initializes itself or the swapchain has been r...
The FenceManager keeps track of fences which in turn are used to keep track of GPU progress...
FenceManager & getFenceManager()
Gets the fence manager for the current swapchain image. Used by the platform internally.
void submitSwapchain(VkCommandBuffer cmdBuffer)
Submit a command buffer to the queue which renders to the swapchain image.
VkQueue getGraphicsQueue()
Get the Vulkan graphics queue assigned to the context.
VkSemaphore beginFrame(unsigned index, VkSemaphore acquireSemaphore)
Called by the platform, begins a frame.
VkCommandBuffer requestSecondaryCommandBuffer(unsigned threadIndex)
Requests a reset secondary command buffer, suitable for rendering multithreaded.
VkPhysicalDevice getPhysicalDevice() const
Gets the Vulkan physical device assigned to the context.
const VkSemaphore & getSwapchainAcquireSemaphore() const
Gets the acquire semaphore for the swapchain. Used by the platform internally.
const VkSemaphore & getSwapchainReleaseSemaphore() const
Gets the release semaphore for the swapchain. Used by the platform internally.