tclib icon indicating copy to clipboard operation
tclib copied to clipboard

tc_texture_load.h won't support DDS files without `TCTEX_DDSD_PITCH` and `TCTEX_DDSD_LINEARSIZE`

Open wind0204 opened this issue 2 months ago • 2 comments

Hello, I'm a novice programmer and do not have clues but I had some issue with tc_texture_load.h tonight.

I transcoded from a 2048 by 2048 PNG image to a 8-mip-level BC7 dds file using AMD's compressonatorcli 4.5.52 In order to proceed with my programming study I had to make tctex_i_dds_load() ignore a small part of the code by applying a small change shown below:

diff --git a/tc_texture_load.h b/tc_texture_load.h
index 74f769d..9fd1018 100644
--- a/tc_texture_load.h
+++ b/tc_texture_load.h
@@ -870,7 +870,8 @@ static TCTex_Texture* tctex_i_dds_load(TCTex_Texture* tex, const uint8_t* udata,
     uint32_t dwPitchOrLinearSize = TCTEX__FROM_LE32(header->dwPitchOrLinearSize);
     switch(dwFlags & (TCTEX_DDSD_PITCH | TCTEX_DDSD_LINEARSIZE))
     {
-    case 0: TCTEX_I_RETERROR(tex, "[TODO] UNHANDLED: Compute pitch *and* linear size");
+    case 0: //TCTEX_I_RETERROR(tex, "[TODO] UNHANDLED: Compute pitch *and* linear size");
+        [[fallthrough]];
     case TCTEX_DDSD_PITCH:
         tex->pitch.y = TCTEX__FROM_LE32(dwPitchOrLinearSize);
         tex->pitch.z = tex->size.y * tex->pitch.y;

Thank you so much.

Now I have to figure out how to load the BC7 texture to my GPU; I hope it will be easy

wind0204 avatar Nov 23 '25 17:11 wind0204

Hi, thanks for the report!

I'll have to do some testing on my end, because I have a sneaking suspicion that I'll have to compute one or the other for this to work correctly in cases where neither flag is set. Are you able to submit a test file without those flags (e.g. your 2048x2048 dds file), so that I could do my own testing — assuming no legal/copyright issues in doing so?

darkuranium avatar Nov 23 '25 17:11 darkuranium

Are you able to submit a test file without those flags (e.g. your 2048x2048 dds file), so that I could do my own testing — assuming no legal/copyright issues in doing so?

I'm afraid it's not one of the allowed usages of Texturelabs but I can tell you how I produced one:

  • I downloaded version 4.5.52 of AMD CompressonatorCli
  • I downloaded a beautiful stone texture in the size of size of 7952x5304 on Texturelabs: https://texturelabs.org/textures/stone_153/
  • in Gimp, I copied a sample of 2048x2048 pixels from the texture and exported the sample as PNG in 8bpc RGB format, without any information like EXIF, creation time, thumbnail etc
  • I ran this sequence of commands—You should probably replace OCL with HPC to reduce the transcoding time, for me it reduced the CPU time spent from 10+min down to 1.33min:
 cd /dev/shm/$(whoami) && compressonatorcli -log -fd BC7 -EncodeWith OCL -Quality 1.0 -mipsize 16 /path_to_the_downloaded_texture/Texturelabs_Stone_153_2048.png /dev/shm/$(whoami)/stone.dds

wind0204 avatar Nov 24 '25 08:11 wind0204