Repository navigation
Pixel shaders: masks hold the helper lanes (#105 item 1) - #134
Conversation
baf85df to
737f395
Compare
|
Rebased on |
|
Tested #134 The PR's new test To find the step, I ran it alone ( So the translation is complete and DXC accepts it ( The translated HLSL ( |
|
Narrowed the In the test's translated PS: only the waterfall loop (C, Standalone reproducer, no resources, crashes the driver in float4 main(float4 pos : SV_Position) : SV_Target0 {
uint x = (uint)pos.x;
uint lane = WaveGetLaneIndex();
uint active = WaveActiveBallot(true).x;
uint n = 0u;
[loop] for (;;) {
uint first = firstbitlow(active);
uint s = WaveReadLaneAt(x, first);
bool eq = s == x;
uint own = (uint)eq << (lane & 3u);
uint q = own | QuadReadAcrossX(own) | QuadReadAcrossY(own) | QuadReadAcrossDiagonal(own);
eq = q != 0u;
uint b = eq ? (1u << (lane & 31u)) : 0u;
n++;
active &= ~b;
if (active == 0u || n >= 64u) break;
}
return float4((float)n, (float)active, 0.0f, 1.0f);
}
So it's AMD's compiler crashing on quad reads of a value derived from Also reported to AMD through the AMD Bug Report Tool (driver 26.11.2) with the standalone shader above. |
…ts result (xcl-dev#134) Avoids quad reads of WaveReadLaneAt-derived values in loops, which crash AMD's RDNA2 compiler in CreateGraphicsPipelineState. Masks outside loops unchanged.
737f395 to
afdfc11
Compare
|
Rebased on
@WarmMilkCodes, could you rerun |
|
Linux / Turing run of the current head
No new failures. All three new tests pass: The 5 failures on every build are this stack's memory-window reads, which return zeros (explained in #175), and are the same on Not covered: whether the RX 6600 XT driver crash is gone at AI-assisted (Claude Code). |
|
Not merged yet: with this PR on current main the lib test process dies with 0xC0000005 in |
|
@ivall same crash here on RDNA3 ( Tested on RDNA3: RX 7800 XT, driver 32.0.32029.2010, Windows 11 26300, debug build, no
The crash is What triggers itI replaced the test's PS with hand-edited HLSL, one variant per run:
So it is the reverse of the RDNA2 shape: a float4 main(float4 pos : SV_Position) : SV_Target0 {
uint x = (uint)pos.x + 16u * (uint)pos.y;
uint own = (uint)((x & 1u) != 0u) << (WaveGetLaneIndex() & 3u);
uint q = own | QuadReadAcrossX(own) | QuadReadAcrossY(own) | QuadReadAcrossDiagonal(own);
uint m = WaveActiveBallot((q & 1u) != 0u).x;
uint l = firstbitlow(m);
return float4((float)WaveReadLaneAt(x, l), 0.0f, 0.0f, 1.0f);
}With Suggested change: the operand form for every mask, not only in loops- let in_loop = self.loops.iter().any(|&(start, end)| start <= self.cur_pc && self.cur_pc < end);
- match if ballot == "ballot_px" && in_loop { quad_bits(a, cond, &m) } else { None } {
+ match if ballot == "ballot_px" { quad_bits(a, cond, &m) } else { None } {plus
Not tested: NVIDIA with this change, RDNA2, retail shaders. On your "whether AMD behaves the same": Patch against
|
|
Re-tested The fix works for its own test: But merged onto current main it crashes another test – same driver crash, 0xC0000005 in the lib binary, in Likely an interaction with #155 (merged at 2abc562, after this branch's base – it's 102 commits behind): on RDNA2/3 the VS / PS are now translated in the 32-lane |
|
Tested Pass: 654 passed, 0 failed, 40 ignored. GPU skips: the same 2 as on Run and written with Claude Code (Claude Opus 5.5). |
After s_wqm the helper pixels of a quad an edge splits are in EXEC, but ballot() took masks with WaveActiveBallot alone, which leaves helper lanes out before SM 6.7: v_cndmask gave them the false value, s_and_saveexec dropped them, derivatives taken across the quad by hand were wrong along every edge, and a waterfall loop over v_readfirstlane never removed a helper lane from EXEC (ran into the loop budget). ballot_px gets each quad's four bits through quad reads and collects them with four ballots (a helper lane gets the wave's result of a ballot, but not of WaveActiveBitOr on an RTX 5070 Ti, and it holds its own copy of EXEC). Masks only read lane by lane (x64_masks liveness, now also for pixel shaders) take ballot_px_local: one ballot plus the lane's own bit. The entry EXEC stays the live lanes. HLSL of every other stage is byte-identical. Tests: gpu_ps_masks_hold_helper_lanes_on_triangle_edges (384 / 1024 pixels wrong before, 0 after, wave64 and wave32 programs), gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…xcl-dev#134) ballot_px quad-reads a compare's result for the helper lanes' bits. AMD's compilers crash in CreateGraphicsPipelineState on two shapes of that: RDNA2 on quad reads of a value computed from a WaveReadLaneAt in a loop (WarmMilkCodes, RX 6600 XT), RDNA3 on a WaveReadLaneAt whose lane comes from such a mask, with no loop (srcamarda, RX 7800 XT; RDNA4 too per the maintainer's run). Every mask quad_bits can express now reads the compare's vector operands through quad reads and evaluates the compare per member (ballot_px_quad); the others keep ballot_px. The loop ranges this first needed are gone. The change outside loops is srcamarda's, from their review of this PR. Co-Authored-By: srcamarda <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
afdfc11 to
8c3cfd8
Compare
|
@srcamarda thanks for the repro and the patch. It is in now ( @WarmMilkCodes @srcamarda if you can, a rerun of AI-assisted (Claude Code). |
|
Independent AMD RDNA2 (native wave64) test report on exact head Tested
Not tested
AI use
|
|
Test report for this PR's head Tested
SKIPPED tests (the same on
|
|
RTX 3090 helper-lane regression check on exact head Tested
Not tested: full workspace suite, retail title, current-main integration, shader compile-time or memory impact, AMD. This is focused native Ampere correctness coverage for the PR's synthetic helper-lane cases, not a merge-readiness claim. AI use: Codex desktop (GPT-6) prepared the paired snapshots, ran and checked the Windows tests, and drafted this report; all counts come from retained raw logs. |
In `crates/xcl/src/gpu/dxil/lanes.rs`, `Lw::ballot` called plain `WaveActiveBallot` even in pixel shaders (`self.gfx` with `ps: Some(_)`). Under SM 6.6, `WaveActiveBallot` excludes helper lanes, whereas `Lw::rla` already uses quad reads for pixel shader helper lanes and the HLSL path uses `ballot_px` / `quad_bits` + `ballot_px_quad` (PR #134 / #105 item 1). After `s_wqm_b32`/`s_wqm_b64`, dropping helper-lane bits from compare masks corrupted `v_cndmask` / `s_and_saveexec` values read via DPP quad derivatives and caused `v_readfirstlane` waterfall loops to spin until the loop budget. Port both parts of #105 item 1 and #134 to the direct DXIL translator: - Split `Lw::ballot_ps_quad(q)` out of `Lw::ballot_ps(cond)` in `crates/xcl/src/gpu/dxil/lanes.rs`: four `WaveActiveBallot` passes spread each quad member's bit `p` from live lanes back to bit `4k + p`, preserving the wave32-in-wave64 `gfx_half` select, constant-false `(0, 0)` short-circuit, and live-lanes-only entry `EXEC` (`setup_pixel` calls `gfx_common_init` before setting `self.gfx`). Non-VOPC PS masks (such as `v_add_co_u32` carries) route through `ballot_ps` -> `ballot_ps_quad`. - In `crates/xcl/src/gpu/dxil/lower_valu.rs`, evaluate plain pixel-shader VOPC compares per quad member (`p in 0..4`) by quad-reading VGPR source operands with `QuadReadLaneAt` (leaving SGPRs such as `v_readfirstlane` results and constants wave-uniform) and feeding the 4-bit quad mask to `Lw::ballot_ps_quad`, avoiding `QuadReadAcross*` on compare predicates that crash AMD RDNA2/3/4 `amdxc64` (#134). Add CPU/DXIL-validator and CI-WARP-safe GPU draw regression tests in `lanes.rs` (384/1024 wrong pixels pre-fix on RTX 4060 -> 0/1024 post-fix for both wave64 and wave32 pixel shaders, with zero `dx.op.quadOp` in VOPC pixel shaders). Part of #1269 Assisted-by: Google Antigravity (Gemini 4 Neon)
#105 item 1 (HANDOFF: "Ballots (v_cmp) still leave helper lanes out").
After
s_wqmthe helper pixels of a quad a primitive's edge splits are in EXEC, and the console'sv_cmp*/ carries set their bits like any other lane's.ballot()usedWaveActiveBallotalone, which leaves helper lanes out before SM 6.7, so in whole-quad sections:v_cndmask_b32gave helper lanes the false value;s_and_saveexec/v_cmpxdropped them, so what was written under that mask never reached them;v_readfirstlane(rlaalready reads a helper lane right) never took the helper lane out of EXEC (itsv_cmp_eqbit stayed 0) and ran until the loop budget: 65 536 iterations, in every wave with a helper lane.Found on the way: not every wave op reaches a helper lane
Each lane holds its own copy of EXEC, so a helper lane has to get the whole mask too, not just contribute its bit. Measured on an RTX 5070 Ti with native HLSL (the new test
gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k):WaveActiveBallotgives a helper lane the wave's result (32 / 32 helper lanes, with a lane-varying condition too);WaveActiveBitOrdoes not (0 / 32: it gets another value);So "quad reads +
WaveActiveBitOr" (the variant HANDOFF says was tried for XDefiant's text) leaves the helper lanes' own EXEC wrong on NVIDIA: with it the new test failed exactly as it does without any change (384 / 1024). Whether AMD behaves the same I could not check.Change
ballot_px(pixel shaders,PRELUDE_PIXEL): every lane gets its quad's four bits through quad reads (they see helper lanes); ballot p collects bit p of them from the live lanes, and any live lane of a quad answers for its member p. 3 quad reads + 4 ballots, nothing else.ballot_px_local: a mask only ever read lane by lane (v_cndmaskselector, carry-ins – thex64_masksliveness pass, now also run for pixel shaders) needs only the lane's own bit: the wave's ballot with that bit OR-ed in. 1 ballot, as before.ballot(true): the live lanes only, as on the console (with the helper lanes in it they never stop – the[WaveOpsIncludeHelperLanes]hang).x64_whole_live→mask_whole_live(it now serves both).quad_bits/ballot_px_quad(second commit): a maskquad_bitscan express reads the compare's vector operands through quad reads and evaluates the compare per member, instead of quad-reading the compare's result (ballot_px). AMD's compilers crashed inCreateGraphicsPipelineStateon theballot_pxform: RDNA2 on quad reads of a value from aWaveReadLaneAtin a waterfall loop (WarmMilkCodes, RX 6600 XT), RDNA3 / RDNA4 on aWaveReadLaneAtwhose lane comes from such a mask, with no loop (gpu_wave64_ps_whole_wave_reductions; srcamarda on an RX 7800 XT with a standalone repro, the maintainer on an RX 9070). Using it for every mask, not only in loops, is srcamarda's change from their review. Masksquad_bitscannot express keepballot_px.HLSL / DXIL cache
Only pixel shaders change. On the first version I dumped every HLSL the lib tests translate on
mainand on this branch: 132 byte-identical; the ones that differ are all pixel shaders (2 existing + 2 from the new tests). VS / CS / mesh / GS keep their cached DXIL; pixel shaders recompile once.What is in it
Pixel shaders: masks hold the helper lanes (#105 item 1):ballot_px/ballot_px_localinPRELUDE_PIXEL(crates/xcl/src/gpu/recomp/emit.rs), the liveness pass for pixel shaders (x64_masks.rs), two GPU tests (tests.rs).Pixel shaders: masks quad-read the compare's operands, not its result (#134):quad_bits/ballot_px_quad(emit.rs), testps_masks_in_loops_quad_read_the_operands_not_the_compare(tests.rs).Tests
gpu_ps_masks_hold_helper_lanes_on_triangle_edges: a hand-assembled PS on two triangles sharing the diagonal of a 32×32 target, wave64 and wave32 programs. Per pixel: |ddx| of a value picked byv_cndmaskin WQM, |ddy| of a value written unders_and_saveexec, and a waterfall loop's iteration count.gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k: the two properties above thatballot_pxandrlarely on, checked on the adapter (theWaveActiveBitOrresult is printed, not checked).Tested
main47efa2e.cargo build --workspace && cargo test --workspace -- --test-threads=4on8c3cfd8: 744 passed, 0 failed, 41 ignored. SKIPPED:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64).cargo test -p xcl --lib -- ps_masks helper_lanes wave64_ps --test-threads=1: 5 passed (gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k,gpu_ps_masks_hold_helper_lanes_on_triangle_edges,gpu_wave64_ps_spill_slots,gpu_wave64_ps_whole_wave_reductions,ps_masks_in_loops_quad_read_the_operands_not_the_compare).afdfc11(RX 7800 XT, not mine):cargo test -p xcl --lib538 passed, 1 failed (gpu_wave64_ps_whole_wave_reductions[2, 928, 2], the VS / PS: the 32-lane form on every GPU that can run 32-lane waves (RD… #155 case thatmainfails there too, no crash); withXCL_SPLIT_WAVE64=1539 passed, 0 failed.Regression run
Not tested
s_and_saveexec,v_cmpx) costs quad reads and per-member compares instead of 1 ballot; masks read lane by lane cost about the same.AI use