Pipeline & CLI: stable shader cache key, in-flight dedup, and AOT warm-up #254

Closed
github-bot wants to merge 1 commit from gh-pr/254/head into gh-pr/254/base
Owner

@⁠wbkepler on GitHub · 2026-11-24 01:51 UTC · original
wbkepler:pipeline/stable-shader-cache-and-warmup → main · +829 −115 · 12 files · 1 commits · closed without merging

Summary

Prevents full shader-cache invalidation on unrelated crate rebuilds, eliminates duplicate concurrent shader translations and disk read-backs, and adds AOT shader cache warming via victory translate --write-cache:

  • victory-pipeline (cache.rs):
    • Adds get_or_convert_bytes (returning converted bytes directly on miss without disk read-back), put(), panic-safe per-key in-flight deduplication (InFlightGuard with zero-clone uncontended fast path), and write_atomic staging temp-file cleanup on write/rename failure.
  • victory-shader (build.rs, dxbc.rs, lib.rs):
    • Computes a deterministic BLAKE3 digest of src/**/*.rs (victory_shader::SOURCE_HASH), and exposes dxbc::Container::total_size.
  • victory-gpu (shader_cache.rs):
    • Keys entries on (MAGIC, CACHE_SCHEMA_VERSION, SOURCE_HASH, loop_limit) instead of hashing current_exe(), uses get_or_convert_bytes, and exposes open()/store() sharing KeySpec.
  • apps/victory (translate.rs, main.rs, shader.rs):
    • Reuses one persistent worker pool (keeping Validator and D3D12 Host alive across all input files via bounded WorkQueue + SourceRef), slices raw DXBC containers to exact total_size, and adds --write-cache to populate <cache_dir>/shaders.
  • Adds unit tests in victory-pipeline (7/7) and victory-gpu (46/46).

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed
  • cargo xtask policy — passed (152 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 01:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/254) `wbkepler:pipeline/stable-shader-cache-and-warmup` → `main` · +829 −115 · 12 files · 1 commits · closed without merging ## Summary Prevents full shader-cache invalidation on unrelated crate rebuilds, eliminates duplicate concurrent shader translations and disk read-backs, and adds AOT shader cache warming via `victory translate --write-cache`: - **`victory-pipeline` (`cache.rs`)**: - Adds `get_or_convert_bytes` (returning converted bytes directly on miss without disk read-back), `put()`, panic-safe per-key in-flight deduplication (`InFlightGuard` with zero-clone uncontended fast path), and `write_atomic` staging temp-file cleanup on write/rename failure. - **`victory-shader` (`build.rs`, `dxbc.rs`, `lib.rs`)**: - Computes a deterministic BLAKE3 digest of `src/**/*.rs` (`victory_shader::SOURCE_HASH`), and exposes `dxbc::Container::total_size`. - **`victory-gpu` (`shader_cache.rs`)**: - Keys entries on `(MAGIC, CACHE_SCHEMA_VERSION, SOURCE_HASH, loop_limit)` instead of hashing `current_exe()`, uses `get_or_convert_bytes`, and exposes `open()`/`store()` sharing `KeySpec`. - **`apps/victory` (`translate.rs`, `main.rs`, `shader.rs`)**: - Reuses one persistent worker pool (keeping `Validator` and D3D12 `Host` alive across all input files via bounded `WorkQueue` + `SourceRef`), slices raw DXBC containers to exact `total_size`, and adds `--write-cache` to populate `<cache_dir>/shaders`. - Adds unit tests in `victory-pipeline` (7/7) and `victory-gpu` (46/46). ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed - `cargo xtask policy` — passed (152 files ok)
Avoid wiping the shader cache on unrelated rebuilds, eliminate duplicate
concurrent translations and redundant disk read-backs, and support
ahead-of-time cache warming via `victory translate --write-cache`:

- victory-pipeline: add `Cache::get_or_convert_bytes` (returning converted
  bytes directly in memory on a miss without re-reading from disk) and
  `Cache::put`, deduplicate concurrent in-flight conversions per key via a
  panic-safe `InFlightGuard`, and remove staging temp files on write or
  rename failure.
- victory-shader: compute a deterministic BLAKE3 digest of `src/**/*.rs`
  at build time (`victory_shader::SOURCE_HASH`) and expose `total_size` on
  `dxbc::Container`.
- victory-gpu: key `shader_cache` on `(MAGIC, CACHE_SCHEMA_VERSION,
  victory_shader::SOURCE_HASH, loop_limit)` instead of hashing
  `current_exe()`, use `get_or_convert_bytes`, and expose `open`/`store`
  for offline cache warming.
- victory CLI: share one persistent worker pool (keeping `Validator` and
  D3D12 `Host` alive across all input files), slice raw DXBC containers to
  `total_size`, and add `victory translate --write-cache` to pre-populate
  `<cache_dir>/shaders`.
- tests: add unit tests for direct bytes return, concurrent in-flight
  dedup, staging temp-file cleanup on rename failure, fingerprint stability
  and sensitivity, and `store` warm-up round-trips.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:48 +00:00
github-bot closed this pull request 2026-11-26 03:56:48 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 05:53 UTC · original

