# HG changeset patch # User sam # Date 1758725872 -25200 # Node ID 02e869aded5d5c2d9f246bbb66f3802c81b7b046 # Parent 986e37dc76e08aa8908716ffb80a4cddee681c71 fix: issue with presentation-wait semaphores diff -r 986e37dc76e0 -r 02e869aded5d semicongine/core/types.nim --- a/semicongine/core/types.nim Sun Jun 01 21:57:13 2025 +0700 +++ b/semicongine/core/types.nim Wed Sep 24 21:57:52 2025 +0700 @@ -4,7 +4,7 @@ import ../thirdparty/db_connector/db_sqlite const - INFLIGHTFRAMES* = 2'u32 + INFLIGHTFRAMES* = 1'u32 MAX_DESCRIPTORSETS* = 4 BUFFER_ALIGNMENT* = 64'u64 # align offsets inside buffers along this alignment # ca. 100mb per block, seems reasonable @@ -93,7 +93,7 @@ # frame-in-flight handling currentFiF*: range[0 .. (INFLIGHTFRAMES - 1).int] queueFinishedFence*: array[INFLIGHTFRAMES.int, VkFence] - imageAvailableSemaphore*: array[INFLIGHTFRAMES.int, VkSemaphore] + imageAvailableSemaphore*: seq[VkSemaphore] renderFinishedSemaphore*: array[INFLIGHTFRAMES.int, VkSemaphore] commandBuffers*: array[INFLIGHTFRAMES.int, VkCommandBuffer] oldSwapchain*: Swapchain diff -r 986e37dc76e0 -r 02e869aded5d semicongine/rendering/swapchain.nim --- a/semicongine/rendering/swapchain.nim Sun Jun 01 21:57:13 2025 +0700 +++ b/semicongine/rendering/swapchain.nim Wed Sep 24 21:57:52 2025 +0700 @@ -155,8 +155,11 @@ # create sync primitives for i in 0 ..< INFLIGHTFRAMES: swapchain.queueFinishedFence[i] = svkCreateFence(signaled = true) + swapchain.renderFinishedSemaphore[i] = svkCreateSemaphore() + + swapchain.imageAvailableSemaphore.setLen(framebuffers.len) + for i in 0 ..< framebuffers.len: swapchain.imageAvailableSemaphore[i] = svkCreateSemaphore() - swapchain.renderFinishedSemaphore[i] = svkCreateSemaphore() # command buffers var commandPoolCreateInfo = VkCommandPoolCreateInfo( @@ -224,7 +227,7 @@ swapchain.vk, # high(uint64), 10_000_000'u64, # wait max 10ms - swapchain.imageAvailableSemaphore[swapchain.currentFiF], + swapchain.imageAvailableSemaphore[swapchain.currentFramebufferIndex], VkFence(0), addr(swapchain.currentFramebufferIndex), ) @@ -236,12 +239,13 @@ return some(swapchain.framebuffers[swapchain.currentFramebufferIndex]) proc swap(swapchain: Swapchain, commandBuffer: VkCommandBuffer): bool = + debugecho "currentFiF: ", swapchain.currentFiF var waitStage = VkPipelineStageFlags(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT) submitInfo = VkSubmitInfo( sType: VK_STRUCTURE_TYPE_SUBMIT_INFO, waitSemaphoreCount: 1, - pWaitSemaphores: addr(swapchain.imageAvailableSemaphore[swapchain.currentFiF]), + pWaitSemaphores: addr(swapchain.imageAvailableSemaphore[swapchain.currentFramebufferIndex]), pWaitDstStageMask: addr(waitStage), commandBufferCount: 1, pCommandBuffers: addr(commandBuffer),