softgpu: Optimize > non-zero alpha tests as well.

These are fairly common, especially in 3D games.
This commit is contained in:
Unknown W. Brackets 2022-12-03 12:55:38 -08:00
parent eb19e24399
commit 00e76b11b6
2 changed files with 16 additions and 8 deletions

View File

@ -312,12 +312,17 @@ static RasterizerStateFlags DetectStateOptimizations(RasterizerState *state) {
bool usesClut = (samplerID.texfmt & 4) != 0;
if (usesClut && alphaFull && samplerID.useTextureAlpha) {
bool alphaTest = pixelID.AlphaTestFunc() == GE_COMP_NOTEQUAL && pixelID.alphaTestRef == 0 && !state->pixelID.hasAlphaTestMask;
if (state->flags & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF)
alphaTest = true;
GEComparison alphaTestFunc = pixelID.AlphaTestFunc();
// We optimize > 0 to != 0, so this is especially common.
if (state->flags & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_NE)
alphaTestFunc = GE_COMP_NOTEQUAL;
// > 16, 8, or similar are also very common.
if (state->flags & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_GT)
alphaTestFunc = GE_COMP_GREATER;
bool alphaTest = (alphaTestFunc == GE_COMP_NOTEQUAL || alphaTestFunc == GE_COMP_GREATER) && pixelID.alphaTestRef < 0xFF && !state->pixelID.hasAlphaTestMask;
if (alphaTest && CheckClutAlphaFull(state))
optimize |= RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF;
optimize |= alphaTestFunc == GE_COMP_NOTEQUAL ? RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_NE : RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_GT;
}
}
@ -348,10 +353,12 @@ static bool ApplyStateOptimizations(RasterizerState *state, const RasterizerStat
pixelID.applyFog = false;
else if (state->flags & RasterizerStateFlags::OPTIMIZED_FOG_OFF)
pixelID.applyFog = true;
if (optimize & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF)
if (optimize & (RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_NE | RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_GT))
pixelID.alphaTestFunc = GE_COMP_ALWAYS;
else if (state->flags & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF)
else if (state->flags & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_NE)
pixelID.alphaTestFunc = GE_COMP_NOTEQUAL;
else if (state->flags & RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_GT)
pixelID.alphaTestFunc = GE_COMP_GREATER;
SingleFunc drawPixel = Rasterizer::GetSingleFunc(pixelID, nullptr);
// Can't compile during runtime. This failing is a bit of a problem when undoing...

View File

@ -51,10 +51,11 @@ enum class RasterizerStateFlags {
OPTIMIZED_BLEND_OFF = 0x0008'0000,
OPTIMIZED_TEXREPLACE = 0x0010'0000,
OPTIMIZED_FOG_OFF = 0x0020'0000,
OPTIMIZED_ALPHATEST_OFF = 0x0040'0000,
OPTIMIZED_ALPHATEST_OFF_NE = 0x0040'0000,
OPTIMIZED_ALPHATEST_OFF_GT = 0x0080'0000,
// Anything that changes the actual pixel or sampler func.
OPTIMIZED_PIXELID = OPTIMIZED_BLEND_SRC | OPTIMIZED_BLEND_DST | OPTIMIZED_BLEND_OFF | OPTIMIZED_FOG_OFF | RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF,
OPTIMIZED_PIXELID = OPTIMIZED_BLEND_SRC | OPTIMIZED_BLEND_DST | OPTIMIZED_BLEND_OFF | OPTIMIZED_FOG_OFF | RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_NE | RasterizerStateFlags::OPTIMIZED_ALPHATEST_OFF_GT,
OPTIMIZED_SAMPLERID = OPTIMIZED_TEXREPLACE,
INVALID = 0x7FFFFFFF,