Cache deterministic shader translation refusals across runs #230

Open
github-bot wants to merge 2 commits from github-bot/gh-230 into rx9070xt AGit
Owner

@⁠feanorsun on GitHub · 2026-11-26 06:09 UTC · original
feanorsun:fix/cache-deterministic-shader-refusals → rx9070xt · +432 −74 · 5 files · 2 commits · open

Refs #218 (item 1)

Store the reason from a final ShaderError::Unsupported under the same disk key as a successful translation. Reopening the cache returns that reason as an error and skips the translator. The record uses the pipeline cache's atomic write path. Existing success records still decode, and damaged records are retried.

An empty VICTORY_STRICT_JOINS or VICTORY_MESH_OUTPUT_STRICT enables strict mode. The key now distinguishes an empty switch from an unset one so a strict-mode refusal cannot carry over when the switch is removed.

Verification

On Windows, cargo test --offline --locked -j 1 -p victory-gpu --lib shader_cache::tests:: -- --list listed 6 tests. Running the same filter with --test-threads=1 passed all 6 (359 filtered out). The tests used only the CPU, temporary directories, fixed build fingerprints and synthetic inputs.

  • Before the fix, the reopen regression failed its call-count assertion with 2 translations. With the fix, dropping the cache and opening it again returned the same error on both requests with 1 translation in total. Changing the input or the build fingerprint triggered a fresh translation.
  • Other translation errors and cache I/O failures remain retryable. A simulated Malformed error containing “unsupported” succeeded on retry, as did a cache write after removing a file that blocked the cache directory.
**@⁠feanorsun** on GitHub · 2026-11-26 06:09 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/230) `feanorsun:fix/cache-deterministic-shader-refusals` → `rx9070xt` · +432 −74 · 5 files · 2 commits · open Refs #218 (item 1) Store the reason from a final `ShaderError::Unsupported` under the same disk key as a successful translation. Reopening the cache returns that reason as an error and skips the translator. The record uses the pipeline cache's atomic write path. Existing success records still decode, and damaged records are retried. An empty `VICTORY_STRICT_JOINS` or `VICTORY_MESH_OUTPUT_STRICT` enables strict mode. The key now distinguishes an empty switch from an unset one so a strict-mode refusal cannot carry over when the switch is removed. ## Verification On Windows, `cargo test --offline --locked -j 1 -p victory-gpu --lib shader_cache::tests:: -- --list` listed 6 tests. Running the same filter with `--test-threads=1` passed all 6 (359 filtered out). The tests used only the CPU, temporary directories, fixed build fingerprints and synthetic inputs. - Before the fix, the reopen regression failed its call-count assertion with 2 translations. With the fix, dropping the cache and opening it again returned the same error on both requests with 1 translation in total. Changing the input or the build fingerprint triggered a fresh translation. - Other translation errors and cache I/O failures remain retryable. A simulated `Malformed` error containing “unsupported” succeeded on retry, as did a cache write after removing a file that blocked the cache directory.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:02 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 22:42 UTC · original

Checked by reading the code on a-publier cd8dfc0 (head b524804, change 81ebb7b..b524804); I did not build or run it.

Rebase: 81ebb7b..b524804 conflicts in crates/victory-gpu/src/shader_cache.rs on cd8dfc0. cd8dfc0 still does not store refusals (test "Failures are not stored", shader_cache.rs:520). Two things change on the new base:

1. Refusals and version keying

  • On cd8dfc0 the key is TRANSLATOR_VERSION (shader_cache.rs:99-103, crates/victory-shader/src/lib.rs:29 = 1), not the translator's source hash as on 81ebb7b.
  • crates/victory-shader/src/lib.rs:21-28 says the version is left as it is for "shaders that did not translate before". The module doc says the same (shader_cache.rs:4-6: the store grows by the shaders a change made translate).
  • So a VSR1 record stored under that key would be served after the translator learns the construct, until someone bumps the version for another reason.
  • a-publier has since moved to 4eb6cfd, where #324 bumped the version to 2 (lib.rs:29) for an output change in emit/bitcode/opt.rs. That is the kind of unrelated bump the stale refusals would wait for. shader_cache.rs is unchanged there, so the point still stands.
  • cd8dfc0 already handles this for translations: entries carry the build that made them (encode, shader_cache.rs:316-320), cached_by spots entries from another build (:239-241), and precompile and VICTORY_SHADER_FRESH=1 translate them again (:166, :178). A VSR1 record with no build stamp cannot take part in that.
  • Suggested for the rebase: put the same source stamp in the refusal record. A refusal from another build could also just be retried, since refusals are few.
  • old in cached_by (:234, :256-260) is a HostShader. If a stale refusal now translates, do not count it in CHANGED. Per crates/victory-shader/src/lib.rs:25-28 that is not a reason to bump the version.

