Vulkan: Simplify set_vsync. Remove relaxed fifo.

It looks like relaxed fifo tears when refresh rate doesn't
match because it always misses a refresh interval.
This commit is contained in:
BearOso 2024-06-13 16:16:20 -05:00
parent 3980a9d6d4
commit 008cbcd1a1
3 changed files with 7 additions and 20 deletions

View File

@ -18,13 +18,9 @@ Swapchain::~Swapchain()
{ {
} }
bool Swapchain::set_vsync(bool new_setting) void Swapchain::set_vsync(bool new_setting)
{ {
if (new_setting == vsync)
return false;
vsync = new_setting; vsync = new_setting;
return true;
} }
void Swapchain::on_render_pass_end(std::function<void ()> function) void Swapchain::on_render_pass_end(std::function<void ()> function)
@ -104,14 +100,14 @@ static bool vector_find(std::vector<T> haystack, T&& needle)
vk::PresentModeKHR Swapchain::get_present_mode() { vk::PresentModeKHR Swapchain::get_present_mode() {
auto present_mode = vk::PresentModeKHR::eFifo; auto present_mode = vk::PresentModeKHR::eFifo;
if (supports_relaxed)
present_mode = vk::PresentModeKHR::eFifoRelaxed;
if (!vsync) { if (!vsync) {
if (supports_mailbox) if (supports_mailbox)
present_mode = vk::PresentModeKHR::eMailbox; present_mode = vk::PresentModeKHR::eMailbox;
if (supports_immediate) if (supports_immediate)
present_mode = vk::PresentModeKHR::eImmediate; present_mode = vk::PresentModeKHR::eImmediate;
} }
return present_mode; return present_mode;
} }

View File

@ -27,8 +27,7 @@ class Swapchain
void end_frame_without_swap(); void end_frame_without_swap();
bool swap(); bool swap();
void wait_on_frames(); void wait_on_frames();
// Returns true if vsync setting was changed, false if it was the same void set_vsync(bool on);
bool set_vsync(bool on);
void on_render_pass_end(std::function<void()> function); void on_render_pass_end(std::function<void()> function);
int get_num_frames() { return num_swapchain_images; } int get_num_frames() { return num_swapchain_images; }
vk::PresentModeKHR get_present_mode(); vk::PresentModeKHR get_present_mode();

View File

@ -70,6 +70,8 @@ bool CVulkan::Initialize(HWND hWnd)
return false; return false;
} }
context->swapchain->set_vsync(GUI.Vsync);
if (!Settings.AutoDisplayMessages) if (!Settings.AutoDisplayMessages)
{ {
Settings.DisplayIndicators = true; Settings.DisplayIndicators = true;
@ -91,11 +93,6 @@ bool CVulkan::Initialize(HWND hWnd)
} }
} }
if (context->swapchain->set_vsync(GUI.Vsync))
{
context->recreate_swapchain();
}
simple_output = std::make_unique<Vulkan::SimpleOutput>(context.get(), vk::Format::eR5G6B5UnormPack16); simple_output = std::make_unique<Vulkan::SimpleOutput>(context.get(), vk::Format::eR5G6B5UnormPack16);
return true; return true;
@ -181,8 +178,6 @@ bool CVulkan::ChangeRenderSize(unsigned int newWidth, unsigned int newHeight)
if (!context) if (!context)
return false; return false;
bool vsync_changed = context->swapchain->set_vsync(GUI.Vsync);
if (newWidth != current_width || newHeight != current_height || vsync_changed) if (newWidth != current_width || newHeight != current_height || vsync_changed)
{ {
context->recreate_swapchain(newWidth, newHeight); context->recreate_swapchain(newWidth, newHeight);
@ -218,10 +213,7 @@ bool CVulkan::ApplyDisplayChanges(void)
current_shadername = shadername; current_shadername = shadername;
} }
if (context->swapchain->set_vsync(GUI.Vsync)) context->swapchain->set_vsync(GUI.Vsync);
{
context->recreate_swapchain();
}
return true; return true;
} }