KhronosGroup / KTX-Software

KTX (Khronos Texture) Library and Tools
Other
874 stars 229 forks source link

Inconsistent ktx2check and ktxinfo results #576

Closed donmccurdy closed 2 years ago

donmccurdy commented 2 years ago

I'm writing these KTX2 files with a new exporter, so it's very likely the files have some real issues. However, the errors I see from ktx2check do not seem to match what I think is happening, and ktxinfo is able to read the files including parts that ktx2check complains about, so I'm wondering if this might be a bug in the validation.

The easiest sample to start with is f32_5x1.ktx2:

$ ktx2check f32_5x1.ktx2

Issues in: f32_5x1.ktx2
    ERROR: DFD bytesPlane0 must be non-zero for non-supercompressed texture
    with VK_FORMAT_R32_SFLOAT.

However, ktxinfo reports that bytesPlane0 is non-zero, which is what I'd expected:

$ ktxinfo f32_5x1.ktx2

Header

identifier: «KTX 20»\r\n\x1A\n
vkFormat: VK_FORMAT_R32_SFLOAT
typeSize: 4
pixelWidth: 5
pixelHeight: 1
pixelDepth: 0
layerCount: 0
faceCount: 1
levelCount: 1
supercompressionScheme: KTX_SS_NONE
dataFormatDescriptor.byteOffset: 0x68
dataFormatDescriptor.byteLength: 44
keyValueData.byteOffset: 0x94
keyValueData.byteLength: 32
supercompressionGlobalData.byteOffset: 0
supercompressionGlobalData.byteLength: 0

Level Index

Level0.byteOffset: 0xb4
Level0.byteLength: 20
Level0.uncompressedByteLength: 20

Data Format Descriptor

DFD total bytes: 44
BDB descriptor type 0x0000 vendor id = 0x00000
Descriptor block size 40 (1 samples) versionNumber = 0x0002
Flags 0x00 Xfer 01 Primaries 00 Model 001
Dimensions: 1,1,1,1
Plane bytes: 4,0,0,0,0,0,0,0
    Sample 0
Qualifiers d Channel 0x0 (R) Length 32 bits Offset 0
Position: 0,0,0,0
Lower 0xffffffff
Upper 0x00000001

Key/Value Data

KTXwriter: three.js 141dev

The other files report the same issue, as well as others like Level 0 byteLength or uncompressedByteLength does not match expected value. But ktxinfo reports the expected byteLength and uncompressedByteLength just fine. I'm using uncompressed formats, no supercompression involved.

Does this seem like a bug in a CLI tool, or are my files just totally bad? Thanks!

Samples:

ktx_samples.zip ktx_samples.zip

Code:

MarkCallow commented 2 years ago

Which ktx2check are you using, version 4, version 4.1-rc1 or are you building from master?

MarkCallow commented 2 years ago

Which ktx2check are you using,

Never mind. The problem is happening with the code in master. There seem to be 2 issues:

  1. Your DFD has primaries = 0. The comparator DFD used by ktx2check has primaries = 1 which causes a memcmp to fail leading to a deeper analysis.
  2. The deeper analysis is getting confused and giving an incorrect reason for the discrepancy.

For no. 1 ktx2check must only check that primaries is a valid DFD value. It must permit differences with the comparator.

No. 2 is just a silly coding error in the bytesPlane0 check.

MarkCallow commented 2 years ago

With the fix I just committed f32_5x1.ktx2 passes validation. The other 2 files fail for reasons that appear to be genuine problems.

donmccurdy commented 2 years ago

Thanks @MarkCallow, appreciate the help! I'll work on the remaining issues. I didn't realize there were so many sample .ktx2 files in this repository, those should be helpful for me in testing output as well.

MarkCallow commented 2 years ago

@donmccurdy heads up. I introduced a bug in ktx2check just before I fixed the issues discussed here. The bug affects validation of UASTC files. See PR #585 for details and watch for it landing. I also found that the exit code could be wrong when validating multiple files and there are valid files after the broken one(s). This too is fixed in PR #585.