fix(shader): read quad_perm DPP lanes in pixel shaders through quad operations #6290
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6290"
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 boykopovar/AnyPS5. Originally posted by jackthereaper2006 on 2026-10-15T09:13:25Z.
What
In a pixel shader, a DPP
quad_permread is now emitted asOpGroupNonUniformQuadBroadcastfrom each lane of the quad, with the result chosen by the lane'squad_permentry. This covers the source EXEC check of a DPP move and of a DPP write condition as well as the value. Other DPP controls, other stages and devices withoutVK_SUBGROUP_FEATURE_QUAD_BITkeep the subgroup shuffle and ballot.Until now the read was a subgroup shuffle plus a ballot of EXEC. Mesa gives a fragment shader full quads only for quad group operations, or for subgroup operations when the shader requires full quads (
RequireFullQuadsKHR) (nir_gather_info.c,needs_full_quad_helper_invocations). On RADV the shuffle and the ballot therefore run without helper invocations, and a DPP read from a helper lane is wrong. The derivatives that ACO builds from DPPquad_permreads are the visible case.The same failure shows on AMD's Windows driver (LeandroLP23's run). NVIDIA, Intel ANV Gen9 and lavapipe already keep helpers in the shuffle, so on those drivers the change only moves the read to quad operations.
The device now lists
GroupNonUniformQuadwhen it reportsVK_SUBGROUP_FEATURE_QUAD_BIT, and shader validation maps that capability to the bit.Tested
Linux (CachyOS, kernel 7.2.9), GCC 16.2.1, Release,
BUILD_TESTING=ON. Rebased onmain6ef5a1c4c; the only conflict wasShaderMemory.cpp, whereverifyFmaskImageModeandverifyPixelQuadPermReadswere added at the same place. Runs that name no commit were onmain0afa6a607before the rebase.37a0ef4e…d388). Its instance pixel shader takes the normal fromnormalize(cross(dFdx(v_world), dFdy(v_world)))(main.c:259). In the translated program0x229255000that becomes the only shader with DPP moves.RADV on
main: the 8192 instances render as a white bloom cloud with black specks.RADV with this change: they render as in the author's screenshot.
Checks on
main:APS5_SKIP_SHADER=229255000the rest of the frame is correct.RADV_DEBUG=nodcc,nofastclearsandzerovrameach leave the cloud.Frames (
APS5_DUMP_FRAMESdumps of the title's own display buffer, 960×540):main, RADVmain+ the fix, RADVmain, lavapipemain, RADV,APS5_SKIP_SHADER=229255000Full-size files: https://gist.github.com/jackthereaper2006/aec623dfe08f2a6d8e5207ac3e2a209b. Reference: the author's screenshot.
agc_shader_memorycheck:quad_permreads, with full and partial row masks, useOpGroupNonUniformQuadBroadcastand no shuffle.agc_driver_pixel_quad_perm_helpers(5e25bc870, 3dd3a9832 before the rebase): pixel quad_perm DPP reads of helper neighbours afters_wqm, with and withoutfi, wave64 and wave32. It passes on RADV, fails on RADV with the emitter frommain(pixel 584 read 0 from quad_perm [1,0,3,2], its helper neighbour is pixel 585), and skips on lavapipe (8-lane subgroup) and without the quad capability. Wholectestwith it: 1227/1227 with Mesa patched for #5444.main6ef5a1c4c,ctest -V -R 'quad|dpp|agc_shader_memory' -E audio_outwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1, validation layers 1.4.363):main: 11/11 pass, noVUID-errors.agc_driver_pixel_quad_perm_helpers), noVUID-errors.was not found but was requested by env var VK_INSTANCE_LAYERS;VK_LOADER_DEBUG=layershows the layer inserted at instance and device level.ctestonmain6ef5a1c4c, RADV, stock Mesa 26.2.4: 1776 pass, 32 skip and 7 fail out of 1815. The 7 failures fail the same way with this change's files reverted tomain:agc_driver_tessellation: the Mesa crash of #5444.agc_driver_log_near_one,agc_driver_vop1_float_unary,agc_driver_fp16_overflow,agc_driver_float16_result_modifiers: they passed on0afa6a607on this machine (e.g.v_log_f32of 2.0 now returns 25.0).agc_driver_pixel_sample_iteration,agc_idle_publish_wait: new onmainsince0afa6a607.ctestonmain0afa6a607:agc_driver_tessellation, the Mesa crash of #5444.ctest -R '^agc_'on lavapipe: 573/573.maind92a8dad3plusagc_import_watch_other_family, which is new onmainand skips because this device has no other queue family.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)0x1638), Mesa 26.2.4, CachyOS Linux 7.2.9; lavapipe, Mesa 26.2.4 (built locally), same machine🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-15T11:49:12Z.
Windows and NVIDIA run, for the "GPUs tested" line (RADV and lavapipe on Linux only). Windows 11 (26200), RTX 3060 Laptop GPU (NVIDIA 617.42), WinLibs GCC 15.2.0 r7 (UCRT), Release,
BUILD_TESTING=ON. Head891885201merged ontomain8856f180c(clean);ANYPS5_GPU=3060, and a verbose test log shows the RTX 3060 selected.vulkaninfolistsSUBGROUP_FEATURE_QUAD_BITfor this device, withsubgroupQuadOperationsInAllStages = true.agc_shader_memory: passes.VulkanDevice.cpp,ShaderValidation.cpp,SpirvSubgroup.hpp,SpirvSubgroup.cpp,SpirvAluEmitterMath.cpp) frommainand the PR's test (2 of 2 runs),agc_shader_memoryfails:a pixel quad_perm read did not go through quad operations.ctest -R "agc|shader|guest_memory|write_watch" -j4: 591/591 pass with the PR, and 591/591 onmain. Both skip the same 3 tests (agc_host_import_sparse,agc_driver_sparse_dma_buf_import,agc_driver_stencil_ref_export).Not checked: which of the GPU tests above run a pixel shader with a DPP
quad_permread, so the suite result does not show that the quad path ran on NVIDIA. Not run: PS5 OpenGL Showcase, Intel.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T14:16:19Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head 891885201 merged on main
3ee537191:PS5 OpenGL Showcase (PPSA99005, catalog 1.0.1), 90 s per run,
ANYPS5_REQUIRE_DISPLAY=1,APS5_DUMP_FRAMESevery 30 presents (960x540). The title runs until the limit in every run; no stop line and no error indownload0/ps5-opengl.log.main8856f180c: 379 frames (410 in a second run).The #6289 symptom (white bloom cloud with black specks over the 8192 instances, RADV) does not occur on NVIDIA
main. Before and after, every dump shows the instances as shaded, faceted icosahedra and cubes, as in your fix image. The share of near-white pixels is 1.0-2.3% per dump before and 1.05-2.4% after; your RADVmainimage has 27.7% and your fix image 1.9%. So this run shows no regression on NVIDIA, not the fix itself. (#6289 returns 404 for me, so the symptom is taken from the PR body.)The quad path does run here (RTX 4070, subgroup 32). I checked the cold per-run shader cache:
main: two of the 31 SPIR-V modules hold 15OpGroupNonUniformShuffleeach.OpGroupNonUniformQuadBroadcasteach, and no module has a shuffle.The 15 reads in the title take no source-EXEC check.
Tests:
agc_shader_memory: 3/3.VulkanDevice.cpp,ShaderValidation.cpp,SpirvSubgroup.hpp,SpirvSubgroup.cppandSpirvAluEmitterMath.cppfrommainand your test kept, it fails 2/2 witha pixel quad_perm read did not go through quad operations.dpp,quad,swizzle,derivatives,pixel_helper_lanes,wave_reduction,float16_dot,agc_dpp_write,agc_shader_memory),--repeat until-fail:3: 57/57.ctest -R '^agc_driver_' -j1: 446/447, with 2 skipped (sparse_dma_buf_import,stencil_ref_export). The failure,agc_driver_store_over_untracked("the first result was not stored"), also fails with your five files reverted on the same merge and passes on8856f180c. That test changed in #5671, so it is not from this PR.-j8): 11 failures, run on a loaded host at the same time as the GPU suite. On a serial rerun all pass excepthardware_oracle_compare, which still hits its 20 s limit, as onmainunder load.tools/check_conventions.py --base origin/main: passes.git diff origin/main --check: clean.Review:
EmitDppGroupPermTargetLane(2 bits per lane). It matches ACO'sdpp_quad_permencoding (aco_builder_h.py, mesa-26.2.4). Thenir_gather_info.clines you cite say what the description says.EmitDppWriteCondition. fi returns the read. Without fi the result is 0 when the source EXEC is clear. Other DPP16 controls and DPP8 keep the shuffle.QuadBroadcastinstead of a ballot. That is only defined while the source invocation is active (helpers count; an invocation terminated earlier would not). The title does not take that path.agc_driver_test runs a pixel shader with a quad_perm read. The DPP execution tests are compute, andpixel_wave_reductionuses row_shr. On the GPU side only the title exercises the new path.No other concerns.
Written with Claude Code assistance.
Imported from boykopovar/AnyPS5. Originally posted by jackthereaper2006 on 2026-10-15T16:28:38Z.
Thanks to both of you. The NVIDIA results cover the GPU I could not test. The module scan (15 shuffles → 60
OpGroupNonUniformQuadBroadcast, no shuffle left) shows the quad path runs on NVIDIA too.@screamm on the source-EXEC point: you're right that
OpGroupNonUniformQuadBroadcastis only defined while the source invocation is active, where the ballot would have reported a gone lane as inactive. In a pixel shader that has a DPP read, a lane can't leave before the read:SpirvModuleEmitter.cpp:1212-1234) becomesOpDemoteToHelperInvocationwhen the program reads neighbour lanes.DppMoveU32andDppUpdateU32count as such reads (SpirvAnalysis.cpp:16-17). Without demote support that compile throws. A demoted lane is a helper, and helpers take part in quad operations.EmitReturnTerminator(SpirvFlowEmitter.cpp:83-110), after the last instruction.OpKillis the BDA fault path (SpirvBdaFault.cpp:118). It runs after a fault has already been recorded.On the missing GPU coverage: 3dd3a9832 adds
agc_driver_pixel_quad_perm_helpers. It draws the skewed triangles ofPixelWaveReductionand turns whole-quad mode on withs_wqm. Then it reads the horizontal and vertical neighbour's pixel index throughv_mov_b32_dpp quad_perm:[1,0,3,2]and[2,3,0,1], with and withoutfi, in wave64 and wave32. Every covered pixel must read its neighbour's index, helper or not.SpirvAluEmitterMath.cppfrommain: fails 3/3 withpixel 584 read 0 from quad_perm [1,0,3,2], its helper neighbour is pixel 585.PixelHelperLanes.ctest: 1227/1227 with Mesa patched for #5444, and 1226/1227 on stock Mesa 26.2.4 (agc_driver_tessellation, #5444).#6289 loads for me signed out (HTTP 200), so the 404 may have been a token without discussion access.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T22:07:15Z.
Rerun on
3dd3a9832, merged on main44df21632(Windows 11 Pro 26220, NVIDIA RTX 4070 596.21, MinGW GCC 15.2):agc_driver_pixel_quad_perm_helpers,--repeat until-fail:3: 3 of 3 pass, not skipped. A direct run prints 4432 reads from helper neighbours over 4 draws for each of wave64, wave64fi, wave32 and wave32fi(the same count you report on RADV).ctest -R 'quad|dpp'(11 tests, includingagc_driver_quad_pixel_maskand thedpp16/dpp8tests),-j1 --repeat until-fail:3: all pass.SpirvAluEmitterMath.cpptaken frommain(your control) the test still passes, 3 of 3 direct runs, 4432 reads per variant. With the other four source files reverted as well, it is skipped by the new capability gate. So the new test pins the quad path on RADV but cannot distinguish it from the shuffle on NVIDIA, where the shuffle already returns the neighbour's value for helper lanes. That matches the earlier title run (no #6289 symptom on NVIDIAmain). I am not asking for a change, just noting what the test covers here.agc_driver_gpu_indirect_arguments_misaligned_writer_ahead_tests, which fails onmainas well here (65536 alignment, #6452/#6478).Not rerun: the full GPU and non-GPU suites and the PPSA99005 title run on this head.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-16T07:53:56Z.
Windows with AMD's own driver, the combination not covered yet: the Showcase artifact from #6289 shows up there on
maintoo, and this change fixes it. The new test also works as a negative control on this driver.Setup: Windows 11 Home 26300, AMD Radeon 860M (RDNA 3.5,
1002:1114, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release. Head3dd3a9832merged ontomain5d9dcc42d(clean merge). PS5 OpenGL Showcase, catalog 1.0.1, relinked with--windows, warm shader cache. Frame dumps useAPS5_DUMP_FRAMES=5,APS5_DUMP_FRAMES_EVERY=20, from one 45 s run per build.Title
mainthe 8192 instances render as a white bloom band with black specks across the middle of the screen, as in the RADV image on #6289. Near-white pixels (all channels > 235) make up 21.0 / 20.8 / 21.3 / 23.9 / 39.3 % of the five dumps.main. That cost is #6189 / #6202.Tests
agc_driver_pixel_quad_perm_helpersandagc_shader_memorypass.SpirvAluEmitterMath.cpptaken frommain,agc_driver_pixel_quad_perm_helpersfails 3 of 3 withpixel quad_perm wave64: pixel 584 read 0 from quad_perm [1,0,3,2], its helper neighbour is pixel 585. So on this driver the shuffle loses helper lanes as on RADV, and the test does tell the two paths apart here, unlike on NVIDIA.ctest -R 'quad|dpp|agc_shader_memory'(12 tests): all pass exceptagc_driver_quad_pixel_mask, which fails onmainon this GPU too and is fixed by #6255.--repeat until-fail:3). The Showcase dumps then look the same as with this change alone. #6255 kills demoted pixels when the program returns, after the DPP reads, so the two don't interfere.Not tested: discrete RDNA, Linux.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by odntht on 2026-10-16T19:59:54Z.
An Intel run, for the "Not run: Intel" line. It passes, but Gen9 does not show the bug on
maineither.Setup: Intel HD Graphics 520 (Skylake GT2, Gen9), Mesa 25.2.8 ANV, Ubuntu 24.04 (container), kernel 6.12.111, GCC 13.3, Release. Head
3dd3a9832merged ontomainf474fb776(clean).ANYPS5_GPU="HD Graphics 520"; the log shows it selected,subgroup=32. ANV reportsSUBGROUP_FEATURE_QUAD_BITfor the fragment stage.agc_driver_pixel_quad_perm_helperspasses 3 of 3 (4432 reads from helper neighbours over 4 drawsfor wave64, wave64 fi, wave32 and wave32 fi).agc_shader_memory,agc_shader_quad_mask_no_demote,agc_driver_quad_pixel_maskandagc_driver_vop3_quad_sadpass 3 of 3.main: the new test skips (the device has no subgroup quad operations), becausemainnever addsGroupNonUniformQuad.agc_shader_memoryfails as expected (a pixel quad_perm read did not go through quad operations).VulkanDevice.cppandShaderValidation.cppwithmain'sSpirvSubgroup.*andSpirvAluEmitterMath.cpp, so the old shuffle path runs on a device that advertises quad:agc_driver_pixel_quad_perm_helpersalso passes 3 of 3, with the same 4432 reads.So on ANV Gen9, as on lavapipe, the shuffle path already reads helper neighbours correctly, and the PR keeps it working. The test does not catch the RADV failure on this device. I could not run the PS5 OpenGL Showcase here.
AI-assisted: yes (Claude Code). The runs are on my machine.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T02:46:21Z.
Review: APPROVED
Merged head
3dd3a9832onto currentmain(40393b0f9) — clean merge, builds with WinLibs GCC 15.2.0, Release, Ninja,-j 8. Windows 11, NVIDIA GeForce RTX 5090 (selected device; RTX 4090 and an AMD iGPU are also present), 32-lane subgroups.Tests run on the merged tree:
agc_shader_memory— pass (includes the new pixel quad_perm check)agc_driver_pixel_quad_perm_helpers— passagc_dpp_write,agc_driver_dpp8,agc_driver_dpp8_pk_fmac,agc_driver_dpp16_inactive_source,agc_driver_dpp16_operands,agc_driver_dpp16_row_share_xmask,agc_driver_dpp_no_form,agc_driver_quad_pixel_mask,agc_driver_vop3_quad_sadrequest_serializer,agc_driver_gpu_buffer_format,agc_driver_layered_volume_draw— passNegative control (plain
main40393b0f9plus only this PR's test changes):agc_shader_memoryfails with "a pixel quad_perm read did not go through quad operations"agc_driver_pixel_quad_perm_helpersskips (exit 77, "skipped, the device has no subgroup quad operations") because main does not exposeGroupNonUniformQuadNote: on NVIDIA the exec test passes even without the emitter change (NVIDIA keeps helpers in the shuffle), so on this machine the failing negative control is the
agc_shader_memorycheck; the RADV-specific failure was already demonstrated by @jackthereaper2006 and @LeandroLP23 above.Read through the diff: capability exposure in
VulkanDevice.cpp, validation mapping inShaderValidation.cpp, and quad-broadcast emission for pixel-stage quad_perm reads (control ≤ 0xff) covering both the DPP move value and the write-condition source EXEC check — no problems found. Not tested here: AMD, Intel, Linux, titles.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T22:48:27Z.
Review: APPROVED
Reviewed — approved
Pixel-shader DPP
quad_permreads now go throughOpGroupNonUniformQuadBroadcastwhen the device has quad operations. The change merges cleanly and builds. The focused tests pass, and the newagc_shader_memorycheck fails once the production files are reverted tomain.What I ran
Head
5e25bc870e6eda3f0cb994290a53f71cac0aaf8d,main1c8c0efc8c41314402e6966da5bef6ea3d639d10, merged tree2c00d3afe895b0453533a9f7e4019b234ca50c7d. The machine is Debian 13 (VM, 32 vCPU Xeon Gold 6136) with GCC 14.2.0, and Vulkan runs on lavapipe (Mesa 26.1.6, LLVM 19, 8-lane subgroups).Results
git diff --checkcheck_conventions.pylibs(script)agc_driver_division, denormal-mode tests,vector_constant_factor_tininess, an unwrap test) also fail onmaincheck_skips.pyagc_shader_memory,agc_dpp_write,agc_driver_quad_pixel_mask,agc_shader_quad_mask_no_demote. 3 skip on lavapipe with "subgroup size 8 cannot hold a wave32":agc_driver_pixel_quad_perm_helpers,agc_driver_pixel_helper_lanes,agc_driver_dpp16_inactive_sourcemainisagc_driver_image_gather_volume(VUID-VkSamplerCreateInfo-addressMode*). That test is marked "test not run on main", so the baseline has no comparison for it. It checks sampler address modes, which this change does not touch, so I don't count it against the PRgit status --porcelainis emptyagc_driver_pixel_quad_perm_helpers on lavapipe
Negative control
I restored these five production files from
main:VulkanDevice.cppShaderValidation.cppSpirvSubgroup.hppSpirvSubgroup.cppSpirvAluEmitterMath.cppI kept the PR's tests and rebuilt
agc_shader_memory_tests. It fails with:After I restored the merged files, it passes again.
The GPU execution test
agc_driver_pixel_quad_perm_helpersskips on this machine, so I couldn't run a negative control for it. Others ran it in the discussion:Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp:317-329, used atcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp:1382-1386and:196).OpGroupNonUniformQuadBroadcastplus three selects. A move withoutfiemits that twice, once for the value and once for the source EXEC. That is why screamm counted 60 broadcasts where there were 15 shuffles before.controlis a compile-time constant. When all four entries are the same (0x00, 0x55, 0xaa, 0xff), oneOpGroupNonUniformQuadBroadcastwith that index is enough.[1,0,3,2],[2,3,0,1]and[3,2,1,0]map directly toOpGroupNonUniformQuadSwapwith direction 0, 1 and 2.QuadBroadcastof EXEC is undefined when the source invocation is inactive was raised by screamm and answered by the author. I checked that pixel shaders keep the scalar control flow uniform here, and I have nothing new to add. Astronaut10's coverage notes onrow_xmaskand reconvergence are follow-up scope.Not verified
agc_driver_pixel_quad_perm_helpersskips because of the 8-lane subgroup, so I didn't run any pixelquad_permread on a GPU here. The RADV, AMD Windows, NVIDIA and Intel results come from the discussion, not from my runs.agc_driver_pixel_quad_perm_helpers. It skipped, so it reached no draw.