Added wrapper for frame preparation and submission, including semaphore selection and text overlay
This commit is contained in:
parent
5266c25c33
commit
1b335ad2c8
3 changed files with 70 additions and 9 deletions
|
|
@ -664,6 +664,55 @@ void VulkanExampleBase::updateTextOverlay()
|
||||||
textOverlay->endTextUpdate();
|
textOverlay->endTextUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanExampleBase::prepareFrame()
|
||||||
|
{
|
||||||
|
// Acquire the next image from the swap chaing
|
||||||
|
VK_CHECK_RESULT(swapChain.acquireNextImage(semaphores.presentComplete, ¤tBuffer));
|
||||||
|
// Submit barrier that transforms color attachment image layout back from khr
|
||||||
|
submitPostPresentBarrier(swapChain.buffers[currentBuffer].image);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanExampleBase::submitFrame()
|
||||||
|
{
|
||||||
|
bool submitTextOverlay = enableTextOverlay && textOverlay->visible;
|
||||||
|
|
||||||
|
if (submitTextOverlay)
|
||||||
|
{
|
||||||
|
// Wait for color attachment output to finish before rendering the text overlay
|
||||||
|
VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
submitInfo.pWaitDstStageMask = &stageFlags;
|
||||||
|
|
||||||
|
// Set semaphores
|
||||||
|
// Wait for render complete semaphore
|
||||||
|
submitInfo.waitSemaphoreCount = 1;
|
||||||
|
submitInfo.pWaitSemaphores = &semaphores.renderComplete;
|
||||||
|
// Signal ready with text overlay complete semaphpre
|
||||||
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
|
submitInfo.pSignalSemaphores = &semaphores.textOverlayComplete;
|
||||||
|
|
||||||
|
// Submit current text overlay command buffer
|
||||||
|
submitInfo.commandBufferCount = 1;
|
||||||
|
submitInfo.pCommandBuffers = &textOverlay->cmdBuffers[currentBuffer];
|
||||||
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||||
|
|
||||||
|
// Reset wait and signal semaphores for rendering next frame
|
||||||
|
// Wait for swap chain presentation to finish
|
||||||
|
submitInfo.waitSemaphoreCount = 1;
|
||||||
|
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
||||||
|
// Signal ready with offscreen semaphore
|
||||||
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
|
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Submit barrier that transforms color attachment to khr presen
|
||||||
|
submitPrePresentBarrier(swapChain.buffers[currentBuffer].image);
|
||||||
|
|
||||||
|
VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, submitTextOverlay ? semaphores.textOverlayComplete : semaphores.renderComplete));
|
||||||
|
|
||||||
|
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
||||||
|
}
|
||||||
|
|
||||||
VulkanExampleBase::VulkanExampleBase(bool enableValidation)
|
VulkanExampleBase::VulkanExampleBase(bool enableValidation)
|
||||||
{
|
{
|
||||||
// Check for validation command line flag
|
// Check for validation command line flag
|
||||||
|
|
@ -1031,6 +1080,12 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
||||||
case 0x50:
|
case 0x50:
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
break;
|
break;
|
||||||
|
case VK_F1:
|
||||||
|
if (enableTextOverlay)
|
||||||
|
{
|
||||||
|
textOverlay->visible = !textOverlay->visible;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case VK_ESCAPE:
|
case VK_ESCAPE:
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -340,5 +340,17 @@ public:
|
||||||
VkPipelineStageFlags *pipelineStages);
|
VkPipelineStageFlags *pipelineStages);
|
||||||
|
|
||||||
void updateTextOverlay();
|
void updateTextOverlay();
|
||||||
|
|
||||||
|
// Prepare the frame for workload submission
|
||||||
|
// - Acquires the next image from the swap chain
|
||||||
|
// - Submits a post present barrier
|
||||||
|
// - Sets the default wait and signal semaphores
|
||||||
|
void prepareFrame();
|
||||||
|
|
||||||
|
// Submit the frames' workload
|
||||||
|
// - Submits the text overlay (if enabled)
|
||||||
|
// -
|
||||||
|
void submitFrame();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ public:
|
||||||
zoom = -2.5f;
|
zoom = -2.5f;
|
||||||
rotation = { 0.0f, 15.0f, 0.0f };
|
rotation = { 0.0f, 15.0f, 0.0f };
|
||||||
title = "Vulkan Example - Texturing";
|
title = "Vulkan Example - Texturing";
|
||||||
|
enableTextOverlay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
|
|
@ -517,10 +518,7 @@ public:
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
// Get next image in the swap chain (back/front buffer)
|
VulkanExampleBase::prepareFrame();
|
||||||
VK_CHECK_RESULT(swapChain.acquireNextImage(semaphores.presentComplete, ¤tBuffer));
|
|
||||||
|
|
||||||
submitPostPresentBarrier(swapChain.buffers[currentBuffer].image);
|
|
||||||
|
|
||||||
// Command buffer to be sumitted to the queue
|
// Command buffer to be sumitted to the queue
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
|
|
@ -529,11 +527,7 @@ public:
|
||||||
// Submit to queue
|
// Submit to queue
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||||
|
|
||||||
submitPrePresentBarrier(swapChain.buffers[currentBuffer].image);
|
VulkanExampleBase::submitFrame();
|
||||||
|
|
||||||
VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, semaphores.renderComplete));
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateQuad()
|
void generateQuad()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue