Skip to content

Pixel shaders: masks hold the helper lanes (#105 item 1) - #134

Merged
raylitebull merged 2 commits into
xcl-dev:mainfrom
tiagonleal:fix/ps-helper-lane-masks
Nov 25, 2026
Merged

raylitebull merged 2 commits into
xcl-dev:mainfrom
tiagonleal:fix/ps-helper-lane-masks

Conversation

@tiagonleal

@tiagonleal tiagonleal commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

#105 item 1 (HANDOFF: "Ballots (v_cmp) still leave helper lanes out").

After s_wqm the helper pixels of a quad a primitive's edge splits are in EXEC, and the console's v_cmp* / carries set their bits like any other lane's. ballot() used WaveActiveBallot alone, which leaves helper lanes out before SM 6.7, so in whole-quad sections:

  • v_cndmask_b32 gave helper lanes the false value;
  • s_and_saveexec / v_cmpx dropped them, so what was written under that mask never reached them;
  • a derivative taken across the quad by hand (DPP quad_perm, ds_swizzle) was wrong next to them, along every edge;
  • a waterfall loop over v_readfirstlane (rla already reads a helper lane right) never took the helper lane out of EXEC (its v_cmp_eq bit 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):

  • WaveActiveBallot gives a helper lane the wave's result (32 / 32 helper lanes, with a lane-varying condition too);
  • WaveActiveBitOr does not (0 / 32: it gets another value);
  • a quad is hardware lanes 4k..4k+3 (X = ^1, Y = ^2, diagonal = ^3) in 1024 / 1024 pixels.

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_cndmask selector, carry-ins – the x64_masks liveness 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.
  • The entry EXEC stays 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 mask quad_bits can 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 in CreateGraphicsPipelineState on the ballot_px form: RDNA2 on quad reads of a value from a WaveReadLaneAt in a waterfall loop (WarmMilkCodes, RX 6600 XT), RDNA3 / RDNA4 on a WaveReadLaneAt whose 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. Masks quad_bits cannot express keep ballot_px.

HLSL / DXIL cache

Only pixel shaders change. On the first version I dumped every HLSL the lib tests translate on main and 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_local in PRELUDE_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), test ps_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 by v_cndmask in WQM, |ddy| of a value written under s_and_saveexec, and a waterfall loop's iteration count.
    • before: 384 / 1024 pixels wrong (ddx 32, ddy 32, loop 384 – at the budget);
    • after: 0 / 1024, both wave sizes.
  • gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k: the two properties above that ballot_px and rla rely on, checked on the adapter (the WaveActiveBitOr result is printed, not checked).

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1742), Ryzen 7 9800X3D, Windows 11 Pro 26300, rustc 1.100.0 MSVC, DXC 1.8.2502.11; debug for the tests, release for the runs. Rebased onto main 47efa2e.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 8c3cfd8: 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).
  • On AMD, from srcamarda's run of the same change on afdfc11 (RX 7800 XT, not mine): cargo test -p xcl --lib 538 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 that main fails there too, no crash); with XCL_SPLIT_WAVE64=1 539 passed, 0 failed.

Regression run

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1656 (PresentX 1656)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14426 MB
xcl-smoke v1
commit: 8c3cfd8d8e511dcea13ec2ffa7f682f3c21d5e04
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14433 MB

