Shader cache key: a switch set to nothing keys apart from an unset one #1129

Open
KainanP wants to merge 1 commit from upstream-pr/1132 into main
KainanP commented 2026-11-25 21:09:02 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-25T21:09:02Z.


Refs #848 (section 3, "Bugs noticed in diffs", item 10).

The bug

emit::translation_fingerprint (the shader cache key, used by victory-gpu's shader_cache::build) wrote NAME= followed by the value for every switch the translator reads. An unset switch and a switch set to an empty value produced the same bytes.

Two switches that change the translation count as on when they are merely set:

  • VICTORY_STRICT_JOINS (lower.rs, var_os(..).is_some()): joins read only by another join are checked, and about 40 programs stop by name.
  • VICTORY_MESH_OUTPUT_STRICT (lower.rs, var_os(..).is_some()): mesh shaders past the 32 KiB output cap are refused.

So a run with VICTORY_STRICT_JOINS= (empty, e.g. VICTORY_STRICT_JOINS= wine victory.exe ... or SetEnvironmentVariable(name, "") from a launcher) translates with strict joins. But it gets the cache key of a run without the switch, and reads translations made without it. The reverse also happens.

The fix

An unset switch now writes NAME\0 and a set one writes NAME=value\0, so the two can't collide. Environment values can't contain NUL, so a value can't run into the next name. The loop moves into switch_values(out, names, value), which takes the lookup as a closure so a test can drive it with synthetic values. Every existing key changes once, but so does every edit to the translator source (VICTORY_SHADER_SOURCE_HASH), so a stale entry is just a cache miss.

Tested

  • New test emit::tests::a_switch_set_to_nothing_keys_apart_from_an_unset_one. It fails with the old encoding (assertion left != right failed: the unset and empty keys were byte-identical) and passes with the fix. It also checks that both switches are in the real VICTORY_SHADER_SWITCHES list.
  • cargo test -p victory-shader --lib: 216 passed, 0 failed, 3 ignored. Windows 11, RTX 4060 Laptop + Intel UHD hybrid laptop, default adapter, Rust 1.98.1 MSVC.
  • cargo test -p victory-gpu --lib shader_cache: 2 passed.
  • cargo clippy -p victory-shader --all-targets --locked: nothing new. rustfmt --check reports nothing in the changed lines.

Not tested

  • No title run. Nothing here needs one: the change only affects the cache key bytes.
  • I did not run the suite on WARP or the Intel UHD separately, because the change has no GPU code.

AI use: Claude Code (Claude Opus 5.5) found the affected switches, wrote the change and the test, and ran the commands above on my machine. No game files were used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6613799874 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1132). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-25T21:09:02Z. --- Refs #848 (section 3, "Bugs noticed in diffs", item 10). ## The bug `emit::translation_fingerprint` (the shader cache key, used by `victory-gpu`'s `shader_cache::build`) wrote `NAME=` followed by the value for every switch the translator reads. An unset switch and a switch set to an empty value produced the same bytes. Two switches that change the translation count as on when they are merely set: - `VICTORY_STRICT_JOINS` (`lower.rs`, `var_os(..).is_some()`): joins read only by another join are checked, and about 40 programs stop by name. - `VICTORY_MESH_OUTPUT_STRICT` (`lower.rs`, `var_os(..).is_some()`): mesh shaders past the 32 KiB output cap are refused. So a run with `VICTORY_STRICT_JOINS=` (empty, e.g. `VICTORY_STRICT_JOINS= wine victory.exe ...` or `SetEnvironmentVariable(name, "")` from a launcher) translates with strict joins. But it gets the cache key of a run without the switch, and reads translations made without it. The reverse also happens. ## The fix An unset switch now writes `NAME\0` and a set one writes `NAME=value\0`, so the two can't collide. Environment values can't contain NUL, so a value can't run into the next name. The loop moves into `switch_values(out, names, value)`, which takes the lookup as a closure so a test can drive it with synthetic values. Every existing key changes once, but so does every edit to the translator source (`VICTORY_SHADER_SOURCE_HASH`), so a stale entry is just a cache miss. ## Tested - New test `emit::tests::a_switch_set_to_nothing_keys_apart_from_an_unset_one`. It fails with the old encoding (`assertion left != right failed`: the unset and empty keys were byte-identical) and passes with the fix. It also checks that both switches are in the real `VICTORY_SHADER_SWITCHES` list. - `cargo test -p victory-shader --lib`: 216 passed, 0 failed, 3 ignored. Windows 11, RTX 4060 Laptop + Intel UHD hybrid laptop, default adapter, Rust 1.98.1 MSVC. - `cargo test -p victory-gpu --lib shader_cache`: 2 passed. - `cargo clippy -p victory-shader --all-targets --locked`: nothing new. `rustfmt --check` reports nothing in the changed lines. ## Not tested - No title run. Nothing here needs one: the change only affects the cache key bytes. - I did not run the suite on WARP or the Intel UHD separately, because the change has no GPU code. AI use: Claude Code (Claude Opus 5.5) found the affected switches, wrote the change and the test, and ran the commands above on my machine. No game files were used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/1132:upstream-pr/1132'
git switch 'upstream-pr/1132'

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/1132'
git switch 'upstream-pr/1132'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1132'
git switch 'upstream-pr/1132'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1132'
git switch 'main'
git merge --squash 'upstream-pr/1132'
git switch 'main'
git merge --ff-only 'upstream-pr/1132'
git switch 'main'
git merge 'upstream-pr/1132'
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
fxceless/victory-fork!1129
No description provided.