fix(shader): sum the append/consume result over the guest wave instead of shuffling it from the first lane #24575
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24575"
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 cryst4lpepsi on 2026-11-20T20:09:24Z.
What
ds_appendandds_consume(LDS and GDS) hand the first active lane's atomic result to the other lanes withOpGroupNonUniformShuffle, at a lane index fromOpGroupNonUniformBallotFindLSB. AMD's Windows driver 23.19 on GCN 5 faults insidevkCreateGraphicsPipelineson that shuffle in a pixel shader (#18480). With the index guarded byOpSelect, asEmitReadFirstLanedoes, it hangs in pipeline creation instead.Narrowed on a Radeon Vega iGPU (
1002:1638) by changing only the final shuffle:FindLSBlane (main)amdvlk64.dll+0x21d1c24OpGroupNonUniformBroadcastFirstOpSelect(any, FindLSB, 0)Only the first lane of the guest wave runs the atomic. Every other lane gets 0 from
EmitValueOrZeroIfCondition. So anOpGroupNonUniformIAddreduction over the host lanes that hold the guest wave gives every lane the same value the shuffle did, with no lane index:Reducewhen the wave fills the host subgroup.ClusteredReducewith the wave's lane count (min(host subgroup, wave size / lanes per invocation)) when two waves share it, as wave32 does on a 64-lane subgroup.A reduction reads only active invocations, so it stays defined inside divergent control flow. A
ShuffleXorbutterfly, which also builds on this driver, would not.When the device lacks subgroup arithmetic, or lacks clustered operations while the wave shares the subgroup, the shuffle stays. Spanned waves and single-lane hosts also keep the shuffle.
EmitWaveSumsits with the other subgroup helpers inSpirvSubgroup.cpp. Devices that reportVK_SUBGROUP_FEATURE_CLUSTERED_BITnow listGroupNonUniformClustered, andShaderValidationchecks it like the other subgroup capabilities. On those devices the shader cache keys change once.ds_ordered_countstill shuffles its operand from theFindLSBlane before the atomic. No test reaches it on this device, so it is unchanged here.The latest comment on #18480 proposes skipping the test on a denylist of AMD drivers, or a fallback lowering for those drivers. This change needs neither: the trigger is the shuffle's computed lane index, not GDS append, and the reduction applies on every device that supports it.
#12944 changes the atomic step of the same function. Its ordered path still returns 0 to the lanes that do not run the atomic, so the sum stays correct, and the branches merge without conflicts.
Tested
Windows 11 Home 22621, WinLibs GCC 15.2.0 r7, Release,
maine481b13555. Rebased onto335fdd7770, which changes none of the files here or the two failing tests. Each test ran on its own (ctest -R ^<name>$ -V) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer. The validation layer is the Khronos nightly from 2026-11-20 (6ca326f85c). Every log showsInsert instance layer "VK_LAYER_KHRONOS_validation"and none showswas not found.mainmainagc_driver_recorded_draw_stagingagc_driver_pixel_lds_read_modify_writeagc_driver_ds_append_consumeagc_driver_gds_append_consumeagc_driver_pixel_wave_reductionagc_driver_pixel_row_reductionagc_driver_ngg_vertex_wave_reductionVUID-messages: none on either GPU, onmainor with this PR.agc_driver_pixel_lds_read_modify_writerunsds_appendon LDS, so the fix covers LDS as well as GDS.agc_shader_memoryandagc_wave_control_decode. Microsoft Defender quarantines their executables on this machine (objcopy ... Invalid argument, as BUILD.md describes).python tools/check_conventions.py --base origin/main: all checks passed.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)1002:1638), AMD proprietary driver 23.19.10.08, Windows 11 22621; NVIDIA GeForce RTX 3050 Ti Laptop GPU (10de:25a0), driver 596.36, Windows 11 22621Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:12:27Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected lowering and capability checks support merging.
What I ran
Reviewed head
8fc4f14e40aaf24339cdc04c0d87b128cbc42c3d. No commands or tests were run; I used the prepared diff and repository reader.Files read:
description.md,commits.md,manifest.json,diff.patch,ShaderValidation.cpp,SpirvSubgroup.hpp,SpirvMemoryInstructions.cpp,SpirvSubgroup.cpp,SpirvEmitter.cpp,SpirvEmitterHelpers.hpp, and the changedVulkanDevice.cpplines. The other full changed-file text was not included, so it was not read.Results
VulkanDevice.cppfull text was excludedFindings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
VulkanDevice.cppwas excluded as too large; only its changed lines were read. No tests or convention checks were run. The author-reported test results and hardware behavior were not independently verified.ShaderValidation.cpp,SpirvSubgroup.hpp,SpirvMemoryInstructions.cpp, andSpirvSubgroup.cppwere read in full;SpirvEmitter.cppandSpirvEmitterHelpers.hppwere read only in relevant ranges.To get this to a good state
Nothing is required.