Shader caches take 9.5 GB after a fresh preparation: half the program cache is the same SPIR-V twice (proposal: compress each stage, notes without zeros) #1649
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot#1649
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For a decision: a fresh preparation leaves 9.5 GB of shader caches (plus 1.1 GB of NVIDIA's own), which players with small drives notice. Half of
longshot_programs.binis the same SPIR-V stored twice, and the pipeline notes are 99% zeros. Every fix changes the cache format, so every player would prepare once more: that is the team's call, ideally with a release that changes the translator anyway. The proposal below is written, not implemented.Measured on existing caches only (no new runs), on Linux, RTX 4070 Ti: a fresh Most preparation of v3.0.0-rc.5-era main, then played
(its longshot_programs.bin the same size, 7,913,087,763 bytes, as fresh preparations of main
1cc59e37on 2026-11-18), and asecond folder prepared and played longer. Read with two read-only scripts over the files' records.
What a fresh Most preparation leaves in cache/ (9.5 GB) plus NVIDIA's GLCache (1.1 GB)
longshot_programs.bin
Layout (vk_progcache.cpp program_cache_save, format 1, uncompressed): a 16-byte file head, then records
[key u64][size u64][payload]; the payload is put_head (flags, answers, questions, workgroup, fallback words), the stagecount, and per stage: NVN and Vulkan stage, the SPIR-V (u64 count + words), c1 constants, Shader::Info as it lies in
memory (816 bytes, heap pointers included), then Info's lists.
By kind: graphics 44,511 records 5,894 MB; compute 9,927 records (4,128 programs, up to 64 texture variants) 984 MB; mesh
2,284 records 1,036 MB. SPIR-V by stage: vertex 1,690 MB (44,511), fragment 4,346 MB (46,795), compute 971 MB, task 242 MB,
mesh 515 MB.
Duplicate and dead data
By stage: vertex 975 MB of 1,690 (58%), fragment 2,376 of 4,346 (55%), task 241 of 242 (99%), mesh 385 of 515 (75%),
compute 0.7 of 971. Mostly across program keys (programs sharing a vertex or fragment shader: the seed's 33,369 vertex uses
are of 15,852 stages, its 34,681 fragment uses of 22,356; and the bone-input variants, which repeat the fragment stage).
36,263 blobs are stored once, 8,245 twice, 339 twenty times or more.
Their earlier copy is never read ("of two records of one variant, the later is the one kept").
over only when the translator stamp or kProgramCacheFormat changes, then holds everything again. No compaction exists.
preparations write different bytes for the same programs (sizes and keys match: the index's (key, size, kind) multiset is
identical across runs).
play's longshot_compute_variants.bin names the variants dispatched: 159 in game-rs and 276 in game-br, against 9,927 kept)
Compression (python zstandard 0.25, one thread, 3,038 sampled records compressed one at a time as program_cache_save
does with RX_VK_PROGRAM_CACHE_ZSTD=1): level 1 x3.8 (416 MB/s in, 1,202 MB/s out), level 3 x3.7 (314 / 1,102 MB/s),
level 9 x4.0, level 19 x5.0. The distinct blobs alone: x3.7 at level 3. As a stream (zstd CLI, 512 MB): x6.8 at -3,
x9.8 with --long=27, decompressing at 1.8 GB/s a thread: the variants of one program are near copies of each other.
Options
Proposed: A, then C. A has the best size for the least load-time risk: it keeps every reader's positional access (the
create path's light reads find a record's head and descriptors where they are; only complete_from, the whole-record read,
complete_graphics and program_cache_each decompress the stage they read), and the compressed bytes are fewer to read from
disk, which a cold start on an HDD or SATA SSD gains back. B adds most of its win again on top of A but needs a blob map
at save and references in four readers; do it after A, if wanted. C is independent and cheap in risk (0.84 GB).
A, in code (vk_progcache.cpp only, outside the translator stamp)
every player prepares again once; ship it with a release that changes the translator anyway).
[u64 words | 1 << 63][u64 stored bytes][zstd frame](level 1 or 3; a stagethat does not shrink stays plain, count without the bit). zstd is already linked (program_cache_payload).
as they are: they are in the translator stamp's ABI words).
test_program_cache_reader.py, test_program_cache_format.py, test_program_cache_index.py; a new one: a record with a
compressed stage read back whole, by the light read, by complete_from and by complete_graphics, byte for byte.
and changes six readers and five tests. Proposed, not implemented.
What an in-game check of A must confirm
A cold preparation finishes with the same counts (programs, pipelines, "0 not made"); the first start after it loads at
create (
programs are loaded when the game makes them (create)), plays Kokiri Forest and Hyrule Field with no draws leftout for programs that did not read (
program cache: ... did not readlines stay absent); a compute-heavy scene (the movieupscaler, the culling programs) shows no first-dispatch hitch beyond main's; and the cache folder's size.
Found while looking at Preparing shaders on 4-core / 8-16 GB PCs (worklist 3.2).
🤖 Generated with Claude Code
The same files on AMD, for the cross-vendor side of this. Windows 11, RX 9070 XT (driver 26.11.1), main
1055077d. The cache folder is our test install's, not a fresh Most preparation. Measured read-only, by sampling records in memory. No game runs were made for this.For C: zstd -3 on each note on its own, with no shared dictionary and no stream, took the 256 sampled notes from 6,948,864 bytes to 35,493. Over 32,623 notes that projects to about 4.5 MB of payload before any framing or index, about 0.88 GB less. That is close to the 1-4 MB estimated for run-length notes. Each note stays independent, so reading a note by position still works. On this AMD install the notes shrink about as much as on NVIDIA.
Not measured here: the duplicated SPIR-V (option B) and the per-stage compression (option A), so I have no AMD numbers for either. There is also no timing of the note reader or the cold open with compact notes.
🤖 Generated with Claude Code
Option B across game folders, measured: the same SPIR-V is stored again in every build, not only within one file.
Windows 11, RX 6700 XT. Two of a player's installs, prepared and played: stable v3.0.0 (program cache stamp
6cc34dcd…) and nightly-486 (stamp33f15f4a…). Different stamps, so today each keeps a whole cache of its own. Read-only, every record of both files, SPIR-V found by its magic and hashed (BLAKE2b-128):So for a player with stable and nightly (or test builds, or a pull request build), B is worth far more than within one file: each further build adds only the few programs whose translation changed, not ~7.5 GB.
I'd like to do B as a pack shared by every game folder, under #1759:
%LOCALAPPDATA%\Longshot\shaders\,$XDG_CACHE_HOME/longshot/shaders/on Linux), appended to, never rewritten; its index read once at the start.longshot_programs.binkeeps every record as now (heads, Info, lists, the order, the index), with each stage's SPIR-V replaced by a reference (hash, words, the pack's offset). The four readers that take SPIR-V (the whole read, the light read by position, complete_from/complete_graphics, program_cache_each) read it from the pack.@TrashPanda, are you already on A or B in
vk_progcache.cpp? If not, I'll start B-shared now and keep the pack's blob format open for A. If you'd rather do it together, or in another order, say so.🤖 Generated with Claude Code