Not tested

  • This rebased head on AMD (RDNA2 / RDNA3 / RDNA4): the AMD numbers above are srcamarda's, on the earlier head.
  • Cost on retail shaders: a mask read whole in a pixel shader (branch, 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.
  • The smoke run does not show whether the retail title's pixel shaders look different. The HANDOFF line "Ballots (v_cmp) still leave helper lanes out" would be out of date with this.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the tests and this description, applied srcamarda's change, did the rebase, and ran the tests and the smoke runs on my machine.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tiagonleal
tiagonleal force-pushed the fix/ps-helper-lane-masks branch from baf85df to 737f395 Compare November 23, 2026 14:54
@tiagonleal

Copy link
Copy Markdown
Contributor Author

Rebased on main 484dd57 (after #133). No interaction: #133 changes what lane reads of lanes 32..63 give, this changes the masks' helper-lane bits; on a 32-lane wave ballot_px's upper word stays 0, which is what upper_lanes assumes for VALU masks while EXEC's upper word is 0. Re-run on the RTX 5070 Ti: cargo test --workspace 562 passed, 0 failed (the two new PS tests included).

@WarmMilkCodes

Copy link
Copy Markdown
Contributor

Tested #134 737f395 merged onto main 956a476 on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): fail – the new test crashes inside the AMD driver's CreateGraphicsPipelineState

The PR's new test gpu_ps_masks_hold_helper_lanes_on_triangle_edges takes down the xcl lib test binary with 0xC0000005 (STATUS_ACCESS_VIOLATION), every run (full suite, serial, and alone). Main at 956a476 (no such test) runs the whole lib suite here without a crash. No Rust backtrace (not a panic).

To find the step, I ran it alone (--exact --nocapture --test-threads=1) with temporary eprintln!s before each step of the test and of runner::draw / draw_on_multi:

XCL-STEP wave64 true: translate
XCL-STEP wave64 true: HLSL saved (35728 bytes); DXC compile
XCL-STEP wave64 true: DXC ok (6588 bytes DXIL); runner::draw
XCL-STEP   runner::draw: CreateGraphicsPipelineState
<crash, 0xC0000005>

So the translation is complete and DXC accepts it (ps_6_6); the access violation is in ID3D12Device::CreateGraphicsPipelineState for the wave64 PS – the driver's shader compiler. The marker after PSO creation never prints, and the wave32 pass never runs. The PS uses WaveActiveBallot ×4, WaveReadLaneAt ×5 (the waterfall loop), QuadReadLaneAt ×4, QuadReadAcrossX/Y/Diagonal, WaveActiveBitOr, WaveGetLaneIndex and a discard, inside 11 for loops.

The translated HLSL (pr134_ps_wave64.hlsl, from the synthetic test only) is attached in case it helps reduce it.

pr134_ps_wave64.hlsl.txt

@WarmMilkCodes

WarmMilkCodes commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Narrowed the CreateGraphicsPipelineState crash down on the same RX 6600 XT (driver 32.0.21045.29003), compiling ps_6_6 with DXC and creating the PSO through runner::draw, each variant in its own process:

In the test's translated PS: only the waterfall loop (C, 0038–0058) matters. Without it: ok. With A and B cut out: still crashes. Replacing rla with a plain WaveReadLaneAt, removing the xcl_budget check or removing the discard: still crashes. Replacing the loop's ballot_px(...) with ballot(...), i.e. no QuadReadAcrossX/Y/Diagonal in the loop, makes it build and draw.

Standalone reproducer, no resources, crashes the driver in CreateGraphicsPipelineState:

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);
}
loop WaveReadLaneAt Quad reads WaveActiveBallot result
✓ ✓ ✓ ✓ crash
✓ ✓ ✓ – crash
✓ – ✓ ✓ ok
✓ ✓ – ✓ ok
– (one pass) ✓ ✓ ✓ ok
✓ – ✓ – ok
✓ – – ✓ ok

So it's AMD's compiler crashing on quad reads of a value derived from WaveReadLaneAt inside a loop. That's the shape ballot_px gives every v_cmp in a translated waterfall loop, so retail shaders with waterfall loops likely hit it too on this driver, not just the test. A workaround on the XCL side would be to keep ballot_px's quad reads out of loops (as loop_plain_ballot does) or to restructure that step; which one is right for helper-lane semantics is your call.

Also reported to AMD through the AMD Bug Report Tool (driver 26.11.2) with the standalone shader above.

tiagonleal added a commit to tiagonleal/xcl that referenced this pull request Nov 23, 2026
…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.
@tiagonleal
tiagonleal force-pushed the fix/ps-helper-lane-masks branch from 737f395 to afdfc11 Compare November 23, 2026 20:43
@tiagonleal

Copy link
Copy Markdown
Contributor Author

