d3d12: skip the lane-parking scan for programs with no lane save or restore, walk register sets by word #2780

Merged
bobcatchris merged 2 commits from upstream-pr/2780 into main 2026-11-30 20:13:32 +00:00
bobcatchris commented 2026-11-30 18:39:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-30T18:39:41Z.


Claim: D3D12-SHADER-IR-BUILD-CHEAP-PASSES in #2570.

What

Two cheap cuts in ir::build (d3d12/crates/leonida-shader/src/ir.rs), which every shader goes through:

  • unspill decodes the fields and the effects of every instruction to find scalars parked in VGPR lanes, though most programs have no v_writelane_b32 or v_readlane_b32. It now returns at once for a list without one; the scan is unchanged (unspill_scan) for the rest.
  • members (the register sets rename walks for every block) tested one bit of each of 513 registers; it now takes the set bits a word at a time. rename also sizes each block's live-out list once.

Measured

Full-archive leonida translate on the user's own shader archive, mimalloc build (--features diagnostics,mimalloc), 16 threads, Ryzen 7 7800X3D, four interleaved pairs against main (08e42a516, DXIL-hash build), values read from each run after the final edit:

main this branch
CPU (user + kernel), mean of 4 655.2 s 645.7 s (-1.5 %; three pairs of four lower)
wall, median of 4 50.0 s 49.9 s

It is a small gain: wall time is the same within the noise of the runs (48 to 55 s), and the profile put ir::build at about 12 % of the translator's samples before this and about 8 % after (different sample windows, so only an indication). Nothing is traded for it.

Equivalence

The DXIL of all 25 689 programs is identical to main's: blake3 and length of each, compared as multisets for five full runs (a scratch patch to translate.rs writes the hashes; not part of this PR). No game data in the PR or in this text.

Tests

  • New unspill_looks_only_where_the_code_has_a_save_or_a_restore_of_a_lane: hand-encoded lists (no lane at all, a pair parked and taken back, a save alone, a restore alone, a pair parked across a branch), both wave sizes. unspill and unspill_scan must give the same moves and the same instructions; the list without a lane must give none (negative control) and the others must give some. I broke each of three things on purpose (early-out checking only saves, checking only restores, skipping always) and the test failed each time.
  • cargo test -p leonida-shader --release: 387 passed, 0 failed, 5 ignored (before merging main); ir:: tests pass after the merge.
  • cargo clippy -p leonida-shader --release --all-targets: nothing in ir.rs.
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/ir.rs: clean.

AI-assisted: Claude Sonnet 5.5. Tested on an AMD RX 7900 XTX host (no GPU work here: translator only).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5571459277 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2780). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-30T18:39:41Z. --- Claim: D3D12-SHADER-IR-BUILD-CHEAP-PASSES in #2570. ## What Two cheap cuts in `ir::build` (`d3d12/crates/leonida-shader/src/ir.rs`), which every shader goes through: - `unspill` decodes the fields and the effects of every instruction to find scalars parked in VGPR lanes, though most programs have no `v_writelane_b32` or `v_readlane_b32`. It now returns at once for a list without one; the scan is unchanged (`unspill_scan`) for the rest. - `members` (the register sets `rename` walks for every block) tested one bit of each of 513 registers; it now takes the set bits a word at a time. `rename` also sizes each block's live-out list once. ## Measured Full-archive `leonida translate` on the user's own shader archive, mimalloc build (`--features diagnostics,mimalloc`), 16 threads, Ryzen 7 7800X3D, four interleaved pairs against main (`08e42a516`, DXIL-hash build), values read from each run after the final edit: | | main | this branch | |---|---|---| | CPU (user + kernel), mean of 4 | 655.2 s | 645.7 s (-1.5 %; three pairs of four lower) | | wall, median of 4 | 50.0 s | 49.9 s | It is a small gain: wall time is the same within the noise of the runs (48 to 55 s), and the profile put `ir::build` at about 12 % of the translator's samples before this and about 8 % after (different sample windows, so only an indication). Nothing is traded for it. ## Equivalence The DXIL of all 25 689 programs is identical to main's: blake3 and length of each, compared as multisets for five full runs (a scratch patch to `translate.rs` writes the hashes; not part of this PR). No game data in the PR or in this text. ## Tests - New `unspill_looks_only_where_the_code_has_a_save_or_a_restore_of_a_lane`: hand-encoded lists (no lane at all, a pair parked and taken back, a save alone, a restore alone, a pair parked across a branch), both wave sizes. `unspill` and `unspill_scan` must give the same moves and the same instructions; the list without a lane must give none (negative control) and the others must give some. I broke each of three things on purpose (early-out checking only saves, checking only restores, skipping always) and the test failed each time. - `cargo test -p leonida-shader --release`: 387 passed, 0 failed, 5 ignored (before merging main); `ir::` tests pass after the merge. - `cargo clippy -p leonida-shader --release --all-targets`: nothing in `ir.rs`. - `python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/ir.rs`: clean. AI-assisted: Claude Sonnet 5.5. Tested on an AMD RX 7900 XTX host (no GPU work here: translator only).
OreoFR commented 2026-11-30 18:42:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T18:42:04Z.


