Browse Source

Fix Vulkan renderer

Kajetan Johannes Hammerle 4 days ago
parent
commit
19fc097f3c
2 changed files with 8 additions and 6 deletions
  1. 1 0
      include/core/VulkanWrapper.hpp
  2. 7 6
      src/VulkanWrapper.cpp

+ 1 - 0
include/core/VulkanWrapper.hpp

@@ -119,6 +119,7 @@ namespace Core::Vulkan {
     struct SwapchainImages {
         List<VkImage> images{};
         List<ImageView> imageViews{};
+        List<Semaphore> renderFinishedSemaphore{};
 
         bool init(const Swapchain& s, VkFormat format);
     };

+ 7 - 6
src/VulkanWrapper.cpp

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