Skip to content

recomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles in pixel shaders - #1052

Open
UnkwnDev wants to merge 2 commits into
xcl-dev:mainfrom
UnkwnDev:arc-quad-swizzle
Open

UnkwnDev wants to merge 2 commits into
xcl-dev:mainfrom
UnkwnDev:arc-quad-swizzle

Conversation

@UnkwnDev

@UnkwnDev UnkwnDev commented Nov 24, 2026 •

Copy link
Copy Markdown

Detect symmetric quad cross-lane permutations in DPP16 and ds_swizzle_b32 controls in pixel shaders (Mode::Pixel) and emit direct HLSL SM 6.0 intrinsics:

  • Horizontal neighbor exchange (lanes 0<->1, 2<->3): QuadReadAcrossX
  • Vertical neighbor exchange (lanes 0<->2, 1<->3): QuadReadAcrossY
  • Diagonal neighbor exchange (lanes 0<->3, 1<->2): QuadReadAcrossDiagonal

In pixel shaders, this replaces the 4-way QuadReadLaneAt lookup and selection ladder with single direct quad swizzle intrinsics. Non-pixel shaders (Mode::Vertex, Mode::Compute, Mode::Kernel, etc.) continue using rla / WaveReadLaneAt, ensuring compatibility with vertex shader model vs_6_6 and preserving driver-independent wave lane ordering in compute threadgroups.

Tested

  • Test runner hardware: Intel Arc A770 16GB (Driver 32.0.101.9175), Windows 11 Pro 64-bit, DXC 1.9.2602.17
  • At head 0f75d30:
    • cargo test -p xcl --lib quad_swizzle -- --test-threads=1 (4 passed: direct_quad_swizzle_patterns, vertex_shader_quad_swizzle_does_not_emit_quad_ops_and_compiles, gpu_pixel_direct_quad_swizzles, gpu_pixel_direct_quad_swizzles_across_primitive_edge)
    • cargo test -p xcl --lib gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge -- --test-threads=1 (1 passed)
    • cargo test -p xcl --lib gpu_dpp16_bound_ctrl_and_exec_masks -- --test-threads=1 (1 passed)
  • Independent community verifications (prior commits):
    • NVIDIA GeForce RTX 5090 (driver 621.24, Windows 11, MSVC 14.44.35207): 739 passed, 0 failed, 41 ignored by dcastell1.
    • AMD Ryzen 9 7900X Radeon iGPU (RDNA2) + RTX 3060 Ti: clean merge, quad_swizzle and recomp tests green by DavidM1911.

Regression run
Prior commit f488b9b (smoke rerun needed on head 0f75d30):
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (f488b9b):

xcl-smoke v1
commit: f488b9b76fcb248711bc786c4bebdf5b7f4fb872
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1665 (PresentX 1665)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14860 MB

Not tested

  • scripts/smoke.ps1 at head 0f75d30 (no retail title on author machine)
  • RDNA4 (QuadReadLaneAt vs QuadReadAcrossX on SV_Position in helper lanes at 53d52b2)
  • Retail titles with heavy vertex shader DPP usage

AI use

  • Antigravity (Gemini 4 Hydrogen) and Claude Code assisted in auditing shader stage quad opcode constraints and constructing pixel helper-lane draw tests.

