Introduction
KTX 2 is the second version of the Khronos
Group’s texture container, built around Vulkan. The texture format is a Vulkan
VkFormat number, and a Khronos data format descriptor spells out the exact
layout of every texel, so a reader does not need a table of graphics API constants.
Each mipmap level can be supercompressed on its own: with Zstandard or zlib for any
format, or with BasisLZ for Basis Universal ETC1S data, which a loader transcodes to
whatever block-compressed format the graphics card supports. This makes KTX 2 the
texture format of the glTF extension KHR_texture_basisu. Its media type is
image/ktx2.
Structure
The file is little-endian throughout. A fixed 80-byte header and index are followed by the level index, then the data format descriptor, the key and value data, any supercompression global data, and the mipmap levels, smallest first. The reference pages cover the header and level layout, the data format descriptor, the key and value data and supercompression; then how the levels and images are laid out, the Basis Universal data (ETC1S and UASTC) and the texture formats and how they are decoded.
0Identifier «KTX 20»12 bytes12Header format, size, counts, supercompression scheme36 bytes48Index offsets and lengths of the descriptor, key and value data, supercompression data32 bytes80Level index offset and lengths for each mipmap level24 bytes each…Descriptor, key and value data, supercompression datavaries…Mipmap levels smallest firstvaries
In the viewer
Drop a .ktx2 file on the page and the viewer shows every byte of it in the
tree: the header, the index, each level-index entry, the data format descriptor with each
of its samples, every key and value (the known keys with their meaning), the
supercompression global data, and each mip level with each of its images, padding
included. It checks the file as it reads: a descriptor that disagrees with
vkFormat, a level that is the wrong size, a section outside the file,
padding that is not zero.
It also draws the textures. Every image of every level (each array layer, cube face
and depth slice) can be opened as a picture, and the base level’s first images are shown
straight away. What is decoded is listed on the
texture formats page: uncompressed texels of
any layout, BC1 to BC7, ETC1, ETC2 and EAC, ASTC in every 2D block size and in its low
and high dynamic range forms, and Basis Universal ETC1S and UASTC. A level that is
Zstandard or ZLIB supercompressed is decompressed when it is needed, and can be opened as a
file of its own. The decoders give the same pixels as the Khronos ktx tool,
ARM’s astcenc, Ericsson’s ETC decoder and bcdec on their test data.
A KTX 2 image inside a glTF file (KHR_texture_basisu) is drawn in the
glTF viewer by the same decoders.
Not described
KTX 2 is documented by Khronos. These pages follow the 2.0 specification and the Data Format Specification 1.3, and the Basis Universal source for ETC1S and UASTC; the parts below are not covered yet.
Known, not yet covered
- Viewer: pictures of PVRTC and PVRTC2 data, of ASTC blocks of three dimensions, and of colour-difference (YCbCr) formats are not made: their layout is shown, with the bytes. PVRTC and ASTC 3D are public formats; YCbCr needs the conversion matrices and chroma siting of the descriptor.
- Viewer: the intermediate UASTC HDR 6x6 supercompression (scheme 4) is shown as bytes. A decompressed level over 512 MiB is not held whole, and one Zstandard or ZLIB level is decompressed from its start every time (it is not read in windows).
- Viewer: UASTC HDR 6x6 that is not intermediate is decoded as ASTC 6x6 HDR blocks, but no sample file was available to check that.
- Reference: the OpenGL, Direct3D and Metal format numbers that the
KTXglFormat,KTXdxgiFormat__andKTXmetalPixelFormatkeys hold are shown as numbers, without a name; extended descriptor blocks (additional planes and dimensions) and colour models added after version 1.3 are shown as bytes; theVkFormatof every value is named by the viewer but only the common ones are on the header page.
Unknown
- Reference: the intermediate UASTC HDR 6x6 coding and the vendor
supercompression schemes (
0x10000and above) are not documented where this site could read them.
Variants
- Khronos Texture 1 – OpenGL textures described by OpenGL constants, in either byte order
- Khronos Texture 2 – Vulkan textures with a data format descriptor and optional supercompression
Links
Software
- KTX-Software tools – Khronos command-line tools that create, check and convert KTX files (Windows, macOS, Linux)
- PVRTexTool – Imagination Technologies’ texture compression and viewing tool (Windows, macOS, Linux)
- Compressonator – AMD’s texture compression tool (Windows, Linux)
Developers
- libktx – Khronos library that reads and writes KTX 1 and KTX 2 (C)
- Basis Universal – encoder and transcoder for supercompressed KTX 2 (C++)
Reference
- KTX File Format Specification – the Khronos specification of KTX 2
- Khronos Data Format Specification – the descriptor that KTX 2 uses to describe texels