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

Open
ArturoWolff wants to merge 1 commit from upstream-pr/2072 into main
ArturoWolff commented 2026-11-29 09:06:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ArturoWolff on 2026-11-29T09:06:46Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549266733 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2072). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-29T09:06:46Z. --- ## What it changes Follow-up to #1607 (VlREX, `ca35e799`) and #1489 (FIocker, `4fd7f4db`), as discussed in [the regression report](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1607#issuecomment-7253403494). 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).
babuakhil commented 2026-11-29 23:37:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by babuakhil on 2026-11-29T23:37:53Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7264606230 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2072#issuecomment-7264606230). Originally posted by [babuakhil](https://github.com/babuakhil) on 2026-11-29T23:37:53Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2072:upstream-pr/2072'
git switch 'upstream-pr/2072'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2072'
git switch 'upstream-pr/2072'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2072'
git switch 'upstream-pr/2072'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2072'
git switch 'main'
git merge --squash 'upstream-pr/2072'
git switch 'main'
git merge --ff-only 'upstream-pr/2072'
git switch 'main'
git merge 'upstream-pr/2072'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!2072
No description provided.