Skip to content

Commit

Permalink
Merge ktx compare to main (#868)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
aqnuep authored Mar 27, 2024
1 parent 39a8213 commit 6fcd95a
Show file tree
Hide file tree
Showing 27 changed files with 4,895 additions and 114 deletions.
1 change: 1 addition & 0 deletions cmake/docs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function( CreateDocTools )
doxygen_add_docs(
tools.doc
tools/ktx/ktx_main.cpp
tools/ktx/command_compare.cpp
tools/ktx/command_create.cpp
tools/ktx/command_encode.cpp
tools/ktx/command_extract.cpp
Expand Down
13 changes: 13 additions & 0 deletions lib/dfdutils/createdfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,19 @@ uint32_t *createDFDDepthStencil(int depthBits,
uint32_t *DFD = 0;
DFD = writeHeader((depthBits > 0) + (stencilBits > 0),
sizeBytes, s_UNORM, i_NON_COLOR);

/* Handle the special case of D24_UNORM_S8_UINT where the order of the
channels is flipped by putting stencil in the LSBs. */
if (depthBits == 24 && stencilBits == 8) {
writeSample(DFD, 0, KHR_DF_CHANNEL_RGBSDA_STENCIL,
8, 0,
1, 1, s_UINT);
writeSample(DFD, 1, KHR_DF_CHANNEL_RGBSDA_DEPTH,
24, 8,
1, 1, s_UNORM);
return DFD;
}

if (depthBits == 32) {
writeSample(DFD, 0, KHR_DF_CHANNEL_RGBSDA_DEPTH,
32, 0,
Expand Down
7 changes: 6 additions & 1 deletion lib/dfdutils/dfd2vk.inl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ if (KHR_DFDVAL(dfd + 1, MODEL) == KHR_DF_MODEL_RGBSDA || KHR_DFDVAL(dfd + 1, MOD
}
}
if (KHR_DFDSVAL((dfd + 1), 0, CHANNELID) == KHR_DF_CHANNEL_RGBSDA_STENCIL) {
return VK_FORMAT_S8_UINT;
if (KHR_DFDSAMPLECOUNT((dfd + 1)) == 1) {
return VK_FORMAT_S8_UINT;
} else {
// The KTX 2.0 specification defines D24_UNORM_S8_UINT with S8 in the LSBs
return VK_FORMAT_D24_UNORM_S8_UINT;
}
}

r = interpretDFD(dfd, &R, &G, &B, &A, &wordBytes);
Expand Down
7 changes: 6 additions & 1 deletion lib/dfdutils/makedfd2vk.pl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ sub checkSuffices {
}
}
if (KHR_DFDSVAL((dfd + 1), 0, CHANNELID) == KHR_DF_CHANNEL_RGBSDA_STENCIL) {
return VK_FORMAT_S8_UINT;
if (KHR_DFDSAMPLECOUNT((dfd + 1)) == 1) {
return VK_FORMAT_S8_UINT;
} else {
// The KTX 2.0 specification defines D24_UNORM_S8_UINT with S8 in the LSBs
return VK_FORMAT_D24_UNORM_S8_UINT;
}
}
r = interpretDFD(dfd, &R, &G, &B, &A, &wordBytes);
Expand Down
6 changes: 3 additions & 3 deletions lib/dfdutils/printdfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const char* dfdToStringColorModel(khr_df_model_e value) {
return NULL;
}

const char* dfdToStringSampleDatatypeQualifiers(uint32_t bit_index, bool bit_value) {
const char* dfdToStringSampleDatatypeQualifiersBit(uint32_t bit_index, bool bit_value) {
if (!bit_value)
return NULL;

Expand Down Expand Up @@ -782,7 +782,7 @@ void printDFD(uint32_t *DFD, uint32_t dataSize)

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

} else {
PRINT_INDENT(4, "\"qualifiers\":%s[%s", space, nl)
printFlagBitsJSON(LENGTH_OF_INDENT(5), nl, qualifiers, dfdToStringSampleDatatypeQualifiers);
printFlagBitsJSON(LENGTH_OF_INDENT(5), nl, qualifiers, dfdToStringSampleDatatypeQualifiersBit);
PRINT_INDENT(4, "],%s", nl)
}

Expand Down
3 changes: 3 additions & 0 deletions lib/internalexport_write.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ EXPORTS
dfdToStringColorModel
dfdToStringColorPrimaries
dfdToStringDescriptorType
dfdToStringFlagsBit
dfdToStringSampleDatatypeQualifiersBit
dfdToStringTransferFunction
dfdToStringVendorID
dfdToStringVersionNumber
ktxBUImageFlagsBitString
ktxTexture2_constructCopy
3 changes: 3 additions & 0 deletions lib/internalexport_write_mingw.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ EXPORTS
dfdToStringColorModel
dfdToStringColorPrimaries
dfdToStringDescriptorType
dfdToStringFlagsBit
dfdToStringSampleDatatypeQualifiersBit
dfdToStringTransferFunction
dfdToStringVendorID
dfdToStringVersionNumber
ktxBUImageFlagsBitString
ktxTexture2_constructCopy
2 changes: 1 addition & 1 deletion tests/cts
Submodule cts updated 4526 files
2 changes: 2 additions & 0 deletions tools/imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set( PLUGIN_HEADERS
add_library( imageio STATIC
formatdesc.h
image.hpp
imagecodec.hpp
imagespan.hpp
imageinput.cc
imageio.cc
imageio.h
Expand Down
53 changes: 34 additions & 19 deletions tools/imageio/formatdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ struct FormatDescriptor {
/// @internal
/// @brief Basic descriptor.
struct basicDescriptor {
khr_df_model_e model: 8;
khr_df_primaries_e primaries: 8;
khr_df_transfer_e transfer: 8;
khr_df_flags_e flags: 8;
uint32_t colorModel: 8;
uint32_t colorPrimaries: 8;
uint32_t transferFunction: 8;
uint32_t dataFlags: 8;
uint32_t texelBlockDimension0: 8;
uint32_t texelBlockDimension1: 8;
uint32_t texelBlockDimension2: 8;
Expand All @@ -80,10 +80,10 @@ struct FormatDescriptor {
khr_df_primaries_e p = KHR_DF_PRIMARIES_BT709,
khr_df_model_e m = KHR_DF_MODEL_RGBSDA,
khr_df_flags_e f = KHR_DF_FLAG_ALPHA_STRAIGHT) {
model = m;
primaries = p;
transfer = t;
flags = f;
colorModel = m;
colorPrimaries = p;
transferFunction = t;
dataFlags = f;
texelBlockDimension0 = 0; // Uncompressed means only 1x1x1x1 blocks.
texelBlockDimension1 = 0;
texelBlockDimension2 = 0;
Expand All @@ -104,6 +104,19 @@ struct FormatDescriptor {
bool operator!=(const basicDescriptor& rhs) const {
return !(*this == rhs);
}

khr_df_model_e model() const noexcept {
return static_cast<khr_df_model_e>(colorModel);
}
khr_df_primaries_e primaries() const noexcept {
return static_cast<khr_df_primaries_e>(colorPrimaries);
}
khr_df_transfer_e transfer() const noexcept {
return static_cast<khr_df_transfer_e>(transferFunction);
}
khr_df_flags_e flags() const noexcept {
return static_cast<khr_df_flags_e>(dataFlags);
}
} basic;

/// @internal
Expand Down Expand Up @@ -206,7 +219,7 @@ struct FormatDescriptor {
qualifierLinear = (dataType & KHR_DF_SAMPLE_DATATYPE_LINEAR) != 0;
if (oetf > KHR_DF_TRANSFER_LINEAR
&& channelType == KHR_DF_CHANNEL_RGBSDA_ALPHA) {
channelType |= KHR_DF_SAMPLE_DATATYPE_LINEAR;
qualifierLinear = 1;
}

union {
Expand Down Expand Up @@ -523,16 +536,16 @@ struct FormatDescriptor {
}

khr_df_model_e model() const noexcept {
return static_cast<khr_df_model_e>(basic.model);
return basic.model();
}
khr_df_primaries_e primaries() const noexcept {
return static_cast<khr_df_primaries_e>(basic.primaries);
return basic.primaries();
}
khr_df_transfer_e transfer() const noexcept {
return static_cast<khr_df_transfer_e>(basic.transfer);
return basic.transfer();
}
khr_df_flags_e flags() const noexcept {
return static_cast<khr_df_flags_e>(basic.flags);
return basic.flags();
}
float oeGamma() const noexcept {
return extended.oeGamma;
Expand All @@ -544,14 +557,14 @@ struct FormatDescriptor {
return extended.iccProfile.profile;
}
void setModel(khr_df_model_e m) {
basic.model = m;
basic.colorModel = m;
}
void setPrimaries(khr_df_primaries_e p) {
basic.primaries = p;
basic.colorPrimaries = p;
}
void setTransfer(khr_df_transfer_e t) {
khr_df_transfer_e oldOetf = basic.transfer;
basic.transfer = t;
khr_df_transfer_e oldOetf = transfer();
basic.transferFunction = t;
if ((oldOetf <= KHR_DF_TRANSFER_LINEAR) != (t <= KHR_DF_TRANSFER_LINEAR))
{
std::vector<sample>::iterator sit = samples.begin();
Expand Down Expand Up @@ -672,9 +685,11 @@ struct FormatDescriptor {
samples.push_back(sample(s, channelBitLength,
s * channelBitLength,
sampleLower, sampleUpper,
dt, basic.transfer, basic.model));
dt,
basic.transfer(),
basic.model()));
}
if (basic.model == KHR_DF_MODEL_YUVSDA && channelCount == 2) {
if (basic.model() == KHR_DF_MODEL_YUVSDA && channelCount == 2) {
samples[1].channelType = KHR_DF_CHANNEL_YUVSDA_ALPHA;
}
extended.channelCount = channelCount;
Expand Down
Loading

0 comments on commit 6fcd95a

Please sign in to comment.