diff options
Diffstat (limited to 'src/video_core/surface.h')
| -rw-r--r-- | src/video_core/surface.h | 152 |
1 files changed, 15 insertions, 137 deletions
diff --git a/src/video_core/surface.h b/src/video_core/surface.h index cfd12fa61..c40ab89d0 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h | |||
| @@ -120,7 +120,7 @@ enum class PixelFormat { | |||
| 120 | Max = MaxDepthStencilFormat, | 120 | Max = MaxDepthStencilFormat, |
| 121 | Invalid = 255, | 121 | Invalid = 255, |
| 122 | }; | 122 | }; |
| 123 | static constexpr std::size_t MaxPixelFormat = static_cast<std::size_t>(PixelFormat::Max); | 123 | constexpr std::size_t MaxPixelFormat = static_cast<std::size_t>(PixelFormat::Max); |
| 124 | 124 | ||
| 125 | enum class SurfaceType { | 125 | enum class SurfaceType { |
| 126 | ColorTexture = 0, | 126 | ColorTexture = 0, |
| @@ -140,117 +140,7 @@ enum class SurfaceTarget { | |||
| 140 | TextureCubeArray, | 140 | TextureCubeArray, |
| 141 | }; | 141 | }; |
| 142 | 142 | ||
| 143 | constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{ | 143 | constexpr std::array<u32, MaxPixelFormat> BLOCK_WIDTH_TABLE = {{ |
| 144 | 0, // A8B8G8R8_UNORM | ||
| 145 | 0, // A8B8G8R8_SNORM | ||
| 146 | 0, // A8B8G8R8_SINT | ||
| 147 | 0, // A8B8G8R8_UINT | ||
| 148 | 0, // R5G6B5_UNORM | ||
| 149 | 0, // B5G6R5_UNORM | ||
| 150 | 0, // A1R5G5B5_UNORM | ||
| 151 | 0, // A2B10G10R10_UNORM | ||
| 152 | 0, // A2B10G10R10_UINT | ||
| 153 | 0, // A1B5G5R5_UNORM | ||
| 154 | 0, // R8_UNORM | ||
| 155 | 0, // R8_SNORM | ||
| 156 | 0, // R8_SINT | ||
| 157 | 0, // R8_UINT | ||
| 158 | 0, // R16G16B16A16_FLOAT | ||
| 159 | 0, // R16G16B16A16_UNORM | ||
| 160 | 0, // R16G16B16A16_SNORM | ||
| 161 | 0, // R16G16B16A16_SINT | ||
| 162 | 0, // R16G16B16A16_UINT | ||
| 163 | 0, // B10G11R11_FLOAT | ||
| 164 | 0, // R32G32B32A32_UINT | ||
| 165 | 2, // BC1_RGBA_UNORM | ||
| 166 | 2, // BC2_UNORM | ||
| 167 | 2, // BC3_UNORM | ||
| 168 | 2, // BC4_UNORM | ||
| 169 | 2, // BC4_SNORM | ||
| 170 | 2, // BC5_UNORM | ||
| 171 | 2, // BC5_SNORM | ||
| 172 | 2, // BC7_UNORM | ||
| 173 | 2, // BC6H_UFLOAT | ||
| 174 | 2, // BC6H_SFLOAT | ||
| 175 | 2, // ASTC_2D_4X4_UNORM | ||
| 176 | 0, // B8G8R8A8_UNORM | ||
| 177 | 0, // R32G32B32A32_FLOAT | ||
| 178 | 0, // R32G32B32A32_SINT | ||
| 179 | 0, // R32G32_FLOAT | ||
| 180 | 0, // R32G32_SINT | ||
| 181 | 0, // R32_FLOAT | ||
| 182 | 0, // R16_FLOAT | ||
| 183 | 0, // R16_UNORM | ||
| 184 | 0, // R16_SNORM | ||
| 185 | 0, // R16_UINT | ||
| 186 | 0, // R16_SINT | ||
| 187 | 0, // R16G16_UNORM | ||
| 188 | 0, // R16G16_FLOAT | ||
| 189 | 0, // R16G16_UINT | ||
| 190 | 0, // R16G16_SINT | ||
| 191 | 0, // R16G16_SNORM | ||
| 192 | 0, // R32G32B32_FLOAT | ||
| 193 | 0, // A8B8G8R8_SRGB | ||
| 194 | 0, // R8G8_UNORM | ||
| 195 | 0, // R8G8_SNORM | ||
| 196 | 0, // R8G8_SINT | ||
| 197 | 0, // R8G8_UINT | ||
| 198 | 0, // R32G32_UINT | ||
| 199 | 0, // R16G16B16X16_FLOAT | ||
| 200 | 0, // R32_UINT | ||
| 201 | 0, // R32_SINT | ||
| 202 | 2, // ASTC_2D_8X8_UNORM | ||
| 203 | 2, // ASTC_2D_8X5_UNORM | ||
| 204 | 2, // ASTC_2D_5X4_UNORM | ||
| 205 | 0, // B8G8R8A8_SRGB | ||
| 206 | 2, // BC1_RGBA_SRGB | ||
| 207 | 2, // BC2_SRGB | ||
| 208 | 2, // BC3_SRGB | ||
| 209 | 2, // BC7_SRGB | ||
| 210 | 0, // A4B4G4R4_UNORM | ||
| 211 | 2, // ASTC_2D_4X4_SRGB | ||
| 212 | 2, // ASTC_2D_8X8_SRGB | ||
| 213 | 2, // ASTC_2D_8X5_SRGB | ||
| 214 | 2, // ASTC_2D_5X4_SRGB | ||
| 215 | 2, // ASTC_2D_5X5_UNORM | ||
| 216 | 2, // ASTC_2D_5X5_SRGB | ||
| 217 | 2, // ASTC_2D_10X8_UNORM | ||
| 218 | 2, // ASTC_2D_10X8_SRGB | ||
| 219 | 2, // ASTC_2D_6X6_UNORM | ||
| 220 | 2, // ASTC_2D_6X6_SRGB | ||
| 221 | 2, // ASTC_2D_10X10_UNORM | ||
| 222 | 2, // ASTC_2D_10X10_SRGB | ||
| 223 | 2, // ASTC_2D_12X12_UNORM | ||
| 224 | 2, // ASTC_2D_12X12_SRGB | ||
| 225 | 2, // ASTC_2D_8X6_UNORM | ||
| 226 | 2, // ASTC_2D_8X6_SRGB | ||
| 227 | 2, // ASTC_2D_6X5_UNORM | ||
| 228 | 2, // ASTC_2D_6X5_SRGB | ||
| 229 | 0, // E5B9G9R9_FLOAT | ||
| 230 | 0, // D32_FLOAT | ||
| 231 | 0, // D16_UNORM | ||
| 232 | 0, // D24_UNORM_S8_UINT | ||
| 233 | 0, // S8_UINT_D24_UNORM | ||
| 234 | 0, // D32_FLOAT_S8_UINT | ||
| 235 | }}; | ||
| 236 | |||
| 237 | /** | ||
| 238 | * Gets the compression factor for the specified PixelFormat. This applies to just the | ||
| 239 | * "compressed width" and "compressed height", not the overall compression factor of a | ||
| 240 | * compressed image. This is used for maintaining proper surface sizes for compressed | ||
| 241 | * texture formats. | ||
| 242 | */ | ||
| 243 | inline constexpr u32 GetCompressionFactorShift(PixelFormat format) { | ||
| 244 | DEBUG_ASSERT(format != PixelFormat::Invalid); | ||
| 245 | DEBUG_ASSERT(static_cast<std::size_t>(format) < compression_factor_shift_table.size()); | ||
| 246 | return compression_factor_shift_table[static_cast<std::size_t>(format)]; | ||
| 247 | } | ||
| 248 | |||
| 249 | inline constexpr u32 GetCompressionFactor(PixelFormat format) { | ||
| 250 | return 1U << GetCompressionFactorShift(format); | ||
| 251 | } | ||
| 252 | |||
| 253 | constexpr std::array<u32, MaxPixelFormat> block_width_table = {{ | ||
| 254 | 1, // A8B8G8R8_UNORM | 144 | 1, // A8B8G8R8_UNORM |
| 255 | 1, // A8B8G8R8_SNORM | 145 | 1, // A8B8G8R8_SNORM |
| 256 | 1, // A8B8G8R8_SINT | 146 | 1, // A8B8G8R8_SINT |
| @@ -344,15 +234,12 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{ | |||
| 344 | 1, // D32_FLOAT_S8_UINT | 234 | 1, // D32_FLOAT_S8_UINT |
| 345 | }}; | 235 | }}; |
| 346 | 236 | ||
| 347 | static constexpr u32 GetDefaultBlockWidth(PixelFormat format) { | 237 | constexpr u32 DefaultBlockWidth(PixelFormat format) { |
| 348 | if (format == PixelFormat::Invalid) | 238 | ASSERT(static_cast<std::size_t>(format) < BLOCK_WIDTH_TABLE.size()); |
| 349 | return 0; | 239 | return BLOCK_WIDTH_TABLE[static_cast<std::size_t>(format)]; |
| 350 | |||
| 351 | ASSERT(static_cast<std::size_t>(format) < block_width_table.size()); | ||
| 352 | return block_width_table[static_cast<std::size_t>(format)]; | ||
| 353 | } | 240 | } |
| 354 | 241 | ||
| 355 | constexpr std::array<u32, MaxPixelFormat> block_height_table = {{ | 242 | constexpr std::array<u32, MaxPixelFormat> BLOCK_HEIGHT_TABLE = {{ |
| 356 | 1, // A8B8G8R8_UNORM | 243 | 1, // A8B8G8R8_UNORM |
| 357 | 1, // A8B8G8R8_SNORM | 244 | 1, // A8B8G8R8_SNORM |
| 358 | 1, // A8B8G8R8_SINT | 245 | 1, // A8B8G8R8_SINT |
| @@ -446,15 +333,12 @@ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{ | |||
| 446 | 1, // D32_FLOAT_S8_UINT | 333 | 1, // D32_FLOAT_S8_UINT |
| 447 | }}; | 334 | }}; |
| 448 | 335 | ||
| 449 | static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { | 336 | constexpr u32 DefaultBlockHeight(PixelFormat format) { |
| 450 | if (format == PixelFormat::Invalid) | 337 | ASSERT(static_cast<std::size_t>(format) < BLOCK_HEIGHT_TABLE.size()); |
| 451 | return 0; | 338 | return BLOCK_HEIGHT_TABLE[static_cast<std::size_t>(format)]; |
| 452 | |||
| 453 | ASSERT(static_cast<std::size_t>(format) < block_height_table.size()); | ||
| 454 | return block_height_table[static_cast<std::size_t>(format)]; | ||
| 455 | } | 339 | } |
| 456 | 340 | ||
| 457 | constexpr std::array<u32, MaxPixelFormat> bpp_table = {{ | 341 | constexpr std::array<u32, MaxPixelFormat> BITS_PER_BLOCK_TABLE = {{ |
| 458 | 32, // A8B8G8R8_UNORM | 342 | 32, // A8B8G8R8_UNORM |
| 459 | 32, // A8B8G8R8_SNORM | 343 | 32, // A8B8G8R8_SNORM |
| 460 | 32, // A8B8G8R8_SINT | 344 | 32, // A8B8G8R8_SINT |
| @@ -548,20 +432,14 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{ | |||
| 548 | 64, // D32_FLOAT_S8_UINT | 432 | 64, // D32_FLOAT_S8_UINT |
| 549 | }}; | 433 | }}; |
| 550 | 434 | ||
| 551 | static constexpr u32 GetFormatBpp(PixelFormat format) { | 435 | constexpr u32 BitsPerBlock(PixelFormat format) { |
| 552 | if (format == PixelFormat::Invalid) | 436 | ASSERT(static_cast<std::size_t>(format) < BITS_PER_BLOCK_TABLE.size()); |
| 553 | return 0; | 437 | return BITS_PER_BLOCK_TABLE[static_cast<std::size_t>(format)]; |
| 554 | |||
| 555 | ASSERT(static_cast<std::size_t>(format) < bpp_table.size()); | ||
| 556 | return bpp_table[static_cast<std::size_t>(format)]; | ||
| 557 | } | 438 | } |
| 558 | 439 | ||
| 559 | /// Returns the sizer in bytes of the specified pixel format | 440 | /// Returns the sizer in bytes of the specified pixel format |
| 560 | static constexpr u32 GetBytesPerPixel(PixelFormat pixel_format) { | 441 | constexpr u32 BytesPerBlock(PixelFormat pixel_format) { |
| 561 | if (pixel_format == PixelFormat::Invalid) { | 442 | return BitsPerBlock(pixel_format) / CHAR_BIT; |
| 562 | return 0; | ||
| 563 | } | ||
| 564 | return GetFormatBpp(pixel_format) / CHAR_BIT; | ||
| 565 | } | 443 | } |
| 566 | 444 | ||
| 567 | SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_type); | 445 | SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_type); |