summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/textures/astc.cpp62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp
index 028670800..5fce8546c 100644
--- a/src/video_core/textures/astc.cpp
+++ b/src/video_core/textures/astc.cpp
@@ -39,18 +39,15 @@ constexpr u32 Popcnt(u32 n) {
39 39
40class InputBitStream { 40class InputBitStream {
41public: 41public:
42 explicit InputBitStream(const u8* ptr, s32 start_offset = 0) 42 explicit InputBitStream(const u8* ptr, std::size_t start_offset = 0)
43 : m_CurByte(ptr), m_NextBit(start_offset % 8) {} 43 : m_CurByte(ptr), m_NextBit(start_offset % 8) {}
44 44
45 ~InputBitStream() = default; 45 std::size_t GetBitsRead() const {
46
47 s32 GetBitsRead() const {
48 return m_BitsRead; 46 return m_BitsRead;
49 } 47 }
50 48
51 s32 ReadBit() { 49 u32 ReadBit() {
52 50 u32 bit = *m_CurByte >> m_NextBit++;
53 s32 bit = *m_CurByte >> m_NextBit++;
54 while (m_NextBit >= 8) { 51 while (m_NextBit >= 8) {
55 m_NextBit -= 8; 52 m_NextBit -= 8;
56 m_CurByte++; 53 m_CurByte++;
@@ -60,9 +57,18 @@ public:
60 return bit & 1; 57 return bit & 1;
61 } 58 }
62 59
63 u32 ReadBits(u32 nBits) { 60 u32 ReadBits(std::size_t nBits) {
64 u32 ret = 0; 61 u32 ret = 0;
65 for (u32 i = 0; i < nBits; i++) { 62 for (std::size_t i = 0; i < nBits; ++i) {
63 ret |= (ReadBit() & 1) << i;
64 }
65 return ret;
66 }
67
68 template <std::size_t nBits>
69 u32 ReadBits() {
70 u32 ret = 0;
71 for (std::size_t i = 0; i < nBits; ++i) {
66 ret |= (ReadBit() & 1) << i; 72 ret |= (ReadBit() & 1) << i;
67 } 73 }
68 return ret; 74 return ret;
@@ -70,8 +76,8 @@ public:
70 76
71private: 77private:
72 const u8* m_CurByte; 78 const u8* m_CurByte;
73 s32 m_NextBit = 0; 79 std::size_t m_NextBit = 0;
74 s32 m_BitsRead = 0; 80 std::size_t m_BitsRead = 0;
75}; 81};
76 82
77class OutputBitStream { 83class OutputBitStream {
@@ -200,13 +206,13 @@ static void DecodeTritBlock(InputBitStream& bits, std::vector<IntegerEncodedValu
200 // Read the trit encoded block according to 206 // Read the trit encoded block according to
201 // table C.2.14 207 // table C.2.14
202 m[0] = bits.ReadBits(nBitsPerValue); 208 m[0] = bits.ReadBits(nBitsPerValue);
203 T = bits.ReadBits(2); 209 T = bits.ReadBits<2>();
204 m[1] = bits.ReadBits(nBitsPerValue); 210 m[1] = bits.ReadBits(nBitsPerValue);
205 T |= bits.ReadBits(2) << 2; 211 T |= bits.ReadBits<2>() << 2;
206 m[2] = bits.ReadBits(nBitsPerValue); 212 m[2] = bits.ReadBits(nBitsPerValue);
207 T |= bits.ReadBit() << 4; 213 T |= bits.ReadBit() << 4;
208 m[3] = bits.ReadBits(nBitsPerValue); 214 m[3] = bits.ReadBits(nBitsPerValue);
209 T |= bits.ReadBits(2) << 5; 215 T |= bits.ReadBits<2>() << 5;
210 m[4] = bits.ReadBits(nBitsPerValue); 216 m[4] = bits.ReadBits(nBitsPerValue);
211 T |= bits.ReadBit() << 7; 217 T |= bits.ReadBit() << 7;
212 218
@@ -259,11 +265,11 @@ static void DecodeQus32Block(InputBitStream& bits, std::vector<IntegerEncodedVal
259 // Read the trit encoded block according to 265 // Read the trit encoded block according to
260 // table C.2.15 266 // table C.2.15
261 m[0] = bits.ReadBits(nBitsPerValue); 267 m[0] = bits.ReadBits(nBitsPerValue);
262 Q = bits.ReadBits(3); 268 Q = bits.ReadBits<3>();
263 m[1] = bits.ReadBits(nBitsPerValue); 269 m[1] = bits.ReadBits(nBitsPerValue);
264 Q |= bits.ReadBits(2) << 3; 270 Q |= bits.ReadBits<2>() << 3;
265 m[2] = bits.ReadBits(nBitsPerValue); 271 m[2] = bits.ReadBits(nBitsPerValue);
266 Q |= bits.ReadBits(2) << 5; 272 Q |= bits.ReadBits<2>() << 5;
267 273
268 Bits<u32> Qb(Q); 274 Bits<u32> Qb(Q);
269 if (Qb(1, 2) == 3 && Qb(5, 6) == 0) { 275 if (Qb(1, 2) == 3 && Qb(5, 6) == 0) {
@@ -399,7 +405,7 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) {
399 TexelWeightParams params; 405 TexelWeightParams params;
400 406
401 // Read the entire block mode all at once 407 // Read the entire block mode all at once
402 u16 modeBits = static_cast<u16>(strm.ReadBits(11)); 408 u16 modeBits = static_cast<u16>(strm.ReadBits<11>());
403 409
404 // Does this match the void extent block mode? 410 // Does this match the void extent block mode?
405 if ((modeBits & 0x01FF) == 0x1FC) { 411 if ((modeBits & 0x01FF) == 0x1FC) {
@@ -598,14 +604,14 @@ static void FillVoidExtentLDR(InputBitStream& strm, u32* const outBuf, u32 block
598 u32 blockHeight) { 604 u32 blockHeight) {
599 // Don't actually care about the void extent, just read the bits... 605 // Don't actually care about the void extent, just read the bits...
600 for (s32 i = 0; i < 4; ++i) { 606 for (s32 i = 0; i < 4; ++i) {
601 strm.ReadBits(13); 607 strm.ReadBits<13>();
602 } 608 }
603 609
604 // Decode the RGBA components and renormalize them to the range [0, 255] 610 // Decode the RGBA components and renormalize them to the range [0, 255]
605 u16 r = static_cast<u16>(strm.ReadBits(16)); 611 u16 r = static_cast<u16>(strm.ReadBits<16>());
606 u16 g = static_cast<u16>(strm.ReadBits(16)); 612 u16 g = static_cast<u16>(strm.ReadBits<16>());
607 u16 b = static_cast<u16>(strm.ReadBits(16)); 613 u16 b = static_cast<u16>(strm.ReadBits<16>());
608 u16 a = static_cast<u16>(strm.ReadBits(16)); 614 u16 a = static_cast<u16>(strm.ReadBits<16>());
609 615
610 u32 rgba = (r >> 8) | (g & 0xFF00) | (static_cast<u32>(b) & 0xFF00) << 8 | 616 u32 rgba = (r >> 8) | (g & 0xFF00) | (static_cast<u32>(b) & 0xFF00) << 8 |
611 (static_cast<u32>(a) & 0xFF00) << 16; 617 (static_cast<u32>(a) & 0xFF00) << 16;
@@ -1390,7 +1396,7 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32
1390 } 1396 }
1391 1397
1392 // Read num partitions 1398 // Read num partitions
1393 u32 nPartitions = strm.ReadBits(2) + 1; 1399 u32 nPartitions = strm.ReadBits<2>() + 1;
1394 assert(nPartitions <= 4); 1400 assert(nPartitions <= 4);
1395 1401
1396 if (nPartitions == 4 && weightParams.m_bDualPlane) { 1402 if (nPartitions == 4 && weightParams.m_bDualPlane) {
@@ -1415,17 +1421,17 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32
1415 // Read extra config data... 1421 // Read extra config data...
1416 u32 baseCEM = 0; 1422 u32 baseCEM = 0;
1417 if (nPartitions == 1) { 1423 if (nPartitions == 1) {
1418 colorEndpos32Mode[0] = strm.ReadBits(4); 1424 colorEndpos32Mode[0] = strm.ReadBits<4>();
1419 partitionIndex = 0; 1425 partitionIndex = 0;
1420 } else { 1426 } else {
1421 partitionIndex = strm.ReadBits(10); 1427 partitionIndex = strm.ReadBits<10>();
1422 baseCEM = strm.ReadBits(6); 1428 baseCEM = strm.ReadBits<6>();
1423 } 1429 }
1424 u32 baseMode = (baseCEM & 3); 1430 u32 baseMode = (baseCEM & 3);
1425 1431
1426 // Remaining bits are color endpos32 data... 1432 // Remaining bits are color endpos32 data...
1427 u32 nWeightBits = weightParams.GetPackedBitSize(); 1433 u32 nWeightBits = weightParams.GetPackedBitSize();
1428 s32 remainingBits = 128 - nWeightBits - strm.GetBitsRead(); 1434 s32 remainingBits = 128 - nWeightBits - static_cast<s32>(strm.GetBitsRead());
1429 1435
1430 // Consider extra bits prior to texel data... 1436 // Consider extra bits prior to texel data...
1431 u32 extraCEMbits = 0; 1437 u32 extraCEMbits = 0;