Direct DXIL pixel shaders: the export mask taken from the entry WaveActiveBallot(true) loses live lanes on NVIDIA after a divergent loop (right on WARP) #3772

Open
opened 2026-12-03 06:49:32 +00:00 by CharlyRien · 1 comment
CharlyRien commented 2026-12-03 06:49:32 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T06:49:32Z.


On an RTX 3090 (driver 616.56), a direct-DXIL pixel shader can leave live pixels unwritten. Its export mask is the entry WaveActiveBallot(true) word, read again at the export after a loop whose exits depend on the data, and some live lanes find their own bit at 0 there. The same DXIL gives the right image on WARP. I think it is a driver miscompile, but XCL can avoid it by not reading a ballot word for the lane's own export bit. A local workaround is below; I have not opened a PR for it yet.

I searched open and merged PRs and issues first. #3689 is the closest (it reads v_readlane / v_readfirstlane results again from the first live lane) but it does not touch the entry ballot or the export guard. #2083, #2501, #2872 and #3535 are already in the base below.

What the translation does (read on main 16c2fd08)

  • gfx_common_init (dxil/lower_gfx.rs:262) sets a pixel shader's entry EXEC to ballot(true), i.e. WaveActiveBallot(true).
  • The guest program saves that EXEC in SGPRs before s_wqm exec, exec, runs a loop of up to 16 passes in which lanes leave by s_and_saveexec / s_andn2 depending on a texture sample, restores its WQM EXEC after the loop, and exports with EXEC = saved WQM EXEC & saved entry EXEC.
  • The translator knows both saved values statically, so the export guard in the DXIL is wqm(ballot) & ballot. That is the SSA value of the entry ballot, used directly in the export block after the loop, with no phi in between. lanebit tests the lane's bit by shifting the ballot word by the lane index, and a lane whose bit is 0 is discarded.

Measured

