From a321aba68c8f79e9e79bddba56f90774faea26bd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 10 Aug 2022 23:11:16 -0700 Subject: [PATCH] GPU: Avoid stencil force pass when writing depth. There's a risk if the stencil test failed, it might cause a depth write unless it's also masked. Hunter x Hunter doesn't in this case. --- GPU/Common/GPUStateUtils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index 98f9f72b6a..e86c056c5a 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -1511,10 +1511,12 @@ void ConvertStencilFuncState(GenericStencilFuncState &state) { state.testRef = gstate.getStencilTestRef(); state.testMask = gstate.getStencilTestMask(); - if ((state.sFail == state.zFail || !gstate.isDepthTestEnabled()) && state.sFail == state.zPass) { + bool depthTest = gstate.isDepthTestEnabled(); + if ((state.sFail == state.zFail || !depthTest) && state.sFail == state.zPass) { // Common case: we're writing only to stencil (usually REPLACE/REPLACE/REPLACE.) // We want to write stencil to alpha in this case, so switch to ALWAYS if already masked. - if ((gstate.getColorMask() & 0x00FFFFFF) == 0x00FFFFFF) { + bool depthWrite = gstate.isDepthWriteEnabled(); + if ((gstate.getColorMask() & 0x00FFFFFF) == 0x00FFFFFF && (!depthTest || !depthWrite)) { state.testFunc = GE_COMP_ALWAYS; } }