keep s_cbranch_execz skips around trapped nested loops #614

Open
RileyW wants to merge 1 commit from RileyW/Darner:pr/exec-zero-loops into Main
First-time contributor

What it changes

  • The problem on main: read from code & synthetic wave64 reproduction (crates/darner-shader/src/ir.rs:877, decided_cycle).

When an s_cbranch_execz skips an outer cmp* vcc + s_cbranch_vccz loop that encloses an undecided inner scalar loop (s_cmp_* + s_cbranch_scc0), decided_cycle stops at the undecided inner branch and never discovers that the outer cycle has no path out when EXEC == 0. ir::without_skips then strips the s_cbranch_execz guard, so an empty 32-lane host wave enters the loop and spins until the iteration watchdog aborts.

This change:

  1. Propagates empty-mask scalar definitions (s_mov, s_and/s_andn2, s_cselect, s_and_saveexec) so empty-wave branches are recognized through scalar temporaries.
  2. Replaces decided_cycle with reverse exit-reachability ( rapped), keeping the s_cbranch_execz skip whenever a reachable block has no path out of the skipped region under EXEC == 0, while still preserving #1914's
    eads_lanes && any_cycle rule and allowing finite counted scalar loops to be unskipped.
  3. Adds unit tests in crates/darner-shader/src/ir.rs and crates/darner-shader/src/emit/wave64_tests.rs covering shallow/deep without_skips, finite counted loops, and 32-lane widening + DXIL validation.

How it was tested

  • Tested revision: 1da3c1 (based on c8258f9)
  • Commands and results:
    • cargo test -p darner-shader --lib ir::tests --locked -> 18 passed, 0 failed
    • cargo test -p darner-shader --lib skip_around_trapped_nested_vccz_loop_does_not_abort_when_empty --locked -> 1 passed, 0 failed (DXIL validated by dxil.dll)
    • cargo clippy --workspace --all-targets --locked -- -D warnings -> 0 warnings
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings -> 0 warnings
    • cargo xtask policy and cargo xtask policy --staged -> ok
  • Changes a default: yes, for all hosts (preserves s_cbranch_execz skips around trapped nested cycles; no effect on loops that can exit when EXEC == 0).
  • A/B result: correctness fix (prevents infinite-loop watchdog aborts on empty 32-lane waves); not a speed claim.
  • Gates run on that revision: cargo clippy --workspace --all-targets --locked -- -D warnings, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo xtask policy, plus targeted darner-shader tests.
  • Gameplay, when relevant: not yet re-run in-game on this Darner branch (previously verified on RTX 3080 SM86 in a downstream fork with 32-lane host waves).
  • Shader wave sizes tested, when relevant: 32 lanes (TEST_HOST_WAVE = Some(32) in wave64_tests).
  • Hardware dependence: likely general; primarily impacts 32-lane wave hosts (NVIDIA / widened wave64 compute shaders).
  • Coverage gaps: On this Windows 10 22H2 machine, test binaries without Agility SDK exports see SM 0x65 from system d3d12.dll, so the GPU dispatch step in wave64_tests skipped while IR analysis, 32-lane widening, and dxil.dll validation all executed.

Checklist

  • I ran this change in the game, or say below why it can't be (synthetic unit/DXIL tests run on this revision; in-game Darner run pending).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found.
  • Replaces or overlaps: none found.
## What it changes - The problem on main: read from code & synthetic wave64 reproduction (crates/darner-shader/src/ir.rs:877, decided_cycle). When an s_cbranch_execz skips an outer _cmp_* vcc + s_cbranch_vccz loop that encloses an undecided inner scalar loop (s_cmp_* + s_cbranch_scc0), decided_cycle stops at the undecided inner branch and never discovers that the outer cycle has no path out when EXEC == 0. ir::without_skips then strips the s_cbranch_execz guard, so an empty 32-lane host wave enters the loop and spins until the iteration watchdog aborts. This change: 1. Propagates empty-mask scalar definitions (s_mov, s_and/s_andn2, s_cselect, s_and_saveexec) so empty-wave branches are recognized through scalar temporaries. 2. Replaces decided_cycle with reverse exit-reachability ( rapped), keeping the s_cbranch_execz skip whenever a reachable block has no path out of the skipped region under EXEC == 0, while still preserving #1914's eads_lanes && any_cycle rule and allowing finite counted scalar loops to be unskipped. 3. Adds unit tests in crates/darner-shader/src/ir.rs and crates/darner-shader/src/emit/wave64_tests.rs covering shallow/deep without_skips, finite counted loops, and 32-lane widening + DXIL validation. ## How it was tested - Tested revision: 1da3c1 (based on c8258f9) - Commands and results: - cargo test -p darner-shader --lib ir::tests --locked -> 18 passed, 0 failed - cargo test -p darner-shader --lib skip_around_trapped_nested_vccz_loop_does_not_abort_when_empty --locked -> 1 passed, 0 failed (DXIL validated by dxil.dll) - cargo clippy --workspace --all-targets --locked -- -D warnings -> 0 warnings - cargo clippy --workspace --all-targets --all-features --locked -- -D warnings -> 0 warnings - cargo xtask policy and cargo xtask policy --staged -> ok - Changes a default: yes, for all hosts (preserves s_cbranch_execz skips around trapped nested cycles; no effect on loops that can exit when EXEC == 0). - A/B result: correctness fix (prevents infinite-loop watchdog aborts on empty 32-lane waves); not a speed claim. - Gates run on that revision: cargo clippy --workspace --all-targets --locked -- -D warnings, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo xtask policy, plus targeted darner-shader tests. - Gameplay, when relevant: not yet re-run in-game on this Darner branch (previously verified on RTX 3080 SM86 in a downstream fork with 32-lane host waves). - Shader wave sizes tested, when relevant: 32 lanes (TEST_HOST_WAVE = Some(32) in wave64_tests). - Hardware dependence: likely general; primarily impacts 32-lane wave hosts (NVIDIA / widened wave64 compute shaders). - Coverage gaps: On this Windows 10 22H2 machine, test binaries without Agility SDK exports see SM 0x65 from system d3d12.dll, so the GPU dispatch step in wave64_tests skipped while IR analysis, 32-lane widening, and dxil.dll validation all executed. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (synthetic unit/DXIL tests run on this revision; in-game Darner run pending). - [x] This PR contains one change based on main. - [x] The diff follows docs/asset-policy.md. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. - Replaces or overlaps: none found.
Contributor

