d3d12 shader: find the wave sections after an unmatched saveexec (D3D12-SHADER-WAVE-SECTIONS-PAST-UNMATCHED-SAVEEXEC) #2710

Merged
Kal0s-design merged 2 commits from upstream-pr/2710 into main 2026-11-30 16:49:57 +00:00
Kal0s-design commented 2026-11-30 10:39:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T10:39:20Z.


Claimed in the coordination issue as: D3D12-SHADER-WAVE-SECTIONS-PAST-UNMATCHED-SAVEEXEC (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275699446)

What and why

emit::wave::sections() finds a block's whole-wave sections: a saveexec of every lane, the code under it, and the EXEC restore that ends it. Their reductions are then lowered from the recognised shape (Shape::Active and friends). When a saveexec's restore is not in the block (the restore lies in a later block), the scan stopped right there:

let Some(end) = end else {
    break;
};

Every whole-wave section later in that block was then missed, and its reduction was translated the general way instead of from its shape. Such a saveexec is no section, so the scan now skips it (i += 1; continue;) and keeps looking.

This is a port of shh's fix and test from the sibling VIctory tree (TaynanGT/Vice-Tay 17e3e2c, GPL-3.0), credited as co-author. That tree took it from an earlier Leonida commit that never reached this repository. The test is unchanged: it puts an unmatched s_or_saveexec_b64 in front of WAVE_OR_V7_TO_S7.

No translator version bump is needed: leonida-gpu/build.rs fingerprints leonida-shader/src, so cached translations are made again.

Tested

  • New emit::wave::tests::an_unmatched_saveexec_leaves_the_later_sections_of_its_block expects the OR section and its shape at index 1 after an unmatched saveexec, and no section at index 0. On main (012b79a67) it fails with the section after an unmatched saveexec (left None); with the change it passes.
  • cargo test -p leonida-shader --lib: 386 passed, 0 failed, 4 ignored.
  • cargo clippy -p leonida-shader --all-targets: no warning in wave.rs.
  • How many of the title's shaders change isn't measured here (that needs game data). Windows only; Linux and macOS are not covered.

GPUs tested: n/a (CPU unit tests)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: this fixes the section scan, not an instruction's semantics)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5563613508 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-30T10:39:20Z. --- Claimed in the coordination issue as: D3D12-SHADER-WAVE-SECTIONS-PAST-UNMATCHED-SAVEEXEC (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275699446) ### What and why `emit::wave::sections()` finds a block's whole-wave sections: a saveexec of every lane, the code under it, and the EXEC restore that ends it. Their reductions are then lowered from the recognised shape (`Shape::Active` and friends). When a saveexec's restore is **not in the block** (the restore lies in a later block), the scan stopped right there: ```rust let Some(end) = end else { break; }; ``` Every whole-wave section later in that block was then missed, and its reduction was translated the general way instead of from its shape. Such a saveexec is no section, so the scan now skips it (`i += 1; continue;`) and keeps looking. This is a port of shh's fix and test from the sibling VIctory tree (TaynanGT/Vice-Tay `17e3e2c`, GPL-3.0), credited as co-author. That tree took it from an earlier Leonida commit that never reached this repository. The test is unchanged: it puts an unmatched `s_or_saveexec_b64` in front of `WAVE_OR_V7_TO_S7`. No translator version bump is needed: `leonida-gpu/build.rs` fingerprints `leonida-shader/src`, so cached translations are made again. ### Tested - New `emit::wave::tests::an_unmatched_saveexec_leaves_the_later_sections_of_its_block` expects the OR section and its shape at index 1 after an unmatched saveexec, and no section at index 0. **On `main` (012b79a67) it fails** with `the section after an unmatched saveexec` (left `None`); with the change it passes. - `cargo test -p leonida-shader --lib`: 386 passed, 0 failed, 4 ignored. - `cargo clippy -p leonida-shader --all-targets`: no warning in `wave.rs`. - How many of the title's shaders change isn't measured here (that needs game data). Windows only; Linux and macOS are not covered. GPUs tested: n/a (CPU unit tests) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: this fixes the section scan, not an instruction's semantics) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OreoFR commented 2026-11-30 10:42:53 +00:00 (Migrated from github.com)

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


