# HG changeset patch # User Sam # Date 1710083212 -25200 # Node ID b19faed54b140d234c9a5a78f04f8b0c4e3b02dc # Parent c72b246d841314081fb979358ec245a61a990fd8 did: correct usage of vSync/triple buffering diff -r c72b246d8413 -r b19faed54b14 semicongine/vulkan/swapchain.nim --- a/semicongine/vulkan/swapchain.nim Sun Mar 10 20:02:11 2024 +0700 +++ b/semicongine/vulkan/swapchain.nim Sun Mar 10 22:06:52 2024 +0700 @@ -40,7 +40,8 @@ queueFamily: QueueFamily, desiredNumberOfImages = 3'u32, inFlightFrames = 2, - oldSwapchain = VkSwapchainKHR(0) + oldSwapchain = VkSwapchainKHR(0), + vSync = false ): Option[Swapchain] = assert device.vk.valid assert device.physicalDevice.vk.valid @@ -57,6 +58,7 @@ imageCount = max(imageCount, capabilities.minImageCount) if capabilities.maxImageCount != 0: imageCount = min(imageCount, capabilities.maxImageCount) + let hasTripleBuffering = VK_PRESENT_MODE_MAILBOX_KHR in device.physicalDevice.getSurfacePresentModes() var createInfo = VkSwapchainCreateInfoKHR( sType: VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, surface: device.physicalDevice.surface, @@ -70,7 +72,7 @@ imageSharingMode: VK_SHARING_MODE_EXCLUSIVE, preTransform: capabilities.currentTransform, compositeAlpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, # only used for blending with other windows, can be opaque - presentMode: VK_PRESENT_MODE_FIFO_KHR, + presentMode: if (vSync or not hasTripleBuffering): VK_PRESENT_MODE_FIFO_KHR else: VK_PRESENT_MODE_MAILBOX_KHR, clipped: true, oldSwapchain: oldSwapchain, )