VERY experimental Nintendo Switch 2 emulator
C++
video_core: Fix DXT4 and RGB565
ReinUsesLisp44fb3cf92038
diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cppindex 7f239566a7..0c3c9f12d1 100644--- a/src/video_core/morton.cpp+++ b/src/video_core/morton.cpp@@ -46,6 +46,7 @@ static constexpr ConversionArray morton_to_linear_fns = {MortonCopy<true, PixelFormat::ABGR8I>,MortonCopy<true, PixelFormat::ABGR8UI>,MortonCopy<true, PixelFormat::B5G6R5U>,+ MortonCopy<true, PixelFormat::R5G6B5U>,MortonCopy<true, PixelFormat::B5G5R5A1U>,MortonCopy<true, PixelFormat::A2B10G10R10U>,MortonCopy<true, PixelFormat::A2B10G10R10UI>,@@ -64,7 +65,8 @@ static constexpr ConversionArray morton_to_linear_fns = {MortonCopy<true, PixelFormat::DXT1>,MortonCopy<true, PixelFormat::DXT23>,MortonCopy<true, PixelFormat::DXT45>,- MortonCopy<true, PixelFormat::DXN1>,+ MortonCopy<true, PixelFormat::DXN1UNORM>,+ MortonCopy<true, PixelFormat::DXN1SNORM>,MortonCopy<true, PixelFormat::DXN2UNORM>,MortonCopy<true, PixelFormat::DXN2SNORM>,MortonCopy<true, PixelFormat::BC7U>,@@ -138,6 +140,7 @@ static constexpr ConversionArray linear_to_morton_fns = {MortonCopy<false, PixelFormat::ABGR8I>,MortonCopy<false, PixelFormat::ABGR8UI>,MortonCopy<false, PixelFormat::B5G6R5U>,+ MortonCopy<false, PixelFormat::R5G6B5U>,MortonCopy<false, PixelFormat::B5G5R5A1U>,MortonCopy<false, PixelFormat::A2B10G10R10U>,MortonCopy<false, PixelFormat::A2B10G10R10UI>,@@ -156,7 +159,8 @@ static constexpr ConversionArray linear_to_morton_fns = {MortonCopy<false, PixelFormat::DXT1>,MortonCopy<false, PixelFormat::DXT23>,MortonCopy<false, PixelFormat::DXT45>,- MortonCopy<false, PixelFormat::DXN1>,+ MortonCopy<false, PixelFormat::DXN1UNORM>,+ MortonCopy<false, PixelFormat::DXN1SNORM>,MortonCopy<false, PixelFormat::DXN2UNORM>,MortonCopy<false, PixelFormat::DXN2SNORM>,MortonCopy<false, PixelFormat::BC7U>,diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cppindex 7f85ceca9e..12f54c050a 100644--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp@@ -46,6 +46,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format{GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, // ABGR8I{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, // ABGR8UI{GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // B5G6R5U+ {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV}, // R5G6B5U{GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // B5G5R5A1U{GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10U{GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10UI@@ -64,7 +65,8 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format{GL_COMPRESSED_RGBA_S3TC_DXT1_EXT}, // DXT1{GL_COMPRESSED_RGBA_S3TC_DXT3_EXT}, // DXT23{GL_COMPRESSED_RGBA_S3TC_DXT5_EXT}, // DXT45- {GL_COMPRESSED_RED_RGTC1}, // DXN1+ {GL_COMPRESSED_RED_RGTC1}, // DXN1UNORM+ {GL_COMPRESSED_SIGNED_RED_RGTC1}, // DXN1SNORM{GL_COMPRESSED_RG_RGTC2}, // DXN2UNORM{GL_COMPRESSED_SIGNED_RG_RGTC2}, // DXN2SNORM{GL_COMPRESSED_RGBA_BPTC_UNORM}, // BC7Udiff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cppindex 3cb3b00d9b..57c3822c2d 100644--- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp+++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp@@ -122,6 +122,7 @@ struct FormatTuple {{VK_FORMAT_A8B8G8R8_SINT_PACK32, Attachable | Storage}, // ABGR8I{VK_FORMAT_A8B8G8R8_UINT_PACK32, Attachable | Storage}, // ABGR8UI{VK_FORMAT_R5G6B5_UNORM_PACK16, Attachable}, // B5G6R5U+ {VK_FORMAT_B5G6R5_UNORM_PACK16, Attachable}, // R5G6B5U{VK_FORMAT_A1R5G5B5_UNORM_PACK16, Attachable}, // B5G5R5A1U{VK_FORMAT_A2B10G10R10_UNORM_PACK32, Attachable | Storage}, // A2B10G10R10U{VK_FORMAT_A2B10G10R10_UINT_PACK32, Attachable | Storage}, // A2B10G10R10UI@@ -140,7 +141,8 @@ struct FormatTuple {{VK_FORMAT_BC1_RGBA_UNORM_BLOCK}, // DXT1{VK_FORMAT_BC2_UNORM_BLOCK}, // DXT23{VK_FORMAT_BC3_UNORM_BLOCK}, // DXT45- {VK_FORMAT_BC4_UNORM_BLOCK}, // DXN1+ {VK_FORMAT_BC4_UNORM_BLOCK}, // DXN1UNORM+ {VK_FORMAT_BC4_SNORM_BLOCK}, // DXN1SNORM{VK_FORMAT_BC5_UNORM_BLOCK}, // DXN2UNORM{VK_FORMAT_BC5_SNORM_BLOCK}, // DXN2SNORM{VK_FORMAT_BC7_UNORM_BLOCK}, // BC7Udiff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cppindex 2f5621889a..71f0ff4274 100644--- a/src/video_core/renderer_vulkan/vk_device.cpp+++ b/src/video_core/renderer_vulkan/vk_device.cpp@@ -125,6 +125,7 @@ std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(VK_FORMAT_BC2_UNORM_BLOCK,VK_FORMAT_BC3_UNORM_BLOCK,VK_FORMAT_BC4_UNORM_BLOCK,+ VK_FORMAT_BC4_SNORM_BLOCK,VK_FORMAT_BC5_UNORM_BLOCK,VK_FORMAT_BC5_SNORM_BLOCK,VK_FORMAT_BC7_UNORM_BLOCK,diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cppindex c1c2f2c524..492ab6215e 100644--- a/src/video_core/surface.cpp+++ b/src/video_core/surface.cpp@@ -283,25 +283,4 @@ std::pair<u32, u32> GetASTCBlockSize(PixelFormat format) {return {GetDefaultBlockWidth(format), GetDefaultBlockHeight(format)};}-bool IsFormatBCn(PixelFormat format) {- switch (format) {- case PixelFormat::DXT1:- case PixelFormat::DXT23:- case PixelFormat::DXT45:- case PixelFormat::DXN1:- case PixelFormat::DXN2SNORM:- case PixelFormat::DXN2UNORM:- case PixelFormat::BC7U:- case PixelFormat::BC6H_UF16:- case PixelFormat::BC6H_SF16:- case PixelFormat::DXT1_SRGB:- case PixelFormat::DXT23_SRGB:- case PixelFormat::DXT45_SRGB:- case PixelFormat::BC7U_SRGB:- return true;- default:- return false;- }-}-} // namespace VideoCore::Surfacediff --git a/src/video_core/surface.h b/src/video_core/surface.hindex 9510db2c87..826c5a3ad5 100644--- a/src/video_core/surface.h+++ b/src/video_core/surface.h@@ -20,6 +20,7 @@ enum class PixelFormat {ABGR8I,ABGR8UI,B5G6R5U,+ R5G6B5U,B5G5R5A1U,A2B10G10R10U,A2B10G10R10UI,@@ -38,7 +39,8 @@ enum class PixelFormat {DXT1,DXT23,DXT45,- DXN1, // This is also known as BC4+ DXN1UNORM, // This is also known as BC4+ DXN1SNORM,DXN2UNORM,DXN2SNORM,BC7U,@@ -144,6 +146,7 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{0, // ABGR8I0, // ABGR8UI0, // B5G6R5U+ 0, // R5G6B5U0, // B5G5R5A1U0, // A2B10G10R10U0, // A2B10G10R10UI@@ -162,7 +165,8 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{2, // DXT12, // DXT232, // DXT45- 2, // DXN1+ 2, // DXN1UNORM+ 2, // DXN1SNORM2, // DXN2UNORM2, // DXN2SNORM2, // BC7U@@ -252,6 +256,7 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{1, // ABGR8I1, // ABGR8UI1, // B5G6R5U+ 1, // R5G6B5U1, // B5G5R5A1U1, // A2B10G10R10U1, // A2B10G10R10UI@@ -270,7 +275,8 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{4, // DXT14, // DXT234, // DXT45- 4, // DXN1+ 4, // DXN1UNORM+ 4, // DXN1SNORM4, // DXN2UNORM4, // DXN2SNORM4, // BC7U@@ -352,6 +358,7 @@ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{1, // ABGR8I1, // ABGR8UI1, // B5G6R5U+ 1, // R5G6B5U1, // B5G5R5A1U1, // A2B10G10R10U1, // A2B10G10R10UI@@ -370,7 +377,8 @@ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{4, // DXT14, // DXT234, // DXT45- 4, // DXN1+ 4, // DXN1UNORM+ 4, // DXN1SNORM4, // DXN2UNORM4, // DXN2SNORM4, // BC7U@@ -452,6 +460,7 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{32, // ABGR8I32, // ABGR8UI16, // B5G6R5U+ 16, // R5G6B5U16, // B5G5R5A1U32, // A2B10G10R10U32, // A2B10G10R10UI@@ -470,7 +479,8 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{64, // DXT1128, // DXT23128, // DXT45- 64, // DXN1+ 64, // DXN1UNORM+ 64, // DXN1SNORM128, // DXN2UNORM128, // DXN2SNORM128, // BC7U@@ -574,7 +584,4 @@ bool IsPixelFormatSRGB(PixelFormat format);std::pair<u32, u32> GetASTCBlockSize(PixelFormat format);-/// Returns true if the specified PixelFormat is a BCn format, e.g. DXT or DXN-bool IsFormatBCn(PixelFormat format);-} // namespace VideoCore::Surfacediff --git a/src/video_core/texture_cache/format_lookup_table.cpp b/src/video_core/texture_cache/format_lookup_table.cppindex b7f44ead22..148a3935d3 100644--- a/src/video_core/texture_cache/format_lookup_table.cpp+++ b/src/video_core/texture_cache/format_lookup_table.cpp@@ -48,7 +48,7 @@ constexpr std::array<Table, 86> DefinitionTable = {{{TextureFormat::A8R8G8B8, C, SINT, SINT, SINT, SINT, PixelFormat::ABGR8I},{TextureFormat::A8R8G8B8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA8_SRGB},- {TextureFormat::B5G6R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::B5G6R5U},+ {TextureFormat::B5G6R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R5G6B5U},{TextureFormat::A2B10G10R10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A2B10G10R10U},{TextureFormat::A2B10G10R10, C, UINT, UINT, UINT, UINT, PixelFormat::A2B10G10R10UI},@@ -118,9 +118,8 @@ constexpr std::array<Table, 86> DefinitionTable = {{{TextureFormat::DXT45, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45},{TextureFormat::DXT45, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45_SRGB},- // TODO: Use a different pixel format for SNORM- {TextureFormat::DXN1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN1},- {TextureFormat::DXN1, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN1},+ {TextureFormat::DXN1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN1UNORM},+ {TextureFormat::DXN1, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN1SNORM},{TextureFormat::DXN2, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN2UNORM},{TextureFormat::DXN2, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN2SNORM},