Permalink
Browse files

TexCache: Optimize DXT5 alpha lerp.

This makes the overall DXT5 decode about 8% faster.
  • Loading branch information...
unknownbrackets committed Sep 2, 2018
1 parent 3f35221 commit f65edc20a3ebc7c4e67b5afc872f0e7f546282a2
Showing with 7 additions and 4 deletions.
  1. +7 −4 GPU/Common/TextureDecoder.cpp
@@ -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) {

0 comments on commit f65edc2

Please sign in to comment.