Allow AMD proprietary drivers to disable vsync

The original logic for presentation was done before the vsync toggle in graphics > advanced was added, afaik.
NVIDIA drivers can run games at framerates higher than the display's refresh rate while in mailbox (triple buffer) mode, but AMD proprietary drivers get locked to the refresh rate of the display.
While having tearing is undesired, Smash players use high framerate mods to reduce the hardcoded input delay of the game, and not everyone has access to >120 Hz monitors.
Letting 60 Hz AMD users have the choice between being able to use the 120 FPS mod with tearing, or stopping tearing and sticking to 60 FPS is a better option IMO.
This commit is contained in:
Matías Locatti
2023-02-18 06:15:04 -03:00
committed by GitHub
parent e91ff9b7bd
commit 89d4c84ec0

View File

@@ -33,21 +33,30 @@ VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats)
return found != formats.end() ? *found : formats[0];
}
VkPresentModeKHR ChooseSwapPresentMode(vk::Span<VkPresentModeKHR> modes) {
VkPresentModeKHR ChooseSwapPresentMode(vk::Span<VkPresentModeKHR> modes, VkDriverIdKHR driver_id) {
// Mailbox (triple buffering) doesn't lock the application like fifo (vsync),
// prefer it if vsync option is not selected
// prefer it if vsync option is not selected.
// FIFO present mode locks the framerate to the monitor's refresh rate,
// find an alternative to surpass this limitation if FPS is unlocked.
// AMD proprietary drivers can't render past the screen's refresh rate,
// immediate wil be enforced instead.
const auto found_mailbox = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_MAILBOX_KHR);
if (Settings::values.fullscreen_mode.GetValue() == Settings::FullscreenMode::Borderless &&
found_mailbox != modes.end() && !Settings::values.use_vsync.GetValue()) {
return VK_PRESENT_MODE_MAILBOX_KHR;
const auto found_imm = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_IMMEDIATE_KHR);
const bool is_amd = driver_id == VK_DRIVER_ID_AMD_PROPRIETARY_KHR;
if (!Settings::values.use_speed_limit.GetValue() && found_imm != modes.end()) {
return VK_PRESENT_MODE_IMMEDIATE_KHR;
}
if (!Settings::values.use_speed_limit.GetValue()) {
// FIFO present mode locks the framerate to the monitor's refresh rate,
// Find an alternative to surpass this limitation if FPS is unlocked.
const auto found_imm = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_IMMEDIATE_KHR);
if (found_imm != modes.end()) {
if (Settings::values.use_vsync.GetValue()) {
if (found_mailbox != modes.end()) {
return VK_PRESENT_MODE_MAILBOX_KHR;
}
} else {
if (is_amd && found_imm != modes.end()) {
return VK_PRESENT_MODE_IMMEDIATE_KHR;
}
if (found_mailbox != modes.end()) {
return VK_PRESENT_MODE_MAILBOX_KHR;
}
}
return VK_PRESENT_MODE_FIFO_KHR;
}