diff options
| -rw-r--r-- | src/video_core/textures/astc.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index 91b4c5d7e..0985cb578 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp | |||
| @@ -628,12 +628,14 @@ static void FillError(u32* outBuf, u32 blockWidth, u32 blockHeight) { | |||
| 628 | // Replicates low numBits such that [(toBit - 1):(toBit - 1 - fromBit)] | 628 | // Replicates low numBits such that [(toBit - 1):(toBit - 1 - fromBit)] |
| 629 | // is the same as [(numBits - 1):0] and repeats all the way down. | 629 | // is the same as [(numBits - 1):0] and repeats all the way down. |
| 630 | template <typename IntType> | 630 | template <typename IntType> |
| 631 | static IntType Replicate(IntType val, u32 numBits, u32 toBit) { | 631 | static constexpr IntType Replicate(IntType val, u32 numBits, u32 toBit) { |
| 632 | if (numBits == 0) | 632 | if (numBits == 0) { |
| 633 | return 0; | 633 | return 0; |
| 634 | if (toBit == 0) | 634 | } |
| 635 | if (toBit == 0) { | ||
| 635 | return 0; | 636 | return 0; |
| 636 | IntType v = val & static_cast<IntType>((1 << numBits) - 1); | 637 | } |
| 638 | const IntType v = val & static_cast<IntType>((1 << numBits) - 1); | ||
| 637 | IntType res = v; | 639 | IntType res = v; |
| 638 | u32 reslen = numBits; | 640 | u32 reslen = numBits; |
| 639 | while (reslen < toBit) { | 641 | while (reslen < toBit) { |
| @@ -650,6 +652,34 @@ static IntType Replicate(IntType val, u32 numBits, u32 toBit) { | |||
| 650 | return res; | 652 | return res; |
| 651 | } | 653 | } |
| 652 | 654 | ||
| 655 | static constexpr std::size_t NumReplicateEntries(u32 num_bits) { | ||
| 656 | return std::size_t(1) << num_bits; | ||
| 657 | } | ||
| 658 | |||
| 659 | template <typename IntType, u32 num_bits, u32 to_bit> | ||
| 660 | static constexpr auto MakeReplicateTable() { | ||
| 661 | std::array<IntType, NumReplicateEntries(num_bits)> table{}; | ||
| 662 | for (IntType value = 0; value < static_cast<IntType>(std::size(table)); ++value) { | ||
| 663 | table[value] = Replicate(value, num_bits, to_bit); | ||
| 664 | } | ||
| 665 | return table; | ||
| 666 | } | ||
| 667 | |||
| 668 | static constexpr auto REPLICATE_BYTE_TO_16_TABLE = MakeReplicateTable<u32, 8, 16>(); | ||
| 669 | static constexpr u32 ReplicateByteTo16(std::size_t value) { | ||
| 670 | return REPLICATE_BYTE_TO_16_TABLE[value]; | ||
| 671 | } | ||
| 672 | |||
| 673 | static constexpr auto REPLICATE_BIT_TO_7_TABLE = MakeReplicateTable<u32, 1, 7>(); | ||
| 674 | static constexpr u32 ReplicateBitTo7(std::size_t value) { | ||
| 675 | return REPLICATE_BIT_TO_7_TABLE[value]; | ||
| 676 | } | ||
| 677 | |||
| 678 | static constexpr auto REPLICATE_BIT_TO_9_TABLE = MakeReplicateTable<u32, 1, 9>(); | ||
| 679 | static constexpr u32 ReplicateBitTo9(std::size_t value) { | ||
| 680 | return REPLICATE_BIT_TO_9_TABLE[value]; | ||
| 681 | } | ||
| 682 | |||
| 653 | class Pixel { | 683 | class Pixel { |
| 654 | protected: | 684 | protected: |
| 655 | using ChannelType = s16; | 685 | using ChannelType = s16; |
| @@ -833,7 +863,7 @@ static void DecodeColorValues(u32* out, u8* data, const u32* modes, const u32 nP | |||
| 833 | 863 | ||
| 834 | u32 A = 0, B = 0, C = 0, D = 0; | 864 | u32 A = 0, B = 0, C = 0, D = 0; |
| 835 | // A is just the lsb replicated 9 times. | 865 | // A is just the lsb replicated 9 times. |
| 836 | A = Replicate(bitval & 1, 1, 9); | 866 | A = ReplicateBitTo9(bitval & 1); |
| 837 | 867 | ||
| 838 | switch (val.encoding) { | 868 | switch (val.encoding) { |
| 839 | // Replicate bits | 869 | // Replicate bits |
| @@ -956,7 +986,7 @@ static u32 UnquantizeTexelWeight(const IntegerEncodedValue& val) { | |||
| 956 | u32 bitval = val.bit_value; | 986 | u32 bitval = val.bit_value; |
| 957 | u32 bitlen = val.num_bits; | 987 | u32 bitlen = val.num_bits; |
| 958 | 988 | ||
| 959 | u32 A = Replicate(bitval & 1, 1, 7); | 989 | u32 A = ReplicateBitTo7(bitval & 1); |
| 960 | u32 B = 0, C = 0, D = 0; | 990 | u32 B = 0, C = 0, D = 0; |
| 961 | 991 | ||
| 962 | u32 result = 0; | 992 | u32 result = 0; |
| @@ -1562,9 +1592,9 @@ static void DecompressBlock(const u8 inBuf[16], const u32 blockWidth, const u32 | |||
| 1562 | Pixel p; | 1592 | Pixel p; |
| 1563 | for (u32 c = 0; c < 4; c++) { | 1593 | for (u32 c = 0; c < 4; c++) { |
| 1564 | u32 C0 = endpos32s[partition][0].Component(c); | 1594 | u32 C0 = endpos32s[partition][0].Component(c); |
| 1565 | C0 = Replicate(C0, 8, 16); | 1595 | C0 = ReplicateByteTo16(C0); |
| 1566 | u32 C1 = endpos32s[partition][1].Component(c); | 1596 | u32 C1 = endpos32s[partition][1].Component(c); |
| 1567 | C1 = Replicate(C1, 8, 16); | 1597 | C1 = ReplicateByteTo16(C1); |
| 1568 | 1598 | ||
| 1569 | u32 plane = 0; | 1599 | u32 plane = 0; |
| 1570 | if (weightParams.m_bDualPlane && (((planeIdx + 1) & 3) == c)) { | 1600 | if (weightParams.m_bDualPlane && (((planeIdx + 1) & 3) == c)) { |