Skip to content

Update to BasisU 2.0#1115

Open
MarkCallow wants to merge 9 commits intomainfrom
update_basisu
Open

Update to BasisU 2.0#1115
MarkCallow wants to merge 9 commits intomainfrom
update_basisu

Conversation

@MarkCallow
Copy link
Copy Markdown
Collaborator

Just a few lines of code changed due to basisu_encoder API changes plus some golden files regenerated due to a different version of zstd being included.

…KhronosGroup/basis_universal.git external/basis_universal

subrepo:
  subdir:   "external/basis_universal"
  merged:   "d479d2631"
upstream:
  origin:   "https://github.com/KhronosGroup/basis_universal.git"
  branch:   "set_fp_options"
  commit:   "d479d2631"
git-subrepo:
  version:  "0.4.9"
  origin:   "https://github.com/MarkCallow/git-subrepo.git"
  commit:   "4f60dd7"
subrepo:
  subdir:   "external/basis_universal"
  merged:   "29e75d0f3"
upstream:
  origin:   "https://github.com/KhronosGroup/basis_universal.git"
  branch:   "set_fp_options"
  commit:   "29e75d0f3"
git-subrepo:
  version:  "0.4.9"
  origin:   "https://github.com/MarkCallow/git-subrepo.git"
  commit:   "4f60dd7"
subrepo:
  subdir:   "external/basis_universal"
  merged:   "c40de6605"
upstream:
  origin:   "https://github.com/KhronosGroup/basis_universal.git"
  branch:   "set_fp_options"
  commit:   "c40de6605"
git-subrepo:
  version:  "0.4.9"
  origin:   "https://github.com/MarkCallow/git-subrepo.git"
  commit:   "4f60dd7"
@solbjorn
Copy link
Copy Markdown

solbjorn commented Feb 17, 2026

The diff outside external/ folder after rebasing the PR onto the latest commit (with HDR):

diff --git a/interface/js_binding/transcoder_wrapper.cpp b/interface/js_binding/transcoder_wrapper.cpp
index b54b8aaab7c5..71609f33b6ad 100644
--- a/interface/js_binding/transcoder_wrapper.cpp
+++ b/interface/js_binding/transcoder_wrapper.cpp
@@ -465,7 +465,7 @@ enum TranscodeTarget = {
 
 enum TextureFormat = {
     "ETC1S",
-    "UASTC4x4",
+    "UASTC_LDR_4x4",
 };
 
 enum TranscodeFlagBits =
@@ -525,7 +525,7 @@ container format.
     // Determine from the KTX2 header information in buData if
     // the data format  is BasisU or Uastc.
     // supercompressionScheme value == 1, it's TextureFormat.ETC1S.
-    // DFD colorModel == 166, it's TextureFormat.UASTC4x4.
+    // DFD colorModel == 166, it's TextureFormat.UASTC_LDR_4x4.
     const texFormat = ...
 
     // Determine appropriate transcode format from available targets,
@@ -536,7 +536,7 @@ container format.
         throw new Error( ... );
     }
 