Verified by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1, cargo test -p leonida-shader, main 012b79a67, PR head 709a6bbb1. MEASURED:

  • red (main's emit/wave.rs + only this PR's test hunk): emit::wave::tests::an_unmatched_saveexec_leaves_the_later_sections_of_its_block FAILED, the section after an unmatched saveexec (wave.rs:1381).
  • green (main + this PR, merge --no-ff): that test ok; whole crate 229 passed, 2 ignored, 0 failed (main: 228 + this one).
  • Merges cleanly with main (#2566 is merged now).

Not covered: the effect on real shaders (how many translations change, DXIL validation, the image); this is the unit test only.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275977104 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7275977104). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T10:42:53Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1, `cargo test -p leonida-shader`, main 012b79a67, PR head 709a6bbb1. MEASURED: - red (main's `emit/wave.rs` + only this PR's test hunk): `emit::wave::tests::an_unmatched_saveexec_leaves_the_later_sections_of_its_block` **FAILED**, `the section after an unmatched saveexec` (`wave.rs:1381`). - green (main + this PR, `merge --no-ff`): that test **ok**; whole crate **229 passed**, 2 ignored, 0 failed (main: 228 + this one). - Merges cleanly with main (#2566 is merged now). Not covered: the effect on real shaders (how many translations change, DXIL validation, the image); this is the unit test only. AI-assisted: Claude Code
merzleckeier commented 2026-11-30 10:47:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T10:47:45Z.


Independent Linux and Wine verification of 709a6bbb1 against 012b79a67 with Rust 1.98.1. The PR also merges cleanly into 0568cd62e; the shader crate and Cargo inputs are identical for that merge.

  • CachyOS, cargo test --locked --offline -p leonida-shader --lib: 228 passed on main, 229 on the PR, 2 ignored on each. The PR's regression test also failed with the test hunk applied to main and passed with the fix.

  • MSVC x64 builds under Wine 11.22: all 10 stock emit::wave::tests passed on main and all 11 on the PR.

  • I added two local synthetic cases for Wave32 and Wave64. Each puts s_or_saveexec -1 and s_nand_saveexec 0 before two complete sections in one block, then uses an actual s_branch to the block that restores both outer masks. The cases check the two section boundaries and the constant each section produces. main found neither section in either wave width. The PR found both and returned the expected constants in both cases.

CPU-only synthetic tests. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7276089025 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7276089025). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T10:47:45Z. --- **Independent Linux and Wine verification** of `709a6bbb1` against `012b79a67` with Rust 1.98.1. The PR also merges cleanly into `0568cd62e`; the shader crate and Cargo inputs are identical for that merge. - CachyOS, `cargo test --locked --offline -p leonida-shader --lib`: 228 passed on `main`, 229 on the PR, 2 ignored on each. The PR's regression test also failed with the test hunk applied to `main` and passed with the fix. - MSVC x64 builds under Wine 11.22: all 10 stock `emit::wave::tests` passed on `main` and all 11 on the PR. - I added two local synthetic cases for Wave32 and Wave64. Each puts `s_or_saveexec -1` and `s_nand_saveexec 0` before two complete sections in one block, then uses an actual `s_branch` to the block that restores both outer masks. The cases check the two section boundaries and the constant each section produces. `main` found neither section in either wave width. The PR found both and returned the expected constants in both cases. CPU-only synthetic tests. AI-assisted with OpenAI Codex.
MoonEyes commented 2026-11-30 11:33:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T11:33:17Z.


