Skip to content

Key cached shader translations by effective host wave width - #35

Open
ryotdev wants to merge 2 commits into
fxceless:mainfrom
ryotdev:codex/shader-cache-wave-width
Open

ryotdev wants to merge 2 commits into
fxceless:mainfrom
ryotdev:codex/shader-cache-wave-width

Conversation

@ryotdev

@ryotdev ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

The translator can emit different DXIL for the same input depending on the adapter’s wave width. The disk cache used the same key for both outputs. With a shared cache, a shader compiled on a 64-lane adapter could be returned on a 32-lane adapter that cannot create its pipeline.

I confirmed the distinction with a hand-built wave reduction. The two outputs validate with Microsoft’s DXIL validator and declare different required widths in PSV0. This change includes the translator’s effective wave32 setting in the cache key, bumps the converter version, and still reuses entries across adapters that choose the same lowering mode.

The regression reopens the cache four times, alternating modes. On the old key the second lookup returned the first mode’s output. With the fix each mode compiles once and subsequent lookups return the correct entry.

Verification on 90228a7 plus this patch:

  • Windows shader-cache tests: 3 passed. The negative control failed before the key change.
  • Portable shader library: 170 passed, 2 ignored.
  • Windows Clippy for the two affected crates with all targets and features, and the asset-policy check, passed.

AI-assisted. This fixes cache reuse across adapters. Our fresh-cache RTX 5070 run cannot demonstrate an in-game visual change from this patch.

@adriaespii

Copy link
Copy Markdown

Independent test run on commit 7545c97 (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 497 passed, 0 failed, 7 ignored (victory-gpu: 111 passed, 0 failed, 1 ignored; victory-shader: 210 passed, 0 failed, 2 ignored)
  • Not tested: live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

@arminkhaleghirod

Copy link
Copy Markdown

Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080. Changes against main, by failure reason:

No change: every failure count is the same as main, and no new reason appears. So no regression in translation. What this PR changes at run time isn't covered by this check.

@ericomeehan

Copy link
Copy Markdown

Three more inputs change the translation but aren't in the cache key. That's true on main (4e17478), with this PR, and in #147's version of the list:

  • VICTORY_WAVE_LOCAL, read at crates/victory-shader/src/emit/mod.rs:338 and :344. 0 turns the local-wave forms off, idiom refuses the approximate ones. This runs inside the wave64-on-a-32-lane-host retry, so it changes the DXIL on the hosts this PR is about.
  • VICTORY_STRICT_JOINS, read at crates/victory-shader/src/emit/lower.rs:10624. It marks joins that are read only through other joins. Its comment says about 40 programs that translate today stop with it.
  • VICTORY_MESH_OUTPUT_STRICT, read at crates/victory-shader/src/emit/lower.rs:4021. It refuses mesh shaders whose outputs exceed the host's 32 KiB, instead of emitting them with lower maxima.

crates/victory-gpu/src/shader_cache.rs:63-68 keys VICTORY_WAVE_WIDE, VICTORY_WAVE_DEEP_SKIPS, VICTORY_WAVE_OWN_BITS and VICTORY_F16_NEAREST only, and #147 keeps the same four (its shader_cache.rs:69-72). So two runs of the same build, one with one of these set and one without, share entries. Failed translations aren't stored, so a run with a strict switch set is served the successful translation an earlier run cached without it. The comment above the list describes this case for VICTORY_WAVE_WIDE=0. The fix is three more names in that list: "VICTORY_WAVE_LOCAL", "VICTORY_STRICT_JOINS", "VICTORY_MESH_OUTPUT_STRICT",. Nothing changes for anyone who doesn't set them.

This PR and #147 both change how the cache key is built in shader_cache.rs (#147 replaces build() with a key(...)), so whichever merges second has to carry the other's inputs, in particular this PR's host-wave byte.

Related: this PR also addresses the stale-cache explanation in #75, where a cache filled without the host's 32-lane setting serves WaveSize(64) translations, which NVIDIA refuses. Whether that is what happened on the RTX 3070 there still depends on the empty-cache run asked for in that thread.

I found all of this by reading the code; I haven't built or run it.

Written with an AI assistant (Claude).

@ryotdev

ryotdev commented Nov 25, 2026

Copy link
Copy Markdown
Author

@ericomeehan I reproduced the missing cache inputs in separate Windows processes and updated this branch in 7eebb26. The cache now distinguishes the default local-wave behavior from VICTORY_WAVE_LOCAL=0 and idiom, and includes both strict switches you identified.

One additional case matters for integration with #544. The translator checks whether each strict variable exists, so even an empty value enables it. Adding their names to the old serialization still produced the same key for strictly enabled (empty) and unset. The new regression failed on that negative control and on the previous #35 head. With the fix the full Windows GPU suite on WARP passed 119 tests, with one ignored. AI-assisted.

oz-stanislav-zhukov pushed a commit to oz-stanislav-zhukov/victory-fork that referenced this pull request Nov 26, 2026
…ns (fxceless#35)

(cherry picked from commit fe5139303a66fdaf46c515b59cd63bf944909216)
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.

4 participants