Rebased on 956a476; afdfc11: in a loop, v_cmp masks quad-read the compare's vector operands (QuadReadLaneAt, once per register and member) and use ballot_px_quad; no quad read of a WaveReadLaneAt-derived value in a loop any more. Masks outside loops unchanged.

  • DXIL of the test PS (dxc 10.0.26100, ps_6_6): quad ops in the loop reading a WaveReadLaneAt-derived value 3 → 0 (wave64 and wave32).
  • RTX 5070 Ti, 617.42, cargo test --workspace -- --test-threads=4: 572 passed, 0 failed, 39 ignored (main 956a476: 569 / 0 / 39). gpu_ps_masks_hold_helper_lanes_on_triangle_edges: 0 of 1024 pixels wrong, wave64 and wave32. New: ps_masks_in_loops_quad_read_the_operands_not_the_compare (fails without the change).

@WarmMilkCodes, could you rerun gpu_ps_masks_hold_helper_lanes_on_triangle_edges on the RX 6600 XT?

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Linux / Turing run of the current head afdfc11 (on main 956a476, so head = merge result). Ubuntu 24.04, GeForce RTX 2060 (Turing, 32-lane waves), NVIDIA 595.91.07, Wine 11.21 Staging (wow64), vkd3d-proton master 30b0eb9 (relaxed as in #175), DXVK 3.1.1 dxgi; XCL cross-built for x86_64-pc-windows-gnu, release; DXC 1.7.2308. So the D3D12 path is vkd3d-proton → dxil-spirv → NVIDIA Vulkan, which translates the wave, quad and helper-lane operations itself.

gpu::recomp filter, --test-threads=1:

passed failed ignored
main 956a476 160 5 18
this PR 163 5 18

No new failures. All three new tests pass: gpu_ps_masks_hold_helper_lanes_on_triangle_edges, ps_masks_in_loops_quad_read_the_operands_not_the_compare and gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k. The PSO with the loop's quad reads builds without trouble through dxil-spirv.

The 5 failures on every build are this stack's memory-window reads, which return zeros (explained in #175), and are the same on main: gpu_memory_windows_above_4_gib, gpu_unified_memory_arena, gpu_mesh_mode_reads_memory_windows, gpu_sparse_vram_descriptors_buffers_and_xmem, gpu_bvh64_intersect_ray_across_memory_windows_and_grazing. The 2 skips on every build are no wave64 (gpu_geometry_*).

Not covered: whether the RX 6600 XT driver crash is gone at afdfc11 (that needs AMD on Windows); RADV; any title.

AI-assisted (Claude Code).

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Not merged yet: with this PR on current main the lib test process dies with 0xC0000005 in gpu_wave64_ps_whole_wave_reductions (creating its pixel-shader pipeline) on an RX 9070 (RDNA4, driver 32.0.x); main passes it. It looks like the driver's compiler crashing on the new mask form, the RDNA2 crash this PR avoids, now on RDNA4. Could you check it with --test-threads=1 on an RDNA3/4 card, and rebase on main?

@srcamarda

Copy link
Copy Markdown
Contributor

@ivall same crash here on RDNA3 (gpu_wave64_ps_whole_wave_reductions, --test-threads=1); cause and a fix that removes it below.

Tested on RDNA3: RX 7800 XT, driver 32.0.32029.2010, Windows 11 26300, debug build, no XCL_SAMPLE_* data.

afdfc11 fixes the loop case on RDNA3 too, but another driver crash remains, without a loop.

b9e6e25 (before the workaround) afdfc11
gpu_ps_masks_hold_helper_lanes_on_triangle_edges alone 0xC0000005 pass
gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k, ps_masks_in_loops_… – pass
cargo test -p xcl --lib – 0xC0000005, the whole test binary

The crash is gpu_wave64_ps_whole_wave_reductions, natively and with XCL_SPLIT_WAVE64=1, at both commits. On main it only fails on RDNA2/3 ([2, 928, 2], #155). Its PS has no loop. The access violation comes after DXC succeeds, in PSO creation (same place as on the RX 6600 XT).

What triggers it

I replaced the test's PS with hand-edited HLSL, one variant per run:

variant result
as translated crash
rla() without its XCL_PIXEL quad part crash
the one v_cmp (ballot_px(and(lanebit(exec…), v14 != 0))) without EXEC crash
ballot_px without its QuadReadAcross* no crash (main's 928)
the waterfall read rla(v13, s0) with a constant lane instead of s_ff1(s18 & exec) no crash (928)

So it is the reverse of the RDNA2 shape: a WaveReadLaneAt whose lane index comes from a ballot of quad-read bits. No loop is needed. Standalone, it crashes the driver here:

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 l = 3u it builds, and so does the same shader without the quad reads. Your operand form does not crash it. The same shader with q built from QuadReadLaneAt(x, p) compares (as quad_bits emits) builds and runs.

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 ps_masks_in_loops_quad_read_the_operands_not_the_compare's last assertion turned around (masks before the loop take ballot_px_quad too). Full patch at the end. With it, on the RX 7800 XT:

Em::loops / loop_ranges are then unused for this. Masks quad_bits can't express still fall back to ballot_px, so the shape can still occur there.

Not tested: NVIDIA with this change, RDNA2, retail shaders.

On your "whether AMD behaves the same": gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k prints 32 pixels next to a helper lane; its ballot right in 32, its bit-or in 32; quads at lanes 4k in 1024 of 1024. So on this AMD driver WaveActiveBallot reaches helper lanes and quads are lanes 4k..4k+3, as on the RTX 5070 Ti. Unlike there, WaveActiveBitOr reaches them too (32 / 32 vs 0 / 32).

Patch against afdfc11 (git apply)
diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs
index c76fb8e..56ad01c 100644
--- a/crates/xcl/src/gpu/recomp/emit.rs
+++ b/crates/xcl/src/gpu/recomp/emit.rs
@@ -868,8 +868,7 @@ impl Em {
                 ballot = "ballot_px_local";
             }
         }
-        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 } {
             Some((reads, q)) => {
                 if !reads.is_empty() {
                     self.line(&reads);
diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs
index 2916cf4..bac3757 100644
--- a/crates/xcl/src/gpu/recomp/tests.rs
+++ b/crates/xcl/src/gpu/recomp/tests.rs
@@ -1946,8 +1946,10 @@ fn gpu_ps_masks_hold_helper_lanes_on_triangle_edges() {
 /// The masks of a waterfall loop in a pixel shader take the helper lanes' bits from quad reads
 /// of the compare's vector operand, not of the compare (#134): AMD's RDNA2 compiler crashed in
 /// `CreateGraphicsPipelineState` on quad reads of a value computed from a `WaveReadLaneAt` in a
-/// loop (WarmMilkCodes, RX 6600 XT), which `ballot_px` gave the loop's `v_cmp`. Outside loops the
-/// masks keep `ballot_px`. CPU only: what the GPU sees is `gpu_ps_masks_hold_helper_lanes_on_triangle_edges`.
+/// loop (WarmMilkCodes, RX 6600 XT), which `ballot_px` gave the loop's `v_cmp`. Outside loops too:
+/// AMD's RDNA3 compiler crashed on a `WaveReadLaneAt` whose lane came from such a mask, with no
+/// loop (`s_ff1` of it → `v_readlane`, RX 7800 XT), so every mask `quad_bits` can express takes
+/// this form. CPU only: what the GPU sees is `gpu_ps_masks_hold_helper_lanes_on_triangle_edges`.
 #[test]
 fn ps_masks_in_loops_quad_read_the_operands_not_the_compare() {
     for wave64 in [true, false] {
@@ -1959,7 +1961,7 @@ fn ps_masks_in_loops_quad_read_the_operands_not_the_compare() {
         assert!(body.contains("ballot_px_quad(") && body.contains("QuadReadLaneAt(v2, 3u)"), "wave64 {wave64}: the loop's v_cmp without its operand's quad reads\n{body}");
         // one read per register and member, though the float compare names v2 twice (NaN test, ==)
         assert_eq!(body.matches("QuadReadLaneAt(v2, ").count(), 4, "wave64 {wave64}\n{body}");
-        assert!(before.contains("= ballot_px(and("), "wave64 {wave64}: the masks before the loop lost ballot_px\n{before}");
+        assert!(!before.contains("= ballot_px(and(") && before.contains("ballot_px_quad("), "wave64 {wave64}: a mask before the loop quad-reads its compare\n{before}");
     }
 }
 

@WarmMilkCodes

WarmMilkCodes commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Re-tested afdfc11 (merged onto current main 0f34407) on the RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2.

The fix works for its own test: gpu_ps_masks_hold_helper_lanes_on_triangle_edges and gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k now pass here (serial run). Thanks for picking up the repro.

But merged onto current main it crashes another test – same driver crash, 0xC0000005 in the lib binary, in gpu_wave64_ps_whole_wave_reductions (cargo test -p xcl --lib -- --test-threads=1: 198 tests ok, then that one never returns). On main 0f34407 alone that test passes and the whole suite is 651 passed / 0 failed on this card.

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 upper_lanes form, and that test's PS (whole-wave reduction + waterfall v_readlane of the s_ff1 lane) together with this PR's masks seems to hit the same AMD compiler crash again. Rebasing onto main should reproduce it on any RDNA2/3 card; on NVIDIA it wouldn't show.

@PHeitor1

Copy link
Copy Markdown

Tested afdfc11 merged onto main 9ab7d76 on RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native), rustc 1.100.0 MSVC, debug, cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_*. Baseline main 9ab7d76: 651 passed, 0 failed, 40 ignored.

Pass: 654 passed, 0 failed, 40 ignored. GPU skips: the same 2 as on main (no wave64).

Run and written with Claude Code (Claude Opus 5.5).

tiagonleal and others added 2 commits November 24, 2026 13:56
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]>
@tiagonleal

Copy link
Copy Markdown
Contributor Author

@srcamarda thanks for the repro and the patch. It is in now (8c3cfd8, credited in the commit): every mask quad_bits can express takes the operand form, the loop ranges it first needed are gone, and the test's last assertion is turned around as you suggested. Rebased onto main 47efa2e; on the RTX 5070 Ti the whole suite passes (744 / 0 / 41) and the smoke run is clean, both in the description.

@WarmMilkCodes @srcamarda if you can, a rerun of cargo test -p xcl --lib -- --test-threads=1 on 8c3cfd8 on RDNA2 / RDNA3 would say whether gpu_wave64_ps_whole_wave_reductions still crashes the driver there; I have no AMD card.

AI-assisted (Claude Code).

@thiagocalile

Copy link
Copy Markdown

Independent AMD RDNA2 (native wave64) test report on exact head 8c3cfd8d8e511dcea13ec2ffa7f682f3c21d5e04 (without rebasing or edits).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, driver 32.0.21045.29003; XCL_ADAPTER=radeon, native wave64 + mesh shaders), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (26200), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11, debug build.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib gpu::recomp -- --test-threads=4: 191 passed, 0 failed, 18 ignored (0 GPU skips).
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 741 passed, 3 failed, 41 ignored. The 3 failures are pre-existing on this RX 6600 on main (placed_title_textures_share_vram_and_preserve_pixels: 3D 64x64x64 4 mips subresource 2 mismatch, plus 2 mutex-poison cascades; covered by D3D12.X: map and unmap 3D texture mips separately #1028).

Not tested

  • Retail title / scripts/smoke.ps1 (no retail executable here), D3D12 debug layer (no d3d12SDKLayers.dll), NVIDIA / Intel / WARP, Linux / Wine.

AI use

  • Antigravity (Gemini 4 Neon) checked out 8c3cfd8, ran the tests on my RX 6600, and drafted this report; I checked the output before posting.

@thaqiart139-alt

Copy link
Copy Markdown

Test report for this PR's head 8c3cfd8, merged into main 689f2db (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card.

Tested

  • GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with XCL_ADAPTER.
  • System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
main 689f2db with this PR
RTX 5070 971 passed, 4 failed, 45 ignored 974 passed, 4 failed, 45 ignored
Radeon iGPU 974 passed, 1 failed, 45 ignored 977 passed, 1 failed, 45 ignored
  • This PR adds no failure. The failures are the same on main, from Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679's new fuzz tests, and both are already reported on Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679:
    • RTX 5070: fuzz_validate_and_gpu_0 to _3 (CreateComputePipelineState: 0x8007000E)
    • iGPU: fuzz_validate_and_gpu_1 (seed 540: res[833] = 0x7, CPU 0x6)
  • This PR's new tests pass on both GPUs: gpu_ps_masks_hold_helper_lanes_on_triangle_edges, ps_masks_in_loops_quad_read_the_operands_not_the_compare, gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k.
  • This is an AMD run on the current head, which the description lists as not tested: its AMD numbers are from an earlier head. The new GPU tests pass with native 64-lane waves on the iGPU and with 32-lane waves on the RTX 5070.
SKIPPED tests (the same on main and with this PR)
  • RTX 5070:
    • no wave64:
      • gpu::recomp::lower::tests: a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu
      • gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu, and the wave64 cases of its f16 / f32 / f64 / integer_programs_on_the_gpu
      • gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
    • the wave32 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused ("its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's")
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is off)
  • Radeon iGPU:
    • no mesh shaders: gpu::dxil::geometry_tests::gpu_geometry_direct_records, emitted_ms_primitive_attribute_reaches_the_pixel_shader, emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip, gpu_geometry_mode_es_gs_strip_with_branches, gpu_mesh_mode_two_passes
    • the wave32 and wave64 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused, as above
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off)

Not tested

  • the cost on retail pixel shaders, a title run, RDNA3 / RDNA4; other GPUs; Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.

@WebIdentity1

Copy link
Copy Markdown
Contributor

RTX 3090 helper-lane regression check on exact head 8c3cfd8d8e511dcea13ec2ffa7f682f3c21d5e04, compared with its parent 47efa2ecea0a12934719ae69b81930cf02a4b1c3. I applied this PR's tests.rs only to the parent so the same three synthetic tests ran on both implementations. No game data or SDK was used.

Tested

  • Native Windows 10 19045, NVIDIA GeForce RTX 3090, driver 32.0.15.9174 (591.74), Ryzen 7 7800X3D, Rust 1.98.1 MSVC, DXC 1.8.2502.11. XCL_ADAPTER=3090; direct DXIL and forced split-wave64 unset.
  • cargo test --locked -p xcl --lib gpu_ps_masks_hold_helper_lanes_on_triangle_edges -- --test-threads=1 --show-output: parent 0 passed / 1 failed with 384 / 1,024 pixels wrong in its wave64 pass (ddx 32, ddy 32, waterfall loop 384); PR 1 passed / 0 failed, with 0 / 1,024 wrong for both wave64 and wave32 pixel programs.
  • cargo test --locked -p xcl --lib gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k -- --test-threads=1 --show-output: 1 / 0 on each snapshot. On the RTX 3090, all 32 / 32 tested helper-adjacent pixels saw the expected ballot; WaveActiveBitOr matched in 0 / 32 (observed, not asserted); all 1,024 / 1,024 pixels had the expected 4-lane quad layout.
  • cargo test --locked -p xcl --lib ps_masks_in_loops_quad_read_the_operands_not_the_compare -- --test-threads=1 --show-output: parent 0 / 1, PR 1 / 0, as expected for the emission change.
  • Each source snapshot contained 221 files and matched its SHA-256 manifest before and after each test. I caught and discarded an initial PR run where Cargo had reused the parent's binary across source directories. The reported PR run forced recompilation; its log shows Compiling xcl from source-head, and the GPU outputs changed as above.

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.

@raylitebull
raylitebull merged commit 400e638 into xcl-dev:main Nov 25, 2026
4 checks passed
raylitebull pushed a commit that referenced this pull request Nov 25, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.