From 025ac99f2fbd072a057b650b07ff364e101ea135 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 1 Jan 2022 18:34:04 -0800 Subject: [PATCH] softgpu: Reduce interpolation if not needed. About 3% gain in some areas. --- GPU/Software/Rasterizer.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index baf2a0f407..aa2b5acb61 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -756,6 +756,10 @@ void DrawTriangleSlice( // All the z values are the same, no interpolation required. // This is common, and when we interpolate, we lose accuracy. const bool flatZ = v0.screenpos.z == v1.screenpos.z && v0.screenpos.z == v2.screenpos.z; + const bool flatColorAll = clearMode || gstate.getShadeMode() != GE_SHADE_GOURAUD; + const bool flatColor0 = flatColorAll || (v0.color0 == v1.color0 && v0.color0 == v2.color0); + const bool flatColor1 = flatColorAll || (v0.color1 == v1.color1 && v0.color1 == v2.color1); + const bool noFog = clearMode || !gstate.isFogEnabled() || (v0.fogdepth >= 1.0f && v1.fogdepth >= 1.0f && v2.fogdepth >= 1.0f); for (int64_t curY = minY; curY <= maxY; curY += 32, w0_base = e0.StepY(w0_base), @@ -785,16 +789,23 @@ void DrawTriangleSlice( Vec4 wsum_recip = EdgeRecip(w0, w1, w2); Vec4 prim_color[4]; - Vec3 sec_color[4]; - if (gstate.getShadeMode() == GE_SHADE_GOURAUD && !clearMode) { + if (!flatColor0) { // Does the PSP do perspective-correct color interpolation? The GC doesn't. for (int i = 0; i < 4; ++i) { prim_color[i] = Interpolate(v0.color0, v1.color0, v2.color0, w0[i], w1[i], w2[i], wsum_recip[i]); - sec_color[i] = Interpolate(v0.color1, v1.color1, v2.color1, w0[i], w1[i], w2[i], wsum_recip[i]); } } else { for (int i = 0; i < 4; ++i) { prim_color[i] = v2.color0; + } + } + Vec3 sec_color[4]; + if (!flatColor1) { + for (int i = 0; i < 4; ++i) { + sec_color[i] = Interpolate(v0.color1, v1.color1, v2.color1, w0[i], w1[i], w2[i], wsum_recip[i]); + } + } else { + for (int i = 0; i < 4; ++i) { sec_color[i] = v2.color1; } } @@ -829,7 +840,7 @@ void DrawTriangleSlice( } Vec4 fog = Vec4::AssignToAll(255); - if (gstate.isFogEnabled() && !clearMode) { + if (!noFog) { Vec4 fogdepths = w0.Cast() * v0.fogdepth + w1.Cast() * v1.fogdepth + w2.Cast() * v2.fogdepth; fogdepths = fogdepths * wsum_recip; for (int i = 0; i < 4; ++i) {