Shaders: share the per-key flight on cold cache misses #2072

Open
github-bot wants to merge 1 commit from github-bot/gh-2072 into main AGit
Owner

@⁠ArturoWolff on GitHub · 2026-11-29 09:06 UTC · original
ArturoWolff:fix/shader-cache-singleflight → main · +173 −27 · 2 files · 1 commits · open

What it changes

Follow-up to #1607 (VlREX, ca35e799) and #1489 (FIocker, 4fd7f4db), as discussed in the regression report. The current shader-specific decoded-cache path calls convert_and_store directly, bypassing the existing process-local per-key flight. Two overlapping cold misses for the same key can therefore translate twice.

  • Reuse the existing canonical-root per-key gate via a closure-scoped Cache::with_key_gate helper; keep the validated warm hit ungated.
  • Recheck decoded validity while holding the gate and translate only if still needed. Preserve independent-key progress and the successful in-memory result when publication fails or gate setup cannot open the cache root.
  • Keep the translation fingerprint, shader format, translation semantics and atomic publication unchanged.
  • Add deterministic synthetic regressions at the actual cold-miss boundary, including independent keys, canonical-root aliases, warm hits, persisted output and missing cache roots.

How it was tested

  • GPU/profile/wave sizes: not applicable; game-free cache fixtures, no title assets or GPU dispatch. Linux host, GE-Proton11-14, Rust 1.98.1, locked dependencies, MSVC Windows test binary.
  • Before: on 4d98ca87, the same-key fixture failed with two translation callbacks (expected one); the distinct-key fixture passed. Both cache source files are unchanged between that base and 829188e9.
  • After: on 829188e9 plus this patch, both concurrency fixtures pass, including exact returned shader equality, warm hits, expected file count, and completion of the distinct key while the first conversion is blocked.
  • cargo test --locked --offline -p victory-pipeline -j2: 13 passed. MSVC GPU test compile succeeded; under Wine the two concurrency tests and three fallback controls (warm/corrupt/unsupported, failed publication, missing root) passed, zero ignored. Full GPU/workspace tests, clippy and native Windows execution remain for CI; no full-suite green claim.
  • Independent read-only review of the exact two-file patch: no correctness blocker. cargo xtask policy --staged: 2 files OK. Whitespace check passed.

Limitations: process-local only; unsuccessful conversions/publications may serialize later same-key retries (as already discussed on #1607). A foreground caller can wait for an existing worker. No failure sharing or additional retry loop. Sampled-marker concurrency and global counter totals were reviewed statically, not separately exercised. Actual gameplay, startup-time improvement, FPS and physical memory savings are not established by these tests.

Checked for overlap

  • Searched open PRs for the same issue and reviewed relevant cache-file changes. Related: #1607, #1489, #1539/#632 (cross-process publication, not changed here), #1581 (fingerprint/pruning/hit tracking), #1575/#807 (cache-key switches), #636 and #1012 (older cache fallback/integrity work using the earlier wrapper). This is a focused integration of the two changes already merged, not a replacement for those other proposals.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

**@⁠ArturoWolff** on GitHub · 2026-11-29 09:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2072) `ArturoWolff:fix/shader-cache-singleflight` → `main` · +173 −27 · 2 files · 1 commits · open ## What it changes Follow-up to #1607 (VlREX, `ca35e799`) and #1489 (FIocker, `4fd7f4db`), as discussed in [the regression report](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/1607). The current shader-specific decoded-cache path calls `convert_and_store` directly, bypassing the existing process-local per-key flight. Two overlapping cold misses for the same key can therefore translate twice. - Reuse the existing canonical-root per-key gate via a closure-scoped `Cache::with_key_gate` helper; keep the validated warm hit ungated. - Recheck decoded validity while holding the gate and translate only if still needed. Preserve independent-key progress and the successful in-memory result when publication fails or gate setup cannot open the cache root. - Keep the translation fingerprint, shader format, translation semantics and atomic publication unchanged. - Add deterministic synthetic regressions at the actual cold-miss boundary, including independent keys, canonical-root aliases, warm hits, persisted output and missing cache roots. ## How it was tested - GPU/profile/wave sizes: not applicable; game-free cache fixtures, no title assets or GPU dispatch. Linux host, GE-Proton11-14, Rust 1.98.1, locked dependencies, MSVC Windows test binary. - Before: on `4d98ca87`, the same-key fixture failed with two translation callbacks (expected one); the distinct-key fixture passed. Both cache source files are unchanged between that base and `829188e9`. - After: on `829188e9` plus this patch, both concurrency fixtures pass, including exact returned shader equality, warm hits, expected file count, and completion of the distinct key while the first conversion is blocked. - `cargo test --locked --offline -p victory-pipeline -j2`: 13 passed. MSVC GPU test compile succeeded; under Wine the two concurrency tests and three fallback controls (warm/corrupt/unsupported, failed publication, missing root) passed, zero ignored. Full GPU/workspace tests, clippy and native Windows execution remain for CI; no full-suite green claim. - Independent read-only review of the exact two-file patch: no correctness blocker. `cargo xtask policy --staged`: 2 files OK. Whitespace check passed. Limitations: process-local only; unsuccessful conversions/publications may serialize later same-key retries (as already discussed on #1607). A foreground caller can wait for an existing worker. No failure sharing or additional retry loop. Sampled-marker concurrency and global counter totals were reviewed statically, not separately exercised. Actual gameplay, startup-time improvement, FPS and physical memory savings are not established by these tests. ## Checked for overlap - [x] Searched open PRs for the same issue and reviewed relevant cache-file changes. Related: #1607, #1489, #1539/#632 (cross-process publication, not changed here), #1581 (fingerprint/pruning/hit tracking), #1575/#807 (cache-key switches), #636 and #1012 (older cache fallback/integrity work using the earlier wrapper). This is a focused integration of the two changes already merged, not a replacement for those other proposals. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
Preserve decoded hits and the in-memory fallback from #1489 while reusing the per-key gate from #1607. Recheck under the gate before translation and keep independent keys concurrent. Add game-free regression coverage.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 09:12:07 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-29 23:37 UTC · original

