Permalink
Browse files

TexCache: Mix DXT colors using 2/3 not 3/8.

Hardware draws using 2/3.  Adding this way matches rounding, too.
  • Loading branch information...
unknownbrackets committed Nov 4, 2018
1 parent 35a1d8a commit 11ab4e86344f1823153a3f03b0092785ab47fb13
Showing with 8 additions and 12 deletions.
  1. +8 −12 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);
}

0 comments on commit 11ab4e8

Please sign in to comment.