From ef62aa92f3ec5bf4b79c2ff22b6c994ce816092a Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Mon, 23 Dec 2024 15:40:17 +0000 Subject: [PATCH 1/9] First commit to fix issues#960 --- lib/astc_codec.cpp | 285 ++++++++++++++++++++++++++++++++++++-- tools/ktx/metrics_utils.h | 8 +- 2 files changed, 276 insertions(+), 17 deletions(-) diff --git a/lib/astc_codec.cpp b/lib/astc_codec.cpp index 3a62d412f3..f09ad63940 100644 --- a/lib/astc_codec.cpp +++ b/lib/astc_codec.cpp @@ -289,24 +289,208 @@ astcVkFormat(ktx_uint32_t block_size, bool sRGB) { return VK_FORMAT_ASTC_6x6_SRGB_BLOCK; // Default is 6x6 sRGB image } +inline bool isFormatSRGB(VkFormat format) noexcept { + switch (format) { + case VK_FORMAT_R8_SRGB: [[fallthrough]]; + case VK_FORMAT_R8G8_SRGB: [[fallthrough]]; + case VK_FORMAT_R8G8B8_SRGB: [[fallthrough]]; + case VK_FORMAT_B8G8R8_SRGB: [[fallthrough]]; + case VK_FORMAT_R8G8B8A8_SRGB: [[fallthrough]]; + case VK_FORMAT_B8G8R8A8_SRGB: [[fallthrough]]; + case VK_FORMAT_A8B8G8R8_SRGB_PACK32: [[fallthrough]]; + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_BC2_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_BC3_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_BC7_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: [[fallthrough]]; + case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: [[fallthrough]]; + case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: [[fallthrough]]; + case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: [[fallthrough]]; + case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: + return true; + default: + return false; + } +} + +inline bool isFormatAstc(VkFormat format) noexcept { + switch (format) { + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT: + return true; + default: + return false; + } +} + +inline bool isFormatAstcLDR(VkFormat format) noexcept { + switch (format) { + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: [[fallthrough]]; + case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: + return true; + default: + return false; + } +} + /** * @memberof ktxTexture * @ingroup writer * @~English - * @brief Creates valid ASTC encoder action from string. + * @brief Creates valid ASTC decoder profile from VkFormat * - * @return Valid astc_profile from string + * @return Valid astc_profile from VkFormat */ static astcenc_profile -astcEncoderAction(const ktxAstcParams ¶ms, const uint32_t* bdb) { +astcProfile(bool sRGB, bool ldr) { - ktx_uint32_t transfer = KHR_DFDVAL(bdb, TRANSFER); - - if (transfer == KHR_DF_TRANSFER_SRGB && - params.mode == KTX_PACK_ASTC_ENCODER_MODE_LDR) + if (sRGB && ldr) return ASTCENC_PRF_LDR_SRGB; - else if (transfer == KHR_DF_TRANSFER_LINEAR) { - if (params.mode == KTX_PACK_ASTC_ENCODER_MODE_LDR) + else if (!sRGB) { + if (ldr) return ASTCENC_PRF_LDR; else return ASTCENC_PRF_HDR; @@ -317,6 +501,45 @@ astcEncoderAction(const ktxAstcParams ¶ms, const uint32_t* bdb) { return ASTCENC_PRF_LDR_SRGB; } +/** + * @memberof ktxTexture + * @ingroup writer + * @~English + * @brief Creates valid ASTC encoder profile provided params and bdb + * + * @return Valid astc_profile from params and bdb + */ +static astcenc_profile +astcEncoderProfile(const ktxAstcParams ¶ms, const uint32_t* bdb) { + + ktx_uint32_t transfer = KHR_DFDVAL(bdb, TRANSFER); + + bool sRGB = transfer == KHR_DF_TRANSFER_SRGB; + bool ldr = params.mode == KTX_PACK_ASTC_ENCODER_MODE_LDR; + + if (!sRGB) { + assert(transfer == KHR_DF_TRANSFER_LINEAR && "Unsupported transfer function, only support sRGB and Linear"); + } + + return astcProfile(sRGB, ldr); +} + +/** + * @memberof ktxTexture + * @ingroup writer + * @~English + * @brief Creates valid ASTC decoder profile from VkFormat + * + * @return Valid astc_profile from VkFormat + */ +static astcenc_profile +astcDecoderProfile(VkFormat vkformat) { + + bool sRGB = isFormatSRGB(vkformat); + bool ldr = isFormatAstcLDR(vkformat); + + return astcProfile(sRGB, ldr); +} /** * @memberof ktxTexture @@ -756,7 +979,7 @@ ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params) { astcBlockDimensions(params->blockDimension, block_size_x, block_size_y, block_size_z); quality = astcQuality(params->qualityLevel); - profile = astcEncoderAction(*params, BDB); + profile = astcEncoderProfile(*params, BDB); swizzle = astcSwizzle(*params); if(params->perceptual) @@ -992,6 +1215,18 @@ static void decompression_workload_runner(int thread_count, int thread_id, void* * @exception KTX_FILE_DATA_ERROR * DFD is incorrect: supercompression scheme or * sample's channelId do not match ASTC colorModel. + * @exception KTX_FILE_DATA_ERROR + * The provided texture is not ASTC LDR encoded. + * @exception KTX_FILE_DATA_ERROR + * The provided texture is not ASTC encoded. + * @exception KTX_INVALID_OPERATION + * The decoding format is not supported. + * @exception KTX_INVALID_OPERATION + * HDR to LDR decode is not supported. + * @exception KTX_INVALID_OPERATION + * sRGB to linear decode is not supported. + * @exception KTX_INVALID_OPERATION + * Linear to sRGB decode is not supported. * @exception KTX_INVALID_OPERATION * The texture's images are not in ASTC format. * @exception KTX_INVALID_OPERATION @@ -1027,6 +1262,31 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { } // Other schemes are decoded in ktxTexture2_LoadImageData. + if (!isFormatAstcLDR((VkFormat)This->vkFormat)) { + if (isFormatAstcLDR((VkFormat)vkformat)) { + return KTX_INVALID_OPERATION; // Decompressing to LDR from HDR is not supported. + } + return KTX_FILE_DATA_ERROR; // Should be removed when supporting HDR images. + } + + if (!isFormatAstc((VkFormat)This->vkFormat)) { + return KTX_FILE_DATA_ERROR; // Not a valid input file. + } + + if (isFormatAstc((VkFormat)vkformat)) { + return KTX_INVALID_OPERATION; // Not a supported decoding format. + } + + if (isFormatSRGB((VkFormat)vkformat)) { + if (!isFormatSRGB((VkFormat)This->vkFormat)) { + return KTX_INVALID_OPERATION; // Not a supported decoding format for sRGB input. + } + } else { + if (isFormatSRGB((VkFormat)This->vkFormat)) { + return KTX_INVALID_OPERATION; // Not a supported decoding format for linear input. + } + } + DECLARE_PRIVATE(priv, This); uint32_t channelId = KHR_DFDSVAL(BDB, 0, CHANNELID); @@ -1080,7 +1340,7 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { astcenc_profile profile{ASTCENC_PRF_LDR_SRGB}; astcenc_swizzle swizzle{ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A}; - uint32_t block_size_x{4}; // Get the right blocks from vkformat + uint32_t block_size_x{4}; uint32_t block_size_y{4}; uint32_t block_size_z{1}; float quality{ASTCENC_PRE_MEDIUM}; @@ -1089,11 +1349,12 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { astcBlockDimensions((VkFormat)This->vkFormat, block_size_x, block_size_y, block_size_z); // quality = astcQuality(params->qualityLevel); - // profile = astcEncoderAction(*params, BDB); // swizzle = astcSwizzle(*params); // if(params->perceptual) flags |= ASTCENC_FLG_USE_PERCEPTUAL; + profile = astcDecoderProfile((VkFormat)vkformat); + uint32_t threadCount{1}; // Decompression isn't the bottleneck and only used when checking for psnr and ssim astcenc_config astc_config; astcenc_context *astc_context; diff --git a/tools/ktx/metrics_utils.h b/tools/ktx/metrics_utils.h index 7e8512fcd6..dde761e72c 100644 --- a/tools/ktx/metrics_utils.h +++ b/tools/ktx/metrics_utils.h @@ -110,12 +110,10 @@ class MetricsCalculator { // Decode the encoded texture to observe the compression losses const auto* bdfd = texture->pDfd + 1; - if (khr_df_model_e(KHR_DFDVAL(bdfd, MODEL)) == KHR_DF_MODEL_ASTC) - { - ec = ktxTexture2_DecodeAstc(texture, VK_FORMAT_R8G8B8A8_UNORM); + if (khr_df_model_e(KHR_DFDVAL(bdfd, MODEL)) == KHR_DF_MODEL_ASTC) { + ec = ktxTexture2_DecodeAstc(texture, VK_FORMAT_R8G8B8A8_UNORM); // TODO: Fix format for HDR support } - else - { + else { tSwizzleInfo = determineTranscodeSwizzle(texture, report); ec = ktxTexture2_TranscodeBasis(texture, KTX_TTF_RGBA32, 0); } From 35b71f4a64302bffa20b607086ad98061af31756 Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Mon, 23 Dec 2024 17:31:06 +0000 Subject: [PATCH 2/9] Add support to Metrics to selects the right encode format --- tools/ktx/metrics_utils.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/ktx/metrics_utils.h b/tools/ktx/metrics_utils.h index dde761e72c..b4b0060f28 100644 --- a/tools/ktx/metrics_utils.h +++ b/tools/ktx/metrics_utils.h @@ -107,11 +107,16 @@ class MetricsCalculator { tSwizzleInfo.swizzle = "rgba"; ktx_error_code_e ec = KTX_SUCCESS; + auto vkformat = VK_FORMAT_R8G8B8A8_UNORM; // TODO: Fix format for HDR support // Decode the encoded texture to observe the compression losses const auto* bdfd = texture->pDfd + 1; + if (KHR_DFDVAL(bdfd, TRANSFER) == KHR_DF_TRANSFER_SRGB) { + vkformat = VK_FORMAT_R8G8B8A8_SRGB; + } + if (khr_df_model_e(KHR_DFDVAL(bdfd, MODEL)) == KHR_DF_MODEL_ASTC) { - ec = ktxTexture2_DecodeAstc(texture, VK_FORMAT_R8G8B8A8_UNORM); // TODO: Fix format for HDR support + ec = ktxTexture2_DecodeAstc(texture, vkformat); } else { tSwizzleInfo = determineTranscodeSwizzle(texture, report); From 7feac679423b87da2116bf5b380e68910635c542 Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Mon, 23 Dec 2024 18:45:37 +0000 Subject: [PATCH 3/9] Remove [[fallthrough]] --- lib/astc_codec.cpp | 320 ++++++++++++++++++++++----------------------- 1 file changed, 160 insertions(+), 160 deletions(-) diff --git a/lib/astc_codec.cpp b/lib/astc_codec.cpp index f09ad63940..37210a42bc 100644 --- a/lib/astc_codec.cpp +++ b/lib/astc_codec.cpp @@ -291,48 +291,48 @@ astcVkFormat(ktx_uint32_t block_size, bool sRGB) { inline bool isFormatSRGB(VkFormat format) noexcept { switch (format) { - case VK_FORMAT_R8_SRGB: [[fallthrough]]; - case VK_FORMAT_R8G8_SRGB: [[fallthrough]]; - case VK_FORMAT_R8G8B8_SRGB: [[fallthrough]]; - case VK_FORMAT_B8G8R8_SRGB: [[fallthrough]]; - case VK_FORMAT_R8G8B8A8_SRGB: [[fallthrough]]; - case VK_FORMAT_B8G8R8A8_SRGB: [[fallthrough]]; - case VK_FORMAT_A8B8G8R8_SRGB_PACK32: [[fallthrough]]; - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_BC2_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_BC3_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_BC7_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: [[fallthrough]]; - case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: [[fallthrough]]; - case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: [[fallthrough]]; - case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: [[fallthrough]]; - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_R8_SRGB: + case VK_FORMAT_R8G8_SRGB: + case VK_FORMAT_R8G8B8_SRGB: + case VK_FORMAT_B8G8R8_SRGB: + case VK_FORMAT_R8G8B8A8_SRGB: + case VK_FORMAT_B8G8R8A8_SRGB: + case VK_FORMAT_A8B8G8R8_SRGB_PACK32: + case VK_FORMAT_BC1_RGB_SRGB_BLOCK: + case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: + case VK_FORMAT_BC2_SRGB_BLOCK: + case VK_FORMAT_BC3_SRGB_BLOCK: + case VK_FORMAT_BC7_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: + case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: + case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: + case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: + case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: + case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: return true; default: @@ -342,77 +342,77 @@ inline bool isFormatSRGB(VkFormat format) noexcept { inline bool isFormatAstc(VkFormat format) noexcept { switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK: + case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT: return true; default: @@ -422,53 +422,53 @@ inline bool isFormatAstc(VkFormat format) noexcept { inline bool isFormatAstcLDR(VkFormat format) noexcept { switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: [[fallthrough]]; - case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: [[fallthrough]]; - case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: [[fallthrough]]; + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: return true; default: From c2af9025076bbc58e1108556ba5bd02de38f38a8 Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Tue, 24 Dec 2024 13:42:20 +0000 Subject: [PATCH 4/9] Update CTS submodule --- tests/cts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cts b/tests/cts index 33801c64b2..382c891068 160000 --- a/tests/cts +++ b/tests/cts @@ -1 +1 @@ -Subproject commit 33801c64b21f629b84a200939e85fa82fca042e2 +Subproject commit 382c8910689e375835da03aae36783f8f595d6d5 From a7c09eecf18dc76475083a2c6017b67c9a64fefb Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Fri, 27 Dec 2024 12:37:38 +0000 Subject: [PATCH 5/9] Remove format argument from ktxTexture2_DecodeAstc --- include/ktx.h | 2 +- lib/astc_codec.cpp | 205 +++++++++++++++----------------------- tools/ktx/metrics_utils.h | 7 +- 3 files changed, 80 insertions(+), 134 deletions(-) diff --git a/include/ktx.h b/include/ktx.h index 267d716cba..7e442a6950 100644 --- a/include/ktx.h +++ b/include/ktx.h @@ -1313,7 +1313,7 @@ KTX_API KTX_error_code KTX_APIENTRY ktxTexture2_CompressAstc(ktxTexture2* This, ktx_uint32_t quality); KTX_API KTX_error_code KTX_APIENTRY -ktxTexture2_DecodeAstc(ktxTexture2* This, ktx_uint32_t vkformat); +ktxTexture2_DecodeAstc(ktxTexture2* This); /** * @memberof ktxTexture2 diff --git a/lib/astc_codec.cpp b/lib/astc_codec.cpp index 37210a42bc..7e1300625d 100644 --- a/lib/astc_codec.cpp +++ b/lib/astc_codec.cpp @@ -201,6 +201,7 @@ unorm8x4ArrayToImage(const uint8_t *data, uint32_t dim_x, uint32_t dim_y) { /** * @memberof ktxTexture + * @internal * @ingroup writer * @~English * @brief Creates default ASTC parameters @@ -222,6 +223,7 @@ astcDefaultOptions() { /** * @memberof ktxTexture + * @internal * @ingroup writer * @~English * @brief Should be used to get VkFormat from ASTC block enum @@ -289,23 +291,45 @@ astcVkFormat(ktx_uint32_t block_size, bool sRGB) { return VK_FORMAT_ASTC_6x6_SRGB_BLOCK; // Default is 6x6 sRGB image } -inline bool isFormatSRGB(VkFormat format) noexcept { +/** + * @memberof ktxTexture + * @internal + * @ingroup reader + * @~English + * @brief Should be used to get uncompressed version of ASTC VkFormat + * + * The decompressed format is calculated from coressponding ASTC format. There are + * only 3 possible options currently supported. RGBA8, sRGBA8 and RGBA32. + * + * @return Uncompressed version of VKFormat for a specific ASTC VkFormat + */ +inline VkFormat getUncompressedFormat(VkFormat format) noexcept { switch (format) { - case VK_FORMAT_R8_SRGB: - case VK_FORMAT_R8G8_SRGB: - case VK_FORMAT_R8G8B8_SRGB: - case VK_FORMAT_B8G8R8_SRGB: - case VK_FORMAT_R8G8B8A8_SRGB: - case VK_FORMAT_B8G8R8A8_SRGB: - case VK_FORMAT_A8B8G8R8_SRGB_PACK32: - case VK_FORMAT_BC1_RGB_SRGB_BLOCK: - case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: - case VK_FORMAT_BC2_SRGB_BLOCK: - case VK_FORMAT_BC3_SRGB_BLOCK: - case VK_FORMAT_BC7_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: - case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: + case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: + case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: + case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: + case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: + case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: + case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: + return VK_FORMAT_R8G8B8A8_UNORM; case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: @@ -320,10 +344,6 @@ inline bool isFormatSRGB(VkFormat format) noexcept { case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: - case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: - case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: - case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: @@ -334,42 +354,7 @@ inline bool isFormatSRGB(VkFormat format) noexcept { case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: - return true; - default: - return false; - } -} - -inline bool isFormatAstc(VkFormat format) noexcept { - switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: + return VK_FORMAT_R8G8B8A8_SRGB; case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK: case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK: case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK: @@ -384,42 +369,31 @@ inline bool isFormatAstc(VkFormat format) noexcept { case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK: case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK: case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: case VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT: - return true; + return VK_FORMAT_R32G32B32A32_SFLOAT; default: - return false; + return VK_FORMAT_R8G8B8A8_SRGB; } } +/** + * @memberof ktxTexture + * @internal + * @ingroup reader + * @~English + * @brief Should be used to check if an ASTC VkFormat is LDR format or not. + * + * @return true if the VkFormat is an ASTC LDR format. + */ inline bool isFormatAstcLDR(VkFormat format) noexcept { switch (format) { case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: @@ -478,9 +452,10 @@ inline bool isFormatAstcLDR(VkFormat format) noexcept { /** * @memberof ktxTexture - * @ingroup writer + * @internal + * @ingroup reader writer * @~English - * @brief Creates valid ASTC decoder profile from VkFormat + * @brief Creates valid ASTC decoder profile from VkFormat * * @return Valid astc_profile from VkFormat */ @@ -498,14 +473,17 @@ astcProfile(bool sRGB, bool ldr) { // TODO: Add support for the following // KTX_PACK_ASTC_ENCODER_ACTION_COMP_HDR_RGB_LDR_ALPHA; currently not supported + assert(ldr && "HDR sRGB profile not supported"); + return ASTCENC_PRF_LDR_SRGB; } /** * @memberof ktxTexture + * @internal * @ingroup writer * @~English - * @brief Creates valid ASTC encoder profile provided params and bdb + * @brief Creates valid ASTC encoder profile provided params and bdb * * @return Valid astc_profile from params and bdb */ @@ -526,26 +504,31 @@ astcEncoderProfile(const ktxAstcParams ¶ms, const uint32_t* bdb) { /** * @memberof ktxTexture - * @ingroup writer + * @internal + * @ingroup reader * @~English - * @brief Creates valid ASTC decoder profile from VkFormat + * @brief Creates valid ASTC decoder profile from VkFormat * * @return Valid astc_profile from VkFormat */ static astcenc_profile -astcDecoderProfile(VkFormat vkformat) { +astcDecoderProfile(ktxTexture2 *This) { + + uint32_t* BDB = This->pDfd + 1; + ktx_uint32_t transfer = KHR_DFDVAL(BDB, TRANSFER); - bool sRGB = isFormatSRGB(vkformat); - bool ldr = isFormatAstcLDR(vkformat); + bool sRGB = transfer == KHR_DF_TRANSFER_SRGB; + bool ldr = isFormatAstcLDR((VkFormat)This->vkFormat); return astcProfile(sRGB, ldr); } /** * @memberof ktxTexture + * @internal * @ingroup writer * @~English - * @brief Creates valid ASTC encoder swizzle from string. + * @brief Creates valid ASTC encoder swizzle from string. * * @return Valid astcenc_swizzle from string */ @@ -1181,6 +1164,7 @@ struct decompression_workload /** * @internal + * @ingroup reader * @brief Runner callback function for a decompression worker thread. * * @param thread_count The number of threads in the worker pool. @@ -1204,29 +1188,19 @@ static void decompression_workload_runner(int thread_count, int thread_id, void* /** * @ingroup reader * @brief Decodes a ktx2 texture object, if it is ASTC encoded. + + * The decompressed format is calculated from coressponding ASTC format. There are + * only 3 possible options currently supported. RGBA8, sRGBA8 and RGBA32. * * Updates @p This with the decoded image. * * @param This The texture to decode - * @param vkformat The decoding format to use * * @return KTX_SUCCESS on success, other KTX_* enum values on error. * * @exception KTX_FILE_DATA_ERROR * DFD is incorrect: supercompression scheme or * sample's channelId do not match ASTC colorModel. - * @exception KTX_FILE_DATA_ERROR - * The provided texture is not ASTC LDR encoded. - * @exception KTX_FILE_DATA_ERROR - * The provided texture is not ASTC encoded. - * @exception KTX_INVALID_OPERATION - * The decoding format is not supported. - * @exception KTX_INVALID_OPERATION - * HDR to LDR decode is not supported. - * @exception KTX_INVALID_OPERATION - * sRGB to linear decode is not supported. - * @exception KTX_INVALID_OPERATION - * Linear to sRGB decode is not supported. * @exception KTX_INVALID_OPERATION * The texture's images are not in ASTC format. * @exception KTX_INVALID_OPERATION @@ -1246,7 +1220,7 @@ static void decompression_workload_runner(int thread_count, int thread_id, void* * not happen in release package. */ KTX_error_code -ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { +ktxTexture2_DecodeAstc(ktxTexture2 *This) { // Decompress This using astc-decoder uint32_t* BDB = This->pDfd + 1; khr_df_model_e colorModel = (khr_df_model_e)KHR_DFDVAL(BDB, MODEL); @@ -1262,31 +1236,6 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { } // Other schemes are decoded in ktxTexture2_LoadImageData. - if (!isFormatAstcLDR((VkFormat)This->vkFormat)) { - if (isFormatAstcLDR((VkFormat)vkformat)) { - return KTX_INVALID_OPERATION; // Decompressing to LDR from HDR is not supported. - } - return KTX_FILE_DATA_ERROR; // Should be removed when supporting HDR images. - } - - if (!isFormatAstc((VkFormat)This->vkFormat)) { - return KTX_FILE_DATA_ERROR; // Not a valid input file. - } - - if (isFormatAstc((VkFormat)vkformat)) { - return KTX_INVALID_OPERATION; // Not a supported decoding format. - } - - if (isFormatSRGB((VkFormat)vkformat)) { - if (!isFormatSRGB((VkFormat)This->vkFormat)) { - return KTX_INVALID_OPERATION; // Not a supported decoding format for sRGB input. - } - } else { - if (isFormatSRGB((VkFormat)This->vkFormat)) { - return KTX_INVALID_OPERATION; // Not a supported decoding format for linear input. - } - } - DECLARE_PRIVATE(priv, This); uint32_t channelId = KHR_DFDSVAL(BDB, 0, CHANNELID); @@ -1294,6 +1243,8 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { return KTX_FILE_DATA_ERROR; } + ktx_uint32_t vkformat = (ktx_uint32_t)getUncompressedFormat((VkFormat)This->vkFormat); + // Create a prototype texture to use for calculating sizes in the target // format and, as useful side effects, provide us with a properly sized // data allocation and the DFD for the target format. @@ -1353,7 +1304,7 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This, ktx_uint32_t vkformat) { // if(params->perceptual) flags |= ASTCENC_FLG_USE_PERCEPTUAL; - profile = astcDecoderProfile((VkFormat)vkformat); + profile = astcDecoderProfile(This); uint32_t threadCount{1}; // Decompression isn't the bottleneck and only used when checking for psnr and ssim astcenc_config astc_config; diff --git a/tools/ktx/metrics_utils.h b/tools/ktx/metrics_utils.h index b4b0060f28..12ec23136c 100644 --- a/tools/ktx/metrics_utils.h +++ b/tools/ktx/metrics_utils.h @@ -107,16 +107,11 @@ class MetricsCalculator { tSwizzleInfo.swizzle = "rgba"; ktx_error_code_e ec = KTX_SUCCESS; - auto vkformat = VK_FORMAT_R8G8B8A8_UNORM; // TODO: Fix format for HDR support // Decode the encoded texture to observe the compression losses const auto* bdfd = texture->pDfd + 1; - if (KHR_DFDVAL(bdfd, TRANSFER) == KHR_DF_TRANSFER_SRGB) { - vkformat = VK_FORMAT_R8G8B8A8_SRGB; - } - if (khr_df_model_e(KHR_DFDVAL(bdfd, MODEL)) == KHR_DF_MODEL_ASTC) { - ec = ktxTexture2_DecodeAstc(texture, vkformat); + ec = ktxTexture2_DecodeAstc(texture); } else { tSwizzleInfo = determineTranscodeSwizzle(texture, report); From b7acc0aa7d4b45c8286a341dae73bdd8101fe21c Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Mon, 30 Dec 2024 14:30:16 +0000 Subject: [PATCH 6/9] Add more use of DFD for existing ASTC file --- lib/astc_codec.cpp | 246 ++++----------------------------------------- 1 file changed, 20 insertions(+), 226 deletions(-) diff --git a/lib/astc_codec.cpp b/lib/astc_codec.cpp index 7e1300625d..a2e437e3d8 100644 --- a/lib/astc_codec.cpp +++ b/lib/astc_codec.cpp @@ -299,89 +299,20 @@ astcVkFormat(ktx_uint32_t block_size, bool sRGB) { * @brief Should be used to get uncompressed version of ASTC VkFormat * * The decompressed format is calculated from coressponding ASTC format. There are - * only 3 possible options currently supported. RGBA8, sRGBA8 and RGBA32. + * only 3 possible options currently supported. RGBA8, SRGBA8 and RGBA32. * * @return Uncompressed version of VKFormat for a specific ASTC VkFormat */ -inline VkFormat getUncompressedFormat(VkFormat format) noexcept { - switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: - return VK_FORMAT_R8G8B8A8_UNORM; - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: - return VK_FORMAT_R8G8B8A8_SRGB; - case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK: - case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT: +inline VkFormat getUncompressedFormat(ktxTexture2* This) noexcept { + uint32_t* BDB = This->pDfd + 1; + + if (KHR_DFDSVAL(BDB, 0, QUALIFIERS) & KHR_DF_SAMPLE_DATATYPE_FLOAT) { return VK_FORMAT_R32G32B32A32_SFLOAT; - default: - return VK_FORMAT_R8G8B8A8_SRGB; + } else { + if (khr_df_transfer_e(KHR_DFDVAL(BDB, TRANSFER) == KHR_DF_TRANSFER_SRGB)) + return VK_FORMAT_R8G8B8A8_SRGB; + else + return VK_FORMAT_R8G8B8A8_UNORM; } } @@ -394,60 +325,8 @@ inline VkFormat getUncompressedFormat(VkFormat format) noexcept { * * @return true if the VkFormat is an ASTC LDR format. */ -inline bool isFormatAstcLDR(VkFormat format) noexcept { - switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: - case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: - case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: - return true; - default: - return false; - } +inline bool isFormatAstcLDR(ktxTexture2* This) noexcept { + return (KHR_DFDSVAL(This->pDfd + 1, 0, QUALIFIERS) & KHR_DF_SAMPLE_DATATYPE_FLOAT) != 0; } /** @@ -518,7 +397,7 @@ astcDecoderProfile(ktxTexture2 *This) { ktx_uint32_t transfer = KHR_DFDVAL(BDB, TRANSFER); bool sRGB = transfer == KHR_DF_TRANSFER_SRGB; - bool ldr = isFormatAstcLDR((VkFormat)This->vkFormat); + bool ldr = isFormatAstcLDR(This); return astcProfile(sRGB, ldr); } @@ -597,88 +476,6 @@ astcBlockDimensions(ktx_uint32_t block_size, } } - -static void -astcBlockDimensions(VkFormat format, - uint32_t &x, uint32_t &y, uint32_t &z) noexcept { - switch (format) { - case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: x = 4; y = 4; z = 0; break; - case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: x = 4; y = 4; z = 0; break; - case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: x = 5; y = 4; z = 0; break; - case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: x = 5; y = 4; z = 0; break; - case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: x = 5; y = 5; z = 0; break; - case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: x = 5; y = 5; z = 0; break; - case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: x = 6; y = 5; z = 0; break; - case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: x = 6; y = 5; z = 0; break; - case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: x = 6; y = 6; z = 0; break; - case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: x = 6; y = 6; z = 0; break; - case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: x = 8; y = 5; z = 0; break; - case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: x = 8; y = 5; z = 0; break; - case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: x = 8; y = 6; z = 0; break; - case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: x = 8; y = 6; z = 0; break; - case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: x = 8; y = 8; z = 0; break; - case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: x = 8; y = 8; z = 0; break; - case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: x = 10; y = 5; z = 0; break; - case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: x = 10; y = 5; z = 0; break; - case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: x = 10; y = 6; z = 0; break; - case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: x = 10; y = 6; z = 0; break; - case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: x = 10; y = 8; z = 0; break; - case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: x = 10; y = 8; z = 0; break; - case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: x = 10; y = 10; z = 0; break; - case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: x = 10; y = 10; z = 0; break; - case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: x = 12; y = 10; z = 0; break; - case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: x = 12; y = 10; z = 0; break; - case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: x = 12; y = 12; z = 0; break; - case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: x = 12; y = 12; z = 0; break; - case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK: x = 4; y = 4; z = 0; break; - case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK: x = 5; y = 4; z = 0; break; - case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK: x = 5; y = 5; z = 0; break; - case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK: x = 6; y = 5; z = 0; break; - case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK: x = 6; y = 6; z = 0; break; - case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK: x = 8; y = 5; z = 0; break; - case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK: x = 8; y = 6; z = 0; break; - case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK: x = 8; y = 8; z = 0; break; - case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK: x = 10; y = 5; z = 0; break; - case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK: x = 10; y = 6; z = 0; break; - case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK: x = 10; y = 8; z = 0; break; - case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK: x = 10; y = 10; z = 0; break; - case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK: x = 12; y = 10; z = 0; break; - case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK: x = 12; y = 12; z = 0; break; - case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: x = 3; y = 3; z = 3; break; - case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: x = 3; y = 3; z = 3; break; - case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: x = 3; y = 3; z = 3; break; - case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: x = 4; y = 3; z = 3; break; - case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: x = 4; y = 3; z = 3; break; - case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: x = 4; y = 3; z = 3; break; - case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: x = 4; y = 4; z = 3; break; - case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: x = 4; y = 4; z = 3; break; - case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: x = 4; y = 4; z = 3; break; - case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: x = 4; y = 4; z = 4; break; - case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: x = 4; y = 4; z = 4; break; - case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: x = 4; y = 4; z = 4; break; - case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: x = 5; y = 4; z = 4; break; - case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: x = 5; y = 4; z = 4; break; - case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: x = 5; y = 4; z = 4; break; - case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: x = 5; y = 5; z = 4; break; - case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: x = 5; y = 5; z = 4; break; - case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: x = 5; y = 5; z = 4; break; - case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: x = 5; y = 5; z = 5; break; - case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: x = 5; y = 5; z = 5; break; - case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: x = 5; y = 5; z = 5; break; - case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: x = 6; y = 5; z = 5; break; - case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: x = 6; y = 5; z = 5; break; - case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: x = 6; y = 5; z = 5; break; - case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: x = 6; y = 6; z = 5; break; - case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: x = 6; y = 6; z = 5; break; - case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: x = 6; y = 6; z = 5; break; - case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: x = 6; y = 6; z = 6; break; - case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: x = 6; y = 6; z = 6; break; - case VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT: x = 6; y = 6; z = 6; break; - default: - x = 0; y = 0; z = 0; - } -} - static float astcQuality(ktx_uint32_t quality_level) { switch (quality_level) { @@ -1189,8 +986,8 @@ static void decompression_workload_runner(int thread_count, int thread_id, void* * @ingroup reader * @brief Decodes a ktx2 texture object, if it is ASTC encoded. - * The decompressed format is calculated from coressponding ASTC format. There are - * only 3 possible options currently supported. RGBA8, sRGBA8 and RGBA32. + * The decompressed format is calculated from corresponding ASTC format. There are + * only 3 possible options currently supported. RGBA8, SRGBA8 and RGBA32. * * Updates @p This with the decoded image. * @@ -1243,7 +1040,7 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This) { return KTX_FILE_DATA_ERROR; } - ktx_uint32_t vkformat = (ktx_uint32_t)getUncompressedFormat((VkFormat)This->vkFormat); + ktx_uint32_t vkformat = (ktx_uint32_t)getUncompressedFormat(This); // Create a prototype texture to use for calculating sizes in the target // format and, as useful side effects, provide us with a properly sized @@ -1288,23 +1085,20 @@ ktxTexture2_DecodeAstc(ktxTexture2 *This) { } // This is where I do the decompression from "This" to prototype target - astcenc_profile profile{ASTCENC_PRF_LDR_SRGB}; astcenc_swizzle swizzle{ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A}; - - uint32_t block_size_x{4}; - uint32_t block_size_y{4}; - uint32_t block_size_z{1}; float quality{ASTCENC_PRE_MEDIUM}; uint32_t flags{0}; // TODO: Use normals mode to reconstruct normals params->normalMap ? ASTCENC_FLG_MAP_NORMAL : 0}; - astcBlockDimensions((VkFormat)This->vkFormat, block_size_x, block_size_y, block_size_z); + uint32_t block_size_x = KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION0) + 1; + uint32_t block_size_y = KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION1) + 1; + uint32_t block_size_z = KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION2) + 1; // quality = astcQuality(params->qualityLevel); // swizzle = astcSwizzle(*params); // if(params->perceptual) flags |= ASTCENC_FLG_USE_PERCEPTUAL; - profile = astcDecoderProfile(This); + astcenc_profile profile = astcDecoderProfile(This); uint32_t threadCount{1}; // Decompression isn't the bottleneck and only used when checking for psnr and ssim astcenc_config astc_config; From 42c08d41f30910ced10ffc9d2170cfb547d2bfb8 Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Wed, 1 Jan 2025 14:26:35 +0000 Subject: [PATCH 7/9] Fix review comments --- lib/astc_codec.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/astc_codec.cpp b/lib/astc_codec.cpp index a2e437e3d8..d26bbd9abe 100644 --- a/lib/astc_codec.cpp +++ b/lib/astc_codec.cpp @@ -298,7 +298,7 @@ astcVkFormat(ktx_uint32_t block_size, bool sRGB) { * @~English * @brief Should be used to get uncompressed version of ASTC VkFormat * - * The decompressed format is calculated from coressponding ASTC format. There are + * The decompressed format is calculated from corresponding ASTC format. There are * only 3 possible options currently supported. RGBA8, SRGBA8 and RGBA32. * * @return Uncompressed version of VKFormat for a specific ASTC VkFormat @@ -988,6 +988,7 @@ static void decompression_workload_runner(int thread_count, int thread_id, void* * The decompressed format is calculated from corresponding ASTC format. There are * only 3 possible options currently supported. RGBA8, SRGBA8 and RGBA32. + * @note 3d textures are decoded to a multi-slice 3d texture. * * Updates @p This with the decoded image. * From 037c29c074d9896298d750c8f89854f8a19d9be6 Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Thu, 2 Jan 2025 09:57:03 +0000 Subject: [PATCH 8/9] Update tests cts module --- tests/cts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cts b/tests/cts index 382c891068..66b97a5b34 160000 --- a/tests/cts +++ b/tests/cts @@ -1 +1 @@ -Subproject commit 382c8910689e375835da03aae36783f8f595d6d5 +Subproject commit 66b97a5b342889d5332a6485882fa549b8aaffe0 From 0ead350ebe12167f25e159f28b118ab9981c8d16 Mon Sep 17 00:00:00 2001 From: Wasim Abbas Date: Mon, 6 Jan 2025 13:01:12 +0000 Subject: [PATCH 9/9] Fix isFormatASTCLDR --- lib/astc_codec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astc_codec.cpp b/lib/astc_codec.cpp index d26bbd9abe..d1166dd64a 100644 --- a/lib/astc_codec.cpp +++ b/lib/astc_codec.cpp @@ -326,7 +326,7 @@ inline VkFormat getUncompressedFormat(ktxTexture2* This) noexcept { * @return true if the VkFormat is an ASTC LDR format. */ inline bool isFormatAstcLDR(ktxTexture2* This) noexcept { - return (KHR_DFDSVAL(This->pDfd + 1, 0, QUALIFIERS) & KHR_DF_SAMPLE_DATATYPE_FLOAT) != 0; + return (KHR_DFDSVAL(This->pDfd + 1, 0, QUALIFIERS) & KHR_DF_SAMPLE_DATATYPE_FLOAT) == 0; } /**