Skip to content

Commit d402f5e

Browse files
committed
libktx: Update to 4.3.2
1 parent f6a78f8 commit d402f5e

File tree

14 files changed

+992
-483
lines changed

14 files changed

+992
-483
lines changed

modules/ktx/SCsub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ thirdparty_sources = [
2222
"lib/texture1.c",
2323
"lib/texture2.c",
2424
"lib/vkformat_check.c",
25+
"lib/vkformat_typesize.c",
2526
"lib/dfdutils/createdfd.c",
2627
"lib/dfdutils/colourspaces.c",
2728
"lib/dfdutils/interpretdfd.c",

thirdparty/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,18 @@ Files extracted from upstream source:
432432
## libktx
433433

434434
- Upstream: https://github.com/KhronosGroup/KTX-Software
435-
- Version: 4.3.1 (c0214158d551cfc779624b0f84130bcbbefef59a, 2024)
435+
- Version: 4.3.2 (91ace88675ac59a97e55d0378a6602a9ae6b98bd, 2024)
436436
- License: Apache-2.0
437437

438438
Files extracted from upstream source:
439439

440440
- `LICENSE.md`
441-
- `include/*`
441+
- `include/`
442442
- `lib/dfdutils/LICENSE.adoc` as `LICENSE.dfdutils.adoc` (in root)
443443
- `lib/dfdutils/LICENSES/Apache-2.0.txt` as `Apache-2.0.txt` (in root)
444-
- `lib/dfdutils/{KHR/*,dfd.h,colourspaces.c,createdfd.c,interpretdfd.c,printdfd.c,queries.c,dfd2vk.inl,vk2dfd.*}`
445-
- `lib/{basis_sgd.h,formatsize.h,gl_format.h,ktxint.h,uthash.h,vk_format.h,vkformat_enum.h,checkheader.c,swap.c,hashlist.c,vkformat_check.c,basis_transcode.cpp,miniz_wrapper.cpp,filestream.*,memstream.*,texture*}`
446-
- `other_include/KHR/*`
444+
- `lib/dfdutils/{KHR/,dfd.h,colourspaces.c,createdfd.c,interpretdfd.c,printdfd.c,queries.c,dfd2vk.inl,vk2dfd.*}`
445+
- `lib/{basis_sgd.h,formatsize.h,gl_format.h,ktxint.h,uthash.h,vk_format.h,vkformat_enum.h,checkheader.c,swap.c,hashlist.c,vkformat_check.c,vkformat_typesize.c,basis_transcode.cpp,miniz_wrapper.cpp,filestream.*,memstream.*,texture*}`
446+
- `other_include/KHR/`
447447
- `utils/unused.h`
448448

449449
Some Godot-specific changes are applied via patches included in the `patches` folder.

thirdparty/libktx/lib/dfdutils/createdfd.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ static uint32_t setChannelFlags(uint32_t channel, enum VkSuffix suffix)
9494
channel |= KHR_DF_SAMPLE_DATATYPE_LINEAR;
9595
}
9696
break;
97+
case s_S10_5:
98+
channel |=
99+
KHR_DF_SAMPLE_DATATYPE_SIGNED;
100+
break;
97101
}
98102
return channel;
99103
}
@@ -109,7 +113,6 @@ static void writeSample(uint32_t *DFD, int sampleNo, int channel,
109113
float f;
110114
} lower, upper;
111115
uint32_t *sample = DFD + 1 + KHR_DF_WORD_SAMPLESTART + sampleNo * KHR_DF_WORD_SAMPLEWORDS;
112-
if (channel == 3) channel = KHR_DF_CHANNEL_RGBSDA_ALPHA;
113116

