Very large levels

One game's first 3D frame uploads two 1365x1365 ASTC 4x4 arrays of 90 layers: their first levels are 168 MB of BC7 blocks each, 447 megatexels with their mips. Its blocks are the encoder's worst kind, most of them trying every mode, and the fast build took a Radeon 890M 92 ms a strip of two layers: the frame took 10.1 seconds. (In one submission it had reset the GPU, amdgpu's job timeout being 2 seconds: the upload's wait once 256 thousand blocks are queued, above, keeps every submission well under that.) The rules above count one layer (1.9 megatexels), and the levels were past what the cache took, so every run paid it again. A level held as BC7 at load (astc_textures=3: one made BC7 between frames goes up as RGBA8 first, above) of the very large size or more, every layer of a 2D array and every slice of a 3D level counted, now goes another way. The size starts at astc_quick_mtexels megatexels (8 by default: a 4096x2048 level, or two layers of 2048x2048) and then follows the encoder's speed here (The size from the encoder's time):

On the 890M in that game's first 3D scene (the 3D picture is wrong there for other reasons, and its frame rate climbs over the scene's first 40 seconds as the game streams):

BeforeGPU background (first run)Cache hit (next run)CPU background, 2 threads (first run)
The frame that uploads the arrays10,123 ms417 ms, then 471under 250 ms (the hits: 56 ms of the GPU thread, the pieces in the page cache)422 ms, then 474
Frames a second, 37 to 87 s after the scene starts15.415.015.913.8
Frames a second, 87 to 137 s after16.015.217.914.0
The backgroundnone133 s for 1890 pieces, 2 to 10 ms of the GPU a frame, 13 s of GPU time in allnone62% done after 230 s, 416 s of CPU time

The GPU had room: before, it was busy 27 ms of each 57 ms frame, and a piece of the background made that 36. The frame rates' differences are within what runs vary by: runs without any background gave 15.4 to 17.9 in the same windows. Copying each piece into the texture as well (the build after these runs) left the background's cost a frame and its length (138 s) the same. The CPU column is the worker threads the background once had as well, which ran the CPU decoder and the encoder's body at idle priority. The game was run capped to four CPUs (a cgroup quota of 400%), as all our test runs are: its own threads took 2 to 2.3 of them in that scene, so even two workers used up the cap and held the game back, and six brought it down to 3 to 6 frames a second. Without such a cap the cost stays: on that game's blocks a Zen 5 core encodes 0.7 megatexels a second, so the two arrays take 10 minutes of CPU time where the GPU spends 13 seconds. The background is the GPU's alone now; the CPU decoder and encoder are only the tests' references (tests/support/astc.c, tests/glsl/bc7_cpu.cpp).

Why 8 megatexels: at that game's rate (25 ns a texel, most blocks trying every mode), the fast build of a level under it costs the frame at most about 200 ms on the 890M, and a tenth of that on blocks mode 6 holds (an albedo map); a game has many 2048x2048 levels (4 megatexels), which keep the fast build and the whole level's record of the cache, records earlier runs made included. Each quick level shows the quick build until the background reaches its pieces, one a frame, so a lower bound (4 takes those in) trades those levels' first frames' hitches for their quick blocks a while longer. That game's arrays are past either bound: their levels of 160, 40 and 10 megatexels go quick, the next (2.5) takes the fast build. A level between 8 megatexels and VK_BC7_CAPTURE_BYTES that earlier runs cached whole is encoded quickly once more, and its pieces stored, as its old record is not the pieces'.

The pieces of the two arrays' quick levels are 1890, 450 MB of blocks: they stay in the cache while its bound and the other levels' uses leave them room.

The quick build on Amberlith's astcimage pictureGradientsEdgesNoiseAlpha
PSNR, against mode 6 alone42.7 dB (43.2)23.1 (26.2)24.7 (25.2)32.4 (40.0)

The size from the encoder's time

The stall a very large level saves is the fast build's time over it, and that time is the GPU's: 25 ns a texel on the Radeon 890M above, 65 to 1400 megatexels a second on a GeForce RTX 2080 by the blocks (a game's normal maps to its albedo). So astc_quick_mtexels stands for a time, what that many megatexels take the 890M (8: 0.21 s), and the size is the one this GPU encodes in that time (gpu/texture/astc_bc.h's snx_astc_quick_texels): the setting's own until the fast build has been timed over as many texels, then that time over the cost a texel measured. Every transcode of the fast build (its two passes) of a megatexel or more goes between a pair of timestamps on the graphics queue, each after all the work before it (astc.c's bc7_time_begin, 32 pairs at once, the rest untimed), and each pair's time goes into the sums once its submission is done (vk_astc_frame_done). The sums are of the game's own blocks, so the cost is theirs. A smaller dispatch is timed not: its time is the latency of its slowest blocks more than the encoder's throughput, which is what a very large level's strips cost (SNX_ASTC_QUICK_TIMED_TEXELS, with the numbers that measured it). The levels encoded between frames go in strips of 32768 blocks at most, half a megatexel, so a game whose ASTC textures are made BC7 between frames times none, and its size stays the setting's: only the levels held as BC7 at load are ever very large. A queue that writes no timestamps keeps the setting's size, and the log says why. The log says the size once it comes from the time measured (with the cost a texel, the megatexels timed and the time the setting stands for), and with the stats of every 600 presents where anything was timed or a texture is held as BC7 at load, what the size is and where it came from. On an RX 6700 XT (RADV) the fast build of random blocks of every mode took 4.5 ns a texel in a 1024x1024 level and 5.1 in a 1536x768 one (the tests below), so 8 is about 40 megatexels there; lavapipe took 27 to 41 ns, so 8 is 5 to 7 there.


Made from docs/layers/gpu/astc.md at 69237645142c. GPL-3.0-or-later.