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
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_readfirstlaneresults 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
main16c2fd08)gfx_common_init(dxil/lower_gfx.rs:262) sets a pixel shader's entry EXEC toballot(true), i.e.WaveActiveBallot(true).s_wqm exec, exec, runs a loop of up to 16 passes in which lanes leave bys_and_saveexec/s_andn2depending on a texture sample, restores its WQM EXEC after the loop, and exports withEXEC = saved WQM EXEC & saved entry EXEC.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.lanebittests 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.
s_cbranch_execzskip 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.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_bitsalready letslanebitanswer "this lane's bit" without reading a mask word. The entry EXEC keepslive_lanes()(WaveActiveBallot(true)) for every cross-lane use, and its own bit is notedtrue, asballot(true)already did.s_wqmapplied to that entry pair is also notedtrue(every running lane shares its quad with a live lane). The export guardwqm(entry) & entrythen becomestrue & true, with no wave operation.Lw::trivial_phi_valueresolves 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.Results:
identical. On the 119 programs of the probe that had coverage differences, none gets worse (cover, NaN/major or a lostidentical).gpu::dxiltests: 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 entrys_wqm, and after a loop plus a join; wave32, wave64 and split wave64) pass, and check that the discard condition has no wave operation.!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:
trueis 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).Setup
main817eb1fc+ 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 everyexeczskip whose region only narrows EXEC), and the witness commits 0b4a1ffa and d65372fa. Workaround: 322e4d23..20fab92d on top of 626acb3b.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.
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:main817eb1fc+ the local probe commits + #3591 atc1900e4e+ the local probes626acb3b,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.