diff --git a/GPU/Common/GPUStateUtils.h b/GPU/Common/GPUStateUtils.h index 41ee3adc73..1224a68b7d 100644 --- a/GPU/Common/GPUStateUtils.h +++ b/GPU/Common/GPUStateUtils.h @@ -4,6 +4,7 @@ #include "Common/CommonTypes.h" #include "GPU/ge_constants.h" +#include "GPU/GPUState.h" // TODO: Replace enums and structs with same from thin3d.h, for convenient mapping. @@ -198,3 +199,13 @@ struct GenericStencilFuncState { }; void ConvertStencilFuncState(GenericStencilFuncState &stencilFuncState); + +// See issue #15898 +inline bool SpongebobDepthInverseConditions(const GenericStencilFuncState &stencilState) { + return gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO && + stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP && + stencilState.testFunc == GE_COMP_ALWAYS && + stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF && + // Also verify no color is written. + true; +} diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index 873328879a..b75edef5d5 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -297,10 +297,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { // Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during // depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth // test and modify the alpha function... - if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO && - stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP && - stencilState.testFunc == GE_COMP_ALWAYS && - stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) { + if (SpongebobDepthInverseConditions(stencilState)) { keys_.blend.blendEnable = true; keys_.blend.blendOpAlpha = D3D11_BLEND_OP_ADD; keys_.blend.blendOpColor = D3D11_BLEND_OP_ADD; diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index ad144562b6..a82ccb4605 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -251,11 +251,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) { // Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during // depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth // test and modify the alpha function... - if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO && - stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP && - stencilState.testFunc == GE_COMP_ALWAYS && - stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) { - + if (SpongebobDepthInverseConditions(stencilState)) { dxstate.blend.set(true); dxstate.blendEquation.set(D3DBLENDOP_ADD, D3DBLENDOP_ADD); dxstate.blendFunc.set(D3DBLEND_ZERO, D3DBLEND_ZERO, D3DBLEND_ZERO, D3DBLEND_ZERO); diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index a5dc125f5a..a06bac650c 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -263,11 +263,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) { // Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during // depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth // test and modify the alpha function... - if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO && - stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP && - stencilState.testFunc == GE_COMP_ALWAYS && - stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) { - + if (SpongebobDepthInverseConditions(stencilState)) { renderManager->SetBlendAndMask(0x8, true, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_FUNC_ADD, GL_FUNC_ADD); renderManager->SetDepth(true, false, GL_LESS); renderManager->SetStencilFunc(true, GL_ALWAYS, 0xFF, 0xFF); diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 10f3e377b2..9ca4a81b9d 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -305,10 +305,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag // Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during // depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth // test and modify the alpha function... - if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO && - stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP && - stencilState.testFunc == GE_COMP_ALWAYS && - stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) { + if (SpongebobDepthInverseConditions(stencilState)) { key.blendEnable = true; key.blendOpAlpha = VK_BLEND_OP_ADD; key.blendOpColor = VK_BLEND_OP_ADD;