From 9b602ef850981071f4b8c4fa450b80142ba61bcc Mon Sep 17 00:00:00 2001 From: DadSchoorse <49841484+DadSchoorse@users.noreply.github.com> Date: Sat, 2 May 2020 10:18:13 +0200 Subject: [PATCH] [util] Rework tearFree as a Tristate PR #1606. --- dxvk.conf | 15 +++++++++++---- src/d3d11/d3d11_options.cpp | 2 +- src/d3d11/d3d11_options.h | 3 ++- src/d3d11/d3d11_swapchain.cpp | 5 +++-- src/d3d9/d3d9_options.cpp | 1 + src/d3d9/d3d9_options.h | 4 ++++ src/d3d9/d3d9_swapchain.cpp | 6 ++++-- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/dxvk.conf b/dxvk.conf index 025848d7..99f0d309 100644 --- a/dxvk.conf +++ b/dxvk.conf @@ -69,14 +69,21 @@ # d3d9.presentInterval = -1 -# Enables the mailbox present mode in case regular Vsync is disabled. +# True enables the mailbox present mode in case regular Vsync is disabled. # This should avoid tearing, but may be unsupported on some systems # or require setting dxgi.numBackBuffers to a higher value in order -# to work properly. Please do not report issues with this option. +# to work properly. # -# Supported values: True, False +# False enables the relaxed fifo present mode in case regular Vsync is enabled. +# This should result in tearing but reduce stutter if FPS are too low, +# but may be unsupported on some systems. +# +# Please do not report issues with this option. +# +# Supported values: Auto, True, False -# dxgi.tearFree = False +# dxgi.tearFree = Auto +# d3d9.tearFree = Auto # Performs range check on dynamically indexed constant buffers in shaders. diff --git a/src/d3d11/d3d11_options.cpp b/src/d3d11/d3d11_options.cpp index 2ae15276..f3310b42 100644 --- a/src/d3d11/d3d11_options.cpp +++ b/src/d3d11/d3d11_options.cpp @@ -19,7 +19,7 @@ namespace dxvk { this->numBackBuffers = config.getOption("dxgi.numBackBuffers", 0); this->maxFrameLatency = config.getOption("dxgi.maxFrameLatency", 0); this->syncInterval = config.getOption("dxgi.syncInterval", -1); - this->tearFree = config.getOption("dxgi.tearFree", false); + this->tearFree = config.getOption("dxgi.tearFree", Tristate::Auto); this->constantBufferRangeCheck = config.getOption("d3d11.constantBufferRangeCheck", false) && DxvkGpuVendor(devInfo.core.properties.vendorID) != DxvkGpuVendor::Amd; diff --git a/src/d3d11/d3d11_options.h b/src/d3d11/d3d11_options.h index 13f97b81..75ce54e4 100644 --- a/src/d3d11/d3d11_options.h +++ b/src/d3d11/d3d11_options.h @@ -73,7 +73,8 @@ namespace dxvk { int32_t syncInterval; /// Tear-free mode if vsync is disabled - bool tearFree; + /// Tearing mode if vsync is enabled + Tristate tearFree; /// Override maximum frame latency if the app specifies /// a higher value. May help with frame timing issues. diff --git a/src/d3d11/d3d11_swapchain.cpp b/src/d3d11/d3d11_swapchain.cpp index 9b3f39ad..9d1b9d6c 100644 --- a/src/d3d11/d3d11_swapchain.cpp +++ b/src/d3d11/d3d11_swapchain.cpp @@ -850,12 +850,13 @@ namespace dxvk { uint32_t n = 0; if (Vsync) { + if (m_parent->GetOptions()->tearFree == Tristate::False) + pDstModes[n++] = VK_PRESENT_MODE_FIFO_RELAXED_KHR; pDstModes[n++] = VK_PRESENT_MODE_FIFO_KHR; } else { - if (!m_parent->GetOptions()->tearFree) + if (m_parent->GetOptions()->tearFree != Tristate::True) pDstModes[n++] = VK_PRESENT_MODE_IMMEDIATE_KHR; pDstModes[n++] = VK_PRESENT_MODE_MAILBOX_KHR; - pDstModes[n++] = VK_PRESENT_MODE_FIFO_RELAXED_KHR; } return n; diff --git a/src/d3d9/d3d9_options.cpp b/src/d3d9/d3d9_options.cpp index 939f4f4b..4da9f936 100644 --- a/src/d3d9/d3d9_options.cpp +++ b/src/d3d9/d3d9_options.cpp @@ -70,6 +70,7 @@ namespace dxvk { this->allowDiscard = config.getOption ("d3d9.allowDiscard", true); this->enumerateByDisplays = config.getOption ("d3d9.enumerateByDisplays", true); this->longMad = config.getOption ("d3d9.longMad", false); + this->tearFree = config.getOption ("d3d9.tearFree", Tristate::Auto); // If we are not Nvidia, enable general hazards. this->generalHazards = adapter == nullptr || !adapter->matchesDriver(DxvkGpuVendor::Nvidia, VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR, 0, 0); diff --git a/src/d3d9/d3d9_options.h b/src/d3d9/d3d9_options.h index b5742f9c..5f36a9a4 100644 --- a/src/d3d9/d3d9_options.h +++ b/src/d3d9/d3d9_options.h @@ -143,6 +143,10 @@ namespace dxvk { /// This solves some rendering bugs in games that have z-pass shaders which /// don't match entirely to the regular vertex shader in this way. bool longMad; + + /// Tear-free mode if vsync is disabled + /// Tearing mode if vsync is enabled + Tristate tearFree; }; } \ No newline at end of file diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp index bc416cd8..ae10cae7 100644 --- a/src/d3d9/d3d9_swapchain.cpp +++ b/src/d3d9/d3d9_swapchain.cpp @@ -1362,11 +1362,13 @@ namespace dxvk { uint32_t n = 0; if (Vsync) { + if (m_parent->GetOptions()->tearFree == Tristate::False) + pDstModes[n++] = VK_PRESENT_MODE_FIFO_RELAXED_KHR; pDstModes[n++] = VK_PRESENT_MODE_FIFO_KHR; } else { - pDstModes[n++] = VK_PRESENT_MODE_IMMEDIATE_KHR; + if (m_parent->GetOptions()->tearFree != Tristate::True) + pDstModes[n++] = VK_PRESENT_MODE_IMMEDIATE_KHR; pDstModes[n++] = VK_PRESENT_MODE_MAILBOX_KHR; - pDstModes[n++] = VK_PRESENT_MODE_FIFO_RELAXED_KHR; } return n;