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

Manually merged
github merged 2 commits from github-bot/gh-2780 into main 2026-11-30 20:16:49 +00:00 AGit
Owner

@⁠bobcatchris on GitHub · 2026-11-30 18:39 UTC · original
bobcatchris:perf/d3d12-ir-unspill-early-out → main · +119 −7 · 1 files · 2 commits · merged 2026-11-30 20:13 UTC

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).

**@⁠bobcatchris** on GitHub · 2026-11-30 18:39 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2780) `bobcatchris:perf/d3d12-ir-unspill-early-out` → `main` · +119 −7 · 1 files · 2 commits · merged 2026-11-30 20:13 UTC 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).
`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 those. The scan itself is unchanged
for the rest (`unspill_scan`).

`members` (the register sets `rename` walks for every block) stepped through all
513 registers testing a bit each; it now takes the set bits a word at a time, and
`rename` sizes each block's live-out list once.

Measured on a full-archive `leonida translate` (mimalloc build, 16 threads, four
interleaved pairs against main): CPU 655.2 s -> 645.7 s (-1.5 %, three pairs of
four lower), wall unchanged within noise (median 50.0 s vs 49.9 s). The DXIL of
all 25 689 programs is identical to main's (blake3 of each, five runs).

New test: `unspill` leaves a list with no lane save or restore alone, and finds
the same parks as the scan for lists that have them; it fails if the early-out
skips a list that has one.

AI-assisted: Claude Sonnet 5.5
Co-authored-by: Cursor <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 18:41:22 +00:00
Author
Owner

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

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

**@⁠OreoFR** on GitHub · 2026-11-30 18:42 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2780#issuecomment-7288237722) 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
github manually merged commit 1808c4fd70 into main 2026-11-30 20:16:49 +00:00
Author
Owner

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

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** on GitHub · 2026-11-30 20:11 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2780#issuecomment-7290549405) 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).
Author
Owner

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

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).

**@⁠MoonEyes** on GitHub · 2026-11-30 20:13 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2780#issuecomment-7290591432) 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).
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!2780
No description provided.