Tested current PR head 0e6b2b4db5eee53aa3dde1e4eaafcf4e80f5aab9.

  • cargo test --locked -p victory-pipeline --lib cache -- --test-threads=1: 7 passed. The tests cover first conversion versus disk hit, byte return without rereading, version invalidation, eight concurrent same-key callers converting once, cache prewarming, refusal of an in-repository cache, and cleanup of a staging file after rename failure (cache tests).
  • cargo test --locked -p victory-gpu --lib shader_cache -- --test-threads=1: 5 passed. Fingerprints are deterministic and change with source hash, schema version, or loop limit; cache entries reject truncation/trailing bytes; prewarmed runtime lookups avoid translation; six concurrent lookups translate once (shader-cache tests).
  • cargo test --locked -p victory-game --lib sgd5 -- --test-threads=1: 2 passed for record iteration and corrupt-stream handling, including the offset lookup used by the AOT source scanner (SGD5 record lookup).
  • cargo test --locked -p victory-shader -- --test-threads=1: 69 passed, 0 doc tests. cargo test --locked -p victory -- --test-threads=1: the CLI package built and its 1 existing loader-lock test passed. cargo run --locked -p victory -- translate --help displays the new --write-cache option (CLI option).

No AOT translation was run over title files or other assets, and these checks do not exercise the full source-scanning/worker pipeline against an input file or a runtime D3D12 pipeline.

**@⁠jeremygold02** on GitHub · 2026-11-24 05:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/254#issuecomment-7123371815) Tested current PR head `0e6b2b4db5eee53aa3dde1e4eaafcf4e80f5aab9`. - `cargo test --locked -p victory-pipeline --lib cache -- --test-threads=1`: 7 passed. The tests cover first conversion versus disk hit, byte return without rereading, version invalidation, eight concurrent same-key callers converting once, cache prewarming, refusal of an in-repository cache, and cleanup of a staging file after rename failure ([cache tests](https://github.com/Marvisak/VIctory/blob/0e6b2b4db5eee53aa3dde1e4eaafcf4e80f5aab9/crates/victory-pipeline/src/cache.rs#L315-L440)). - `cargo test --locked -p victory-gpu --lib shader_cache -- --test-threads=1`: 5 passed. Fingerprints are deterministic and change with source hash, schema version, or loop limit; cache entries reject truncation/trailing bytes; prewarmed runtime lookups avoid translation; six concurrent lookups translate once ([shader-cache tests](https://github.com/Marvisak/VIctory/blob/0e6b2b4db5eee53aa3dde1e4eaafcf4e80f5aab9/crates/victory-gpu/src/shader_cache.rs#L401-L491)). - `cargo test --locked -p victory-game --lib sgd5 -- --test-threads=1`: 2 passed for record iteration and corrupt-stream handling, including the offset lookup used by the AOT source scanner ([SGD5 record lookup](https://github.com/Marvisak/VIctory/blob/0e6b2b4db5eee53aa3dde1e4eaafcf4e80f5aab9/crates/victory-game/src/sgd5.rs#L44-L71)). - `cargo test --locked -p victory-shader -- --test-threads=1`: 69 passed, 0 doc tests. `cargo test --locked -p victory -- --test-threads=1`: the CLI package built and its 1 existing loader-lock test passed. `cargo run --locked -p victory -- translate --help` displays the new `--write-cache` option ([CLI option](https://github.com/Marvisak/VIctory/blob/0e6b2b4db5eee53aa3dde1e4eaafcf4e80f5aab9/apps/victory/src/main.rs#L84-L88)). No AOT translation was run over title files or other assets, and these checks do not exercise the full source-scanning/worker pipeline against an input file or a runtime D3D12 pipeline.
Author
Owner

@⁠Callimann8 on GitHub · 2026-11-24 11:06 UTC · original

Tested on an RTX 4070 (driver 32.0.16.2114, Ryzen 9 7945HX, Win 11), merged onto main ffe310e.

Merge: two small conflicts with current main, in victory-gpu/src/shader_cache.rs (doc comment) and victory-pipeline/src/cache.rs (imports, plus the convert/publish block that #161 changed). I took the PR's side, since get_or_convert_bytes' publish helper already removes the staging file. std::io::Write becomes unused. cargo test -p victory-pipeline -p victory-gpu passes.

Warm-up (victory translate --write-cache, release build): 85 s, 26,148 programs, 21,898 written to the cache (606 MB). The rest fail translation for the known reasons (scalar memory read as data, 64-bit image atomics, ...).

Effect (diag build, same scripted key presses, so this also checks that the cache key survives a different build profile):

cold cache after warm-up
cache hits / misses by world 0 / 2,131 1,553 / 0
frame 512 presented 31.0 s 20.2 s
world archive opened 47.4 s 36.2 s

So about 11 s off boot-to-world here. World fps can't be compared yet, because both runs hit the NVIDIA world hang (#97) shortly after.

**@⁠Callimann8** on GitHub · 2026-11-24 11:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/254#issuecomment-7129666481) Tested on an RTX 4070 (driver 32.0.16.2114, Ryzen 9 7945HX, Win 11), merged onto main ffe310e. Merge: two small conflicts with current main, in victory-gpu/src/shader_cache.rs (doc comment) and victory-pipeline/src/cache.rs (imports, plus the convert/publish block that #161 changed). I took the PR's side, since get_or_convert_bytes' publish helper already removes the staging file. std::io::Write becomes unused. `cargo test -p victory-pipeline -p victory-gpu` passes. Warm-up (`victory translate --write-cache`, release build): 85 s, 26,148 programs, 21,898 written to the cache (606 MB). The rest fail translation for the known reasons (scalar memory read as data, 64-bit image atomics, ...). Effect (diag build, same scripted key presses, so this also checks that the cache key survives a different build profile): | | cold cache | after warm-up | |---------------------------------|------------|---------------| | cache hits / misses by world | 0 / 2,131 | 1,553 / 0 | | frame 512 presented | 31.0 s | 20.2 s | | world archive opened | 47.4 s | 36.2 s | So about 11 s off boot-to-world here. World fps can't be compared yet, because both runs hit the NVIDIA world hang (#97) shortly after.

Pull request closed

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!254
No description provided.