mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
astc: Hard code bit depth changes to 8 and use fast replicate
This commit is contained in:
parent
bd2c1ab8a0
commit
6bf5d2b011
1 changed files with 15 additions and 21 deletions
|
@ -759,10 +759,10 @@ public:
|
||||||
// significant bits when going from larger to smaller bit depth
|
// significant bits when going from larger to smaller bit depth
|
||||||
// or by repeating the most significant bits when going from
|
// or by repeating the most significant bits when going from
|
||||||
// smaller to larger bit depths.
|
// smaller to larger bit depths.
|
||||||
void ChangeBitDepth(const u8 (&depth)[4]) {
|
void ChangeBitDepth() {
|
||||||
for (u32 i = 0; i < 4; i++) {
|
for (u32 i = 0; i < 4; i++) {
|
||||||
Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i], depth[i]);
|
Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i]);
|
||||||
m_BitDepth[i] = depth[i];
|
m_BitDepth[i] = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,29 +774,24 @@ public:
|
||||||
|
|
||||||
// Changes the bit depth of a single component. See the comment
|
// Changes the bit depth of a single component. See the comment
|
||||||
// above for how we do this.
|
// above for how we do this.
|
||||||
static ChannelType ChangeBitDepth(Pixel::ChannelType val, u8 oldDepth, u8 newDepth) {
|
static ChannelType ChangeBitDepth(Pixel::ChannelType val, u8 oldDepth) {
|
||||||
assert(newDepth <= 8);
|
|
||||||
assert(oldDepth <= 8);
|
assert(oldDepth <= 8);
|
||||||
|
|
||||||
if (oldDepth == newDepth) {
|
if (oldDepth == 8) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
return val;
|
return val;
|
||||||
} else if (oldDepth == 0 && newDepth != 0) {
|
} else if (oldDepth == 0) {
|
||||||
return static_cast<ChannelType>((1 << newDepth) - 1);
|
return static_cast<ChannelType>((1 << 8) - 1);
|
||||||
} else if (newDepth > oldDepth) {
|
} else if (8 > oldDepth) {
|
||||||
return Replicate(val, oldDepth, newDepth);
|
return static_cast<ChannelType>(FastReplicateTo8(static_cast<u32>(val), oldDepth));
|
||||||
} else {
|
} else {
|
||||||
// oldDepth > newDepth
|
// oldDepth > newDepth
|
||||||
if (newDepth == 0) {
|
const u8 bitsWasted = static_cast<u8>(oldDepth - 8);
|
||||||
return 0xFF;
|
|
||||||
} else {
|
|
||||||
u8 bitsWasted = static_cast<u8>(oldDepth - newDepth);
|
|
||||||
u16 v = static_cast<u16>(val);
|
u16 v = static_cast<u16>(val);
|
||||||
v = static_cast<u16>((v + (1 << (bitsWasted - 1))) >> bitsWasted);
|
v = static_cast<u16>((v + (1 << (bitsWasted - 1))) >> bitsWasted);
|
||||||
v = ::std::min<u16>(::std::max<u16>(0, v), static_cast<u16>((1 << newDepth) - 1));
|
v = ::std::min<u16>(::std::max<u16>(0, v), static_cast<u16>((1 << 8) - 1));
|
||||||
return static_cast<u8>(v);
|
return static_cast<u8>(v);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
assert(false && "We shouldn't get here.");
|
assert(false && "We shouldn't get here.");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -845,8 +840,7 @@ public:
|
||||||
// up in the most-significant byte.
|
// up in the most-significant byte.
|
||||||
u32 Pack() const {
|
u32 Pack() const {
|
||||||
Pixel eightBit(*this);
|
Pixel eightBit(*this);
|
||||||
const u8 eightBitDepth[4] = {8, 8, 8, 8};
|
eightBit.ChangeBitDepth();
|
||||||
eightBit.ChangeBitDepth(eightBitDepth);
|
|
||||||
|
|
||||||
u32 r = 0;
|
u32 r = 0;
|
||||||
r |= eightBit.A();
|
r |= eightBit.A();
|
||||||
|
|
Loading…
Reference in a new issue