Repository navigation
Conversation
…ad operations (SHADER-PS-DPP-QUAD-OPS) Without MaximallyReconvergesKHR, Vulkan lets helper invocations count as inactive for every group operation other than quad and derivative ones. quad_perm was lowered to OpGroupNonUniformShuffle (and, with fi:0, the source lane's EXEC bit to a ballot), so a pixel next to a triangle edge could read an undefined value from its helper neighbour. In fragment shaders (not under --wave64-emulate), the three swaps become OpGroupNonUniformQuadSwap and every other selector one OpGroupNonUniformQuadBroadcast per lane read plus a select on the lane's selector; with fi:0 the EXEC bit goes through the same quad read. Each result is stored eagerly, as the shuffle was (SHADER-529). Other stages keep the shuffle. tests/semantic/spirv_wave_interp.py gains a helpers= option that takes the strict reading of the spec, and tests/semantic/test_dpp_quad_ops_ps.py checks values for 12 selectors x fi/bound_ctrl x EXEC with and without helper lanes. The test_translate.py DPP assertion now expects the quad ops for its pixel-shader quad_perm cases.
|
Independently checked For reproduction, I used the 12 selectors in |
tiguan26
left a comment
There was a problem hiding this comment.
Approving edd67b2.
The three swaps map onto OpGroupNonUniformQuadSwap directions correctly ([1,0,3,2] horizontal 0, [2,3,0,1] vertical 1, [3,2,1,0] diagonal 2), and the other selectors take one QuadBroadcast per distinct lane read with constant indices and a select on the lane's selector, so a helper neighbour is read through a quad operation the spec defines for helpers. With fi:0 the source's EXEC bit goes through the same quad read, so it is the neighbour's bit, not this lane's. uses_quad adds GroupNonUniformQuad, the eager stores keep SHADER-529's every-lane execution, and stages other than pixel shaders and --wave64-emulate keep the shuffle.
Merged onto main d1dff7949 together with #2397, #2355, #2357, #2360 and #2366 (no conflicts), on Linux with Python 3.13: test_dpp_quad_ops_ps.py 7 passed (132 subtests); tests/test_translate.py passes except main's own ps_sdwa_f16_const.asm failure (an llvm-mc version difference here); the full translator suite has only the 8 failures main has here. AI-assisted (Claude Code, Claude Opus 5.5).
tiguan26
left a comment
There was a problem hiding this comment.
Approving. Checked on edd67b2 merged onto current main (d1dff79).
Translator semantic suite: 501 files, the only failures are main's known test_fspx_dot4_op_sel_disasm and test_int32_to_f64. tests/test_translate.py: 719 passed, the one failure is main's ps_sdwa_f16_const.asm. As a negative check I ran the new test_dpp_quad_ops_ps against main's rdna2spirv.py: 36 failures and 23 errors, so the strict-helper interpreter does catch the shuffle/ballot reading a helper neighbour; with the PR it passes.
Read the diff. The three QUAD_SWAPS directions match the spec's OpGroupNonUniformQuadSwap (0 horizontal 1,0,3,2; 1 vertical 2,3,0,1; 2 diagonal 3,2,1,0). Every other selector does one QuadBroadcast per distinct lane read (constant Index, as required) and a select on this lane's perm, and the results go through eager, so the SHADER-529 rule holds. The source lane's EXEC bit for fi:0 also goes through the quad read rather than a ballot, which is the part a helper would otherwise break. The emulate path keeps its exchange, and compute and other stages keep the shuffle.
One note, not a blocker: there is no GPU fixture with quad_perm in a pixel shader, so nothing on a real device draws the triangle-edge case. The interpreter's strict reading is the stronger check anyway, but a small ps_ fixture drawn across an edge would show it on hardware, if anyone has a GPU that actually drops helpers from shuffles.
|
Confirmed a visible difference at triangle edges on fixed-wave64 gfx906, RADV 26.0.8, using hand-written shaders. Same 273 draws on each translator: 13 quad selectors × 7 EXEC/fi/bound settings × 3 triangles.
Every wrong value on main read a helper neighbour; none came from the 419,027 live-source reads. The PR matched all 9,037 helper-source reads and left every outside pixel at its clear sentinel. A separate This exercises native fragment quad operations on this driver, not wave32 hardware or the emulation path. AI-assisted. |
…r groups (SHADER-PS-DPP-QUAD-OPS)
|
Thanks for the hardware runs and the reviews. The gfx906 numbers show the edge-pixel case on Pushed 1ef7065: test-only, it restores the A small |
Claimed in the coordination issue as: SHADER-PS-DPP-QUAD-OPS (#1608 (comment)), from Snooozs's note in the same issue (#1608 (comment))
What and why
Gen.dpp_insnlowered everyquad_permtoOpGroupNonUniformShuffle, and withfi:0it read the source lane's EXEC bit throughOpGroupNonUniformBallot. WithoutMaximallyReconvergesKHR, Vulkan ("Helper Invocations") lets an implementation treat helper invocations as inactive for every group operation other than quad and derivative ones. So in a pixel shader, a lane whose quad neighbour is a helper (a pixel at a triangle edge) could read an undefined value, or miss the neighbour's EXEC bit. Thes_wqmpath already usesOpGroupNonUniformQuadSwapfor this reason.In fragment shaders (not under
--wave64-emulate, which already uses the workgroup exchange),quad_permnow reads its quad through quad operations:[1,0,3,2],[2,3,0,1]and[3,2,1,0]become oneOpGroupNonUniformQuadSwap(direction 0, 1, 2);OpGroupNonUniformQuadBroadcastper lane it reads (constant index), then a select on the lane's selector. A broadcast like[2,2,2,2]is a single op;[0,1,2,3]reads its own lane, with no group op;fi:0, the source lane's EXEC bit goes through the same quad read instead of a ballot.Each quad result is stored eagerly (
Gen.eager), as the shuffle was, so SPIRV-Cross cannot inline it into a conditional (SHADER-529). Vertex, geometry, mesh and compute shaders keep the shuffle. Quad operations are only guaranteed in fragment and compute shaders, and compute has no helpers.docs/design.md's DPP row describes the new rule and says how it was checked.Tests:
tests/semantic/spirv_wave_interp.pygets ahelpers=option, the strict reading of the spec. Helper lanes take part in quad ops. A shuffle or broadcast from one is undefined, a ballot does not see it, any other group op they reach raisesUnsupportedConstruct, and their outputs are discarded.tests/semantic/test_dpp_quad_ops_ps.py, all hand-written programs:quad_permselectors: the three swaps, the four broadcasts, the pair and half broadcasts[1,1,3,3],[2,3,2,3],[0,0,2,2],[0,1,0,1], and[3,1,2,0](all four lanes, no pattern).fi/bound_ctrl1/1, 0/1 and 0/0, with lane 5 on or off in EXEC, and is checked lane by lane against the RDNA2 rule.conditional_subgroup_opsfromtest_dpp_eager_subgroup.py), and that a vertex shader keeps the shuffle.tests/test_translate.py::test_dpp_controls_translate_and_validatebuilds pixel shaders. For its threequad_permcases it now expects the quad ops:QuadSwapfor the swap, no group op for the identity.Tested
Windows 11, CPython 3.12.13, CPU only, no game files, on
maind1dff7949. Tools: llvm-mc 21.1.8 (the CI pin; conda-forgellvm-tools) and SPIRV-Tools 2026.3 (conda-forge).python -I -m unittest discover -s tests/semantic -p test_dpp_quad_ops_ps.py: 7 tests OK. With the oldtools/rdna2spirv.py, 59 subtests fail. The helper case, for example, readsQuadSwap/Shuffle from invocation 2, which is not runningas an undefined output.LLVM_MC=<llvm-mc 21.1.8> python -I -m pytest tests/test_translate.py: 720 passed. The threequad_permcases oftest_dpp_controls_translate_and_validatefail on the old translator with the new assertion.spirv-as/spirv-val --target-env vulkan1.2.python -I scripts/run_semantic_tests.py tests/semantic -j 8, with SPIRV-Tools on PATH andLEONIDA_REQUIRE_SPIRV_TOOLS=1: 501 files, 6,381 tests, 0 files failed (435 s). Without SPIRV-Tools: the same counts, 0 failed (810 s).quad_perm. It replaces one subgroup op with quad ops of the same capability family (GroupNonUniformQuad, which thes_wqmpath already declares).Not GPU-verified by me (CPU only). Hardware checks by reviewers in the comments: RADV 26.0.8 on gfx906 (wave64) shows wrong edge pixels on
main(8,276 of 1,118,208, all from helper-neighbour reads) and none with this PR; an RTX 4090 matches the RDNA reference with both lowerings, as expected for a driver that runs helpers in shuffles.#2362 also changes
Gen.dpp_insn, in the src0 modifier handling. It conflicts withmainalready, so whichever lands second needs a small rebase.GPUs tested: n/a (CPU-only tests)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.