shader cache: key on the translator's environment switches #285

Manually merged
github merged 3 commits from github-bot/gh-285 into main 2026-11-27 12:02:37 +00:00 AGit
Owner

@⁠maaalrey on GitHub · 2026-11-27 08:44 UTC · original
maaalrey:fix/shader-cache-keys-translation-switches → main · +137 −14 · 4 files · 3 commits · merged 2026-11-27 11:42 UTC

What this changes

Refs #284

The native shader cache keys on the translator's sources, the entry encoding, the loop limit and the translation Options. It doesn't key on the switches the translator reads from the environment while it translates: VICTORY_DEBUG_PS, VICTORY_DEBUG_PS_RED, VICTORY_DEBUG_VS_PARAM, VICTORY_DEBUG_VS_POS, VICTORY_DEBUG_VS_TRI and VICTORY_NO_LOCKSTEP. That has two effects:

  • On a warm cache, a debug switch does nothing: the translations made without it are served. I lost two bisection runs to this. VICTORY_DEBUG_PS_RED=1 VICTORY_DEBUG_VS_TRI=1 left every target black, because no shader was translated again.
  • A translation made with a switch is stored under the normal key, and later runs without the switch are served it.

victory_shader::emit::TRANSLATION_SWITCHES lists the switches, and translation_switches() returns those that are set as NAME=value lines, read once per process. shader_cache::build() hashes that text into the build key next to the loop limit, and logs a warning when any switch is set. Docs: native-host.md (the Translations cache entry) and the debug-graphics skill.

How it was tested

  • New tests:
    • the_key_covers_translator_encoding_and_settings now covers the switches.
    • the_translation_switches_list_only_those_set checks the listing.
    • every_environment_switch_the_translator_reads_is_keyed scans src/emit and fails when a VICTORY_ switch read there is in neither the translation list nor the short list of switches that are keyed another way or change no translation (VICTORY_SHADER_LOOP_LIMIT, VICTORY_WARP, VICTORY_PC_DXC, VICTORY_DXIL).
  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 381 passed, 0 failed
  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask -p victory-shader (arm64): all passed but described_rectangle_list_draw_uses_supplied_triangles. That test needs the Metal Shader Converter at its default path; it passes with VICTORY_MSC_DYLIB set.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean
  • cargo xtask policy: ok
  • Ran the game: not needed. The change is the cache key only; existing caches get a new build folder once.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none)
  • New diagnostics are behind a VICTORY_* variable and documented (none new; existing switches documented as keyed)
**@⁠maaalrey** on GitHub · 2026-11-27 08:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/285) `maaalrey:fix/shader-cache-keys-translation-switches` → `main` · +137 −14 · 4 files · 3 commits · merged 2026-11-27 11:42 UTC ## What this changes Refs #284 The native shader cache keys on the translator's sources, the entry encoding, the loop limit and the translation `Options`. It doesn't key on the switches the translator reads from the environment while it translates: `VICTORY_DEBUG_PS`, `VICTORY_DEBUG_PS_RED`, `VICTORY_DEBUG_VS_PARAM`, `VICTORY_DEBUG_VS_POS`, `VICTORY_DEBUG_VS_TRI` and `VICTORY_NO_LOCKSTEP`. That has two effects: - On a warm cache, a debug switch does nothing: the translations made without it are served. I lost two bisection runs to this. `VICTORY_DEBUG_PS_RED=1 VICTORY_DEBUG_VS_TRI=1` left every target black, because no shader was translated again. - A translation made with a switch is stored under the normal key, and later runs without the switch are served it. `victory_shader::emit::TRANSLATION_SWITCHES` lists the switches, and `translation_switches()` returns those that are set as `NAME=value` lines, read once per process. `shader_cache::build()` hashes that text into the build key next to the loop limit, and logs a warning when any switch is set. Docs: `native-host.md` (the Translations cache entry) and the debug-graphics skill. ## How it was tested - [x] New tests: - `the_key_covers_translator_encoding_and_settings` now covers the switches. - `the_translation_switches_list_only_those_set` checks the listing. - `every_environment_switch_the_translator_reads_is_keyed` scans `src/emit` and fails when a `VICTORY_` switch read there is in neither the translation list nor the short list of switches that are keyed another way or change no translation (`VICTORY_SHADER_LOOP_LIMIT`, `VICTORY_WARP`, `VICTORY_PC_DXC`, `VICTORY_DXIL`). - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: 381 passed, 0 failed - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask -p victory-shader` (arm64): all passed but `described_rectangle_list_draw_uses_supplied_triangles`. That test needs the Metal Shader Converter at its default path; it passes with `VICTORY_MSC_DYLIB` set. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: clean - [x] `cargo xtask policy`: ok - [x] Ran the game: not needed. The change is the cache key only; existing caches get a new build folder once. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none new; existing switches documented as keyed)
The native shader cache keyed on the translator's sources, the entry
encoding, the loop limit and the translation Options, but not on the
switches the translator reads from the environment while it translates
(VICTORY_DEBUG_PS, _PS_RED, _VS_PARAM, _VS_POS, _VS_TRI and
VICTORY_NO_LOCKSTEP). So on a warm cache a debug switch did nothing (the
translations made without it were served), and a translation made with
one was stored under the normal key and served to later runs without it.

victory_shader::emit::TRANSLATION_SWITCHES lists them, and
translation_switches() gives those set as NAME=value lines, read once
per process. shader_cache::build() hashes that text into the build key
next to the loop limit, and warns when any switch is set.

Tests: the key changes with the switches; translation_switches lists
only those set; and a scan of src/emit fails when a VICTORY_ switch read
there is in neither the translation list nor the short list of switches
that are keyed another way or change no translation.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:47:28 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 10:32 UTC · original

Thank you. Putting the debug switches into the cache key is right, and the test that fails when a new VICTORY_ switch is read in emit and listed nowhere is a good guard. Your workflow has not run; it needs my approval. The branch is behind main, please update it. I have not run it.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 10:32 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/285#issuecomment-7216008005) Thank you. Putting the debug switches into the cache key is right, and the test that fails when a new `VICTORY_` switch is read in `emit` and listed nowhere is a good guard. Your workflow has not run; it needs my approval. The branch is behind main, please update it. I have not run it.
Author
Owner

@⁠maaalrey on GitHub · 2026-11-27 10:50 UTC · original

Updated: main (ce2b786) merged in. The switch scan still passes with main's new code, so every VICTORY_ read in emit is listed. The cache-key tests pass, cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings is clean with and without --all-features, and cargo xtask policy is ok. Thanks for the review.

**@⁠maaalrey** on GitHub · 2026-11-27 10:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/285#issuecomment-7216372624) Updated: main (ce2b786) merged in. The switch scan still passes with main's new code, so every `VICTORY_` read in `emit` is listed. The cache-key tests pass, `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` is clean with and without `--all-features`, and `cargo xtask policy` is ok. Thanks for the review.
github manually merged commit b54fab429d into main 2026-11-27 12:02:37 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.