Shader cache: translation failures are not cached, so every run re-translates the same refused programs (fix on a fork) #1089

Open
opened 2026-11-26 04:19:26 +00:00 by github-bot · 4 comments
Owner

@⁠lines9686-rgb on GitHub · 2026-11-24 15:38 UTC · original

Shaders that fail translation are translated again in every run. shader_cache.rs stores only successful translations: Translate::convert returns the error and victory-pipeline's cache keeps only Ok results. A program that fails therefore fails again on the next start, with the same input and the same result.

Measured on an RTX 3060 Ti, own 1.0.2.1 copy, five warm runs of one build:

  • About 400 programs fail translation in each run. 405 of the 408 failures in one run also failed in the run before.
  • The big compute ones fail 64–96 KiB into their code and take 2–3 s each on the 6 creation workers.
  • For about 1.5 min after world entry the workers do nothing but re-fail them. The per-frame summary shows 150–270 pipelines "being made" in every warm run, and their draws are dropped until the queue drains.

Why caching the error is safe: translation is a pure function of the container and of what build() already hashes (our executable and the loop limit). The same key gives the same error. A new build changes the key, so it tries again, and so does a new loop limit.

Change (one file, crates/victory-gpu/src/shader_cache.rs):

  • convert stores a failed translation as a VSF1 entry (magic, then the error text) under the same key.
  • cached returns Err(text) for such an entry and counts it as a hit.
  • A damaged VSF1 entry is treated like a damaged shader entry: it is a miss and is tried again.
  • The test assertion "Failures are not stored" is replaced by two tests:
    • failures_come_back_from_the_cache_too: a second lookup comes from disk, another build tries again, a damaged entry is retried;
    • failure_entries_round_trip_and_are_no_shader.

Branch: lines9686-rgb/VIctory@fail-cache (commit 1c2b2d6), one commit on main ffe310e. cargo test -p victory-gpu --lib shader_cache passes 4/4, and cargo clippy -p victory-gpu --all-targets -- -D warnings is clean. The changed file is rustfmt-clean. Other files on main show existing cargo fmt --check differences, which I left alone.

AI-assisted (Claude Code); measured on my machine with my own copy, nothing from the game attached.

