mirror of
https://github.com/morluto/rea.git
synced 2026-11-24 21:28:41 +00:00
* feat(artifacts): report declared DDS, GLB, KTX and KTX2 headers and regions Recognize DDS (including the DX10 extension), GLB, KTX 1.1 and KTX 2.0 by their header signatures and inventory them as containers. The root format metadata carries the declared header facts. Each declared byte region is a member that is hashed, classified and extractable: the DDS payload; GLB JSON and BIN chunks and BIN-stored images; KTX key/value data and mip levels; and KTX2 DFD, KVD, SGD and levels. Nothing is decoded. A DDS payload is checked against the size derived from its dimensions, mips, faces, layers and block size. Disagreeing extents are reported in extent_check with unknown coverage rather than refused, and regions past the end of the file are dropped, not clipped. Structural header faults refuse as malformed input with the format and offset. Part of #14155 * fix(gpu-assets): bound GLB chunks and keep unexamined regions unknown - Stop the GLB chunk walk at 1,024 chunks with unknown coverage. - Refuse a GLB chunk that crosses the declared length, or a chunk table that stops short of a physically present declared end, as malformed. - Report coverage unknown when GLB images were not all listed: past the image allowance, an unparsed JSON chunk, or an unresolved bufferView. - Leave the DDS payload size unknown when rows are padded to a declared pitch or more than 32 mip levels are declared, instead of deriving it from different dimensions. * fix(gpu-assets): report GLB images in URI-backed buffers as external Only buffers[0] without a uri is the GLB BIN chunk. An image whose bufferView sits in a buffer with a uri, or an image named by uri, is stored outside the file; it was counted as an unresolved image and made coverage unknown. Such images are now counted in external_images and leave coverage complete; only views that resolve to no buffer stay unknown. * fix(gpu-assets): report KTX2 level-index failures at file offsets The 64-bit level-index fields were read from a buffer that starts at file offset 80, but an unsafe value reported its index-relative position. The reader now takes the buffer's file base and reports base plus position, so every failure offset is a file offset. * fix(gpu-assets): count a GLB image as external only for a URI string An image or buffer whose uri is present but not a string, and an image with neither a uri nor a bufferView, were counted in external_images and left coverage complete without an established source. Only a URI string now marks a source external; other sources stay unresolved and keep coverage unknown.
90 lines
4.8 KiB
Markdown
90 lines
4.8 KiB
Markdown
# GPU asset headers: DDS, GLB, KTX and KTX2
|
||
|
||
`inspect-artifact` and `extract-artifact` read the declared headers of four
|
||
GPU asset containers without decoding them. Each one is inventoried as a
|
||
container. Its root `format_metadata` holds the header facts, and each
|
||
declared byte region is a member that can be hashed, classified and
|
||
extracted. Texture, mesh and image payloads are never decoded,
|
||
decompressed or transcoded.
|
||
|
||
Detection reads the bytes, so the file name does not matter:
|
||
|
||
| Format | Signature | Specification |
|
||
| ------ | ------------------------------------------ | ------------------------------------------------------- |
|
||
| `dds` | `DDS ` then a DDS_HEADER whose size is 124 | Microsoft DDS_HEADER, DDS_PIXELFORMAT, DDS_HEADER_DXT10 |
|
||
| `glb` | `glTF`, container version 2 | glTF 2.0 "Binary glTF Layout" |
|
||
| `ktx` | `«KTX 11»` identifier | Khronos KTX 1.1 |
|
||
| `ktx2` | `«KTX 20»` identifier | Khronos KTX 2.0 |
|
||
|
||
## What each format reports
|
||
|
||
- **DDS**: flags, width, height, depth, pitch, mip count, pixel-format flags,
|
||
FourCC, RGB bit count and caps. When the FourCC is `DX10`, the root also
|
||
reports the DXGI format number and name, the resource dimension, misc flags
|
||
and the array size. The payload after the header is one region,
|
||
`payload.bin`. For block-compressed formats (BC1–BC7, DXT1–DXT5, ATI1/ATI2)
|
||
and common uncompressed formats, `expected_payload_bytes` is derived from
|
||
the dimensions, mips, cube faces, array layers and volume depth. Otherwise
|
||
it is null.
|
||
- **GLB**: version, declared length and the chunk table. The `asset.version`
|
||
and `asset.generator` fields come from the JSON chunk, along with the
|
||
length of every top-level array (`counts`, for example `meshes` or
|
||
`accessors`) and `extensionsUsed`. Regions are the JSON chunk, the BIN
|
||
chunk and each image stored in the BIN chunk through a `bufferView`, named
|
||
by its `mimeType` (`images/<n>.png`). An embedded image therefore gets its
|
||
own content hash. `external_images` counts images stored outside the GLB,
|
||
either named by a URI or held in a buffer that has a URI. These are not
|
||
regions of the file and do not make coverage unknown. An image whose
|
||
`bufferView` resolves to neither is not listed, and coverage is `unknown`.
|
||
- **KTX 1.1**: endianness, the GL type and format fields, dimensions, array
|
||
elements, faces, mip levels and key/value byte count. Regions are the
|
||
key/value data and one region per mip level. The level region holds the
|
||
bytes after that level's `imageSize` field, which is six padded faces for
|
||
a non-array cube map.
|
||
- **KTX2**: `vkFormat`, type size, dimensions, layer, face and level counts,
|
||
and the supercompression scheme (`none`, `BasisLZ`, `Zstandard`, `ZLIB`).
|
||
The root also reports the DFD, KVD and SGD extents and the level index
|
||
(offset, length and uncompressed length per level). Each non-empty extent
|
||
and each level is a region.
|
||
|
||
## Declared extents that disagree
|
||
|
||
`extent_check` is `consistent`, `truncated` or `trailing-bytes`. A
|
||
disagreement is reported as a fact, not a refusal:
|
||
|
||
- A truncated DDS keeps its partial `payload.bin` and reports
|
||
`payload_bytes` next to `expected_payload_bytes`.
|
||
- A GLB, KTX or KTX2 region that ends past the file is not listed. A region
|
||
is never clipped. A limitation names the region and the file end.
|
||
- Bytes after every declared region are counted in a limitation.
|
||
|
||
Coverage is `complete` only when `extent_check` is `consistent`.
|
||
|
||
A header that breaks its format's structure refuses with a malformed-input
|
||
error that names the format and offset. Examples are a DDS_PIXELFORMAT
|
||
whose size is not 32, a GLB whose first chunk is not JSON or whose chunk
|
||
length is not 4-byte aligned, a KTX endianness marker that is neither byte
|
||
order, and a level count above 32. The GLB JSON chunk is parsed for counts
|
||
only up to 16 MiB. A larger or invalid JSON chunk stays a region, and
|
||
`json_status` says why no counts were read.
|
||
|
||
## CLI
|
||
|
||
```sh
|
||
rea inspect-artifact Duck.glb --detail summary --json
|
||
rea extract-artifact texture.ktx2 --json
|
||
```
|
||
|
||
## Verification scope
|
||
|
||
Synthetic fixtures built from the specifications cover each format's header
|
||
facts, regions, a truncated case and a malformed case. Public files checked,
|
||
all `consistent`:
|
||
|
||
- KhronosGroup/glTF-Sample-Assets `Duck.glb`: two chunks and one 16,302-byte PNG image.
|
||
- KhronosGroup/KTX-Software `bc3_unorm_array_7.ktx`: seven 256x256 BC3 layers in 458,752 bytes.
|
||
- `kodim23.ktx2`: BasisLZ, with DFD, KVD, SGD and one level.
|
||
- ImHex-Patterns `dds.hexpat.dds`: DXT1 64x64, 2,048 payload bytes.
|
||
|
||
Ogg Opus, RIFF/XMA2, Bink 2 and Vulkan pipeline caches are not covered yet.
|