xshader: decide a loop's back edge for the whole wave too #396

Merged
MathiewMay merged 1 commit from upstream-pr/396 into main 2026-11-28 15:07:14 +00:00
MathiewMay commented 2026-11-28 12:56:55 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by MathiewMay on 2026-11-28T12:56:55Z.


Summary

8724e8f ("decide branches on EXEC and VCC for the whole wave") turned forward branches on EXEC and VCC into WaveActiveAnyTrue votes where the mask ballots apply. The back edge of a structured loop kept each lane's own bit (tools/shader-compiler/src/hlsl/emitter/control_flow.rs):

// 0x0ac0 s_cbranch_execz
tb_skip = max(tb_skip, uint(!WaveActiveAnyTrue((exec_lo & 1u) != 0u)) * 814u);
...
// 0x0bd0 s_cbranch_vccz
tb_c523 = ((vcc_lo & 1u) == 0u);
} while (tb_c523 && tb_skip <= 523u && ++tb_guard < 65536u);

Before 8724e8f a lane outside EXEC skipped the loop by itself. Now it enters with its wave, its own VCC bit never sets, and it stays until tb_guard runs out. The wave stays with it, and the lane has no iterations left for the loops after it.

This takes the wave's decision for the back edge too, as emitter/scalar.rs does for the forward branches. The latch above becomes tb_c523 = (!WaveActiveAnyTrue((vcc_lo & 1u) != 0u));.

The lines above are from ProjectScarlett's CS_ScreenProbes_Inject, which the title dispatches over 14,400 groups in its first frames that trace rays. Three of three runs on a880dfd lost the device there: each time vkd3d-proton's breadcrumbs named that dispatch as the one command the GPU had started and not finished. With this change the same run passed that point and kept presenting until I stopped it three minutes later. That was only seven more frames: the title was down to a frame every 25 s by then, for a reason of its own that this does not touch. I ran those on a880dfd together with other changes of mine, not on this branch alone.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them.

Not a Lanes scenario: this is how one branch form is translated, which the translator's GPU checks cover with synthetic programs on the card, as 8724e8f's own tests do. tools/check_mask_ballots_gpu.py gains a latch program in its 32-lane, 64-lane and paired forms: a loop that ends on VCC, entered by a wave that left lanes outside EXEC, then a loop every lane runs. On main 8 of its cases fail on RADV, four inputs each in the 32-lane and 64-lane forms: the lanes left out get one turn of the second loop, not three. With the change all 665 cases pass.

A unit test, a_loop_ends_when_the_whole_wave_says_so in tools/shader-compiler/src/tests/hlsl/mask_ballots.rs, checks the emitted latch for a whole wave and for a partial one. It fails on main.

GPU, driver and backend: AMD Radeon RX 9070 (1002:7550, RADV GFX1201), Mesa 26.2.7, Linux 7.3, GE-Proton11-14 (--backend proton).

Commands run and their results:

cargo test --locked --target x86_64-unknown-linux-gnu --manifest-path tools/shader-compiler/Cargo.toml
  525 passed (plus 3 in the other test targets); the new test fails on main

python tools/check_translator_gpu.py --provider build/d3d12-smoke/d3d12_xs.dll ... --adapter 1002:7550 --only mask-ballots
  with the change   PASS: 665 cases
  without it        FAIL: 8 of 665 cases (latch32 and latch64, four inputs each)

python tools/shader_harness.py run --baseline origin/main        (baseline 6f89916)
  PASS
  code checks        passed   Build the shader compiler, Python tests, Shader compiler tests, DXBC tests,
                              XG layout tests, Storage codec tests, D3D12 Windows typecheck
  recorded shaders   no program regressed on either host width; 178 outputs changed for 64-lane hosts
                     and 110 for 32-lane hosts
  DXC and DXV        194 of 200 sampled changed programs compiled and none broke
                     (the other six do not compile on main either)
  GPU checks         60 translator checks PASS, shader Lanes suites 29 PASS
  executed           of 100 sampled compute programs 30 ran: 24 same, 2 equivalent, 0 changed,
                     4 unstable, 0 lost (the machine was building other things at the time)

The GPU checks ran outside their Bubblewrap/xvfb-run sandbox, which stalls on this machine (it has no Xvfb).

Checks

No evidence JSON changes. host_profiles.txt changes in one line, waterfall any-host: the only recorded program whose translation changes.

<!-- greyfinch-sync:brcly/TuxBox:issue:5540341160 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/396). Originally posted by [MathiewMay](https://github.com/MathiewMay) on 2026-11-28T12:56:55Z. --- ## Summary 8724e8f ("decide branches on EXEC and VCC for the whole wave") turned forward branches on EXEC and VCC into `WaveActiveAnyTrue` votes where the mask ballots apply. The back edge of a structured loop kept each lane's own bit (`tools/shader-compiler/src/hlsl/emitter/control_flow.rs`): ```hlsl // 0x0ac0 s_cbranch_execz tb_skip = max(tb_skip, uint(!WaveActiveAnyTrue((exec_lo & 1u) != 0u)) * 814u); ... // 0x0bd0 s_cbranch_vccz tb_c523 = ((vcc_lo & 1u) == 0u); } while (tb_c523 && tb_skip <= 523u && ++tb_guard < 65536u); ``` Before 8724e8f a lane outside EXEC skipped the loop by itself. Now it enters with its wave, its own VCC bit never sets, and it stays until `tb_guard` runs out. The wave stays with it, and the lane has no iterations left for the loops after it. This takes the wave's decision for the back edge too, as `emitter/scalar.rs` does for the forward branches. The latch above becomes `tb_c523 = (!WaveActiveAnyTrue((vcc_lo & 1u) != 0u));`. The lines above are from ProjectScarlett's `CS_ScreenProbes_Inject`, which the title dispatches over 14,400 groups in its first frames that trace rays. Three of three runs on `a880dfd` lost the device there: each time vkd3d-proton's breadcrumbs named that dispatch as the one command the GPU had started and not finished. With this change the same run passed that point and kept presenting until I stopped it three minutes later. That was only seven more frames: the title was down to a frame every 25 s by then, for a reason of its own that this does not touch. I ran those on `a880dfd` together with other changes of mine, not on this branch alone. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: **NVIDIA still needs to run them.** Not a Lanes scenario: this is how one branch form is translated, which the translator's GPU checks cover with synthetic programs on the card, as 8724e8f's own tests do. `tools/check_mask_ballots_gpu.py` gains a `latch` program in its 32-lane, 64-lane and paired forms: a loop that ends on VCC, entered by a wave that left lanes outside EXEC, then a loop every lane runs. On `main` 8 of its cases fail on RADV, four inputs each in the 32-lane and 64-lane forms: the lanes left out get one turn of the second loop, not three. With the change all 665 cases pass. A unit test, `a_loop_ends_when_the_whole_wave_says_so` in `tools/shader-compiler/src/tests/hlsl/mask_ballots.rs`, checks the emitted latch for a whole wave and for a partial one. It fails on `main`. GPU, driver and backend: AMD Radeon RX 9070 (1002:7550, RADV GFX1201), Mesa 26.2.7, Linux 7.3, GE-Proton11-14 (`--backend proton`). Commands run and their results: ```text cargo test --locked --target x86_64-unknown-linux-gnu --manifest-path tools/shader-compiler/Cargo.toml 525 passed (plus 3 in the other test targets); the new test fails on main python tools/check_translator_gpu.py --provider build/d3d12-smoke/d3d12_xs.dll ... --adapter 1002:7550 --only mask-ballots with the change PASS: 665 cases without it FAIL: 8 of 665 cases (latch32 and latch64, four inputs each) python tools/shader_harness.py run --baseline origin/main (baseline 6f89916) PASS code checks passed Build the shader compiler, Python tests, Shader compiler tests, DXBC tests, XG layout tests, Storage codec tests, D3D12 Windows typecheck recorded shaders no program regressed on either host width; 178 outputs changed for 64-lane hosts and 110 for 32-lane hosts DXC and DXV 194 of 200 sampled changed programs compiled and none broke (the other six do not compile on main either) GPU checks 60 translator checks PASS, shader Lanes suites 29 PASS executed of 100 sampled compute programs 30 ran: 24 same, 2 equivalent, 0 changed, 4 unstable, 0 lost (the machine was building other things at the time) ``` The GPU checks ran outside their Bubblewrap/`xvfb-run` sandbox, which stalls on this machine (it has no Xvfb). ## Checks No evidence JSON changes. `host_profiles.txt` changes in one line, `waterfall any-host`: the only recorded program whose translation changes.
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
brcly/TuxBox!396
No description provided.