D3D12-SHADER-STRUCTURE-GIVEN-FORCED: Bools::given from the literals a condition forces (translator -8% CPU, DXIL unchanged) #2726
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2726"
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 bobcatchris on 2026-11-30T13:33:43Z.
Claim: D3D12-SHADER-STRUCTURE-GIVEN-FORCED (comment).
AI-assisted: Claude Sonnet 5.5 (Cursor agent). No game files are in this pull request: the numbers are counts and times from running the translator on the author's own copy of the archive, and the tool that hashed the output was a local patch that is not part of it.
What
Bools::given(b, known)(the BDD behindstructure::structure) restrictedbby every atom thatknowndecides. It found the atoms one at a time: for each atom ofb, build the conjunction ofknownwith the atom's negation (and again with the atom) to compare it with 0. It is called fromLanes::finishfor each block's guards, branches and mask joins.It is now the restriction of
bby the literalsknownforces, found once per node ofknown(Bools::forced: a node's literals are what both children force, or the one child's plus the node's own atom where the other child is 0) and kept for the later calls on the same condition (bounded at 16 M literals, then it starts over). Where nothing satisfiesknownevery atombhas is decided both ways and the old code took them as true; that is kept (bat all-ones). The result is the same function, so the same node.Why
Counts from one
leonida translate <shaders.rpf>(LEONIDA_HOST_RDNA=1, 26,084 programs, 40.6 M IR instructions,--releaseat497bdd039, Ryzen 7 7800X3D, 16 threads; timers around each stage in a scratch build): 890 s of CPU, of them 330 instructure::structure, 313 of those in the 720 programs of 10,000 to 30,000 instructions (0.4 µs an instruction below 1,000 instructions, 28 µs there).finishis 114 s of the 330 andgivenis 97 s of that (1.52 M calls, 5.4 M atoms, 10.7 Mimplies). That is what a cold shader cache pays for the heavy compute programs on the translating threads before their first dispatch;docs/findings.mdhas the table (new section "Where the translator's time goes").Result
Same machine, same archive, alternating old and new builds of the same source plus a local patch that appends
blake3(dxil)of each emitted program to a file:(about 8 % of the CPU and 6 to 9 % of the wall clock; the wall clock ends on the longest program, so it gains less than the sum.)
Output unchanged: the DXIL of all 25,689 emitted programs (15,799 distinct; the rest are duplicate containers) hashes the same in all 9 runs (5 of the old build, 4 of the new), compared as multisets of (hash, length); the label of a duplicate container is whichever thread gets there first and differs between runs of the same build, which is why the labels are not compared.
Tests
given_as_the_forced_literals_of_what_is_known_gives_what_testing_each_atom_gave: keeps the old algorithm as the reference (given_anew) and compares it withgivenfor every pair of 72 random functions of 10 atoms (conjunctions of literals among them, as a block's reach is, and the constants), and asserts that the cases where the function changes, stays, or nothing is known each come up more than 10 times; it also checksforced's literals againstimpliesfor every atom and their variable order. Controlled: with the intersection's comparison of the two sides' values left out it fails (Bool(10) given Bool(14)).cargo test -p leonida-shader: 385 passed, 1 failed, 4 ignored. The one failure,emit::valu_tests::rdna_forms_give_what_the_spelled_out_ones_give(mad_legacy: written alike), fails the same onmainwithout this change (run with this file stashed); it is what #2624 fixes.structure::alone: 15 passed.cargo clippy -p leonida-shader --no-deps --all-targets: 3 warnings in the library and 7 in its tests, the same as onmain;Bools::restrictis only the test's reference now and is#[cfg(test)], so it adds none.python -I scripts/check_no_game_data.pyon both files: clean.leonida translatewithout--validateor--pipelines), so no GPU or driver to name.Not covered: the effect on a title's frame time (it is the translation, not the frame), and the other ~230 s of the BDD's
ite(masks_in_order,paths), which this does not touch.Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T14:36:11Z.
Independent check on Windows (not the author), at
986771506.cargo test --locked -p leonida-shader(pinned 1.98.1): 386 passed, 0 failed, 4 ignored in 247.9 s; doc-tests 0.scripts/build-nvidia.ps1(diag profile, featuresdiagnostics,mimalloc): succeeded in 1m 00s,leonida.exe20,209,152 bytes.given/forcedequivalence test runs as part of the suite.Machine: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), MSVC 14.52.37025, Rust 1.98.1 as pinned by
d3d12/rust-toolchain.toml.Not independently measured: the PR's -8% translator CPU claim (that needs a corpus work folder); this check covers correctness and that the d3d12 runtime still builds with the change.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T14:57:51Z.
Independent Linux truth-table and
guard_runscheckI tested
986771506merged ontomain232f9e603(treea6680ead) on CachyOS, Ryzen 7 7800X3D, Rust 1.98.1.cargo test --locked --offline -p leonida-shader --libpassed 228 tests onmainand 229 with the PR, with 2 ignored in each run.given(formula, known)for every pair of three-variable truth tables over all eight assignments. Both engines matched all 524,288 evaluations, including unsatisfiableknown. The PR also matched every evaluation with a test-only limit of 16 cached literals, which triggered 11 clears during this run. The production limit was used for the stock tests and benchmark.guard_runsbenchmark. I alternated nine pairs of optimized benchmark executables on one pinned CPU. Each cell shows the median of the nine per-program medians and their range, in microseconds.mainµsThe masked timings were lower in 9/9 short-run pairs and 8/9 long-run pairs. The unmasked ranges overlap. This benchmark measures structurisation on its synthetic fixtures. A second agent independently verified the oracle and recomputed the benchmark statistics. AI-assisted with OpenAI Codex.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:11:42Z.
RUN · VERIFY-2726-RTX4060 · by MoonEyes (another person than the author) on head
986771506, with #2745 (88d0dbf9c), #2773 (6bbaeed11), #2726 (986771506) and #2780 (6c4474cfd) merged intomain51dbc5b58. Windows 11 Pro 26300, RTX 4060 8 GB,-SeriesS -FrameGen 2, diag build.cargo test -p leonida-shader --locked: 400 passed;-p leonida-gpu: 580 passed; 0 failed.main8f41d7d01with two other pull requests: n=1 on each side and not the same tree, so no speed-up is claimed. The four pull requests were in one build.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:12:57Z.
Merging. Head
986771506merges cleanly withmain810651e15and does not force a rebase of #2566. Two runs in the game (RTX 4060, about 500 s steady each, no device loss) with #2745, #2773, #2726 and #2780 together on this head; cargo test green; checked by other people. The shaders are translated again at the first start. Merged by MoonEyes.AI-assisted (Claude Code).