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

Closed
wbkepler wants to merge 1 commit from upstream-pr/254 into main
wbkepler commented 2026-11-24 01:51:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T01:51:06Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572779632 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/254). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T01:51:06Z. --- ## 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)
jeremygold02 commented 2026-11-24 06:56:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:53:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123371815 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/254#issuecomment-7123371815). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:53:29Z. --- 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.
Callimann8 commented 2026-11-24 12:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Callimann8 on 2026-11-24T11:06:33Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129666481 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/254#issuecomment-7129666481). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-11-24T11:06:33Z. --- 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.
mercuryVM commented 2026-11-24 13:39:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T13:39:29Z.

Review: APPROVED


Tested 0e6b2b4 on Windows 11, RTX 5070, MSVC: cargo test -p victory-pipeline -p victory-gpu -p victory-shader -p victory -- --test-threads=1 123 passed. Clippy shows only the two existing warnings (host.rs:267, xmem.rs:747).

  • Safety check: the new crates/victory-shader/build.rs only reads the crate's own src/**/*.rs and hashes them with blake3, already a workspace dependency, as a build-dependency. It downloads and runs nothing. Cargo.lock gains only edges.
  • victory translate <exe> --write-cache works. With VICTORY_CACHE_DIR pointed at a scratch folder, the first run on a local title executable wrote 12 entries and a second run reported "0 written (12 already cached)".
  • Keying on (MAGIC, CACHE_SCHEMA_VERSION, SOURCE_HASH, loop_limit) instead of current_exe() stops unrelated rebuilds from invalidating the whole cache, which is the right trade.
  • Things I couldn't verify here without running the title:
    • That the runtime looks up exactly the keys --write-cache writes. The CLI and runtime must agree on loop_limit, and the CLI uses the default. A test asserting that the CLI's key for a container equals shader_cache's runtime key would pin it.
    • That in-flight dedup never holds a translation lock across a pipeline wait.
  • This currently conflicts with main (and with mercuryVM/VIctory main), so it needs a rebase.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6040196552 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/254#pullrequestreview-6040196552). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T13:39:29Z. **Review:** APPROVED --- Tested 0e6b2b4 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-pipeline -p victory-gpu -p victory-shader -p victory -- --test-threads=1` 123 passed. Clippy shows only the two existing warnings (host.rs:267, xmem.rs:747). - Safety check: the new `crates/victory-shader/build.rs` only reads the crate's own `src/**/*.rs` and hashes them with `blake3`, already a workspace dependency, as a build-dependency. It downloads and runs nothing. `Cargo.lock` gains only edges. - `victory translate <exe> --write-cache` works. With `VICTORY_CACHE_DIR` pointed at a scratch folder, the first run on a local title executable wrote 12 entries and a second run reported "0 written (12 already cached)". - Keying on `(MAGIC, CACHE_SCHEMA_VERSION, SOURCE_HASH, loop_limit)` instead of `current_exe()` stops unrelated rebuilds from invalidating the whole cache, which is the right trade. - Things I couldn't verify here without running the title: - That the runtime looks up exactly the keys `--write-cache` writes. The CLI and runtime must agree on `loop_limit`, and the CLI uses the default. A test asserting that the CLI's key for a container equals `shader_cache`'s runtime key would pin it. - That in-flight dedup never holds a translation lock across a pipeline wait. - This currently conflicts with main (and with mercuryVM/VIctory main), so it needs a rebase. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 23:04:00 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!254
No description provided.