Checked by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup), main 8f41d7d01 merged with head 6c4474cfd.

  • MEASURED, cargo test --release -p leonida-shader: main 232 passed, 0 failed, 2 ignored; main + this PR 233 passed, 0 failed, 2 ignored. The extra one is the new unspill_looks_only_where_the_code_has_a_save_or_a_restore_of_a_lane.
  • Not shown: a red run. The new test sits in ir.rs next to the change, so it was not run against main's ir.rs here.
  • Not covered: the crate's Windows-only test modules, the output identity over the archive, and the translate-time gain.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7288237722 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2780#issuecomment-7288237722). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T18:42:04Z. --- Checked by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup), `main` `8f41d7d01` merged with head `6c4474cfd`. - MEASURED, `cargo test --release -p leonida-shader`: `main` 232 passed, 0 failed, 2 ignored; `main` + this PR 233 passed, 0 failed, 2 ignored. The extra one is the new `unspill_looks_only_where_the_code_has_a_save_or_a_restore_of_a_lane`. - Not shown: a red run. The new test sits in `ir.rs` next to the change, so it was not run against `main`'s `ir.rs` here. - Not covered: the crate's Windows-only test modules, the output identity over the archive, and the translate-time gain. AI-assisted: Claude Code
MoonEyes commented 2026-11-30 20:11:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:11:44Z.


RUN · VERIFY-2780-RTX4060 · by MoonEyes (another person than the author) on head 6c4474cfd, with #2745 (88d0dbf9c), #2773 (6bbaeed11), #2726 (986771506) and #2780 (6c4474cfd) merged into main 51dbc5b58. 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.
  • Game: two runs of 480 s, the person walking in the world from 345 s. First (shaders translated again: 132 s, pipelines warmed: 533 s): steady after 98 s, about 500 s of it. Second, warm: steady after 107 s, about 495 s of it, about 51 m walked. In both no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s. The picture was not looked at.
  • Translation at a first start 132 s here, 177 s on main 8f41d7d01 with 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290549405 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2780#issuecomment-7290549405). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T20:11:44Z. --- RUN · VERIFY-2780-RTX4060 · by MoonEyes (another person than the author) on head `6c4474cfd`, with #2745 (`88d0dbf9c`), #2773 (`6bbaeed11`), #2726 (`986771506`) and #2780 (`6c4474cfd`) merged into `main` `51dbc5b58`. 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. - Game: two runs of 480 s, the person walking in the world from 345 s. First (shaders translated again: 132 s, pipelines warmed: 533 s): steady after 98 s, about 500 s of it. Second, warm: steady after 107 s, about 495 s of it, about 51 m walked. In both no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s. The picture was not looked at. - Translation at a first start 132 s here, 177 s on `main` `8f41d7d01` with 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).
MoonEyes commented 2026-11-30 20:13:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:13:29Z.


Merging. Head 6c4474cfd merges cleanly with main 643cad411 and 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290591432 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2780#issuecomment-7290591432). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T20:13:29Z. --- Merging. Head `6c4474cfd` merges cleanly with `main` `643cad411` and 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).
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
ProjectLeonida/mandy!2780
No description provided.