**@⁠lines9686-rgb** on GitHub · 2026-11-24 15:38 UTC · [original](https://github.com/Marvisak/VIctory/issues/1089) Shaders that fail translation are translated again in every run. `shader_cache.rs` stores only successful translations: `Translate::convert` returns the error and `victory-pipeline`'s cache keeps only `Ok` results. A program that fails therefore fails again on the next start, with the same input and the same result. **Measured** on an RTX 3060 Ti, own 1.0.2.1 copy, five warm runs of one build: - About 400 programs fail translation in each run. 405 of the 408 failures in one run also failed in the run before. - The big compute ones fail 64–96 KiB into their code and take 2–3 s each on the 6 creation workers. - For about 1.5 min after world entry the workers do nothing but re-fail them. The per-frame summary shows 150–270 pipelines "being made" in every warm run, and their draws are dropped until the queue drains. **Why caching the error is safe:** translation is a pure function of the container and of what `build()` already hashes (our executable and the loop limit). The same key gives the same error. A new build changes the key, so it tries again, and so does a new loop limit. **Change** (one file, `crates/victory-gpu/src/shader_cache.rs`): - `convert` stores a failed translation as a `VSF1` entry (magic, then the error text) under the same key. - `cached` returns `Err(text)` for such an entry and counts it as a hit. - A damaged `VSF1` entry is treated like a damaged shader entry: it is a miss and is tried again. - The test assertion "Failures are not stored" is replaced by two tests: - `failures_come_back_from_the_cache_too`: a second lookup comes from disk, another build tries again, a damaged entry is retried; - `failure_entries_round_trip_and_are_no_shader`. Branch: [`lines9686-rgb/VIctory@fail-cache`](https://github.com/lines9686-rgb/VIctory/tree/fail-cache) (commit `1c2b2d6`), one commit on `main` `ffe310e`. `cargo test -p victory-gpu --lib shader_cache` passes 4/4, and `cargo clippy -p victory-gpu --all-targets -- -D warnings` is clean. The changed file is `rustfmt`-clean. Other files on `main` show existing `cargo fmt --check` differences, which I left alone. AI-assisted (Claude Code); measured on my machine with my own copy, nothing from the game attached.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:26 +00:00
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 15:42 UTC · original

Carried this to #1094, with @⁠lines9686-rgb's commit 1c2b2d6 unchanged and its authorship kept, since the issue says external PR creation is still restricted.

Verified on ffe310e with the commit applied (Windows 11, Rust 1.98.1): cargo test -p victory-gpu 52 passed / 1 ignored (50 before), cargo clippy -p victory-gpu --all-targets --all-features -D warnings clean, cargo build --release -p victory builds, and the changed file is rustfmt-clean.

I checked the three ways this could go wrong and none does: the key holds the build fingerprint, so a rebuilt translator retries rather than trusting a cached refusal; a truncated VSF1 entry decodes to nothing and is retried as a miss; and nothing outside host_shader reads the entry.

One thing that follows from it: the per-frame line queue.rs:270 reports hits and misses, and a cached refusal lands in hits now, so a run full of refusals shows a higher hit rate than it has translations. Fine, but the wording could say so. It also removes the need for the dedupe I raised on #638's VICTORY_DUMP_FAILED: the container is translated once per build now, so the dump is written once per hash.

**@⁠adamdotpy** on GitHub · 2026-11-24 15:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/1089#issuecomment-7136468159) Carried this to #1094, with @⁠lines9686-rgb's commit `1c2b2d6` unchanged and its authorship kept, since the issue says external PR creation is still restricted. Verified on `ffe310e` with the commit applied (Windows 11, Rust 1.98.1): `cargo test -p victory-gpu` 52 passed / 1 ignored (50 before), `cargo clippy -p victory-gpu --all-targets --all-features -D warnings` clean, `cargo build --release -p victory` builds, and the changed file is `rustfmt`-clean. I checked the three ways this could go wrong and none does: the key holds the build fingerprint, so a rebuilt translator retries rather than trusting a cached refusal; a truncated `VSF1` entry decodes to nothing and is retried as a miss; and nothing outside `host_shader` reads the entry. One thing that follows from it: the per-frame line `queue.rs:270` reports hits and misses, and a cached refusal lands in hits now, so a run full of refusals shows a higher hit rate than it has translations. Fine, but the wording could say so. It also removes the need for the dedupe I raised on #638's `VICTORY_DUMP_FAILED`: the container is translated once per build now, so the dump is written once per hash.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 15:42 UTC · original

Cross-check from ivall/xcl: we have this gap twice over, and your issue is the trigger to write it up on our side. (1) Your exact case: compile_cached_in_with on failure only bumps a counters.failure — no negative artifact — so a deterministically failing DXC compile re-pays the full compile every run (your measured per-run cost is our cold-boot tail too). (2) A worse upstream variant on us: translator refusals (the "X is not supported" errors — e.g. your #1062 log's 64-bit image atomic / untracked-mask select) occur before the DXIL cache exists, so refused programs are re-emitted from scratch every single launch, forever — our cold-boot time on mesh-storm titles is dominated by re-translating an unchanging refusal set.

The one trap your design (and ours) has to survive: negative-cache invalidation. A refusal is only as durable as the capability set that produced it — a translator update (your #1068 trio landing, our BCPack merge turning 512 refusals into successes) must not be poisoned by yesterday's marker. So the negative key must include everything the positive key includes plus anything capability-shaped: our positive key already folds toolchain identity; a negative entry additionally needs translator/spec revision and any config knob that changes lowering (wave mode, post-#1398: GVN-retry state) — or the strictly safer design: key the marker by the refusal reason string plus lowering-revision digest and refuse to trust markers whose digest drifted. If your measurements land per-program refusal timings, share them — on our side the same numbers would justify an xcl issue + a cache-version bump scheme, and both projects should converge on one invalidation story rather than invent two incompatible ones.

**@⁠pickles976** on GitHub · 2026-11-24 15:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/1089#issuecomment-7136470290) Cross-check from ivall/xcl: **we have this gap twice over**, and your issue is the trigger to write it up on our side. (1) Your exact case: `compile_cached_in_with` on failure only bumps a `counters.failure` — no negative artifact — so a deterministically failing DXC compile re-pays the full compile every run (your measured per-run cost is our cold-boot tail too). (2) A **worse upstream variant** on us: translator refusals (the "`X is not supported`" errors — e.g. your #1062 log's 64-bit image atomic / untracked-mask select) occur **before** the DXIL cache exists, so refused programs are re-emitted from scratch every single launch, forever — our cold-boot time on mesh-storm titles is dominated by re-translating an unchanging refusal set. The one trap your design (and ours) has to survive: **negative-cache invalidation**. A refusal is only as durable as the capability set that produced it — a translator update (your #1068 trio landing, our BCPack merge turning 512 refusals into successes) must *not* be poisoned by yesterday's marker. So the negative key must include everything the positive key includes **plus** anything capability-shaped: our positive key already folds toolchain identity; a negative entry additionally needs translator/spec revision and any config knob that changes lowering (wave mode, post-#1398: GVN-retry state) — or the strictly safer design: key the marker by the **refusal reason string plus lowering-revision digest** and refuse to trust markers whose digest drifted. If your measurements land per-program refusal timings, share them — on our side the same numbers would justify an xcl issue + a cache-version bump scheme, and both projects should converge on one invalidation story rather than invent two incompatible ones.
Author
Owner

@⁠lines9686-rgb on GitHub · 2026-11-24 15:46 UTC · original

Thanks @⁠adamdotpy for carrying it to #1094 and for checking it.

Hit-rate wording: agreed. A second commit on the same branch, lines9686-rgb/VIctory@fail-cache (HEAD), counts refusals found in the cache in their own counter. counts() now returns (hits, misses, refusals), and the per-frame line in queue.rs reports all three. Hits are only real translations now. cargo test -p victory-gpu --lib shader_cache passes 4/4 and clippy -D warnings is clean. If you want it in #1094, cherry-pick it as it is.

@⁠pickles976, on invalidation: here the key isn't a version number. It's the BLAKE3 of the whole executable plus the loop limit (build()). On stacks with #439 it is also keyed by the host's wave-lane range (key(build(), target)). Any change to the translator, or to a constant that changes lowering, produces a new executable and a new key, so every refusal is retried once per build. No marker can outlive the translator that wrote it. The one caveat is run-time switches that change lowering without changing the binary. Such a switch has to go into build()'s hash, as the loop limit already does. A diagnostics-only switch that changes translation (wave-mode experiments, for example) needs to be added there too.

Numbers, from the same machine (RTX 3060 Ti, Ryzen 5 5600, 6 creation workers):

refusals per run about 400
still refused in the next run of the same build 405 of 408
time per large compute refusal (failing 64–96 KiB into the code) 2–3 s
total spent re-failing about 1.5 min after world entry, with 150–270 pipelines "being made"

AI-assisted (Claude Code).

**@⁠lines9686-rgb** on GitHub · 2026-11-24 15:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/1089#issuecomment-7136596103) Thanks @⁠adamdotpy for carrying it to #1094 and for checking it. **Hit-rate wording:** agreed. A second commit on the same branch, [`lines9686-rgb/VIctory@fail-cache`](https://github.com/lines9686-rgb/VIctory/tree/fail-cache) (`HEAD`), counts refusals found in the cache in their own counter. `counts()` now returns `(hits, misses, refusals)`, and the per-frame line in `queue.rs` reports all three. Hits are only real translations now. `cargo test -p victory-gpu --lib shader_cache` passes 4/4 and clippy `-D warnings` is clean. If you want it in #1094, cherry-pick it as it is. @⁠pickles976, on invalidation: here the key isn't a version number. It's the BLAKE3 of the whole executable plus the loop limit (`build()`). On stacks with #439 it is also keyed by the host's wave-lane range (`key(build(), target)`). Any change to the translator, or to a constant that changes lowering, produces a new executable and a new key, so every refusal is retried once per build. No marker can outlive the translator that wrote it. The one caveat is run-time switches that change lowering without changing the binary. Such a switch has to go into `build()`'s hash, as the loop limit already does. A diagnostics-only switch that changes translation (wave-mode experiments, for example) needs to be added there too. Numbers, from the same machine (RTX 3060 Ti, Ryzen 5 5600, 6 creation workers): | | | |---|---| | refusals per run | about 400 | | still refused in the next run of the same build | 405 of 408 | | time per large compute refusal (failing 64–96 KiB into the code) | 2–3 s | | total spent re-failing | about 1.5 min after world entry, with 150–270 pipelines "being made" | AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:02 UTC · original

Automated triage for the maintainers.

This is fixed in main. Since c47b529 ("Shader warm-up (translate --cache), a cache keyed by the translator, pipeline queue fixes"), crates/victory-gpu/src/shader_cache.rs keeps a container that does not translate: encode writes a refusal entry (REFUSED magic plus the reason) and decode returns it as Err(reason), under the same key built by build() (translator source hash, the entry encoding and the loop limit). The file's header comment says so too. PR #1094, which carried this branch, has been closed.

Proposed close as fixed in main. The issue will be closed in 48 hours unless the reporter replies or a maintainer removes the label. If you see refused programs being translated again on current main with the cache enabled, please say so here.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/1089#issuecomment-7159137675) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-24T15:46:44Z at=2026-11-25T09:50:38Z --> Automated triage for the maintainers. This is fixed in `main`. Since c47b529 ("Shader warm-up (translate --cache), a cache keyed by the translator, pipeline queue fixes"), `crates/victory-gpu/src/shader_cache.rs` keeps a container that does not translate: `encode` writes a refusal entry (`REFUSED` magic plus the reason) and `decode` returns it as `Err(reason)`, under the same key built by `build()` (translator source hash, the entry encoding and the loop limit). The file's header comment says so too. PR #1094, which carried this branch, has been closed. Proposed close as fixed in `main`. The issue will be closed in 48 hours unless the reporter replies or a maintainer removes the label. If you see refused programs being translated again on current `main` with the cache enabled, please say so here. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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/Marvisak--VIctory#1089
No description provided.