Skip to content

Commit

Permalink
TexCache: Optimize DXT5 alpha lerp.
Browse files Browse the repository at this point in the history
This makes the overall DXT5 decode about 8% faster.
  • Loading branch information
unknownbrackets committed Sep 2, 2018
1 parent 3f35221 commit f65edc2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions GPU/Common/TextureDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,16 @@ void DXTDecoder::DecodeColors(const DXT1Block *src, bool ignore1bitAlpha) {
}

static inline u8 lerp8(const DXT5Block *src, int n) {
float d = n / 7.0f;
return (u8)(src->alpha1 + (src->alpha2 - src->alpha1) * d);
// These weights translate alpha1/alpha2 to fixed 8.8 point, pre-divided by 7.
int weight1 = ((7 - n) << 8) / 7;
int weight2 = (n << 8) / 7;
return (u8)((src->alpha1 * weight1 + src->alpha2 * weight2) >> 8);
}

static inline u8 lerp6(const DXT5Block *src, int n) {
float d = n / 5.0f;
return (u8)(src->alpha1 + (src->alpha2 - src->alpha1) * d);
int weight1 = ((5 - n) << 8) / 5;
int weight2 = (n << 8) / 5;
return (u8)((src->alpha1 * weight1 + src->alpha2 * weight2) >> 8);
}

void DXTDecoder::DecodeAlphaDXT5(const DXT5Block *src) {
Expand Down

0 comments on commit f65edc2

Please sign in to comment.