From a605366254a5ff7e3c4807de183b05d73fcabd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 13 Oct 2022 22:35:23 +0200 Subject: [PATCH] Add ShaderId utility function to be used for some sanity checking. --- GPU/Common/ShaderId.cpp | 12 +++++++++--- GPU/Common/ShaderId.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/GPU/Common/ShaderId.cpp b/GPU/Common/ShaderId.cpp index 94ade2fd26..43fcbab8ab 100644 --- a/GPU/Common/ShaderId.cpp +++ b/GPU/Common/ShaderId.cpp @@ -255,6 +255,12 @@ std::string FragmentShaderDesc(const FShaderID &id) { return desc.str(); } +bool FragmentIdNeedsFramebufferRead(const FShaderID &id) { + return id.Bit(FS_BIT_COLOR_WRITEMASK) || + id.Bits(FS_BIT_REPLACE_LOGIC_OP, 4) != GE_LOGIC_COPY || + (ReplaceBlendType)id.Bits(FS_BIT_REPLACE_BLEND, 3) == REPLACE_BLEND_READ_FRAMEBUFFER; +} + // Here we must take all the bits of the gstate that determine what the fragment shader will // look like, and concatenate them together into an ID. void ComputeFragmentShaderID(FShaderID *id_out, const ComputedPipelineState &pipelineState, const Draw::Bugs &bugs) { @@ -276,12 +282,12 @@ void ComputeFragmentShaderID(FShaderID *id_out, const ComputedPipelineState &pip ShaderDepalMode shaderDepalMode = gstate_c.shaderDepalMode; bool colorWriteMask = pipelineState.maskState.applyFramebufferRead; - ReplaceBlendType replaceBlend = pipelineState.blendState.replaceBlend; - ReplaceAlphaType stencilToAlpha = pipelineState.blendState.replaceAlphaWithStencil; - SimulateLogicOpType simulateLogicOpType = pipelineState.blendState.simulateLogicOpType; GELogicOp replaceLogicOpType = pipelineState.logicState.applyFramebufferRead ? pipelineState.logicState.logicOp : GE_LOGIC_COPY; + SimulateLogicOpType simulateLogicOpType = pipelineState.blendState.simulateLogicOpType; + ReplaceAlphaType stencilToAlpha = pipelineState.blendState.replaceAlphaWithStencil; + // All texfuncs except replace are the same for RGB as for RGBA with full alpha. // Note that checking this means that we must dirty the fragment shader ID whenever textureFullAlpha changes. if (gstate_c.textureFullAlpha && gstate.getTextureFunction() != GE_TEXFUNC_REPLACE) { diff --git a/GPU/Common/ShaderId.h b/GPU/Common/ShaderId.h index 560b8a873a..2edf271b6d 100644 --- a/GPU/Common/ShaderId.h +++ b/GPU/Common/ShaderId.h @@ -284,3 +284,6 @@ std::string FragmentShaderDesc(const FShaderID &id); void ComputeGeometryShaderID(GShaderID *id, const Draw::Bugs &bugs, int prim); std::string GeometryShaderDesc(const GShaderID &id); + +// For sanity checking. +bool FragmentIdNeedsFramebufferRead(const FShaderID &id);