diff options
| author | 2020-03-13 22:22:27 -0300 | |
|---|---|---|
| committer | 2020-03-13 22:22:27 -0300 | |
| commit | 731a9a322e5b0623a5700cccc52307163c51c564 (patch) | |
| tree | a0aac09c432fa56409468e0118640acade61eeb1 /src | |
| parent | astc: Use 'enum class' instead of 'enum' for EIntegerEncoding (diff) | |
| download | yuzu-731a9a322e5b0623a5700cccc52307163c51c564.tar.gz yuzu-731a9a322e5b0623a5700cccc52307163c51c564.tar.xz yuzu-731a9a322e5b0623a5700cccc52307163c51c564.zip | |
astc: Use common types instead of stdint.h integer types
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/textures/astc.cpp | 566 |
1 files changed, 282 insertions, 284 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index af5a6c4ce..dcfab4dad 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp | |||
| @@ -21,6 +21,8 @@ | |||
| 21 | #include <cstring> | 21 | #include <cstring> |
| 22 | #include <vector> | 22 | #include <vector> |
| 23 | 23 | ||
| 24 | #include "common/common_types.h" | ||
| 25 | |||
| 24 | #include "video_core/textures/astc.h" | 26 | #include "video_core/textures/astc.h" |
| 25 | 27 | ||
| 26 | class InputBitStream { | 28 | class InputBitStream { |
| @@ -123,20 +125,20 @@ public: | |||
| 123 | Bits(const Bits&) = delete; | 125 | Bits(const Bits&) = delete; |
| 124 | Bits& operator=(const Bits&) = delete; | 126 | Bits& operator=(const Bits&) = delete; |
| 125 | 127 | ||
| 126 | uint8_t operator[](uint32_t bitPos) const { | 128 | u8 operator[](u32 bitPos) const { |
| 127 | return static_cast<uint8_t>((m_Bits >> bitPos) & 1); | 129 | return static_cast<u8>((m_Bits >> bitPos) & 1); |
| 128 | } | 130 | } |
| 129 | 131 | ||
| 130 | IntType operator()(uint32_t start, uint32_t end) const { | 132 | IntType operator()(u32 start, u32 end) const { |
| 131 | if (start == end) { | 133 | if (start == end) { |
| 132 | return (*this)[start]; | 134 | return (*this)[start]; |
| 133 | } else if (start > end) { | 135 | } else if (start > end) { |
| 134 | uint32_t t = start; | 136 | u32 t = start; |
| 135 | start = end; | 137 | start = end; |
| 136 | end = t; | 138 | end = t; |
| 137 | } | 139 | } |
| 138 | 140 | ||
| 139 | uint64_t mask = (1 << (end - start + 1)) - 1; | 141 | u64 mask = (1 << (end - start + 1)) - 1; |
| 140 | return (m_Bits >> start) & static_cast<IntType>(mask); | 142 | return (m_Bits >> start) & static_cast<IntType>(mask); |
| 141 | } | 143 | } |
| 142 | 144 | ||
| @@ -149,11 +151,11 @@ enum class IntegerEncoding { JustBits, Quint, Trit }; | |||
| 149 | class IntegerEncodedValue { | 151 | class IntegerEncodedValue { |
| 150 | private: | 152 | private: |
| 151 | const IntegerEncoding m_Encoding; | 153 | const IntegerEncoding m_Encoding; |
| 152 | const uint32_t m_NumBits; | 154 | const u32 m_NumBits; |
| 153 | uint32_t m_BitValue; | 155 | u32 m_BitValue; |
| 154 | union { | 156 | union { |
| 155 | uint32_t m_QuintValue; | 157 | u32 m_QuintValue; |
| 156 | uint32_t m_TritValue; | 158 | u32 m_TritValue; |
| 157 | }; | 159 | }; |
| 158 | 160 | ||
| 159 | public: | 161 | public: |
| @@ -164,34 +166,34 @@ public: | |||
| 164 | return *this; | 166 | return *this; |
| 165 | } | 167 | } |
| 166 | 168 | ||
| 167 | IntegerEncodedValue(IntegerEncoding encoding, uint32_t numBits) | 169 | IntegerEncodedValue(IntegerEncoding encoding, u32 numBits) |
| 168 | : m_Encoding(encoding), m_NumBits(numBits) {} | 170 | : m_Encoding(encoding), m_NumBits(numBits) {} |
| 169 | 171 | ||
| 170 | IntegerEncoding GetEncoding() const { | 172 | IntegerEncoding GetEncoding() const { |
| 171 | return m_Encoding; | 173 | return m_Encoding; |
| 172 | } | 174 | } |
| 173 | uint32_t BaseBitLength() const { | 175 | u32 BaseBitLength() const { |
| 174 | return m_NumBits; | 176 | return m_NumBits; |
| 175 | } | 177 | } |
| 176 | 178 | ||
| 177 | uint32_t GetBitValue() const { | 179 | u32 GetBitValue() const { |
| 178 | return m_BitValue; | 180 | return m_BitValue; |
| 179 | } | 181 | } |
| 180 | void SetBitValue(uint32_t val) { | 182 | void SetBitValue(u32 val) { |
| 181 | m_BitValue = val; | 183 | m_BitValue = val; |
| 182 | } | 184 | } |
| 183 | 185 | ||
| 184 | uint32_t GetTritValue() const { | 186 | u32 GetTritValue() const { |
| 185 | return m_TritValue; | 187 | return m_TritValue; |
| 186 | } | 188 | } |
| 187 | void SetTritValue(uint32_t val) { | 189 | void SetTritValue(u32 val) { |
| 188 | m_TritValue = val; | 190 | m_TritValue = val; |
| 189 | } | 191 | } |
| 190 | 192 | ||
| 191 | uint32_t GetQuintValue() const { | 193 | u32 GetQuintValue() const { |
| 192 | return m_QuintValue; | 194 | return m_QuintValue; |
| 193 | } | 195 | } |
| 194 | void SetQuintValue(uint32_t val) { | 196 | void SetQuintValue(u32 val) { |
| 195 | m_QuintValue = val; | 197 | m_QuintValue = val; |
| 196 | } | 198 | } |
| 197 | 199 | ||
| @@ -200,8 +202,8 @@ public: | |||
| 200 | } | 202 | } |
| 201 | 203 | ||
| 202 | // Returns the number of bits required to encode nVals values. | 204 | // Returns the number of bits required to encode nVals values. |
| 203 | uint32_t GetBitLength(uint32_t nVals) const { | 205 | u32 GetBitLength(u32 nVals) const { |
| 204 | uint32_t totalBits = m_NumBits * nVals; | 206 | u32 totalBits = m_NumBits * nVals; |
| 205 | if (m_Encoding == IntegerEncoding::Trit) { | 207 | if (m_Encoding == IntegerEncoding::Trit) { |
| 206 | totalBits += (nVals * 8 + 4) / 5; | 208 | totalBits += (nVals * 8 + 4) / 5; |
| 207 | } else if (m_Encoding == IntegerEncoding::Quint) { | 209 | } else if (m_Encoding == IntegerEncoding::Quint) { |
| @@ -211,8 +213,8 @@ public: | |||
| 211 | } | 213 | } |
| 212 | 214 | ||
| 213 | // Count the number of bits set in a number. | 215 | // Count the number of bits set in a number. |
| 214 | static inline uint32_t Popcnt(uint32_t n) { | 216 | static inline u32 Popcnt(u32 n) { |
| 215 | uint32_t c; | 217 | u32 c; |
| 216 | for (c = 0; n; c++) { | 218 | for (c = 0; n; c++) { |
| 217 | n &= n - 1; | 219 | n &= n - 1; |
| 218 | } | 220 | } |
| @@ -221,9 +223,9 @@ public: | |||
| 221 | 223 | ||
| 222 | // Returns a new instance of this struct that corresponds to the | 224 | // Returns a new instance of this struct that corresponds to the |
| 223 | // can take no more than maxval values | 225 | // can take no more than maxval values |
| 224 | static IntegerEncodedValue CreateEncoding(uint32_t maxVal) { | 226 | static IntegerEncodedValue CreateEncoding(u32 maxVal) { |
| 225 | while (maxVal > 0) { | 227 | while (maxVal > 0) { |
| 226 | uint32_t check = maxVal + 1; | 228 | u32 check = maxVal + 1; |
| 227 | 229 | ||
| 228 | // Is maxVal a power of two? | 230 | // Is maxVal a power of two? |
| 229 | if (!(check & (check - 1))) { | 231 | if (!(check & (check - 1))) { |
| @@ -251,12 +253,12 @@ public: | |||
| 251 | // bitstream. We must know beforehand what the maximum possible | 253 | // bitstream. We must know beforehand what the maximum possible |
| 252 | // value is, and how many values we're decoding. | 254 | // value is, and how many values we're decoding. |
| 253 | static void DecodeIntegerSequence(std::vector<IntegerEncodedValue>& result, | 255 | static void DecodeIntegerSequence(std::vector<IntegerEncodedValue>& result, |
| 254 | InputBitStream& bits, uint32_t maxRange, uint32_t nValues) { | 256 | InputBitStream& bits, u32 maxRange, u32 nValues) { |
| 255 | // Determine encoding parameters | 257 | // Determine encoding parameters |
| 256 | IntegerEncodedValue val = IntegerEncodedValue::CreateEncoding(maxRange); | 258 | IntegerEncodedValue val = IntegerEncodedValue::CreateEncoding(maxRange); |
| 257 | 259 | ||
| 258 | // Start decoding | 260 | // Start decoding |
| 259 | uint32_t nValsDecoded = 0; | 261 | u32 nValsDecoded = 0; |
| 260 | while (nValsDecoded < nValues) { | 262 | while (nValsDecoded < nValues) { |
| 261 | switch (val.GetEncoding()) { | 263 | switch (val.GetEncoding()) { |
| 262 | case IntegerEncoding::Quint: | 264 | case IntegerEncoding::Quint: |
| @@ -280,11 +282,11 @@ public: | |||
| 280 | 282 | ||
| 281 | private: | 283 | private: |
| 282 | static void DecodeTritBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, | 284 | static void DecodeTritBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, |
| 283 | uint32_t nBitsPerValue) { | 285 | u32 nBitsPerValue) { |
| 284 | // Implement the algorithm in section C.2.12 | 286 | // Implement the algorithm in section C.2.12 |
| 285 | uint32_t m[5]; | 287 | u32 m[5]; |
| 286 | uint32_t t[5]; | 288 | u32 t[5]; |
| 287 | uint32_t T; | 289 | u32 T; |
| 288 | 290 | ||
| 289 | // Read the trit encoded block according to | 291 | // Read the trit encoded block according to |
| 290 | // table C.2.14 | 292 | // table C.2.14 |
| @@ -299,9 +301,9 @@ private: | |||
| 299 | m[4] = bits.ReadBits(nBitsPerValue); | 301 | m[4] = bits.ReadBits(nBitsPerValue); |
| 300 | T |= bits.ReadBit() << 7; | 302 | T |= bits.ReadBit() << 7; |
| 301 | 303 | ||
| 302 | uint32_t C = 0; | 304 | u32 C = 0; |
| 303 | 305 | ||
| 304 | Bits<uint32_t> Tb(T); | 306 | Bits<u32> Tb(T); |
| 305 | if (Tb(2, 4) == 7) { | 307 | if (Tb(2, 4) == 7) { |
| 306 | C = (Tb(5, 7) << 2) | Tb(0, 1); | 308 | C = (Tb(5, 7) << 2) | Tb(0, 1); |
| 307 | t[4] = t[3] = 2; | 309 | t[4] = t[3] = 2; |
| @@ -316,7 +318,7 @@ private: | |||
| 316 | } | 318 | } |
| 317 | } | 319 | } |
| 318 | 320 | ||
| 319 | Bits<uint32_t> Cb(C); | 321 | Bits<u32> Cb(C); |
| 320 | if (Cb(0, 1) == 3) { | 322 | if (Cb(0, 1) == 3) { |
| 321 | t[2] = 2; | 323 | t[2] = 2; |
| 322 | t[1] = Cb[4]; | 324 | t[1] = Cb[4]; |
| @@ -331,7 +333,7 @@ private: | |||
| 331 | t[0] = (Cb[1] << 1) | (Cb[0] & ~Cb[1]); | 333 | t[0] = (Cb[1] << 1) | (Cb[0] & ~Cb[1]); |
| 332 | } | 334 | } |
| 333 | 335 | ||
| 334 | for (uint32_t i = 0; i < 5; i++) { | 336 | for (u32 i = 0; i < 5; i++) { |
| 335 | IntegerEncodedValue val(IntegerEncoding::Trit, nBitsPerValue); | 337 | IntegerEncodedValue val(IntegerEncoding::Trit, nBitsPerValue); |
| 336 | val.SetBitValue(m[i]); | 338 | val.SetBitValue(m[i]); |
| 337 | val.SetTritValue(t[i]); | 339 | val.SetTritValue(t[i]); |
| @@ -340,11 +342,11 @@ private: | |||
| 340 | } | 342 | } |
| 341 | 343 | ||
| 342 | static void DecodeQuintBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, | 344 | static void DecodeQuintBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, |
| 343 | uint32_t nBitsPerValue) { | 345 | u32 nBitsPerValue) { |
| 344 | // Implement the algorithm in section C.2.12 | 346 | // Implement the algorithm in section C.2.12 |
| 345 | uint32_t m[3]; | 347 | u32 m[3]; |
| 346 | uint32_t q[3]; | 348 | u32 q[3]; |
| 347 | uint32_t Q; | 349 | u32 Q; |
| 348 | 350 | ||
| 349 | // Read the trit encoded block according to | 351 | // Read the trit encoded block according to |
| 350 | // table C.2.15 | 352 | // table C.2.15 |
| @@ -355,12 +357,12 @@ private: | |||
| 355 | m[2] = bits.ReadBits(nBitsPerValue); | 357 | m[2] = bits.ReadBits(nBitsPerValue); |
| 356 | Q |= bits.ReadBits(2) << 5; | 358 | Q |= bits.ReadBits(2) << 5; |
| 357 | 359 | ||
| 358 | Bits<uint32_t> Qb(Q); | 360 | Bits<u32> Qb(Q); |
| 359 | if (Qb(1, 2) == 3 && Qb(5, 6) == 0) { | 361 | if (Qb(1, 2) == 3 && Qb(5, 6) == 0) { |
| 360 | q[0] = q[1] = 4; | 362 | q[0] = q[1] = 4; |
| 361 | q[2] = (Qb[0] << 2) | ((Qb[4] & ~Qb[0]) << 1) | (Qb[3] & ~Qb[0]); | 363 | q[2] = (Qb[0] << 2) | ((Qb[4] & ~Qb[0]) << 1) | (Qb[3] & ~Qb[0]); |
| 362 | } else { | 364 | } else { |
| 363 | uint32_t C = 0; | 365 | u32 C = 0; |
| 364 | if (Qb(1, 2) == 3) { | 366 | if (Qb(1, 2) == 3) { |
| 365 | q[2] = 4; | 367 | q[2] = 4; |
| 366 | C = (Qb(3, 4) << 3) | ((~Qb(5, 6) & 3) << 1) | Qb[0]; | 368 | C = (Qb(3, 4) << 3) | ((~Qb(5, 6) & 3) << 1) | Qb[0]; |
| @@ -369,7 +371,7 @@ private: | |||
| 369 | C = Qb(0, 4); | 371 | C = Qb(0, 4); |
| 370 | } | 372 | } |
| 371 | 373 | ||
| 372 | Bits<uint32_t> Cb(C); | 374 | Bits<u32> Cb(C); |
| 373 | if (Cb(0, 2) == 5) { | 375 | if (Cb(0, 2) == 5) { |
| 374 | q[1] = 4; | 376 | q[1] = 4; |
| 375 | q[0] = Cb(3, 4); | 377 | q[0] = Cb(3, 4); |
| @@ -379,7 +381,7 @@ private: | |||
| 379 | } | 381 | } |
| 380 | } | 382 | } |
| 381 | 383 | ||
| 382 | for (uint32_t i = 0; i < 3; i++) { | 384 | for (u32 i = 0; i < 3; i++) { |
| 383 | IntegerEncodedValue val(IntegerEncoding::Quint, nBitsPerValue); | 385 | IntegerEncodedValue val(IntegerEncoding::Quint, nBitsPerValue); |
| 384 | val.m_BitValue = m[i]; | 386 | val.m_BitValue = m[i]; |
| 385 | val.m_QuintValue = q[i]; | 387 | val.m_QuintValue = q[i]; |
| @@ -391,17 +393,17 @@ private: | |||
| 391 | namespace ASTCC { | 393 | namespace ASTCC { |
| 392 | 394 | ||
| 393 | struct TexelWeightParams { | 395 | struct TexelWeightParams { |
| 394 | uint32_t m_Width = 0; | 396 | u32 m_Width = 0; |
| 395 | uint32_t m_Height = 0; | 397 | u32 m_Height = 0; |
| 396 | bool m_bDualPlane = false; | 398 | bool m_bDualPlane = false; |
| 397 | uint32_t m_MaxWeight = 0; | 399 | u32 m_MaxWeight = 0; |
| 398 | bool m_bError = false; | 400 | bool m_bError = false; |
| 399 | bool m_bVoidExtentLDR = false; | 401 | bool m_bVoidExtentLDR = false; |
| 400 | bool m_bVoidExtentHDR = false; | 402 | bool m_bVoidExtentHDR = false; |
| 401 | 403 | ||
| 402 | uint32_t GetPackedBitSize() const { | 404 | u32 GetPackedBitSize() const { |
| 403 | // How many indices do we have? | 405 | // How many indices do we have? |
| 404 | uint32_t nIdxs = m_Height * m_Width; | 406 | u32 nIdxs = m_Height * m_Width; |
| 405 | if (m_bDualPlane) { | 407 | if (m_bDualPlane) { |
| 406 | nIdxs *= 2; | 408 | nIdxs *= 2; |
| 407 | } | 409 | } |
| @@ -409,8 +411,8 @@ struct TexelWeightParams { | |||
| 409 | return IntegerEncodedValue::CreateEncoding(m_MaxWeight).GetBitLength(nIdxs); | 411 | return IntegerEncodedValue::CreateEncoding(m_MaxWeight).GetBitLength(nIdxs); |
| 410 | } | 412 | } |
| 411 | 413 | ||
| 412 | uint32_t GetNumWeightValues() const { | 414 | u32 GetNumWeightValues() const { |
| 413 | uint32_t ret = m_Width * m_Height; | 415 | u32 ret = m_Width * m_Height; |
| 414 | if (m_bDualPlane) { | 416 | if (m_bDualPlane) { |
| 415 | ret *= 2; | 417 | ret *= 2; |
| 416 | } | 418 | } |
| @@ -422,7 +424,7 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 422 | TexelWeightParams params; | 424 | TexelWeightParams params; |
| 423 | 425 | ||
| 424 | // Read the entire block mode all at once | 426 | // Read the entire block mode all at once |
| 425 | uint16_t modeBits = static_cast<uint16_t>(strm.ReadBits(11)); | 427 | u16 modeBits = static_cast<u16>(strm.ReadBits(11)); |
| 426 | 428 | ||
| 427 | // Does this match the void extent block mode? | 429 | // Does this match the void extent block mode? |
| 428 | if ((modeBits & 0x01FF) == 0x1FC) { | 430 | if ((modeBits & 0x01FF) == 0x1FC) { |
| @@ -457,7 +459,7 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 457 | // of the block mode. Layout is determined by a number | 459 | // of the block mode. Layout is determined by a number |
| 458 | // between 0 and 9 corresponding to table C.2.8 of the | 460 | // between 0 and 9 corresponding to table C.2.8 of the |
| 459 | // ASTC spec. | 461 | // ASTC spec. |
| 460 | uint32_t layout = 0; | 462 | u32 layout = 0; |
| 461 | 463 | ||
| 462 | if ((modeBits & 0x1) || (modeBits & 0x2)) { | 464 | if ((modeBits & 0x1) || (modeBits & 0x2)) { |
| 463 | // layout is in [0-4] | 465 | // layout is in [0-4] |
| @@ -509,7 +511,7 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 509 | assert(layout < 10); | 511 | assert(layout < 10); |
| 510 | 512 | ||
| 511 | // Determine R | 513 | // Determine R |
| 512 | uint32_t R = !!(modeBits & 0x10); | 514 | u32 R = !!(modeBits & 0x10); |
| 513 | if (layout < 5) { | 515 | if (layout < 5) { |
| 514 | R |= (modeBits & 0x3) << 1; | 516 | R |= (modeBits & 0x3) << 1; |
| 515 | } else { | 517 | } else { |
| @@ -520,54 +522,54 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 520 | // Determine width & height | 522 | // Determine width & height |
| 521 | switch (layout) { | 523 | switch (layout) { |
| 522 | case 0: { | 524 | case 0: { |
| 523 | uint32_t A = (modeBits >> 5) & 0x3; | 525 | u32 A = (modeBits >> 5) & 0x3; |
| 524 | uint32_t B = (modeBits >> 7) & 0x3; | 526 | u32 B = (modeBits >> 7) & 0x3; |
| 525 | params.m_Width = B + 4; | 527 | params.m_Width = B + 4; |
| 526 | params.m_Height = A + 2; | 528 | params.m_Height = A + 2; |
| 527 | break; | 529 | break; |
| 528 | } | 530 | } |
| 529 | 531 | ||
| 530 | case 1: { | 532 | case 1: { |
| 531 | uint32_t A = (modeBits >> 5) & 0x3; | 533 | u32 A = (modeBits >> 5) & 0x3; |
| 532 | uint32_t B = (modeBits >> 7) & 0x3; | 534 | u32 B = (modeBits >> 7) & 0x3; |
| 533 | params.m_Width = B + 8; | 535 | params.m_Width = B + 8; |
| 534 | params.m_Height = A + 2; | 536 | params.m_Height = A + 2; |
| 535 | break; | 537 | break; |
| 536 | } | 538 | } |
| 537 | 539 | ||
| 538 | case 2: { | 540 | case 2: { |
| 539 | uint32_t A = (modeBits >> 5) & 0x3; | 541 | u32 A = (modeBits >> 5) & 0x3; |
| 540 | uint32_t B = (modeBits >> 7) & 0x3; | 542 | u32 B = (modeBits >> 7) & 0x3; |
| 541 | params.m_Width = A + 2; | 543 | params.m_Width = A + 2; |
| 542 | params.m_Height = B + 8; | 544 | params.m_Height = B + 8; |
| 543 | break; | 545 | break; |
| 544 | } | 546 | } |
| 545 | 547 | ||
| 546 | case 3: { | 548 | case 3: { |
| 547 | uint32_t A = (modeBits >> 5) & 0x3; | 549 | u32 A = (modeBits >> 5) & 0x3; |
| 548 | uint32_t B = (modeBits >> 7) & 0x1; | 550 | u32 B = (modeBits >> 7) & 0x1; |
| 549 | params.m_Width = A + 2; | 551 | params.m_Width = A + 2; |
| 550 | params.m_Height = B + 6; | 552 | params.m_Height = B + 6; |
| 551 | break; | 553 | break; |
| 552 | } | 554 | } |
| 553 | 555 | ||
| 554 | case 4: { | 556 | case 4: { |
| 555 | uint32_t A = (modeBits >> 5) & 0x3; | 557 | u32 A = (modeBits >> 5) & 0x3; |
| 556 | uint32_t B = (modeBits >> 7) & 0x1; | 558 | u32 B = (modeBits >> 7) & 0x1; |
| 557 | params.m_Width = B + 2; | 559 | params.m_Width = B + 2; |
| 558 | params.m_Height = A + 2; | 560 | params.m_Height = A + 2; |
| 559 | break; | 561 | break; |
| 560 | } | 562 | } |
| 561 | 563 | ||
| 562 | case 5: { | 564 | case 5: { |
| 563 | uint32_t A = (modeBits >> 5) & 0x3; | 565 | u32 A = (modeBits >> 5) & 0x3; |
| 564 | params.m_Width = 12; | 566 | params.m_Width = 12; |
| 565 | params.m_Height = A + 2; | 567 | params.m_Height = A + 2; |
| 566 | break; | 568 | break; |
| 567 | } | 569 | } |
| 568 | 570 | ||
| 569 | case 6: { | 571 | case 6: { |
| 570 | uint32_t A = (modeBits >> 5) & 0x3; | 572 | u32 A = (modeBits >> 5) & 0x3; |
| 571 | params.m_Width = A + 2; | 573 | params.m_Width = A + 2; |
| 572 | params.m_Height = 12; | 574 | params.m_Height = 12; |
| 573 | break; | 575 | break; |
| @@ -586,8 +588,8 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 586 | } | 588 | } |
| 587 | 589 | ||
| 588 | case 9: { | 590 | case 9: { |
| 589 | uint32_t A = (modeBits >> 5) & 0x3; | 591 | u32 A = (modeBits >> 5) & 0x3; |
| 590 | uint32_t B = (modeBits >> 9) & 0x3; | 592 | u32 B = (modeBits >> 9) & 0x3; |
| 591 | params.m_Width = A + 6; | 593 | params.m_Width = A + 6; |
| 592 | params.m_Height = B + 6; | 594 | params.m_Height = B + 6; |
| 593 | break; | 595 | break; |
| @@ -605,10 +607,10 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 605 | bool H = (layout != 9) && (modeBits & 0x200); | 607 | bool H = (layout != 9) && (modeBits & 0x200); |
| 606 | 608 | ||
| 607 | if (H) { | 609 | if (H) { |
| 608 | const uint32_t maxWeights[6] = {9, 11, 15, 19, 23, 31}; | 610 | const u32 maxWeights[6] = {9, 11, 15, 19, 23, 31}; |
| 609 | params.m_MaxWeight = maxWeights[R - 2]; | 611 | params.m_MaxWeight = maxWeights[R - 2]; |
| 610 | } else { | 612 | } else { |
| 611 | const uint32_t maxWeights[6] = {1, 2, 3, 4, 5, 7}; | 613 | const u32 maxWeights[6] = {1, 2, 3, 4, 5, 7}; |
| 612 | params.m_MaxWeight = maxWeights[R - 2]; | 614 | params.m_MaxWeight = maxWeights[R - 2]; |
| 613 | } | 615 | } |
| 614 | 616 | ||
| @@ -617,32 +619,32 @@ static TexelWeightParams DecodeBlockInfo(InputBitStream& strm) { | |||
| 617 | return params; | 619 | return params; |
| 618 | } | 620 | } |
| 619 | 621 | ||
| 620 | static void FillVoidExtentLDR(InputBitStream& strm, uint32_t* const outBuf, uint32_t blockWidth, | 622 | static void FillVoidExtentLDR(InputBitStream& strm, u32* const outBuf, u32 blockWidth, |
| 621 | uint32_t blockHeight) { | 623 | u32 blockHeight) { |
| 622 | // Don't actually care about the void extent, just read the bits... | 624 | // Don't actually care about the void extent, just read the bits... |
| 623 | for (int i = 0; i < 4; ++i) { | 625 | for (int i = 0; i < 4; ++i) { |
| 624 | strm.ReadBits(13); | 626 | strm.ReadBits(13); |
| 625 | } | 627 | } |
| 626 | 628 | ||
| 627 | // Decode the RGBA components and renormalize them to the range [0, 255] | 629 | // Decode the RGBA components and renormalize them to the range [0, 255] |
| 628 | uint16_t r = static_cast<uint16_t>(strm.ReadBits(16)); | 630 | u16 r = static_cast<u16>(strm.ReadBits(16)); |
| 629 | uint16_t g = static_cast<uint16_t>(strm.ReadBits(16)); | 631 | u16 g = static_cast<u16>(strm.ReadBits(16)); |
| 630 | uint16_t b = static_cast<uint16_t>(strm.ReadBits(16)); | 632 | u16 b = static_cast<u16>(strm.ReadBits(16)); |
| 631 | uint16_t a = static_cast<uint16_t>(strm.ReadBits(16)); | 633 | u16 a = static_cast<u16>(strm.ReadBits(16)); |
| 632 | 634 | ||
| 633 | uint32_t rgba = (r >> 8) | (g & 0xFF00) | (static_cast<uint32_t>(b) & 0xFF00) << 8 | | 635 | u32 rgba = (r >> 8) | (g & 0xFF00) | (static_cast<u32>(b) & 0xFF00) << 8 | |
| 634 | (static_cast<uint32_t>(a) & 0xFF00) << 16; | 636 | (static_cast<u32>(a) & 0xFF00) << 16; |
| 635 | 637 | ||
| 636 | for (uint32_t j = 0; j < blockHeight; j++) { | 638 | for (u32 j = 0; j < blockHeight; j++) { |
| 637 | for (uint32_t i = 0; i < blockWidth; i++) { | 639 | for (u32 i = 0; i < blockWidth; i++) { |
| 638 | outBuf[j * blockWidth + i] = rgba; | 640 | outBuf[j * blockWidth + i] = rgba; |
| 639 | } | 641 | } |
| 640 | } | 642 | } |
| 641 | } | 643 | } |
| 642 | 644 | ||
| 643 | static void FillError(uint32_t* outBuf, uint32_t blockWidth, uint32_t blockHeight) { | 645 | static void FillError(u32* outBuf, u32 blockWidth, u32 blockHeight) { |
| 644 | for (uint32_t j = 0; j < blockHeight; j++) { | 646 | for (u32 j = 0; j < blockHeight; j++) { |
| 645 | for (uint32_t i = 0; i < blockWidth; i++) { | 647 | for (u32 i = 0; i < blockWidth; i++) { |
| 646 | outBuf[j * blockWidth + i] = 0xFFFF00FF; | 648 | outBuf[j * blockWidth + i] = 0xFFFF00FF; |
| 647 | } | 649 | } |
| 648 | } | 650 | } |
| @@ -651,18 +653,18 @@ static void FillError(uint32_t* outBuf, uint32_t blockWidth, uint32_t blockHeigh | |||
| 651 | // Replicates low numBits such that [(toBit - 1):(toBit - 1 - fromBit)] | 653 | // Replicates low numBits such that [(toBit - 1):(toBit - 1 - fromBit)] |
| 652 | // is the same as [(numBits - 1):0] and repeats all the way down. | 654 | // is the same as [(numBits - 1):0] and repeats all the way down. |
| 653 | template <typename IntType> | 655 | template <typename IntType> |
| 654 | static IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) { | 656 | static IntType Replicate(const IntType& val, u32 numBits, u32 toBit) { |
| 655 | if (numBits == 0) | 657 | if (numBits == 0) |
| 656 | return 0; | 658 | return 0; |
| 657 | if (toBit == 0) | 659 | if (toBit == 0) |
| 658 | return 0; | 660 | return 0; |
| 659 | IntType v = val & static_cast<IntType>((1 << numBits) - 1); | 661 | IntType v = val & static_cast<IntType>((1 << numBits) - 1); |
| 660 | IntType res = v; | 662 | IntType res = v; |
| 661 | uint32_t reslen = numBits; | 663 | u32 reslen = numBits; |
| 662 | while (reslen < toBit) { | 664 | while (reslen < toBit) { |
| 663 | uint32_t comp = 0; | 665 | u32 comp = 0; |
| 664 | if (numBits > toBit - reslen) { | 666 | if (numBits > toBit - reslen) { |
| 665 | uint32_t newshift = toBit - reslen; | 667 | u32 newshift = toBit - reslen; |
| 666 | comp = numBits - newshift; | 668 | comp = numBits - newshift; |
| 667 | numBits = newshift; | 669 | numBits = newshift; |
| 668 | } | 670 | } |
| @@ -675,14 +677,14 @@ static IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) { | |||
| 675 | 677 | ||
| 676 | class Pixel { | 678 | class Pixel { |
| 677 | protected: | 679 | protected: |
| 678 | using ChannelType = int16_t; | 680 | using ChannelType = s16; |
| 679 | uint8_t m_BitDepth[4] = {8, 8, 8, 8}; | 681 | u8 m_BitDepth[4] = {8, 8, 8, 8}; |
| 680 | int16_t color[4] = {}; | 682 | s16 color[4] = {}; |
| 681 | 683 | ||
| 682 | public: | 684 | public: |
| 683 | Pixel() = default; | 685 | Pixel() = default; |
| 684 | Pixel(uint32_t a, uint32_t r, uint32_t g, uint32_t b, unsigned bitDepth = 8) | 686 | Pixel(u32 a, u32 r, u32 g, u32 b, unsigned bitDepth = 8) |
| 685 | : m_BitDepth{uint8_t(bitDepth), uint8_t(bitDepth), uint8_t(bitDepth), uint8_t(bitDepth)}, | 687 | : m_BitDepth{u8(bitDepth), u8(bitDepth), u8(bitDepth), u8(bitDepth)}, |
| 686 | color{static_cast<ChannelType>(a), static_cast<ChannelType>(r), | 688 | color{static_cast<ChannelType>(a), static_cast<ChannelType>(r), |
| 687 | static_cast<ChannelType>(g), static_cast<ChannelType>(b)} {} | 689 | static_cast<ChannelType>(g), static_cast<ChannelType>(b)} {} |
| 688 | 690 | ||
| @@ -691,22 +693,22 @@ public: | |||
| 691 | // significant bits when going from larger to smaller bit depth | 693 | // significant bits when going from larger to smaller bit depth |
| 692 | // or by repeating the most significant bits when going from | 694 | // or by repeating the most significant bits when going from |
| 693 | // smaller to larger bit depths. | 695 | // smaller to larger bit depths. |
| 694 | void ChangeBitDepth(const uint8_t (&depth)[4]) { | 696 | void ChangeBitDepth(const u8 (&depth)[4]) { |
| 695 | for (uint32_t i = 0; i < 4; i++) { | 697 | for (u32 i = 0; i < 4; i++) { |
| 696 | Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i], depth[i]); | 698 | Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i], depth[i]); |
| 697 | m_BitDepth[i] = depth[i]; | 699 | m_BitDepth[i] = depth[i]; |
| 698 | } | 700 | } |
| 699 | } | 701 | } |
| 700 | 702 | ||
| 701 | template <typename IntType> | 703 | template <typename IntType> |
| 702 | static float ConvertChannelToFloat(IntType channel, uint8_t bitDepth) { | 704 | static float ConvertChannelToFloat(IntType channel, u8 bitDepth) { |
| 703 | float denominator = static_cast<float>((1 << bitDepth) - 1); | 705 | float denominator = static_cast<float>((1 << bitDepth) - 1); |
| 704 | return static_cast<float>(channel) / denominator; | 706 | return static_cast<float>(channel) / denominator; |
| 705 | } | 707 | } |
| 706 | 708 | ||
| 707 | // Changes the bit depth of a single component. See the comment | 709 | // Changes the bit depth of a single component. See the comment |
| 708 | // above for how we do this. | 710 | // above for how we do this. |
| 709 | static ChannelType ChangeBitDepth(Pixel::ChannelType val, uint8_t oldDepth, uint8_t newDepth) { | 711 | static ChannelType ChangeBitDepth(Pixel::ChannelType val, u8 oldDepth, u8 newDepth) { |
| 710 | assert(newDepth <= 8); | 712 | assert(newDepth <= 8); |
| 711 | assert(oldDepth <= 8); | 713 | assert(oldDepth <= 8); |
| 712 | 714 | ||
| @@ -722,12 +724,11 @@ public: | |||
| 722 | if (newDepth == 0) { | 724 | if (newDepth == 0) { |
| 723 | return 0xFF; | 725 | return 0xFF; |
| 724 | } else { | 726 | } else { |
| 725 | uint8_t bitsWasted = static_cast<uint8_t>(oldDepth - newDepth); | 727 | u8 bitsWasted = static_cast<u8>(oldDepth - newDepth); |
| 726 | uint16_t v = static_cast<uint16_t>(val); | 728 | u16 v = static_cast<u16>(val); |
| 727 | v = static_cast<uint16_t>((v + (1 << (bitsWasted - 1))) >> bitsWasted); | 729 | v = static_cast<u16>((v + (1 << (bitsWasted - 1))) >> bitsWasted); |
| 728 | v = ::std::min<uint16_t>(::std::max<uint16_t>(0, v), | 730 | v = ::std::min<u16>(::std::max<u16>(0, v), static_cast<u16>((1 << newDepth) - 1)); |
| 729 | static_cast<uint16_t>((1 << newDepth) - 1)); | 731 | return static_cast<u8>(v); |
| 730 | return static_cast<uint8_t>(v); | ||
| 731 | } | 732 | } |
| 732 | } | 733 | } |
| 733 | 734 | ||
| @@ -759,14 +760,14 @@ public: | |||
| 759 | ChannelType& B() { | 760 | ChannelType& B() { |
| 760 | return color[3]; | 761 | return color[3]; |
| 761 | } | 762 | } |
| 762 | const ChannelType& Component(uint32_t idx) const { | 763 | const ChannelType& Component(u32 idx) const { |
| 763 | return color[idx]; | 764 | return color[idx]; |
| 764 | } | 765 | } |
| 765 | ChannelType& Component(uint32_t idx) { | 766 | ChannelType& Component(u32 idx) { |
| 766 | return color[idx]; | 767 | return color[idx]; |
| 767 | } | 768 | } |
| 768 | 769 | ||
| 769 | void GetBitDepth(uint8_t (&outDepth)[4]) const { | 770 | void GetBitDepth(u8 (&outDepth)[4]) const { |
| 770 | for (int i = 0; i < 4; i++) { | 771 | for (int i = 0; i < 4; i++) { |
| 771 | outDepth[i] = m_BitDepth[i]; | 772 | outDepth[i] = m_BitDepth[i]; |
| 772 | } | 773 | } |
| @@ -776,12 +777,12 @@ public: | |||
| 776 | // and then pack each channel into an R8G8B8A8 32-bit integer. We assume | 777 | // and then pack each channel into an R8G8B8A8 32-bit integer. We assume |
| 777 | // that the architecture is little-endian, so the alpha channel will end | 778 | // that the architecture is little-endian, so the alpha channel will end |
| 778 | // up in the most-significant byte. | 779 | // up in the most-significant byte. |
| 779 | uint32_t Pack() const { | 780 | u32 Pack() const { |
| 780 | Pixel eightBit(*this); | 781 | Pixel eightBit(*this); |
| 781 | const uint8_t eightBitDepth[4] = {8, 8, 8, 8}; | 782 | const u8 eightBitDepth[4] = {8, 8, 8, 8}; |
| 782 | eightBit.ChangeBitDepth(eightBitDepth); | 783 | eightBit.ChangeBitDepth(eightBitDepth); |
| 783 | 784 | ||
| 784 | uint32_t r = 0; | 785 | u32 r = 0; |
| 785 | r |= eightBit.A(); | 786 | r |= eightBit.A(); |
| 786 | r <<= 8; | 787 | r <<= 8; |
| 787 | r |= eightBit.B(); | 788 | r |= eightBit.B(); |
| @@ -794,7 +795,7 @@ public: | |||
| 794 | 795 | ||
| 795 | // Clamps the pixel to the range [0,255] | 796 | // Clamps the pixel to the range [0,255] |
| 796 | void ClampByte() { | 797 | void ClampByte() { |
| 797 | for (uint32_t i = 0; i < 4; i++) { | 798 | for (u32 i = 0; i < 4; i++) { |
| 798 | color[i] = (color[i] < 0) ? 0 : ((color[i] > 255) ? 255 : color[i]); | 799 | color[i] = (color[i] < 0) ? 0 : ((color[i] > 255) ? 255 : color[i]); |
| 799 | } | 800 | } |
| 800 | } | 801 | } |
| @@ -804,20 +805,20 @@ public: | |||
| 804 | } | 805 | } |
| 805 | }; | 806 | }; |
| 806 | 807 | ||
| 807 | static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* modes, | 808 | static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nPartitions, |
| 808 | const uint32_t nPartitions, const uint32_t nBitsForColorData) { | 809 | const u32 nBitsForColorData) { |
| 809 | // First figure out how many color values we have | 810 | // First figure out how many color values we have |
| 810 | uint32_t nValues = 0; | 811 | u32 nValues = 0; |
| 811 | for (uint32_t i = 0; i < nPartitions; i++) { | 812 | for (u32 i = 0; i < nPartitions; i++) { |
| 812 | nValues += ((modes[i] >> 2) + 1) << 1; | 813 | nValues += ((modes[i] >> 2) + 1) << 1; |
| 813 | } | 814 | } |
| 814 | 815 | ||
| 815 | // Then based on the number of values and the remaining number of bits, | 816 | // Then based on the number of values and the remaining number of bits, |
| 816 | // figure out the max value for each of them... | 817 | // figure out the max value for each of them... |
| 817 | uint32_t range = 256; | 818 | u32 range = 256; |
| 818 | while (--range > 0) { | 819 | while (--range > 0) { |
| 819 | IntegerEncodedValue val = IntegerEncodedValue::CreateEncoding(range); | 820 | IntegerEncodedValue val = IntegerEncodedValue::CreateEncoding(range); |
| 820 | uint32_t bitLength = val.GetBitLength(nValues); | 821 | u32 bitLength = val.GetBitLength(nValues); |
| 821 | if (bitLength <= nBitsForColorData) { | 822 | if (bitLength <= nBitsForColorData) { |
| 822 | // Find the smallest possible range that matches the given encoding | 823 | // Find the smallest possible range that matches the given encoding |
| 823 | while (--range > 0) { | 824 | while (--range > 0) { |
| @@ -840,7 +841,7 @@ static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* mode | |||
| 840 | 841 | ||
| 841 | // Once we have the decoded values, we need to dequantize them to the 0-255 range | 842 | // Once we have the decoded values, we need to dequantize them to the 0-255 range |
| 842 | // This procedure is outlined in ASTC spec C.2.13 | 843 | // This procedure is outlined in ASTC spec C.2.13 |
| 843 | uint32_t outIdx = 0; | 844 | u32 outIdx = 0; |
| 844 | for (auto itr = decodedColorValues.begin(); itr != decodedColorValues.end(); ++itr) { | 845 | for (auto itr = decodedColorValues.begin(); itr != decodedColorValues.end(); ++itr) { |
| 845 | // Have we already decoded all that we need? | 846 | // Have we already decoded all that we need? |
| 846 | if (outIdx >= nValues) { | 847 | if (outIdx >= nValues) { |
| @@ -848,12 +849,12 @@ static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* mode | |||
| 848 | } | 849 | } |
| 849 | 850 | ||
| 850 | const IntegerEncodedValue& val = *itr; | 851 | const IntegerEncodedValue& val = *itr; |
| 851 | uint32_t bitlen = val.BaseBitLength(); | 852 | u32 bitlen = val.BaseBitLength(); |
| 852 | uint32_t bitval = val.GetBitValue(); | 853 | u32 bitval = val.GetBitValue(); |
| 853 | 854 | ||
| 854 | assert(bitlen >= 1); | 855 | assert(bitlen >= 1); |
| 855 | 856 | ||
| 856 | uint32_t A = 0, B = 0, C = 0, D = 0; | 857 | u32 A = 0, B = 0, C = 0, D = 0; |
| 857 | // A is just the lsb replicated 9 times. | 858 | // A is just the lsb replicated 9 times. |
| 858 | A = Replicate(bitval & 1, 1, 9); | 859 | A = Replicate(bitval & 1, 1, 9); |
| 859 | 860 | ||
| @@ -876,35 +877,35 @@ static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* mode | |||
| 876 | case 2: { | 877 | case 2: { |
| 877 | C = 93; | 878 | C = 93; |
| 878 | // B = b000b0bb0 | 879 | // B = b000b0bb0 |
| 879 | uint32_t b = (bitval >> 1) & 1; | 880 | u32 b = (bitval >> 1) & 1; |
| 880 | B = (b << 8) | (b << 4) | (b << 2) | (b << 1); | 881 | B = (b << 8) | (b << 4) | (b << 2) | (b << 1); |
| 881 | } break; | 882 | } break; |
| 882 | 883 | ||
| 883 | case 3: { | 884 | case 3: { |
| 884 | C = 44; | 885 | C = 44; |
| 885 | // B = cb000cbcb | 886 | // B = cb000cbcb |
| 886 | uint32_t cb = (bitval >> 1) & 3; | 887 | u32 cb = (bitval >> 1) & 3; |
| 887 | B = (cb << 7) | (cb << 2) | cb; | 888 | B = (cb << 7) | (cb << 2) | cb; |
| 888 | } break; | 889 | } break; |
| 889 | 890 | ||
| 890 | case 4: { | 891 | case 4: { |
| 891 | C = 22; | 892 | C = 22; |
| 892 | // B = dcb000dcb | 893 | // B = dcb000dcb |
| 893 | uint32_t dcb = (bitval >> 1) & 7; | 894 | u32 dcb = (bitval >> 1) & 7; |
| 894 | B = (dcb << 6) | dcb; | 895 | B = (dcb << 6) | dcb; |
| 895 | } break; | 896 | } break; |
| 896 | 897 | ||
| 897 | case 5: { | 898 | case 5: { |
| 898 | C = 11; | 899 | C = 11; |
| 899 | // B = edcb000ed | 900 | // B = edcb000ed |
| 900 | uint32_t edcb = (bitval >> 1) & 0xF; | 901 | u32 edcb = (bitval >> 1) & 0xF; |
| 901 | B = (edcb << 5) | (edcb >> 2); | 902 | B = (edcb << 5) | (edcb >> 2); |
| 902 | } break; | 903 | } break; |
| 903 | 904 | ||
| 904 | case 6: { | 905 | case 6: { |
| 905 | C = 5; | 906 | C = 5; |
| 906 | // B = fedcb000f | 907 | // B = fedcb000f |
| 907 | uint32_t fedcb = (bitval >> 1) & 0x1F; | 908 | u32 fedcb = (bitval >> 1) & 0x1F; |
| 908 | B = (fedcb << 4) | (fedcb >> 4); | 909 | B = (fedcb << 4) | (fedcb >> 4); |
| 909 | } break; | 910 | } break; |
| 910 | 911 | ||
| @@ -927,28 +928,28 @@ static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* mode | |||
| 927 | case 2: { | 928 | case 2: { |
| 928 | C = 54; | 929 | C = 54; |
| 929 | // B = b0000bb00 | 930 | // B = b0000bb00 |
| 930 | uint32_t b = (bitval >> 1) & 1; | 931 | u32 b = (bitval >> 1) & 1; |
| 931 | B = (b << 8) | (b << 3) | (b << 2); | 932 | B = (b << 8) | (b << 3) | (b << 2); |
| 932 | } break; | 933 | } break; |
| 933 | 934 | ||
| 934 | case 3: { | 935 | case 3: { |
| 935 | C = 26; | 936 | C = 26; |
| 936 | // B = cb0000cbc | 937 | // B = cb0000cbc |
| 937 | uint32_t cb = (bitval >> 1) & 3; | 938 | u32 cb = (bitval >> 1) & 3; |
| 938 | B = (cb << 7) | (cb << 1) | (cb >> 1); | 939 | B = (cb << 7) | (cb << 1) | (cb >> 1); |
| 939 | } break; | 940 | } break; |
| 940 | 941 | ||
| 941 | case 4: { | 942 | case 4: { |
| 942 | C = 13; | 943 | C = 13; |
| 943 | // B = dcb0000dc | 944 | // B = dcb0000dc |
| 944 | uint32_t dcb = (bitval >> 1) & 7; | 945 | u32 dcb = (bitval >> 1) & 7; |
| 945 | B = (dcb << 6) | (dcb >> 1); | 946 | B = (dcb << 6) | (dcb >> 1); |
| 946 | } break; | 947 | } break; |
| 947 | 948 | ||
| 948 | case 5: { | 949 | case 5: { |
| 949 | C = 6; | 950 | C = 6; |
| 950 | // B = edcb0000e | 951 | // B = edcb0000e |
| 951 | uint32_t edcb = (bitval >> 1) & 0xF; | 952 | u32 edcb = (bitval >> 1) & 0xF; |
| 952 | B = (edcb << 5) | (edcb >> 3); | 953 | B = (edcb << 5) | (edcb >> 3); |
| 953 | } break; | 954 | } break; |
| 954 | 955 | ||
| @@ -961,7 +962,7 @@ static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* mode | |||
| 961 | } // switch(val.GetEncoding()) | 962 | } // switch(val.GetEncoding()) |
| 962 | 963 | ||
| 963 | if (val.GetEncoding() != IntegerEncoding::JustBits) { | 964 | if (val.GetEncoding() != IntegerEncoding::JustBits) { |
| 964 | uint32_t T = D * C + B; | 965 | u32 T = D * C + B; |
| 965 | T ^= A; | 966 | T ^= A; |
| 966 | T = (A & 0x80) | (T >> 2); | 967 | T = (A & 0x80) | (T >> 2); |
| 967 | out[outIdx++] = T; | 968 | out[outIdx++] = T; |
| @@ -969,19 +970,19 @@ static void DecodeColorValues(uint32_t* out, uint8_t* data, const uint32_t* mode | |||
| 969 | } | 970 | } |
| 970 | 971 | ||
| 971 | // Make sure that each of our values is in the proper range... | 972 | // Make sure that each of our values is in the proper range... |
| 972 | for (uint32_t i = 0; i < nValues; i++) { | 973 | for (u32 i = 0; i < nValues; i++) { |
| 973 | assert(out[i] <= 255); | 974 | assert(out[i] <= 255); |
| 974 | } | 975 | } |
| 975 | } | 976 | } |
| 976 | 977 | ||
| 977 | static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { | 978 | static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { |
| 978 | uint32_t bitval = val.GetBitValue(); | 979 | u32 bitval = val.GetBitValue(); |
| 979 | uint32_t bitlen = val.BaseBitLength(); | 980 | u32 bitlen = val.BaseBitLength(); |
| 980 | 981 | ||
| 981 | uint32_t A = Replicate(bitval & 1, 1, 7); | 982 | u32 A = Replicate(bitval & 1, 1, 7); |
| 982 | uint32_t B = 0, C = 0, D = 0; | 983 | u32 B = 0, C = 0, D = 0; |
| 983 | 984 | ||
| 984 | uint32_t result = 0; | 985 | u32 result = 0; |
| 985 | switch (val.GetEncoding()) { | 986 | switch (val.GetEncoding()) { |
| 986 | case IntegerEncoding::JustBits: | 987 | case IntegerEncoding::JustBits: |
| 987 | result = Replicate(bitval, bitlen, 6); | 988 | result = Replicate(bitval, bitlen, 6); |
| @@ -993,7 +994,7 @@ static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 993 | 994 | ||
| 994 | switch (bitlen) { | 995 | switch (bitlen) { |
| 995 | case 0: { | 996 | case 0: { |
| 996 | uint32_t results[3] = {0, 32, 63}; | 997 | u32 results[3] = {0, 32, 63}; |
| 997 | result = results[D]; | 998 | result = results[D]; |
| 998 | } break; | 999 | } break; |
| 999 | 1000 | ||
| @@ -1003,13 +1004,13 @@ static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1003 | 1004 | ||
| 1004 | case 2: { | 1005 | case 2: { |
| 1005 | C = 23; | 1006 | C = 23; |
| 1006 | uint32_t b = (bitval >> 1) & 1; | 1007 | u32 b = (bitval >> 1) & 1; |
| 1007 | B = (b << 6) | (b << 2) | b; | 1008 | B = (b << 6) | (b << 2) | b; |
| 1008 | } break; | 1009 | } break; |
| 1009 | 1010 | ||
| 1010 | case 3: { | 1011 | case 3: { |
| 1011 | C = 11; | 1012 | C = 11; |
| 1012 | uint32_t cb = (bitval >> 1) & 3; | 1013 | u32 cb = (bitval >> 1) & 3; |
| 1013 | B = (cb << 5) | cb; | 1014 | B = (cb << 5) | cb; |
| 1014 | } break; | 1015 | } break; |
| 1015 | 1016 | ||
| @@ -1025,7 +1026,7 @@ static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1025 | 1026 | ||
| 1026 | switch (bitlen) { | 1027 | switch (bitlen) { |
| 1027 | case 0: { | 1028 | case 0: { |
| 1028 | uint32_t results[5] = {0, 16, 32, 47, 63}; | 1029 | u32 results[5] = {0, 16, 32, 47, 63}; |
| 1029 | result = results[D]; | 1030 | result = results[D]; |
| 1030 | } break; | 1031 | } break; |
| 1031 | 1032 | ||
| @@ -1035,7 +1036,7 @@ static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1035 | 1036 | ||
| 1036 | case 2: { | 1037 | case 2: { |
| 1037 | C = 13; | 1038 | C = 13; |
| 1038 | uint32_t b = (bitval >> 1) & 1; | 1039 | u32 b = (bitval >> 1) & 1; |
| 1039 | B = (b << 6) | (b << 1); | 1040 | B = (b << 6) | (b << 1); |
| 1040 | } break; | 1041 | } break; |
| 1041 | 1042 | ||
| @@ -1063,12 +1064,11 @@ static uint32_t UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1063 | return result; | 1064 | return result; |
| 1064 | } | 1065 | } |
| 1065 | 1066 | ||
| 1066 | static void UnquantizeTexelWeights(uint32_t out[2][144], | 1067 | static void UnquantizeTexelWeights(u32 out[2][144], const std::vector<IntegerEncodedValue>& weights, |
| 1067 | const std::vector<IntegerEncodedValue>& weights, | 1068 | const TexelWeightParams& params, const u32 blockWidth, |
| 1068 | const TexelWeightParams& params, const uint32_t blockWidth, | 1069 | const u32 blockHeight) { |
| 1069 | const uint32_t blockHeight) { | 1070 | u32 weightIdx = 0; |
| 1070 | uint32_t weightIdx = 0; | 1071 | u32 unquantized[2][144]; |
| 1071 | uint32_t unquantized[2][144]; | ||
| 1072 | 1072 | ||
| 1073 | for (auto itr = weights.begin(); itr != weights.end(); ++itr) { | 1073 | for (auto itr = weights.begin(); itr != weights.end(); ++itr) { |
| 1074 | unquantized[0][weightIdx] = UnquantizeTexelWeight(*itr); | 1074 | unquantized[0][weightIdx] = UnquantizeTexelWeight(*itr); |
| @@ -1086,34 +1086,34 @@ static void UnquantizeTexelWeights(uint32_t out[2][144], | |||
| 1086 | } | 1086 | } |
| 1087 | 1087 | ||
| 1088 | // Do infill if necessary (Section C.2.18) ... | 1088 | // Do infill if necessary (Section C.2.18) ... |
| 1089 | uint32_t Ds = (1024 + (blockWidth / 2)) / (blockWidth - 1); | 1089 | u32 Ds = (1024 + (blockWidth / 2)) / (blockWidth - 1); |
| 1090 | uint32_t Dt = (1024 + (blockHeight / 2)) / (blockHeight - 1); | 1090 | u32 Dt = (1024 + (blockHeight / 2)) / (blockHeight - 1); |
| 1091 | 1091 | ||
| 1092 | const uint32_t kPlaneScale = params.m_bDualPlane ? 2U : 1U; | 1092 | const u32 kPlaneScale = params.m_bDualPlane ? 2U : 1U; |
| 1093 | for (uint32_t plane = 0; plane < kPlaneScale; plane++) | 1093 | for (u32 plane = 0; plane < kPlaneScale; plane++) |
| 1094 | for (uint32_t t = 0; t < blockHeight; t++) | 1094 | for (u32 t = 0; t < blockHeight; t++) |
| 1095 | for (uint32_t s = 0; s < blockWidth; s++) { | 1095 | for (u32 s = 0; s < blockWidth; s++) { |
| 1096 | uint32_t cs = Ds * s; | 1096 | u32 cs = Ds * s; |
| 1097 | uint32_t ct = Dt * t; | 1097 | u32 ct = Dt * t; |
| 1098 | 1098 | ||
| 1099 | uint32_t gs = (cs * (params.m_Width - 1) + 32) >> 6; | 1099 | u32 gs = (cs * (params.m_Width - 1) + 32) >> 6; |
| 1100 | uint32_t gt = (ct * (params.m_Height - 1) + 32) >> 6; | 1100 | u32 gt = (ct * (params.m_Height - 1) + 32) >> 6; |
| 1101 | 1101 | ||
| 1102 | uint32_t js = gs >> 4; | 1102 | u32 js = gs >> 4; |
| 1103 | uint32_t fs = gs & 0xF; | 1103 | u32 fs = gs & 0xF; |
| 1104 | 1104 | ||
| 1105 | uint32_t jt = gt >> 4; | 1105 | u32 jt = gt >> 4; |
| 1106 | uint32_t ft = gt & 0x0F; | 1106 | u32 ft = gt & 0x0F; |
| 1107 | 1107 | ||
| 1108 | uint32_t w11 = (fs * ft + 8) >> 4; | 1108 | u32 w11 = (fs * ft + 8) >> 4; |
| 1109 | uint32_t w10 = ft - w11; | 1109 | u32 w10 = ft - w11; |
| 1110 | uint32_t w01 = fs - w11; | 1110 | u32 w01 = fs - w11; |
| 1111 | uint32_t w00 = 16 - fs - ft + w11; | 1111 | u32 w00 = 16 - fs - ft + w11; |
| 1112 | 1112 | ||
| 1113 | uint32_t v0 = js + jt * params.m_Width; | 1113 | u32 v0 = js + jt * params.m_Width; |
| 1114 | 1114 | ||
| 1115 | #define FIND_TEXEL(tidx, bidx) \ | 1115 | #define FIND_TEXEL(tidx, bidx) \ |
| 1116 | uint32_t p##bidx = 0; \ | 1116 | u32 p##bidx = 0; \ |
| 1117 | do { \ | 1117 | do { \ |
| 1118 | if ((tidx) < (params.m_Width * params.m_Height)) { \ | 1118 | if ((tidx) < (params.m_Width * params.m_Height)) { \ |
| 1119 | p##bidx = unquantized[plane][(tidx)]; \ | 1119 | p##bidx = unquantized[plane][(tidx)]; \ |
| @@ -1133,7 +1133,7 @@ static void UnquantizeTexelWeights(uint32_t out[2][144], | |||
| 1133 | } | 1133 | } |
| 1134 | 1134 | ||
| 1135 | // Transfers a bit as described in C.2.14 | 1135 | // Transfers a bit as described in C.2.14 |
| 1136 | static inline void BitTransferSigned(int32_t& a, int32_t& b) { | 1136 | static inline void BitTransferSigned(s32& a, s32& b) { |
| 1137 | b >>= 1; | 1137 | b >>= 1; |
| 1138 | b |= a & 0x80; | 1138 | b |= a & 0x80; |
| 1139 | a >>= 1; | 1139 | a >>= 1; |
| @@ -1144,14 +1144,14 @@ static inline void BitTransferSigned(int32_t& a, int32_t& b) { | |||
| 1144 | 1144 | ||
| 1145 | // Adds more precision to the blue channel as described | 1145 | // Adds more precision to the blue channel as described |
| 1146 | // in C.2.14 | 1146 | // in C.2.14 |
| 1147 | static inline Pixel BlueContract(int32_t a, int32_t r, int32_t g, int32_t b) { | 1147 | static inline Pixel BlueContract(s32 a, s32 r, s32 g, s32 b) { |
| 1148 | return Pixel(static_cast<int16_t>(a), static_cast<int16_t>((r + b) >> 1), | 1148 | return Pixel(static_cast<s16>(a), static_cast<s16>((r + b) >> 1), |
| 1149 | static_cast<int16_t>((g + b) >> 1), static_cast<int16_t>(b)); | 1149 | static_cast<s16>((g + b) >> 1), static_cast<s16>(b)); |
| 1150 | } | 1150 | } |
| 1151 | 1151 | ||
| 1152 | // Partition selection functions as specified in | 1152 | // Partition selection functions as specified in |
| 1153 | // C.2.21 | 1153 | // C.2.21 |
| 1154 | static inline uint32_t hash52(uint32_t p) { | 1154 | static inline u32 hash52(u32 p) { |
| 1155 | p ^= p >> 15; | 1155 | p ^= p >> 15; |
| 1156 | p -= p << 17; | 1156 | p -= p << 17; |
| 1157 | p += p << 7; | 1157 | p += p << 7; |
| @@ -1165,8 +1165,7 @@ static inline uint32_t hash52(uint32_t p) { | |||
| 1165 | return p; | 1165 | return p; |
| 1166 | } | 1166 | } |
| 1167 | 1167 | ||
| 1168 | static uint32_t SelectPartition(int32_t seed, int32_t x, int32_t y, int32_t z, | 1168 | static u32 SelectPartition(s32 seed, s32 x, s32 y, s32 z, s32 partitionCount, s32 smallBlock) { |
| 1169 | int32_t partitionCount, int32_t smallBlock) { | ||
| 1170 | if (1 == partitionCount) | 1169 | if (1 == partitionCount) |
| 1171 | return 0; | 1170 | return 0; |
| 1172 | 1171 | ||
| @@ -1178,34 +1177,34 @@ static uint32_t SelectPartition(int32_t seed, int32_t x, int32_t y, int32_t z, | |||
| 1178 | 1177 | ||
| 1179 | seed += (partitionCount - 1) * 1024; | 1178 | seed += (partitionCount - 1) * 1024; |
| 1180 | 1179 | ||
| 1181 | uint32_t rnum = hash52(static_cast<uint32_t>(seed)); | 1180 | u32 rnum = hash52(static_cast<u32>(seed)); |
| 1182 | uint8_t seed1 = static_cast<uint8_t>(rnum & 0xF); | 1181 | u8 seed1 = static_cast<u8>(rnum & 0xF); |
| 1183 | uint8_t seed2 = static_cast<uint8_t>((rnum >> 4) & 0xF); | 1182 | u8 seed2 = static_cast<u8>((rnum >> 4) & 0xF); |
| 1184 | uint8_t seed3 = static_cast<uint8_t>((rnum >> 8) & 0xF); | 1183 | u8 seed3 = static_cast<u8>((rnum >> 8) & 0xF); |
| 1185 | uint8_t seed4 = static_cast<uint8_t>((rnum >> 12) & 0xF); | 1184 | u8 seed4 = static_cast<u8>((rnum >> 12) & 0xF); |
| 1186 | uint8_t seed5 = static_cast<uint8_t>((rnum >> 16) & 0xF); | 1185 | u8 seed5 = static_cast<u8>((rnum >> 16) & 0xF); |
| 1187 | uint8_t seed6 = static_cast<uint8_t>((rnum >> 20) & 0xF); | 1186 | u8 seed6 = static_cast<u8>((rnum >> 20) & 0xF); |
| 1188 | uint8_t seed7 = static_cast<uint8_t>((rnum >> 24) & 0xF); | 1187 | u8 seed7 = static_cast<u8>((rnum >> 24) & 0xF); |
| 1189 | uint8_t seed8 = static_cast<uint8_t>((rnum >> 28) & 0xF); | 1188 | u8 seed8 = static_cast<u8>((rnum >> 28) & 0xF); |
| 1190 | uint8_t seed9 = static_cast<uint8_t>((rnum >> 18) & 0xF); | 1189 | u8 seed9 = static_cast<u8>((rnum >> 18) & 0xF); |
| 1191 | uint8_t seed10 = static_cast<uint8_t>((rnum >> 22) & 0xF); | 1190 | u8 seed10 = static_cast<u8>((rnum >> 22) & 0xF); |
| 1192 | uint8_t seed11 = static_cast<uint8_t>((rnum >> 26) & 0xF); | 1191 | u8 seed11 = static_cast<u8>((rnum >> 26) & 0xF); |
| 1193 | uint8_t seed12 = static_cast<uint8_t>(((rnum >> 30) | (rnum << 2)) & 0xF); | 1192 | u8 seed12 = static_cast<u8>(((rnum >> 30) | (rnum << 2)) & 0xF); |
| 1194 | 1193 | ||
| 1195 | seed1 = static_cast<uint8_t>(seed1 * seed1); | 1194 | seed1 = static_cast<u8>(seed1 * seed1); |
| 1196 | seed2 = static_cast<uint8_t>(seed2 * seed2); | 1195 | seed2 = static_cast<u8>(seed2 * seed2); |
| 1197 | seed3 = static_cast<uint8_t>(seed3 * seed3); | 1196 | seed3 = static_cast<u8>(seed3 * seed3); |
| 1198 | seed4 = static_cast<uint8_t>(seed4 * seed4); | 1197 | seed4 = static_cast<u8>(seed4 * seed4); |
| 1199 | seed5 = static_cast<uint8_t>(seed5 * seed5); | 1198 | seed5 = static_cast<u8>(seed5 * seed5); |
| 1200 | seed6 = static_cast<uint8_t>(seed6 * seed6); | 1199 | seed6 = static_cast<u8>(seed6 * seed6); |
| 1201 | seed7 = static_cast<uint8_t>(seed7 * seed7); | 1200 | seed7 = static_cast<u8>(seed7 * seed7); |
| 1202 | seed8 = static_cast<uint8_t>(seed8 * seed8); | 1201 | seed8 = static_cast<u8>(seed8 * seed8); |
| 1203 | seed9 = static_cast<uint8_t>(seed9 * seed9); | 1202 | seed9 = static_cast<u8>(seed9 * seed9); |
| 1204 | seed10 = static_cast<uint8_t>(seed10 * seed10); | 1203 | seed10 = static_cast<u8>(seed10 * seed10); |
| 1205 | seed11 = static_cast<uint8_t>(seed11 * seed11); | 1204 | seed11 = static_cast<u8>(seed11 * seed11); |
| 1206 | seed12 = static_cast<uint8_t>(seed12 * seed12); | 1205 | seed12 = static_cast<u8>(seed12 * seed12); |
| 1207 | 1206 | ||
| 1208 | int32_t sh1, sh2, sh3; | 1207 | s32 sh1, sh2, sh3; |
| 1209 | if (seed & 1) { | 1208 | if (seed & 1) { |
| 1210 | sh1 = (seed & 2) ? 4 : 5; | 1209 | sh1 = (seed & 2) ? 4 : 5; |
| 1211 | sh2 = (partitionCount == 3) ? 6 : 5; | 1210 | sh2 = (partitionCount == 3) ? 6 : 5; |
| @@ -1215,23 +1214,23 @@ static uint32_t SelectPartition(int32_t seed, int32_t x, int32_t y, int32_t z, | |||
| 1215 | } | 1214 | } |
| 1216 | sh3 = (seed & 0x10) ? sh1 : sh2; | 1215 | sh3 = (seed & 0x10) ? sh1 : sh2; |
| 1217 | 1216 | ||
| 1218 | seed1 = static_cast<uint8_t>(seed1 >> sh1); | 1217 | seed1 = static_cast<u8>(seed1 >> sh1); |
| 1219 | seed2 = static_cast<uint8_t>(seed2 >> sh2); | 1218 | seed2 = static_cast<u8>(seed2 >> sh2); |
| 1220 | seed3 = static_cast<uint8_t>(seed3 >> sh1); | 1219 | seed3 = static_cast<u8>(seed3 >> sh1); |
| 1221 | seed4 = static_cast<uint8_t>(seed4 >> sh2); | 1220 | seed4 = static_cast<u8>(seed4 >> sh2); |
| 1222 | seed5 = static_cast<uint8_t>(seed5 >> sh1); | 1221 | seed5 = static_cast<u8>(seed5 >> sh1); |
| 1223 | seed6 = static_cast<uint8_t>(seed6 >> sh2); | 1222 | seed6 = static_cast<u8>(seed6 >> sh2); |
| 1224 | seed7 = static_cast<uint8_t>(seed7 >> sh1); | 1223 | seed7 = static_cast<u8>(seed7 >> sh1); |
| 1225 | seed8 = static_cast<uint8_t>(seed8 >> sh2); | 1224 | seed8 = static_cast<u8>(seed8 >> sh2); |
| 1226 | seed9 = static_cast<uint8_t>(seed9 >> sh3); | 1225 | seed9 = static_cast<u8>(seed9 >> sh3); |
| 1227 | seed10 = static_cast<uint8_t>(seed10 >> sh3); | 1226 | seed10 = static_cast<u8>(seed10 >> sh3); |
| 1228 | seed11 = static_cast<uint8_t>(seed11 >> sh3); | 1227 | seed11 = static_cast<u8>(seed11 >> sh3); |
| 1229 | seed12 = static_cast<uint8_t>(seed12 >> sh3); | 1228 | seed12 = static_cast<u8>(seed12 >> sh3); |
| 1230 | 1229 | ||
| 1231 | int32_t a = seed1 * x + seed2 * y + seed11 * z + (rnum >> 14); | 1230 | s32 a = seed1 * x + seed2 * y + seed11 * z + (rnum >> 14); |
| 1232 | int32_t b = seed3 * x + seed4 * y + seed12 * z + (rnum >> 10); | 1231 | s32 b = seed3 * x + seed4 * y + seed12 * z + (rnum >> 10); |
| 1233 | int32_t c = seed5 * x + seed6 * y + seed9 * z + (rnum >> 6); | 1232 | s32 c = seed5 * x + seed6 * y + seed9 * z + (rnum >> 6); |
| 1234 | int32_t d = seed7 * x + seed8 * y + seed10 * z + (rnum >> 2); | 1233 | s32 d = seed7 * x + seed8 * y + seed10 * z + (rnum >> 2); |
| 1235 | 1234 | ||
| 1236 | a &= 0x3F; | 1235 | a &= 0x3F; |
| 1237 | b &= 0x3F; | 1236 | b &= 0x3F; |
| @@ -1252,24 +1251,23 @@ static uint32_t SelectPartition(int32_t seed, int32_t x, int32_t y, int32_t z, | |||
| 1252 | return 3; | 1251 | return 3; |
| 1253 | } | 1252 | } |
| 1254 | 1253 | ||
| 1255 | static inline uint32_t Select2DPartition(int32_t seed, int32_t x, int32_t y, int32_t partitionCount, | 1254 | static inline u32 Select2DPartition(s32 seed, s32 x, s32 y, s32 partitionCount, s32 smallBlock) { |
| 1256 | int32_t smallBlock) { | ||
| 1257 | return SelectPartition(seed, x, y, 0, partitionCount, smallBlock); | 1255 | return SelectPartition(seed, x, y, 0, partitionCount, smallBlock); |
| 1258 | } | 1256 | } |
| 1259 | 1257 | ||
| 1260 | // Section C.2.14 | 1258 | // Section C.2.14 |
| 1261 | static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const uint32_t*& colorValues, | 1259 | static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const u32*& colorValues, |
| 1262 | uint32_t colorEndpointMode) { | 1260 | u32 colorEndpointMode) { |
| 1263 | #define READ_UINT_VALUES(N) \ | 1261 | #define READ_UINT_VALUES(N) \ |
| 1264 | uint32_t v[N]; \ | 1262 | u32 v[N]; \ |
| 1265 | for (uint32_t i = 0; i < N; i++) { \ | 1263 | for (u32 i = 0; i < N; i++) { \ |
| 1266 | v[i] = *(colorValues++); \ | 1264 | v[i] = *(colorValues++); \ |
| 1267 | } | 1265 | } |
| 1268 | 1266 | ||
| 1269 | #define READ_INT_VALUES(N) \ | 1267 | #define READ_INT_VALUES(N) \ |
| 1270 | int32_t v[N]; \ | 1268 | s32 v[N]; \ |
| 1271 | for (uint32_t i = 0; i < N; i++) { \ | 1269 | for (u32 i = 0; i < N; i++) { \ |
| 1272 | v[i] = static_cast<int32_t>(*(colorValues++)); \ | 1270 | v[i] = static_cast<s32>(*(colorValues++)); \ |
| 1273 | } | 1271 | } |
| 1274 | 1272 | ||
| 1275 | switch (colorEndpointMode) { | 1273 | switch (colorEndpointMode) { |
| @@ -1281,8 +1279,8 @@ static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const uint32_t*& colorValue | |||
| 1281 | 1279 | ||
| 1282 | case 1: { | 1280 | case 1: { |
| 1283 | READ_UINT_VALUES(2) | 1281 | READ_UINT_VALUES(2) |
| 1284 | uint32_t L0 = (v[0] >> 2) | (v[1] & 0xC0); | 1282 | u32 L0 = (v[0] >> 2) | (v[1] & 0xC0); |
| 1285 | uint32_t L1 = std::max(L0 + (v[1] & 0x3F), 0xFFU); | 1283 | u32 L1 = std::max(L0 + (v[1] & 0x3F), 0xFFU); |
| 1286 | ep1 = Pixel(0xFF, L0, L0, L0); | 1284 | ep1 = Pixel(0xFF, L0, L0, L0); |
| 1287 | ep2 = Pixel(0xFF, L1, L1, L1); | 1285 | ep2 = Pixel(0xFF, L1, L1, L1); |
| 1288 | } break; | 1286 | } break; |
| @@ -1379,8 +1377,8 @@ static void ComputeEndpoints(Pixel& ep1, Pixel& ep2, const uint32_t*& colorValue | |||
| 1379 | #undef READ_INT_VALUES | 1377 | #undef READ_INT_VALUES |
| 1380 | } | 1378 | } |
| 1381 | 1379 | ||
| 1382 | static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | 1380 | static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 blockHeight, |
| 1383 | const uint32_t blockHeight, uint32_t* outBuf) { | 1381 | u32* outBuf) { |
| 1384 | InputBitStream strm(inBuf); | 1382 | InputBitStream strm(inBuf); |
| 1385 | TexelWeightParams weightParams = DecodeBlockInfo(strm); | 1383 | TexelWeightParams weightParams = DecodeBlockInfo(strm); |
| 1386 | 1384 | ||
| @@ -1415,7 +1413,7 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1415 | } | 1413 | } |
| 1416 | 1414 | ||
| 1417 | // Read num partitions | 1415 | // Read num partitions |
| 1418 | uint32_t nPartitions = strm.ReadBits(2) + 1; | 1416 | u32 nPartitions = strm.ReadBits(2) + 1; |
| 1419 | assert(nPartitions <= 4); | 1417 | assert(nPartitions <= 4); |
| 1420 | 1418 | ||
| 1421 | if (nPartitions == 4 && weightParams.m_bDualPlane) { | 1419 | if (nPartitions == 4 && weightParams.m_bDualPlane) { |
| @@ -1428,17 +1426,17 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1428 | // each partition. | 1426 | // each partition. |
| 1429 | 1427 | ||
| 1430 | // Determine partitions, partition index, and color endpoint modes | 1428 | // Determine partitions, partition index, and color endpoint modes |
| 1431 | int32_t planeIdx = -1; | 1429 | s32 planeIdx = -1; |
| 1432 | uint32_t partitionIndex; | 1430 | u32 partitionIndex; |
| 1433 | uint32_t colorEndpointMode[4] = {0, 0, 0, 0}; | 1431 | u32 colorEndpointMode[4] = {0, 0, 0, 0}; |
| 1434 | 1432 | ||
| 1435 | // Define color data. | 1433 | // Define color data. |
| 1436 | uint8_t colorEndpointData[16]; | 1434 | u8 colorEndpointData[16]; |
| 1437 | memset(colorEndpointData, 0, sizeof(colorEndpointData)); | 1435 | memset(colorEndpointData, 0, sizeof(colorEndpointData)); |
| 1438 | OutputBitStream colorEndpointStream(colorEndpointData, 16 * 8, 0); | 1436 | OutputBitStream colorEndpointStream(colorEndpointData, 16 * 8, 0); |
| 1439 | 1437 | ||
| 1440 | // Read extra config data... | 1438 | // Read extra config data... |
| 1441 | uint32_t baseCEM = 0; | 1439 | u32 baseCEM = 0; |
| 1442 | if (nPartitions == 1) { | 1440 | if (nPartitions == 1) { |
| 1443 | colorEndpointMode[0] = strm.ReadBits(4); | 1441 | colorEndpointMode[0] = strm.ReadBits(4); |
| 1444 | partitionIndex = 0; | 1442 | partitionIndex = 0; |
| @@ -1446,14 +1444,14 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1446 | partitionIndex = strm.ReadBits(10); | 1444 | partitionIndex = strm.ReadBits(10); |
| 1447 | baseCEM = strm.ReadBits(6); | 1445 | baseCEM = strm.ReadBits(6); |
| 1448 | } | 1446 | } |
| 1449 | uint32_t baseMode = (baseCEM & 3); | 1447 | u32 baseMode = (baseCEM & 3); |
| 1450 | 1448 | ||
| 1451 | // Remaining bits are color endpoint data... | 1449 | // Remaining bits are color endpoint data... |
| 1452 | uint32_t nWeightBits = weightParams.GetPackedBitSize(); | 1450 | u32 nWeightBits = weightParams.GetPackedBitSize(); |
| 1453 | int32_t remainingBits = 128 - nWeightBits - strm.GetBitsRead(); | 1451 | s32 remainingBits = 128 - nWeightBits - strm.GetBitsRead(); |
| 1454 | 1452 | ||
| 1455 | // Consider extra bits prior to texel data... | 1453 | // Consider extra bits prior to texel data... |
| 1456 | uint32_t extraCEMbits = 0; | 1454 | u32 extraCEMbits = 0; |
| 1457 | if (baseMode) { | 1455 | if (baseMode) { |
| 1458 | switch (nPartitions) { | 1456 | switch (nPartitions) { |
| 1459 | case 2: | 1457 | case 2: |
| @@ -1473,17 +1471,17 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1473 | remainingBits -= extraCEMbits; | 1471 | remainingBits -= extraCEMbits; |
| 1474 | 1472 | ||
| 1475 | // Do we have a dual plane situation? | 1473 | // Do we have a dual plane situation? |
| 1476 | uint32_t planeSelectorBits = 0; | 1474 | u32 planeSelectorBits = 0; |
| 1477 | if (weightParams.m_bDualPlane) { | 1475 | if (weightParams.m_bDualPlane) { |
| 1478 | planeSelectorBits = 2; | 1476 | planeSelectorBits = 2; |
| 1479 | } | 1477 | } |
| 1480 | remainingBits -= planeSelectorBits; | 1478 | remainingBits -= planeSelectorBits; |
| 1481 | 1479 | ||
| 1482 | // Read color data... | 1480 | // Read color data... |
| 1483 | uint32_t colorDataBits = remainingBits; | 1481 | u32 colorDataBits = remainingBits; |
| 1484 | while (remainingBits > 0) { | 1482 | while (remainingBits > 0) { |
| 1485 | uint32_t nb = std::min(remainingBits, 8); | 1483 | u32 nb = std::min(remainingBits, 8); |
| 1486 | uint32_t b = strm.ReadBits(nb); | 1484 | u32 b = strm.ReadBits(nb); |
| 1487 | colorEndpointStream.WriteBits(b, nb); | 1485 | colorEndpointStream.WriteBits(b, nb); |
| 1488 | remainingBits -= 8; | 1486 | remainingBits -= 8; |
| 1489 | } | 1487 | } |
| @@ -1493,24 +1491,24 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1493 | 1491 | ||
| 1494 | // Read the rest of the CEM | 1492 | // Read the rest of the CEM |
| 1495 | if (baseMode) { | 1493 | if (baseMode) { |
| 1496 | uint32_t extraCEM = strm.ReadBits(extraCEMbits); | 1494 | u32 extraCEM = strm.ReadBits(extraCEMbits); |
| 1497 | uint32_t CEM = (extraCEM << 6) | baseCEM; | 1495 | u32 CEM = (extraCEM << 6) | baseCEM; |
| 1498 | CEM >>= 2; | 1496 | CEM >>= 2; |
| 1499 | 1497 | ||
| 1500 | bool C[4] = {0}; | 1498 | bool C[4] = {0}; |
| 1501 | for (uint32_t i = 0; i < nPartitions; i++) { | 1499 | for (u32 i = 0; i < nPartitions; i++) { |
| 1502 | C[i] = CEM & 1; | 1500 | C[i] = CEM & 1; |
| 1503 | CEM >>= 1; | 1501 | CEM >>= 1; |
| 1504 | } | 1502 | } |
| 1505 | 1503 | ||
| 1506 | uint8_t M[4] = {0}; | 1504 | u8 M[4] = {0}; |
| 1507 | for (uint32_t i = 0; i < nPartitions; i++) { | 1505 | for (u32 i = 0; i < nPartitions; i++) { |
| 1508 | M[i] = CEM & 3; | 1506 | M[i] = CEM & 3; |
| 1509 | CEM >>= 2; | 1507 | CEM >>= 2; |
| 1510 | assert(M[i] <= 3); | 1508 | assert(M[i] <= 3); |
| 1511 | } | 1509 | } |
| 1512 | 1510 | ||
| 1513 | for (uint32_t i = 0; i < nPartitions; i++) { | 1511 | for (u32 i = 0; i < nPartitions; i++) { |
| 1514 | colorEndpointMode[i] = baseMode; | 1512 | colorEndpointMode[i] = baseMode; |
| 1515 | if (!(C[i])) | 1513 | if (!(C[i])) |
| 1516 | colorEndpointMode[i] -= 1; | 1514 | colorEndpointMode[i] -= 1; |
| @@ -1518,35 +1516,35 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1518 | colorEndpointMode[i] |= M[i]; | 1516 | colorEndpointMode[i] |= M[i]; |
| 1519 | } | 1517 | } |
| 1520 | } else if (nPartitions > 1) { | 1518 | } else if (nPartitions > 1) { |
| 1521 | uint32_t CEM = baseCEM >> 2; | 1519 | u32 CEM = baseCEM >> 2; |
| 1522 | for (uint32_t i = 0; i < nPartitions; i++) { | 1520 | for (u32 i = 0; i < nPartitions; i++) { |
| 1523 | colorEndpointMode[i] = CEM; | 1521 | colorEndpointMode[i] = CEM; |
| 1524 | } | 1522 | } |
| 1525 | } | 1523 | } |
| 1526 | 1524 | ||
| 1527 | // Make sure everything up till here is sane. | 1525 | // Make sure everything up till here is sane. |
| 1528 | for (uint32_t i = 0; i < nPartitions; i++) { | 1526 | for (u32 i = 0; i < nPartitions; i++) { |
| 1529 | assert(colorEndpointMode[i] < 16); | 1527 | assert(colorEndpointMode[i] < 16); |
| 1530 | } | 1528 | } |
| 1531 | assert(strm.GetBitsRead() + weightParams.GetPackedBitSize() == 128); | 1529 | assert(strm.GetBitsRead() + weightParams.GetPackedBitSize() == 128); |
| 1532 | 1530 | ||
| 1533 | // Decode both color data and texel weight data | 1531 | // Decode both color data and texel weight data |
| 1534 | uint32_t colorValues[32]; // Four values, two endpoints, four maximum paritions | 1532 | u32 colorValues[32]; // Four values, two endpoints, four maximum paritions |
| 1535 | DecodeColorValues(colorValues, colorEndpointData, colorEndpointMode, nPartitions, | 1533 | DecodeColorValues(colorValues, colorEndpointData, colorEndpointMode, nPartitions, |
| 1536 | colorDataBits); | 1534 | colorDataBits); |
| 1537 | 1535 | ||
| 1538 | Pixel endpoints[4][2]; | 1536 | Pixel endpoints[4][2]; |
| 1539 | const uint32_t* colorValuesPtr = colorValues; | 1537 | const u32* colorValuesPtr = colorValues; |
| 1540 | for (uint32_t i = 0; i < nPartitions; i++) { | 1538 | for (u32 i = 0; i < nPartitions; i++) { |
| 1541 | ComputeEndpoints(endpoints[i][0], endpoints[i][1], colorValuesPtr, colorEndpointMode[i]); | 1539 | ComputeEndpoints(endpoints[i][0], endpoints[i][1], colorValuesPtr, colorEndpointMode[i]); |
| 1542 | } | 1540 | } |
| 1543 | 1541 | ||
| 1544 | // Read the texel weight data.. | 1542 | // Read the texel weight data.. |
| 1545 | uint8_t texelWeightData[16]; | 1543 | u8 texelWeightData[16]; |
| 1546 | memcpy(texelWeightData, inBuf, sizeof(texelWeightData)); | 1544 | memcpy(texelWeightData, inBuf, sizeof(texelWeightData)); |
| 1547 | 1545 | ||
| 1548 | // Reverse everything | 1546 | // Reverse everything |
| 1549 | for (uint32_t i = 0; i < 8; i++) { | 1547 | for (u32 i = 0; i < 8; i++) { |
| 1550 | // Taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64Bits | 1548 | // Taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64Bits |
| 1551 | #define REVERSE_BYTE(b) (((b)*0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32 | 1549 | #define REVERSE_BYTE(b) (((b)*0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32 |
| 1552 | unsigned char a = static_cast<unsigned char>(REVERSE_BYTE(texelWeightData[i])); | 1550 | unsigned char a = static_cast<unsigned char>(REVERSE_BYTE(texelWeightData[i])); |
| @@ -1558,10 +1556,10 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1558 | } | 1556 | } |
| 1559 | 1557 | ||
| 1560 | // Make sure that higher non-texel bits are set to zero | 1558 | // Make sure that higher non-texel bits are set to zero |
| 1561 | const uint32_t clearByteStart = (weightParams.GetPackedBitSize() >> 3) + 1; | 1559 | const u32 clearByteStart = (weightParams.GetPackedBitSize() >> 3) + 1; |
| 1562 | texelWeightData[clearByteStart - 1] = | 1560 | texelWeightData[clearByteStart - 1] = |
| 1563 | texelWeightData[clearByteStart - 1] & | 1561 | texelWeightData[clearByteStart - 1] & |
| 1564 | static_cast<uint8_t>((1 << (weightParams.GetPackedBitSize() % 8)) - 1); | 1562 | static_cast<u8>((1 << (weightParams.GetPackedBitSize() % 8)) - 1); |
| 1565 | memset(texelWeightData + clearByteStart, 0, 16 - clearByteStart); | 1563 | memset(texelWeightData + clearByteStart, 0, 16 - clearByteStart); |
| 1566 | 1564 | ||
| 1567 | std::vector<IntegerEncodedValue> texelWeightValues; | 1565 | std::vector<IntegerEncodedValue> texelWeightValues; |
| @@ -1572,36 +1570,36 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1572 | weightParams.GetNumWeightValues()); | 1570 | weightParams.GetNumWeightValues()); |
| 1573 | 1571 | ||
| 1574 | // Blocks can be at most 12x12, so we can have as many as 144 weights | 1572 | // Blocks can be at most 12x12, so we can have as many as 144 weights |
| 1575 | uint32_t weights[2][144]; | 1573 | u32 weights[2][144]; |
| 1576 | UnquantizeTexelWeights(weights, texelWeightValues, weightParams, blockWidth, blockHeight); | 1574 | UnquantizeTexelWeights(weights, texelWeightValues, weightParams, blockWidth, blockHeight); |
| 1577 | 1575 | ||
| 1578 | // Now that we have endpoints and weights, we can interpolate and generate | 1576 | // Now that we have endpoints and weights, we can interpolate and generate |
| 1579 | // the proper decoding... | 1577 | // the proper decoding... |
| 1580 | for (uint32_t j = 0; j < blockHeight; j++) | 1578 | for (u32 j = 0; j < blockHeight; j++) |
| 1581 | for (uint32_t i = 0; i < blockWidth; i++) { | 1579 | for (u32 i = 0; i < blockWidth; i++) { |
| 1582 | uint32_t partition = Select2DPartition(partitionIndex, i, j, nPartitions, | 1580 | u32 partition = Select2DPartition(partitionIndex, i, j, nPartitions, |
| 1583 | (blockHeight * blockWidth) < 32); | 1581 | (blockHeight * blockWidth) < 32); |
| 1584 | assert(partition < nPartitions); | 1582 | assert(partition < nPartitions); |
| 1585 | 1583 | ||
| 1586 | Pixel p; | 1584 | Pixel p; |
| 1587 | for (uint32_t c = 0; c < 4; c++) { | 1585 | for (u32 c = 0; c < 4; c++) { |
| 1588 | uint32_t C0 = endpoints[partition][0].Component(c); | 1586 | u32 C0 = endpoints[partition][0].Component(c); |
| 1589 | C0 = Replicate(C0, 8, 16); | 1587 | C0 = Replicate(C0, 8, 16); |
| 1590 | uint32_t C1 = endpoints[partition][1].Component(c); | 1588 | u32 C1 = endpoints[partition][1].Component(c); |
| 1591 | C1 = Replicate(C1, 8, 16); | 1589 | C1 = Replicate(C1, 8, 16); |
| 1592 | 1590 | ||
| 1593 | uint32_t plane = 0; | 1591 | u32 plane = 0; |
| 1594 | if (weightParams.m_bDualPlane && (((planeIdx + 1) & 3) == c)) { | 1592 | if (weightParams.m_bDualPlane && (((planeIdx + 1) & 3) == c)) { |
| 1595 | plane = 1; | 1593 | plane = 1; |
| 1596 | } | 1594 | } |
| 1597 | 1595 | ||
| 1598 | uint32_t weight = weights[plane][j * blockWidth + i]; | 1596 | u32 weight = weights[plane][j * blockWidth + i]; |
| 1599 | uint32_t C = (C0 * (64 - weight) + C1 * weight + 32) / 64; | 1597 | u32 C = (C0 * (64 - weight) + C1 * weight + 32) / 64; |
| 1600 | if (C == 65535) { | 1598 | if (C == 65535) { |
| 1601 | p.Component(c) = 255; | 1599 | p.Component(c) = 255; |
| 1602 | } else { | 1600 | } else { |
| 1603 | double Cf = static_cast<double>(C); | 1601 | double Cf = static_cast<double>(C); |
| 1604 | p.Component(c) = static_cast<uint16_t>(255.0 * (Cf / 65536.0) + 0.5); | 1602 | p.Component(c) = static_cast<u16>(255.0 * (Cf / 65536.0) + 0.5); |
| 1605 | } | 1603 | } |
| 1606 | } | 1604 | } |
| 1607 | 1605 | ||
| @@ -1613,26 +1611,26 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth, | |||
| 1613 | 1611 | ||
| 1614 | namespace Tegra::Texture::ASTC { | 1612 | namespace Tegra::Texture::ASTC { |
| 1615 | 1613 | ||
| 1616 | std::vector<uint8_t> Decompress(const uint8_t* data, uint32_t width, uint32_t height, | 1614 | std::vector<u8> Decompress(const u8* data, u32 width, u32 height, u32 depth, u32 block_width, |
| 1617 | uint32_t depth, uint32_t block_width, uint32_t block_height) { | 1615 | u32 block_height) { |
| 1618 | uint32_t blockIdx = 0; | 1616 | u32 blockIdx = 0; |
| 1619 | std::size_t depth_offset = 0; | 1617 | std::size_t depth_offset = 0; |
| 1620 | std::vector<uint8_t> outData(height * width * depth * 4); | 1618 | std::vector<u8> outData(height * width * depth * 4); |
| 1621 | for (uint32_t k = 0; k < depth; k++) { | 1619 | for (u32 k = 0; k < depth; k++) { |
| 1622 | for (uint32_t j = 0; j < height; j += block_height) { | 1620 | for (u32 j = 0; j < height; j += block_height) { |
| 1623 | for (uint32_t i = 0; i < width; i += block_width) { | 1621 | for (u32 i = 0; i < width; i += block_width) { |
| 1624 | 1622 | ||
| 1625 | const uint8_t* blockPtr = data + blockIdx * 16; | 1623 | const u8* blockPtr = data + blockIdx * 16; |
| 1626 | 1624 | ||
| 1627 | // Blocks can be at most 12x12 | 1625 | // Blocks can be at most 12x12 |
| 1628 | uint32_t uncompData[144]; | 1626 | u32 uncompData[144]; |
| 1629 | ASTCC::DecompressBlock(blockPtr, block_width, block_height, uncompData); | 1627 | ASTCC::DecompressBlock(blockPtr, block_width, block_height, uncompData); |
| 1630 | 1628 | ||
| 1631 | uint32_t decompWidth = std::min(block_width, width - i); | 1629 | u32 decompWidth = std::min(block_width, width - i); |
| 1632 | uint32_t decompHeight = std::min(block_height, height - j); | 1630 | u32 decompHeight = std::min(block_height, height - j); |
| 1633 | 1631 | ||
| 1634 | uint8_t* outRow = depth_offset + outData.data() + (j * width + i) * 4; | 1632 | u8* outRow = depth_offset + outData.data() + (j * width + i) * 4; |
| 1635 | for (uint32_t jj = 0; jj < decompHeight; jj++) { | 1633 | for (u32 jj = 0; jj < decompHeight; jj++) { |
| 1636 | memcpy(outRow + jj * width * 4, uncompData + jj * block_width, decompWidth * 4); | 1634 | memcpy(outRow + jj * width * 4, uncompData + jj * block_width, decompWidth * 4); |
| 1637 | } | 1635 | } |
| 1638 | 1636 | ||