# HG changeset patch # User sam # Date 1711811798 -25200 # Node ID 4bf4c029b880192e1c3cb17bef6f9c7c21ce32df # Parent b101ea4d411e8d4baaa8bb6309a14313fde793e1 fix: possibly undeterministic queue selection in swapchain diff -r b101ea4d411e -r 4bf4c029b880 semicongine/renderer.nim --- 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 diff -r b101ea4d411e -r 4bf4c029b880 semicongine/vulkan/swapchain.nim --- 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