diff options
Diffstat (limited to 'src/video_core/textures/astc.cpp')
| -rw-r--r-- | src/video_core/textures/astc.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index 26c19d75b..25161df1f 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp | |||
| @@ -151,6 +151,76 @@ private: | |||
| 151 | const IntType& m_Bits; | 151 | const IntType& m_Bits; |
| 152 | }; | 152 | }; |
| 153 | 153 | ||
| 154 | enum class IntegerEncoding { JustBits, Quint, Trit }; | ||
| 155 | |||
| 156 | struct IntegerEncodedValue { | ||
| 157 | constexpr IntegerEncodedValue() = default; | ||
| 158 | |||
| 159 | constexpr IntegerEncodedValue(IntegerEncoding encoding_, u32 num_bits_) | ||
| 160 | : encoding{encoding_}, num_bits{num_bits_} {} | ||
| 161 | |||
| 162 | constexpr bool MatchesEncoding(const IntegerEncodedValue& other) const { | ||
| 163 | return encoding == other.encoding && num_bits == other.num_bits; | ||
| 164 | } | ||
| 165 | |||
| 166 | // Returns the number of bits required to encode num_vals values. | ||
| 167 | u32 GetBitLength(u32 num_vals) const { | ||
| 168 | u32 total_bits = num_bits * num_vals; | ||
| 169 | if (encoding == IntegerEncoding::Trit) { | ||
| 170 | total_bits += (num_vals * 8 + 4) / 5; | ||
| 171 | } else if (encoding == IntegerEncoding::Quint) { | ||
| 172 | total_bits += (num_vals * 7 + 2) / 3; | ||
| 173 | } | ||
| 174 | return total_bits; | ||
| 175 | } | ||
| 176 | |||
| 177 | IntegerEncoding encoding{}; | ||
| 178 | u32 num_bits = 0; | ||
| 179 | u32 bit_value = 0; | ||
| 180 | union { | ||
| 181 | u32 quint_value = 0; | ||
| 182 | u32 trit_value; | ||
| 183 | }; | ||
| 184 | }; | ||
| 185 | |||
| 186 | // Returns a new instance of this struct that corresponds to the | ||
| 187 | // can take no more than mav_value values | ||
| 188 | static constexpr IntegerEncodedValue CreateEncoding(u32 mav_value) { | ||
| 189 | while (mav_value > 0) { | ||
| 190 | u32 check = mav_value + 1; | ||
| 191 | |||
| 192 | // Is mav_value a power of two? | ||
| 193 | if (!(check & (check - 1))) { | ||
| 194 | return IntegerEncodedValue(IntegerEncoding::JustBits, std::popcount(mav_value)); | ||
| 195 | } | ||
| 196 | |||
| 197 | // Is mav_value of the type 3*2^n - 1? | ||
| 198 | if ((check % 3 == 0) && !((check / 3) & ((check / 3) - 1))) { | ||
| 199 | return IntegerEncodedValue(IntegerEncoding::Trit, std::popcount(check / 3 - 1)); | ||
| 200 | } | ||
| 201 | |||
| 202 | // Is mav_value of the type 5*2^n - 1? | ||
| 203 | if ((check % 5 == 0) && !((check / 5) & ((check / 5) - 1))) { | ||
| 204 | return IntegerEncodedValue(IntegerEncoding::Quint, std::popcount(check / 5 - 1)); | ||
| 205 | } | ||
| 206 | |||
| 207 | // Apparently it can't be represented with a bounded integer sequence... | ||
| 208 | // just iterate. | ||
| 209 | mav_value--; | ||
| 210 | } | ||
| 211 | return IntegerEncodedValue(IntegerEncoding::JustBits, 0); | ||
| 212 | } | ||
| 213 | |||
| 214 | static constexpr std::array<IntegerEncodedValue, 256> MakeEncodedValues() { | ||
| 215 | std::array<IntegerEncodedValue, 256> encodings{}; | ||
| 216 | for (std::size_t i = 0; i < encodings.size(); ++i) { | ||
| 217 | encodings[i] = CreateEncoding(static_cast<u32>(i)); | ||
| 218 | } | ||
| 219 | return encodings; | ||
| 220 | } | ||
| 221 | |||
| 222 | static constexpr std::array<IntegerEncodedValue, 256> ASTC_ENCODINGS_VALUES = MakeEncodedValues(); | ||
| 223 | |||
| 154 | namespace Tegra::Texture::ASTC { | 224 | namespace Tegra::Texture::ASTC { |
| 155 | using IntegerEncodedVector = boost::container::static_vector< | 225 | using IntegerEncodedVector = boost::container::static_vector< |
| 156 | IntegerEncodedValue, 256, | 226 | IntegerEncodedValue, 256, |