Fence sync
This commit is contained in:
parent
19afba3f71
commit
671cebdc63
1 changed files with 17 additions and 5 deletions
|
|
@ -59,6 +59,7 @@ public:
|
||||||
// Semaphore used to synchronize blit to swapchain
|
// Semaphore used to synchronize blit to swapchain
|
||||||
VkSemaphore blitCompleteSemaphore;
|
VkSemaphore blitCompleteSemaphore;
|
||||||
std::vector<VkCommandBuffer> blitCommandBuffers;
|
std::vector<VkCommandBuffer> blitCommandBuffers;
|
||||||
|
std::vector<VkFence> blitWaitFences;
|
||||||
|
|
||||||
// Camera and view properties
|
// Camera and view properties
|
||||||
float eyeSeparation = 0.08f;
|
float eyeSeparation = 0.08f;
|
||||||
|
|
@ -92,6 +93,9 @@ public:
|
||||||
vkFreeMemory(device, colorAttachment.memory, nullptr);
|
vkFreeMemory(device, colorAttachment.memory, nullptr);
|
||||||
|
|
||||||
vkDestroySemaphore(device, blitCompleteSemaphore, nullptr);
|
vkDestroySemaphore(device, blitCompleteSemaphore, nullptr);
|
||||||
|
for (auto& fence : blitWaitFences) {
|
||||||
|
vkDestroyFence(device, fence, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
scene.destroy();
|
scene.destroy();
|
||||||
|
|
||||||
|
|
@ -636,23 +640,24 @@ public:
|
||||||
VulkanExampleBase::prepareFrame();
|
VulkanExampleBase::prepareFrame();
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
|
VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
||||||
|
VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer]));
|
||||||
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
||||||
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
||||||
|
|
||||||
// Blit
|
// Blit
|
||||||
|
VK_CHECK_RESULT(vkWaitForFences(device, 1, &blitWaitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
||||||
|
VK_CHECK_RESULT(vkResetFences(device, 1, &blitWaitFences[currentBuffer]));
|
||||||
submitInfo.pWaitSemaphores = &semaphores.renderComplete;
|
submitInfo.pWaitSemaphores = &semaphores.renderComplete;
|
||||||
submitInfo.pSignalSemaphores = &blitCompleteSemaphore;
|
submitInfo.pSignalSemaphores = &blitCompleteSemaphore;
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = &blitCommandBuffers[currentBuffer];
|
submitInfo.pCommandBuffers = &blitCommandBuffers[currentBuffer];
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, blitWaitFences[currentBuffer]));
|
||||||
|
|
||||||
VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, blitCompleteSemaphore));
|
VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, blitCompleteSemaphore));
|
||||||
|
|
||||||
// TODO: Proper fence sync
|
|
||||||
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepare()
|
void prepare()
|
||||||
|
|
@ -663,6 +668,13 @@ public:
|
||||||
prepareDescriptors();
|
prepareDescriptors();
|
||||||
preparePipelines();
|
preparePipelines();
|
||||||
buildCommandBuffers();
|
buildCommandBuffers();
|
||||||
|
|
||||||
|
VkFenceCreateInfo fenceCreateInfo = vks::initializers::fenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT);
|
||||||
|
blitWaitFences.resize(blitCommandBuffers.size());
|
||||||
|
for (auto& fence : blitWaitFences) {
|
||||||
|
VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence));
|
||||||
|
}
|
||||||
|
|
||||||
prepared = true;
|
prepared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue