changeset 946:5ef3e789b672

fix: possibly undeterministic queue selection in swapchain
author sam <sam@basx.dev>
date Sat, 30 Mar 2024 22:16:38 +0700
parents b65068f5f246
children 17943f768402
files semicongine/renderer.nim semicongine/vulkan/swapchain.nim
diffstat 2 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/renderer.nim	Sat Mar 30 21:52:17 2024 +0700
+++ b/semicongine/renderer.nim	Sat Mar 30 22:16:38 2024 +0700
@@ -433,7 +433,7 @@
 
   renderer.currentCommandBuffer.endRenderCommands()
 
-  if not renderer.swapchain.swap(renderer.currentCommandBuffer):
+  if not renderer.swapchain.swap(renderer.queue, renderer.currentCommandBuffer):
     let res = renderer.swapchain.recreate()
     if res.isSome:
       var oldSwapchain = renderer.swapchain
--- a/semicongine/vulkan/swapchain.nim	Sat Mar 30 21:52:17 2024 +0700
+++ b/semicongine/vulkan/swapchain.nim	Sat Mar 30 22:16:38 2024 +0700
@@ -27,6 +27,7 @@
     surfaceFormat: VkSurfaceFormatKHR
     imageCount: uint32
     inFlightFrames*: int
+    presentQueue: Queue
 
 
 proc createSwapchain*(
@@ -96,6 +97,8 @@
       swapchain.imageAvailableSemaphore.add device.createSemaphore()
       swapchain.renderFinishedSemaphore.add device.createSemaphore()
     debug &"Created swapchain with: {nImages} framebuffers, {inFlightFrames} in-flight frames, {swapchain.dimension.x}x{swapchain.dimension.y}"
+    assert swapchain.device.firstPresentationQueue().isSome, "No present queue found"
+    swapchain.presentQueue = swapchain.device.firstPresentationQueue().get
     result = some(swapchain)
   else:
     result = none(Swapchain)
@@ -126,11 +129,10 @@
   else:
     result = none(int)
 
-proc swap*(swapchain: var Swapchain, commandBuffer: VkCommandBuffer): bool =
+proc swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool =
   assert swapchain.device.vk.valid
   assert swapchain.vk.valid
-  assert swapchain.device.firstGraphicsQueue().isSome
-  assert swapchain.device.firstPresentationQueue().isSome
+  assert queue.vk.isSome
 
   var
     waitSemaphores = [swapchain.imageAvailableSemaphore[swapchain.currentInFlight].vk]
@@ -145,8 +147,7 @@
       signalSemaphoreCount: 1,
       pSignalSemaphores: addr(swapchain.renderFinishedSemaphore[swapchain.currentInFlight].vk),
     )
-  checkVkResult vkQueueSubmit(
-    swapchain.device.firstGraphicsQueue().get.vk,
+  checkVkResult queue.vk.vkQueueSubmit(
     1,
     addr(submitInfo),
     swapchain.queueFinishedFence[swapchain.currentInFlight].vk
@@ -161,7 +162,7 @@
     pImageIndices: addr(swapchain.currentFramebufferIndex),
     pResults: nil,
   )
-  let presentResult = vkQueuePresentKHR(swapchain.device.firstPresentationQueue().get().vk, addr(presentInfo))
+  let presentResult = vkQueuePresentKHR(swapchain.presentQueue.vk, addr(presentInfo))
   if presentResult != VK_SUCCESS:
     return false