Shaders: precompile answers for its own shader, not by the shared miss count (#291) #441

Open
github-bot wants to merge 1 commit from github-bot/gh-441 into a-publier AGit
Owner

@⁠hussainmussa on GitHub · 2026-11-27 01:55 UTC · original
hussainmussa:fix/precompile-own-answer → a-publier · +70 −5 · 1 files · 1 commits · open

Refs #291.

What was wrong

On the dispute in #291 first: the comment there is right about reachability. On a-publier (4eb6cfd) the None arm of precompile cannot run from victory shaders or translate --warm, because both call cfg.cache_subdir("shaders")? first, and Cache::open then makes the same two calls on the same path (ensure_outside_repo, create_dir_all). With VICTORY_CACHE_DIR pointing at a file, both commands stop with creating ...\shaders before a shader is read.

But the issue is right that the answer is wrong by construction, and one case of that is reachable. precompile returned Ok(MISSES == misses), and MISSES is every thread's count. translate --warm runs on all cores and turns that answer into "translated now" against "in the cache already" (warm_shader, d3d12x.rs:74). So a shader found in the cache is counted as "translated now" whenever another thread stores one during the call.

What this does

precompile now answers by whether this call reached the translator. The body moves to precompiled(cache, build, container, translate), which takes the cache and the translator so that tests need no graphics device. One file, no signature of anything public changes.

  • A shader found in the cache is "there", whatever other threads do meanwhile.
  • A shader translated with no cache to keep it is not "there" (the None arm of the issue, unreachable today, now answers correctly too).

MISSES moves exactly when the translator ran (cached_by), so on one thread the answer is the same as before.

Testing

Windows 11, Rust 1.98.1, no graphics device used.

  • cargo test -p victory-gpu --locked --lib shader_cache: 5 passed, the two new ones among them.
  • With the old arithmetic put back inside precompiled, both new tests fail: precompiling_without_a_cache_is_not_there gets Ok(true) for Ok(false), and precompiling_answers_for_its_own_shader reports 16 of 500 shaders found in the cache were said translated now.
  • cargo clippy -p victory-gpu --no-deps --all-targets --locked -- -D warnings: clean.
  • cargo test -p xtask --locked: 9 passed.

The second test is a race between two threads, so with the old code the number of wrong answers varies from run to run (16 and 21 of 500 in two runs here); with the new code it is 0 by construction, since the answer no longer reads shared state.

Not tested: precompile itself, which opens the graphics device, and a real translate --warm over the title's shaders (I have no game files). The tests drive precompiled with a stand-in translator.

Note

#436 also refers to #291 and changes how --warm reports failures in translate.rs. This touches only shader_cache.rs and the two do not overlap.

Written with help from Claude; everything above was built and run on my machine.

**@⁠hussainmussa** on GitHub · 2026-11-27 01:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/441) `hussainmussa:fix/precompile-own-answer` → `a-publier` · +70 −5 · 1 files · 1 commits · open Refs #291. ## What was wrong On the dispute in #291 first: the comment there is right about reachability. On `a-publier` (4eb6cfd) the `None` arm of `precompile` cannot run from `victory shaders` or `translate --warm`, because both call `cfg.cache_subdir("shaders")?` first, and `Cache::open` then makes the same two calls on the same path (`ensure_outside_repo`, `create_dir_all`). With `VICTORY_CACHE_DIR` pointing at a file, both commands stop with `creating ...\shaders` before a shader is read. But the issue is right that the answer is wrong by construction, and one case of that is reachable. `precompile` returned `Ok(MISSES == misses)`, and `MISSES` is every thread's count. `translate --warm` runs on all cores and turns that answer into "translated now" against "in the cache already" (`warm_shader`, `d3d12x.rs:74`). So a shader found in the cache is counted as "translated now" whenever another thread stores one during the call. ## What this does `precompile` now answers by whether this call reached the translator. The body moves to `precompiled(cache, build, container, translate)`, which takes the cache and the translator so that tests need no graphics device. One file, no signature of anything public changes. - A shader found in the cache is "there", whatever other threads do meanwhile. - A shader translated with no cache to keep it is not "there" (the `None` arm of the issue, unreachable today, now answers correctly too). `MISSES` moves exactly when the translator ran (`cached_by`), so on one thread the answer is the same as before. ## Testing Windows 11, Rust 1.98.1, no graphics device used. - `cargo test -p victory-gpu --locked --lib shader_cache`: 5 passed, the two new ones among them. - With the old arithmetic put back inside `precompiled`, both new tests fail: `precompiling_without_a_cache_is_not_there` gets `Ok(true)` for `Ok(false)`, and `precompiling_answers_for_its_own_shader` reports `16 of 500 shaders found in the cache were said translated now`. - `cargo clippy -p victory-gpu --no-deps --all-targets --locked -- -D warnings`: clean. - `cargo test -p xtask --locked`: 9 passed. The second test is a race between two threads, so with the old code the number of wrong answers varies from run to run (16 and 21 of 500 in two runs here); with the new code it is 0 by construction, since the answer no longer reads shared state. **Not tested:** `precompile` itself, which opens the graphics device, and a real `translate --warm` over the title's shaders (I have no game files). The tests drive `precompiled` with a stand-in translator. ## Note #436 also refers to #291 and changes how `--warm` reports failures in `translate.rs`. This touches only `shader_cache.rs` and the two do not overlap. Written with help from Claude; everything above was built and run on my machine.
`precompile` said a translation "was there" when the count of misses had
not moved during the call. That count is every thread's: a shader found
in the cache was "translated now" whenever another thread stored one
meanwhile, which `translate --warm` printed (some 20 of 500 in a test on
two threads), and one translated with no cache to keep it was "there".

