changeset 1158:f32359ffd882

fix: now something wrong with swapchain on linux XD
author sam <sam@basx.dev>
date Sat, 15 Jun 2024 21:02:21 +0700
parents dd757eb5ca86
children e7cbb13999e4 92691ddcb9fe
files semicongine/renderer.nim semicongine/vulkan/swapchain.nim
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/renderer.nim	Sat Jun 15 18:17:31 2024 +0700
+++ b/semicongine/renderer.nim	Sat Jun 15 21:02:21 2024 +0700
@@ -370,15 +370,29 @@
   scene.ClearDirtyShaderGlobals()
 
 proc StartNewFrame*(renderer: var Renderer): bool =
+  # first, we need to await the next free frame from the swapchain
   if not renderer.swapchain.AcquireNextFrame():
+    # so, there was a problem while acquiring the frame
+    # lets first take a break (not sure if this helps anything)
     checkVkResult renderer.device.vk.vkDeviceWaitIdle()
+    # now, first thing is, we recreate the swapchain, because a invalid swapchain
+    # is a common reason for the inability to acquire the next frame
     let res = renderer.swapchain.Recreate()
     if res.isSome:
+      # okay, swapchain recreation worked
+      # Now we can swap old and new swapchain
+      # the vkDeviceWaitIdle makes the resizing of windows not super smooth,
+      # but things seem to be more stable this way
       var oldSwapchain = renderer.swapchain
       renderer.swapchain = res.get()
       checkVkResult renderer.device.vk.vkDeviceWaitIdle()
       oldSwapchain.Destroy()
+      # NOW, we still have to acquire that next frame with the NEW swapchain
+      # if that fails, I don't know what to smart to do...
+      if not renderer.swapchain.AcquireNextFrame():
+        return false
     else:
+      # dang, swapchain could not be recreated. Some bigger issues is at hand...
       return false
   renderer.nextFrameReady = true
   return true
--- a/semicongine/vulkan/swapchain.nim	Sat Jun 15 18:17:31 2024 +0700
+++ b/semicongine/vulkan/swapchain.nim	Sat Jun 15 21:02:21 2024 +0700
@@ -120,11 +120,9 @@
     addr swapchain.currentFramebufferIndex,
   )
 
-  if nextImageResult == VK_SUCCESS:
-    swapchain.queueFinishedFence[swapchain.currentInFlight].Reset()
-    return true
-  else:
-    return false
+  swapchain.queueFinishedFence[swapchain.currentInFlight].Reset()
+
+  return nextImageResult == VK_SUCCESS
 
 proc Swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool =
   assert swapchain.device.vk.Valid