# HG changeset patch # User sam # Date 1730822552 -25200 # Node ID ce92db0b8f50ffdcf238eff13c577f467625a15d # Parent 3dbf77ca78b9b9896c8a0804e55ddda8e502bc54 add: allow configuration of triple buffering diff -r 3dbf77ca78b9 -r ce92db0b8f50 semicongine/rendering.nim --- a/semicongine/rendering.nim Mon Nov 04 23:27:30 2024 +0700 +++ b/semicongine/rendering.nim Tue Nov 05 23:02:32 2024 +0700 @@ -85,6 +85,7 @@ # parameters to initSwapchain, required for swapchain recreation renderPass*: RenderPass vSync*: bool + tripleBuffering*: bool # populated through initSwapchain proc vk: VkSwapchainKHR width*: uint32 diff -r 3dbf77ca78b9 -r ce92db0b8f50 semicongine/rendering/swapchain.nim --- a/semicongine/rendering/swapchain.nim Mon Nov 04 23:27:30 2024 +0700 +++ b/semicongine/rendering/swapchain.nim Tue Nov 05 23:02:32 2024 +0700 @@ -1,7 +1,8 @@ -const N_FRAMEBUFFERS = 3'u32 - proc initSwapchain( - renderPass: RenderPass, vSync: bool = false, oldSwapchain: Swapchain = nil + renderPass: RenderPass, + vSync: bool = false, + tripleBuffering: bool = true, + oldSwapchain: Swapchain = nil, ): Swapchain = assert vulkan.instance.Valid, "Vulkan not initialized" @@ -17,7 +18,7 @@ return nil # following "count" is established according to vulkan specs - var minFramebufferCount = N_FRAMEBUFFERS + var minFramebufferCount = if tripleBuffering: 3'u32 else: 2'u32 minFramebufferCount = max(minFramebufferCount, capabilities.minImageCount) if capabilities.maxImageCount != 0: minFramebufferCount = min(minFramebufferCount, capabilities.maxImageCount) @@ -56,6 +57,7 @@ height: height, renderPass: renderPass, vSync: vSync, + tripleBuffering: tripleBuffering, oldSwapchain: oldSwapchain, ) @@ -267,19 +269,23 @@ swapchain.currentFiF = (uint32(swapchain.currentFiF) + 1) mod INFLIGHTFRAMES return true +# for re-creation with same settings, e.g. window resized proc recreateSwapchain*() = let newSwapchain = initSwapchain( renderPass = vulkan.swapchain.renderPass, vSync = vulkan.swapchain.vSync, + tripleBuffering = vulkan.swapchain.tripleBuffering, oldSwapchain = vulkan.swapchain, ) if newSwapchain != nil: vulkan.swapchain = newSwapchain -proc recreateSwapchain*(vSync: bool) = +# for re-creation with different settings +proc recreateSwapchain*(vSync: bool, tripleBuffering: bool) = let newSwapchain = initSwapchain( renderPass = vulkan.swapchain.renderPass, vSync = vSync, + tripleBuffering = tripleBuffering, oldSwapchain = vulkan.swapchain, ) if newSwapchain != nil: