From 11ab4e86344f1823153a3f03b0092785ab47fb13 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Nov 2018 08:37:24 -0800 Subject: [PATCH] TexCache: Mix DXT colors using 2/3 not 3/8. Hardware draws using 2/3. Adding this way matches rounding, too. --- GPU/Common/TextureDecoder.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/GPU/Common/TextureDecoder.cpp b/GPU/Common/TextureDecoder.cpp index 4a84fb264a..8f40cc13f4 100644 --- a/GPU/Common/TextureDecoder.cpp +++ b/GPU/Common/TextureDecoder.cpp @@ -348,9 +348,8 @@ static inline u32 makecol(int r, int g, int b, int a) { return (a << 24) | (r << 16) | (g << 8) | b; } -static inline int mul_3_8(int c) { - // This is 3/8 * c = 4/8 * c - 1/8 * c. - return (c >> 1) - (c >> 3); +static inline int mix_2_3(int c1, int c2) { + return (c1 + c1 + c2) / 3; } // This could probably be done faster by decoding two or four blocks at a time with SSE/NEON. @@ -370,16 +369,13 @@ void DXTDecoder::DecodeColors(const DXT1Block *src, bool ignore1bitAlpha) { colors_[0] = makecol(red1, green1, blue1, alpha); colors_[1] = makecol(red2, green2, blue2, alpha); if (c1 > c2 || ignore1bitAlpha) { - int red3 = mul_3_8(red2 - red1); - int green3 = mul_3_8(green2 - green1); - int blue3 = mul_3_8(blue2 - blue1); - colors_[2] = makecol(red1 + red3, green1 + green3, blue1 + blue3, alpha); - colors_[3] = makecol(red2 - red3, green2 - green3, blue2 - blue3, alpha); + colors_[2] = makecol(mix_2_3(red1, red2), mix_2_3(green1, green2), mix_2_3(blue1, blue2), alpha); + colors_[3] = makecol(mix_2_3(red2, red1), mix_2_3(green2, green1), mix_2_3(blue2, blue1), alpha); } else { - // Average - int red3 = (red1 + red2 + 1) / 2; - int green3 = (green1 + green2 + 1) / 2; - int blue3 = (blue1 + blue2 + 1) / 2; + // Average - these are always left shifted, so no need to worry about ties. + int red3 = (red1 + red2) / 2; + int green3 = (green1 + green2) / 2; + int blue3 = (blue1 + blue2) / 2; colors_[2] = makecol(red3, green3, blue3, 255); colors_[3] = makecol(0, 0, 0, 0); }