fix(shader): sum the append/consume result over the guest wave instead of shuffling it from the first lane #24575

Merged
cryst4lpepsi merged 1 commit from upstream-pr/24575 into main 2026-11-27 09:35:40 +00:00
cryst4lpepsi commented 2026-11-20 20:09:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cryst4lpepsi on 2026-11-20T20:09:24Z.


What

ds_append and ds_consume (LDS and GDS) hand the first active lane's atomic result to the other lanes with OpGroupNonUniformShuffle, at a lane index from OpGroupNonUniformBallotFindLSB. AMD's Windows driver 23.19 on GCN 5 faults inside vkCreateGraphicsPipelines on that shuffle in a pixel shader (#18480). With the index guarded by OpSelect, as EmitReadFirstLane does, it hangs in pipeline creation instead.

Narrowed on a Radeon Vega iGPU (1002:1638) by changing only the final shuffle:

Final step Result
Shuffle at the FindLSB lane (main) fault in amdvlk64.dll+0x21d1c24
Same index, another value shuffled fault
Index made uniform with OpGroupNonUniformBroadcastFirst fault
Index guarded with OpSelect(any, FindLSB, 0) hang
Constant lane 0 builds and runs
No shuffle builds and runs

Only the first lane of the guest wave runs the atomic. Every other lane gets 0 from EmitValueOrZeroIfCondition. So an OpGroupNonUniformIAdd reduction over the host lanes that hold the guest wave gives every lane the same value the shuffle did, with no lane index:

  • Reduce when the wave fills the host subgroup.
  • ClusteredReduce with 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 ShuffleXor butterfly, 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. EmitWaveSum sits with the other subgroup helpers in SpirvSubgroup.cpp. Devices that report VK_SUBGROUP_FEATURE_CLUSTERED_BIT now list GroupNonUniformClustered, and ShaderValidation checks it like the other subgroup capabilities. On those devices the shader cache keys change once.

ds_ordered_count still shuffles its operand from the FindLSB lane 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, main e481b13555. Rebased onto 335fdd7770, which changes none of the files here or the two failing tests. Each test ran on its own (ctest -R ^<name>$ -V) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, APS5_NO_PIPELINE_JOURNAL=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer. The validation layer is the Khronos nightly from 2026-11-20 (6ca326f85c). Every log shows Insert instance layer "VK_LAYER_KHRONOS_validation" and none shows was not found.

Test Vega main Vega this PR RTX 3050 Ti main RTX 3050 Ti this PR
agc_driver_recorded_draw_staging SegFault pass pass pass
agc_driver_pixel_lds_read_modify_write SegFault pass pass pass
agc_driver_ds_append_consume pass pass pass pass
agc_driver_gds_append_consume pass pass pass pass
agc_driver_pixel_wave_reduction pass pass pass pass
agc_driver_pixel_row_reduction pass pass pass pass
agc_driver_ngg_vertex_wave_reduction skipped skipped pass pass
  • VUID- messages: none on either GPU, on main or with this PR.
  • agc_driver_pixel_lds_read_modify_write runs ds_append on LDS, so the fix covers LDS as well as GDS.
  • Not run: agc_shader_memory and agc_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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Fixes #18480
  • Unblocks: none
  • GPUs tested: AMD Radeon Graphics (Vega iGPU, 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 22621
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5419578950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24575). Originally posted by [cryst4lpepsi](https://github.com/cryst4lpepsi) on 2026-11-20T20:09:24Z. --- ### What `ds_append` and `ds_consume` (LDS and GDS) hand the first active lane's atomic result to the other lanes with `OpGroupNonUniformShuffle`, at a lane index from `OpGroupNonUniformBallotFindLSB`. AMD's Windows driver 23.19 on GCN 5 faults inside `vkCreateGraphicsPipelines` on that shuffle in a pixel shader (#18480). With the index guarded by `OpSelect`, as `EmitReadFirstLane` does, it hangs in pipeline creation instead. Narrowed on a Radeon Vega iGPU (`1002:1638`) by changing only the final shuffle: | Final step | Result | |---|---| | Shuffle at the `FindLSB` lane (`main`) | fault in `amdvlk64.dll+0x21d1c24` | | Same index, another value shuffled | fault | | Index made uniform with `OpGroupNonUniformBroadcastFirst` | fault | | Index guarded with `OpSelect(any, FindLSB, 0)` | hang | | Constant lane 0 | builds and runs | | No shuffle | builds and runs | Only the first lane of the guest wave runs the atomic. Every other lane gets 0 from `EmitValueOrZeroIfCondition`. So an `OpGroupNonUniformIAdd` reduction over the host lanes that hold the guest wave gives every lane the same value the shuffle did, with no lane index: - `Reduce` when the wave fills the host subgroup. - `ClusteredReduce` with 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 `ShuffleXor` butterfly, 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. `EmitWaveSum` sits with the other subgroup helpers in `SpirvSubgroup.cpp`. Devices that report `VK_SUBGROUP_FEATURE_CLUSTERED_BIT` now list `GroupNonUniformClustered`, and `ShaderValidation` checks it like the other subgroup capabilities. On those devices the shader cache keys change once. `ds_ordered_count` still shuffles its operand from the `FindLSB` lane 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, `main` `e481b13555`. Rebased onto `335fdd7770`, which changes none of the files here or the two failing tests. Each test ran on its own (`ctest -R ^<name>$ -V`) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `APS5_NO_PIPELINE_JOURNAL=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`. The validation layer is the Khronos nightly from 2026-11-20 (`6ca326f85c`). Every log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"` and none shows `was not found`. | Test | Vega `main` | Vega this PR | RTX 3050 Ti `main` | RTX 3050 Ti this PR | |---|---|---|---|---| | `agc_driver_recorded_draw_staging` | SegFault | pass | pass | pass | | `agc_driver_pixel_lds_read_modify_write` | SegFault | pass | pass | pass | | `agc_driver_ds_append_consume` | pass | pass | pass | pass | | `agc_driver_gds_append_consume` | pass | pass | pass | pass | | `agc_driver_pixel_wave_reduction` | pass | pass | pass | pass | | `agc_driver_pixel_row_reduction` | pass | pass | pass | pass | | `agc_driver_ngg_vertex_wave_reduction` | skipped | skipped | pass | pass | - `VUID-` messages: none on either GPU, on `main` or with this PR. - `agc_driver_pixel_lds_read_modify_write` runs `ds_append` on LDS, so the fix covers LDS as well as GDS. - Not run: `agc_shader_memory` and `agc_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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: Fixes #18480 - [x] Unblocks: none - [x] GPUs tested: AMD Radeon Graphics (Vega iGPU, `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 22621 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 20:12:27 +00:00 (Migrated from github.com)

Imported 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 changed VulkanDevice.cpp lines. The other full changed-file text was not included, so it was not read.

Results

Check Result Note
Diff and changed code review passed Relevant lowering and capability paths inspected
Tests not run Author-reported GPU runs were not independently verified
Full changed-file coverage not run VulkanDevice.cpp full text was excluded

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full text of VulkanDevice.cpp was 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, and SpirvSubgroup.cpp were read in full; SpirvEmitter.cpp and SpirvEmitterHelpers.hpp were read only in relevant ranges.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5998734531 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24575#pullrequestreview-5998734531). Originally posted by [MarcZX10](https://github.com/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 changed `VulkanDevice.cpp` lines. The other full changed-file text was not included, so it was not read. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Relevant lowering and capability paths inspected | | Tests | not run | Author-reported GPU runs were not independently verified | | Full changed-file coverage | not run | `VulkanDevice.cpp` full text was excluded | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full text of `VulkanDevice.cpp` was 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`, and `SpirvSubgroup.cpp` were read in full; `SpirvEmitter.cpp` and `SpirvEmitterHelpers.hpp` were read only in relevant ranges. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!24575
No description provided.