From 11f08c7dea591079e588d1f1c9cb7cbf3f8eb777 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 22 Jan 2020 23:58:36 +0100 Subject: [PATCH] [dxbc] Declare vertex positions as invariant Otherwise, games relying on different vertex shaders to produce the same numerical results may suffer from Z-fighting issues. Fixes #1364. --- src/dxbc/dxbc_compiler.cpp | 5 +++++ src/dxbc/dxbc_options.cpp | 4 ++++ src/dxbc/dxbc_options.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index d0608436..555ffa1c 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -740,6 +740,11 @@ namespace dxvk { // Add index decoration for potential dual-source blending if (m_programInfo.type() == DxbcProgramType::PixelShader) m_module.decorateIndex(varId, 0); + + // Declare vertex positions in all stages as invariant, even if + // this is not the last stage, to help with potential Z fighting. + if (sv == DxbcSystemValue::Position && m_moduleInfo.options.invariantPosition) + m_module.decorate(varId, spv::DecorationInvariant); } m_oRegs.at(regIdx) = { regType, varId }; diff --git a/src/dxbc/dxbc_options.cpp b/src/dxbc/dxbc_options.cpp index e60f20bf..fdcb7a37 100644 --- a/src/dxbc/dxbc_options.cpp +++ b/src/dxbc/dxbc_options.cpp @@ -41,6 +41,10 @@ namespace dxvk { zeroInitWorkgroupMemory = options.zeroInitWorkgroupMemory; dynamicIndexedConstantBufferAsSsbo = options.constantBufferRangeCheck; + // Don't declare vertex positions as invariant on Nvidia since it + // may break certain games, such as Shadow of the Tomb Raider. + invariantPosition = !adapter->matchesDriver(DxvkGpuVendor::Nvidia, VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR, 0, 0); + // Disable early discard on RADV (with LLVM) due to GPU hangs // Disable early discard on Nvidia because it may hurt performance bool isRadvAco = std::string(devInfo.core.properties.deviceName).find("RADV/ACO") != std::string::npos; diff --git a/src/dxbc/dxbc_options.h b/src/dxbc/dxbc_options.h index 4fb78140..a94a3a4a 100644 --- a/src/dxbc/dxbc_options.h +++ b/src/dxbc/dxbc_options.h @@ -42,6 +42,9 @@ namespace dxvk { /// Clear thread-group shared memory to zero bool zeroInitWorkgroupMemory = false; + /// Declare vertex positions as invariant + bool invariantPosition = false; + /// Minimum storage buffer alignment VkDeviceSize minSsboAlignment = 0; };