GPU: cache parsed shader resource metadata across runs (shader-meta.bin) #2614

Open
github-bot wants to merge 2 commits from github-bot/gh-2614 into main AGit
Owner

@⁠Bebrik229 on GitHub · 2026-11-25 16:52 UTC · original
Bebrik229:gpu/shader-meta-cache → main · +524 −21 · 4 files · 2 commits · open

Summary

Persists each translated shader container's parsed UsedResource table alongside the pipeline cache (shader-meta.bin) so warm runs avoid repeating Container::parse and zlib XBCH decompression (native_programs) on every shader cache hit.

  • New module crates/victory-gpu/src/shader_meta.rs:
    • Loads shader-meta.bin (VSM1 v1 binary store keyed by the container's 32-byte BLAKE3 hash) in library::use_pipeline_cache.
    • get_or_compute checks a RwLock<MetaStore> under read lock first, drops the lock before computing on a miss, and marks the store dirty on insertion.
    • save short-circuits lock-free/read-only when clean, serializes outside the store lock on dirty state, and writes atomically via shader-meta.bin.tmp-<pid>-<seq> + rename from library::save.
    • Losslessly encodes/decodes all ResourceType (Srv, Sampler, Cbv, Uav, Other(u8)) and RootType (Constants, Descriptor, Table, ImmediateSampler, ResourceHeap, SamplerHeap, Other(u32)) variants, rejecting truncated/corrupt/trailing data.
  • No cache invalidation: shader_cache.rs and crates/victory-shader are untouched, so all existing cached shader translations remain valid hits on the next launch (shader-meta.bin populates automatically on the first run and hits from the second run onward).
  • crates/victory-gpu/src/pipeline.rs: stores full_hash: [u8; 32] on Shader (avoiding double hashing in shader()) and resolves used in with_resources via shader_meta::get_or_compute.

Verification

  • cargo test -p victory-gpu --lib shader_meta -- --test-threads=1 — 2 passed (encode_decode_roundtrip_and_corruption, store_persists_to_disk_and_skips_recompute)
  • cargo test -p victory-gpu --lib pipeline -- --test-threads=1 — 16 passed, 0 failed
  • cargo clippy -p victory-gpu --lib --tests -- -D warnings — clean (0 warnings)
  • cargo xtask policy — asset policy: 185 files ok
**@⁠Bebrik229** on GitHub · 2026-11-25 16:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2614) `Bebrik229:gpu/shader-meta-cache` → `main` · +524 −21 · 4 files · 2 commits · open ## Summary Persists each translated shader container's parsed `UsedResource` table alongside the pipeline cache (`shader-meta.bin`) so warm runs avoid repeating `Container::parse` and zlib `XBCH` decompression (`native_programs`) on every shader cache hit. - **New module `crates/victory-gpu/src/shader_meta.rs`**: - Loads `shader-meta.bin` (`VSM1` v1 binary store keyed by the container's 32-byte BLAKE3 hash) in `library::use_pipeline_cache`. - `get_or_compute` checks a `RwLock<MetaStore>` under read lock first, drops the lock before computing on a miss, and marks the store dirty on insertion. - `save` short-circuits lock-free/read-only when clean, serializes outside the store lock on dirty state, and writes atomically via `shader-meta.bin.tmp-<pid>-<seq>` + rename from `library::save`. - Losslessly encodes/decodes all `ResourceType` (`Srv`, `Sampler`, `Cbv`, `Uav`, `Other(u8)`) and `RootType` (`Constants`, `Descriptor`, `Table`, `ImmediateSampler`, `ResourceHeap`, `SamplerHeap`, `Other(u32)`) variants, rejecting truncated/corrupt/trailing data. - **No cache invalidation**: `shader_cache.rs` and `crates/victory-shader` are untouched, so all existing cached shader translations remain valid hits on the next launch (`shader-meta.bin` populates automatically on the first run and hits from the second run onward). - **`crates/victory-gpu/src/pipeline.rs`**: stores `full_hash: [u8; 32]` on `Shader` (avoiding double hashing in `shader()`) and resolves `used` in `with_resources` via `shader_meta::get_or_compute`. ## Verification - `cargo test -p victory-gpu --lib shader_meta -- --test-threads=1` — 2 passed (`encode_decode_roundtrip_and_corruption`, `store_persists_to_disk_and_skips_recompute`) - `cargo test -p victory-gpu --lib pipeline -- --test-threads=1` — 16 passed, 0 failed - `cargo clippy -p victory-gpu --lib --tests -- -D warnings` — clean (0 warnings) - `cargo xtask policy` — `asset policy: 185 files ok`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:22 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:51 UTC · original

Reviewed (first half): carrying the full BLAKE3 alongside the 16-char display hash and passing it into translate() makes the metadata cache key collision-free. The SHADERS map key is now the full hash — consistent. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2614#issuecomment-7170101320) Reviewed (first half): carrying the full BLAKE3 alongside the 16-char display hash and passing it into `translate()` makes the metadata cache key collision-free. The SHADERS map key is now the full hash — consistent. CI green.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:16 UTC · original

Automated triage for the maintainers.

Merges cleanly. The idea (skip Container::parse / native_programs on warm runs) is plausible, but as written the store can go stale:

  • shader-meta.bin is keyed only by the container's BLAKE3 (shader_meta::get_or_compute). The shader cache next to it keys every entry on the build fingerprint (shader_cache::key: victory_shader::SOURCE_HASH plus its own encoding), so a translator change invalidates it. Here, a fix to native_programs or to how UsedResource is derived would keep serving the old resource lists from disk, silently, with no way to notice except deleting the file. Please key the store (or the file header) on the same fingerprint, e.g. victory_shader::SOURCE_HASH, and drop the file when it differs.
  • The description gives no measurement of what this saves on a warm run (time spent in with_resources before and after). A 488-line persistent cache wants a number showing it is worth having.

With the fingerprint keying and a measured gain this could be reconsidered.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2614#issuecomment-7176165326) <!-- victory-triage v1 head=8c42f1476eb848455ac364b651b001c34ef931ea verdict=needs-work at=2026-11-25T22:17:30Z --> Automated triage for the maintainers. Merges cleanly. The idea (skip `Container::parse` / `native_programs` on warm runs) is plausible, but as written the store can go stale: - `shader-meta.bin` is keyed only by the container's BLAKE3 (`shader_meta::get_or_compute`). The shader cache next to it keys every entry on the build fingerprint (`shader_cache::key`: `victory_shader::SOURCE_HASH` plus its own encoding), so a translator change invalidates it. Here, a fix to `native_programs` or to how `UsedResource` is derived would keep serving the old resource lists from disk, silently, with no way to notice except deleting the file. Please key the store (or the file header) on the same fingerprint, e.g. `victory_shader::SOURCE_HASH`, and drop the file when it differs. - The description gives no measurement of what this saves on a warm run (time spent in `with_resources` before and after). A 488-line persistent cache wants a number showing it is worth having. With the fingerprint keying and a measured gain this could be reconsidered. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2614/head:github-bot/gh-2614'
git switch 'github-bot/gh-2614'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2614'
git switch 'github-bot/gh-2614'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2614'
git switch 'github-bot/gh-2614'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2614'
git switch 'main'
git merge --squash 'github-bot/gh-2614'
git switch 'main'
git merge --ff-only 'github-bot/gh-2614'
git switch 'main'
git merge 'github-bot/gh-2614'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2614
No description provided.