From 439a4e4687bf4ad3b6d88d5dd313e02f0d129d2e Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 1 Apr 2025 16:33:31 +0200 Subject: [PATCH] Vulkan: Partial revert of swap chain refactor. On Windows presenting mode mailbox would reduce lag. We might want to be more selective on which mode to use when. --- intern/ghost/intern/GHOST_ContextVK.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/intern/ghost/intern/GHOST_ContextVK.cc b/intern/ghost/intern/GHOST_ContextVK.cc index e127e2b9263..096d7a35068 100644 --- a/intern/ghost/intern/GHOST_ContextVK.cc +++ b/intern/ghost/intern/GHOST_ContextVK.cc @@ -733,13 +733,26 @@ static void requireExtension(const vector &extensions_ava } } -static GHOST_TSuccess selectPresentMode(VkPhysicalDevice /*device*/, - VkSurfaceKHR /*surface*/, +static GHOST_TSuccess selectPresentMode(VkPhysicalDevice device, + VkSurfaceKHR surface, VkPresentModeKHR *r_presentMode) { - /* FIFO present mode is always available and we prefer it as it will keep the main loop running - * along the monitor refresh rate. Mailbox and Fifo relaxed can generate a lot of frames that - * will never be displayed. */ + uint32_t present_count; + vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &present_count, nullptr); + vector presents(present_count); + vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &present_count, presents.data()); + /* MAILBOX is the lowest latency V-Sync enabled mode. We will use it if available as it fixes + * some lag on NVIDIA/Intel GPUs. */ + for (auto present_mode : presents) { + if (present_mode == VK_PRESENT_MODE_MAILBOX_KHR) { + *r_presentMode = present_mode; + return GHOST_kSuccess; + } + } + + /*FIFO present mode is always available and we (should) prefer it as it will keep the main loop + * running along the monitor refresh rate. Mailbox and Fifo relaxed can generate a lot of frames + * that will never be displayed. */ *r_presentMode = VK_PRESENT_MODE_FIFO_KHR; return GHOST_kSuccess; }