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

Manually merged
github merged 2 commits from github-bot/gh-2710 into gh-pr/2710/base 2026-11-30 16:55:46 +00:00 AGit
Owner

@⁠Kal0s-design on GitHub · 2026-11-30 10:39 UTC · original
Kal0s-design:fix/wave-sections-unmatched-saveexec → main · +30 −1 · 1 files · 2 commits · merged 2026-11-30 16:49 UTC

Claimed in the coordination issue as: D3D12-SHADER-WAVE-SECTIONS-PAST-UNMATCHED-SAVEEXEC (#2570)

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

**@⁠Kal0s-design** on GitHub · 2026-11-30 10:39 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710) `Kal0s-design:fix/wave-sections-unmatched-saveexec` → `main` · +30 −1 · 1 files · 2 commits · merged 2026-11-30 16:49 UTC Claimed in the coordination issue as: D3D12-SHADER-WAVE-SECTIONS-PAST-UNMATCHED-SAVEEXEC (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570) ### 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)
wave::sections() looks in a block for whole-wave sections: a saveexec of
every lane, the code under it, and the EXEC restore that ends it. When a
saveexec's restore was not in the block (it lies in a later one), the scan
stopped there (`let Some(end) = end else { break; }`), so every whole-wave
section later in the same block was missed and its reduction translated
the general way instead of as the section's shape. Such a saveexec is no
section; the scan now goes on past it.

Test: an_unmatched_saveexec_leaves_the_later_sections_of_its_block puts an
unmatched s_or_saveexec_b64 before the wave64 OR reduction the other tests
use and expects that section and its shape at index 1. On main it fails
("the section after an unmatched saveexec", left None).

Port of shh's fix and test in the sibling VIctory tree (TaynanGT/Vice-Tay
17e3e2c, GPL-3.0). The shader cache key covers leonida-shader/src, so
cached translations are made again.

Co-Authored-By: shh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 10:41:28 +00:00
Author
Owner

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

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

**@⁠OreoFR** on GitHub · 2026-11-30 10:42 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7275977104) 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
Author
Owner

@⁠merzleckeier on GitHub · 2026-11-30 10:47 UTC · original

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.

**@⁠merzleckeier** on GitHub · 2026-11-30 10:47 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7276089025) **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.
Author
Owner

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

@⁠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

**@⁠MoonEyes** on GitHub · 2026-11-30 11:33 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7277192021) @⁠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
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-30 11:41 UTC · original

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

**@⁠Kal0s-design** on GitHub · 2026-11-30 11:41 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7277389913) 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
Author
Owner

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

@⁠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

**@⁠MoonEyes** on GitHub · 2026-11-30 12:06 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7277946288) @⁠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
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-30 12:10 UTC · original

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

**@⁠ecox982745** on GitHub · 2026-11-30 12:10 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7278060810) 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).
Author
Owner

@⁠OreoFR on GitHub · 2026-11-30 15:44 UTC · original

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

**@⁠OreoFR** on GitHub · 2026-11-30 15:44 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7283516122) **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).
Author
Owner

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

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

**@⁠MoonEyes** on GitHub · 2026-11-30 16:49 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2710#issuecomment-7285296132) 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).
github-bot changed target branch from main to gh-pr/2710/base 2026-11-30 16:55:42 +00:00
github manually merged commit 61945356f4 into gh-pr/2710/base 2026-11-30 16:55:45 +00:00
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!2710
No description provided.