d3d12: the translator's test modules are no part of the shader cache key (D3D12-SHADER-KEY-NO-TESTS) #2777

Manually merged
github merged 1 commit from github-bot/gh-2777 into gh-pr/2777/base 2026-11-30 23:17:59 +00:00 AGit
Owner

@⁠TheGeogeo on GitHub · 2026-11-30 18:21 UTC · original
TheGeogeo:d3d12-shader-key-no-tests → main · +105 −0 · 3 files · 1 commits · merged 2026-11-30 23:14 UTC

Claimed in the coordination issue as: D3D12-SHADER-KEY-NO-TESTS (#2570)

What and why

leonida-shader/build.rs hashes the crate's .rs files into LEONIDA_SHADER_SOURCE_HASH, test modules (*_tests.rs) included. Since 0baa9278c that hash is part of the shader cache key (translation_fingerprint, emit/mod.rs; shader_cache.rs).

The effect: a pull request that only adds or edits a translator test makes every player and tester translate all of the title's shaders again at their next start, and make their early pipelines again. That is several minutes on a 4060-class machine, for a translator that emits the same code. 69837e53a had left test modules out of leonida-gpu's own fingerprint for exactly this reason (see the comment in leonida-gpu/build.rs); the source hash brought them back in.

The switch-name scan in the same script has the same issue. Four names are read only by tests (LEONIDA_DIFF_ONLY, LEONIDA_EMIT_DUMP, LEONIDA_CONSOLE_DXC, LEONIDA_PROBE), and their values reached the key at run time.

This change makes the build script leave *_tests.rs out of both the hash and the scan. Each of those modules is declared under a cfg with test, so none can change what the translator emits. A new test guards that rule.

What it does not change: a real translator change still retranslates everything once, as #2710 did. That is legitimate. The key changes once with this pull request too.

Tested

On Windows 11, from d3d12\:

  • Three new tests in leonida-shader/src/source_hash_tests.rs, declared #[cfg(test)] (they also run off Windows):
    • the_source_hash_leaves_the_test_modules_out recomputes the hash without the test modules and compares it with the built value;
    • switches_only_tests_read_are_no_part_of_the_key checks that test-only switches are out of the key and that the translator's own (LEONIDA_GROUP_PACK, LEONIDA_MESH_COUNTS) are in;
    • every_test_module_is_built_for_tests_only checks every mod *_tests; declaration.
  • With main's build.rs, the first two fail: the hash differs, and LEONIDA_DIFF_ONLY is in the key's switches. With the change, all three pass. The third already holds on main; it is the guard.
  • cargo test -p leonida-shader --locked: 389 passed, 5 ignored. cargo test -p leonida-gpu --locked --lib shader_cache: 5 passed.
  • cargo clippy -p leonida-shader --all-targets --locked: nothing in the changed lines. git diff --check and check_no_game_data.py are clean.
  • It merges cleanly with #2750, the other open pull request on leonida-shader (git merge-tree).

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300 (the leonida-shader suite).

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: the translator's output does not change.)
**@⁠TheGeogeo** on GitHub · 2026-11-30 18:21 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2777) `TheGeogeo:d3d12-shader-key-no-tests` → `main` · +105 −0 · 3 files · 1 commits · merged 2026-11-30 23:14 UTC Claimed in the coordination issue as: D3D12-SHADER-KEY-NO-TESTS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570) ### What and why `leonida-shader/build.rs` hashes the crate's `.rs` files into `LEONIDA_SHADER_SOURCE_HASH`, test modules (`*_tests.rs`) included. Since 0baa9278c that hash is part of the shader cache key (`translation_fingerprint`, `emit/mod.rs`; `shader_cache.rs`). The effect: a pull request that only adds or edits a translator test makes every player and tester translate all of the title's shaders again at their next start, and make their early pipelines again. That is several minutes on a 4060-class machine, for a translator that emits the same code. 69837e53a had left test modules out of `leonida-gpu`'s own fingerprint for exactly this reason (see the comment in `leonida-gpu/build.rs`); the source hash brought them back in. The switch-name scan in the same script has the same issue. Four names are read only by tests (`LEONIDA_DIFF_ONLY`, `LEONIDA_EMIT_DUMP`, `LEONIDA_CONSOLE_DXC`, `LEONIDA_PROBE`), and their values reached the key at run time. This change makes the build script leave `*_tests.rs` out of both the hash and the scan. Each of those modules is declared under a `cfg` with `test`, so none can change what the translator emits. A new test guards that rule. What it does not change: a real translator change still retranslates everything once, as #2710 did. That is legitimate. The key changes once with this pull request too. ### Tested On Windows 11, from `d3d12\`: - Three new tests in `leonida-shader/src/source_hash_tests.rs`, declared `#[cfg(test)]` (they also run off Windows): - `the_source_hash_leaves_the_test_modules_out` recomputes the hash without the test modules and compares it with the built value; - `switches_only_tests_read_are_no_part_of_the_key` checks that test-only switches are out of the key and that the translator's own (`LEONIDA_GROUP_PACK`, `LEONIDA_MESH_COUNTS`) are in; - `every_test_module_is_built_for_tests_only` checks every `mod *_tests;` declaration. - With `main`'s `build.rs`, the first two fail: the hash differs, and `LEONIDA_DIFF_ONLY is in the key's switches`. With the change, all three pass. The third already holds on `main`; it is the guard. - `cargo test -p leonida-shader --locked`: 389 passed, 5 ignored. `cargo test -p leonida-gpu --locked --lib shader_cache`: 5 passed. - `cargo clippy -p leonida-shader --all-targets --locked`: nothing in the changed lines. `git diff --check` and `check_no_game_data.py` are clean. - It merges cleanly with #2750, the other open pull request on `leonida-shader` (`git merge-tree`). GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300 (the leonida-shader suite). AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Not applicable: the translator's output does not change.)
leonida-shader's build script hashed every .rs file of the crate, its
*_tests.rs modules included, into LEONIDA_SHADER_SOURCE_HASH, and since
0baa9278c that hash is part of the shader cache key
(translation_fingerprint). A pull request that only adds a translator test
made every player and tester translate all shaders again at the next start
and make their early pipelines again, which 69837e53a had ruled out for
leonida-gpu's own fingerprint. The switch-name scan in the same script also
put the switches only tests read (LEONIDA_DIFF_ONLY, LEONIDA_EMIT_DUMP,
LEONIDA_CONSOLE_DXC, LEONIDA_PROBE) into the key.

The build script now leaves *_tests.rs out of both. Each of those modules
is declared under a cfg with test, so none changes what the translator
emits. Three portable tests: the hash recomputed without the test modules
equals the built one; test-only switches are out of the key and the
translator's own are in; every `mod *_tests;` is test-only.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 18:24:51 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-11-30 18:26 UTC · original

Verified by OreoFR (another owner than TheGeogeo) on macOS 27.2.1, Apple M5, Rust (rustup), main 6cdc0a0d1 merged with head aec6998a9.

  • MEASURED, red (main + only this PR's source_hash_tests.rs and its mod line in lib.rs, without the build.rs change): cargo test --release -p leonida-shader source_hash: 1 passed, 2 failed: the_source_hash_leaves_the_test_modules_out (line 50) and switches_only_tests_read_are_no_part_of_the_key (line 62).
  • MEASURED, green (main + this PR, merged): the same 3 tests pass; whole crate cargo test --release -p leonida-shader: 232 passed, 0 failed, 2 ignored.
  • Not covered here: the crate's Windows-only test modules, and a real first run showing the cache key unchanged after a test-only change (needs the game).

AI-assisted: Claude Code

**@⁠OreoFR** on GitHub · 2026-11-30 18:26 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2777#issuecomment-7287859470) Verified by OreoFR (another owner than TheGeogeo) on macOS 27.2.1, Apple M5, Rust (rustup), `main` `6cdc0a0d1` merged with head `aec6998a9`. - MEASURED, red (`main` + only this PR's `source_hash_tests.rs` and its `mod` line in `lib.rs`, without the `build.rs` change): `cargo test --release -p leonida-shader source_hash`: **1 passed, 2 failed**: `the_source_hash_leaves_the_test_modules_out` (line 50) and `switches_only_tests_read_are_no_part_of_the_key` (line 62). - MEASURED, green (`main` + this PR, merged): the same 3 tests pass; whole crate `cargo test --release -p leonida-shader`: 232 passed, 0 failed, 2 ignored. - Not covered here: the crate's Windows-only test modules, and a real first run showing the cache key unchanged after a test-only change (needs the game). AI-assisted: Claude Code
Author
Owner

@⁠KelboLive on GitHub · 2026-11-30 18:30 UTC · original

Independent check on Windows (not the author), at aec6998a9.

  • cargo test --locked -p leonida-shader --lib (shared warm target, run alone): 389 passed, 0 failed, 5 ignored in 274.4 s.
  • That includes the new source_hash_tests (the_source_hash_leaves_the_test_modules_out, switches_only_tests_read_are_no_part_of_the_key, every_test_module_is_built_for_tests_only).

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.

AI-assisted: yes (opencode).

**@⁠KelboLive** on GitHub · 2026-11-30 18:30 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2777#issuecomment-7287962616) Independent check on Windows (not the author), at `aec6998a9`. - `cargo test --locked -p leonida-shader --lib` (shared warm target, run alone): **389 passed, 0 failed, 5 ignored** in 274.4 s. - That includes the new `source_hash_tests` (`the_source_hash_leaves_the_test_modules_out`, `switches_only_tests_read_are_no_part_of_the_key`, `every_test_module_is_built_for_tests_only`). Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. AI-assisted: yes (opencode).
Author
Owner

@⁠enlight3d on GitHub · 2026-11-30 20:31 UTC · original

RUN (independent run on Windows, #2777 head aec6998a9, merged locally into main 6cdc0a0d1 with git merge --no-ff, no conflicts. The head still merges cleanly into main d8ca18240. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with --locked, at low priority:

  • cargo test -p leonida-shader --no-fail-fast: main 387 passed / 0 failed / 5 ignored; merge 390 / 0 / 5. The 3 new source_hash_tests pass. (The PR says 389, counted on an older main.)
  • cargo test -p leonida-gpu --lib shader_cache on the merge: 5 passed.
  • cargo clippy -p leonida-shader --all-targets (without -D warnings, which already fails on main in leonida-shader), on main and on the merge: no warning in build.rs, lib.rs or source_hash_tests.rs.
  • Red, by assertion: with main's build.rs back on the merge and the PR's tests kept, cargo test -p leonida-shader --lib source_hash_tests gives 1 passed / 2 failed. switches_only_tests_read_are_no_part_of_the_key fails with "LEONIDA_DIFF_ONLY is in the key's switches", and the_source_hash_leaves_the_test_modules_out fails because the hash differs. every_test_module_is_built_for_tests_only already holds on main: it is the guard. With the PR's build.rs, all 3 pass.

The key no longer follows the test modules. I checked this with a local probe (a test I added locally, not pushed) that prints the built source hash and the number of switches in the key:

  • On main, editing another *_tests.rs (one comment line added) changes the source hash.
  • On the merge, the same edit leaves it unchanged.
  • The key's switches go from 60 to 56: the four that only tests read are out.

The translator's output does not change: the same probe translates 74 synthetic programs (VOP3 opcodes 0x100-0x17F, three registers each; the ones the translator refuses are skipped, the same on both sides) and hashes each DXIL. 74 programs on main, 74 on the merge, 74 identical byte for byte.

Not covered: the title's own programs. That needs game data. The code that emits them is unchanged; only build.rs, a mod line under #[cfg(test)] and a test file change.

No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

**@⁠enlight3d** on GitHub · 2026-11-30 20:31 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2777#issuecomment-7291052590) RUN (independent run on Windows, #2777 head aec6998a9, merged locally into main 6cdc0a0d1 with `git merge --no-ff`, no conflicts. The head still merges cleanly into main d8ca18240. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) Commands, in `d3d12/`, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with `--locked`, at low priority: - `cargo test -p leonida-shader --no-fail-fast`: main 387 passed / 0 failed / 5 ignored; merge 390 / 0 / 5. The 3 new `source_hash_tests` pass. (The PR says 389, counted on an older main.) - `cargo test -p leonida-gpu --lib shader_cache` on the merge: 5 passed. - `cargo clippy -p leonida-shader --all-targets` (without `-D warnings`, which already fails on main in leonida-shader), on main and on the merge: no warning in `build.rs`, `lib.rs` or `source_hash_tests.rs`. - Red, by assertion: with main's `build.rs` back on the merge and the PR's tests kept, `cargo test -p leonida-shader --lib source_hash_tests` gives 1 passed / 2 failed. `switches_only_tests_read_are_no_part_of_the_key` fails with "LEONIDA_DIFF_ONLY is in the key's switches", and `the_source_hash_leaves_the_test_modules_out` fails because the hash differs. `every_test_module_is_built_for_tests_only` already holds on main: it is the guard. With the PR's `build.rs`, all 3 pass. The key no longer follows the test modules. I checked this with a local probe (a test I added locally, not pushed) that prints the built source hash and the number of switches in the key: - On main, editing another `*_tests.rs` (one comment line added) changes the source hash. - On the merge, the same edit leaves it unchanged. - The key's switches go from 60 to 56: the four that only tests read are out. The translator's output does not change: the same probe translates 74 synthetic programs (VOP3 opcodes 0x100-0x17F, three registers each; the ones the translator refuses are skipped, the same on both sides) and hashes each DXIL. 74 programs on main, 74 on the merge, 74 identical byte for byte. Not covered: the title's own programs. That needs game data. The code that emits them is unchanged; only `build.rs`, a `mod` line under `#[cfg(test)]` and a test file change. No runtime/ C++ or Python in this PR, so no link or import check applies. Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.
github-bot changed target branch from main to gh-pr/2777/base 2026-11-30 23:17:58 +00:00
github manually merged commit aec6998a9d into gh-pr/2777/base 2026-11-30 23:17:59 +00:00
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-30 23:13 UTC · original

RUN - VERIFY-2777-RTX4060 - by MoonEyes (another person than the author) on head aec6998a9, with #2775 (58db554c7), #2777 (aec6998a9) and #2779 (4c36dba7c) merged together into main 407f71a23 (clean).

  • Machine: RTX 4060 8 GB, Windows 11, diag profile, features diagnostics,mimalloc, Series S, -FrameGen 2 (frame generation files absent, so off), BAR window off, texture budget 1024 MB.

  • In-game, standing in the prologue cell, 480 s asked each: 2 runs, 0 device lost, 0 panics, 0 exceptions, alive at the time limit. About 500 s in the world each. Frame rate median 18.7 (first start: shaders retranslated and pipelines made, 955 s) and 18.6 (warm, 167 s). p5 11.0 and 11.6. The lowest lines are the load and the window's end.

  • Tests on main eec86d0fa + the three (Windows): leonida 47, leonida-hle 223, leonida-gpu 582, leonida-shader 403, 0 failed.

  • #2777 in the run: the cache key changes once (the first start retranslates), the second start finds everything.

Limits: one card, the character standing still, a session that did not reach the open world. Values only, no game data.

AI-assisted (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-11-30 23:13 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2777#issuecomment-7294860561) RUN - VERIFY-2777-RTX4060 - by MoonEyes (another person than the author) on head `aec6998a9`, with #2775 (`58db554c7`), #2777 (`aec6998a9`) and #2779 (`4c36dba7c`) merged together into `main` `407f71a23` (clean). - **Machine:** RTX 4060 8 GB, Windows 11, diag profile, features diagnostics,mimalloc, Series S, `-FrameGen 2` (frame generation files absent, so off), BAR window off, texture budget 1024 MB. - **In-game, standing in the prologue cell, 480 s asked each:** 2 runs, **0 device lost, 0 panics, 0 exceptions**, alive at the time limit. About 500 s in the world each. Frame rate median 18.7 (first start: shaders retranslated and pipelines made, 955 s) and 18.6 (warm, 167 s). p5 11.0 and 11.6. The lowest lines are the load and the window's end. - **Tests on `main` `eec86d0fa` + the three (Windows):** leonida 47, leonida-hle 223, leonida-gpu 582, leonida-shader 403, 0 failed. - **#2777 in the run:** the cache key changes once (the first start retranslates), the second start finds everything. Limits: one card, the character standing still, a session that did not reach the open world. Values only, no game data. AI-assisted (Claude Code).
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-30 23:14 UTC · original

Merging. Head aec6998a9 merges cleanly with main e5d896f6d and does not force a rebase of #2566. CI green on this head. Red/green by enlight3d (and KelboLive, OreoFR where they posted) on it; in-game run on the RTX 4060 posted above (2 runs, 0 device lost, about 500 s in the world); leonida, leonida-hle, leonida-gpu and leonida-shader tests pass on main + the three. Merged by MoonEyes.

AI-assisted (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-11-30 23:14 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2777#issuecomment-7294873603) Merging. Head `aec6998a9` merges cleanly with `main` `e5d896f6d` and does not force a rebase of #2566. CI green on this head. Red/green by enlight3d (and KelboLive, OreoFR where they posted) on it; in-game run on the RTX 4060 posted above (2 runs, 0 device lost, about 500 s in the world); leonida, leonida-hle, leonida-gpu and leonida-shader tests pass on main + the three. Merged by MoonEyes. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!2777
No description provided.