diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 65391be14f..fb1218224b 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -189,6 +189,9 @@ protected: bool fboTexNeedsBind_ = false; bool fboTexBound_ = false; + // Sometimes, unusual situations mean we need to reset dirty flags after state calc finishes. + uint64_t dirtyRequiresRecheck_ = 0; + // Hardware tessellation TessellationDataTransfer *tessDataTransfer; }; diff --git a/GPU/Common/GPUStateUtils.h b/GPU/Common/GPUStateUtils.h index a6c751739e..1bdd7cce5b 100644 --- a/GPU/Common/GPUStateUtils.h +++ b/GPU/Common/GPUStateUtils.h @@ -202,25 +202,40 @@ void ConvertStencilFuncState(GenericStencilFuncState &stencilFuncState); // See issue #15898 inline bool SpongebobDepthInverseConditions(const GenericStencilFuncState &stencilState) { - // Check that the depth/stencil state matches the conditions exactly - return gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && - gstate.getDepthTestFunction() == GE_COMP_GEQUAL && - stencilState.zFail == GE_STENCILOP_ZERO && stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP && - stencilState.testFunc == GE_COMP_ALWAYS && stencilState.writeMask == 0xFF && - // And also verify no color is written. The game does this through simple alpha blending with a constant zero alpha. - // We also check for color mask, since it's more natural, in case another game does it. - ((gstate.isAlphaBlendEnabled() && - !gstate.isTextureMapEnabled() && - gstate.getBlendFuncA() == GE_SRCBLEND_SRCALPHA && - gstate.getBlendFuncB() == GE_DSTBLEND_INVSRCALPHA && - ( - ( // Spongebob - gstate.getMaterialAmbientA() == 0x0 && // our accessor is kinda misnamed here, but material diffuse A is both used as default color and as ambient alpha - gstate.getMaterialUpdate() == 0 - ) || - ( // MX vs ATV : Reflex - gstate.getMaterialUpdate() == 1 // Really should also check vertex data, since that's where the zero is :( - ) - ) - ) || gstate.getColorMask() == 0xFFFFFF00); // note that PSP masks are "inverted" + // Check that the depth/stencil state matches the conditions exactly. + // Always with a depth test that's not writing to the depth buffer (only stencil.) + if (!gstate.isDepthTestEnabled() || gstate.isDepthWriteEnabled()) + return false; + // Always GREATER_EQUAL, which we flip to LESS. + if (gstate.getDepthTestFunction() != GE_COMP_GEQUAL) + return false; + + // The whole purpose here is a depth fail that we need to write to alpha. + if (stencilState.zFail != GE_STENCILOP_ZERO || stencilState.sFail != GE_STENCILOP_KEEP || stencilState.zPass != GE_STENCILOP_KEEP) + return false; + if (stencilState.testFunc != GE_COMP_ALWAYS || stencilState.writeMask != 0xFF) + return false; + + // Lastly, verify no color is written. Natural way is a mask, in case another game uses it. + // Note that the PSP masks are reversed compared to typical APIs. + if (gstate.getColorMask() == 0xFFFFFF00) + return true; + + // These games specifically use simple alpha blending with a constant zero alpha. + if (!gstate.isAlphaBlendEnabled() || gstate.getBlendFuncA() != GE_SRCBLEND_SRCALPHA || gstate.getBlendFuncB() != GE_DSTBLEND_INVSRCALPHA) + return false; + + // Also make sure there's no texture, in case its alpha gets involved. + if (gstate.isTextureMapEnabled()) + return false; + + // Spongebob uses material alpha. + if (gstate.getMaterialAmbientA() == 0x00 && gstate.getMaterialUpdate() == 0) + return true; + // MX vs ATV : Reflex uses vertex colors, should really check them... + if (gstate.getMaterialUpdate() == 1) + return true; + + // Okay, color is most likely being used if we didn't hit the above. + return false; } diff --git a/GPU/Common/TextureShaderCommon.cpp b/GPU/Common/TextureShaderCommon.cpp index 2584dc595b..79417a482e 100644 --- a/GPU/Common/TextureShaderCommon.cpp +++ b/GPU/Common/TextureShaderCommon.cpp @@ -191,7 +191,7 @@ Draw2DPipeline *TextureShaderCache::GetDepalettizeShader(uint32_t clutMode, GETe using namespace Draw; // Generate an ID for depal shaders. - u64 id = (depthUpperBits << 32) | (clutMode & 0xFFFFFF) | (textureFormat << 24) | (bufferFormat << 28); + u64 id = ((u64)depthUpperBits << 32) | (clutMode & 0xFFFFFF) | (textureFormat << 24) | (bufferFormat << 28); auto shader = depalCache_.find(id); if (shader != depalCache_.end()) { diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index b75edef5d5..561ea414b3 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -174,12 +174,15 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyDrawState"); // Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects. + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE; gstate_c.Dirty(DIRTY_BLEND_STATE); } + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } else if (blendState.resetFramebufferRead) { ResetFramebufferRead(); + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } @@ -193,6 +196,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { keys_.blend.destColor = d3d11BlendFactorLookup[(size_t)blendState.dstColor]; keys_.blend.destAlpha = d3d11BlendFactorLookup[(size_t)blendState.dstAlpha]; if (blendState.dirtyShaderBlendFixValues) { + dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND; gstate_c.Dirty(DIRTY_SHADERBLEND); } dynState_.useBlendColor = blendState.useBlendColor; @@ -315,8 +319,8 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { keys_.depthStencil.stencilFailOp = D3D11_STENCIL_OP_ZERO; keys_.depthStencil.stencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - // TODO: Need to set in a way that carries over to the next draw.. - gstate_c.Dirty(DIRTY_BLEND_STATE); + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE; + gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); } } else { keys_.depthStencil.stencilTestEnable = false; @@ -464,8 +468,6 @@ void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRe context_->OMSetDepthStencilState(depthStencilState_, applyStencilRef ? stencilRef : dynState_.stencilRef); } gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE); - - // Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects. - if (fboTexBound_) - gstate_c.Dirty(DIRTY_BLEND_STATE); + gstate_c.Dirty(dirtyRequiresRecheck_); + dirtyRequiresRecheck_ = 0; } diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index a82ccb4605..1e4d1d348c 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -153,9 +153,11 @@ void DrawEngineDX9::ApplyDrawState(int prim) { device_->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); fboTexBound_ = true; fboTexNeedsBind_ = false; + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE; gstate_c.Dirty(DIRTY_BLEND_STATE); } + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } else if (blendState.resetFramebufferRead) { ResetFramebufferRead(); @@ -169,6 +171,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) { dxBlendFactorLookup[(size_t)blendState.srcColor], dxBlendFactorLookup[(size_t)blendState.dstColor], dxBlendFactorLookup[(size_t)blendState.srcAlpha], dxBlendFactorLookup[(size_t)blendState.dstAlpha]); if (blendState.dirtyShaderBlendFixValues) { + dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND; gstate_c.Dirty(DIRTY_SHADERBLEND); } if (blendState.useBlendColor) { @@ -262,8 +265,8 @@ void DrawEngineDX9::ApplyDrawState(int prim) { // Invert dxstate.stencilOp.set(D3DSTENCILOP_ZERO, D3DSTENCILOP_KEEP, D3DSTENCILOP_ZERO); - // TODO: Need to set in a way that carries over to the next draw.. - gstate_c.Dirty(DIRTY_BLEND_STATE); + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE; + gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); } } else { dxstate.stencilTest.disable(); @@ -289,6 +292,8 @@ void DrawEngineDX9::ApplyDrawState(int prim) { } gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE); + gstate_c.Dirty(dirtyRequiresRecheck_); + dirtyRequiresRecheck_ = 0; } void DrawEngineDX9::ApplyDrawStateLate() { diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index a06bac650c..5f9fe9d135 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -141,6 +141,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) { // Start profiling here to skip SetTexture which is already accounted for PROFILE_THIS_SCOPE("applydrawstate"); + uint64_t dirtyRequiresRecheck_ = 0; bool useBufferedRendering = framebufferManager_->UseBufferedRendering(); if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) { @@ -177,17 +178,21 @@ void DrawEngineGLES::ApplyDrawState(int prim) { framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyDrawState"); // Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects. + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE; gstate_c.Dirty(DIRTY_BLEND_STATE); } + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } else if (blendState.resetFramebufferRead) { ResetFramebufferRead(); + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } if (blendState.enabled) { if (blendState.dirtyShaderBlendFixValues) { // Not quite sure how necessary this is. + dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND; gstate_c.Dirty(DIRTY_SHADERBLEND); } if (blendState.useBlendColor) { @@ -269,8 +274,8 @@ void DrawEngineGLES::ApplyDrawState(int prim) { renderManager->SetStencilFunc(true, GL_ALWAYS, 0xFF, 0xFF); renderManager->SetStencilOp(0xFF, GL_ZERO, GL_KEEP, GL_ZERO); - // TODO: Need to set in a way that carries over to the next draw.. - gstate_c.Dirty(DIRTY_BLEND_STATE); + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE; + gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); } } else { renderManager->SetStencilDisabled(); @@ -293,6 +298,8 @@ void DrawEngineGLES::ApplyDrawState(int prim) { } gstate_c.Clean(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_BLEND_STATE); + gstate_c.Dirty(dirtyRequiresRecheck_); + dirtyRequiresRecheck_ = 0; } void DrawEngineGLES::ApplyDrawStateLate(bool setStencilValue, int stencilValue) { diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 7cbaba3ca6..37243cac85 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -796,11 +796,9 @@ void DrawEngineVulkan::DoFlush() { } ApplyDrawStateLate(renderManager, false, 0, pipeline->UsesBlendConstant()); gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); + gstate_c.Dirty(dirtyRequiresRecheck_); + dirtyRequiresRecheck_ = 0; lastPipeline_ = pipeline; - - // Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects. - if (fboTexBound_) - gstate_c.Dirty(DIRTY_BLEND_STATE); } lastPrim_ = prim; @@ -928,11 +926,9 @@ void DrawEngineVulkan::DoFlush() { } ApplyDrawStateLate(renderManager, result.setStencil, result.stencilValue, pipeline->UsesBlendConstant()); gstate_c.Clean(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); + gstate_c.Dirty(dirtyRequiresRecheck_); + dirtyRequiresRecheck_ = 0; lastPipeline_ = pipeline; - - // Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects. - if (fboTexBound_) - gstate_c.Dirty(DIRTY_BLEND_STATE); } lastPrim_ = prim; diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 9ca4a81b9d..ac51debc6a 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -173,9 +173,11 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag ApplyFramebufferRead(&fboTexNeedsBind_); // The shader takes over the responsibility for blending, so recompute. ApplyStencilReplaceAndLogicOpIgnoreBlend(blendState.replaceAlphaWithStencil, blendState); + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } else if (blendState.resetFramebufferRead) { ResetFramebufferRead(); + dirtyRequiresRecheck_ |= DIRTY_FRAGMENTSHADER_STATE; gstate_c.Dirty(DIRTY_FRAGMENTSHADER_STATE); } @@ -188,6 +190,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag key.destColor = vkBlendFactorLookup[(size_t)blendState.dstColor]; key.destAlpha = vkBlendFactorLookup[(size_t)blendState.dstAlpha]; if (blendState.dirtyShaderBlendFixValues) { + dirtyRequiresRecheck_ |= DIRTY_SHADERBLEND; gstate_c.Dirty(DIRTY_SHADERBLEND); } dynState.useBlendColor = blendState.useBlendColor; @@ -322,8 +325,8 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag key.stencilFailOp = VK_STENCIL_OP_ZERO; key.stencilDepthFailOp = VK_STENCIL_OP_KEEP; - // TODO: Need to set in a way that carries over to the next draw.. - gstate_c.Dirty(DIRTY_BLEND_STATE); + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE; + gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); } } else { key.stencilTestEnable = false; @@ -375,6 +378,9 @@ void DrawEngineVulkan::BindShaderBlendTex() { boundSecondary_ = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE1_IMAGEVIEW); fboTexBound_ = true; fboTexNeedsBind_ = false; + + // Must dirty blend state here so we re-copy next time. Example: Lunar's spell effects. + dirtyRequiresRecheck_ |= DIRTY_BLEND_STATE; } } } diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index acc0347fd1..1b38c93093 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -1,3 +1,4 @@ +#include #include #include "UI/OnScreenDisplay.h"