From 1eeb4f0bcfa3b52cd7e86e4f70c6607150971aa1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 24 Sep 2022 18:04:23 -0700 Subject: [PATCH] softpu: Refactor out 5551 fast path checks. They were duplicated, and better to organize them according to state. --- GPU/Software/RasterizerRectangle.cpp | 92 +++++++++++++--------------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index 35a665d5a0..0322ae185f 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -49,6 +49,47 @@ inline void DrawSinglePixel5551(u16 *pixel, const u32 color_in, const PixelFuncI *pixel = RGBA8888ToRGBA5551(new_color); } +// Check if we can safely ignore the alpha test, assuming standard alpha blending. +static inline bool AlphaTestIsNeedless(const PixelFuncID &pixelID) { + switch (pixelID.AlphaTestFunc()) { + case GE_COMP_NEVER: + case GE_COMP_EQUAL: + case GE_COMP_LESS: + case GE_COMP_LEQUAL: + return false; + + case GE_COMP_ALWAYS: + return true; + + case GE_COMP_NOTEQUAL: + case GE_COMP_GREATER: + case GE_COMP_GEQUAL: + if (pixelID.alphaTestRef != 0 || pixelID.hasAlphaTestMask) + return false; + return true; + } + + return false; +} + +bool UseDrawSinglePixel5551(const PixelFuncID &pixelID) { + if (pixelID.clearMode || pixelID.colorTest || pixelID.stencilTest) + return false; + if (!AlphaTestIsNeedless(pixelID) || pixelID.DepthTestFunc() != GE_COMP_ALWAYS) + return false; + if (pixelID.FBFormat() != GE_FORMAT_5551 || !pixelID.alphaBlend) + return false; + // We skip blending when alpha = FF, so we can't allow other blend modes. + if (pixelID.AlphaBlendEq() != GE_BLENDMODE_MUL_AND_ADD || pixelID.AlphaBlendSrc() != PixelBlendFactor::SRCALPHA) + return false; + if (pixelID.AlphaBlendDst() != PixelBlendFactor::INVSRCALPHA) + return false; + if (pixelID.dithering || pixelID.applyLogicOp || pixelID.applyColorWriteMask) + return false; + + return true; +} + static inline Vec4IntResult SOFTRAST_CALL ModulateRGBA(Vec4IntArg prim_in, Vec4IntArg texcolor_in, const SamplerID &samplerID) { Vec4 out; Vec4 prim_color = prim_in; @@ -79,29 +120,6 @@ static inline Vec4IntResult SOFTRAST_CALL ModulateRGBA(Vec4IntArg prim_in, Vec4I return ToVec4IntResult(out); } -// Check if we can safely ignore the alpha test, assuming standard alpha blending. -static inline bool AlphaTestIsNeedless(const PixelFuncID &pixelID) { - switch (pixelID.AlphaTestFunc()) { - case GE_COMP_NEVER: - case GE_COMP_EQUAL: - case GE_COMP_LESS: - case GE_COMP_LEQUAL: - return false; - - case GE_COMP_ALWAYS: - return true; - - case GE_COMP_NOTEQUAL: - case GE_COMP_GREATER: - case GE_COMP_GEQUAL: - if (pixelID.alphaTestRef != 0 || pixelID.hasAlphaTestMask) - return false; - return true; - } - - return false; -} - void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state) { const u8 *texptr = state.texptr[0]; @@ -155,20 +173,7 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran pos0.y = scissorTL.y; } - if (!pixelID.stencilTest && - pixelID.DepthTestFunc() == GE_COMP_ALWAYS && - !pixelID.applyLogicOp && - !pixelID.colorTest && - !pixelID.dithering && - pixelID.alphaBlend && - pixelID.AlphaBlendEq() == GE_BLENDMODE_MUL_AND_ADD && - pixelID.AlphaBlendSrc() == PixelBlendFactor::SRCALPHA && - pixelID.AlphaBlendDst() == PixelBlendFactor::INVSRCALPHA && - AlphaTestIsNeedless(pixelID) && - samplerID.useTextureAlpha && - samplerID.TexFunc() == GE_TEXFUNC_MODULATE && - !pixelID.applyColorWriteMask && - pixelID.FBFormat() == GE_FORMAT_5551) { + if (UseDrawSinglePixel5551(pixelID) && samplerID.TexFunc() == GE_TEXFUNC_MODULATE && samplerID.useTextureAlpha) { if (isWhite) { int t = t_start; for (int y = pos0.y; y < pos1.y; y++) { @@ -246,18 +251,7 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran if (pos1.y > scissorBR.y) pos1.y = scissorBR.y + 1; if (pos0.x < scissorTL.x) pos0.x = scissorTL.x; if (pos0.y < scissorTL.y) pos0.y = scissorTL.y; - if (!pixelID.stencilTest && - pixelID.DepthTestFunc() == GE_COMP_ALWAYS && - !pixelID.applyLogicOp && - !pixelID.colorTest && - !pixelID.dithering && - pixelID.alphaBlend && - pixelID.AlphaBlendEq() == GE_BLENDMODE_MUL_AND_ADD && - pixelID.AlphaBlendSrc() == PixelBlendFactor::SRCALPHA && - pixelID.AlphaBlendDst() == PixelBlendFactor::INVSRCALPHA && - AlphaTestIsNeedless(pixelID) && - !pixelID.applyColorWriteMask && - pixelID.FBFormat() == GE_FORMAT_5551) { + if (UseDrawSinglePixel5551(pixelID)) { if (Vec4::FromRGBA(v1.color0).a() == 0) return;