@Kal0s-design could you merge current main into this branch (a merge, no rebase or force-push)? The two red checks on 709a6bbb1 (check and linux-python-and-viewer) show the same failing test names as main at 012b79a67, and main has had a fix since #2708.

OreoFR's and merzleckeier's results are on 709a6bbb1, so the red/green will need to be run again on the new head.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7277192021 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7277192021). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T11:33:17Z. --- @Kal0s-design could you merge current `main` into this branch (a merge, no rebase or force-push)? The two red checks on `709a6bbb1` (`check` and `linux-python-and-viewer`) show the same failing test names as `main` at `012b79a67`, and `main` has had a fix since #2708. OreoFR's and merzleckeier's results are on `709a6bbb1`, so the red/green will need to be run again on the new head. AI-assisted: yes
Kal0s-design commented 2026-11-30 11:41:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T11:41:59Z.


Done: merged main (d367675c7) into the branch, new head 61945356f (merge commit, no rebase or force-push of the PR's commit). cargo test -p leonida-shader --lib on the new head: 386 passed, 4 ignored, 0 failed.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7277389913 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7277389913). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-30T11:41:59Z. --- Done: merged `main` (`d367675c7`) into the branch, new head `61945356f` (merge commit, no rebase or force-push of the PR's commit). `cargo test -p leonida-shader --lib` on the new head: 386 passed, 4 ignored, 0 failed. AI-assisted: yes
MoonEyes commented 2026-11-30 12:06:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T12:06:04Z.


@OreoFR @merzleckeier could one of you run your red/green again on the new head 61945356f? Kal0s-design merged main (d367675c7) into the branch, and your results are on the previous head 709a6bbb1. CI there: 4 of 5 checks green, check still running.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7277946288 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7277946288). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T12:06:04Z. --- @OreoFR @merzleckeier could one of you run your red/green again on the new head `61945356f`? Kal0s-design merged `main` (`d367675c7`) into the branch, and your results are on the previous head `709a6bbb1`. CI there: 4 of 5 checks green, `check` still running. AI-assisted: yes
ecox982745 commented 2026-11-30 12:10:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-30T12:10:30Z.


Independent red/green and native RTX 4090 check of the updated head 61945356f. I merged it into ec1d85846 (tree 11d409073), then built both arms with Rust 1.98.1 MSVC in release mode on Windows 11.

  • The published regression test, copied by itself to the base, failed at the section after an unmatched saveexec (None instead of Active(Or, ...)). All 11 emit::wave::tests passed on the merged tree.
  • A separate synthetic Wave64 dispatch saves EXEC in the same block as a complete OR reduction and restores that outer mask in the target of an actual branch. The base recognized zero sections and emitted three group barriers. The PR recognized one section and emitted two. Both DXIL modules passed the pinned SDK 26100 validator, created hardware PSOs on the RTX 4090 (NVIDIA 616.64), and returned all 64 expected 0xffffffff words in three alternating runs per arm.

The test inputs were synthetic. The barrier count is for this case, and runtime timing remains unmeasured. AI-assisted with OpenAI Codex (GPT-6.2 Sol).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7278060810 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7278060810). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-30T12:10:30Z. --- Independent red/green and native RTX 4090 check of the updated head `61945356f`. I merged it into `ec1d85846` (tree `11d409073`), then built both arms with Rust 1.98.1 MSVC in release mode on Windows 11. - The published regression test, copied by itself to the base, failed at `the section after an unmatched saveexec` (`None` instead of `Active(Or, ...)`). All 11 `emit::wave::tests` passed on the merged tree. - A separate synthetic Wave64 dispatch saves EXEC in the same block as a complete OR reduction and restores that outer mask in the target of an actual branch. The base recognized zero sections and emitted three group barriers. The PR recognized one section and emitted two. Both DXIL modules passed the pinned SDK 26100 validator, created hardware PSOs on the RTX 4090 (NVIDIA 616.64), and returned all 64 expected `0xffffffff` words in three alternating runs per arm. The test inputs were synthetic. The barrier count is for this case, and runtime timing remains unmeasured. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
OreoFR commented 2026-11-30 15:44:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T15:44:57Z.


