From f2497f14d6c43c0b1c75e58e161c455d0cd058d7 Mon Sep 17 00:00:00 2001 From: Richard Geldreich Date: Sat, 18 Jul 2026 17:12:51 -0400 Subject: [PATCH] KTX2 transcoder: build with BASISD_SUPPORT_KTX2 disabled Two things prevented the transcoder from compiling with BASISD_SUPPORT_KTX2 set to 0: - ktx2_image_level_info was defined inside the #if BASISD_SUPPORT_KTX2 block, but dds_transcoder::get_image_level_info() takes it by reference and is compiled unconditionally. Move the struct ahead of that block so it is always defined; it has no KTX2-specific members. - The "#include ../zstd/zstd.h" was nested inside #if BASISD_SUPPORT_KTX2, but the Zstd decompressor (zstd_decompress()) is compiled whenever BASISD_SUPPORT_KTX2_ZSTD is set, independent of KTX2 (Zstd is also used by other codecs). With KTX2 off but Zstd on, the ZSTD_* symbols were referenced without the header being included. Gate the include on BASISD_SUPPORT_KTX2_ZSTD alone, matching where the symbols are used. BASISD_SUPPORT_KTX2_ZSTD still defaults to 1 (unchanged). The default build (KTX2 and Zstd both enabled) is unaffected. Co-Authored-By: Claude Opus 4.8 --- transcoder/basisu_transcoder.cpp | 12 +++--- transcoder/basisu_transcoder.h | 70 ++++++++++++++++---------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/transcoder/basisu_transcoder.cpp b/transcoder/basisu_transcoder.cpp index 721d298..2e413ed 100644 --- a/transcoder/basisu_transcoder.cpp +++ b/transcoder/basisu_transcoder.cpp @@ -171,13 +171,11 @@ #define BASISD_ENABLE_DEBUG_FLAGS 0 #endif -// If KTX2 support is enabled, we may need Zstd for decompression of supercompressed UASTC files. Include this header. -#if BASISD_SUPPORT_KTX2 - // If BASISD_SUPPORT_KTX2_ZSTD is 0, UASTC files compressed with Zstd cannot be loaded. - #if BASISD_SUPPORT_KTX2_ZSTD - // We only use two Zstd API's: ZSTD_decompress() and ZSTD_isError() - #include "../zstd/zstd.h" - #endif +// Zstd is used both for KTX2 supercompressed UASTC files and for Zstd-compressed data in other codecs (independent of KTX2 support), so include the header whenever Zstd usage is enabled -- not just when KTX2 is enabled. +// If BASISD_SUPPORT_KTX2_ZSTD is 0, data compressed with Zstd cannot be loaded. +#if BASISD_SUPPORT_KTX2_ZSTD + // We only use these Zstd API's: ZSTD_decompress(), ZSTD_isError() and ZSTD_getFrameContentSize() + #include "../zstd/zstd.h" #endif #if BASISD_SUPPORT_UASTC_HDR diff --git a/transcoder/basisu_transcoder.h b/transcoder/basisu_transcoder.h index 4a961cd..1cf2b18 100644 --- a/transcoder/basisu_transcoder.h +++ b/transcoder/basisu_transcoder.h @@ -984,7 +984,41 @@ namespace basist uint32_t get_debug_flags(); void set_debug_flags(uint32_t f); - // ------------------------------------------------------------------------------------------------------ + // Information about a single 2D texture "image" in a KTX2 file. (Also used by the DDS transcoder, so it is defined unconditionally, i.e. even when BASISD_SUPPORT_KTX2 is 0.) + struct ktx2_image_level_info + { + // The mipmap level index (0=largest), texture array layer index, and cubemap face index of the image. + uint32_t m_level_index; + uint32_t m_layer_index; + uint32_t m_face_index; + + // The image's ACTUAL (or the original source image's) width/height in pixels, which may not be divisible by the block size (4-12 pixels). + uint32_t m_orig_width; + uint32_t m_orig_height; + + // The image's physical width/height, which will always be divisible by the format's block size (4-12 pixels). + uint32_t m_width; + uint32_t m_height; + + // The texture's dimensions in 4x4-12x12 texel blocks. + uint32_t m_num_blocks_x; + uint32_t m_num_blocks_y; + + // The format's block width/height (4-12). + uint32_t m_block_width; + uint32_t m_block_height; + + // The total number of blocks + uint32_t m_total_blocks; + + // true if the image has alpha data + bool m_alpha_flag; + + // true if the image is an I-Frame. Currently, for ETC1S textures, the first frame will always be an I-Frame, and subsequent frames will always be P-Frames. + bool m_iframe_flag; + }; + + // ------------------------------------------------------------------------------------------------------ // Optional .KTX2 file format support // KTX2 reading optionally requires miniz or Zstd decompressors for supercompressed UASTC files. // ------------------------------------------------------------------------------------------------------ @@ -1196,39 +1230,7 @@ namespace basist return "?"; } - // Information about a single 2D texture "image" in a KTX2 file. - struct ktx2_image_level_info - { - // The mipmap level index (0=largest), texture array layer index, and cubemap face index of the image. - uint32_t m_level_index; - uint32_t m_layer_index; - uint32_t m_face_index; - - // The image's ACTUAL (or the original source image's) width/height in pixels, which may not be divisible by the block size (4-12 pixels). - uint32_t m_orig_width; - uint32_t m_orig_height; - - // The image's physical width/height, which will always be divisible by the format's block size (4-12 pixels). - uint32_t m_width; - uint32_t m_height; - - // The texture's dimensions in 4x4-12x12 texel blocks. - uint32_t m_num_blocks_x; - uint32_t m_num_blocks_y; - - // The format's block width/height (4-12). - uint32_t m_block_width; - uint32_t m_block_height; - - // The total number of blocks - uint32_t m_total_blocks; - - // true if the image has alpha data - bool m_alpha_flag; - - // true if the image is an I-Frame. Currently, for ETC1S textures, the first frame will always be an I-Frame, and subsequent frames will always be P-Frames. - bool m_iframe_flag; - }; + // ktx2_image_level_info is defined above, before the BASISD_SUPPORT_KTX2 block (unconditionally, since the DDS transcoder also uses it). // Thread-specific ETC1S/supercompressed UASTC transcoder state. (If you're not doing multithreading transcoding you can ignore this.) struct ktx2_transcoder_state