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

Open
github-bot wants to merge 1 commit from github-bot/gh-1132 into main AGit
Owner

@⁠KainanP on GitHub · 2026-11-25 21:09 UTC · original
KainanP:fix/fingerprint-unset-vs-empty → main · +55 −8 · 1 files · 1 commits · open

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

**@⁠KainanP** on GitHub · 2026-11-25 21:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/1132) `KainanP:fix/fingerprint-unset-vs-empty` → `main` · +55 −8 · 1 files · 1 commits · open 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)
translation_fingerprint wrote NAME= followed by the value for every
switch, so an unset switch and one set to an empty value gave the same
bytes. VICTORY_STRICT_JOINS and VICTORY_MESH_OUTPUT_STRICT count as on
when merely set (var_os(..).is_some()), so a run with either set to
nothing translated differently but read translations cached without it.

An unset switch now writes NAME\0 and a set one NAME=value\0. The
encoding moves into switch_values, which a unit test drives with
synthetic values; the test fails with the old encoding.

Reported in #848 (bugs noticed in diffs, item 10).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:06 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1132/head:github-bot/gh-1132'
git switch 'github-bot/gh-1132'

Merge

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