Checked on native Windows 11 (Rust 1.98.1, pinned), applied on current main (41adb551); cherry-picks cleanly. Clippy on victory-pipeline is clean with -D warnings, and victory-gpu shows no new warnings in the touched files (the one in shader_cache.rs, an unused AtomicBool, is on main already; -D warnings on the crate stops at the 3 victory-shader errors that are on main too). The 14 victory-pipeline tests and 13 of the 14 shader_cache tests pass in all five runs, including the two new concurrency tests, missing_cache_root_still_yields_the_translation and key_gate_uses_canonical_root_and_releases_on_return. every_switch_of_the_translator_is_in_the_key fails, but it fails the same way on main (VICTORY_SCALAR_SPLITS, #3210).

It does what it says. I ran a throwaway test (not part of this PR) through cached on both main and this PR:

scenario main this PR
A held inside its translation, B asks for the same key (20 rounds) B translates as well, every round (2 translations) B waits for A, every round (1 translation)
16 threads released together on one cold key (50 rounds, 5 ms translation) 16 translations every round 1 translation every round
warm hit (2000 hits, debug build) ~123 µs each ~132 µs each, the same within noise

On main, every thread that misses translates, so the bypass is total, not occasional. With this PR every round ended with exactly one entry on disk and the same shader returned to every caller. The warm path still takes no gate.

A full cargo test -p victory-gpu --lib run sometimes fails a few unrelated tests (card_steps, texback, pipeline::host, menu) that pass when run alone. main does the same in its own runs (uav_pool, menu), so I don't think it's caused by this PR.

**@⁠babuakhil** on GitHub · 2026-11-29 23:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2072#issuecomment-7264606230) Checked on native Windows 11 (Rust 1.98.1, pinned), applied on current `main` (`41adb551`); cherry-picks cleanly. Clippy on `victory-pipeline` is clean with `-D warnings`, and `victory-gpu` shows no new warnings in the touched files (the one in `shader_cache.rs`, an unused `AtomicBool`, is on `main` already; `-D warnings` on the crate stops at the 3 `victory-shader` errors that are on `main` too). The 14 `victory-pipeline` tests and 13 of the 14 `shader_cache` tests pass in all five runs, including the two new concurrency tests, `missing_cache_root_still_yields_the_translation` and `key_gate_uses_canonical_root_and_releases_on_return`. `every_switch_of_the_translator_is_in_the_key` fails, but it fails the same way on `main` (`VICTORY_SCALAR_SPLITS`, #3210). **It does what it says.** I ran a throwaway test (not part of this PR) through `cached` on both `main` and this PR: | scenario | `main` | this PR | |---|---|---| | A held inside its translation, B asks for the same key (20 rounds) | B translates as well, every round (2 translations) | B waits for A, every round (1 translation) | | 16 threads released together on one cold key (50 rounds, 5 ms translation) | 16 translations every round | 1 translation every round | | warm hit (2000 hits, debug build) | ~123 µs each | ~132 µs each, the same within noise | On `main`, every thread that misses translates, so the bypass is total, not occasional. With this PR every round ended with exactly one entry on disk and the same shader returned to every caller. The warm path still takes no gate. A full `cargo test -p victory-gpu --lib` run sometimes fails a few unrelated tests (`card_steps`, `texback`, `pipeline::host`, `menu`) that pass when run alone. `main` does the same in its own runs (`uav_pool`, `menu`), so I don't think it's caused by this PR.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shader_cache.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2072/head:github-bot/gh-2072'
git switch 'github-bot/gh-2072'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2072'
git switch 'github-bot/gh-2072'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2072'
git switch 'github-bot/gh-2072'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2072'
git switch 'main'
git merge --squash 'github-bot/gh-2072'
git switch 'main'
git merge --ff-only 'github-bot/gh-2072'
git switch 'main'
git merge 'github-bot/gh-2072'
git push origin 'main'
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/trustno1-coder--VIctory-NVIDIA!2072
No description provided.