Additional semaphore to synchronize offscreen and final render (Refs #70)
This commit is contained in:
parent
c463a2905d
commit
046d0f2c42
1 changed files with 19 additions and 11 deletions
|
|
@ -124,12 +124,16 @@ public:
|
||||||
FrameBufferAttachment color, depth;
|
FrameBufferAttachment color, depth;
|
||||||
// Texture target for framebuffer blit
|
// Texture target for framebuffer blit
|
||||||
vkTools::VulkanTexture textureTarget;
|
vkTools::VulkanTexture textureTarget;
|
||||||
|
VkSampler colorSampler;
|
||||||
} offScreenFrameBuf, offScreenFrameBufB;
|
} offScreenFrameBuf, offScreenFrameBufB;
|
||||||
|
|
||||||
// Used to store commands for rendering and blitting
|
// Used to store commands for rendering and blitting
|
||||||
// the offscreen scene
|
// the offscreen scene
|
||||||
VkCommandBuffer offScreenCmdBuffer = VK_NULL_HANDLE;
|
VkCommandBuffer offScreenCmdBuffer = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
// Semaphore used to synchronize between offscreen and final scene rendering
|
||||||
|
VkSemaphore offscreenSemaphore = VK_NULL_HANDLE;
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||||
{
|
{
|
||||||
zoom = -10.25f;
|
zoom = -10.25f;
|
||||||
|
|
@ -192,6 +196,7 @@ public:
|
||||||
vkTools::destroyUniformData(device, &uniformData.fsHorzBlur);
|
vkTools::destroyUniformData(device, &uniformData.fsHorzBlur);
|
||||||
|
|
||||||
vkFreeCommandBuffers(device, cmdPool, 1, &offScreenCmdBuffer);
|
vkFreeCommandBuffers(device, cmdPool, 1, &offScreenCmdBuffer);
|
||||||
|
vkDestroySemaphore(device, offscreenSemaphore, nullptr);
|
||||||
|
|
||||||
textureLoader->destroyTexture(textures.cubemap);
|
textureLoader->destroyTexture(textures.cubemap);
|
||||||
}
|
}
|
||||||
|
|
@ -394,18 +399,22 @@ public:
|
||||||
VulkanExampleBase::flushCommandBuffer(cmdBuffer, queue, true);
|
VulkanExampleBase::flushCommandBuffer(cmdBuffer, queue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createOffscreenCommandBuffer()
|
// Sets up the command buffer that renders the scene to the offscreen frame buffer
|
||||||
{
|
// The blur method used in this example is multi pass and renders the vertical
|
||||||
VkCommandBufferAllocateInfo cmd = vkTools::initializers::commandBufferAllocateInfo(
|
// blur first and then the horizontal one.
|
||||||
cmdPool,
|
// While it's possible to blur in one pass, this method is widely used as it
|
||||||
VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
// requires far less samples to generate the blur
|
||||||
1);
|
|
||||||
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmd, &offScreenCmdBuffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the 3D scene into a texture target
|
|
||||||
void buildOffscreenCommandBuffer()
|
void buildOffscreenCommandBuffer()
|
||||||
{
|
{
|
||||||
|
if (offScreenCmdBuffer == VK_NULL_HANDLE)
|
||||||
|
{
|
||||||
|
offScreenCmdBuffer = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a semaphore used to synchronize offscreen rendering and usage
|
||||||
|
VkSemaphoreCreateInfo semaphoreCreateInfo = vkTools::initializers::semaphoreCreateInfo();
|
||||||
|
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &offscreenSemaphore));
|
||||||
|
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
||||||
|
|
||||||
// Horizontal blur
|
// Horizontal blur
|
||||||
|
|
@ -1207,7 +1216,6 @@ public:
|
||||||
preparePipelines();
|
preparePipelines();
|
||||||
setupDescriptorPool();
|
setupDescriptorPool();
|
||||||
setupDescriptorSet();
|
setupDescriptorSet();
|
||||||
createOffscreenCommandBuffer();
|
|
||||||
buildCommandBuffers();
|
buildCommandBuffers();
|
||||||
prepared = true;
|
prepared = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue