Skip to content

Commit

Permalink
Use correct counter for indexing sample. (#739)
Browse files Browse the repository at this point in the history
Fixes #738.
  • Loading branch information
MarkCallow authored Jul 13, 2023
1 parent 682f456 commit 3153e94
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/dfdutils/interpretdfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
if (numSamples == 0)
return i_UNSUPPORTED_CHANNEL_TYPES;

uint32_t sampleCounter;
int determinedEndianness = 0;
enum InterpretDFDResult result = 0; /* Build this up incrementally. */

Expand All @@ -91,7 +90,7 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
/* we have the RGBA/ABGR ambiguity; we *probably* don't want the packed */
/* version in this case, and if hardware has to pack it and swizzle, */
/* that's up to the hardware to special-case. */
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
for (uint32_t sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
uint32_t offset = KHR_DFDSVAL(BDFDB, sampleCounter, BITOFFSET);
uint32_t length = KHR_DFDSVAL(BDFDB, sampleCounter, BITLENGTH) + 1;
if ((offset & 0x7U) || ((offset + length) & 0x7U)) {
Expand Down Expand Up @@ -119,15 +118,15 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
// an API we can support.
const bool isNormalized = isFloat ?
*(float*) (void*) &BDFDB[KHR_DF_WORD_SAMPLESTART +
KHR_DF_WORD_SAMPLEWORDS * sampleCounter +
KHR_DF_WORD_SAMPLEWORDS * i +
KHR_DF_SAMPLEWORD_SAMPLEUPPER] != 1.0f :
KHR_DFDSVAL(BDFDB, i, SAMPLEUPPER) != 1U;

hasSigned |= isSigned;
hasFloat |= isFloat;
// By our definition the normalizedness of a single bit channel (like in RGBA 5:5:5:1)
// is ambiguous. Ignore these during normalized checks.
if (KHR_DFDSVAL(BDFDB, sampleCounter, BITLENGTH) > 0)
if (KHR_DFDSVAL(BDFDB, i, BITLENGTH) > 0)
hasNormalized |= isNormalized;
}
result |= hasSigned ? i_SIGNED_FORMAT_BIT : 0;
Expand Down Expand Up @@ -172,13 +171,13 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
/* We only support samples at coordinate 0,0,0,0. */
/* (We could confirm this from texel_block_dimensions in 1.2, but */
/* the interpretation might change in later versions.) */
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
for (uint32_t sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
if (KHR_DFDSVAL(BDFDB, sampleCounter, SAMPLEPOSITION_ALL))
return i_UNSUPPORTED_MULTIPLE_SAMPLE_LOCATIONS;
}

/* For Depth/Stencil formats mixed channels are allowed */
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
for (uint32_t sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
switch (KHR_DFDSVAL(BDFDB, sampleCounter, CHANNELID)) {
case KHR_DF_CHANNEL_RGBSDA_DEPTH:
case KHR_DF_CHANNEL_RGBSDA_STENCIL:
Expand Down Expand Up @@ -228,7 +227,7 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
uint32_t currentByteOffset = 0;
uint32_t currentBitLength = 0;
*wordBytes = (BDFDB[KHR_DF_WORD_BYTESPLANE0] & 0xFFU);
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
for (uint32_t sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
uint32_t sampleBitOffset = KHR_DFDSVAL(BDFDB, sampleCounter, BITOFFSET);
uint32_t sampleByteOffset = sampleBitOffset >> 3U;
/* The sample bitLength field stores the bit length - 1. */
Expand Down Expand Up @@ -315,7 +314,7 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
uint32_t currentChannel = ~0U; /* Don't start matched. */
uint32_t currentByteOffset = 0;
uint32_t currentByteLength = 0;
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
for (uint32_t sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
uint32_t sampleByteOffset = KHR_DFDSVAL(BDFDB, sampleCounter, BITOFFSET) >> 3U;
uint32_t sampleByteLength = (KHR_DFDSVAL(BDFDB, sampleCounter, BITLENGTH) + 1) >> 3U;
uint32_t sampleChannel = KHR_DFDSVAL(BDFDB, sampleCounter, CHANNELID);
Expand Down

0 comments on commit 3153e94

Please sign in to comment.