Supercompression is a second layer of compression over the texture data, which may itself be block-compressed. It shrinks files for storage and download; a loader undoes it before handing the data to the graphics card. Each mipmap level is supercompressed on its own, so levels can be streamed and read in any order.
Schemes
| supercompressionScheme | Scheme | Global data |
|---|---|---|
| 0 | None | None |
| 1 | BasisLZ: Basis Universal ETC1S data | Yes (below) |
| 2 | Zstandard (RFC 8478) | None |
| 3 | zlib (RFC 1950, with Deflate, RFC 1951) | None |
4 to 0xFFFF | Reserved for Khronos | |
0x10000 to 0x1FFFF | Registered vendor schemes; 0x10000 is registered to Asobo | Vendor-defined |
0x20000 and above | Reserved, not to be used |
Zstandard and zlib
- Each level’s
byteLengthbytes are one Zstandard frame or one zlib stream; it expands touncompressedByteLengthbytes laid out as an uncompressed level. vkFormatand the data format descriptor describe the data before compression.- There is no padding before supercompressed levels.
- UASTC data is usually supercompressed with Zstandard.
BasisLZ
BasisLZ holds ETC1S texture data from Basis Universal. vkFormat is 0, and
the data format descriptor has the ETC1S colour model. ETC1S has no alpha, so each image
is one slice of colour and, optionally, a second slice that carries alpha. A loader
decodes the slices and transcodes them to a block format the graphics card supports.
Each level’s uncompressedByteLength is 0.
The shared codebooks and tables are in the supercompression global data, at
sgdByteOffset, aligned to 8 bytes:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 2 | endpointCount | Number of endpoints in the codebook. |
| 2 | 2 | selectorCount | Number of selectors in the codebook. |
| 4 | 4 | endpointsByteLength | Bytes of compressed endpoint data. |
| 8 | 4 | selectorsByteLength | Bytes of compressed selector data. |
| 12 | 4 | tablesByteLength | Bytes of the Huffman tables. |
| 16 | 4 | extendedByteLength | Bytes of extended data; 0 for ETC1S. |
| 20 | 20 × imageCount | imageDescs | One descriptor per image (below). |
| … | endpointsByteLength | endpointsData | The endpoint codebook. |
| … | selectorsByteLength | selectorsData | The selector codebook. |
| … | tablesByteLength | tablesData | The Huffman tables. |
| … | extendedByteLength | extendedData | Extended data, if any. |
imageCount is the number of images in all levels together:
max(layerCount, 1) × faceCount times the sum over the levels of each level’s
depth. The descriptors run through the levels from level 0, and within a level through
layers, faces and slices.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | imageFlags | 0x02 isPFrame: the image is coded relative to the previous one in an animation. Other images are I-frames. |
| 4 | 4 | rgbSliceByteOffset | Offset of the colour slice from the start of the level’s data. |
| 8 | 4 | rgbSliceByteLength | Its length. |
| 12 | 4 | alphaSliceByteOffset | Offset of the alpha slice; 0 when there is none. |
| 16 | 4 | alphaSliceByteLength | Its length; 0 when there is none. |
The bit-level format of the codebooks, tables and slices is defined by the Basis Universal ETC1S specification, not by KTX, and is not covered here.