Independent native Windows result at b1da3c1 on an RTX 4060 (driver 621.40). The existing nested-loop fixture reached D3D12 dispatch and all four outputs matched. For s0=0 it returned 0x12345600, and for s0=1,40,64 it returned 0x12345606.

cargo test --locked --offline -p darner-shader --lib emit::wave64_tests::skip_around_trapped_nested_vccz_loop_does_not_abort_when_empty -- --exact --nocapture passed. A second run with a local DXGI adapter-identity assertion verified that each of the four dispatches ran on the physical RTX 4060. This covers the hardware case skipped on the other Windows test machine.

Independent native Windows result at `b1da3c1` on an RTX 4060 (driver 621.40). The existing nested-loop fixture reached D3D12 dispatch and all four outputs matched. For `s0=0` it returned `0x12345600`, and for `s0=1,40,64` it returned `0x12345606`. `cargo test --locked --offline -p darner-shader --lib emit::wave64_tests::skip_around_trapped_nested_vccz_loop_does_not_abort_when_empty -- --exact --nocapture` passed. A second run with a local DXGI adapter-identity assertion verified that each of the four dispatches ran on the physical RTX 4060. This covers the hardware case skipped on the other Windows test machine.
TrustNo1 changed title from [pr-fix][shaders][NVIDIA] keep s_cbranch_execz skips around trapped nested loops to keep s_cbranch_execz skips around trapped nested loops 2026-12-06 03:26:14 +00:00
Owner

Test needed — commit b1da3c18; what to check:

  • The problem on main: read from code & synthetic wave64 reproduction (crates/darner-shader/src/ir.rs:877, decided_cycle).

When an s_cbranch_execz skips an outer cmp* vcc + s_cbranch_vccz loop that encloses an undecided inner scalar loop (s_cmp_* + s_cbranch_scc0), decided_cycle stops at the undecided inner branch and never discovers that the outer cycle has no path out when EXEC == 0. ir::without_skips then strips the s_cbranch_execz guard, so an empty 32-lane host wave enters the loop and spins until the iteration watchdog aborts.

This change:

  1. Propagates empty-mask scalar definitions (s_mov, s_and/s_andn2, s_cselect, s_and_saveexec) so empty-wave branches are recognized through scalar temporaries.
  2. Replaces decided_cycle with reverse exit-reachability ( rapped), keeping the s_cbranch_execz skip whenever a reachable block has no path out of the skipped region under EXEC == 0, while still preserving #1914's
    eads_lanes && any_cycle rule and allowing finite counted scalar loops to be unskipped.
  3. Adds unit tests in crates/darner-shader/src/ir.rs and crates/darner-shader/src/emit/wave64_tests.rs covering shallow/deep without_skips, finite counted loops, and 32-lane widenin

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `b1da3c18`; what to check: - The problem on main: read from code & synthetic wave64 reproduction (crates/darner-shader/src/ir.rs:877, decided_cycle). When an s_cbranch_execz skips an outer _cmp_* vcc + s_cbranch_vccz loop that encloses an undecided inner scalar loop (s_cmp_* + s_cbranch_scc0), decided_cycle stops at the undecided inner branch and never discovers that the outer cycle has no path out when EXEC == 0. ir::without_skips then strips the s_cbranch_execz guard, so an empty 32-lane host wave enters the loop and spins until the iteration watchdog aborts. This change: 1. Propagates empty-mask scalar definitions (s_mov, s_and/s_andn2, s_cselect, s_and_saveexec) so empty-wave branches are recognized through scalar temporaries. 2. Replaces decided_cycle with reverse exit-reachability ( rapped), keeping the s_cbranch_execz skip whenever a reachable block has no path out of the skipped region under EXEC == 0, while still preserving #1914's eads_lanes && any_cycle rule and allowing finite counted scalar loops to be unskipped. 3. Adds unit tests in crates/darner-shader/src/ir.rs and crates/darner-shader/src/emit/wave64_tests.rs covering shallow/deep without_skips, finite counted loops, and 32-lane widenin Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/exec-zero-loops:RileyW-pr/exec-zero-loops'
git switch 'RileyW-pr/exec-zero-loops'

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 'RileyW-pr/exec-zero-loops'
git switch 'RileyW-pr/exec-zero-loops'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'RileyW-pr/exec-zero-loops'
git switch 'RileyW-pr/exec-zero-loops'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'RileyW-pr/exec-zero-loops'
git switch 'Main'
git merge --squash 'RileyW-pr/exec-zero-loops'
git switch 'Main'
git merge --ff-only 'RileyW-pr/exec-zero-loops'
git switch 'Main'
git merge 'RileyW-pr/exec-zero-loops'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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
TrustNo1/Darner!614
No description provided.