From 7583db3bef522e0303ec913e6d5f0011e347d88d Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 10 Nov 2021 20:55:22 +0100 Subject: [PATCH] vk: option to duplicate frames to simulate swap interval > 1 Issue #293 --- core/cfg/option.cpp | 1 + core/cfg/option.h | 1 + core/rend/gui.cpp | 13 +++++++++++++ core/rend/vulkan/vulkan_context.cpp | 5 +---- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/cfg/option.cpp b/core/cfg/option.cpp index 114f83cce..9ea1e8bc2 100644 --- a/core/cfg/option.cpp +++ b/core/cfg/option.cpp @@ -96,6 +96,7 @@ Option VSync("rend.vsync", true); Option PixelBufferSize("rend.PixelBufferSize", 512 * 1024 * 1024); Option AnisotropicFiltering("rend.AnisotropicFiltering", 1); Option ThreadedRendering("rend.ThreadedRendering", true); +Option DupeFrames("rend.DupeFrames", false); // Misc diff --git a/core/cfg/option.h b/core/cfg/option.h index 65b1a0f86..e4cac2b6b 100644 --- a/core/cfg/option.h +++ b/core/cfg/option.h @@ -436,6 +436,7 @@ extern Option VSync; extern Option PixelBufferSize; extern Option AnisotropicFiltering; extern Option ThreadedRendering; +extern Option DupeFrames; // Misc diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 73578e648..66bbf8f69 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1616,6 +1616,19 @@ static void gui_display_settings() #ifndef TARGET_IPHONE OptionCheckbox("VSync", config::VSync, "Synchronizes the frame rate with the screen refresh rate. Recommended"); #endif + ImGui::Indent(); + if (!config::VSync || !isVulkan(config::RendererType)) + { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); + } + OptionCheckbox("Duplicate frames", config::DupeFrames, "Duplicate frames on high refresh rate monitors (120 Hz and higher)"); + if (!config::VSync || !isVulkan(config::RendererType)) + { + ImGui::PopItemFlag(); + ImGui::PopStyleVar(); + } + ImGui::Unindent(); OptionCheckbox("Show FPS Counter", config::ShowFPS, "Show on-screen frame/sec counter"); OptionCheckbox("Show VMU In-game", config::FloatVMUs, "Show the VMU LCD screens while in-game"); OptionCheckbox("Rotate Screen 90°", config::Rotate90, "Rotate the screen 90° counterclockwise"); diff --git a/core/rend/vulkan/vulkan_context.cpp b/core/rend/vulkan/vulkan_context.cpp index 6dbaff1e4..2fd078aa4 100644 --- a/core/rend/vulkan/vulkan_context.cpp +++ b/core/rend/vulkan/vulkan_context.cpp @@ -567,12 +567,9 @@ void VulkanContext::CreateSwapChain() break; } } - /* - if (swapOnVSync && settings.display.refreshRate > 60.f) - // TODO config option to enable duped frames + if (swapOnVSync && config::DupeFrames && settings.display.refreshRate > 60.f) swapInterval = settings.display.refreshRate / 60.f; else - */ swapInterval = 1; vk::SurfaceTransformFlagBitsKHR preTransform = (surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity) ? vk::SurfaceTransformFlagBitsKHR::eIdentity : surfaceCapabilities.currentTransform;