# HG changeset patch # User sam # Date 1718460141 -25200 # Node ID f32359ffd8828ea3a88bc5c47c7a703e5b58a0a4 # Parent dd757eb5ca860a0cc25d69333916d2d71e3ddfaa fix: now something wrong with swapchain on linux XD diff -r dd757eb5ca86 -r f32359ffd882 semicongine/renderer.nim --- 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 diff -r dd757eb5ca86 -r f32359ffd882 semicongine/vulkan/swapchain.nim --- 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