perf(pipeline): speed up cached pipeline loading while preserving cache reuse #481

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

@⁠ZerefDragnee1l on GitHub · 2026-12-06 01:24 UTC · original
ZerefDragnee1l:perf/cached-pipeline-load-speed → main · +2160 −547 · 6 files · 2 commits · open

Splits the cached pipeline loading and creation optimizations out of #408 onto current main (preserving #376 Store/WindowsIdentity scoping and zero cache invalidation).

Summary

  • Zero cache invalidation: shader_cache.rs and crates/larp-shader/src/** are untouched, and GraphicsState::describe_cached() is unit-tested to match the exact legacy describe() format byte-for-byte so existing on-disk PSO blobs and created-pipelines.bin keys stay 100% valid.
  • Parallel startup & warm-start sidecar (blobs.rs, created.rs, make.rs):
    • Overlaps Store disk index scanning (00..ff sharded RwLock<HashSet<[u8; 16]>> scanned across up to 8 threads), created-shaders.bin parallel BLAKE3 hashing, zero-copy created-pipelines.bin parsing (ListedRef), and quad-pipelines.txt loading.
    • Builds Pending keys in parallel and queues compute pipelines ahead of graphics pipelines in one batch.
    • Adds a self-validating blobs-index.bin sidecar (keyed by exe metadata, shader_replace::fingerprint, env toggles, and host caps + BLAKE3 footer) so warm runs skip queueing and translating already-cached non-compute graphics/mesh pipelines when their blobs are confirmed on disk. Whenever blobs-index.bin is absent, truncated, has a bad footer/digest, or carries a stale fingerprint (or when an entry's blob is missing from disk), startup fails open to an empty warm map and queues every pipeline normally.
    • Seeds DISK/NOTED dedup sets from startup catalog loading and removes redundant 10s sleep in preload_done() via blobs::flush().
  • Low-overhead blob & state hot paths (blobs.rs, host.rs, pipeline.rs, shader_replace.rs):
    • Zero-copy BlobBytes::Owned slices &bytes[HEADER..] directly without an extra Arc<[u8]> copy on warm loads (keeping BLAKE3 verification on by default; LARP_FAST_BLOB_READ=1 opt-in).
    • Pre-PSO blobs::pass_over_if_on_disk(&name) check skips building D3D12_GRAPHICS_PIPELINE_STATE_DESC, Stream, label strings, build_stages, and COM root signatures when warming cached graphics/mesh blobs.
    • Upgrades cached root signature & rect-GS maps to RwLock, shares cached Arc<Plan> on Translated, unifies gfx10::decode across store_flags(), caches of_builder spilled checks and HAS_HEAP, and avoids waking empty DONE / polling loops (DONE_WAITERS + DRAINED).
    • Reapplies concurrent waiter frame-budget & Queue::bump fixes and adds adaptive quiet window (400ms warm / 3s cold) before lifting menu input hold.

Verification

  • git diff --check -> clean
  • cargo check -p larp -> exited 0 (larp-gpu compiled with 0 warnings)
  • cargo test -p larp-gpu --lib pipeline -> 16 passed; 0 failed; 2 ignored (native_windows_compute_blob_dispatch and compare_listed_shader_resolution ignored by upstream #[ignore] attributes), including graphics_state_describe_cached_matches_legacy_format, warm_index_round_trip_and_fingerprint_mismatch, and caller-level fail-open test warm_index_load_and_flush_fail_open_to_full_queue.
**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 01:24 UTC · [original](https://github.com/gamingwithhomie/larp/pull/481) `ZerefDragnee1l:perf/cached-pipeline-load-speed` → `main` · +2160 −547 · 6 files · 2 commits · open Splits the cached pipeline loading and creation optimizations out of #408 onto current `main` (preserving #376 `Store`/`WindowsIdentity` scoping and zero cache invalidation). ### Summary - **Zero cache invalidation**: `shader_cache.rs` and `crates/larp-shader/src/**` are untouched, and `GraphicsState::describe_cached()` is unit-tested to match the exact legacy `describe()` format byte-for-byte so existing on-disk PSO blobs and `created-pipelines.bin` keys stay 100% valid. - **Parallel startup & warm-start sidecar (`blobs.rs`, `created.rs`, `make.rs`)**: - Overlaps `Store` disk index scanning (`00..ff` sharded `RwLock<HashSet<[u8; 16]>>` scanned across up to 8 threads), `created-shaders.bin` parallel BLAKE3 hashing, zero-copy `created-pipelines.bin` parsing (`ListedRef`), and `quad-pipelines.txt` loading. - Builds `Pending` keys in parallel and queues compute pipelines ahead of graphics pipelines in one batch. - Adds a self-validating `blobs-index.bin` sidecar (keyed by exe metadata, `shader_replace::fingerprint`, env toggles, and host caps + BLAKE3 footer) so warm runs skip queueing and translating already-cached non-compute graphics/mesh pipelines when their blobs are confirmed on disk. Whenever `blobs-index.bin` is absent, truncated, has a bad footer/digest, or carries a stale fingerprint (or when an entry's blob is missing from disk), startup fails open to an empty warm map and queues every pipeline normally. - Seeds `DISK`/`NOTED` dedup sets from startup catalog loading and removes redundant 10s sleep in `preload_done()` via `blobs::flush()`. - **Low-overhead blob & state hot paths (`blobs.rs`, `host.rs`, `pipeline.rs`, `shader_replace.rs`)**: - Zero-copy `BlobBytes::Owned` slices `&bytes[HEADER..]` directly without an extra `Arc<[u8]>` copy on warm loads (keeping BLAKE3 verification on by default; `LARP_FAST_BLOB_READ=1` opt-in). - Pre-PSO `blobs::pass_over_if_on_disk(&name)` check skips building `D3D12_GRAPHICS_PIPELINE_STATE_DESC`, `Stream`, label strings, `build_stages`, and COM root signatures when warming cached graphics/mesh blobs. - Upgrades cached root signature & rect-GS maps to `RwLock`, shares cached `Arc<Plan>` on `Translated`, unifies `gfx10::decode` across `store_flags()`, caches `of_builder` spilled checks and `HAS_HEAP`, and avoids waking empty `DONE` / polling loops (`DONE_WAITERS` + `DRAINED`). - Reapplies concurrent waiter frame-budget & `Queue::bump` fixes and adds adaptive quiet window (`400ms` warm / `3s` cold) before lifting menu input hold. ### Verification - `git diff --check` -> clean - `cargo check -p larp` -> exited 0 (`larp-gpu` compiled with 0 warnings) - `cargo test -p larp-gpu --lib pipeline` -> `16 passed; 0 failed; 2 ignored` (`native_windows_compute_blob_dispatch` and `compare_listed_shader_resolution` ignored by upstream `#[ignore]` attributes), including `graphics_state_describe_cached_matches_legacy_format`, `warm_index_round_trip_and_fingerprint_mismatch`, and caller-level fail-open test `warm_index_load_and_flush_fail_open_to_full_queue`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 01:30:30 +00:00
Author
Owner

@⁠vanya890 on GitHub · 2026-12-06 01:37 UTC · original

The sidecar codec tests cover round-trip, fingerprint mismatch and corruption rejection. One important safety boundary is still worth pinning at the caller: when blobs-index.bin is absent, truncated, has a bad footer, or carries a stale fingerprint, does warm startup always fall back to the full legacy queue rather than skip any pipeline? Since the index can suppress queueing/translation for cached graphics and mesh PSOs, a focused fail-open test around the load/flush path would protect the optimization from ever turning an invalid sidecar into a missing pipeline at runtime.

**@⁠vanya890** on GitHub · 2026-12-06 01:37 UTC · [original](https://github.com/gamingwithhomie/larp/pull/481#issuecomment-7449320530) The sidecar codec tests cover round-trip, fingerprint mismatch and corruption rejection. One important safety boundary is still worth pinning at the caller: when `blobs-index.bin` is absent, truncated, has a bad footer, or carries a stale fingerprint, does warm startup always fall back to the full legacy queue rather than skip any pipeline? Since the index can suppress queueing/translation for cached graphics and mesh PSOs, a focused fail-open test around the load/flush path would protect the optimization from ever turning an invalid sidecar into a missing pipeline at runtime.
Author
Owner

@⁠ZerefDragnee1l on GitHub · 2026-12-06 01:44 UTC · original

Good catch — added caller-level fail-open coverage in commit f447885.

How listed() fails open

  • load_warm_index() returns an empty HashMap whenever blobs-index.bin cannot be read or decode_warm_index() rejects it (too short, bad VICBIDX1 magic, stale fingerprint, trailing BLAKE3 footer mismatch, or mismatched entry count).
  • With an empty warm_map (or whenever on_disk returns false for a given blob key), try_warm_skip() leaves pending.warmed == false and plan_listed_queues() pushes every resolved graphics/mesh/quad-mask and compute pipeline onto the startup queues (identical to the legacy path). Compute pipelines are never skipped regardless of warm_map.
  • On flush (save_warm_index() / write_warm_encoded()), a valid atomic write + rename replaces any corrupted on-disk blobs-index.bin without leaving .tmp artifacts behind.

Regression test & verification (f447885)

  • Extracted try_warm_skip, build_listed_entry, plan_listed_queues, and write_warm_encoded / write_warm_index in crates/larp-gpu/src/pipeline/make.rs.
  • Added warm_index_load_and_flush_fail_open_to_full_queue exercising realistic Pending pipelines (vertex+pixel, quad_of, mesh+pixel, and compute) across:
    1. Valid flush + load (skips the 3 non-compute graphics/mesh/quad pipelines when on disk, keeps compute queued; partial disk absence queues only the missing pipeline).
    2. Absent blobs-index.bin -> fails open to full legacy queue (3 graphics + 1 compute, warmed == false for all).
    3. Truncated blobs-index.bin -> fails open to full legacy queue.
    4. Bad footer (flipped trailing BLAKE3 digest byte) -> fails open to full legacy queue.
    5. Stale fingerprint -> fails open to full legacy queue.
    6. Flush overwrite recovery -> corrupt blobs-index.bin is cleanly replaced with valid contents and no leftover *.tmp.

Ran after the final edit:

  • git diff --check -> clean
  • cargo check -p larp -> exited 0 (0 warnings in larp-gpu)
  • cargo test -p larp-gpu --lib pipeline -> 16 passed; 0 failed; 2 ignored (native_windows_compute_blob_dispatch and compare_listed_shader_resolution require external GPU hardware / private cache dir).
**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 01:44 UTC · [original](https://github.com/gamingwithhomie/larp/pull/481#issuecomment-7449416803) Good catch — added caller-level fail-open coverage in commit `f447885`. ### How `listed()` fails open - `load_warm_index()` returns an empty `HashMap` whenever `blobs-index.bin` cannot be read or `decode_warm_index()` rejects it (too short, bad `VICBIDX1` magic, stale fingerprint, trailing BLAKE3 footer mismatch, or mismatched entry count). - With an empty `warm_map` (or whenever `on_disk` returns `false` for a given blob key), `try_warm_skip()` leaves `pending.warmed == false` and `plan_listed_queues()` pushes every resolved graphics/mesh/quad-mask and compute pipeline onto the startup queues (identical to the legacy path). Compute pipelines are never skipped regardless of `warm_map`. - On flush (`save_warm_index()` / `write_warm_encoded()`), a valid atomic write + rename replaces any corrupted on-disk `blobs-index.bin` without leaving `.tmp` artifacts behind. ### Regression test & verification (`f447885`) - Extracted `try_warm_skip`, `build_listed_entry`, `plan_listed_queues`, and `write_warm_encoded` / `write_warm_index` in `crates/larp-gpu/src/pipeline/make.rs`. - Added `warm_index_load_and_flush_fail_open_to_full_queue` exercising realistic `Pending` pipelines (`vertex+pixel`, `quad_of`, `mesh+pixel`, and `compute`) across: 1. Valid flush + load (skips the 3 non-compute graphics/mesh/quad pipelines when on disk, keeps compute queued; partial disk absence queues only the missing pipeline). 2. Absent `blobs-index.bin` -> fails open to full legacy queue (`3` graphics + `1` compute, `warmed == false` for all). 3. Truncated `blobs-index.bin` -> fails open to full legacy queue. 4. Bad footer (flipped trailing BLAKE3 digest byte) -> fails open to full legacy queue. 5. Stale fingerprint -> fails open to full legacy queue. 6. Flush overwrite recovery -> corrupt `blobs-index.bin` is cleanly replaced with valid contents and no leftover `*.tmp`. Ran after the final edit: - `git diff --check` -> clean - `cargo check -p larp` -> exited 0 (0 warnings in `larp-gpu`) - `cargo test -p larp-gpu --lib pipeline` -> `16 passed; 0 failed; 2 ignored` (`native_windows_compute_blob_dispatch` and `compare_listed_shader_resolution` require external GPU hardware / private cache dir).
Author
Owner

@⁠christopear on GitHub · 2026-12-06 01:59 UTC · original

I ran the ignored compare_listed_shader_resolution benchmark on f4478857 with a populated cache under Proton Experimental (Windows MSVC release build). Five fresh processes, each using the test's original / cached / cached / original order. The stage and hash fingerprints matched on every pass.

  • 88,537 records, 169,752 shader references, 19,058 containers.
  • Original resolver median 364.35 ms (327.94–395.39 ms, 10 samples).
  • Cached resolver median 37.44 ms (36.02–44.74 ms, 10 samples).

That's about 9.7× faster for this resolver, saving roughly 0.33 s in this measurement. The timer excludes reading the files and creating GPU pipelines. The regular pipeline:: filter also passed (15 passed, 2 ignored). I ran the populated-cache benchmark separately and left the native Windows GPU test alone.

One integration detail if #435 also lands. A dry merge conflicted in blobs.rs and make.rs. Here try_warm_skip can skip scheduling a graphics key on a disk hit, while #435 decides to retain it during creation. A useful combined test would give both base and quad variants disk hits, mark just one wanted and verify that one is actually created and retained before first draw. Then swap which one is wanted.

**@⁠christopear** on GitHub · 2026-12-06 01:59 UTC · [original](https://github.com/gamingwithhomie/larp/pull/481#issuecomment-7449607428) I ran the ignored `compare_listed_shader_resolution` benchmark on `f4478857` with a populated cache under Proton Experimental (Windows MSVC release build). Five fresh processes, each using the test's original / cached / cached / original order. The stage and hash fingerprints matched on every pass. * 88,537 records, 169,752 shader references, 19,058 containers. * Original resolver median 364.35 ms (327.94–395.39 ms, 10 samples). * Cached resolver median 37.44 ms (36.02–44.74 ms, 10 samples). That's about 9.7× faster for this resolver, saving roughly 0.33 s in this measurement. The timer excludes reading the files and creating GPU pipelines. The regular `pipeline::` filter also passed (15 passed, 2 ignored). I ran the populated-cache benchmark separately and left the native Windows GPU test alone. One integration detail if #435 also lands. A dry merge conflicted in `blobs.rs` and `make.rs`. Here `try_warm_skip` can skip scheduling a graphics key on a disk hit, while #435 decides to retain it during creation. A useful combined test would give both base and quad variants disk hits, mark just one wanted and verify that one is actually created and retained before first draw. Then swap which one is wanted.
Author
Owner

@⁠ZerefDragnee1l on GitHub · 2026-12-06 02:02 UTC · original

Thanks for running the populated-cache compare_listed_shader_resolution benchmark under Proton and flagging the #435 interaction!

Agreed on the integration point with #435 (LARP_KEEP_USED=1):

  • Because try_warm_skip() runs independently on both the base Pending key and its Pending::quad_of variant key in build_listed_entry(), combining #481 and #435 will need try_warm_skip() (and the warming / pass_over_if_on_disk() gate in Pending::make()) to treat any key in #435's retained/wanted set (used-pipelines.txt) the same way compute pipelines are treated here—never warm-skipped and kept resident in self.made.
  • Whichever of #481 or #435 lands second, I'm happy to resolve the blobs.rs / make.rs merge conflict and add that exact combined base-vs-quad swap test (both on disk, mark only base wanted -> base queued & retained while quad skips, then swap so only quad is wanted).
**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 02:02 UTC · [original](https://github.com/gamingwithhomie/larp/pull/481#issuecomment-7449634902) Thanks for running the populated-cache `compare_listed_shader_resolution` benchmark under Proton and flagging the #435 interaction! Agreed on the integration point with #435 (`LARP_KEEP_USED=1`): - Because `try_warm_skip()` runs independently on both the base `Pending` key and its `Pending::quad_of` variant key in `build_listed_entry()`, combining #481 and #435 will need `try_warm_skip()` (and the `warming` / `pass_over_if_on_disk()` gate in `Pending::make()`) to treat any key in #435's retained/wanted set (`used-pipelines.txt`) the same way compute pipelines are treated here—never warm-skipped and kept resident in `self.made`. - Whichever of #481 or #435 lands second, I'm happy to resolve the `blobs.rs` / `make.rs` merge conflict and add that exact combined base-vs-quad swap test (both on disk, mark only base wanted -> base queued & retained while quad skips, then swap so only quad is wanted).
This pull request can be merged automatically.
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/481/head:github-bot/gh-481'
git switch 'github-bot/gh-481'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-481'
git switch 'github-bot/gh-481'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-481'
git switch 'github-bot/gh-481'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-481'
git switch 'main'
git merge --squash 'github-bot/gh-481'
git switch 'main'
git merge --ff-only 'github-bot/gh-481'
git switch 'main'
git merge 'github-bot/gh-481'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.