From 55df3cdf6714f0cb4e841ae68aee88647ae53be8 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Fri, 29 Sep 2017 15:50:35 +0300 Subject: [PATCH] vulkan: Implement vsync --- rpcs3/Emu/RSX/VK/VKHelpers.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index c67f34d106..7eaefec51e 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -834,20 +834,33 @@ namespace vk CHECK_RESULT(vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, m_surface, &nb_available_modes, present_modes.data())); VkPresentModeKHR swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR; + VkPresentModeKHR preferred_mode = (g_cfg.video.vsync) ? VK_PRESENT_MODE_FIFO_RELAXED_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR; + bool mailbox_exists = false; for (VkPresentModeKHR mode : present_modes) { if (mode == VK_PRESENT_MODE_MAILBOX_KHR) { - //If we can get a mailbox mode, use it + mailbox_exists = true; + continue; + } + + if (mode == preferred_mode) + { swapchain_present_mode = mode; break; } + } - //If we can get out of using the FIFO mode, take it. Fifo is very high latency (generic vsync) - if (swapchain_present_mode == VK_PRESENT_MODE_FIFO_KHR && - (mode == VK_PRESENT_MODE_IMMEDIATE_KHR || mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR)) - swapchain_present_mode = mode; + if (preferred_mode != swapchain_present_mode) + { + //Preferred video mode was not found. Fall back to mailbox if it exists + LOG_WARNING(RSX, "Swapchain: Could not set the preferred present mode 0x%X. Falling back to mailbox if supported (supported=%d)", (u32)preferred_mode, mailbox_exists); + + if (mailbox_exists) + { + swapchain_present_mode = VK_PRESENT_MODE_MAILBOX_KHR; + } } uint32_t nb_swap_images = surface_descriptors.minImageCount + 1;