From cd9d58fa531845a5586a02b9c2909e006be5abb6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 23 Apr 2017 07:19:50 -0700 Subject: [PATCH] SoftGPU: Interpolate through texturing better. This is significantly faster. --- GPU/Software/Rasterizer.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index aceb3a6767d0..87b335e5b5eb 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -1180,6 +1180,17 @@ static inline Vec2 Interpolate(const Vec2 &c0, const Vec2 & #endif } +static inline Vec4 Interpolate(const float &c0, const float &c1, const float &c2, Vec4 w0, Vec4 w1, Vec4 w2, Vec4 wsum_recip) { +#if defined(_M_SSE) && !defined(_M_IX86) + __m128 v = _mm_mul_ps(_mm_cvtepi32_ps(w0.ivec), _mm_set1_ps(c0)); + v = _mm_add_ps(v, _mm_mul_ps(_mm_cvtepi32_ps(w1.ivec), _mm_set1_ps(c1))); + v = _mm_add_ps(v, _mm_mul_ps(_mm_cvtepi32_ps(w2.ivec), _mm_set1_ps(c2))); + return _mm_mul_ps(v, wsum_recip.vec); +#else + return (w0.Cast() * c0 + w1.Cast() * c1 + w2.Cast() * c2) * wsum_recip; +#endif +} + struct TriangleEdge { Vec4 Start(const ScreenCoords &v0, const ScreenCoords &v1, const ScreenCoords &origin); inline Vec4 StepX(const Vec4 &w); @@ -1205,7 +1216,11 @@ Vec4 TriangleEdge::Start(const ScreenCoords &v0, const ScreenCoords &v1, co } inline Vec4 TriangleEdge::StepX(const Vec4 &w) { +#if defined(_M_SSE) && !defined(_M_IX86) + return _mm_add_epi32(w.ivec, stepX.ivec); +#else return w + stepX; +#endif } inline Vec4 TriangleEdge::StepY(const Vec4 &w) { @@ -1311,9 +1326,10 @@ void DrawTriangleSlice( if (gstate.isTextureMapEnabled() && !clearMode) { if (gstate.isModeThrough()) { + Vec4 s = Interpolate(v0.texturecoords.s(), v1.texturecoords.s(), v2.texturecoords.s(), w0, w1, w2, wsum_recip); + Vec4 t = Interpolate(v0.texturecoords.t(), v1.texturecoords.t(), v2.texturecoords.t(), w0, w1, w2, wsum_recip); for (int i = 0; i < 4; ++i) { - Vec2 texcoords = Interpolate(v0.texturecoords, v1.texturecoords, v2.texturecoords, w0[i], w1[i], w2[i], wsum_recip[i]); - ApplyTexturing(prim_color[i], texcoords.s(), texcoords.t(), maxTexLevel, magFilt, texptr, texbufwidthbytes); + ApplyTexturing(prim_color[i], s[i], t[i], maxTexLevel, magFilt, texptr, texbufwidthbytes); } } else { // Texture coordinate interpolation must definitely be perspective-correct.