From 7831a42ccc5ed4a6bdd4b876d44e052fc9faf10d Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 18 Sep 2019 12:41:44 +0100 Subject: [PATCH] Fix vulkan handling of ETC2_EAC_RGBA8 to properly encode ResourceFormat * We consider ETC2 to be the base RGB profile, optionally with punch-through alpha, so compCount and type gives those formats. EAC covers R11, RG11, and then the RGB8 + A8 mode, which is again disambiguated with compCount and type. --- renderdoc/api/replay/replay_enums.h | 11 +++++++++- renderdoc/driver/vulkan/vk_resources.cpp | 27 ++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index 2f6c06c29..67b9b7ca8 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -1216,12 +1216,21 @@ or formats that don't have equal byte-multiple sizes for each channel. Commonly used on mobile or embedded platforms. + Note that the mode added in ``EAC`` with 1 byte per pixel and full 8-bit alpha is + grouped as ``EAC``, with a component count of 4. See :data:`EAC`. + .. data:: EAC - A block-compressed texture in ``EAC`` format (Single channel 11-bit or RGBA, 0.5 bytes per pixel) + A block-compressed texture in ``EAC`` format, expanded from ``ETC2``. Commonly used on mobile or embedded platforms. + The single and dual channel formats encode 11-bit data with 0.5 bytes per channel (so + the single channel format is 0.5 bytes per pixel total, and the dual channel format is 1 byte per + pixel total). The four channel format is encoded similarly to ETC2 for the base RGB data and + similarly to the single channel format for the alpha, giving 1 byte per pixel total. + See :data:`ETC2`. + .. data:: ASTC A block-compressed texture in ``ASTC`` format (Representation varies a lot) diff --git a/renderdoc/driver/vulkan/vk_resources.cpp b/renderdoc/driver/vulkan/vk_resources.cpp index 37b9fdb03..f7412ed13 100644 --- a/renderdoc/driver/vulkan/vk_resources.cpp +++ b/renderdoc/driver/vulkan/vk_resources.cpp @@ -1102,6 +1102,10 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_EAC_R11_SNORM_BLOCK: return (typeHint == CompType::SNorm) ? VK_FORMAT_EAC_R11_SNORM_BLOCK : VK_FORMAT_EAC_R11_UNORM_BLOCK; + case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: + case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: + return (typeHint == CompType::SNorm) ? VK_FORMAT_EAC_R11G11_SNORM_BLOCK + : VK_FORMAT_EAC_R11G11_UNORM_BLOCK; case VK_FORMAT_BC2_UNORM_BLOCK: case VK_FORMAT_BC2_SRGB_BLOCK: return (typeHint == CompType::UNormSRGB) ? VK_FORMAT_BC2_SRGB_BLOCK : VK_FORMAT_BC2_UNORM_BLOCK; @@ -1118,10 +1122,6 @@ VkFormat GetViewCastedFormat(VkFormat f, CompType typeHint) case VK_FORMAT_BC7_UNORM_BLOCK: case VK_FORMAT_BC7_SRGB_BLOCK: return (typeHint == CompType::UNormSRGB) ? VK_FORMAT_BC7_SRGB_BLOCK : VK_FORMAT_BC7_UNORM_BLOCK; - case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: - case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: - return (typeHint == CompType::SNorm) ? VK_FORMAT_EAC_R11G11_SNORM_BLOCK - : VK_FORMAT_EAC_R11G11_UNORM_BLOCK; case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: return (typeHint == CompType::UNormSRGB) ? VK_FORMAT_ASTC_4x4_SRGB_BLOCK @@ -1711,9 +1711,9 @@ ResourceFormat MakeResourceFormat(VkFormat fmt) case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: ret.type = ResourceFormatType::ETC2; break; case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: ret.type = ResourceFormatType::ETC2; break; + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: case VK_FORMAT_EAC_R11_UNORM_BLOCK: case VK_FORMAT_EAC_R11_SNORM_BLOCK: case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: @@ -2444,8 +2444,8 @@ VkFormat MakeVkFormat(ResourceFormat fmt) ret = fmt.SRGBCorrected() ? VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK : VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; else - ret = fmt.SRGBCorrected() ? VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK - : VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; + ret = fmt.SRGBCorrected() ? VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK + : VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; break; } case ResourceFormatType::EAC: @@ -2456,6 +2456,9 @@ VkFormat MakeVkFormat(ResourceFormat fmt) else if(fmt.compCount == 2) ret = fmt.compType == CompType::SNorm ? VK_FORMAT_EAC_R11G11_SNORM_BLOCK : VK_FORMAT_EAC_R11G11_UNORM_BLOCK; + else + ret = fmt.SRGBCorrected() ? VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK + : VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; break; } case ResourceFormatType::R10G10B10A2: @@ -3899,14 +3902,6 @@ TEST_CASE("Vulkan formats", "[format][vulkan]") { CHECK(reconstructed == VK_FORMAT_D24_UNORM_S8_UINT); } - else if(f == VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK) - { - CHECK(reconstructed == VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK); - } - else if(f == VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK) - { - CHECK(reconstructed == VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK); - } else { CHECK(reconstructed == original);