changeset 1494:02e869aded5d

fix: issue with presentation-wait semaphores
author sam <sam@basx.dev>
date Wed, 24 Sep 2025 21:57:52 +0700
parents 986e37dc76e0
children a9c0f899a734
files semicongine/core/types.nim semicongine/rendering/swapchain.nim
diffstat 2 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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),