Tool: a local offline probe (not upstream) that translates one console program both ways (direct DXIL and HLSL), draws it with a single triangle covering a 128×128 target (so no helper lanes inside), on 3 synthetic input sets, and compares the targets pixel by pixel.

  • One family of 17 pixel shaders of the retail title (one distortion body, one blend mode each) leaves pixels unwritten on the direct path where HLSL writes them. Every pixel both sides write is equal.
  • With every s_cbranch_execz skip run through (so #3574's whole-wave holes are out of the picture), all 17 lose exactly 8,514 of 49,152 pixels: 990 on input set 0, 7,524 on set 1, 0 on set 2. The holes depend on the input values pixel by pixel and hit parts of quads, not whole waves. The same holes were already there without #3591.
  • The loop's guard (65,536 passes, then the lane is discarded) is not it: a witness colour written when the guard runs out never appeared.
  • A second witness colour, written instead of the discard when the lane's export bit is 0, appeared on 100 % of the hole (all 8,514 pixels, on two programs of the family). So every missing pixel is a live lane whose bit of the entry ballot word reads 0 at the export.
  • The same build and the same DXIL (11,976 bytes on both) run on WARP 1.0.23 with Agility SDK 1.621.0: identical, no witness pixel, 16,384 of 16,384 equal on each input set. On the 3090: 990 and 7,524 witness pixels.

Read as written, the DXIL can only drop a lane whose entry-ballot bit is 0, and with one full-screen triangle every lane's bit is set at entry. My guess is that the driver moves or recomputes the entry WaveActiveBallot(true) to its late use after the divergent loop, where the threads have not all reconverged. I have not seen the driver's machine code, so that part is not shown. It is the same pattern as group 5 in my #3716 review (right on WARP, wrong on the 3090 from the same DXIL).

Workaround tested locally

Branch local/shader-diff-3591-helper (4 commits, not pushed), on top of the setup below:

  • Lw::own_bits already lets lanebit answer "this lane's bit" without reading a mask word. The entry EXEC keeps live_lanes() (WaveActiveBallot(true)) for every cross-lane use, and its own bit is noted true, as ballot(true) already did.
  • New: the lane's bit of s_wqm applied to that entry pair is also noted true (every running lane shares its quad with a live lane). The export guard wqm(entry) & entry then becomes true & true, with no wave operation.
  • New: Lw::trivial_phi_value resolves the phi webs the on-the-fly SSA builder makes for a saved mask read across a loop and a join, when their only outside input is one value (it bails out on an incomplete phi or a web over 64 phis). Without it the guard after the loop still reads the ballot word.
  • Masks read across lanes (ballot words used by other lanes, quad reads, cross-lane EXEC tests) are unchanged.

Results:

  • All 17 programs turn identical. On the 119 programs of the probe that had coverage differences, none gets worse (cover, NaN/major or a lost identical).
  • gpu::dxil tests: 356 passed, 0 failed, 4 ignored (XCL_REQUIRE_GPU=mesh), including the triangle-edge helper-lane tests. The new CPU tests (export guard after the entry s_wqm, and after a loop plus a join; wave32, wave64 and split wave64) pass, and check that the discard condition has no wave operation.
  • A first version that noted !IsHelperLane() as the entry bit fixed the 17 but lost live pixels in about 95 other programs on this card, for a reason I do not know. Their DXIL only differed by !IsHelperLane() masking the VALU writes.

Open points before I would make a PR of it:

  • true is wrong for a helper lane. That is harmless for its render-target writes, which are dropped anyway, but I still have to check the rule for UAV writes and whether a helper lane's own bit reaches anything it can see (VCC, v_cmpx, s_bcnt1).
  • Not tested in the game yet, nor on AMD or another NVIDIA driver. A newer NVIDIA driver is the next thing I will try.

Setup

  • Base: main 817eb1fc + the local probe commits (4b358381..432dd08e, tests only) + #3591 at c1900e4e, XCL_PS_SKIP_RUN_THROUGH=1. For the measurements above, also the local probe 626acb3b (runs through every execz skip whose region only narrows EXEC), and the witness commits 0b4a1ffa and d65372fa. Workaround: 322e4d23..20fab92d on top of 626acb3b.
  • Direct path with wave64 pixel shaders split into two 32-lane halves (all programs here are wave64).
  • RTX 3090, NVIDIA driver 616.56, Windows 11 22631. Second adapter: WARP 1.0.23 with Agility SDK 1.621.0, same exe.

AI use: Claude Code (Claude Opus 5.5) ran the probes and GPU jobs, read the DXIL and wrote this; checked and posted by me.

<!-- greyfinch-sync:ivall/xcl:issue:6762618929 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/3772). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-12-03T06:49:32Z. --- On an RTX 3090 (driver 616.56), a direct-DXIL pixel shader can leave live pixels unwritten. Its export mask is the entry `WaveActiveBallot(true)` word, read again at the export after a loop whose exits depend on the data, and some live lanes find their own bit at 0 there. The same DXIL gives the right image on WARP. I think it is a driver miscompile, but XCL can avoid it by not reading a ballot word for the lane's own export bit. A local workaround is below; I have not opened a PR for it yet. I searched open and merged PRs and issues first. #3689 is the closest (it reads `v_readlane` / `v_readfirstlane` results again from the first live lane) but it does not touch the entry ballot or the export guard. #2083, #2501, #2872 and #3535 are already in the base below. ## What the translation does (read on `main` 16c2fd08) - `gfx_common_init` (`dxil/lower_gfx.rs:262`) sets a pixel shader's entry EXEC to `ballot(true)`, i.e. `WaveActiveBallot(true)`. - The guest program saves that EXEC in SGPRs before `s_wqm exec, exec`, runs a loop of up to 16 passes in which lanes leave by `s_and_saveexec` / `s_andn2` depending on a texture sample, restores its WQM EXEC after the loop, and exports with `EXEC = saved WQM EXEC & saved entry EXEC`. - The translator knows both saved values statically, so the export guard in the DXIL is `wqm(ballot) & ballot`. That is the SSA value of the entry ballot, used directly in the export block after the loop, with no phi in between. `lanebit` tests the lane's bit by shifting the ballot word by the lane index, and a lane whose bit is 0 is discarded. ## Measured Tool: a local offline probe (not upstream) that translates one console program both ways (direct DXIL and HLSL), draws it with a single triangle covering a 128×128 target (so no helper lanes inside), on 3 synthetic input sets, and compares the targets pixel by pixel. - One family of 17 pixel shaders of the retail title (one distortion body, one blend mode each) leaves pixels unwritten on the direct path where HLSL writes them. Every pixel both sides write is equal. - With every `s_cbranch_execz` skip run through (so #3574's whole-wave holes are out of the picture), all 17 lose exactly 8,514 of 49,152 pixels: 990 on input set 0, 7,524 on set 1, 0 on set 2. The holes depend on the input values pixel by pixel and hit parts of quads, not whole waves. The same holes were already there without #3591. - The loop's guard (65,536 passes, then the lane is discarded) is not it: a witness colour written when the guard runs out never appeared. - A second witness colour, written instead of the discard when the lane's export bit is 0, appeared on **100 %** of the hole (all 8,514 pixels, on two programs of the family). So every missing pixel is a live lane whose bit of the entry ballot word reads 0 at the export. - The same build and the same DXIL (11,976 bytes on both) run on WARP 1.0.23 with Agility SDK 1.621.0: `identical`, no witness pixel, 16,384 of 16,384 equal on each input set. On the 3090: 990 and 7,524 witness pixels. Read as written, the DXIL can only drop a lane whose entry-ballot bit is 0, and with one full-screen triangle every lane's bit is set at entry. My guess is that the driver moves or recomputes the entry `WaveActiveBallot(true)` to its late use after the divergent loop, where the threads have not all reconverged. I have not seen the driver's machine code, so that part is not shown. It is the same pattern as group 5 in my #3716 review (right on WARP, wrong on the 3090 from the same DXIL). ## Workaround tested locally Branch `local/shader-diff-3591-helper` (4 commits, not pushed), on top of the setup below: - `Lw::own_bits` already lets `lanebit` answer "this lane's bit" without reading a mask word. The entry EXEC keeps `live_lanes()` (`WaveActiveBallot(true)`) for every cross-lane use, and its own bit is noted `true`, as `ballot(true)` already did. - New: the lane's bit of `s_wqm` applied to that entry pair is also noted `true` (every running lane shares its quad with a live lane). The export guard `wqm(entry) & entry` then becomes `true & true`, with no wave operation. - New: `Lw::trivial_phi_value` resolves the phi webs the on-the-fly SSA builder makes for a saved mask read across a loop and a join, when their only outside input is one value (it bails out on an incomplete phi or a web over 64 phis). Without it the guard after the loop still reads the ballot word. - Masks read across lanes (ballot words used by other lanes, quad reads, cross-lane EXEC tests) are unchanged. Results: - All 17 programs turn `identical`. On the 119 programs of the probe that had coverage differences, none gets worse (cover, NaN/major or a lost `identical`). - `gpu::dxil` tests: 356 passed, 0 failed, 4 ignored (`XCL_REQUIRE_GPU=mesh`), including the triangle-edge helper-lane tests. The new CPU tests (export guard after the entry `s_wqm`, and after a loop plus a join; wave32, wave64 and split wave64) pass, and check that the discard condition has no wave operation. - A first version that noted `!IsHelperLane()` as the entry bit fixed the 17 but lost live pixels in about 95 other programs on this card, for a reason I do not know. Their DXIL only differed by `!IsHelperLane()` masking the VALU writes. Open points before I would make a PR of it: - `true` is wrong for a helper lane. That is harmless for its render-target writes, which are dropped anyway, but I still have to check the rule for UAV writes and whether a helper lane's own bit reaches anything it can see (VCC, `v_cmpx`, `s_bcnt1`). - Not tested in the game yet, nor on AMD or another NVIDIA driver. A newer NVIDIA driver is the next thing I will try. ## Setup - Base: `main` 817eb1fc + the local probe commits (4b358381..432dd08e, tests only) + #3591 at c1900e4e, `XCL_PS_SKIP_RUN_THROUGH=1`. For the measurements above, also the local probe 626acb3b (runs through every `execz` skip whose region only narrows EXEC), and the witness commits 0b4a1ffa and d65372fa. Workaround: 322e4d23..20fab92d on top of 626acb3b. - Direct path with wave64 pixel shaders split into two 32-lane halves (all programs here are wave64). - RTX 3090, NVIDIA driver 616.56, Windows 11 22631. Second adapter: WARP 1.0.23 with Agility SDK 1.621.0, same exe. AI use: Claude Code (Claude Opus 5.5) ran the probes and GPU jobs, read the DXIL and wrote this; checked and posted by me.
CharlyRien commented 2026-12-03 08:05:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T08:05:38Z.