114117
if (channel == 3) channel = KHR_DF_CHANNEL_RGBSDA_ALPHA;
115118
channel = setChannelFlags(channel, suffix);
@@ -159,6 +162,10 @@ static void writeSample(uint32_t *DFD, int sampleNo, int channel,
159162
upper.f = 1.0f;
160163
lower.f = 0.0f;
161164
break;
165+
case s_S10_5:
166+
assert(bits == 16 && "Format with this suffix must be 16 bits per channel.");
167+
upper.i = 32;
168+
lower.i = ~upper.i + 1; // -32
162169
}
163170
sample[KHR_DF_SAMPLEWORD_SAMPLELOWER] = lower.i;
164171
sample[KHR_DF_SAMPLEWORD_SAMPLEUPPER] = upper.i;
@@ -230,8 +237,9 @@ uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes,
230237
* @param bits[] An array of length numChannels.
231238
* Each entry is the number of bits composing the channel, in
232239
* order starting at bit 0 of the packed type.
233-
* @param paddings[] An array of length numChannels.
234-
* Each entry is the number of padding bits after each channel.
240+
* @param shiftBits[] An array of length numChannels.
241+
* Each entry is the number of bits each channel is shifted
242+
* and thus padded with insignificant bits.
235243
* @param channels[] An array of length numChannels.
236244
* Each entry enumerates the channel type: 0 = red, 1 = green,
237245
* 2 = blue, 15 = alpha, in order starting at bit 0 of the
@@ -243,9 +251,9 @@ uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes,
243251
* @return A data format descriptor in malloc'd data. The caller is responsible
244252
* for freeing the descriptor.
245253
**/
246-
uint32_t *createDFDPackedPadded(int bigEndian, int numChannels,
247-
int bits[], int paddings[], int channels[],
248-
enum VkSuffix suffix)
254+
uint32_t *createDFDPackedShifted(int bigEndian, int numChannels,
255+
int bits[], int shiftBits[], int channels[],
256+
enum VkSuffix suffix)
249257
{
250258
uint32_t *DFD = 0;
251259
if (numChannels == 6) {
@@ -291,17 +299,18 @@ uint32_t *createDFDPackedPadded(int bigEndian, int numChannels,
291299
int sampleCounter;
292300
for (channelCounter = 0; channelCounter < numChannels; ++channelCounter) {
293301
beChannelStart[channelCounter] = totalBits;
294-
totalBits += bits[channelCounter] + paddings[channelCounter];
302+
totalBits += shiftBits[channelCounter] + bits[channelCounter];
295303
}
296304
BEMask = (totalBits - 1) & 0x18;
297305
for (channelCounter = 0; channelCounter < numChannels; ++channelCounter) {
306+
bitOffset += shiftBits[channelCounter];
298307
bitChannel[bitOffset ^ BEMask] = channelCounter;
299308
if (((bitOffset + bits[channelCounter] - 1) & ~7) != (bitOffset & ~7)) {
300309
/* Continuation sample */
301310
bitChannel[((bitOffset + bits[channelCounter] - 1) & ~7) ^ BEMask] = channelCounter;
302311
numSamples++;
303312
}
304-
bitOffset += bits[channelCounter] + paddings[channelCounter];
313+
bitOffset += bits[channelCounter];
305314
}
306315
DFD = writeHeader(numSamples, totalBits >> 3, suffix, i_COLOR);
307316

@@ -343,16 +352,17 @@ uint32_t *createDFDPackedPadded(int bigEndian, int numChannels,
343352
int totalBits = 0;
344353
int bitOffset = 0;
345354
for (sampleCounter = 0; sampleCounter < numChannels; ++sampleCounter) {
346-
totalBits += bits[sampleCounter] + paddings[sampleCounter];
355+
totalBits += shiftBits[sampleCounter] + bits[sampleCounter];
347356
}
348357

349358
/* One sample per channel */
350359
DFD = writeHeader(numChannels, totalBits >> 3, suffix, i_COLOR);
351360
for (sampleCounter = 0; sampleCounter < numChannels; ++sampleCounter) {
361+
bitOffset += shiftBits[sampleCounter];
352362
writeSample(DFD, sampleCounter, channels[sampleCounter],
353363
bits[sampleCounter], bitOffset,
354364
1, 1, suffix);
355-
bitOffset += bits[sampleCounter] + paddings[sampleCounter];
365+
bitOffset += bits[sampleCounter];
356366
}
357367
}
358368
return DFD;
@@ -383,20 +393,20 @@ uint32_t *createDFDPacked(int bigEndian, int numChannels,
383393
int bits[], int channels[],
384394
enum VkSuffix suffix) {
385395
assert(numChannels <= 6);
386-
int paddings[] = {0, 0, 0, 0, 0, 0};
387-
return createDFDPackedPadded(bigEndian, numChannels, bits, paddings, channels, suffix);
396+
int shiftBits[] = {0, 0, 0, 0, 0, 0};
397+
return createDFDPackedShifted(bigEndian, numChannels, bits, shiftBits, channels, suffix);
388398
}
389399

390400
uint32_t *createDFD422(int bigEndian, int numSamples,
391-
int bits[], int paddings[], int channels[],
401+
int bits[], int shiftBits[], int channels[],
392402
int position_xs[], int position_ys[],
393403
enum VkSuffix suffix) {
394404
assert(!bigEndian); (void) bigEndian;
395405
assert(suffix == s_UNORM); (void) suffix;
396406

397407
int totalBits = 0;
398408
for (int i = 0; i < numSamples; ++i)
399-
totalBits += bits[i] + paddings[i];
409+
totalBits += shiftBits[i] + bits[i];
400410
assert(totalBits % 8 == 0);
401411

402412
uint32_t BDFDSize = sizeof(uint32_t) * (KHR_DF_WORD_SAMPLESTART + numSamples * KHR_DF_WORD_SAMPLEWORDS);
@@ -428,6 +438,7 @@ uint32_t *createDFD422(int bigEndian, int numSamples,
428438

429439
int bitOffset = 0;
430440
for (int i = 0; i < numSamples; ++i) {
441+
bitOffset += shiftBits[i];
431442
KHR_DFDSETSVAL(BDFD, i, BITOFFSET, bitOffset);
432443
KHR_DFDSETSVAL(BDFD, i, BITLENGTH, bits[i] - 1);
433444
KHR_DFDSETSVAL(BDFD, i, CHANNELID, channels[i]);
@@ -438,7 +449,7 @@ uint32_t *createDFD422(int bigEndian, int numSamples,
438449
KHR_DFDSETSVAL(BDFD, i, SAMPLEPOSITION3, 0);
439450
KHR_DFDSETSVAL(BDFD, i, SAMPLELOWER, 0);
440451
KHR_DFDSETSVAL(BDFD, i, SAMPLEUPPER, (1u << bits[i]) - 1u);
441-
bitOffset += bits[i] + paddings[i];
452+
bitOffset += bits[i];
442453
}
443454

444455
return DFD;

thirdparty/libktx/lib/dfdutils/dfd.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ enum VkSuffix {
3535
s_SINT, /*!< Signed integer format. */
3636
s_SFLOAT, /*!< Signed float format. */
3737
s_UFLOAT, /*!< Unsigned float format. */
38-
s_SRGB /*!< sRGB normalized format. */
38+
s_SRGB, /*!< sRGB normalized format. */
39+
s_S10_5 /*!< 2's complement fixed-point; 5 fractional bits. */
3940
};
4041

4142
/** Compression scheme, in Vulkan terms. */
@@ -68,15 +69,16 @@ typedef unsigned int uint32_t;
6869
#endif
6970

7071
uint32_t* vk2dfd(enum VkFormat format);
72+
enum VkFormat dfd2vk(uint32_t* dfd);
7173

7274
/* Create a Data Format Descriptor for an unpacked format. */
7375
uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes,
7476
int redBlueSwap, enum VkSuffix suffix);
7577

7678
/* Create a Data Format Descriptor for a packed padded format. */
77-
uint32_t *createDFDPackedPadded(int bigEndian, int numChannels,
78-
int bits[], int paddings[], int channels[],
79-
enum VkSuffix suffix);
79+
uint32_t *createDFDPackedShifted(int bigEndian, int numChannels,
80+
int bits[], int shiftBits[],
81+
int channels[], enum VkSuffix suffix);
8082

8183
/* Create a Data Format Descriptor for a packed format. */
8284
uint32_t *createDFDPacked(int bigEndian, int numChannels,
@@ -85,7 +87,7 @@ uint32_t *createDFDPacked(int bigEndian, int numChannels,
8587

8688
/* Create a Data Format Descriptor for a 4:2:2 format. */
8789
uint32_t *createDFD422(int bigEndian, int numChannels,
88-
int bits[], int paddings[], int channels[],
90+
int bits[], int shiftBits[], int channels[],
8991
int position_xs[], int position_ys[],
9092
enum VkSuffix suffix);
9193

@@ -111,10 +113,11 @@ enum InterpretDFDResult {
111113
i_SRGB_FORMAT_BIT = 1u << 2u, /*!< sRGB transfer function. */
112114
i_NORMALIZED_FORMAT_BIT = 1u << 3u, /*!< Normalized (UNORM or SNORM). */
113115
i_SIGNED_FORMAT_BIT = 1u << 4u, /*!< Format is signed. */
114-
i_FLOAT_FORMAT_BIT = 1u << 5u, /*!< Format is floating point. */
115-
i_COMPRESSED_FORMAT_BIT = 1u << 6u, /*!< Format is block compressed (422). */
116-
i_YUVSDA_FORMAT_BIT = 1u << 7u, /*!< Color model is YUVSDA. */
117-
i_UNSUPPORTED_ERROR_BIT = 1u << 8u, /*!< Format not successfully interpreted. */
116+
i_FIXED_FORMAT_BIT = 1u << 5u, /*!< Format is a fixed-point representation. */
117+
i_FLOAT_FORMAT_BIT = 1u << 6u, /*!< Format is floating point. */
118+
i_COMPRESSED_FORMAT_BIT = 1u << 7u, /*!< Format is block compressed (422). */
119+
i_YUVSDA_FORMAT_BIT = 1u << 8u, /*!< Color model is YUVSDA. */
120+
i_UNSUPPORTED_ERROR_BIT = 1u << 9u, /*!< Format not successfully interpreted. */
118121
/** "NONTRIVIAL_ENDIANNESS" means not big-endian, not little-endian
119122
* (a channel has bits that are not consecutive in either order). **/
120123
i_UNSUPPORTED_NONTRIVIAL_ENDIANNESS = i_UNSUPPORTED_ERROR_BIT,
@@ -198,9 +201,12 @@ getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents,
198201
/* Return the number of components described by a DFD. */
199202
uint32_t getDFDNumComponents(const uint32_t* DFD);
200203

201-
/* Recreate and return the value of bytesPlane0 as it should be for the data
204+
/* Reconstruct and return the value of bytesPlane0 as it should be for the data
202205
* post-inflation from variable-rate compression.
203206
*/
207+
uint32_t
208+
reconstructDFDBytesPlane0FromSamples(const uint32_t* DFD);
209+
/* Deprecated. For backward compatibility. */
204210
void
205211
recreateBytesPlane0FromSampleInfo(const uint32_t* DFD, uint32_t* bytesPlane0);
206212

0 commit comments

Comments
 (0)