RUN - in-game gate (Verified by OreoFR), PROVISIONAL - RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11.

  • Base: main f9f3ec4c6; B = main + this PR at 61945356f (git merge --no-ff), diag build of leonida.exe.
  • Recipe: play-d3d12.ps1 -SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, standing in the world, 360 s per run (window: world +30 to +330 s). Each exe got a cold run and a throw-away run first; measured runs interleaved with main (A B B A).

Result: PASS - 0 device loss, 0 panics, every run alive at the end (cold run included).

Arm runs fps median p5 preparing (ms/frame)
main 4 24.53 (23.9-24.8) 20.35 30.3
main + #2710 2 24.30 (23.6, 25.0) 19.85 30.40
  • No fps regression: -0.9 %, within the ~4 % run-to-run noise on this machine.
  • One-time cost: the translator's fingerprint changes, so the first start translated every shader again before the title. It took 10.7 min to reach the title, against about 1 min. After that, the log's hits=/misses= line shows 41 misses in the cold run, 16 in the throw-away run and 0-1 in the measured runs. This is expected for any translator change.
  • Not measured: how many of the title's shaders the change affects (no counter for that), and image correctness beyond the run screenshots.

This run was AI-assisted (Claude Code, oreofr-agent).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283516122 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7283516122). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T15:44:57Z. --- **RUN - in-game gate (Verified by OreoFR), PROVISIONAL** - RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11. - **Base:** main `f9f3ec4c6`; B = main + this PR at `61945356f` (`git merge --no-ff`), diag build of `leonida.exe`. - **Recipe:** `play-d3d12.ps1 -SeriesS -NoDlss -NoFrameGen`, BAR 0, texture budget 1024, standing in the world, 360 s per run (window: world +30 to +330 s). Each exe got a cold run and a throw-away run first; measured runs interleaved with main (A B B A). **Result: PASS** - 0 device loss, 0 panics, every run alive at the end (cold run included). | Arm | runs | fps median | p5 | preparing (ms/frame) | |---|---|---|---|---| | main | 4 | 24.53 (23.9-24.8) | 20.35 | 30.3 | | main + #2710 | 2 | 24.30 (23.6, 25.0) | 19.85 | 30.40 | - **No fps regression:** -0.9 %, within the ~4 % run-to-run noise on this machine. - **One-time cost:** the translator's fingerprint changes, so the first start translated every shader again before the title. It took 10.7 min to reach the title, against about 1 min. After that, the log's `hits=/misses=` line shows 41 misses in the cold run, 16 in the throw-away run and 0-1 in the measured runs. This is expected for any translator change. - **Not measured:** how many of the title's shaders the change affects (no counter for that), and image correctness beyond the run screenshots. This run was AI-assisted (Claude Code, oreofr-agent).
MoonEyes commented 2026-11-30 16:49:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T16:49:54Z.


Merging. Head 61945356f merges cleanly with main 2a880c31d and does not force a rebase of #2566. Run in the game of 360 s, no device loss, posted on this head (OreoFR, RTX 4070 Laptop); red/green on RTX 4090 by another person; cargo test on Windows with main: leonida-shader 386 passed (main 385), 0 failed. First start after this retranslates the shaders. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285296132 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7285296132). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T16:49:54Z. --- Merging. Head `61945356f` merges cleanly with `main` `2a880c31d` and does not force a rebase of #2566. Run in the game of 360 s, no device loss, posted on this head (OreoFR, RTX 4070 Laptop); red/green on RTX 4090 by another person; cargo test on Windows with main: leonida-shader 386 passed (main 385), 0 failed. First start after this retranslates the shaders. 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!2710
No description provided.