Still there after updating the NVIDIA driver from 616.56 to 621.47 (RTX 3090, Windows 11 22631). Same build as in the report above (d65372fa: main 817eb1fc + the local probe commits + #3591 at c1900e4e + the local probes 626acb3b, 0b4a1ffa, d65372fa; XCL_PS_SKIP_RUN_THROUGH=1), same two programs: the same 990 + 7,524 pixels get the witness colour on each, the same counts as on 616.56. So a driver update does not remove it here.

Group 5 from my #3716 review also still fails on 621.47: 58 of 58 seeds, and the plain-HLSL repro compiled by DXC at -O3 (right at -Od).

AI use: Claude Code (Claude Opus 5.5) ran both checks and wrote this; checked and posted by me.

<!-- greyfinch-sync:ivall/xcl:comment:7371813009 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/3772#issuecomment-7371813009). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-12-03T08:05:38Z. --- Still there after updating the NVIDIA driver from 616.56 to 621.47 (RTX 3090, Windows 11 22631). Same build as in the report above (`d65372fa`: `main` `817eb1fc` + the local probe commits + #3591 at `c1900e4e` + the local probes `626acb3b`, `0b4a1ffa`, `d65372fa`; `XCL_PS_SKIP_RUN_THROUGH=1`), same two programs: the same 990 + 7,524 pixels get the witness colour on each, the same counts as on 616.56. So a driver update does not remove it here. Group 5 from my #3716 review also still fails on 621.47: 58 of 58 seeds, and the plain-HLSL repro compiled by DXC at `-O3` (right at `-Od`). AI use: Claude Code (Claude Opus 5.5) ran both checks and wrote this; checked and posted by me.
Sign in to join this conversation.
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
xcl-dev/xcl#3772
No description provided.