GPU: a shader cache miss hands back its translation, not the entry read back #2053

Merged
0xkn0wh3r3 merged 1 commit from upstream-pr/2055 into main 2026-11-25 21:53:59 +00:00
0xkn0wh3r3 commented 2026-11-25 04:12:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T04:12:53Z.


The problem

A shader cache miss paid for a slow file read on top of the translation.

On a miss, shader_cache::cached had the cache write the new entry, then read and decoded that file to return it. The first read of a file just written is slow where a virus scanner looks at new files. Measured here (Windows Defender on):

entry first read after writing later read
8 KB about 0.5 ms 70-85 us
60 KB about 3.3 ms 70-85 us

That is on the order of a 1-12 ms translation. translate --cache misses on every container the first time (some 25,000), and a run misses on every shader not cached.

A second, smaller waste: when the entry could not be written, the shader was translated a second time.

The fix

  • The converter (Translate) now keeps the translation it encoded, and a miss returns it. Entries are read only on hits.
  • A translation whose entry could not be written is returned as made too, where it was translated a second time before.

Testing

  • New test shader_cache::tests::a_translation_is_made_once_when_its_entry_cannot_be_written: makes the cache folder unusable and checks the translation is made once. Passes; with the old fallback it fails (the translation runs twice). The existing translations_come_back_from_the_cache (hits, misses, damaged entries, refusals) still passes.
  • cargo test -p victory-gpu on an RTX 5070 Ti (driver 621.24): all pass except descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, which fail the same way on main (the NVIDIA 1,000,000-descriptor heap cap, #1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.
  • Not timed over a real translate --cache (no game data here); the per-entry read cost is from timings on this machine.
  • #1931, #1936 and #223 edit the same file for other reasons, so expect textual conflicts only.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6597045881 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2055). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T04:12:53Z. --- ## The problem A shader cache miss paid for a slow file read on top of the translation. On a miss, `shader_cache::cached` had the cache write the new entry, then read and decoded that file to return it. The first read of a file just written is slow where a virus scanner looks at new files. Measured here (Windows Defender on): | entry | first read after writing | later read | |---|---|---| | 8 KB | about 0.5 ms | 70-85 us | | 60 KB | about 3.3 ms | 70-85 us | That is on the order of a 1-12 ms translation. `translate --cache` misses on every container the first time (some 25,000), and a run misses on every shader not cached. A second, smaller waste: when the entry could not be written, the shader was translated a second time. ## The fix - The converter (`Translate`) now keeps the translation it encoded, and a miss returns it. Entries are read only on hits. - A translation whose entry could not be written is returned as made too, where it was translated a second time before. ## Testing - New test `shader_cache::tests::a_translation_is_made_once_when_its_entry_cannot_be_written`: makes the cache folder unusable and checks the translation is made once. Passes; with the old fallback it fails (the translation runs twice). The existing `translations_come_back_from_the_cache` (hits, misses, damaged entries, refusals) still passes. - `cargo test -p victory-gpu` on an RTX 5070 Ti (driver 621.24): all pass except `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, which fail the same way on `main` (the NVIDIA 1,000,000-descriptor heap cap, #1835). - `cargo clippy -p victory-gpu --all-targets`, with and without `--features diagnostics`: clean. ## Not covered / Related - Not timed over a real `translate --cache` (no game data here); the per-entry read cost is from timings on this machine. - #1931, #1936 and #223 edit the same file for other reasons, so expect textual conflicts only.
catminou4 commented 2026-11-25 05:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:32Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Shader-cache miss hands back its translation, not the entry read — cache race fix; subtle and important if the read raced with eviction.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051789417 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2055#pullrequestreview-6051789417). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:17:32Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Shader-cache miss hands back its translation, not the entry read — cache race fix; subtle and important if the read raced with eviction.
DenRakEiw commented 2026-11-25 05:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:50:02Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib shader_cache:: — 4 passed, 0 failed (including a_translation_is_made_once_when_its_entry_cannot_be_written)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix returning the in-memory translation on cache miss instead of re-reading from disk when the cache entry cannot be written. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052017852 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2055#pullrequestreview-6052017852). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:50:02Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib shader_cache::` — 4 passed, 0 failed (including `a_translation_is_made_once_when_its_entry_cannot_be_written`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean fix returning the in-memory translation on cache miss instead of re-reading from disk when the cache entry cannot be written. Looks good. AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-25 10:07:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:23:16Z.


Automated triage for the maintainers.
Merge candidate.

shader_cache::cached (crates/victory-gpu/src/shader_cache.rs) now returns the translation that Translate::convert just made on a miss. Main writes the entry and then reads and decodes the new file. When the entry cannot be written, the kept translation is returned instead of translating a second time. Checked against main:

  • Encoding: encode destructures every HostShader field and decode mirrors it, so an in-memory result matches what a later hit decodes. The existing round-trip test covers this.
  • Hits: hits still read the file. A broken entry is still caught on the next run's read.
  • Errors: the error path keeps the existing break fallback.
  • Test: the new test checks the translation runs once.
  • Overlap: #1200, #389 and #358 change the same fallback but predate main's current cached, and all three conflict with main. This PR merges cleanly and is smaller.

Recommending a look, not approving.

CI: not run (no check runs on the head commit).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158261088 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2055#issuecomment-7158261088). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:23:16Z. --- <!-- victory-triage v1 head=6d13eff16c9ab90fb1590cc5750cecc62229b649 verdict=merge-candidate at=2026-11-25T09:23:09Z --> Automated triage for the maintainers. **Merge candidate.** `shader_cache::cached` (crates/victory-gpu/src/shader_cache.rs) now returns the translation that `Translate::convert` just made on a miss. Main writes the entry and then reads and decodes the new file. When the entry cannot be written, the kept translation is returned instead of translating a second time. Checked against main: - Encoding: `encode` destructures every `HostShader` field and `decode` mirrors it, so an in-memory result matches what a later hit decodes. The existing round-trip test covers this. - Hits: hits still read the file. A broken entry is still caught on the next run's read. - Errors: the error path keeps the existing `break` fallback. - Test: the new test checks the translation runs once. - Overlap: #1200, #389 and #358 change the same fallback but predate main's current `cached`, and all three conflict with main. This PR merges cleanly and is smaller. Recommending a look, not approving. CI: not run (no check runs on the head commit). --- _Generated by [Claude Code](https://claude.ai/code)_
Xvania7 commented 2026-11-25 12:02:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T11:44:49Z.

Review: APPROVED


Verified 6d13eff on Windows 10 + NVIDIA GeForce RTX 5060:

  • shader_cache::tests:: (4 passed, including a_translation_is_made_once_when_its_entry_cannot_be_written)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings
  • cargo xtask policy: 182 files ok

Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6056995968 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2055#pullrequestreview-6056995968). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T11:44:49Z. **Review:** APPROVED --- Verified `6d13eff` on Windows 10 + NVIDIA GeForce RTX 5060: - `shader_cache::tests::` (4 passed, including `a_translation_is_made_once_when_its_entry_cannot_be_written`) - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings - `cargo xtask policy`: 182 files ok Approving.
upstream-sync closed this pull request 2026-11-25 22:03:23 +00:00
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
Marvisak/VIctory!2053
No description provided.