Shaders: continue scanning wave sections past an unmatched saveexec #3185

Open
reeledMarek wants to merge 2 commits from upstream-pr/3187 into main
reeledMarek commented 2026-11-26 11:28:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T11:28:33Z.


Summary

  • In crates/victory-shader/src/emit/wave.rs, sections() exited the basic-block scan loop with break whenever an s_or_saveexec_* -1 / s_nand_saveexec_* 0 had no matching EXEC restore in the same basic block.
  • That caused any subsequent whole-wave reduction/scan section later in the same block to be silently skipped.
  • Advance i += 1; continue; instead of break.

Testing

  • Added unmatched_saveexec_does_not_skip_later_wave_sections_in_block in crates/victory-shader/src/emit/wave.rs (fails on main, passes with the fix).
  • Verified cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings and cargo test -p xtask --locked pass.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5509202331 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T11:28:33Z. --- ## Summary - In `crates/victory-shader/src/emit/wave.rs`, `sections()` exited the basic-block scan loop with `break` whenever an `s_or_saveexec_* -1` / `s_nand_saveexec_* 0` had no matching `EXEC` restore in the same basic block. - That caused any subsequent whole-wave reduction/scan section later in the same block to be silently skipped. - Advance `i += 1; continue;` instead of `break`. ## Testing - Added `unmatched_saveexec_does_not_skip_later_wave_sections_in_block` in `crates/victory-shader/src/emit/wave.rs` (fails on `main`, passes with the fix). - Verified `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` and `cargo test -p xtask --locked` pass.
Dukestar69 commented 2026-11-26 11:49:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T11:49:13Z.

Review: APPROVED


Verified against origin/main (63bcca4):

  • cargo test -p victory-shader --lib emit::wave:: -- --test-threads=1: passed.
  • cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1: 33/33 passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly continues scanning wave sections past an unmatched saveexec.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6073626126 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187#pullrequestreview-6073626126). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T11:49:13Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib emit::wave:: -- --test-threads=1`: passed. - `cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1`: 33/33 passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly continues scanning wave sections past an unmatched `saveexec`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
cloph-dsp commented 2026-11-26 12:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T11:44:25Z.


Independent local verification of head d097c31 on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-shader --lib emit::wave::tests::unmatched_saveexec_does_not_skip_later_wave_sections_in_block -- --exact — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

CPU-only synthetic unit test; no D3D12 device or game assets used. Worktree-local CARGO_TARGET_DIR. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7191105971 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187#issuecomment-7191105971). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T11:44:25Z. --- Independent local verification of head `d097c31` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-shader --lib emit::wave::tests::unmatched_saveexec_does_not_skip_later_wave_sections_in_block -- --exact` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. CPU-only synthetic unit test; no D3D12 device or game assets used. Worktree-local `CARGO_TARGET_DIR`. AI-assisted (Hy4 flash).
oni-swr commented 2026-11-26 12:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T11:47:11Z.


WARP verification of #3187 (head d097c310a40be0364c960293390a7e643b4c2265)

Environment: Windows 11 Pro 10.0.26200; WARP D3D10Warp.dll 10.0.26100.9818 (VICTORY_D3D12_WARP=1, physical GPU not used); dxil.dll and dxc.exe 1.8.2502.11 from Windows SDK 10.0.26100.0 (VICTORY_DXIL points at that dxil.dll); rustc 1.98.1.

Commands (CARGO_TARGET_DIR on a scratch dir):
cargo test -p victory-shader --lib -j 4 --locked -- --test-threads=1, on the PR head and on the merge-base with main (63bcca43c6a00a758510398fa43096ce7e4f7df0).

