diff options
| author | 2020-03-13 22:49:28 -0300 | |
|---|---|---|
| committer | 2020-03-13 22:49:28 -0300 | |
| commit | e183820956b528f64bb5d6e05052752bf437d3a1 (patch) | |
| tree | e03afbae2cb53e1bcbb843998056a13bbf9dcd0e | |
| parent | astc: Make IntegerEncodedValue constructor constexpr (diff) | |
| download | yuzu-e183820956b528f64bb5d6e05052752bf437d3a1.tar.gz yuzu-e183820956b528f64bb5d6e05052752bf437d3a1.tar.xz yuzu-e183820956b528f64bb5d6e05052752bf437d3a1.zip | |
astc: Make IntegerEncodedValue a trivial structure
| -rw-r--r-- | src/video_core/textures/astc.cpp | 389 |
1 files changed, 177 insertions, 212 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index f4513998c..2d948ee62 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp | |||
| @@ -160,232 +160,198 @@ private: | |||
| 160 | 160 | ||
| 161 | enum class IntegerEncoding { JustBits, Qus32, Trit }; | 161 | enum class IntegerEncoding { JustBits, Qus32, Trit }; |
| 162 | 162 | ||
| 163 | class IntegerEncodedValue { | 163 | struct IntegerEncodedValue { |
| 164 | private: | 164 | constexpr IntegerEncodedValue(IntegerEncoding encoding_, u32 num_bits_) |
| 165 | IntegerEncoding m_Encoding{}; | 165 | : encoding{encoding_}, num_bits{num_bits_} {} |
| 166 | u32 m_NumBits = 0; | ||
| 167 | u32 m_BitValue = 0; | ||
| 168 | union { | ||
| 169 | u32 m_Qus32Value = 0; | ||
| 170 | u32 m_TritValue; | ||
| 171 | }; | ||
| 172 | |||
| 173 | public: | ||
| 174 | constexpr IntegerEncodedValue() = default; | ||
| 175 | constexpr IntegerEncodedValue(IntegerEncoding encoding, u32 numBits) | ||
| 176 | : m_Encoding(encoding), m_NumBits(numBits) {} | ||
| 177 | |||
| 178 | IntegerEncoding GetEncoding() const { | ||
| 179 | return m_Encoding; | ||
| 180 | } | ||
| 181 | u32 BaseBitLength() const { | ||
| 182 | return m_NumBits; | ||
| 183 | } | ||
| 184 | |||
| 185 | u32 GetBitValue() const { | ||
| 186 | return m_BitValue; | ||
| 187 | } | ||
| 188 | void SetBitValue(u32 val) { | ||
| 189 | m_BitValue = val; | ||
| 190 | } | ||
| 191 | |||
| 192 | u32 GetTritValue() const { | ||
| 193 | return m_TritValue; | ||
| 194 | } | ||
| 195 | void SetTritValue(u32 val) { | ||
| 196 | m_TritValue = val; | ||
| 197 | } | ||
| 198 | |||
| 199 | u32 GetQus32Value() const { | ||
| 200 | return m_Qus32Value; | ||
| 201 | } | ||
| 202 | void SetQus32Value(u32 val) { | ||
| 203 | m_Qus32Value = val; | ||
| 204 | } | ||
| 205 | 166 | ||
| 206 | bool MatchesEncoding(const IntegerEncodedValue& other) const { | 167 | constexpr bool MatchesEncoding(const IntegerEncodedValue& other) const { |
| 207 | return m_Encoding == other.m_Encoding && m_NumBits == other.m_NumBits; | 168 | return encoding == other.encoding && num_bits == other.num_bits; |
| 208 | } | 169 | } |
| 209 | 170 | ||
| 210 | // Returns the number of bits required to encode nVals values. | 171 | // Returns the number of bits required to encode nVals values. |
| 211 | u32 GetBitLength(u32 nVals) const { | 172 | u32 GetBitLength(u32 nVals) const { |
| 212 | u32 totalBits = m_NumBits * nVals; | 173 | u32 totalBits = num_bits * nVals; |
| 213 | if (m_Encoding == IntegerEncoding::Trit) { | 174 | if (encoding == IntegerEncoding::Trit) { |
| 214 | totalBits += (nVals * 8 + 4) / 5; | 175 | totalBits += (nVals * 8 + 4) / 5; |
| 215 | } else if (m_Encoding == IntegerEncoding::Qus32) { | 176 | } else if (encoding == IntegerEncoding::Qus32) { |
| 216 | totalBits += (nVals * 7 + 2) / 3; | 177 | totalBits += (nVals * 7 + 2) / 3; |
| 217 | } | 178 | } |
| 218 | return totalBits; | 179 | return totalBits; |
| 219 | } | 180 | } |
| 220 | 181 | ||
| 221 | // Returns a new instance of this struct that corresponds to the | 182 | IntegerEncoding encoding; |
| 222 | // can take no more than maxval values | 183 | u32 num_bits; |
| 223 | static IntegerEncodedValue CreateEncoding(u32 maxVal) { | 184 | u32 bit_value = 0; |
| 224 | while (maxVal > 0) { | 185 | union { |
| 225 | u32 check = maxVal + 1; | 186 | u32 qus32_value = 0; |
| 187 | u32 trit_value; | ||
| 188 | }; | ||
| 189 | }; | ||
| 226 | 190 | ||
| 227 | // Is maxVal a power of two? | 191 | static void DecodeTritBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, |
| 228 | if (!(check & (check - 1))) { | 192 | u32 nBitsPerValue) { |
| 229 | return IntegerEncodedValue(IntegerEncoding::JustBits, Popcnt(maxVal)); | 193 | // Implement the algorithm in section C.2.12 |
| 230 | } | 194 | u32 m[5]; |
| 195 | u32 t[5]; | ||
| 196 | u32 T; | ||
| 197 | |||
| 198 | // Read the trit encoded block according to | ||
| 199 | // table C.2.14 | ||
| 200 | m[0] = bits.ReadBits(nBitsPerValue); | ||
| 201 | T = bits.ReadBits(2); | ||
| 202 | m[1] = bits.ReadBits(nBitsPerValue); | ||
| 203 | T |= bits.ReadBits(2) << 2; | ||
| 204 | m[2] = bits.ReadBits(nBitsPerValue); | ||
| 205 | T |= bits.ReadBit() << 4; | ||
| 206 | m[3] = bits.ReadBits(nBitsPerValue); | ||
| 207 | T |= bits.ReadBits(2) << 5; | ||
| 208 | m[4] = bits.ReadBits(nBitsPerValue); | ||
| 209 | T |= bits.ReadBit() << 7; | ||
| 210 | |||
| 211 | u32 C = 0; | ||
| 212 | |||
| 213 | Bits<u32> Tb(T); | ||
| 214 | if (Tb(2, 4) == 7) { | ||
| 215 | C = (Tb(5, 7) << 2) | Tb(0, 1); | ||
| 216 | t[4] = t[3] = 2; | ||
| 217 | } else { | ||
| 218 | C = Tb(0, 4); | ||
| 219 | if (Tb(5, 6) == 3) { | ||
| 220 | t[4] = 2; | ||
| 221 | t[3] = Tb[7]; | ||
| 222 | } else { | ||
| 223 | t[4] = Tb[7]; | ||
| 224 | t[3] = Tb(5, 6); | ||
| 225 | } | ||
| 226 | } | ||
| 231 | 227 | ||
| 232 | // Is maxVal of the type 3*2^n - 1? | 228 | Bits<u32> Cb(C); |
| 233 | if ((check % 3 == 0) && !((check / 3) & ((check / 3) - 1))) { | 229 | if (Cb(0, 1) == 3) { |
| 234 | return IntegerEncodedValue(IntegerEncoding::Trit, Popcnt(check / 3 - 1)); | 230 | t[2] = 2; |
| 235 | } | 231 | t[1] = Cb[4]; |
| 232 | t[0] = (Cb[3] << 1) | (Cb[2] & ~Cb[3]); | ||
| 233 | } else if (Cb(2, 3) == 3) { | ||
| 234 | t[2] = 2; | ||
| 235 | t[1] = 2; | ||
| 236 | t[0] = Cb(0, 1); | ||
| 237 | } else { | ||
| 238 | t[2] = Cb[4]; | ||
| 239 | t[1] = Cb(2, 3); | ||
| 240 | t[0] = (Cb[1] << 1) | (Cb[0] & ~Cb[1]); | ||
| 241 | } | ||
| 236 | 242 | ||
| 237 | // Is maxVal of the type 5*2^n - 1? | 243 | for (std::size_t i = 0; i < 5; ++i) { |
| 238 | if ((check % 5 == 0) && !((check / 5) & ((check / 5) - 1))) { | 244 | IntegerEncodedValue& val = result.emplace_back(IntegerEncoding::Trit, nBitsPerValue); |
| 239 | return IntegerEncodedValue(IntegerEncoding::Qus32, Popcnt(check / 5 - 1)); | 245 | val.bit_value = m[i]; |
| 240 | } | 246 | val.trit_value = t[i]; |
| 247 | } | ||
| 248 | } | ||
| 241 | 249 | ||
| 242 | // Apparently it can't be represented with a bounded s32eger sequence... | 250 | static void DecodeQus32Block(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, |
| 243 | // just iterate. | 251 | u32 nBitsPerValue) { |
| 244 | maxVal--; | 252 | // Implement the algorithm in section C.2.12 |
| 253 | u32 m[3]; | ||
| 254 | u32 q[3]; | ||
| 255 | u32 Q; | ||
| 256 | |||
| 257 | // Read the trit encoded block according to | ||
| 258 | // table C.2.15 | ||
| 259 | m[0] = bits.ReadBits(nBitsPerValue); | ||
| 260 | Q = bits.ReadBits(3); | ||
| 261 | m[1] = bits.ReadBits(nBitsPerValue); | ||
| 262 | Q |= bits.ReadBits(2) << 3; | ||
| 263 | m[2] = bits.ReadBits(nBitsPerValue); | ||
| 264 | Q |= bits.ReadBits(2) << 5; | ||
| 265 | |||
| 266 | Bits<u32> Qb(Q); | ||
| 267 | if (Qb(1, 2) == 3 && Qb(5, 6) == 0) { | ||
| 268 | q[0] = q[1] = 4; | ||
| 269 | q[2] = (Qb[0] << 2) | ((Qb[4] & ~Qb[0]) << 1) | (Qb[3] & ~Qb[0]); | ||
| 270 | } else { | ||
| 271 | u32 C = 0; | ||
| 272 | if (Qb(1, 2) == 3) { | ||
| 273 | q[2] = 4; | ||
| 274 | C = (Qb(3, 4) << 3) | ((~Qb(5, 6) & 3) << 1) | Qb[0]; | ||
| 275 | } else { | ||
| 276 | q[2] = Qb(5, 6); | ||
| 277 | C = Qb(0, 4); | ||
| 245 | } | 278 | } |
| 246 | return IntegerEncodedValue(IntegerEncoding::JustBits, 0); | ||
| 247 | } | ||
| 248 | |||
| 249 | // Fills result with the values that are encoded in the given | ||
| 250 | // bitstream. We must know beforehand what the maximum possible | ||
| 251 | // value is, and how many values we're decoding. | ||
| 252 | static void DecodeIntegerSequence(std::vector<IntegerEncodedValue>& result, | ||
| 253 | InputBitStream& bits, u32 maxRange, u32 nValues) { | ||
| 254 | // Determine encoding parameters | ||
| 255 | IntegerEncodedValue val = IntegerEncodedValue::CreateEncoding(maxRange); | ||
| 256 | |||
| 257 | // Start decoding | ||
| 258 | u32 nValsDecoded = 0; | ||
| 259 | while (nValsDecoded < nValues) { | ||
| 260 | switch (val.GetEncoding()) { | ||
| 261 | case IntegerEncoding::Qus32: | ||
| 262 | DecodeQus32Block(bits, result, val.BaseBitLength()); | ||
| 263 | nValsDecoded += 3; | ||
| 264 | break; | ||
| 265 | |||
| 266 | case IntegerEncoding::Trit: | ||
| 267 | DecodeTritBlock(bits, result, val.BaseBitLength()); | ||
| 268 | nValsDecoded += 5; | ||
| 269 | break; | ||
| 270 | 279 | ||
| 271 | case IntegerEncoding::JustBits: | 280 | Bits<u32> Cb(C); |
| 272 | val.SetBitValue(bits.ReadBits(val.BaseBitLength())); | 281 | if (Cb(0, 2) == 5) { |
| 273 | result.push_back(val); | 282 | q[1] = 4; |
| 274 | nValsDecoded++; | 283 | q[0] = Cb(3, 4); |
| 275 | break; | 284 | } else { |
| 276 | } | 285 | q[1] = Cb(3, 4); |
| 286 | q[0] = Cb(0, 2); | ||
| 277 | } | 287 | } |
| 278 | } | 288 | } |
| 279 | 289 | ||
| 280 | private: | 290 | for (std::size_t i = 0; i < 3; ++i) { |
| 281 | static void DecodeTritBlock(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, | 291 | IntegerEncodedValue& val = result.emplace_back(IntegerEncoding::Qus32, nBitsPerValue); |
| 282 | u32 nBitsPerValue) { | 292 | val.bit_value = m[i]; |
| 283 | // Implement the algorithm in section C.2.12 | 293 | val.qus32_value = q[i]; |
| 284 | u32 m[5]; | 294 | } |
| 285 | u32 t[5]; | 295 | } |
| 286 | u32 T; | ||
| 287 | |||
| 288 | // Read the trit encoded block according to | ||
| 289 | // table C.2.14 | ||
| 290 | m[0] = bits.ReadBits(nBitsPerValue); | ||
| 291 | T = bits.ReadBits(2); | ||
| 292 | m[1] = bits.ReadBits(nBitsPerValue); | ||
| 293 | T |= bits.ReadBits(2) << 2; | ||
| 294 | m[2] = bits.ReadBits(nBitsPerValue); | ||
| 295 | T |= bits.ReadBit() << 4; | ||
| 296 | m[3] = bits.ReadBits(nBitsPerValue); | ||
| 297 | T |= bits.ReadBits(2) << 5; | ||
| 298 | m[4] = bits.ReadBits(nBitsPerValue); | ||
| 299 | T |= bits.ReadBit() << 7; | ||
| 300 | 296 | ||
| 301 | u32 C = 0; | 297 | // Returns a new instance of this struct that corresponds to the |
| 298 | // can take no more than maxval values | ||
| 299 | static IntegerEncodedValue CreateEncoding(u32 maxVal) { | ||
| 300 | while (maxVal > 0) { | ||
| 301 | u32 check = maxVal + 1; | ||
| 302 | 302 | ||
| 303 | Bits<u32> Tb(T); | 303 | // Is maxVal a power of two? |
| 304 | if (Tb(2, 4) == 7) { | 304 | if (!(check & (check - 1))) { |
| 305 | C = (Tb(5, 7) << 2) | Tb(0, 1); | 305 | return IntegerEncodedValue(IntegerEncoding::JustBits, Popcnt(maxVal)); |
| 306 | t[4] = t[3] = 2; | ||
| 307 | } else { | ||
| 308 | C = Tb(0, 4); | ||
| 309 | if (Tb(5, 6) == 3) { | ||
| 310 | t[4] = 2; | ||
| 311 | t[3] = Tb[7]; | ||
| 312 | } else { | ||
| 313 | t[4] = Tb[7]; | ||
| 314 | t[3] = Tb(5, 6); | ||
| 315 | } | ||
| 316 | } | 306 | } |
| 317 | 307 | ||
| 318 | Bits<u32> Cb(C); | 308 | // Is maxVal of the type 3*2^n - 1? |
| 319 | if (Cb(0, 1) == 3) { | 309 | if ((check % 3 == 0) && !((check / 3) & ((check / 3) - 1))) { |
| 320 | t[2] = 2; | 310 | return IntegerEncodedValue(IntegerEncoding::Trit, Popcnt(check / 3 - 1)); |
| 321 | t[1] = Cb[4]; | ||
| 322 | t[0] = (Cb[3] << 1) | (Cb[2] & ~Cb[3]); | ||
| 323 | } else if (Cb(2, 3) == 3) { | ||
| 324 | t[2] = 2; | ||
| 325 | t[1] = 2; | ||
| 326 | t[0] = Cb(0, 1); | ||
| 327 | } else { | ||
| 328 | t[2] = Cb[4]; | ||
| 329 | t[1] = Cb(2, 3); | ||
| 330 | t[0] = (Cb[1] << 1) | (Cb[0] & ~Cb[1]); | ||
| 331 | } | 311 | } |
| 332 | 312 | ||
| 333 | for (u32 i = 0; i < 5; i++) { | 313 | // Is maxVal of the type 5*2^n - 1? |
| 334 | IntegerEncodedValue val(IntegerEncoding::Trit, nBitsPerValue); | 314 | if ((check % 5 == 0) && !((check / 5) & ((check / 5) - 1))) { |
| 335 | val.SetBitValue(m[i]); | 315 | return IntegerEncodedValue(IntegerEncoding::Qus32, Popcnt(check / 5 - 1)); |
| 336 | val.SetTritValue(t[i]); | ||
| 337 | result.push_back(val); | ||
| 338 | } | 316 | } |
| 317 | |||
| 318 | // Apparently it can't be represented with a bounded s32eger sequence... | ||
| 319 | // just iterate. | ||
| 320 | maxVal--; | ||
| 339 | } | 321 | } |
| 322 | return IntegerEncodedValue(IntegerEncoding::JustBits, 0); | ||
| 323 | } | ||
| 340 | 324 | ||
| 341 | static void DecodeQus32Block(InputBitStream& bits, std::vector<IntegerEncodedValue>& result, | 325 | // Fills result with the values that are encoded in the given |
| 342 | u32 nBitsPerValue) { | 326 | // bitstream. We must know beforehand what the maximum possible |
| 343 | // Implement the algorithm in section C.2.12 | 327 | // value is, and how many values we're decoding. |
| 344 | u32 m[3]; | 328 | static void DecodeIntegerSequence(std::vector<IntegerEncodedValue>& result, InputBitStream& bits, |
| 345 | u32 q[3]; | 329 | u32 maxRange, u32 nValues) { |
| 346 | u32 Q; | 330 | // Determine encoding parameters |
| 347 | 331 | IntegerEncodedValue val = CreateEncoding(maxRange); | |
| 348 | // Read the trit encoded block according to | 332 | |
| 349 | // table C.2.15 | 333 | // Start decoding |
| 350 | m[0] = bits.ReadBits(nBitsPerValue); | 334 | u32 nValsDecoded = 0; |
| 351 | Q = bits.ReadBits(3); | 335 | while (nValsDecoded < nValues) { |
| 352 | m[1] = bits.ReadBits(nBitsPerValue); | 336 | switch (val.encoding) { |
| 353 | Q |= bits.ReadBits(2) << 3; | 337 | case IntegerEncoding::Qus32: |
| 354 | m[2] = bits.ReadBits(nBitsPerValue); | 338 | DecodeQus32Block(bits, result, val.num_bits); |
| 355 | Q |= bits.ReadBits(2) << 5; | 339 | nValsDecoded += 3; |
| 356 | 340 | break; | |
| 357 | Bits<u32> Qb(Q); | ||
| 358 | if (Qb(1, 2) == 3 && Qb(5, 6) == 0) { | ||
| 359 | q[0] = q[1] = 4; | ||
| 360 | q[2] = (Qb[0] << 2) | ((Qb[4] & ~Qb[0]) << 1) | (Qb[3] & ~Qb[0]); | ||
| 361 | } else { | ||
| 362 | u32 C = 0; | ||
| 363 | if (Qb(1, 2) == 3) { | ||
| 364 | q[2] = 4; | ||
| 365 | C = (Qb(3, 4) << 3) | ((~Qb(5, 6) & 3) << 1) | Qb[0]; | ||
| 366 | } else { | ||
| 367 | q[2] = Qb(5, 6); | ||
| 368 | C = Qb(0, 4); | ||
| 369 | } | ||
| 370 | 341 | ||
| 371 | Bits<u32> Cb(C); | 342 | case IntegerEncoding::Trit: |
| 372 | if (Cb(0, 2) == 5) { | 343 | DecodeTritBlock(bits, result, val.num_bits); |
| 373 | q[1] = 4; | 344 | nValsDecoded += 5; |
| 374 | q[0] = Cb(3, 4); | 345 | break; |
| 375 | } else { | ||
| 376 | q[1] = Cb(3, 4); | ||
| 377 | q[0] = Cb(0, 2); | ||
| 378 | } | ||
| 379 | } | ||
| 380 | 346 | ||
| 381 | for (u32 i = 0; i < 3; i++) { | 347 | case IntegerEncoding::JustBits: |
| 382 | IntegerEncodedValue val(IntegerEncoding::Qus32, nBitsPerValue); | 348 | val.bit_value = bits.ReadBits(val.num_bits); |
| 383 | val.m_BitValue = m[i]; | ||
| 384 | val.m_Qus32Value = q[i]; | ||
| 385 | result.push_back(val); | 349 | result.push_back(val); |
| 350 | nValsDecoded++; | ||
| 351 | break; | ||
| 386 | } | 352 | } |
| 387 | } | 353 | } |
| 388 | }; | 354 | } |
| 389 | 355 | ||
| 390 | namespace ASTCC { | 356 | namespace ASTCC { |
| 391 | 357 | ||
| @@ -405,7 +371,7 @@ struct TexelWeightParams { | |||
| 405 | nIdxs *= 2; | 371 | nIdxs *= 2; |
| 406 | } | 372 | } |
| 407 | 373 | ||
| 408 | return IntegerEncodedValue::CreateEncoding(m_MaxWeight).GetBitLength(nIdxs); | 374 | return CreateEncoding(m_MaxWeight).GetBitLength(nIdxs); |
| 409 | } | 375 | } |
| 410 | 376 | ||
| 411 | u32 GetNumWeightValues() const { | 377 | u32 GetNumWeightValues() const { |
| @@ -814,12 +780,12 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 814 | // figure out the max value for each of them... | 780 | // figure out the max value for each of them... |
| 815 | u32 range = 256; | 781 | u32 range = 256; |
| 816 | while (--range > 0) { | 782 | while (--range > 0) { |
| 817 | IntegerEncodedValue val = IntegerEncodedValue::CreateEncoding(range); | 783 | IntegerEncodedValue val = CreateEncoding(range); |
| 818 | u32 bitLength = val.GetBitLength(nValues); | 784 | u32 bitLength = val.GetBitLength(nValues); |
| 819 | if (bitLength <= nBitsForColorData) { | 785 | if (bitLength <= nBitsForColorData) { |
| 820 | // Find the smallest possible range that matches the given encoding | 786 | // Find the smallest possible range that matches the given encoding |
| 821 | while (--range > 0) { | 787 | while (--range > 0) { |
| 822 | IntegerEncodedValue newval = IntegerEncodedValue::CreateEncoding(range); | 788 | IntegerEncodedValue newval = CreateEncoding(range); |
| 823 | if (!newval.MatchesEncoding(val)) { | 789 | if (!newval.MatchesEncoding(val)) { |
| 824 | break; | 790 | break; |
| 825 | } | 791 | } |
| @@ -834,7 +800,7 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 834 | // We now have enough to decode our s32eger sequence. | 800 | // We now have enough to decode our s32eger sequence. |
| 835 | std::vector<IntegerEncodedValue> decodedColorValues; | 801 | std::vector<IntegerEncodedValue> decodedColorValues; |
| 836 | InputBitStream colorStream(data); | 802 | InputBitStream colorStream(data); |
| 837 | IntegerEncodedValue::DecodeIntegerSequence(decodedColorValues, colorStream, range, nValues); | 803 | DecodeIntegerSequence(decodedColorValues, colorStream, range, nValues); |
| 838 | 804 | ||
| 839 | // Once we have the decoded values, we need to dequantize them to the 0-255 range | 805 | // Once we have the decoded values, we need to dequantize them to the 0-255 range |
| 840 | // This procedure is outlined in ASTC spec C.2.13 | 806 | // This procedure is outlined in ASTC spec C.2.13 |
| @@ -846,8 +812,8 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 846 | } | 812 | } |
| 847 | 813 | ||
| 848 | const IntegerEncodedValue& val = *itr; | 814 | const IntegerEncodedValue& val = *itr; |
| 849 | u32 bitlen = val.BaseBitLength(); | 815 | u32 bitlen = val.num_bits; |
| 850 | u32 bitval = val.GetBitValue(); | 816 | u32 bitval = val.bit_value; |
| 851 | 817 | ||
| 852 | assert(bitlen >= 1); | 818 | assert(bitlen >= 1); |
| 853 | 819 | ||
| @@ -855,7 +821,7 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 855 | // A is just the lsb replicated 9 times. | 821 | // A is just the lsb replicated 9 times. |
| 856 | A = Replicate(bitval & 1, 1, 9); | 822 | A = Replicate(bitval & 1, 1, 9); |
| 857 | 823 | ||
| 858 | switch (val.GetEncoding()) { | 824 | switch (val.encoding) { |
| 859 | // Replicate bits | 825 | // Replicate bits |
| 860 | case IntegerEncoding::JustBits: | 826 | case IntegerEncoding::JustBits: |
| 861 | out[outIdx++] = Replicate(bitval, bitlen, 8); | 827 | out[outIdx++] = Replicate(bitval, bitlen, 8); |
| @@ -864,7 +830,7 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 864 | // Use algorithm in C.2.13 | 830 | // Use algorithm in C.2.13 |
| 865 | case IntegerEncoding::Trit: { | 831 | case IntegerEncoding::Trit: { |
| 866 | 832 | ||
| 867 | D = val.GetTritValue(); | 833 | D = val.trit_value; |
| 868 | 834 | ||
| 869 | switch (bitlen) { | 835 | switch (bitlen) { |
| 870 | case 1: { | 836 | case 1: { |
| @@ -915,7 +881,7 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 915 | 881 | ||
| 916 | case IntegerEncoding::Qus32: { | 882 | case IntegerEncoding::Qus32: { |
| 917 | 883 | ||
| 918 | D = val.GetQus32Value(); | 884 | D = val.qus32_value; |
| 919 | 885 | ||
| 920 | switch (bitlen) { | 886 | switch (bitlen) { |
| 921 | case 1: { | 887 | case 1: { |
| @@ -956,9 +922,9 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 956 | } // switch(bitlen) | 922 | } // switch(bitlen) |
| 957 | } // case IntegerEncoding::Qus32 | 923 | } // case IntegerEncoding::Qus32 |
| 958 | break; | 924 | break; |
| 959 | } // switch(val.GetEncoding()) | 925 | } // switch(val.encoding) |
| 960 | 926 | ||
| 961 | if (val.GetEncoding() != IntegerEncoding::JustBits) { | 927 | if (val.encoding != IntegerEncoding::JustBits) { |
| 962 | u32 T = D * C + B; | 928 | u32 T = D * C + B; |
| 963 | T ^= A; | 929 | T ^= A; |
| 964 | T = (A & 0x80) | (T >> 2); | 930 | T = (A & 0x80) | (T >> 2); |
| @@ -973,20 +939,20 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 973 | } | 939 | } |
| 974 | 940 | ||
| 975 | static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { | 941 | static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { |
| 976 | u32 bitval = val.GetBitValue(); | 942 | u32 bitval = val.bit_value; |
| 977 | u32 bitlen = val.BaseBitLength(); | 943 | u32 bitlen = val.num_bits; |
| 978 | 944 | ||
| 979 | u32 A = Replicate(bitval & 1, 1, 7); | 945 | u32 A = Replicate(bitval & 1, 1, 7); |
| 980 | u32 B = 0, C = 0, D = 0; | 946 | u32 B = 0, C = 0, D = 0; |
| 981 | 947 | ||
| 982 | u32 result = 0; | 948 | u32 result = 0; |
| 983 | switch (val.GetEncoding()) { | 949 | switch (val.encoding) { |
| 984 | case IntegerEncoding::JustBits: | 950 | case IntegerEncoding::JustBits: |
| 985 | result = Replicate(bitval, bitlen, 6); | 951 | result = Replicate(bitval, bitlen, 6); |
| 986 | break; | 952 | break; |
| 987 | 953 | ||
| 988 | case IntegerEncoding::Trit: { | 954 | case IntegerEncoding::Trit: { |
| 989 | D = val.GetTritValue(); | 955 | D = val.trit_value; |
| 990 | assert(D < 3); | 956 | assert(D < 3); |
| 991 | 957 | ||
| 992 | switch (bitlen) { | 958 | switch (bitlen) { |
| @@ -1018,7 +984,7 @@ static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1018 | } break; | 984 | } break; |
| 1019 | 985 | ||
| 1020 | case IntegerEncoding::Qus32: { | 986 | case IntegerEncoding::Qus32: { |
| 1021 | D = val.GetQus32Value(); | 987 | D = val.qus32_value; |
| 1022 | assert(D < 5); | 988 | assert(D < 5); |
| 1023 | 989 | ||
| 1024 | switch (bitlen) { | 990 | switch (bitlen) { |
| @@ -1044,7 +1010,7 @@ static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 1044 | } break; | 1010 | } break; |
| 1045 | } | 1011 | } |
| 1046 | 1012 | ||
| 1047 | if (val.GetEncoding() != IntegerEncoding::JustBits && bitlen > 0) { | 1013 | if (val.encoding != IntegerEncoding::JustBits && bitlen > 0) { |
| 1048 | // Decode the value... | 1014 | // Decode the value... |
| 1049 | result = D * C + B; | 1015 | result = D * C + B; |
| 1050 | result ^= A; | 1016 | result ^= A; |
| @@ -1562,9 +1528,8 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1562 | std::vector<IntegerEncodedValue> texelWeightValues; | 1528 | std::vector<IntegerEncodedValue> texelWeightValues; |
| 1563 | InputBitStream weightStream(texelWeightData); | 1529 | InputBitStream weightStream(texelWeightData); |
| 1564 | 1530 | ||
| 1565 | IntegerEncodedValue::DecodeIntegerSequence(texelWeightValues, weightStream, | 1531 | DecodeIntegerSequence(texelWeightValues, weightStream, weightParams.m_MaxWeight, |
| 1566 | weightParams.m_MaxWeight, | 1532 | weightParams.GetNumWeightValues()); |
| 1567 | weightParams.GetNumWeightValues()); | ||
| 1568 | 1533 | ||
| 1569 | // Blocks can be at most 12x12, so we can have as many as 144 weights | 1534 | // Blocks can be at most 12x12, so we can have as many as 144 weights |
| 1570 | u32 weights[2][144]; | 1535 | u32 weights[2][144]; |