Skip to content

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

Closed
wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:pipeline/stable-shader-cache-and-warmup
Closed

wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:pipeline/stable-shader-cache-and-warmup

Conversation

@wbkepler

Copy link
Copy Markdown
Contributor

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)

AntoninMichelq pushed a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 24, 2026
Every rebuild changed the executable's hash and so retranslated every
shader on the next run (minutes of first-run stalls) even when the
translator had not changed. Key the cache on victory-shader's source
digest (computed by its build script, as upstream PR Marvisak#254 does), this
file (the entry encoding), the build profile and the loop/spin limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSBL6gm6bCVwNso3jAy
@jeremygold02

Copy link
Copy Markdown
Contributor

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.

@Callimann8

Copy link
Copy Markdown

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 mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…ey, in-flight dedup, and AOT warm-up

Conflicts resolved by hand:
- victory-shader/build.rs: one main() that computes the source hash
  (this PR) and then opts test binaries into an app-local Agility SDK
  runtime (upstream main), both unchanged.
- translate.rs: this PR's file work queue, fed by the fork's
  scan_entries() so traversal errors are still counted and reported;
  Tally keeps the cache counters and the smallest-label example (Marvisak#673).
- shader_cache.rs doc: this PR's wording with plain backticks (Marvisak#675).
- victory-pipeline cache.rs: this PR's get_or_convert_bytes path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
Merged with Marvisak#254's shader cache: the host's wave sizes (Target) are part
of every cache key, the offline warm-up (translate --write-cache) stores
under the same key and detects this machine's GPU when no target is given,
and the worker queue passes the target to each worker. Stale test
initializers from Marvisak#650 and Marvisak#233 updated (Parts::target/console_cf,
Container::total_size). On the RTX 4070 no compute pipeline is refused
any more and the world shows a full skyline of lights.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…up, and AOT warm-up

Resolved: the cache key is the PR's source-hash fingerprint plus HEAD's spin-wait limit, then HEAD's per-host wave target (key()); shader_cache::store takes the target so --write-cache entries match runtime lookups. translate.rs takes the PR's work queue with HEAD's target in Checks; main.rs passes both write_cache and host_lanes. shader.rs keeps HEAD's in_record filter (also in source_refs) with the PR's total_size trim; sgd5::record_at maps HEAD's Found. victory-pipeline takes the PR's in-flight dedup with HEAD's create_new temp write in write_atomic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
…s total_size

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m-up

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.
@wbkepler
wbkepler force-pushed the pipeline/stable-shader-cache-and-warmup branch from 0e6b2b4 to b19ad94 Compare November 24, 2026 16:18
@Marvisak Marvisak closed this Nov 24, 2026
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
Where a fork-only change duplicates upstream's own version of a feature,
upstream's is kept and the fork's dropped:
- victory-shader is upstream's crate with the fork-only merges replayed
  onto it oldest first; those that do not apply onto upstream are dropped
  (37 of 63: among them Marvisak#704/raw views, gather4_l, the lane-mask and Marvisak#308
  ports, Marvisak#947, Marvisak#1022, Marvisak#1112, Marvisak#1090, Marvisak#1182). Marvisak#284 (legacy fused madds) and
  Marvisak#98 (permlane16 in whole-wave sections) are dropped too: the first
  disagrees with upstream's hardware-checked model, the second refused 46
  programs upstream translates.
- translate: upstream's --cache replaces Marvisak#254's write-cache and work queue;
  Marvisak#378, Marvisak#517, Marvisak#673 and the victory.toml console are re-applied.
- victory-gpu: upstream's stride table, page table and heap views replace
  the fork's Marvisak#704/stride-table wiring; fork-only fixes re-applied on top.

Package (shaders.rpf, translate --validate --list, counts): vertex/pixel
emitted 12559 -> 14295 of 14337, compute 2359 -> 2628 validated, mesh
2730 -> 2811 validated. Tests: the failures left (rect fourth corner,
two stride tests, row order, gather4 at a level, memory table, dynamic
heap slots) fail on upstream main as well on this host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants