Skip to content

Commit 6fcd95a

Browse files
authored
Merge ktx compare to main (#868)
This PR contains all the code changes for the ktx compare tool, alongside other changes related to fixes needed to be done in order for ktx compare to work as expected (including the fixes related to the handling of the D24S8 format).
1 parent 39a8213 commit 6fcd95a

27 files changed

+4895
-114
lines changed

cmake/docs.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function( CreateDocTools )
154154
doxygen_add_docs(
155155
tools.doc
156156
tools/ktx/ktx_main.cpp
157+
tools/ktx/command_compare.cpp
157158
tools/ktx/command_create.cpp
158159
tools/ktx/command_encode.cpp
159160
tools/ktx/command_extract.cpp

lib/dfdutils/createdfd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,19 @@ uint32_t *createDFDDepthStencil(int depthBits,
736736
uint32_t *DFD = 0;
737737
DFD = writeHeader((depthBits > 0) + (stencilBits > 0),
738738
sizeBytes, s_UNORM, i_NON_COLOR);
739+
740+
/* Handle the special case of D24_UNORM_S8_UINT where the order of the
741+
channels is flipped by putting stencil in the LSBs. */
742+
if (depthBits == 24 && stencilBits == 8) {
743+
writeSample(DFD, 0, KHR_DF_CHANNEL_RGBSDA_STENCIL,
744+
8, 0,
745+
1, 1, s_UINT);
746+
writeSample(DFD, 1, KHR_DF_CHANNEL_RGBSDA_DEPTH,
747+
24, 8,
748+
1, 1, s_UNORM);
749+
return DFD;
750+
}
751+
739752
if (depthBits == 32) {
740753
writeSample(DFD, 0, KHR_DF_CHANNEL_RGBSDA_DEPTH,
741754
32, 0,

lib/dfdutils/dfd2vk.inl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ if (KHR_DFDVAL(dfd + 1, MODEL) == KHR_DF_MODEL_RGBSDA || KHR_DFDVAL(dfd + 1, MOD
4040
}
4141
}
4242
if (KHR_DFDSVAL((dfd + 1), 0, CHANNELID) == KHR_DF_CHANNEL_RGBSDA_STENCIL) {
43-
return VK_FORMAT_S8_UINT;
43+
if (KHR_DFDSAMPLECOUNT((dfd + 1)) == 1) {
44+
return VK_FORMAT_S8_UINT;
45+
} else {
46+
// The KTX 2.0 specification defines D24_UNORM_S8_UINT with S8 in the LSBs
47+
return VK_FORMAT_D24_UNORM_S8_UINT;
48+
}
4449
}
4550

4651
r = interpretDFD(dfd, &R, &G, &B, &A, &wordBytes);

lib/dfdutils/makedfd2vk.pl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ sub checkSuffices {
282282
}
283283
}
284284
if (KHR_DFDSVAL((dfd + 1), 0, CHANNELID) == KHR_DF_CHANNEL_RGBSDA_STENCIL) {
285-
return VK_FORMAT_S8_UINT;
285+
if (KHR_DFDSAMPLECOUNT((dfd + 1)) == 1) {
286+
return VK_FORMAT_S8_UINT;
287+
} else {
288+
// The KTX 2.0 specification defines D24_UNORM_S8_UINT with S8 in the LSBs
289+
return VK_FORMAT_D24_UNORM_S8_UINT;
290+
}
286291
}
287292
288293
r = interpretDFD(dfd, &R, &G, &B, &A, &wordBytes);

lib/dfdutils/printdfd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ const char* dfdToStringColorModel(khr_df_model_e value) {
245245
return NULL;
246246
}
247247

248-
const char* dfdToStringSampleDatatypeQualifiers(uint32_t bit_index, bool bit_value) {
248+
const char* dfdToStringSampleDatatypeQualifiersBit(uint32_t bit_index, bool bit_value) {
249249
if (!bit_value)
250250
return NULL;
251251

@@ -782,7 +782,7 @@ void printDFD(uint32_t *DFD, uint32_t dataSize)
782782

783783
khr_df_sample_datatype_qualifiers_e qualifiers = KHR_DFDSVAL(block, sample, QUALIFIERS);
784784
printf(" Qualifiers: 0x%X (", qualifiers);
785-
printFlagBits(qualifiers, dfdToStringSampleDatatypeQualifiers);
785+
printFlagBits(qualifiers, dfdToStringSampleDatatypeQualifiersBit);
786786
printf(")\n");
787787
printf(" Channel Type: 0x%X", channelType);
788788
{
@@ -960,7 +960,7 @@ void printDFDJSON(uint32_t* DFD, uint32_t dataSize, uint32_t base_indent, uint32
960960

961961
} else {
962962
PRINT_INDENT(4, "\"qualifiers\":%s[%s", space, nl)
963-
printFlagBitsJSON(LENGTH_OF_INDENT(5), nl, qualifiers, dfdToStringSampleDatatypeQualifiers);
963+
printFlagBitsJSON(LENGTH_OF_INDENT(5), nl, qualifiers, dfdToStringSampleDatatypeQualifiersBit);
964964
PRINT_INDENT(4, "],%s", nl)
965965
}
966966

lib/internalexport_write.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ EXPORTS
2121
dfdToStringColorModel
2222
dfdToStringColorPrimaries
2323
dfdToStringDescriptorType
24+
dfdToStringFlagsBit
25+
dfdToStringSampleDatatypeQualifiersBit
2426
dfdToStringTransferFunction
2527
dfdToStringVendorID
2628
dfdToStringVersionNumber
29+
ktxBUImageFlagsBitString
2730
ktxTexture2_constructCopy

lib/internalexport_write_mingw.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ EXPORTS
2121
dfdToStringColorModel
2222
dfdToStringColorPrimaries
2323
dfdToStringDescriptorType
24+
dfdToStringFlagsBit
25+
dfdToStringSampleDatatypeQualifiersBit
2426
dfdToStringTransferFunction
2527
dfdToStringVendorID
2628
dfdToStringVersionNumber
29+
ktxBUImageFlagsBitString
2730
ktxTexture2_constructCopy

tests/cts

Submodule cts updated 4526 files

tools/imageio/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set( PLUGIN_HEADERS
1616
add_library( imageio STATIC
1717
formatdesc.h
1818
image.hpp
19+
imagecodec.hpp
20+
imagespan.hpp
1921
imageinput.cc
2022
imageio.cc
2123
imageio.h

tools/imageio/formatdesc.h

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ struct FormatDescriptor {
5252
/// @internal
5353
/// @brief Basic descriptor.
5454
struct basicDescriptor {
55-
khr_df_model_e model: 8;
56-
khr_df_primaries_e primaries: 8;
57-
khr_df_transfer_e transfer: 8;
58-
khr_df_flags_e flags: 8;
55+
uint32_t colorModel: 8;
56+
uint32_t colorPrimaries: 8;
57+
uint32_t transferFunction: 8;
58+
uint32_t dataFlags: 8;
5959
uint32_t texelBlockDimension0: 8;
6060
uint32_t texelBlockDimension1: 8;
6161
uint32_t texelBlockDimension2: 8;
@@ -80,10 +80,10 @@ struct FormatDescriptor {
8080
khr_df_primaries_e p = KHR_DF_PRIMARIES_BT709,
8181
khr_df_model_e m = KHR_DF_MODEL_RGBSDA,
8282
khr_df_flags_e f = KHR_DF_FLAG_ALPHA_STRAIGHT) {
83-
model = m;
84-
primaries = p;
85-
transfer = t;
86-
flags = f;
83+
colorModel = m;
84+
colorPrimaries = p;
85+
transferFunction = t;
86+
dataFlags = f;
8787
texelBlockDimension0 = 0; // Uncompressed means only 1x1x1x1 blocks.
8888
texelBlockDimension1 = 0;
8989
texelBlockDimension2 = 0;
@@ -104,6 +104,19 @@ struct FormatDescriptor {
104104
bool operator!=(const basicDescriptor& rhs) const {
105105
return !(*this == rhs);
106106
}
107+
108+
khr_df_model_e model() const noexcept {
109+
return static_cast<khr_df_model_e>(colorModel);
110+
}
111+
khr_df_primaries_e primaries() const noexcept {
112+
return static_cast<khr_df_primaries_e>(colorPrimaries);
113+
}
114+
khr_df_transfer_e transfer() const noexcept {
115+
return static_cast<khr_df_transfer_e>(transferFunction);
116+
}
117+
khr_df_flags_e flags() const noexcept {
118+
return static_cast<khr_df_flags_e>(dataFlags);
119+
}
107120
} basic;
108121

109122
/// @internal
@@ -206,7 +219,7 @@ struct FormatDescriptor {
206219
qualifierLinear = (dataType & KHR_DF_SAMPLE_DATATYPE_LINEAR) != 0;
207220
if (oetf > KHR_DF_TRANSFER_LINEAR
208221
&& channelType == KHR_DF_CHANNEL_RGBSDA_ALPHA) {
209-
channelType |= KHR_DF_SAMPLE_DATATYPE_LINEAR;
222+
qualifierLinear = 1;
210223
}
211224

212225
union {
@@ -523,16 +536,16 @@ struct FormatDescriptor {
523536
}
524537

525538
khr_df_model_e model() const noexcept {
526-
return static_cast<khr_df_model_e>(basic.model);
539+
return basic.model();
527540
}
528541
khr_df_primaries_e primaries() const noexcept {
529-
return static_cast<khr_df_primaries_e>(basic.primaries);
542+
return basic.primaries();
530543
}
531544
khr_df_transfer_e transfer() const noexcept {
532-
return static_cast<khr_df_transfer_e>(basic.transfer);
545+
return basic.transfer();
533546
}
534547
khr_df_flags_e flags() const noexcept {
535-
return static_cast<khr_df_flags_e>(basic.flags);
548+
return basic.flags();
536549
}
537550
float oeGamma() const noexcept {
538551
return extended.oeGamma;
@@ -544,14 +557,14 @@ struct FormatDescriptor {
544557
return extended.iccProfile.profile;
545558
}
546559
void setModel(khr_df_model_e m) {
547-
basic.model = m;
560+
basic.colorModel = m;
548561
}
549562
void setPrimaries(khr_df_primaries_e p) {
550-
basic.primaries = p;
563+
basic.colorPrimaries = p;
551564
}
552565
void setTransfer(khr_df_transfer_e t) {
553-
khr_df_transfer_e oldOetf = basic.transfer;
554-
basic.transfer = t;
566+
khr_df_transfer_e oldOetf = transfer();
567+
basic.transferFunction = t;
555568
if ((oldOetf <= KHR_DF_TRANSFER_LINEAR) != (t <= KHR_DF_TRANSFER_LINEAR))
556569
{
557570
std::vector<sample>::iterator sit = samples.begin();
@@ -672,9 +685,11 @@ struct FormatDescriptor {
672685
samples.push_back(sample(s, channelBitLength,
673686
s * channelBitLength,
674687
sampleLower, sampleUpper,
675-
dt, basic.transfer, basic.model));
688+
dt,
689+
basic.transfer(),
690+
basic.model()));
676691
}
677-
if (basic.model == KHR_DF_MODEL_YUVSDA && channelCount == 2) {
692+
if (basic.model() == KHR_DF_MODEL_YUVSDA && channelCount == 2) {
678693
samples[1].channelType = KHR_DF_CHANNEL_YUVSDA_ALPHA;
679694
}
680695
extended.channelCount = channelCount;

0 commit comments

Comments
 (0)