changeset 913:b19faed54b14

did: correct usage of vSync/triple buffering
author Sam <sam@basx.dev>
date Sun, 10 Mar 2024 22:06:52 +0700
parents c72b246d8413
children c5ca795af740
files semicongine/vulkan/swapchain.nim
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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,
   )