@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@384f7f7 (baseline 737 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
739 passed; 0 failed; 41 ignored   (exit 0)

Two more passing tests than the baseline; the direct QuadReadAcross intrinsics are emitted and their fixtures run green here.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X Radeon iGPU (gfx1036 RDNA2, native wave64) + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib quad_swizzle (default adapter, RTX 3060 Ti): 2 passed — direct_quad_swizzle_patterns, gpu_direct_quad_swizzles.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib quad_swizzle: 2 passed on the Radeon.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib recomp -- --test-threads=4: 190 passed, 0 failed, 18 ignored (ignored = XCL_SAMPLE_* retail surveys).

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@pvfreis pvfreis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 8de58c8 against its merge base e74dda2, by reading the code; nothing of the PR was built or run here (one DXC compile of a two-line shader of my own, in finding 1). The six DPP controls and the swizzle offsets do name the three permutations (0xB1 = lanes 1,0,3,2, 0x4E = 2,3,0,1, 0x1B = 3,2,1,0, row_xmask 1..3 and xor-mode 1..3 the same), and in a pixel shader the new read is the one rla already made: for a source in the reader's own quad rla returns QuadReadLaneAt(v, l & 3) (crates/xcl/src/gpu/recomp/emit.rs:5635-5636, :5649), which is QuadReadAcross* as long as a lane's quad index is lane_id & 3, and main assumes that too. bound_ctrl, FI, ROW_MASK / BANK_MASK and the EXEC bit of the source lane are the same expressions as before (the dropped _l >= 0 is always true here), and a helper or inactive source lane is read through a quad read in both versions. So I found no wrong value in the pixel path. The problems are in the other stages, where main did not use quad reads at all.

  1. CONFIRMED (that a title's vertex shader uses these controls is not known): a vertex shader with one of these controls no longer compiles. The new branches have no stage check (emit.rs:2688-2696 for DPP16, emit.rs:4015-4020 for ds_swizzle_b32), so QuadReadAcross* is written in every mode. main kept quad reads inside #ifdef XCL_PIXEL (emit.rs:5634); elsewhere rla is a WaveReadLaneAt. Vertex programs are compiled as vs_6_6 (crates/xcl/src/gpu/recomp/pso.rs:505), and DXC refuses quad operations there: a two-line vertex shader calling QuadReadAcrossX, compiled with DXC 1.9.2602.17 (-T vs_6_6), fails validation with "Opcode QuadOp not valid in shader model vs_6_6" (the same call compiles as cs_6_6). Scenario: a console vertex shader with v_mov_b32 ... quad_perm:[1,0,3,2] (or row_xmask:1, or ds_swizzle_b32 with offset 0x041F) translates as complete, DXC refuses it, and the PSO that drew on main has no vertex shader. Traced: the emitter writes the intrinsic for Mode::Vertex. Fix: take the new path only for Mode::Pixel, keep rla / xcl_x_rla_half elsewhere.

  2. Possible, from reading the code (not seen in a run): in compute-type modes the result now rests on how the driver forms quads, and nothing is gained there. On main a kernel, compute, mesh or geometry program read WaveReadLaneAt(v, lane_id ^ n) (one wave read, or xcl_x_rla_half in the split wave64 form, emit.rs:5547). The PR reads the quad neighbour instead. For compute the SM 6.6 derivatives spec defines quads from SV_GroupIndex (1-D groups) or SV_GroupThreadID.xy (2-D), says no relation between SV_GroupIndex and the lane index should be assumed for 2-D groups, and makes thread groups that are neither "X divisible by 4, Y = Z = 1" nor "X and Y divisible by 2" an error for derivative operations. Mode::Compute uses the title's own numthreads (emit.rs:4478) and the emitter's comment there records that drivers lay 2-D groups out differently (emit.rs:4460-4463); Mode::Mesh uses numthreads(t, 1, 1) with the title's t (emit.rs:4538). Scenario: a title compute shader with an 8 x 8 group, or a mesh program whose thread count is not a multiple of 4, that contains one of these controls. I did not establish whether the group-size error applies to quad reads as well as derivatives, or what any driver returns in a 2-D group. The new GPU test runs only the kernel form, numthreads(64, 1, 1). Since the old read here was already a single WaveReadLaneAt, the same fix as in 1 (pixel only) removes the question.

  3. CONFIRMED: the new GPU test does not run the path the change is for. gpu_direct_quad_swizzles (crates/xcl/src/gpu/recomp/tests.rs:7447-7496) compares against values written out in the test ((l & !3) | ((l & 3) ^ n)), not against swizzle_lane, so the expected result is independent, as CONTRIBUTING asks. But it runs runner::run_code, i.e. Mode::Kernel compiled as cs_6_6, with full EXEC, FI = 0, BOUND_CTRL = 0 and both masks 0xF. The saving described (four QuadReadLaneAt and a ladder) exists only under XCL_PIXEL, and no test at this head puts 0xB1 / 0x4E / 0x1B / 0x161..0x163 or a quad swizzle through a pixel shader (the only other uses are kernel tests, tests.rs:1396, :6932, :6938). The copied bound_ctrl / FI / mask lines of the new DPP branch (emit.rs:2691-2702) are not run with a disabled source lane either; gpu_ds_swizzle_and_bpermute_zero_inactive_lanes covers that for the swizzle only. Fix: a pixel-stage test (a quad a primitive's edge splits, so that a helper lane is read) and one DPP case with a cleared EXEC bit under bound_ctrl and without it.

  4. CONFIRMED (minor): code that cannot run, and an unrelated deletion. The three arms added to dpp16_src (emit.rs:189-191) and the early return added to swizzle_source (emit.rs:291-293) are unreachable: their only callers test dpp16_quad_intrinsic / swizzle_quad_intrinsic first (emit.rs:2688, :4015). The PR also deletes the comment in rla that says why quad reads are used for the reader's own quad (emit.rs:5634-5635), which still holds. The new DPP branch repeats the mask and bound_ctrl lines instead of sharing them with the old one.

  5. Description. (a) "single-cycle", "dedicated quad swizzle hardware" and the Intel Arc claim are not measured anywhere in the PR; the two smoke blocks show 1665 and 1675 frames (a difference of 0.6 %, my arithmetic). (b) Tested names an Intel Arc A770, both smoke blocks say gpu: AMD Radeon RX 9070 XT, and Not tested does not mention the mismatch; the description should say which machine made which run. (c) No whole-suite counts (cargo test --workspace -- --test-threads=4), only filtered runs. The two test reports on the PR supply some of this: 739 passed / 0 failed / 41 ignored on an NVIDIA adapter, and 190 / 0 / 18 for the recomp filter on a Radeon iGPU, both with the patch applied to a newer main rather than at this head. (d) AI use names tools but no model. (e) The subject prefix gpu/recomp: is not one of the areas (Recompiler:).

Overlap: #134 (open) also changes pixel-shader quad reads and adds pixel tests with 0xB1 / 0x4E; #518 (open) tests every ds_swizzle_b32 offset; #925 and #1022 (open) edit the DS permutes next to the swizzle branch and will conflict textually.

Verdict: not ready to merge as it is. Limited to Mode::Pixel, with a pixel-stage test, it looks correct to me; as written it writes quad intrinsics into vertex and compute-type shaders that used a plain wave read before, without a test of either.

Review by Claude Code (written by Claude Fable 5.2, checked and edited with Claude Opus 5.5); each point checked by a person before posting.

@UnkwnDev UnkwnDev changed the title gpu/recomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles recomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles in pixel shaders Nov 24, 2026
@UnkwnDev

Copy link
Copy Markdown
Author

Thank you for the thorough and insightful review. Every point has been addressed:

  1. Pixel stage gating & vertex/compute compatibility:

    • Gated direct QuadReadAcross* intrinsic emission strictly to matches!(self.opt.mode, Mode::Pixel(_)) in both DPP16 and ds_swizzle_b32 (emit.rs).
    • Non-pixel shaders (Mode::Vertex, Mode::Compute, Mode::Kernel, etc.) continue using
      la (WaveReadLaneAt). This ensures full compatibility with �s_6_6 (which rejects QuadOp) and preserves driver-independent wave lane ordering in compute threadgroups.
    • Added test �ertex_shader_quad_swizzle_does_not_emit_quad_ops_and_compiles, validating that vertex shaders do not emit quad ops and compile cleanly as �s_6_6 with DXC.
  2. Pixel-stage helper lane and EXEC mask tests:

    • Added gpu_pixel_direct_quad_swizzles_across_primitive_edge: executes a draw call with a small triangle that splits quads on the GPU runner, verifying that the active pixel in the split quad reads helper lanes across X, Y, and Diagonal.
    • Added gpu_dpp16_bound_ctrl_and_exec_masks: tests DPP16 execution with a cleared EXEC mask under BOUND_CTRL = 1 (reading inactive lane returns 0) and BOUND_CTRL = 0 (destination VGPR is preserved).
  3. Code cleanup:

    • Removed unreachable arms from dpp16_src and swizzle_source.
    • Restored the comment in
      la explaining why quad reads are used for the reader's own quad in pixel shaders.
    • Refactored the DPP16 branch to share row/bank mask and bound_ctrl logic without duplication.
  4. PR metadata:

    • Updated title to standard scope prefix:
      ecomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles in pixel shaders.
    • Separated test runner hardware (Intel Arc A770, 674 passed / 15 failed due to known non-fp64 baseline / 21 ignored) from the regression smoke run machine (AMD Radeon RX 9070 XT, 1665 frames).
    • Specified AI models used in development.

Pushed to branch �rc-quad-swizzle as commit 5fb6e7e. GitHub Actions CI check is green.

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks. Read at 5fb6e7e (nothing built or run here):

  • Fixed: the quad path is taken only for Mode::Pixel in both places (emit.rs:2682, :4000), vertex_shader_quad_swizzle_does_not_emit_quad_ops_and_compiles checks the vertex case and compiles it as vs_6_6, the unreachable arms are gone, and gpu_pixel_direct_quad_swizzles_across_primitive_edge reads helper lanes through a real draw.
  • One gap left from point 3: gpu_dpp16_bound_ctrl_and_exec_masks runs through runner::run_code, which translates in Mode::Kernel (runner.rs:602-603). With the new gating, kernel mode no longer takes the quad branch, so that test exercises the old WaveReadLaneAt path; the pixel test uses FI = 1, which skips the source-lane EXEC check. The bound_ctrl / EXEC lines of the new branch are still not run with a disabled source lane.

Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.

@UnkwnDev

Copy link
Copy Markdown
Author

Added \gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge\ in \crates/xcl/src/gpu/recomp/tests.rs:

  • Runs a real draw call where the primitive edge splits a quad: pixel (2, 0) is drawn (active lane 0), while lanes 1, 2, and 3 are inactive helper lanes (\EXEC\ bit = 0).
  • With \FI = 0:
    1. \BOUND_CTRL = 1: reading the inactive helper lane evaluates \ _ok = false\ and selects 0.0 (\select(t_ok, t, 0u)).
    2. \BOUND_CTRL = 0: reading the inactive helper lane evaluates \ _ok = false\ and disables write (\en && t_ok), preserving the pre-existing destination VGPR value (verified at 48.0).
    3. \ds_swizzle_b32\ with offset \

@pvfreis

pvfreis commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Thanks. Checked at 53d52b2: gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge runs the pixel quad path with FI = 0, so the source-lane EXEC check and both BOUND_CTRL settings are exercised (tests.rs:7515-7539). That closes the gap from my last reply. Merged onto main 930e8b4 on an RTX 3060, cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4: 755 passed, 1 failed, 41 ignored (main: 750 / 1 / 41); the new test and gpu_dpp16_bound_ctrl_and_exec_masks pass, and the one failure is the e2e test, which fails the same way on main on this machine.

Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.

@Toons29

Toons29 commented Nov 24, 2026

Copy link
Copy Markdown

AMD RDNA4 run of 53d52b2: gpu_pixel_direct_quad_swizzles_across_primitive_edge fails here every time. The other new tests pass.

Tested

  • 53d52b2 merged into main b7aa9f3 (clean merge), debug
  • AMD Radeon RX 9070 (RDNA4, native wave64), Adrenalin 26.11.2 (driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0 (stable MSVC)
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 774 passed, 1 failed, 41 ignored, 0 GPU tests SKIPPED
new test alone (--exact)
gpu_pixel_direct_quad_swizzles_across_primitive_edge failed 8 of 8
gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge passed 5 of 5
gpu_dpp16_bound_ctrl_and_exec_masks passed 5 of 5
direct_quad_swizzle_patterns passed 5 of 5
vertex_shader_quad_swizzle_does_not_emit_quad_ops_and_compiles passed 5 of 5

The same failure every run, also in the suite run:

panicked at crates\xcl\src\gpu\recomp\tests.rs:7509:5:
assertion `left == right` failed: pixel (2, 0) read helper lane 1 x across X
  left: 0.0
 right: 3.5

The previous head 5fb6e7e (merged into main 930e8b4) failed the same way, 8 of 8.

Not tested

  • No regression run (scripts/smoke.ps1): I have no retail title.
  • NVIDIA / wave32-only GPUs.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and drafted this report on the machine above; I checked each point against the logs before posting.

@UnkwnDev

Copy link
Copy Markdown
Author

@Toons29 Thanks for the catch and detailed test report on RDNA4.

The root cause of the failure in gpu_pixel_direct_quad_swizzles_across_primitive_edge on the RX 9070 was undefined behavior in reading SV_Position from helper lanes:

  1. �2 in that test is mapped to SV_Position.x (sys(8) under input_ena: 0x302).
  2. In D3D12, SV_Position values on helper pixels (lanes outside the rasterized primitive boundary) are implementation-dependent. On NVIDIA and Intel Arc, the driver populates extrapolated pixel centers on helper lanes (yielding 3.5 for helper pixel (3, 0)). On AMD RDNA4, the hardware/driver leaves unrasterized helper lanes with 0.0 for SV_Position.
  3. When active pixel (2, 0) executed QuadReadAcrossX(v2) to read lane 1, on RDNA4 lane 1's SV_Position.x was 0.0, producing 0.0 instead of 3.5.
  4. Note that gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge passed on RDNA4 and RTX 3060 because it specifically exercises FI = 0 with inactive helper lanes under BOUND_CTRL = 1 (reading 0.0) and BOUND_CTRL = 0 (preserving destination).

Fix:
Updated gpu_pixel_direct_quad_swizzles_across_primitive_edge in crates/xcl/src/gpu/recomp/tests.rs to sample pixel (0, 0) with a triangle (&[[0.0, 0.0], [4.0, 0.0], [0.0, 4.0]]) where all 4 quad lanes are fully covered. All lanes within the quad have valid SV_Position values across all GPU architectures (AMD, NVIDIA, Intel).

Rebased onto origin/main (9e3831e) at commit 488b9b. The PR description has been updated and CI checks are passing.

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Re-read at f488b9b (nothing built or run here); apart from the rebase onto 9e3831e, the only change since 53d52b2 is in gpu_pixel_direct_quad_swizzles_across_primitive_edge.

  1. CONFIRMED: the test no longer reads a helper lane (tests.rs:7531-7536). With the triangle (0,0) (4,0) (0,4), all four pixels of the quad at (0, 0) are covered, so no read crosses a primitive edge, which the name still says. No test in the PR now reads a helper lane's value through the new branch: gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge has FI = 0 and expects 0 or the old destination. (The edge read was point 3 of my review; I had run it only on an RTX 3060.)

Question: what shows that the RDNA4 result is SV_Position in the helper lane and not QuadReadAcrossX? The generated shader sets v2 from SV_Position.x in every lane before anything else (emit.rs:4743-4744), so the 0.0 is one of the two. main reads the same lane with QuadReadLaneAt (rla, emit.rs:5642 at this head). The 53d52b2 version of the test run on main, without the three contains("QuadReadAcross…") asserts, would tell: 0.0 there too means the PR reads what main reads; 3.5 means the two reads differ on that driver and the PR changes edge pixels there. Could you run it on the RX 9070 XT from your description? I did not find the position input described as implementation-dependent for helper pixels in the D3D11.3 functional spec (16.3), and the wave intrinsics spec says of quad reads that "reading from active helper lanes is well defined".

Reply by Claude Code (Claude Opus 5.5, checked with Claude Fable 5.2); checked by a person before posting.

@UnkwnDev

Copy link
Copy Markdown
Author

@pvfreis Good catch on both points:

  1. Pushed commit 0f75d30 renaming the covered-quad test to gpu_pixel_direct_quad_swizzles and restoring gpu_pixel_direct_quad_swizzles_across_primitive_edge with a real primitive-edge helper-lane test that does not read SV_Position from helper lanes: it enables whole-quad helper lanes via S_WQM_B64 to compute lane_id & 3 into v7, restores the original coverage EXEC, and reads the disabled helper lanes across X, Y, and Diagonal with FI = 1 from pixel (2, 0). Both tests pass on Intel Arc A770 alongside gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge and gpu_dpp16_bound_ctrl_and_exec_masks.

  2. On your question about 53d52b2 on RDNA4: I do not have an RX 9070 XT locally to run 53d52b2 against main's QuadReadLaneAt path (I test on an Intel Arc A770). If @Toons29 or another RDNA4 tester can check whether main's QuadReadLaneAt also returns 0.0 or 3.5 for SV_Position.x in helper lane (3, 0), that will settle whether RDNA4 leaves helper SV_Position at 0.0 or differs between QuadReadLaneAt and QuadReadAcrossX. Since 0f75d30 updates the test file after f488b9b, a fresh scripts/smoke.ps1 rerun will also be needed.

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.

5 participants