GPU: Avoid enabling depth test pointlessly.

See #16015.  Attempting to avoid a driver bug.
This commit is contained in:
Unknown W. Brackets 2022-11-07 20:40:14 -08:00
parent 855d16ffb3
commit 745d9ad320
6 changed files with 16 additions and 5 deletions

View File

@ -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,

View File

@ -56,6 +56,7 @@ bool IsColorTestAgainstZero();
bool IsColorTestTriviallyTrue();
bool IsAlphaTestAgainstZero();
bool NeedsTestDiscard();
bool IsDepthTestEffectivelyDisabled();
bool IsStencilTestOutputDisabled();
StencilValueType ReplaceAlphaWithStencilType();

View File

@ -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();

View File

@ -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());

View File

@ -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

View File

@ -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();