MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / validateDfd

Method validateDfd

tools/ktx2check/ktx2check.cpp:1503–1782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1501}
1502
1503void
1504ktxValidator::validateDfd(validationContext& ctx)
1505{
1506 if (ctx.header.dataFormatDescriptor.byteLength == 0)
1507 return;
1508
1509 // We are right after the levelIndex. We've already checked that
1510 // header.dataFormatDescriptor.byteOffset points to this location.
1511 ctx.pActualDfd = new uint32_t[ctx.header.dataFormatDescriptor.byteLength
1512 / sizeof(uint32_t)];
1513 ctx.inp->read((char *)ctx.pActualDfd,
1514 ctx.header.dataFormatDescriptor.byteLength);
1515 if (ctx.inp->fail())
1516 addIssue(logger::eFatal, IOError.FileRead, strerror(errno));
1517 else if (ctx.inp->eof())
1518 addIssue(logger::eFatal, IOError.UnexpectedEOF);
1519
1520 if (ctx.header.dataFormatDescriptor.byteLength != *ctx.pActualDfd)
1521 addIssue(logger::eError, DFD.SizeMismatch);
1522
1523 uint32_t* bdb = ctx.pActualDfd + 1; // Basic descriptor block.
1524
1525 uint32_t xferFunc;
1526 if ((xferFunc = KHR_DFDVAL(bdb, TRANSFER)) != KHR_DF_TRANSFER_SRGB
1527 && xferFunc != KHR_DF_TRANSFER_LINEAR)
1528 addIssue(logger::eError, DFD.InvalidTransferFunction);
1529
1530 bool analyze = false;
1531 uint32_t numSamples = KHR_DFDSAMPLECOUNT(bdb);
1532 switch (ctx.header.supercompressionScheme) {
1533 case KTX_SS_NONE:
1534 case KTX_SS_ZSTD:
1535 case KTX_SS_ZLIB:
1536 if (ctx.header.vkFormat != VK_FORMAT_UNDEFINED) {
1537 if (ctx.header.supercompressionScheme == KTX_SS_NONE) {
1538 // Do a simple comparison with the expected DFD.
1539 analyze = memcmp(ctx.pActualDfd, ctx.pDfd4Format,
1540 *ctx.pDfd4Format);
1541 } else {
1542 // Compare up to BYTESPLANE.
1543 analyze = memcmp(ctx.pActualDfd, ctx.pDfd4Format,
1544 KHR_DF_WORD_BYTESPLANE0 * 4);
1545 // Check for unsized.
1546 if (bdb[KHR_DF_WORD_BYTESPLANE0] == 0)
1547 addIssue(logger::eWarning, DFD.Unsized);
1548 // Compare the sample information.
1549 if (!analyze) {
1550 analyze = memcmp(&ctx.pActualDfd[KHR_DF_WORD_SAMPLESTART+1],
1551 &ctx.pDfd4Format[KHR_DF_WORD_SAMPLESTART+1],
1552 numSamples * KHR_DF_WORD_SAMPLEWORDS);
1553 }
1554 }
1555 } else {
1556 if (KHR_DFDVAL(bdb, MODEL) == KHR_DF_MODEL_UASTC) {
1557 // Validate UASTC
1558 if (numSamples == 0)
1559 addIssue(logger::eError, DFD.ZeroSamples, "UASTC");
1560 if (numSamples > 1)

Callers

nothing calls this directly

Calls 5

vkFormatStringFunction · 0.85
interpretDFDFunction · 0.85
readMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected