diff options
| author | 2020-03-13 22:28:51 -0300 | |
|---|---|---|
| committer | 2020-03-13 22:28:51 -0300 | |
| commit | e7d97605e8f0337406d3fcabca84cb32daf78950 (patch) | |
| tree | 3f50a9025c5282d51485df3b5d18ad7d9fefb002 /src/video_core/textures/astc.cpp | |
| parent | astc: Move Popcnt to an anonymous namespace and make it constexpr (diff) | |
| download | yuzu-e7d97605e8f0337406d3fcabca84cb32daf78950.tar.gz yuzu-e7d97605e8f0337406d3fcabca84cb32daf78950.tar.xz yuzu-e7d97605e8f0337406d3fcabca84cb32daf78950.zip | |
astc: Rename C types to common_types
Diffstat (limited to 'src/video_core/textures/astc.cpp')
| -rw-r--r-- | src/video_core/textures/astc.cpp | 157 |
1 files changed, 78 insertions, 79 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index aba47a0e8..7d5796794 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | 17 | ||
| 18 | #include <algorithm> | 18 | #include <algorithm> |
| 19 | #include <cassert> | 19 | #include <cassert> |
| 20 | #include <cstdint> | ||
| 21 | #include <cstring> | 20 | #include <cstring> |
| 22 | #include <vector> | 21 | #include <vector> |
| 23 | 22 | ||
| @@ -40,18 +39,18 @@ constexpr u32 Popcnt(u32 n) { | |||
| 40 | 39 | ||
| 41 | class InputBitStream { | 40 | class InputBitStream { |
| 42 | public: | 41 | public: |
| 43 | explicit InputBitStream(const unsigned char* ptr, int start_offset = 0) | 42 | explicit InputBitStream(const u8* ptr, s32 start_offset = 0) |
| 44 | : m_CurByte(ptr), m_NextBit(start_offset % 8) {} | 43 | : m_CurByte(ptr), m_NextBit(start_offset % 8) {} |
| 45 | 44 | ||
| 46 | ~InputBitStream() = default; | 45 | ~InputBitStream() = default; |
| 47 | 46 | ||
| 48 | int GetBitsRead() const { | 47 | s32 GetBitsRead() const { |
| 49 | return m_BitsRead; | 48 | return m_BitsRead; |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | int ReadBit() { | 51 | s32 ReadBit() { |
| 53 | 52 | ||
| 54 | int bit = *m_CurByte >> m_NextBit++; | 53 | s32 bit = *m_CurByte >> m_NextBit++; |
| 55 | while (m_NextBit >= 8) { | 54 | while (m_NextBit >= 8) { |
| 56 | m_NextBit -= 8; | 55 | m_NextBit -= 8; |
| 57 | m_CurByte++; | 56 | m_CurByte++; |
| @@ -61,57 +60,57 @@ public: | |||
| 61 | return bit & 1; | 60 | return bit & 1; |
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | unsigned int ReadBits(unsigned int nBits) { | 63 | u32 ReadBits(u32 nBits) { |
| 65 | unsigned int ret = 0; | 64 | u32 ret = 0; |
| 66 | for (unsigned int i = 0; i < nBits; i++) { | 65 | for (u32 i = 0; i < nBits; i++) { |
| 67 | ret |= (ReadBit() & 1) << i; | 66 | ret |= (ReadBit() & 1) << i; |
| 68 | } | 67 | } |
| 69 | return ret; | 68 | return ret; |
| 70 | } | 69 | } |
| 71 | 70 | ||
| 72 | private: | 71 | private: |
| 73 | const unsigned char* m_CurByte; | 72 | const u8* m_CurByte; |
| 74 | int m_NextBit = 0; | 73 | s32 m_NextBit = 0; |
| 75 | int m_BitsRead = 0; | 74 | s32 m_BitsRead = 0; |
| 76 | }; | 75 | }; |
| 77 | 76 | ||
| 78 | class OutputBitStream { | 77 | class OutputBitStream { |
| 79 | public: | 78 | public: |
| 80 | explicit OutputBitStream(unsigned char* ptr, int nBits = 0, int start_offset = 0) | 79 | explicit OutputBitStream(u8* ptr, s32 nBits = 0, s32 start_offset = 0) |
| 81 | : m_NumBits(nBits), m_CurByte(ptr), m_NextBit(start_offset % 8) {} | 80 | : m_NumBits(nBits), m_CurByte(ptr), m_NextBit(start_offset % 8) {} |
| 82 | 81 | ||
| 83 | ~OutputBitStream() = default; | 82 | ~OutputBitStream() = default; |
| 84 | 83 | ||
| 85 | int GetBitsWritten() const { | 84 | s32 GetBitsWritten() const { |
| 86 | return m_BitsWritten; | 85 | return m_BitsWritten; |
| 87 | } | 86 | } |
| 88 | 87 | ||
| 89 | void WriteBitsR(unsigned int val, unsigned int nBits) { | 88 | void WriteBitsR(u32 val, u32 nBits) { |
| 90 | for (unsigned int i = 0; i < nBits; i++) { | 89 | for (u32 i = 0; i < nBits; i++) { |
| 91 | WriteBit((val >> (nBits - i - 1)) & 1); | 90 | WriteBit((val >> (nBits - i - 1)) & 1); |
| 92 | } | 91 | } |
| 93 | } | 92 | } |
| 94 | 93 | ||
| 95 | void WriteBits(unsigned int val, unsigned int nBits) { | 94 | void WriteBits(u32 val, u32 nBits) { |
| 96 | for (unsigned int i = 0; i < nBits; i++) { | 95 | for (u32 i = 0; i < nBits; i++) { |
| 97 | WriteBit((val >> i) & 1); | 96 | WriteBit((val >> i) & 1); |
| 98 | } | 97 | } |
| 99 | } | 98 | } |
| 100 | 99 | ||
| 101 | private: | 100 | private: |
| 102 | void WriteBit(int b) { | 101 | void WriteBit(s32 b) { |
| 103 | 102 | ||
| 104 | if (done) | 103 | if (done) |
| 105 | return; | 104 | return; |
| 106 | 105 | ||
| 107 | const unsigned int mask = 1 << m_NextBit++; | 106 | const u32 mask = 1 << m_NextBit++; |
| 108 | 107 | ||
| 109 | // clear the bit | 108 | // clear the bit |
| 110 | *m_CurByte &= static_cast<unsigned char>(~mask); | 109 | *m_CurByte &= static_cast<u8>(~mask); |
| 111 | 110 | ||
| 112 | // Write the bit, if necessary | 111 | // Write the bit, if necessary |
| 113 | if (b) | 112 | if (b) |
| 114 | *m_CurByte |= static_cast<unsigned char>(mask); | 113 | *m_CurByte |= static_cast<u8>(mask); |
| 115 | 114 | ||
| 116 | // Next byte? | 115 | // Next byte? |
| 117 | if (m_NextBit >= 8) { | 116 | if (m_NextBit >= 8) { |
| @@ -122,10 +121,10 @@ private: | |||
| 122 | done = done || ++m_BitsWritten >= m_NumBits; | 121 | done = done || ++m_BitsWritten >= m_NumBits; |
| 123 | } | 122 | } |
| 124 | 123 | ||
| 125 | int m_BitsWritten = 0; | 124 | s32 m_BitsWritten = 0; |
| 126 | const int m_NumBits; | 125 | const s32 m_NumBits; |
| 127 | unsigned char* m_CurByte; | 126 | u8* m_CurByte; |
| 128 | int m_NextBit = 0; | 127 | s32 m_NextBit = 0; |
| 129 | 128 | ||
| 130 | bool done = false; | 129 | bool done = false; |
| 131 | }; | 130 | }; |
| @@ -159,7 +158,7 @@ private: | |||
| 159 | const IntType& m_Bits; | 158 | const IntType& m_Bits; |
| 160 | }; | 159 | }; |
| 161 | 160 | ||
| 162 | enum class IntegerEncoding { JustBits, Quint, Trit }; | 161 | enum class IntegerEncoding { JustBits, Qus32, Trit }; |
| 163 | 162 | ||
| 164 | class IntegerEncodedValue { | 163 | class IntegerEncodedValue { |
| 165 | private: | 164 | private: |
| @@ -167,7 +166,7 @@ private: | |||
| 167 | const u32 m_NumBits; | 166 | const u32 m_NumBits; |
| 168 | u32 m_BitValue; | 167 | u32 m_BitValue; |
| 169 | union { | 168 | union { |
| 170 | u32 m_QuintValue; | 169 | u32 m_Qus32Value; |
| 171 | u32 m_TritValue; | 170 | u32 m_TritValue; |
| 172 | }; | 171 | }; |
| 173 | 172 | ||
| @@ -203,11 +202,11 @@ public: | |||
| 203 | m_TritValue = val; | 202 | m_TritValue = val; |
| 204 | } | 203 | } |
| 205 | 204 | ||
| 206 | u32 GetQuintValue() const { | 205 | u32 GetQus32Value() const { |
| 207 | return m_QuintValue; | 206 | return m_Qus32Value; |
| 208 | } | 207 | } |
| 209 | void SetQuintValue(u32 val) { | 208 | void SetQus32Value(u32 val) { |
| 210 | m_QuintValue = val; | 209 | m_Qus32Value = val; |
| 211 | } | 210 | } |
| 212 | 211 | ||
| 213 | bool MatchesEncoding(const IntegerEncodedValue& other) const { | 212 | bool MatchesEncoding(const IntegerEncodedValue& other) const { |
| @@ -219,7 +218,7 @@ public: | |||
| 219 | u32 totalBits = m_NumBits * nVals; | 218 | u32 totalBits = m_NumBits * nVals; |
| 220 | if (m_Encoding == IntegerEncoding::Trit) { | 219 | if (m_Encoding == IntegerEncoding::Trit) { |
| 221 | totalBits += (nVals * 8 + 4) / 5; | 220 | totalBits += (nVals * 8 + 4) / 5; |
| 222 | } else if (m_Encoding == IntegerEncoding::Quint) { | 221 | } else if (m_Encoding == IntegerEncoding::Qus32) { |
| 223 | totalBits += (nVals * 7 + 2) / 3; | 222 | totalBits += (nVals * 7 + 2) / 3; |
| 224 | } | 223 | } |
| 225 | return totalBits; | 224 | return totalBits; |
| @@ -243,10 +242,10 @@ public: | |||
| 243 | 242 | ||
| 244 | // Is maxVal of the type 5*2^n - 1? | 243 | // Is maxVal of the type 5*2^n - 1? |
| 245 | if ((check % 5 == 0) && !((check / 5) & ((check / 5) - 1))) { | 244 | if ((check % 5 == 0) && !((check / 5) & ((check / 5) - 1))) { |
| 246 | return IntegerEncodedValue(IntegerEncoding::Quint, Popcnt(check / 5 - 1)); | 245 | return IntegerEncodedValue(IntegerEncoding::Qus32, Popcnt(check / 5 - 1)); |
| 247 | } | 246 | } |
| 248 | 247 | ||
| 249 | // Apparently it can't be represented with a bounded integer sequence... | 248 | // Apparently it can't be represented with a bounded s32eger sequence... |
| 250 | // just iterate. | 249 | // just iterate. |
| 251 | maxVal--; | 250 | maxVal--; |
| 252 | } | 251 | } |
| @@ -265,8 +264,8 @@ public: | |||
| 265 | u32 nValsDecoded = 0; | 264 | u32 nValsDecoded = 0; |
| 266 | while (nValsDecoded < nValues) { | 265 | while (nValsDecoded < nValues) { |
| 267 | switch (val.GetEncoding()) { | 266 | switch (val.GetEncoding()) { |
| 268 | case IntegerEncoding::Quint: | 267 | case IntegerEncoding::Qus32: |
| 269 | DecodeQuintBlock(bits, result, val.BaseBitLength()); | 268 | DecodeQus32Block(bits, result, val.BaseBitLength()); |
| 270 | nValsDecoded += 3; | 269 | nValsDecoded += 3; |
| 271 | break; | 270 | break; |
| 272 | 271 | ||
| @@ -345,7 +344,7 @@ private: | |||
| 345 | } | 344 | } |
| 346 | } | 345 | } |
| 347 | 346 | ||
| 348 | static void DecodeQuintBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, | 347 | static void DecodeQus32Block(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, |
| 349 | u32 nBitsPerValue) { | 348 | u32 nBitsPerValue) { |
| 350 | // Implement the algorithm in section C.2.12 | 349 | // Implement the algorithm in section C.2.12 |
| 351 | u32 m[3]; | 350 | u32 m[3]; |
| @@ -386,9 +385,9 @@ private: | |||
| 386 | } | 385 | } |
| 387 | 386 | ||
| 388 | for (u32 i = 0; i < 3; i++) { | 387 | for (u32 i = 0; i < 3; i++) { |
| 389 | IntegerEncodedValue val(IntegerEncoding::Quint, nBitsPerValue); | 388 | IntegerEncodedValue val(IntegerEncoding::Qus32, nBitsPerValue); |
| 390 | val.m_BitValue = m[i]; | 389 | val.m_BitValue = m[i]; |
| 391 | val.m_QuintValue = q[i]; | 390 | val.m_Qus32Value = q[i]; |
| 392 | result.push_back(val); | 391 | result.push_back(val); |
| 393 | } | 392 | } |
| 394 | } | 393 | } |
| @@ -626,7 +625,7 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 626 | static void FillVoidExtentLDR(InputBitStream& strm, u32* const outBuf, u32 blockWidth, | 625 | static void FillVoidExtentLDR(InputBitStream& strm, u32* const outBuf, u32 blockWidth, |
| 627 | u32 blockHeight) { | 626 | u32 blockHeight) { |
| 628 | // Don't actually care about the void extent, just read the bits... | 627 | // Don't actually care about the void extent, just read the bits... |
| 629 | for (int i = 0; i < 4; ++i) { | 628 | for (s32 i = 0; i < 4; ++i) { |
| 630 | strm.ReadBits(13); | 629 | strm.ReadBits(13); |
| 631 | } | 630 | } |
| 632 | 631 | ||
| @@ -687,7 +686,7 @@ protected: | |||
| 687 | 686 | ||
| 688 | public: | 687 | public: |
| 689 | Pixel() = default; | 688 | Pixel() = default; |
| 690 | Pixel(u32 a, u32 r, u32 g, u32 b, unsigned bitDepth = 8) | 689 | Pixel(u32 a, u32 r, u32 g, u32 b, u32 bitDepth = 8) |
| 691 | : m_BitDepth{u8(bitDepth), u8(bitDepth), u8(bitDepth), u8(bitDepth)}, | 690 | : m_BitDepth{u8(bitDepth), u8(bitDepth), u8(bitDepth), u8(bitDepth)}, |
| 692 | color{static_cast<ChannelType>(a), static_cast<ChannelType>(r), | 691 | color{static_cast<ChannelType>(a), static_cast<ChannelType>(r), |
| 693 | static_cast<ChannelType>(g), static_cast<ChannelType>(b)} {} | 692 | static_cast<ChannelType>(g), static_cast<ChannelType>(b)} {} |
| @@ -772,13 +771,13 @@ public: | |||
| 772 | } | 771 | } |
| 773 | 772 | ||
| 774 | void GetBitDepth(u8 (&outDepth)[4]) const { | 773 | void GetBitDepth(u8 (&outDepth)[4]) const { |
| 775 | for (int i = 0; i < 4; i++) { | 774 | for (s32 i = 0; i < 4; i++) { |
| 776 | outDepth[i] = m_BitDepth[i]; | 775 | outDepth[i] = m_BitDepth[i]; |
| 777 | } | 776 | } |
| 778 | } | 777 | } |
| 779 | 778 | ||
| 780 | // Take all of the components, transform them to their 8-bit variants, | 779 | // Take all of the components, transform them to their 8-bit variants, |
| 781 | // and then pack each channel into an R8G8B8A8 32-bit integer. We assume | 780 | // and then pack each channel s32o an R8G8B8A8 32-bit s32eger. We assume |
| 782 | // that the architecture is little-endian, so the alpha channel will end | 781 | // that the architecture is little-endian, so the alpha channel will end |
| 783 | // up in the most-significant byte. | 782 | // up in the most-significant byte. |
| 784 | u32 Pack() const { | 783 | u32 Pack() const { |
| @@ -838,7 +837,7 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 838 | } | 837 | } |
| 839 | } | 838 | } |
| 840 | 839 | ||
| 841 | // We now have enough to decode our integer sequence. | 840 | // We now have enough to decode our s32eger sequence. |
| 842 | std::vector<IntegerEncodedValue> decodedColorValues; | 841 | std::vector<IntegerEncodedValue> decodedColorValues; |
| 843 | InputBitStream colorStream(data); | 842 | InputBitStream colorStream(data); |
| 844 | IntegerEncodedValue::DecodeIntegerSequence(decodedColorValues, colorStream, range, nValues); | 843 | IntegerEncodedValue::DecodeIntegerSequence(decodedColorValues, colorStream, range, nValues); |
| @@ -920,9 +919,9 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 920 | } // case IntegerEncoding::Trit | 919 | } // case IntegerEncoding::Trit |
| 921 | break; | 920 | break; |
| 922 | 921 | ||
| 923 | case IntegerEncoding::Quint: { | 922 | case IntegerEncoding::Qus32: { |
| 924 | 923 | ||
| 925 | D = val.GetQuintValue(); | 924 | D = val.GetQus32Value(); |
| 926 | 925 | ||
| 927 | switch (bitlen) { | 926 | switch (bitlen) { |
| 928 | case 1: { | 927 | case 1: { |
| @@ -958,10 +957,10 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 958 | } break; | 957 | } break; |
| 959 | 958 | ||
| 960 | default: | 959 | default: |
| 961 | assert(!"Unsupported quint encoding for color values!"); | 960 | assert(!"Unsupported qus32 encoding for color values!"); |
| 962 | break; | 961 | break; |
| 963 | } // switch(bitlen) | 962 | } // switch(bitlen) |
| 964 | } // case IntegerEncoding::Quint | 963 | } // case IntegerEncoding::Qus32 |
| 965 | break; | 964 | break; |
| 966 | } // switch(val.GetEncoding()) | 965 | } // switch(val.GetEncoding()) |
| 967 | 966 | ||
| @@ -1024,8 +1023,8 @@ static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1024 | } | 1023 | } |
| 1025 | } break; | 1024 | } break; |
| 1026 | 1025 | ||
| 1027 | case IntegerEncoding::Quint: { | 1026 | case IntegerEncoding::Qus32: { |
| 1028 | D = val.GetQuintValue(); | 1027 | D = val.GetQus32Value(); |
| 1029 | assert(D < 5); | 1028 | assert(D < 5); |
| 1030 | 1029 | ||
| 1031 | switch (bitlen) { | 1030 | switch (bitlen) { |
| @@ -1045,7 +1044,7 @@ static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1045 | } break; | 1044 | } break; |
| 1046 | 1045 | ||
| 1047 | default: | 1046 | default: |
| 1048 | assert(!"Invalid quint encoding for texel weight"); | 1047 | assert(!"Invalid qus32 encoding for texel weight"); |
| 1049 | break; | 1048 | break; |
| 1050 | } | 1049 | } |
| 1051 | } break; | 1050 | } break; |
| @@ -1260,8 +1259,8 @@ static inline u32 Select2DPartition(s32 seed, s32 x, s32 y, s32 partitionCount, | |||
| 1260 | } | 1259 | } |
| 1261 | 1260 | ||
| 1262 | // Section C.2.14 | 1261 | // Section C.2.14 |
| 1263 | static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const u32*& colorValues, | 1262 | static void ComputeEndpos32s(Pixel& ep1, Pixel& ep2, const u32*& colorValues, |
| 1264 | u32 colorEndpointMode) { | 1263 | u32 colorEndpos32Mode) { |
| 1265 | #define READ_UINT_VALUES(N) \ | 1264 | #define READ_UINT_VALUES(N) \ |
| 1266 | u32 v[N]; \ | 1265 | u32 v[N]; \ |
| 1267 | for (u32 i = 0; i < N; i++) { \ | 1266 | for (u32 i = 0; i < N; i++) { \ |
| @@ -1274,7 +1273,7 @@ static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const u32*& colorValues, | |||
| 1274 | v[i] = static_cast<s32>(*(colorValues++)); \ | 1273 | v[i] = static_cast<s32>(*(colorValues++)); \ |
| 1275 | } | 1274 | } |
| 1276 | 1275 | ||
| 1277 | switch (colorEndpointMode) { | 1276 | switch (colorEndpos32Mode) { |
| 1278 | case 0: { | 1277 | case 0: { |
| 1279 | READ_UINT_VALUES(2) | 1278 | READ_UINT_VALUES(2) |
| 1280 | ep1 = Pixel(0xFF, v[0], v[0], v[0]); | 1279 | ep1 = Pixel(0xFF, v[0], v[0], v[0]); |
| @@ -1373,7 +1372,7 @@ static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const u32*& colorValues, | |||
| 1373 | } break; | 1372 | } break; |
| 1374 | 1373 | ||
| 1375 | default: | 1374 | default: |
| 1376 | assert(!"Unsupported color endpoint mode (is it HDR?)"); | 1375 | assert(!"Unsupported color endpos32 mode (is it HDR?)"); |
| 1377 | break; | 1376 | break; |
| 1378 | } | 1377 | } |
| 1379 | 1378 | ||
| @@ -1426,23 +1425,23 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1426 | return; | 1425 | return; |
| 1427 | } | 1426 | } |
| 1428 | 1427 | ||
| 1429 | // Based on the number of partitions, read the color endpoint mode for | 1428 | // Based on the number of partitions, read the color endpos32 mode for |
| 1430 | // each partition. | 1429 | // each partition. |
| 1431 | 1430 | ||
| 1432 | // Determine partitions, partition index, and color endpoint modes | 1431 | // Determine partitions, partition index, and color endpos32 modes |
| 1433 | s32 planeIdx = -1; | 1432 | s32 planeIdx = -1; |
| 1434 | u32 partitionIndex; | 1433 | u32 partitionIndex; |
| 1435 | u32 colorEndpointMode[4] = {0, 0, 0, 0}; | 1434 | u32 colorEndpos32Mode[4] = {0, 0, 0, 0}; |
| 1436 | 1435 | ||
| 1437 | // Define color data. | 1436 | // Define color data. |
| 1438 | u8 colorEndpointData[16]; | 1437 | u8 colorEndpos32Data[16]; |
| 1439 | memset(colorEndpointData, 0, sizeof(colorEndpointData)); | 1438 | memset(colorEndpos32Data, 0, sizeof(colorEndpos32Data)); |
| 1440 | OutputBitStream colorEndpointStream(colorEndpointData, 16 * 8, 0); | 1439 | OutputBitStream colorEndpos32Stream(colorEndpos32Data, 16 * 8, 0); |
| 1441 | 1440 | ||
| 1442 | // Read extra config data... | 1441 | // Read extra config data... |
| 1443 | u32 baseCEM = 0; | 1442 | u32 baseCEM = 0; |
| 1444 | if (nPartitions == 1) { | 1443 | if (nPartitions == 1) { |
| 1445 | colorEndpointMode[0] = strm.ReadBits(4); | 1444 | colorEndpos32Mode[0] = strm.ReadBits(4); |
| 1446 | partitionIndex = 0; | 1445 | partitionIndex = 0; |
| 1447 | } else { | 1446 | } else { |
| 1448 | partitionIndex = strm.ReadBits(10); | 1447 | partitionIndex = strm.ReadBits(10); |
| @@ -1450,7 +1449,7 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1450 | } | 1449 | } |
| 1451 | u32 baseMode = (baseCEM & 3); | 1450 | u32 baseMode = (baseCEM & 3); |
| 1452 | 1451 | ||
| 1453 | // Remaining bits are color endpoint data... | 1452 | // Remaining bits are color endpos32 data... |
| 1454 | u32 nWeightBits = weightParams.GetPackedBitSize(); | 1453 | u32 nWeightBits = weightParams.GetPackedBitSize(); |
| 1455 | s32 remainingBits = 128 - nWeightBits - strm.GetBitsRead(); | 1454 | s32 remainingBits = 128 - nWeightBits - strm.GetBitsRead(); |
| 1456 | 1455 | ||
| @@ -1486,7 +1485,7 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1486 | while (remainingBits > 0) { | 1485 | while (remainingBits > 0) { |
| 1487 | u32 nb = std::min(remainingBits, 8); | 1486 | u32 nb = std::min(remainingBits, 8); |
| 1488 | u32 b = strm.ReadBits(nb); | 1487 | u32 b = strm.ReadBits(nb); |
| 1489 | colorEndpointStream.WriteBits(b, nb); | 1488 | colorEndpos32Stream.WriteBits(b, nb); |
| 1490 | remainingBits -= 8; | 1489 | remainingBits -= 8; |
| 1491 | } | 1490 | } |
| 1492 | 1491 | ||
| @@ -1513,34 +1512,34 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1513 | } | 1512 | } |
| 1514 | 1513 | ||
| 1515 | for (u32 i = 0; i < nPartitions; i++) { | 1514 | for (u32 i = 0; i < nPartitions; i++) { |
| 1516 | colorEndpointMode[i] = baseMode; | 1515 | colorEndpos32Mode[i] = baseMode; |
| 1517 | if (!(C[i])) | 1516 | if (!(C[i])) |
| 1518 | colorEndpointMode[i] -= 1; | 1517 | colorEndpos32Mode[i] -= 1; |
| 1519 | colorEndpointMode[i] <<= 2; | 1518 | colorEndpos32Mode[i] <<= 2; |
| 1520 | colorEndpointMode[i] |= M[i]; | 1519 | colorEndpos32Mode[i] |= M[i]; |
| 1521 | } | 1520 | } |
| 1522 | } else if (nPartitions > 1) { | 1521 | } else if (nPartitions > 1) { |
| 1523 | u32 CEM = baseCEM >> 2; | 1522 | u32 CEM = baseCEM >> 2; |
| 1524 | for (u32 i = 0; i < nPartitions; i++) { | 1523 | for (u32 i = 0; i < nPartitions; i++) { |
| 1525 | colorEndpointMode[i] = CEM; | 1524 | colorEndpos32Mode[i] = CEM; |
| 1526 | } | 1525 | } |
| 1527 | } | 1526 | } |
| 1528 | 1527 | ||
| 1529 | // Make sure everything up till here is sane. | 1528 | // Make sure everything up till here is sane. |
| 1530 | for (u32 i = 0; i < nPartitions; i++) { | 1529 | for (u32 i = 0; i < nPartitions; i++) { |
| 1531 | assert(colorEndpointMode[i] < 16); | 1530 | assert(colorEndpos32Mode[i] < 16); |
| 1532 | } | 1531 | } |
| 1533 | assert(strm.GetBitsRead() + weightParams.GetPackedBitSize() == 128); | 1532 | assert(strm.GetBitsRead() + weightParams.GetPackedBitSize() == 128); |
| 1534 | 1533 | ||
| 1535 | // Decode both color data and texel weight data | 1534 | // Decode both color data and texel weight data |
| 1536 | u32 colorValues[32]; // Four values, two endpoints, four maximum paritions | 1535 | u32 colorValues[32]; // Four values, two endpos32s, four maximum paritions |
| 1537 | DecodeColorValues(colorValues, colorEndpointData, colorEndpointMode, nPartitions, | 1536 | DecodeColorValues(colorValues, colorEndpos32Data, colorEndpos32Mode, nPartitions, |
| 1538 | colorDataBits); | 1537 | colorDataBits); |
| 1539 | 1538 | ||
| 1540 | Pixel endpoints[4][2]; | 1539 | Pixel endpos32s[4][2]; |
| 1541 | const u32* colorValuesPtr = colorValues; | 1540 | const u32* colorValuesPtr = colorValues; |
| 1542 | for (u32 i = 0; i < nPartitions; i++) { | 1541 | for (u32 i = 0; i < nPartitions; i++) { |
| 1543 | ComputeEndpoints(endpoints[i][0], endpoints[i][1], colorValuesPtr, colorEndpointMode[i]); | 1542 | ComputeEndpos32s(endpos32s[i][0], endpos32s[i][1], colorValuesPtr, colorEndpos32Mode[i]); |
| 1544 | } | 1543 | } |
| 1545 | 1544 | ||
| 1546 | // Read the texel weight data.. | 1545 | // Read the texel weight data.. |
| @@ -1551,8 +1550,8 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1551 | for (u32 i = 0; i < 8; i++) { | 1550 | for (u32 i = 0; i < 8; i++) { |
| 1552 | // Taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64Bits | 1551 | // Taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64Bits |
| 1553 | #define REVERSE_BYTE(b) (((b)*0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32 | 1552 | #define REVERSE_BYTE(b) (((b)*0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32 |
| 1554 | unsigned char a = static_cast<unsigned char>(REVERSE_BYTE(texelWeightData[i])); | 1553 | u8 a = static_cast<u8>(REVERSE_BYTE(texelWeightData[i])); |
| 1555 | unsigned char b = static_cast<unsigned char>(REVERSE_BYTE(texelWeightData[15 - i])); | 1554 | u8 b = static_cast<u8>(REVERSE_BYTE(texelWeightData[15 - i])); |
| 1556 | #undef REVERSE_BYTE | 1555 | #undef REVERSE_BYTE |
| 1557 | 1556 | ||
| 1558 | texelWeightData[i] = b; | 1557 | texelWeightData[i] = b; |
| @@ -1577,7 +1576,7 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1577 | u32 weights[2][144]; | 1576 | u32 weights[2][144]; |
| 1578 | UnquantizeTexelWeights(weights, texelWeightValues, weightParams, blockWidth, blockHeight); | 1577 | UnquantizeTexelWeights(weights, texelWeightValues, weightParams, blockWidth, blockHeight); |
| 1579 | 1578 | ||
| 1580 | // Now that we have endpoints and weights, we can interpolate and generate | 1579 | // Now that we have endpos32s and weights, we can s32erpolate and generate |
| 1581 | // the proper decoding... | 1580 | // the proper decoding... |
| 1582 | for (u32 j = 0; j < blockHeight; j++) | 1581 | for (u32 j = 0; j < blockHeight; j++) |
| 1583 | for (u32 i = 0; i < blockWidth; i++) { | 1582 | for (u32 i = 0; i < blockWidth; i++) { |
| @@ -1587,9 +1586,9 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1587 | 1586 | ||
| 1588 | Pixel p; | 1587 | Pixel p; |
| 1589 | for (u32 c = 0; c < 4; c++) { | 1588 | for (u32 c = 0; c < 4; c++) { |
| 1590 | u32 C0 = endpoints[partition][0].Component(c); | 1589 | u32 C0 = endpos32s[partition][0].Component(c); |
| 1591 | C0 = Replicate(C0, 8, 16); | 1590 | C0 = Replicate(C0, 8, 16); |
| 1592 | u32 C1 = endpoints[partition][1].Component(c); | 1591 | u32 C1 = endpos32s[partition][1].Component(c); |
| 1593 | C1 = Replicate(C1, 8, 16); | 1592 | C1 = Replicate(C1, 8, 16); |
| 1594 | 1593 | ||
| 1595 | u32 plane = 0; | 1594 | u32 plane = 0; |