-    if (TextureFormat.UASTC4x4) {
+    if (TextureFormat.UASTC_LDR_4x4) {
         var result = transcodeUastc(targetFormat);
     } else {
         var result = transcodeEtc1s(targetFormat);
@@ -676,7 +676,7 @@ transcodeUastc(targetFormat) {
       var levelImageCount = number of layers * number of faces * depth;
       var imageOffsetInLevel = 0;
 
-      var imageInfo = new ImageInfo(TextureFormat::UASTC4x4,
+      var imageInfo = new ImageInfo(TextureFormat::UASTC_LDR_4x4,
                                     levelWidth, levelHeight, level);
       var levelImageByteLength = imageInfo.numBlocksX * imageInfo.numBlocksY * DFD bytesPlane0;
 
@@ -746,7 +746,9 @@ EMSCRIPTEN_BINDINGS(ktx_wrappers)
 
     enum_<basis_tex_format>("TextureFormat")
         .value("ETC1S", basis_tex_format::cETC1S)
-        .value("UASTC4x4", basis_tex_format::cUASTC4x4)
+        .value("UASTC_LDR_4x4", basis_tex_format::cUASTC_LDR_4x4)
+        // For backward compatibility
+        .value("UASTC4x4", basis_tex_format::cUASTC_LDR_4x4)
     ;
 
     enum_<msc::TranscodeFlagBits>("TranscodeFlagBits")
diff --git a/lib/src/basis_encode.cpp b/lib/src/basis_encode.cpp
index 4c533e654106..23f42015f6fa 100644
--- a/lib/src/basis_encode.cpp
+++ b/lib/src/basis_encode.cpp
@@ -647,7 +647,7 @@ ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params)
     case ktx_basis_codec_e::KTX_BASIS_CODEC_UASTC_HDR_6X6_INTERMEDIATE:
         cparams.m_uastc = true;
         cparams.m_hdr = true;
-        cparams.m_hdr_mode = basisu::hdr_modes::cASTC_HDR_6X6_INTERMEDIATE;
+        cparams.m_hdr_mode = basisu::hdr_modes::cUASTC_HDR_6X6_INTERMEDIATE;
         break;
     default:
         break;
@@ -867,10 +867,12 @@ ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params)
     ktx_uint32_t transfer = KHR_DFDVAL(BDB, TRANSFER);
     if (transfer == KHR_DF_TRANSFER_SRGB) {
         cparams.m_perceptual = true;
-        cparams.m_ktx2_srgb_transfer_func = true;
+        cparams.m_ktx2_and_basis_srgb_transfer_function = true;
     }
-    else
+    else {
         cparams.m_perceptual = false;
+        cparams.m_ktx2_and_basis_srgb_transfer_function = false;
+    }
 
     cparams.m_mip_gen = false; // We provide the mip levels.
     
@@ -917,7 +919,7 @@ ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params)
         // indicate the parameter has not been set by the caller. (If we
         // leave m_compression_level unset it will default to 1. We don't
         // want the default to differ from `basisu` so 0 can't be the default.
-        cparams.m_compression_level = params->etc1sCompressionLevel;
+        cparams.m_etc1s_compression_level = params->etc1sCompressionLevel;
 
         // There's no default for m_quality_level. `basisu` tool overrides
         // any explicit m_{endpoint,selector}_clusters settings with those
@@ -941,11 +943,11 @@ ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params)
         } else if (params->qualityLevel != 0) {
             cparams.m_etc1s_max_endpoint_clusters = 0;
             cparams.m_etc1s_max_selector_clusters = 0;
-            cparams.m_etc1s_quality_level = params->qualityLevel;
+            cparams.m_quality_level = params->qualityLevel;
         } else {
             cparams.m_etc1s_max_endpoint_clusters = 0;
             cparams.m_etc1s_max_selector_clusters = 0;
-            cparams.m_etc1s_quality_level = 128;
+            cparams.m_quality_level = 128;
         }
 
         if (params->endpointRDOThreshold > 0)
