rdna2spirv: quad_perm DPP in a pixel shader reads its quad through quad operations (SHADER-PS-DPP-QUAD-OPS) #2416
Closed
leonida/mandy
ninjahawk wants to merge 0 commits from
leon/ps-dpp-quad-ops into main
pull from: leon/ps-dpp-quad-ops
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2416
Loading…
Reference in a new issue
No description provided.
Delete branch "leon/ps-dpp-quad-ops"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: SHADER-PS-DPP-QUAD-OPS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7207494420), from Snooozs's note in the same issue (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198062450)
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.Independently checked
edd67b24on a Windows RTX 4090 (NVIDIA 616.64, subgroup size 32). All 60 synthetic triangle draws matched the RDNA reference across 120,960 covered pixel results. The 60 readbacks were also byte-identical to the same draws on the base commitd1dff794. This driver therefore provides a passing hardware check for the new lowering, but it did not reproduce an edge-pixel error on the old one.For reproduction, I used the 12 selectors in
test_dpp_quad_ops_ps.pywith five(fi, bound_ctrl, disabled lane)settings: (1,1,none), (0,1,none), (0,0,5), (0,1,5), (1,1,5). After restoring EXEC, the shader exported the DPP result and lane ID as floats. A 64×64 right triangle with clip-space corners (-1,-1), (1,-1), (-1,1) covered 2,016 pixels per draw. A separate GLSL draw broadcast each quad lane’sgl_HelperInvocationflag and identified the selected source as a helper on 1,416 reads across the matrix. All output modules passedspirv-val --target-env vulkan1.2; Vulkan validation reported no errors. These were synthetic shaders only.Approving edd67b24f.
The three swaps map onto
OpGroupNonUniformQuadSwapdirections correctly ([1,0,3,2] horizontal 0, [2,3,0,1] vertical 1, [3,2,1,0] diagonal 2), and the other selectors take oneQuadBroadcastper 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. Withfi:0the source's EXEC bit goes through the same quad read, so it is the neighbour's bit, not this lane's.uses_quadaddsGroupNonUniformQuad, the eager stores keep SHADER-529's every-lane execution, and stages other than pixel shaders and--wave64-emulatekeep the shuffle.Merged onto
maind1dff7949together with #2397, #2355, #2357, #2360 and #2366 (no conflicts), on Linux with Python 3.13:test_dpp_quad_ops_ps.py7 passed (132 subtests);tests/test_translate.pypasses exceptmain's ownps_sdwa_f16_const.asmfailure (an llvm-mc version difference here); the full translator suite has only the 8 failuresmainhas here. AI-assisted (Claude Code, Claude Opus 5.5).Approving. Checked on edd67b24f merged onto current main (d1dff7949).
Translator semantic suite: 501 files, the only failures are main's known
test_fspx_dot4_op_sel_disasmandtest_int32_to_f64.tests/test_translate.py: 719 passed, the one failure is main'sps_sdwa_f16_const.asm. As a negative check I ran the newtest_dpp_quad_ops_psagainst main'srdna2spirv.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_SWAPSdirections 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'sperm, and the results go througheager, 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.
d1dff794and current main63185f4a3(tested separately)edd67b24Every 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
HelperInvocationshader confirmed the edge coverage; a deliberately wrong oracle failed all 273 draws. Repeating the PR readbacks gave identical bytes. No validation errors or synchronization hazards were reported.This exercises native fragment quad operations on this driver, not wave32 hardware or the emulation path.
AI-assisted.
Thanks for the hardware runs and the reviews. The gfx906 numbers show the edge-pixel case on
mainthat I could not show on CPU, so I added them to the description, together with the 4090 result (no difference there, as expected when a driver keeps helpers in shuffles).Pushed 1ef70658c: test-only, it restores the
parametrize(...)spacing that the first commit lost intests/test_translate.pyand renames one comment in the new test. No translator change.test_dpp_quad_ops_ps.pyand the DPP/quad cases oftests/test_translate.pypass again (51 passed, 132 subtests).A small
ps_GPU fixture drawn across a triangle edge is a good follow-up; I'll leave it out of this PR to keep it to the translator change.