Run Result
PR head 303 passed, 0 failed, 3 ignored (includes emit::wave::tests::unmatched_saveexec_does_not_skip_later_wave_sections_in_block)
merge-base (main) 302 passed, 0 failed, 3 ignored (the new test doesn't exist there)
PR head with only the wave.rs fix reverted (i += 1; continue; back to break;), test kept new test FAILED: "later matched section in the same block must still be discovered"

Defects found: none. The loop still advances i on the continue path, so it can't spin, and the diff touches only wave.rs. The test fails without the fix and passes with it.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Test report only, no code changes. Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7190976040

<!-- greyfinch-sync:Marvisak/VIctory:comment:7191163692 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187#issuecomment-7191163692). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T11:47:11Z. --- ## WARP verification of #3187 (head `d097c310a40be0364c960293390a7e643b4c2265`) **Environment:** Windows 11 Pro 10.0.26200; WARP `D3D10Warp.dll` 10.0.26100.9818 (`VICTORY_D3D12_WARP=1`, physical GPU not used); `dxil.dll` and `dxc.exe` 1.8.2502.11 from Windows SDK 10.0.26100.0 (`VICTORY_DXIL` points at that `dxil.dll`); rustc 1.98.1. **Commands** (`CARGO_TARGET_DIR` on a scratch dir): `cargo test -p victory-shader --lib -j 4 --locked -- --test-threads=1`, on the PR head and on the merge-base with `main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`). | Run | Result | |---|---| | PR head | 303 passed, 0 failed, 3 ignored (includes `emit::wave::tests::unmatched_saveexec_does_not_skip_later_wave_sections_in_block`) | | merge-base (main) | 302 passed, 0 failed, 3 ignored (the new test doesn't exist there) | | PR head with only the `wave.rs` fix reverted (`i += 1; continue;` back to `break;`), test kept | new test **FAILED**: "later matched section in the same block must still be discovered" | **Defects found:** none. The loop still advances `i` on the `continue` path, so it can't spin, and the diff touches only `wave.rs`. The test fails without the fix and passes with it. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Test report only, no code changes. Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7190976040
futurepro62 commented 2026-11-26 22:30:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T22:30:02Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head d097c31 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: unmatched_saveexec_does_not_skip_later_wave_sections_in_block.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7204733060 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187#issuecomment-7204733060). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T22:30:02Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head `d097c31` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `unmatched_saveexec_does_not_skip_later_wave_sections_in_block`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
fuzeofficlal commented 2026-11-26 23:13:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:13:29Z.

Review: CHANGES_REQUESTED


Thanks for tracking down the early break when an unmatched saveexec precedes a clean reduction section. Continuing to scan past unmatched saves exposes a couple of safety gaps in sections / simulate that need to be guarded before this can land:

  1. Silent drop of side effects / unmodeled nested saveexec inside later sections (crates/victory-shader/src/emit/wave.rs:158-168, 329-338, 369-374, crates/victory-shader/src/emit/lower.rs:1116-1131, 1367-1375):
    Because Lower::run replaces every instruction in i + 1..end with section_inst without emitting the underlying instructions, any Section inserted by sections drops all memory/side-effecting instructions in that range. Previously, an earlier unmatched saveexec caused sections to break and fall back to normal lowering; continuing past it exposes any later saveexec ... restore block that contains stores or an unmatched nested saveexec (where simulate returns early at line 337 or skips non-VALU effects at line 369, yet sections still records Section { end, shapes } at line 167).
  2. Pre-existing section-end matching & Wave64 restore gaps made reachable (crates/victory-shader/src/emit/wave.rs:139-141, 158-161):
    • The end search matches any instruction that writes EXEC and reads saved_code(inst) == Some(saved), so a nested s_*_saveexec_* s2, s0 after s_mov exec, 0 will prematurely close the outer section instead of matching an actual EXEC restore.
    • In Wave64 mode, saved_code only checks the low scalar dword of saved (missing partial s_mov_b32 exec_lo, s0 or a clobbered high dword), and lines 140-141 accept _b32 savers even when p.wave64 is true.

Please restrict sections so a candidate interval is only recorded as a whole-wave section when it ends at a real matching-width EXEC restore (full 64-bit pair in Wave64) and contains no side-effecting instructions or unmodeled EXEC mutations, and add tests covering nested saveexec and store preservation.

<!-- greyfinch-sync:Marvisak/VIctory:review:6081384064 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187#pullrequestreview-6081384064). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:13:29Z. **Review:** CHANGES_REQUESTED --- Thanks for tracking down the early `break` when an unmatched `saveexec` precedes a clean reduction section. Continuing to scan past unmatched saves exposes a couple of safety gaps in `sections` / `simulate` that need to be guarded before this can land: 1. **Silent drop of side effects / unmodeled nested `saveexec` inside later sections (`crates/victory-shader/src/emit/wave.rs:158-168, 329-338, 369-374`, `crates/victory-shader/src/emit/lower.rs:1116-1131, 1367-1375`)**: Because `Lower::run` replaces every instruction in `i + 1..end` with `section_inst` without emitting the underlying instructions, any `Section` inserted by `sections` drops all memory/side-effecting instructions in that range. Previously, an earlier unmatched `saveexec` caused `sections` to `break` and fall back to normal lowering; continuing past it exposes any later `saveexec ... restore` block that contains stores or an unmatched nested `saveexec` (where `simulate` returns early at line 337 or skips non-VALU effects at line 369, yet `sections` still records `Section { end, shapes }` at line 167). 2. **Pre-existing section-end matching & Wave64 restore gaps made reachable (`crates/victory-shader/src/emit/wave.rs:139-141, 158-161`)**: - The `end` search matches any instruction that writes `EXEC` and reads `saved_code(inst) == Some(saved)`, so a nested `s_*_saveexec_* s2, s0` after `s_mov exec, 0` will prematurely close the outer section instead of matching an actual `EXEC` restore. - In Wave64 mode, `saved_code` only checks the low scalar dword of `saved` (missing partial `s_mov_b32 exec_lo, s0` or a clobbered high dword), and lines 140-141 accept `_b32` savers even when `p.wave64` is true. Please restrict `sections` so a candidate interval is only recorded as a whole-wave section when it ends at a real matching-width `EXEC` restore (full 64-bit pair in Wave64) and contains no side-effecting instructions or unmodeled `EXEC` mutations, and add tests covering nested `saveexec` and store preservation.
reeledMarek commented 2026-11-27 17:22:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-27T17:22:08Z.


Thanks for the thorough review @fuzeofficlal! Pushed dffd7c6 addressing every point:

  1. No silent drop of side effects or unmodeled EXEC writes: simulate now returns Option<(HashMap<Value, Shape>, u64)> and returns None on any unmodeled EXEC/EXEC+1 write (such as nested saveexec or v_cmpx) or any instruction with observable side effects (has_side_effect: memory/LDS/image/buffer stores & atomics, exports, barriers, s_setreg*, control transfers, etc.), so sections rejects that candidate range instead of dropping it in Lower::run.
  2. Matching-width save & real EXEC restore: sections now matches s_or_saveexec_b64/s_nand_saveexec_b64 only in Wave64 and *_b32 only in Wave32, tracks the full 64-bit saved register pair in Wave64, and uses is_restore to require a real matching-width s_mov_b32/s_mov_b64 (or s_and_b32/s_and_b64 with EXEC equal to all lanes) targeting EXEC rather than any instruction writing EXEC and reading saved_lo.
  3. Regression tests: Added section_with_store_or_side_effect_is_rejected, nested_saveexec_does_not_close_outer_or_drop_inner, and wave64_requires_matching_width_save_and_full_pair_restore.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7224327739 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3187#issuecomment-7224327739). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-27T17:22:08Z. --- Thanks for the thorough review @fuzeofficlal! Pushed `dffd7c6` addressing every point: 1. **No silent drop of side effects or unmodeled `EXEC` writes**: `simulate` now returns `Option<(HashMap<Value, Shape>, u64)>` and returns `None` on any unmodeled `EXEC`/`EXEC+1` write (such as nested `saveexec` or `v_cmpx`) or any instruction with observable side effects (`has_side_effect`: memory/LDS/image/buffer stores & atomics, exports, barriers, `s_setreg*`, control transfers, etc.), so `sections` rejects that candidate range instead of dropping it in `Lower::run`. 2. **Matching-width save & real `EXEC` restore**: `sections` now matches `s_or_saveexec_b64`/`s_nand_saveexec_b64` only in Wave64 and `*_b32` only in Wave32, tracks the full 64-bit saved register pair in Wave64, and uses `is_restore` to require a real matching-width `s_mov_b32`/`s_mov_b64` (or `s_and_b32`/`s_and_b64` with `EXEC` equal to all lanes) targeting `EXEC` rather than any instruction writing `EXEC` and reading `saved_lo`. 3. **Regression tests**: Added `section_with_store_or_side_effect_is_rejected`, `nested_saveexec_does_not_close_outer_or_drop_inner`, and `wave64_requires_matching_width_save_and_full_pair_restore`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3187:upstream-pr/3187'
git switch 'upstream-pr/3187'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3187'
git switch 'upstream-pr/3187'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3187'
git switch 'upstream-pr/3187'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3187'
git switch 'main'
git merge --squash 'upstream-pr/3187'
git switch 'main'
git merge --ff-only 'upstream-pr/3187'
git switch 'main'
git merge 'upstream-pr/3187'
git push origin 'main'
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
Marvisak/VIctory!3185
No description provided.