Add a conservative check that prevents alpha testing in a few cases.

This will become really powerful if we add some code to the vertex decoder
to check for non-full alpha in the vertices, and set gstate_c.vertexFullAlpha if none
is found (probably want to do the reverse, set it to true and clear if any non-255 alpha is found).

Alpha testing is a performance killer on many mobile GPUs so big efforts to
avoid it can be worth it.
This commit is contained in:
Henrik Rydgard 2014-03-23 16:29:11 +01:00
parent 20d480a374
commit b174996c1c
3 changed files with 20 additions and 2 deletions

View file

@ -71,12 +71,24 @@ static bool IsAlphaTestTriviallyTrue() {
case GE_COMP_NOTEQUAL:
case GE_COMP_GREATER:
{
return (!gstate.isStencilTestEnabled() &&
#if 0
// Easy way to check the values in the debugger without ruining && early-out
bool doTextureAlpha = gstate.isTextureAlphaUsed();
bool stencilTest = gstate.isStencilTestEnabled();
bool depthTest = gstate.isDepthTestEnabled();
GEComparison depthTestFunc = gstate.getDepthTestFunction();
int alphaRef = gstate.getAlphaTestRef();
int blendA = gstate.getBlendFuncA();
bool blendEnabled = gstate.isAlphaBlendEnabled();
int blendB = gstate.getBlendFuncA();
#endif
return (gstate_c.vertexFullAlpha && (gstate_c.textureFullAlpha || !gstate.isTextureAlphaUsed())) || (
(!gstate.isStencilTestEnabled() &&
!gstate.isDepthTestEnabled() &&
gstate.getAlphaTestRef() == 0 &&
gstate.isAlphaBlendEnabled() &&
gstate.getBlendFuncA() == GE_SRCBLEND_SRCALPHA &&
safeDestFactors[(int)gstate.getBlendFuncB()]);
safeDestFactors[(int)gstate.getBlendFuncB()]));
}
case GE_COMP_LEQUAL:

View file

@ -265,6 +265,11 @@ void TransformDrawEngine::SetupVertexDecoder(u32 vertType) {
if (vertTypeID != lastVType_) {
dec_ = GetVertexDecoder(vertTypeID);
lastVType_ = vertTypeID;
// TODO: Add functionality to VertexDecoder to scan for non-full alpha in the two other formats,
// which are quite common.
int colorType = vertTypeID & GE_VTYPE_COL_MASK;
gstate_c.vertexFullAlpha = colorType == GE_VTYPE_COL_NONE || colorType == GE_VTYPE_COL_565;
}
}

View file

@ -441,6 +441,7 @@ struct GPUStateCache
bool textureChanged;
bool textureFullAlpha;
bool vertexFullAlpha;
bool framebufChanged;
int skipDrawReason;