diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index c6fcfd7007..f168fa1920 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -136,6 +136,15 @@ bool IsColorTestTriviallyTrue() { } } +bool IsDepthTestEffectivelyDisabled() { + if (!gstate.isDepthTestEnabled()) + return true; + // We can ignore stencil, because ALWAYS and disabled choose the same stencil path. + if (gstate.getDepthTestFunction() != GE_COMP_ALWAYS) + return false; + return !gstate.isDepthWriteEnabled(); +} + const bool nonAlphaSrcFactors[16] = { true, // GE_SRCBLEND_DSTCOLOR, true, // GE_SRCBLEND_INVDSTCOLOR, diff --git a/GPU/Common/GPUStateUtils.h b/GPU/Common/GPUStateUtils.h index 038091f7d8..ab524f6c3f 100644 --- a/GPU/Common/GPUStateUtils.h +++ b/GPU/Common/GPUStateUtils.h @@ -56,6 +56,7 @@ bool IsColorTestAgainstZero(); bool IsColorTestTriviallyTrue(); bool IsAlphaTestAgainstZero(); bool NeedsTestDiscard(); +bool IsDepthTestEffectivelyDisabled(); bool IsStencilTestOutputDisabled(); StencilValueType ReplaceAlphaWithStencilType(); diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index c840265540..2174da2ce9 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -270,7 +270,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { } else { keys_.depthStencil.value = 0; // Depth Test - if (gstate.isDepthTestEnabled()) { + if (!IsDepthTestEffectivelyDisabled()) { keys_.depthStencil.depthTestEnable = true; keys_.depthStencil.depthCompareOp = compareOps[gstate.getDepthTestFunction()]; keys_.depthStencil.depthWriteEnable = gstate.isDepthWriteEnabled(); diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index b6918027f8..4517150daf 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -228,7 +228,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) { } } else { // Depth Test - if (gstate.isDepthTestEnabled()) { + if (!IsDepthTestEffectivelyDisabled()) { dxstate.depthTest.enable(); dxstate.depthFunc.set(ztests[gstate.getDepthTestFunction()]); dxstate.depthWrite.set(gstate.isDepthWriteEnabled()); diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index 0330cdf9f6..1d06ac01e4 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -253,8 +253,9 @@ void DrawEngineGLES::ApplyDrawState(int prim) { renderManager->SetDepth(true, gstate.isClearModeDepthMask() ? true : false, GL_ALWAYS); } else { // Depth Test - renderManager->SetDepth(gstate.isDepthTestEnabled(), gstate.isDepthWriteEnabled(), compareOps[gstate.getDepthTestFunction()]); - if (gstate.isDepthTestEnabled()) + bool depthTestUsed = !IsDepthTestEffectivelyDisabled(); + renderManager->SetDepth(depthTestUsed, gstate.isDepthWriteEnabled(), compareOps[gstate.getDepthTestFunction()]); + if (depthTestUsed) UpdateEverUsedEqualDepth(gstate.getDepthTestFunction()); // Stencil Test diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 7c23c67126..5f75ea2863 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -274,7 +274,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag } } else { // Depth Test - if (gstate.isDepthTestEnabled()) { + if (!IsDepthTestEffectivelyDisabled()) { key.depthTestEnable = true; key.depthCompareOp = compareOps[gstate.getDepthTestFunction()]; key.depthWriteEnable = gstate.isDepthWriteEnabled();