D3D12-SHADER-ITE-LOSSY-MEMO: keep the results of Bools::ite in a table that forgets (-12 % of full-archive translate time) #2773
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2773"
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-30T18:01:37Z.
Claim: D3D12-SHADER-ITE-LOSSY-MEMO (claim in #2570).
What
Bools::iteinleonida-shader/src/structure.rs, the core of the lane-mask structuriser, kept every result in a hash map. A result depends on its triple alone, and the nodes made on the way to it stay in the diagram, so a result that is asked for again after it was dropped finds those nodes and makes none: the table can forget without the diagram, its node numbers or anything built from them changing.The results now live in
IteCache, a set-associative table of four 16-byte entries to a 64-byte line (newest of a set first). It doubles, keeping what it holds, while the diagram has more nodes than it has entries, up to one entry per possible node (MAX_NODES). A lookup touches one line (a hash map touches its control bytes and then the entry), and nothing is rehashed one entry at a time as it grows.Bools::mkalso makes a new node with one probe ofunique(entry) where it looked the key up and then inserted it.Safe Rust, no new dependency, no change to what any caller sees.
Measured
leonida translateof the whole archive, 16 threads on a Ryzen 7 7800X3D, built with--features diagnostics,mimalloc(the build the game uses), four interleaved pairs of this branch against main (08e42a516), final code:That is -12.5 % wall and -12.2 % CPU.
Sizing the table (measured with the first version of the index function, two runs of each): as many entries as nodes was the best of six settings; twice and four times as many entries as nodes, and a half, a quarter and an eighth as many, used 3 % to 19 % more user CPU.
DXIL is unchanged. Every emitted DXIL was hashed (blake3) and compared with a main binary built the same way: 25,689 programs, 15,799 distinct, the same multiset in all four runs of this branch.
Where it does not help: with the system heap (
cargo build --release -p leonida, the build ofREADME-fxceless.md) and 16 threads I measured no change: six interleaved pairs, CPU 908 s on main and 913 s here (+0.5 %, inside the run-to-run spread of the machine, which was busy: walls from 66 to 94 s). The translator on that build waits on the allocator, so time taken out of the diagram work does not show. I did not find out more than that.Tests
cargo test -p leonida-shader --release: 388 passed, 5 ignored. New:the_memo_keeps_the_newest_results_of_a_set_and_forgets_the_rest: of ten results put into one set, the last four are found, no other triple is.the_memo_grows_to_its_limit_and_keeps_what_it_holds.a_memo_that_forgets_gives_the_nodes_one_that_keeps_all_gives: 400 randomand/or/xor/not/iteover 8 variables on three diagrams (default memo, a memo of four entries that cannot grow, one with room for all): the same node at every step, the same node list at the end, and every function checked against its truth table over all 256 assignments. Asking the small one the whole script again makes no node.Negative controls: a lookup that ignores the third key of the triple, an insert that does not push the older entries down, a growth that drops its entries and a growth that ignores its limit each make at least one of them fail (I made each change, ran them, and reverted it).
Not in this pull request
Nothing from the game: no archive, shader, hash or log is in it, and
scripts/check_no_game_data.pyis clean on the one file. It does not touch my open #2726 (Bools::given), which edits other lines of the same file; whichever merges second takes a merge.AI-assisted: Claude Sonnet 5.5. Measured on an RX 7900 XTX machine (no GPU is used by
translate).Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T18:06:08Z.
Verified by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup),
mainad36782c6merged with head6bbaeed11.cargo test --release -p leonida-shader:main229 passed, 0 failed, 2 ignored;main+ this PR 232 passed, 0 failed, 2 ignored. The 3 new tests arethe_memo_keeps_the_newest_results_of_a_set_and_forgets_the_rest,the_memo_grows_to_its_limit_and_keeps_what_it_holdsanda_memo_that_forgets_gives_the_nodes_one_that_keeps_all_gives(the last one checks the forgetting memo against one that keeps everything).main's code.#[cfg(all(test, windows))]), the output identity over the archive and the -12 % translate time (they need the game's shaders).AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T18:19:03Z.
Independent check on Windows (not the author), at
6bbaeed11.cargo test --locked -p leonida-shader --lib(shared warm target): 388 passed, 0 failed, 5 ignored in 273.7 s.The -12% translate-time claim needs a corpus run, which I did not do; the crate's structural tests are green with the memo table.
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 MoonEyes on 2026-11-30T20:11:39Z.
RUN · VERIFY-2773-RTX4060 · by MoonEyes (another person than the author) on head
6bbaeed11, 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:29Z.
Merging. Head
6bbaeed11merges cleanly withmainb7934269dand 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).