From 33abbca464114925dc06f8238726e07cc0dec264 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 1 Dec 2022 23:13:20 -0800 Subject: [PATCH] softgpu: Optimize out texture proj for UVs. Seen in NFS Most Wanted 5-1-0. --- GPU/Software/Rasterizer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index 9677078805..18244fc105 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -132,7 +132,12 @@ void ComputeRasterizerState(RasterizerState *state, std::function flushF state->textureProj = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX; if (state->textureProj) { // We may be able to optimize this off. This is actually kinda common. - if (gstate.tgenMatrix[2] == 0.0f && gstate.tgenMatrix[5] == 0.0f && gstate.tgenMatrix[8] == 0.0f && gstate.tgenMatrix[11] == 1.0f) { + const bool qZeroST = gstate.tgenMatrix[2] == 0.0f && gstate.tgenMatrix[5] == 0.0f; + const bool qZeroQ = gstate.tgenMatrix[8] == 0.0f; + + // Two common cases: the source q factor is zero, OR source is UV. + const bool qFactorZero = gstate.getUVProjMode() == GE_PROJMAP_UV; + if (qZeroST && (qZeroQ || qFactorZero) && gstate.tgenMatrix[11] == 1.0f) { state->textureProj = false; } }