From b9ddb517b191b449b8d935acb29962e43054dde4 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Wed, 2 Oct 2019 19:00:16 -0400 Subject: [PATCH 1/2] Surfaces: Implement ASTC 6x6 10x10 12x12 8x6 6x5 --- src/video_core/morton.cpp | 20 ++ .../renderer_opengl/gl_texture_cache.cpp | 10 + src/video_core/surface.cpp | 25 +++ src/video_core/surface.h | 200 ++++++++++++------ 4 files changed, 185 insertions(+), 70 deletions(-) diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index ab71870ab6..f8f8414906 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -101,6 +101,16 @@ static constexpr ConversionArray morton_to_linear_fns = { MortonCopy, MortonCopy, MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, + MortonCopy, MortonCopy, MortonCopy, MortonCopy, @@ -170,6 +180,16 @@ static constexpr ConversionArray linear_to_morton_fns = { nullptr, nullptr, nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, MortonCopy, MortonCopy, MortonCopy, diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 173b76c4ed..a0ca502b49 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -120,6 +120,16 @@ constexpr std::array tex_format {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X5_SRGB {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X8 {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X8_SRGB + {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X6 + {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X6_SRGB + {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X10 + {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_10X10_SRGB + {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_12X12 + {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_12X12_SRGB + {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X6 + {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X6_SRGB + {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X5 + {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_6X5_SRGB // Depth formats {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, ComponentType::Float, false}, // Z32F diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index 250afc6d6a..a61dcbfb08 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -350,6 +350,16 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format, return is_srgb ? PixelFormat::ASTC_2D_8X5_SRGB : PixelFormat::ASTC_2D_8X5; case Tegra::Texture::TextureFormat::ASTC_2D_10X8: return is_srgb ? PixelFormat::ASTC_2D_10X8_SRGB : PixelFormat::ASTC_2D_10X8; + case Tegra::Texture::TextureFormat::ASTC_2D_6X6: + return is_srgb ? PixelFormat::ASTC_2D_6X6_SRGB : PixelFormat::ASTC_2D_6X6; + case Tegra::Texture::TextureFormat::ASTC_2D_10X10: + return is_srgb ? PixelFormat::ASTC_2D_10X10_SRGB : PixelFormat::ASTC_2D_10X10; + case Tegra::Texture::TextureFormat::ASTC_2D_12X12: + return is_srgb ? PixelFormat::ASTC_2D_12X12_SRGB : PixelFormat::ASTC_2D_12X12; + case Tegra::Texture::TextureFormat::ASTC_2D_8X6: + return is_srgb ? PixelFormat::ASTC_2D_8X6_SRGB : PixelFormat::ASTC_2D_8X6; + case Tegra::Texture::TextureFormat::ASTC_2D_6X5: + return is_srgb ? PixelFormat::ASTC_2D_6X5_SRGB : PixelFormat::ASTC_2D_6X5; case Tegra::Texture::TextureFormat::R16_G16: switch (component_type) { case Tegra::Texture::ComponentType::FLOAT: @@ -510,6 +520,16 @@ bool IsPixelFormatASTC(PixelFormat format) { case PixelFormat::ASTC_2D_8X5_SRGB: case PixelFormat::ASTC_2D_10X8: case PixelFormat::ASTC_2D_10X8_SRGB: + case PixelFormat::ASTC_2D_6X6: + case PixelFormat::ASTC_2D_6X6_SRGB: + case PixelFormat::ASTC_2D_10X10: + case PixelFormat::ASTC_2D_10X10_SRGB: + case PixelFormat::ASTC_2D_12X12: + case PixelFormat::ASTC_2D_12X12_SRGB: + case PixelFormat::ASTC_2D_8X6: + case PixelFormat::ASTC_2D_8X6_SRGB: + case PixelFormat::ASTC_2D_6X5: + case PixelFormat::ASTC_2D_6X5_SRGB: return true; default: return false; @@ -530,6 +550,11 @@ bool IsPixelFormatSRGB(PixelFormat format) { case PixelFormat::ASTC_2D_5X4_SRGB: case PixelFormat::ASTC_2D_5X5_SRGB: case PixelFormat::ASTC_2D_10X8_SRGB: + case PixelFormat::ASTC_2D_6X6_SRGB: + case PixelFormat::ASTC_2D_10X10_SRGB: + case PixelFormat::ASTC_2D_12X12_SRGB: + case PixelFormat::ASTC_2D_8X6_SRGB: + case PixelFormat::ASTC_2D_6X5_SRGB: return true; default: return false; diff --git a/src/video_core/surface.h b/src/video_core/surface.h index 1e1c432a58..dc7306a749 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -75,19 +75,29 @@ enum class PixelFormat { ASTC_2D_5X5_SRGB = 57, ASTC_2D_10X8 = 58, ASTC_2D_10X8_SRGB = 59, + ASTC_2D_6X6 = 60, + ASTC_2D_6X6_SRGB = 61, + ASTC_2D_10X10 = 62, + ASTC_2D_10X10_SRGB = 63, + ASTC_2D_12X12 = 64, + ASTC_2D_12X12_SRGB = 65, + ASTC_2D_8X6 = 66, + ASTC_2D_8X6_SRGB = 67, + ASTC_2D_6X5 = 68, + ASTC_2D_6X5_SRGB = 69, MaxColorFormat, // Depth formats - Z32F = 60, - Z16 = 61, + Z32F = 70, + Z16 = 71, MaxDepthFormat, // DepthStencil formats - Z24S8 = 62, - S8Z24 = 63, - Z32FS8 = 64, + Z24S8 = 72, + S8Z24 = 73, + Z32FS8 = 74, MaxDepthStencilFormat, @@ -185,6 +195,16 @@ constexpr std::array compression_factor_shift_table = {{ 2, // ASTC_2D_5X5_SRGB 2, // ASTC_2D_10X8 2, // ASTC_2D_10X8_SRGB + 2, // ASTC_2D_6X6 + 2, // ASTC_2D_6X6_SRGB + 2, // ASTC_2D_10X10 + 2, // ASTC_2D_10X10_SRGB + 2, // ASTC_2D_12X12 + 2, // ASTC_2D_12X12_SRGB + 2, // ASTC_2D_8X6 + 2, // ASTC_2D_8X6_SRGB + 2, // ASTC_2D_6X5 + 2, // ASTC_2D_6X5_SRGB 0, // Z32F 0, // Z16 0, // Z24S8 @@ -269,6 +289,16 @@ constexpr std::array block_width_table = {{ 5, // ASTC_2D_5X5_SRGB 10, // ASTC_2D_10X8 10, // ASTC_2D_10X8_SRGB + 6, // ASTC_2D_6X6 + 6, // ASTC_2D_6X6_SRGB + 10, // ASTC_2D_10X10 + 10, // ASTC_2D_10X10_SRGB + 12, // ASTC_2D_12X12 + 12, // ASTC_2D_12X12_SRGB + 8, // ASTC_2D_8X6 + 8, // ASTC_2D_8X6_SRGB + 6, // ASTC_2D_6X5 + 6, // ASTC_2D_6X5_SRGB 1, // Z32F 1, // Z16 1, // Z24S8 @@ -285,71 +315,81 @@ static constexpr u32 GetDefaultBlockWidth(PixelFormat format) { } constexpr std::array block_height_table = {{ - 1, // ABGR8U - 1, // ABGR8S - 1, // ABGR8UI - 1, // B5G6R5U - 1, // A2B10G10R10U - 1, // A1B5G5R5U - 1, // R8U - 1, // R8UI - 1, // RGBA16F - 1, // RGBA16U - 1, // RGBA16UI - 1, // R11FG11FB10F - 1, // RGBA32UI - 4, // DXT1 - 4, // DXT23 - 4, // DXT45 - 4, // DXN1 - 4, // DXN2UNORM - 4, // DXN2SNORM - 4, // BC7U - 4, // BC6H_UF16 - 4, // BC6H_SF16 - 4, // ASTC_2D_4X4 - 1, // BGRA8 - 1, // RGBA32F - 1, // RG32F - 1, // R32F - 1, // R16F - 1, // R16U - 1, // R16S - 1, // R16UI - 1, // R16I - 1, // RG16 - 1, // RG16F - 1, // RG16UI - 1, // RG16I - 1, // RG16S - 1, // RGB32F - 1, // RGBA8_SRGB - 1, // RG8U - 1, // RG8S - 1, // RG32UI - 1, // RGBX16F - 1, // R32UI - 8, // ASTC_2D_8X8 - 5, // ASTC_2D_8X5 - 4, // ASTC_2D_5X4 - 1, // BGRA8_SRGB - 4, // DXT1_SRGB - 4, // DXT23_SRGB - 4, // DXT45_SRGB - 4, // BC7U_SRGB - 4, // ASTC_2D_4X4_SRGB - 8, // ASTC_2D_8X8_SRGB - 5, // ASTC_2D_8X5_SRGB - 4, // ASTC_2D_5X4_SRGB - 5, // ASTC_2D_5X5 - 5, // ASTC_2D_5X5_SRGB - 8, // ASTC_2D_10X8 - 8, // ASTC_2D_10X8_SRGB - 1, // Z32F - 1, // Z16 - 1, // Z24S8 - 1, // S8Z24 - 1, // Z32FS8 + 1, // ABGR8U + 1, // ABGR8S + 1, // ABGR8UI + 1, // B5G6R5U + 1, // A2B10G10R10U + 1, // A1B5G5R5U + 1, // R8U + 1, // R8UI + 1, // RGBA16F + 1, // RGBA16U + 1, // RGBA16UI + 1, // R11FG11FB10F + 1, // RGBA32UI + 4, // DXT1 + 4, // DXT23 + 4, // DXT45 + 4, // DXN1 + 4, // DXN2UNORM + 4, // DXN2SNORM + 4, // BC7U + 4, // BC6H_UF16 + 4, // BC6H_SF16 + 4, // ASTC_2D_4X4 + 1, // BGRA8 + 1, // RGBA32F + 1, // RG32F + 1, // R32F + 1, // R16F + 1, // R16U + 1, // R16S + 1, // R16UI + 1, // R16I + 1, // RG16 + 1, // RG16F + 1, // RG16UI + 1, // RG16I + 1, // RG16S + 1, // RGB32F + 1, // RGBA8_SRGB + 1, // RG8U + 1, // RG8S + 1, // RG32UI + 1, // RGBX16F + 1, // R32UI + 8, // ASTC_2D_8X8 + 5, // ASTC_2D_8X5 + 4, // ASTC_2D_5X4 + 1, // BGRA8_SRGB + 4, // DXT1_SRGB + 4, // DXT23_SRGB + 4, // DXT45_SRGB + 4, // BC7U_SRGB + 4, // ASTC_2D_4X4_SRGB + 8, // ASTC_2D_8X8_SRGB + 5, // ASTC_2D_8X5_SRGB + 4, // ASTC_2D_5X4_SRGB + 5, // ASTC_2D_5X5 + 5, // ASTC_2D_5X5_SRGB + 8, // ASTC_2D_10X8 + 8, // ASTC_2D_10X8_SRGB + 6, // ASTC_2D_6X6 + 6, // ASTC_2D_6X6_SRGB + 10, // ASTC_2D_10X10 + 10, // ASTC_2D_10X10_SRGB + 12, // ASTC_2D_12X12 + 12, // ASTC_2D_12X12_SRGB + 6, // ASTC_2D_8X6 + 6, // ASTC_2D_8X6_SRGB + 5, // ASTC_2D_6X5 + 5, // ASTC_2D_6X5_SRGB + 1, // Z32F + 1, // Z16 + 1, // Z24S8 + 1, // S8Z24 + 1, // Z32FS8 }}; static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { @@ -421,6 +461,16 @@ constexpr std::array bpp_table = {{ 128, // ASTC_2D_5X5_SRGB 128, // ASTC_2D_10X8 128, // ASTC_2D_10X8_SRGB + 128, // ASTC_2D_6X6 + 128, // ASTC_2D_6X6_SRGB + 128, // ASTC_2D_10X10 + 128, // ASTC_2D_10X10_SRGB + 128, // ASTC_2D_12X12 + 128, // ASTC_2D_12X12_SRGB + 128, // ASTC_2D_8X6 + 128, // ASTC_2D_8X6_SRGB + 128, // ASTC_2D_6X5 + 128, // ASTC_2D_6X5_SRGB 32, // Z32F 16, // Z16 32, // Z24S8 @@ -512,6 +562,16 @@ constexpr std::array compression_type_table SurfaceCompression::Converted, // ASTC_2D_5X5_SRGB SurfaceCompression::Converted, // ASTC_2D_10X8 SurfaceCompression::Converted, // ASTC_2D_10X8_SRGB + SurfaceCompression::Converted, // ASTC_2D_6X6 + SurfaceCompression::Converted, // ASTC_2D_6X6_SRGB + SurfaceCompression::Converted, // ASTC_2D_10X10 + SurfaceCompression::Converted, // ASTC_2D_10X10_SRGB + SurfaceCompression::Converted, // ASTC_2D_12X12 + SurfaceCompression::Converted, // ASTC_2D_12X12_SRGB + SurfaceCompression::Converted, // ASTC_2D_8X6 + SurfaceCompression::Converted, // ASTC_2D_8X6_SRGB + SurfaceCompression::Converted, // ASTC_2D_6X5 + SurfaceCompression::Converted, // ASTC_2D_6X5_SRGB SurfaceCompression::None, // Z32F SurfaceCompression::None, // Z16 SurfaceCompression::None, // Z24S8 From f32a49d3d8b820a20c5311a0c27df5846d55b0e9 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 8 Oct 2019 12:54:59 -0400 Subject: [PATCH 2/2] Surfaces: Implement R4G4B4A4U format. --- src/video_core/morton.cpp | 2 + .../renderer_opengl/gl_texture_cache.cpp | 3 +- src/video_core/surface.cpp | 8 +++ src/video_core/surface.h | 52 +++++++++++-------- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index f8f8414906..fe5f08aced 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -93,6 +93,7 @@ static constexpr ConversionArray morton_to_linear_fns = { MortonCopy, MortonCopy, MortonCopy, + MortonCopy, MortonCopy, MortonCopy, MortonCopy, @@ -172,6 +173,7 @@ static constexpr ConversionArray linear_to_morton_fns = { MortonCopy, MortonCopy, MortonCopy, + MortonCopy, nullptr, nullptr, nullptr, diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index a0ca502b49..2f9bfd7e41 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -111,7 +111,8 @@ constexpr std::array tex_format {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm, true}, // DXT45_SRGB {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, ComponentType::UNorm, - true}, // BC7U_SRGB + true}, // BC7U_SRGB + {GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, ComponentType::UNorm, false}, // R4G4B4A4U {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_4X4_SRGB {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X8_SRGB {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X5_SRGB diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index a61dcbfb08..4416fb4ace 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -212,6 +212,14 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format, break; } break; + case Tegra::Texture::TextureFormat::A4B4G4R4: + switch (component_type) { + case Tegra::Texture::ComponentType::UNORM: + return PixelFormat::R4G4B4A4U; + default: + break; + } + break; case Tegra::Texture::TextureFormat::R8: switch (component_type) { case Tegra::Texture::ComponentType::UNORM: diff --git a/src/video_core/surface.h b/src/video_core/surface.h index dc7306a749..97668f8029 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -67,37 +67,38 @@ enum class PixelFormat { DXT23_SRGB = 49, DXT45_SRGB = 50, BC7U_SRGB = 51, - ASTC_2D_4X4_SRGB = 52, - ASTC_2D_8X8_SRGB = 53, - ASTC_2D_8X5_SRGB = 54, - ASTC_2D_5X4_SRGB = 55, - ASTC_2D_5X5 = 56, - ASTC_2D_5X5_SRGB = 57, - ASTC_2D_10X8 = 58, - ASTC_2D_10X8_SRGB = 59, - ASTC_2D_6X6 = 60, - ASTC_2D_6X6_SRGB = 61, - ASTC_2D_10X10 = 62, - ASTC_2D_10X10_SRGB = 63, - ASTC_2D_12X12 = 64, - ASTC_2D_12X12_SRGB = 65, - ASTC_2D_8X6 = 66, - ASTC_2D_8X6_SRGB = 67, - ASTC_2D_6X5 = 68, - ASTC_2D_6X5_SRGB = 69, + R4G4B4A4U = 52, + ASTC_2D_4X4_SRGB = 53, + ASTC_2D_8X8_SRGB = 54, + ASTC_2D_8X5_SRGB = 55, + ASTC_2D_5X4_SRGB = 56, + ASTC_2D_5X5 = 57, + ASTC_2D_5X5_SRGB = 58, + ASTC_2D_10X8 = 59, + ASTC_2D_10X8_SRGB = 60, + ASTC_2D_6X6 = 61, + ASTC_2D_6X6_SRGB = 62, + ASTC_2D_10X10 = 63, + ASTC_2D_10X10_SRGB = 64, + ASTC_2D_12X12 = 65, + ASTC_2D_12X12_SRGB = 66, + ASTC_2D_8X6 = 67, + ASTC_2D_8X6_SRGB = 68, + ASTC_2D_6X5 = 69, + ASTC_2D_6X5_SRGB = 70, MaxColorFormat, // Depth formats - Z32F = 70, - Z16 = 71, + Z32F = 71, + Z16 = 72, MaxDepthFormat, // DepthStencil formats - Z24S8 = 72, - S8Z24 = 73, - Z32FS8 = 74, + Z24S8 = 73, + S8Z24 = 74, + Z32FS8 = 75, MaxDepthStencilFormat, @@ -187,6 +188,7 @@ constexpr std::array compression_factor_shift_table = {{ 2, // DXT23_SRGB 2, // DXT45_SRGB 2, // BC7U_SRGB + 0, // R4G4B4A4U 2, // ASTC_2D_4X4_SRGB 2, // ASTC_2D_8X8_SRGB 2, // ASTC_2D_8X5_SRGB @@ -281,6 +283,7 @@ constexpr std::array block_width_table = {{ 4, // DXT23_SRGB 4, // DXT45_SRGB 4, // BC7U_SRGB + 1, // R4G4B4A4U 4, // ASTC_2D_4X4_SRGB 8, // ASTC_2D_8X8_SRGB 8, // ASTC_2D_8X5_SRGB @@ -367,6 +370,7 @@ constexpr std::array block_height_table = {{ 4, // DXT23_SRGB 4, // DXT45_SRGB 4, // BC7U_SRGB + 1, // R4G4B4A4U 4, // ASTC_2D_4X4_SRGB 8, // ASTC_2D_8X8_SRGB 5, // ASTC_2D_8X5_SRGB @@ -453,6 +457,7 @@ constexpr std::array bpp_table = {{ 128, // DXT23_SRGB 128, // DXT45_SRGB 128, // BC7U + 16, // R4G4B4A4U 128, // ASTC_2D_4X4_SRGB 128, // ASTC_2D_8X8_SRGB 128, // ASTC_2D_8X5_SRGB @@ -554,6 +559,7 @@ constexpr std::array compression_type_table SurfaceCompression::Compressed, // DXT23_SRGB SurfaceCompression::Compressed, // DXT45_SRGB SurfaceCompression::Compressed, // BC7U_SRGB + SurfaceCompression::None, // R4G4B4A4U SurfaceCompression::Converted, // ASTC_2D_4X4_SRGB SurfaceCompression::Converted, // ASTC_2D_8X8_SRGB SurfaceCompression::Converted, // ASTC_2D_8X5_SRGB