A level of VK_BC7_FAST_TEXELS or more takes the encoder's fast build, bc7_fast_spv (SNX_BC7_FAST 1): a block
whose mode 6 error is 256 or less (squared, summed over its 16 texels and 4 channels: 2 a channel as a root mean
square) keeps mode 6, and only the others try every mode, stopping at SNX_BC7_GOOD_ENOUGH as the full build does. A
level of VK_BC7_MODE6_TEXELS (8192x8192) or more takes mode 6 alone, bc7_mode6_spv (SNX_BC7_FAST 2): a game's
sparse texture of seven mapped 8192x8192 layers took the full encoder 14 seconds on a GeForce RTX 2080, which mode 6
alone encodes at 1200 megatexels a second. The build goes by the level's size, not the region's (vk_bc7_build), so a
level loaded in pieces, or made BC7 between frames, encodes each block as its whole upload does. Each build's
pipeline is made the first time a level asks for it. Both rules count a layer, as a sparse texture's layers are loaded
one at a time. A level held as BC7 at load that is not sparse and has astc_quick_mtexels megatexels or more, all
its layers counted, takes the quick build instead and the fast build later (Very large levels).
Mode 6 alone holds gradients but not edges, a second plane or luminance apart from alpha; the threshold keeps most of the full build's quality. PSNR over RGBA and the worst channel error:
| Content | Full | Fast build | Mode 6 alone |
|---|---|---|---|
The picture below: gradients, edges, noise, alpha (bc7_glsl) | 51.1, 49.0, 29.0, 48.0 | 43.4, 46.8, 29.0, 47.7 | 43.2, 26.2, 25.2, 40.0 |
| Random ASTC 4x4, 6x6, 8x8, 12x12 blocks, 256x256 decoded (CPU model) | 48.58, 42.96, 46.23, 44.45 | 48.56, 42.92, 46.19, 44.39 | not measured |
| One game's ASTC 6x6 textures, 25 (fuddlesworth, RTX 2080) | 53.8 dB / 50 | 50.7 dB / 50 | 46.5 dB / 147 |
| astcenc's 4x4, 8x8, 12x12 encodings of 7 of them (same) | 46.6, 47.6, 46.4 | 45.9, 46.7, 45.7 | 32.9, 36.2, 38.0 |
On the random blocks 1.3 to 5.9% of the fast build's blocks differ from the full build's, and 90 to 98% of them are mode 6.
VK_BC7_FAST_TEXELS is 0: every level takes the fast build. The full build had most of a game's textures, those under
2048x2048, and a batch of them held a frame for seconds. On an RX 6700 XT (RADV), a level of random 8x8 blocks decoded
and encoded (snx-test-astc-vulkan --bench, two interleaved rounds of four runs after the first; a -O0 test build,
the time the GPU's):
| Level | Full build | Fast build |
|---|---|---|
| 4096x4096 | 103 to 107 ms, 9.8 to 10.2 million BC7 blocks a second | 76 to 80 ms, 13.1 to 13.8 million |
| 2040x2040 | 23.5 to 24.3 ms, 10.7 to 11.1 million | 17.5 to 18.2 ms, 14.3 to 14.8 million |
Random blocks are the fast build's worst case: the blocks that try every mode hold up the invocations beside them. On a GeForce RTX 2080 an 8192x8192 level of random 8x8 blocks decoded in 15 ms and encoded in 860 ms with every mode and in 48 ms with mode 6 alone. Beside a running game, a 4096x4096 level took (decoding included):
| Content | Mode 6 alone | Fast build | Full build (2040x2040, scaled) |
|---|---|---|---|
| One game's ASTC 6x6 albedo | 7 to 11 ms | 12 to 14 ms | 190 ms |
| One game's ASTC 6x6 packed masks (the worst of its textures tried) | 7 to 8 ms | 85 to 88 ms | 250 ms |
| astcenc 8x8 normal map | not measured | 256 to 267 ms | not measured |
| Random 8x8 blocks | 21 to 29 ms | 189 to 196 ms | 260 ms |
The same ASTC bytes always become the same BC7 blocks, and the memory budget's trim evicts textures a game uses again:
each came back through the decoder and the encoder (one game encoded 6,000 to 14,000 levels in a 150 second run, each
3 to 5 ms of an RTX 2080). So the blocks of whole levels encoded are kept in memory while the game runs
(gpu/vk/bc7_cache.c): the levels it uses most, up to a bound. Nothing of it is on disk, and every run starts with it
empty. pipeline.c starts it where ASTC textures are held as BC7 (vk_astc_bc7).
vk_hash128) of the level's guest bytes, as the CPU has them, and the words that place its
blocks in them (block linear or pitch, the GOB block's height and depth, GOBs across, the row's bytes and rows, the
layers: texture.c's astc_content), then of that hash with the level's size, slices or layers, footprint, sRGB
decode mode, the encoder's build and VK_BC7_ENCODER_VERSION (vk_bc7_key). A level of which the GPU holds any byte
(an engine's result, memory/own.c) is not keyed, nor one the page table does not map whole, nor a region, nor a
sparse texture's (only its bound strips are decoded).vk_astc_upload with the key): a hit copies the level's blocks from the cache into staging, on
the recording thread where the frame's commands go through it, and one copy writes the whole level, every layer or
slice, into the image: no decode, no encode. A miss encodes as before and also copies each strip's blocks
into their place in the frame's readback ring (vk_stage_back), with a barrier to the host after the last strip.texture.c's later_encode): the RGBA8 upload keeps each level's key (Surf.bc7.key), and a
level the cache has is copied from it into the BC7 image, counted a sixteenth of its blocks against the frame's
VK_BC7_LATER_BLOCKS; a level the encoder makes whole is copied from the BC7 image into the readback ring
(vk_bc7_capture_level). A texture whose bytes change in pieces loses its keys until it loads whole again.cmd.c's landing (vk_astc_frame_done) gives the blocks to the cache,
before the frame's ring is reused. The GPU thread never waits for them. Blocks on their way are bounded to
VK_BC7_CAPTURE_BYTES (32 MiB), which bounds the ring's growth and is the largest whole level the cache takes (a
4096x4096 level is 16 MiB). A very large level straight to BC7 goes in pieces instead (below), and any other larger
level is encoded each time (from 8192x8192, it is mode 6 alone).vk_mem_release_run), the blocks of every level
the last two presents did not use are freed, their counts kept.RGBA8 levels are not cached: their decode is the cheap part (about 1 ms a 4096x4096 level on the RTX 2080), and a cached one would be four times the bytes to hold and copy.
Made from docs/layers/gpu/astc.md at 69237645142c. GPL-3.0-or-later.