2. append_switch changes every key

  • The empty-vs-unset problem is real on cd8dfc0. lower.rs:5210 and lower.rs:13294 test var_os(..).is_some(), and the key writes NAME=\0 for both cases (shader_cache.rs:127-132).
  • append_switch (head shader_cache.rs:97) also changes the bytes for every unset switch, from NAME=\0 to NAME\0. So every existing key changes.
  • On 81ebb7b that did not matter, because each rebuild changed the key anyway. On cd8dfc0 keys are kept stable on purpose (:4-7, and VICTORY_PORT_CBV is appended only when on, :136-141). This change would make the next run translate the whole set again and orphan the old entries. If it goes in together with a version bump, that cost is paid anyway. If it goes in on its own, it is not.
  • Suggested: keep the current bytes for unset and non-empty values, and add a marker only when the value is empty.

Not checked: whether cd8dfc0 has ShaderError::Unsupported refusals that depend on anything outside build() and host_settings() (lower.rs:1517).

**@⁠adrianmjim** on GitHub · 2026-11-26 22:42 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/230#issuecomment-7204913994) Checked by reading the code on a-publier cd8dfc0 (head b524804, change 81ebb7b..b524804); I did not build or run it. Rebase: 81ebb7b..b524804 conflicts in `crates/victory-gpu/src/shader_cache.rs` on cd8dfc0. cd8dfc0 still does not store refusals (test "Failures are not stored", `shader_cache.rs:520`). Two things change on the new base: **1. Refusals and version keying** - On cd8dfc0 the key is `TRANSLATOR_VERSION` (`shader_cache.rs:99-103`, `crates/victory-shader/src/lib.rs:29` = 1), not the translator's source hash as on 81ebb7b. - `crates/victory-shader/src/lib.rs:21-28` says the version is left as it is for "shaders that did not translate before". The module doc says the same (`shader_cache.rs:4-6`: the store grows by the shaders a change made translate). - So a VSR1 record stored under that key would be served after the translator learns the construct, until someone bumps the version for another reason. - a-publier has since moved to 4eb6cfd, where #324 bumped the version to 2 (`lib.rs:29`) for an output change in `emit/bitcode/opt.rs`. That is the kind of unrelated bump the stale refusals would wait for. `shader_cache.rs` is unchanged there, so the point still stands. - cd8dfc0 already handles this for translations: entries carry the build that made them (`encode`, `shader_cache.rs:316-320`), `cached_by` spots entries from another build (`:239-241`), and `precompile` and `VICTORY_SHADER_FRESH=1` translate them again (`:166`, `:178`). A VSR1 record with no build stamp cannot take part in that. - Suggested for the rebase: put the same source stamp in the refusal record. A refusal from another build could also just be retried, since refusals are few. - `old` in `cached_by` (`:234`, `:256-260`) is a `HostShader`. If a stale refusal now translates, do not count it in `CHANGED`. Per `crates/victory-shader/src/lib.rs:25-28` that is not a reason to bump the version. **2. `append_switch` changes every key** - The empty-vs-unset problem is real on cd8dfc0. `lower.rs:5210` and `lower.rs:13294` test `var_os(..).is_some()`, and the key writes `NAME=\0` for both cases (`shader_cache.rs:127-132`). - `append_switch` (head `shader_cache.rs:97`) also changes the bytes for every unset switch, from `NAME=\0` to `NAME\0`. So every existing key changes. - On 81ebb7b that did not matter, because each rebuild changed the key anyway. On cd8dfc0 keys are kept stable on purpose (`:4-7`, and `VICTORY_PORT_CBV` is appended only when on, `:136-141`). This change would make the next run translate the whole set again and orphan the old entries. If it goes in together with a version bump, that cost is paid anyway. If it goes in on its own, it is not. - Suggested: keep the current bytes for unset and non-empty values, and add a marker only when the value is empty. Not checked: whether cd8dfc0 has `ShaderError::Unsupported` refusals that depend on anything outside `build()` and `host_settings()` (`lower.rs:1517`).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/ambient.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/pipeline/make.rs
  • 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/230/head:github-bot/gh-230'
git switch 'github-bot/gh-230'

Merge

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