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

Merged
maaalrey merged 3 commits from upstream-pr/285 into main 2026-11-27 11:42:57 +00:00
maaalrey commented 2026-11-27 08:44:44 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by maaalrey on 2026-11-27T08:44:44Z.


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)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5523752503 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/285). Originally posted by [maaalrey](https://github.com/maaalrey) on 2026-11-27T08:44:44Z. --- ## 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)
LakshanSivakumar commented 2026-11-27 10:32:29 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:29Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216008005 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/285#issuecomment-7216008005). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:29Z. --- 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.
maaalrey commented 2026-11-27 10:50:42 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by maaalrey on 2026-11-27T10:50:42Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216372624 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/285#issuecomment-7216372624). Originally posted by [maaalrey](https://github.com/maaalrey) on 2026-11-27T10:50:42Z. --- 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.
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
LakshanSivakumar/Native-Victory-macOS!285
No description provided.