diff options
| author | 2020-03-13 23:40:02 -0300 | |
|---|---|---|
| committer | 2020-03-13 23:40:02 -0300 | |
| commit | 801fd04f75fbd5072139759c2a7aac4571b29885 (patch) | |
| tree | b798ecdadd6f6103c7fe8990229a59f86cefe10c /src | |
| parent | astc: Make IntegerEncodedValue a trivial structure (diff) | |
| download | yuzu-801fd04f75fbd5072139759c2a7aac4571b29885.tar.gz yuzu-801fd04f75fbd5072139759c2a7aac4571b29885.tar.xz yuzu-801fd04f75fbd5072139759c2a7aac4571b29885.zip | |
astc: Create a LUT at compile time for encoding values
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/textures/astc.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index 2d948ee62..eb93b44bd 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp | |||
| @@ -161,6 +161,8 @@ private: | |||
| 161 | enum class IntegerEncoding { JustBits, Qus32, Trit }; | 161 | enum class IntegerEncoding { JustBits, Qus32, Trit }; |
| 162 | 162 | ||
| 163 | struct IntegerEncodedValue { | 163 | struct IntegerEncodedValue { |
| 164 | constexpr IntegerEncodedValue() = default; | ||
| 165 | |||
| 164 | constexpr IntegerEncodedValue(IntegerEncoding encoding_, u32 num_bits_) | 166 | constexpr IntegerEncodedValue(IntegerEncoding encoding_, u32 num_bits_) |
| 165 | : encoding{encoding_}, num_bits{num_bits_} {} | 167 | : encoding{encoding_}, num_bits{num_bits_} {} |
| 166 | 168 | ||
| @@ -179,8 +181,8 @@ struct IntegerEncodedValue { | |||
| 179 | return totalBits; | 181 | return totalBits; |
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | IntegerEncoding encoding; | 184 | IntegerEncoding encoding{}; |
| 183 | u32 num_bits; | 185 | u32 num_bits = 0; |
| 184 | u32 bit_value = 0; | 186 | u32 bit_value = 0; |
| 185 | union { | 187 | union { |
| 186 | u32 qus32_value = 0; | 188 | u32 qus32_value = 0; |
| @@ -296,7 +298,7 @@ static void DecodeQus32Block(InputBitStream& bits, std::vector<IntegerEncodedVal | |||
| 296 | 298 | ||
| 297 | // Returns a new instance of this struct that corresponds to the | 299 | // Returns a new instance of this struct that corresponds to the |
| 298 | // can take no more than maxval values | 300 | // can take no more than maxval values |
| 299 | static IntegerEncodedValue CreateEncoding(u32 maxVal) { | 301 | static constexpr IntegerEncodedValue CreateEncoding(u32 maxVal) { |
| 300 | while (maxVal > 0) { | 302 | while (maxVal > 0) { |
| 301 | u32 check = maxVal + 1; | 303 | u32 check = maxVal + 1; |
| 302 | 304 | ||
| @@ -322,13 +324,23 @@ static IntegerEncodedValue CreateEncoding(u32 maxVal) { | |||
| 322 | return IntegerEncodedValue(IntegerEncoding::JustBits, 0); | 324 | return IntegerEncodedValue(IntegerEncoding::JustBits, 0); |
| 323 | } | 325 | } |
| 324 | 326 | ||
| 327 | static constexpr std::array<IntegerEncodedValue, 256> MakeEncodedValues() { | ||
| 328 | std::array<IntegerEncodedValue, 256> encodings{}; | ||
| 329 | for (std::size_t i = 0; i < encodings.size(); ++i) { | ||
| 330 | encodings[i] = CreateEncoding(static_cast<u32>(i)); | ||
| 331 | } | ||
| 332 | return encodings; | ||
| 333 | } | ||
| 334 | |||
| 335 | static constexpr std::array EncodingsValues = MakeEncodedValues(); | ||
| 336 | |||
| 325 | // Fills result with the values that are encoded in the given | 337 | // Fills result with the values that are encoded in the given |
| 326 | // bitstream. We must know beforehand what the maximum possible | 338 | // bitstream. We must know beforehand what the maximum possible |
| 327 | // value is, and how many values we're decoding. | 339 | // value is, and how many values we're decoding. |
| 328 | static void DecodeIntegerSequence(std::vector<IntegerEncodedValue>& result, InputBitStream& bits, | 340 | static void DecodeIntegerSequence(std::vector<IntegerEncodedValue>& result, InputBitStream& bits, |
| 329 | u32 maxRange, u32 nValues) { | 341 | u32 maxRange, u32 nValues) { |
| 330 | // Determine encoding parameters | 342 | // Determine encoding parameters |
| 331 | IntegerEncodedValue val = CreateEncoding(maxRange); | 343 | IntegerEncodedValue val = EncodingsValues[maxRange]; |
| 332 | 344 | ||
| 333 | // Start decoding | 345 | // Start decoding |
| 334 | u32 nValsDecoded = 0; | 346 | u32 nValsDecoded = 0; |
| @@ -371,7 +383,7 @@ struct TexelWeightParams { | |||
| 371 | nIdxs *= 2; | 383 | nIdxs *= 2; |
| 372 | } | 384 | } |
| 373 | 385 | ||
| 374 | return CreateEncoding(m_MaxWeight).GetBitLength(nIdxs); | 386 | return EncodingsValues[m_MaxWeight].GetBitLength(nIdxs); |
| 375 | } | 387 | } |
| 376 | 388 | ||
| 377 | u32 GetNumWeightValues() const { | 389 | u32 GetNumWeightValues() const { |
| @@ -780,12 +792,12 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 780 | // figure out the max value for each of them... | 792 | // figure out the max value for each of them... |
| 781 | u32 range = 256; | 793 | u32 range = 256; |
| 782 | while (--range > 0) { | 794 | while (--range > 0) { |
| 783 | IntegerEncodedValue val = CreateEncoding(range); | 795 | IntegerEncodedValue val = EncodingsValues[range]; |
| 784 | u32 bitLength = val.GetBitLength(nValues); | 796 | u32 bitLength = val.GetBitLength(nValues); |
| 785 | if (bitLength <= nBitsForColorData) { | 797 | if (bitLength <= nBitsForColorData) { |
| 786 | // Find the smallest possible range that matches the given encoding | 798 | // Find the smallest possible range that matches the given encoding |
| 787 | while (--range > 0) { | 799 | while (--range > 0) { |
| 788 | IntegerEncodedValue newval = CreateEncoding(range); | 800 | IntegerEncodedValue newval = EncodingsValues[range]; |
| 789 | if (!newval.MatchesEncoding(val)) { | 801 | if (!newval.MatchesEncoding(val)) { |
| 790 | break; | 802 | break; |
| 791 | } | 803 | } |