recomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles in pixel shaders #1045
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1052"
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 UnkwnDev on 2026-11-24T10:55:59Z.
Detect symmetric quad cross-lane permutations in DPP16 and
ds_swizzle_b32controls in pixel shaders (Mode::Pixel) and emit direct HLSL SM 6.0 intrinsics:QuadReadAcrossXQuadReadAcrossYQuadReadAcrossDiagonalIn pixel shaders, this replaces the 4-way
QuadReadLaneAtlookup and selection ladder with single direct quad swizzle intrinsics. Non-pixel shaders (Mode::Vertex,Mode::Compute,Mode::Kernel, etc.) continue usingrla/WaveReadLaneAt, ensuring compatibility with vertex shader modelvs_6_6and preserving driver-independent wave lane ordering in compute threadgroups.Tested
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)dcastell1.quad_swizzleandrecomptests green byDavidM1911.Regression run
Prior commit
f488b9b(smoke rerun needed on head0f75d30):main(beaa245):PR (
f488b9b):Not tested
scripts/smoke.ps1at head0f75d30(no retail title on author machine)QuadReadLaneAtvsQuadReadAcrossXonSV_Positionin helper lanes at53d52b2)AI use
Imported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T11:07:17Z.
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):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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T11:10:55Z.
Independent verification, merged onto current
main384f7f7locally (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.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T12:54:46Z.
Review: COMMENTED
Review of
8de58c8against its merge basee74dda2, 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_xmask1..3 and xor-mode 1..3 the same), and in a pixel shader the new read is the onerlaalready made: for a source in the reader's own quadrlareturnsQuadReadLaneAt(v, l & 3)(crates/xcl/src/gpu/recomp/emit.rs:5635-5636,:5649), which isQuadReadAcross*as long as a lane's quad index islane_id & 3, andmainassumes that too.bound_ctrl,FI,ROW_MASK/BANK_MASKand the EXEC bit of the source lane are the same expressions as before (the dropped_l >= 0is 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, wheremaindid not use quad reads at all.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-2696for DPP16,emit.rs:4015-4020fords_swizzle_b32), soQuadReadAcross*is written in every mode.mainkept quad reads inside#ifdef XCL_PIXEL(emit.rs:5634); elsewhererlais aWaveReadLaneAt. Vertex programs are compiled asvs_6_6(crates/xcl/src/gpu/recomp/pso.rs:505), and DXC refuses quad operations there: a two-line vertex shader callingQuadReadAcrossX, 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 ascs_6_6). Scenario: a console vertex shader withv_mov_b32 ... quad_perm:[1,0,3,2](orrow_xmask:1, ords_swizzle_b32with offset0x041F) translates as complete, DXC refuses it, and the PSO that drew onmainhas no vertex shader. Traced: the emitter writes the intrinsic forMode::Vertex. Fix: take the new path only forMode::Pixel, keeprla/xcl_x_rla_halfelsewhere.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
maina kernel, compute, mesh or geometry program readWaveReadLaneAt(v, lane_id ^ n)(one wave read, orxcl_x_rla_halfin the split wave64 form,emit.rs:5547). The PR reads the quad neighbour instead. For compute the SM 6.6 derivatives spec defines quads fromSV_GroupIndex(1-D groups) orSV_GroupThreadID.xy(2-D), says no relation betweenSV_GroupIndexand 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::Computeuses the title's ownnumthreads(emit.rs:4478) and the emitter's comment there records that drivers lay 2-D groups out differently (emit.rs:4460-4463);Mode::Meshusesnumthreads(t, 1, 1)with the title'st(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 singleWaveReadLaneAt, the same fix as in 1 (pixel only) removes the question.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 againstswizzle_lane, so the expected result is independent, as CONTRIBUTING asks. But it runsrunner::run_code, i.e.Mode::Kernelcompiled ascs_6_6, with full EXEC,FI = 0,BOUND_CTRL = 0and both masks0xF. The saving described (fourQuadReadLaneAtand a ladder) exists only underXCL_PIXEL, and no test at this head puts0xB1/0x4E/0x1B/0x161..0x163or a quad swizzle through a pixel shader (the only other uses are kernel tests,tests.rs:1396,:6932,:6938). The copiedbound_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_lanescovers 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 underbound_ctrland without it.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 toswizzle_source(emit.rs:291-293) are unreachable: their only callers testdpp16_quad_intrinsic/swizzle_quad_intrinsicfirst (emit.rs:2688,:4015). The PR also deletes the comment inrlathat 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 andbound_ctrllines instead of sharing them with the old one.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 therecompfilter on a Radeon iGPU, both with the patch applied to a newermainrather than at this head. (d) AI use names tools but no model. (e) The subject prefixgpu/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 everyds_swizzle_b32offset; #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.
[PR #1052] gpu/recomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzlesto [PR #1052] recomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles in pixel shadersImported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T13:06:04Z.
Thank you for the thorough and insightful review. Every point has been addressed:
Pixel stage gating & vertex/compute compatibility:
la (WaveReadLaneAt). This ensures full compatibility with s_6_6 (which rejects QuadOp) and preserves driver-independent wave lane ordering in compute threadgroups.
Pixel-stage helper lane and EXEC mask tests:
Code cleanup:
la explaining why quad reads are used for the reader's own quad in pixel shaders.
PR metadata:
ecomp: emit direct QuadReadAcross intrinsics for symmetric DPP quad swizzles in pixel shaders.
Pushed to branch rc-quad-swizzle as commit
5fb6e7ef8c. GitHub Actions CI check is green.Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T13:49:32Z.
Thanks. Read at
5fb6e7e(nothing built or run here):Mode::Pixelin both places (emit.rs:2682,:4000),vertex_shader_quad_swizzle_does_not_emit_quad_ops_and_compileschecks the vertex case and compiles it asvs_6_6, the unreachable arms are gone, andgpu_pixel_direct_quad_swizzles_across_primitive_edgereads helper lanes through a real draw.gpu_dpp16_bound_ctrl_and_exec_masksruns throughrunner::run_code, which translates inMode::Kernel(runner.rs:602-603). With the new gating, kernel mode no longer takes the quad branch, so that test exercises the oldWaveReadLaneAtpath; the pixel test usesFI = 1, which skips the source-lane EXEC check. Thebound_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.
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T15:28:25Z.
Added \gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edge\ in \crates/xcl/src/gpu/recomp/tests.rs:
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T15:57:30Z.
Thanks. Checked at
53d52b2:gpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edgeruns the pixel quad path withFI = 0, so the source-lane EXEC check and bothBOUND_CTRLsettings are exercised (tests.rs:7515-7539). That closes the gap from my last reply. Merged ontomain930e8b4on 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 andgpu_dpp16_bound_ctrl_and_exec_maskspass, and the one failure is the e2e test, which fails the same way onmainon this machine.Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-24T17:12:28Z.
AMD RDNA4 run of
53d52b2:gpu_pixel_direct_quad_swizzles_across_primitive_edgefails here every time. The other new tests pass.Tested
53d52b2merged intomainb7aa9f3(clean merge), debugcargo test --workspace --no-fail-fast -- --test-threads=4: 774 passed, 1 failed, 41 ignored, 0 GPU tests SKIPPED--exact)gpu_pixel_direct_quad_swizzles_across_primitive_edgegpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edgegpu_dpp16_bound_ctrl_and_exec_masksdirect_quad_swizzle_patternsvertex_shader_quad_swizzle_does_not_emit_quad_ops_and_compilesThe same failure every run, also in the suite run:
The previous head
5fb6e7e(merged intomain930e8b4) failed the same way, 8 of 8.Not tested
scripts/smoke.ps1): I have no retail title.AI use
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T18:24:08Z.
@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:
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.Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T20:15:50Z.
Re-read at
f488b9b(nothing built or run here); apart from the rebase onto9e3831e, the only change since53d52b2is ingpu_pixel_direct_quad_swizzles_across_primitive_edge.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_edgehasFI = 0and 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_Positionin the helper lane and notQuadReadAcrossX? The generated shader setsv2fromSV_Position.xin every lane before anything else (emit.rs:4743-4744), so the 0.0 is one of the two.mainreads the same lane withQuadReadLaneAt(rla,emit.rs:5642at this head). The53d52b2version of the test run onmain, without the threecontains("QuadReadAcross…")asserts, would tell: 0.0 there too means the PR reads whatmainreads; 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.
upstream-sync referenced this pull request2026-11-25 01:09:12 +00:00
upstream-sync referenced this pull request2026-11-25 05:07:03 +00:00
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-25T07:35:03Z.
@pvfreis Good catch on both points:
Pushed commit
0f75d30renaming the covered-quad test togpu_pixel_direct_quad_swizzlesand restoringgpu_pixel_direct_quad_swizzles_across_primitive_edgewith a real primitive-edge helper-lane test that does not readSV_Positionfrom helper lanes: it enables whole-quad helper lanes viaS_WQM_B64to computelane_id & 3intov7, restores the original coverageEXEC, and reads the disabled helper lanes across X, Y, and Diagonal withFI = 1from pixel(2, 0). Both tests pass on Intel Arc A770 alongsidegpu_pixel_dpp16_bound_ctrl_and_exec_masks_across_primitive_edgeandgpu_dpp16_bound_ctrl_and_exec_masks.On your question about
53d52b2on RDNA4: I do not have an RX 9070 XT locally to run53d52b2againstmain'sQuadReadLaneAtpath (I test on an Intel Arc A770). If@Toons29or another RDNA4 tester can check whethermain'sQuadReadLaneAtalso returns0.0or3.5forSV_Position.xin helper lane(3, 0), that will settle whether RDNA4 leaves helperSV_Positionat0.0or differs betweenQuadReadLaneAtandQuadReadAcrossX. Since0f75d30updates the test file afterf488b9b, a freshscripts/smoke.ps1rerun will also be needed.Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-26T15:52:33Z.
Read at
0f75d30(nothing built or run here):gpu_pixel_direct_quad_swizzles(tests.rs:7513), andgpu_pixel_direct_quad_swizzles_across_primitive_edge(tests.rs:7540-7571) reads helper lanes through the new branch again. With the triangle (0,0) (3.2,0) (0,3.2), (2, 0) is the only covered pixel of its quad. Unders_wqm_b64the three helper lanes writelane_id & 3tov7, EXEC is restored, and theFI = 1reads expect 1, 2 and 3 (:7568-7570). The pixel's own value, or a helper lanes_wqmdid not enable, would give 0, and nothing depends onSV_Positionin a helper lane.53d52b2-on-mainrun.main8b957be:emit.rsmerges cleanly;tests.rshas one conflict, where #2334 added its qsad tests at the same place (keep both).Claude Code (Claude Opus 5.5) checked this; Claude Fable 5.2 rechecked it; checked by a person before posting.
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:34:51Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:42:05Z.
Triage (#1607) – head
0f75d30#2316 does the same for the Direct DXIL backend (
gpu/dxil/lanes.rs,lower_valu.rs,lower_mem.rs). This PR changes the HLSL emitter (recomp/emit.rs), and nothing on main does it there: the DPP16 andds_swizzle_b32reads in pixel shaders still go throughrla.No problems found in the diff. The mappings check out: quad_perm 0xB1/0x4E/0x1B and row_xmask 0x161-0x163 are lane ^ 1/2/3, matching QuadReadAcrossX/Y/Diagonal. The
_ok/ EXEC handling matches therlapath, which already reads same-quad lanes through quad reads in pixel shaders. The PR conflicts with main. Its smoke blocks are fromf488b9b, not the head, which is why the PR description check fails.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.