It now answers by whether this call reached the translator, in
`precompiled`, which takes the cache and the translator so that tests
need no graphics device.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:16:06 +00:00
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-27 02:16 UTC · original

I checked the public shader_cache::precompile entry point on a-publier@4eb6cfd and PR head 9c38609. I compiled the unmodified cache module on x86-64 Linux with the real GFX10-to-DXIL translator and on-disk cache. The fixture supplies the two Windows host probes. The inputs are synthetic compute shaders with distinct thread-group widths.

For each of 32 runs I paused the thread reading an already-cached shader at the host-capability probe inside build(), let a second thread finish precompiling a distinct cold shader, then resumed the first. The wait uses channels, so no sleeps or timing thresholds are involved.

Result Base PR
Cached reader incorrectly returned Ok(false) 32/32 0/32
Cold call returned Ok(false) 32/32 32/32
Immediate repeat of that cold call returned Ok(true) 32/32 32/32
Entries reported as hits after restarting the process 33/33 33/33

The actual cache counters ended at 65 hits and 33 misses on both builds before restart. That isolates the change to the per-call answer used by the warmer. The old result could report a fresh translation even though the reader's shader was already on disk. This was CPU-side testing with fixed host capabilities; no game or GPU run. AI-assisted verification.

**@⁠Yoshi-233** on GitHub · 2026-11-27 02:16 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/441#issuecomment-7207978332) I checked the public `shader_cache::precompile` entry point on `a-publier@4eb6cfd` and PR head `9c38609`. I compiled the unmodified cache module on x86-64 Linux with the real GFX10-to-DXIL translator and on-disk cache. The fixture supplies the two Windows host probes. The inputs are synthetic compute shaders with distinct thread-group widths. For each of 32 runs I paused the thread reading an already-cached shader at the host-capability probe inside `build()`, let a second thread finish precompiling a distinct cold shader, then resumed the first. The wait uses channels, so no sleeps or timing thresholds are involved. | Result | Base | PR | | --- | ---: | ---: | | Cached reader incorrectly returned `Ok(false)` | 32/32 | 0/32 | | Cold call returned `Ok(false)` | 32/32 | 32/32 | | Immediate repeat of that cold call returned `Ok(true)` | 32/32 | 32/32 | | Entries reported as hits after restarting the process | 33/33 | 33/33 | The actual cache counters ended at 65 hits and 33 misses on both builds before restart. That isolates the change to the per-call answer used by the warmer. The old result could report a fresh translation even though the reader's shader was already on disk. This was CPU-side testing with fixed host capabilities; no game or GPU run. AI-assisted verification.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 03:55 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At 9c38609: cargo test --release -p victory-gpu --lib 398 passed, 0 failed, 34 ignored.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 03:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/441#issuecomment-7209383822) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `9c38609`: `cargo test --release -p victory-gpu --lib` 398 passed, 0 failed, 34 ignored. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠hussainmussa on GitHub · 2026-11-27 17:10 UTC · original

Ran this on the title's real shaders. RTX 4070, Windows 11, 20 threads, diag build, translate --warm over shaders.rpf (25,889 hashes) with a fresh VICTORY_CACHE_DIR per build. Step 1 warms every other hash; step 2 warms all of them, so 12,853 are in the cache when it starts.

step 2 in the cache already translated now
expected 12,853 12,841
4eb6cfd 10,369 15,325
9c38609 12,853 12,841

Step 1 is the same on both (12,853 translated now, 92 do not translate). A third pass on 9c38609: 0 translated now, 25,694 in the cache already, 0.9 s. Both caches end with 25,694 files, so only the report differed. One run of each step per build.

Written with help from Claude; everything above was run on my machine.

**@⁠hussainmussa** on GitHub · 2026-11-27 17:10 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/441#issuecomment-7224116433) Ran this on the title's real shaders. RTX 4070, Windows 11, 20 threads, diag build, `translate --warm` over `shaders.rpf` (25,889 hashes) with a fresh `VICTORY_CACHE_DIR` per build. Step 1 warms every other hash; step 2 warms all of them, so 12,853 are in the cache when it starts. | step 2 | in the cache already | translated now | |---|---|---| | expected | 12,853 | 12,841 | | 4eb6cfd | 10,369 | 15,325 | | 9c38609 | 12,853 | 12,841 | Step 1 is the same on both (12,853 translated now, 92 do not translate). A third pass on 9c38609: 0 translated now, 25,694 in the cache already, 0.9 s. Both caches end with 25,694 files, so only the report differed. One run of each step per build. Written with help from Claude; everything above was run on my machine.
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/441/head:github-bot/gh-441'
git switch 'github-bot/gh-441'

Merge

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