|
@@ -182,10 +182,13 @@ bool SwapchainImages::init(const Swapchain& s, VkFormat format) {
|
|
VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, nullptr));
|
|
VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, nullptr));
|
|
images.resize(c);
|
|
images.resize(c);
|
|
imageViews.resize(c);
|
|
imageViews.resize(c);
|
|
|
|
+ renderFinishedSemaphore.resize(c);
|
|
VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, &images[0]));
|
|
VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, &images[0]));
|
|
for(u32 x = 0; x < c; x++) {
|
|
for(u32 x = 0; x < c; x++) {
|
|
if(imageViews[x].init(s.device, images[x], format)) {
|
|
if(imageViews[x].init(s.device, images[x], format)) {
|
|
return true;
|
|
return true;
|
|
|
|
+ } else if(renderFinishedSemaphore[x].init(s.device)) {
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
@@ -520,7 +523,6 @@ struct VulkanDummy {
|
|
struct Frame {
|
|
struct Frame {
|
|
CommandBuffer commandBuffer{};
|
|
CommandBuffer commandBuffer{};
|
|
Semaphore imageAvailableSemaphore{};
|
|
Semaphore imageAvailableSemaphore{};
|
|
- Semaphore renderFinishedSemaphore{};
|
|
|
|
Fence inFlightFence{};
|
|
Fence inFlightFence{};
|
|
};
|
|
};
|
|
|
|
|
|
@@ -743,7 +745,6 @@ struct VulkanDummy {
|
|
for(Frame& f : frames) {
|
|
for(Frame& f : frames) {
|
|
if(f.commandBuffer.init(commandPool) ||
|
|
if(f.commandBuffer.init(commandPool) ||
|
|
f.imageAvailableSemaphore.init(base) ||
|
|
f.imageAvailableSemaphore.init(base) ||
|
|
- f.renderFinishedSemaphore.init(base) ||
|
|
|
|
f.inFlightFence.init(base)) {
|
|
f.inFlightFence.init(base)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -790,18 +791,18 @@ struct VulkanDummy {
|
|
case SwapchainResult::ERROR_RECREATE: return recreateSwapchain();
|
|
case SwapchainResult::ERROR_RECREATE: return recreateSwapchain();
|
|
case SwapchainResult::ERROR: return true;
|
|
case SwapchainResult::ERROR: return true;
|
|
}
|
|
}
|
|
|
|
+ // https://docs.vulkan.org/guide/latest/swapchain_semaphore_reuse.html
|
|
|
|
+ Semaphore& renderSemaphore = images.renderFinishedSemaphore[imageIndex];
|
|
f.inFlightFence.reset();
|
|
f.inFlightFence.reset();
|
|
f.commandBuffer.reset();
|
|
f.commandBuffer.reset();
|
|
fillCommandBuffer(f.commandBuffer, imageIndex);
|
|
fillCommandBuffer(f.commandBuffer, imageIndex);
|
|
|
|
|
|
graphicsQueue.submit(
|
|
graphicsQueue.submit(
|
|
f.commandBuffer, f.inFlightFence, f.imageAvailableSemaphore,
|
|
f.commandBuffer, f.inFlightFence, f.imageAvailableSemaphore,
|
|
- f.renderFinishedSemaphore,
|
|
|
|
- VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
|
|
|
|
|
+ renderSemaphore, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
|
|
|
|
|
bool recreate = false;
|
|
bool recreate = false;
|
|
- switch(presentQueue.present(
|
|
|
|
- f.renderFinishedSemaphore, swapchain, imageIndex)) {
|
|
|
|
|
|
+ switch(presentQueue.present(renderSemaphore, swapchain, imageIndex)) {
|
|
case SwapchainResult::SUCCESS: break;
|
|
case SwapchainResult::SUCCESS: break;
|
|
case SwapchainResult::RECREATE:
|
|
case SwapchainResult::RECREATE:
|
|
case SwapchainResult::ERROR_RECREATE: recreate = true;
|
|
case SwapchainResult::ERROR_RECREATE: recreate = true;
|