@@ -1089,7 +1091,7 @@ ktxTexture2_CompressBasisEx(ktxTexture2* This, ktxBasisParams* params)
     std::vector<uint32_t> level_file_offsets(This->numLevels);
 
     if (cparams.m_uastc) {
-        if (cparams.m_hdr && cparams.m_hdr_mode == hdr_modes::cASTC_HDR_6X6_INTERMEDIATE) {
+        if (cparams.m_hdr && cparams.m_hdr_mode == hdr_modes::cUASTC_HDR_6X6_INTERMEDIATE) {
             uint32_t image_desc_size = sizeof(ktxUASTCHDR6X6IntermediateImageDesc);
             bgd_size = image_desc_size * num_images;
             bgd = new ktx_uint8_t[bgd_size];
@@ -1356,7 +1358,7 @@ cleanup:
 }
 
 extern "C" KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL
-                                      = BASISU_DEFAULT_COMPRESSION_LEVEL;
+                                           = BASISU_DEFAULT_ETC1S_COMPRESSION_LEVEL;
 
 /**
  * @memberof ktxTexture2
diff --git a/lib/src/basis_transcode.cpp b/lib/src/basis_transcode.cpp
index c9cf31d4f7f1..7c5ed05f66cc 100644
--- a/lib/src/basis_transcode.cpp
+++ b/lib/src/basis_transcode.cpp
@@ -343,11 +343,11 @@ ktx2transcoderFormat(ktx_transcode_fmt_e ktx_fmt) {
 
     basis_tex_format textureFormat;
     if (colorModel == KHR_DF_MODEL_UASTC)
-        textureFormat = basis_tex_format::cUASTC4x4;
+        textureFormat = basis_tex_format::cUASTC_LDR_4x4;
     else if (colorModel == KHR_DF_MODEL_UASTC_HDR_4X4)
         textureFormat = basis_tex_format::cUASTC_HDR_4x4;        
     else if (colorModel == KHR_DF_MODEL_UASTC_HDR_6X6)
-        textureFormat = basis_tex_format::cASTC_HDR_6x6_INTERMEDIATE;    
+        textureFormat = basis_tex_format::cUASTC_HDR_6x6_INTERMEDIATE;    
     else
         textureFormat = basis_tex_format::cETC1S;
 
@@ -911,7 +911,7 @@ transcodeUastcHDR6x6_intermediate(ktxTexture2* This, alpha_content_e alphaConten
     ktxLevelIndexEntry* protoLevelIndex = protoPriv._levelIndex;
     ktx_size_t levelOffsetWrite = 0;
 
-    basist::basisu_lowlevel_astc_hdr_6x6_intermediate_transcoder uit;
+    basist::basisu_lowlevel_uastc_hdr_6x6_intermediate_transcoder uit;
     // See comment on same declaration in transcodeEtc1s.
     std::vector<basisu_transcoder_state> xcoderStates;
     xcoderStates.resize(This->isVideo ? This->numFaces : 1);
diff --git a/tests/webgl/llt-three/KTX2Loader.js b/tests/webgl/llt-three/KTX2Loader.js
index a3681417428d..eba93625f6ad 100644
--- a/tests/webgl/llt-three/KTX2Loader.js
+++ b/tests/webgl/llt-three/KTX2Loader.js
@@ -138,13 +138,13 @@ class KTX2Loader extends CompressedTextureLoader {
 // colorModel is ETC1S (163) or if dfd colorModel is UASTCF (166)
 // then texture must be transcoded.
 
-		var texFormat = ktx.dfd.colorModel == DFD.modelUastc ? TextureFormat.UASTC4x4
+		var texFormat = ktx.dfd.colorModel == DFD.modelUastc ? TextureFormat.UASTC_LDR_4x4
 												   : TextureFormat.ETC1S;
 		// TODO(donmccurdy): Handle all channelIds (i.e. the R & R+G cases),
 		// choosing appropriate transcode target formats or providing queries
 		// for applications so they know what to do with the content.
 		var hasAlpha = false;
-		if (texFormat == TextureFormat.UASTC4x4) {
+		if (texFormat == TextureFormat.UASTC_LDR_4x4) {
 			var transcoder = new UastcImageTranscoder();
 			if ( (ktx.dfd.samples[0].channelId & 0xf) === DFD.channelUastc.rgba )
 				hasAlpha = true;
@@ -419,7 +419,7 @@ class KTX2Container {
 
 		var isVideo = false;
 
-		// For both ETC1S and UASTC4x4 formats.
+		// For both ETC1S and UASTC_LDR_4x4 formats.
 		if ( texFormat == TextureFormat.ETC1S ) {
 			var numEndpoints = this.sgd.endpointCount;
 			var numSelectors = this.sgd.selectorCount;
@@ -483,7 +483,7 @@ class KTX2Container {
 			for ( var imageIndex = 0; imageIndex < numImagesInLevel; imageIndex ++ ) {
 
 				var result;
-				if ( texFormat == TextureFormat.UASTC4x4 ) {
+				if ( texFormat == TextureFormat.UASTC_LDR_4x4 ) {
 					imageInfo.flags = 0;
 					imageInfo.rgbByteOffset = 0;
 					imageInfo.rgbByteLength = levelImageByteLength;

Note the explicit initialization of m_ktx2_and_basis_srgb_transfer_function -- in BasisU 2, it's true by default, so setting it to false is necessary.

I can't say it accounts everything, but I haven't spotted any regressions so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants