d3d12: the translator's test modules are no part of the shader cache key (D3D12-SHADER-KEY-NO-TESTS) #2777
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2777"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T18:21:33Z.
Claimed in the coordination issue as: D3D12-SHADER-KEY-NO-TESTS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7287477050)
What and why
leonida-shader/build.rshashes the crate's.rsfiles intoLEONIDA_SHADER_SOURCE_HASH, test modules (*_tests.rs) included. Since0baa9278cthat 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.
69837e53ahad left test modules out ofleonida-gpu's own fingerprint for exactly this reason (see the comment inleonida-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.rsout of both the hash and the scan. Each of those modules is declared under acfgwithtest, 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\:leonida-shader/src/source_hash_tests.rs, declared#[cfg(test)](they also run off Windows):the_source_hash_leaves_the_test_modules_outrecomputes the hash without the test modules and compares it with the built value;switches_only_tests_read_are_no_part_of_the_keychecks 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_onlychecks everymod *_tests;declaration.main'sbuild.rs, the first two fail: the hash differs, andLEONIDA_DIFF_ONLY is in the key's switches. With the change, all three pass. The third already holds onmain; 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 --checkandcheck_no_game_data.pyare clean.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
mainand merges cleanly.docs/design.md, with how it was confirmed. (Not applicable: the translator's output does not change.)Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T18:26:44Z.
Verified by OreoFR (another owner than TheGeogeo) on macOS 27.2.1, Apple M5, Rust (rustup),
main6cdc0a0d1merged with headaec6998a9.main+ only this PR'ssource_hash_tests.rsand itsmodline inlib.rs, without thebuild.rschange):cargo test --release -p leonida-shader source_hash: 1 passed, 2 failed:the_source_hash_leaves_the_test_modules_out(line 50) andswitches_only_tests_read_are_no_part_of_the_key(line 62).main+ this PR, merged): the same 3 tests pass; whole cratecargo test --release -p leonida-shader: 232 passed, 0 failed, 2 ignored.AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T18:30:59Z.
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.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).
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-30T20:31:09Z.
RUN (independent run on Windows, #2777 head
aec6998a9, merged locally into main6cdc0a0d1withgit merge --no-ff, no conflicts. The head still merges cleanly into maind8ca18240. 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 newsource_hash_testspass. (The PR says 389, counted on an older main.)cargo test -p leonida-gpu --lib shader_cacheon 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 inbuild.rs,lib.rsorsource_hash_tests.rs.build.rsback on the merge and the PR's tests kept,cargo test -p leonida-shader --lib source_hash_testsgives 1 passed / 2 failed.switches_only_tests_read_are_no_part_of_the_keyfails with "LEONIDA_DIFF_ONLY is in the key's switches", andthe_source_hash_leaves_the_test_modules_outfails because the hash differs.every_test_module_is_built_for_tests_onlyalready holds on main: it is the guard. With the PR'sbuild.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:
*_tests.rs(one comment line added) changes the source hash.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, amodline 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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T23:13:27Z.
RUN - VERIFY-2777-RTX4060 - by MoonEyes (another person than the author) on head
aec6998a9, with #2775 (58db554c7), #2777 (aec6998a9) and #2779 (4c36dba7c) merged together intomain407f71a23(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
maineec86d0fa+ 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).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T23:14:05Z.
Merging. Head
aec6998a9merges cleanly withmaine5d896f6dand 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).