fix(shader): isolate wave32 operations in wide host subgroups #587

Merged
nicolasabosch merged 1 commit from upstream-pr/587 into main 2026-10-05 01:25:04 +00:00
nicolasabosch commented 2026-10-05 00:01:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-05T00:01:08Z.


What

Addresses #487: a wave32 shader on a 64-wide host subgroup currently uses the lower ballot word and physical lane IDs for both guest waves. This can mix EXEC/VCC counts and lane reads between independent waves, including the reported RDNA4 pixel-helper failure.

Keep lane IDs in 0..31, select the ballot word belonging to the current 32-lane partition, and translate guest shuffle targets back to physical subgroup lanes. Apply the mapping to lane reads, DPP/DS operations, lane activity, and append/consume broadcasts. Wave64 handling and native wave32 targets keep their existing paths. The partition is derived from the actual invocation ID, so a wide target can also execute on a 32-wide subgroup.

Add a hardware-independent test that evaluates emitted SPIR-V fragments for 32-, 64-, and 128-wide subgroups with independent and empty EXEC masks. Expand the compute test to run native wide subgroups and the pixel/compute tests to exercise wide-target emission on 32-wide hardware.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 4070 Laptop GPU; synthetic shader fixtures, no commercial title tested. Built with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON.

  • Full build and cmake --build build --target libs passed.
  • Full CTest: 222/222 passed, no skips, with ANYPS5_REQUIRE_VULKAN=1 and SPIRV-Tools enabled (88.69 seconds).
  • Pixel helper lanes, wave32 subgroup, readfirstlane/readlane, scalar bit count, DS permute, and DPP tests passed with SPIRV-Tools validation and GPU execution.
  • The new CPU test passed all 18 subgroup/mask combinations. Removing ballot partitioning, shuffle translation, or lane-ID masking independently makes it fail; restored code passes.

The RTX 4070 has 32-wide subgroups: its wide-target runs validate the generated code and lower partition, not physical 64-wide execution. Upper partitions are covered by the CPU test. Direct confirmation on the AMD hardware from #487 remains pending; this PR does not claim measured title compatibility or FPS improvements.

Rebased onto 9651ec9a, including the newly merged #574. During validation, agc_shader_memory exposed the existing vector OpSelect error on clean 07404b67; #574 contains the same correction independently validated locally. The final suite includes that upstream fix and passes completely.

The ballot and shuffle mapping follows the Vulkan subgroup operation semantics.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (no new dependencies)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4738591446 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/587). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-05T00:01:08Z. --- ### What Addresses #487: a wave32 shader on a 64-wide host subgroup currently uses the lower ballot word and physical lane IDs for both guest waves. This can mix EXEC/VCC counts and lane reads between independent waves, including the reported RDNA4 pixel-helper failure. Keep lane IDs in 0..31, select the ballot word belonging to the current 32-lane partition, and translate guest shuffle targets back to physical subgroup lanes. Apply the mapping to lane reads, DPP/DS operations, lane activity, and append/consume broadcasts. Wave64 handling and native wave32 targets keep their existing paths. The partition is derived from the actual invocation ID, so a wide target can also execute on a 32-wide subgroup. Add a hardware-independent test that evaluates emitted SPIR-V fragments for 32-, 64-, and 128-wide subgroups with independent and empty EXEC masks. Expand the compute test to run native wide subgroups and the pixel/compute tests to exercise wide-target emission on 32-wide hardware. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 4070 Laptop GPU; synthetic shader fixtures, no commercial title tested. Built with `BUILD_TESTING=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. - Full build and `cmake --build build --target libs` passed. - Full CTest: 222/222 passed, no skips, with `ANYPS5_REQUIRE_VULKAN=1` and SPIRV-Tools enabled (88.69 seconds). - Pixel helper lanes, wave32 subgroup, readfirstlane/readlane, scalar bit count, DS permute, and DPP tests passed with SPIRV-Tools validation and GPU execution. - The new CPU test passed all 18 subgroup/mask combinations. Removing ballot partitioning, shuffle translation, or lane-ID masking independently makes it fail; restored code passes. The RTX 4070 has 32-wide subgroups: its wide-target runs validate the generated code and lower partition, not physical 64-wide execution. Upper partitions are covered by the CPU test. Direct confirmation on the AMD hardware from #487 remains pending; this PR does not claim measured title compatibility or FPS improvements. Rebased onto `9651ec9a`, including the newly merged #574. During validation, `agc_shader_memory` exposed the existing vector `OpSelect` error on clean `07404b67`; #574 contains the same correction independently validated locally. The final suite includes that upstream fix and passes completely. The ballot and shuffle mapping follows the [Vulkan subgroup operation semantics](https://docs.vulkan.org/spec/latest/chapters/shaders.html#shaders-group-operations). ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (no new dependencies) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, Codex
github-actions[bot] commented 2026-10-05 00:22:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T00:22:27Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#513 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp L9-10
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp L30-33
#515 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp L9-10
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp L30-33
#522 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp L9-10
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp L30-33
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986009442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/587#issuecomment-5986009442). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T00:22:27Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #513 | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp` [L9-10](https://github.com/boykopovar/AnyPS5/blob/4ae4f53ffb4a5fcb6a42a166b0acb6f654a6711e/core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp#L9-L10)<br>`core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp` [L30-33](https://github.com/boykopovar/AnyPS5/blob/4ae4f53ffb4a5fcb6a42a166b0acb6f654a6711e/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp#L30-L33) | | | | #515 | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp` [L9-10](https://github.com/boykopovar/AnyPS5/blob/4ae4f53ffb4a5fcb6a42a166b0acb6f654a6711e/core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp#L9-L10)<br>`core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp` [L30-33](https://github.com/boykopovar/AnyPS5/blob/4ae4f53ffb4a5fcb6a42a166b0acb6f654a6711e/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp#L30-L33) | | | | #522 | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp` [L9-10](https://github.com/boykopovar/AnyPS5/blob/4ae4f53ffb4a5fcb6a42a166b0acb6f654a6711e/core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvMemory/SpirvSubgroup.hpp#L9-L10)<br>`core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp` [L30-33](https://github.com/boykopovar/AnyPS5/blob/4ae4f53ffb4a5fcb6a42a166b0acb6f654a6711e/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cpp#L30-L33) | | |
oneandonlydean commented 2026-10-05 01:18:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T01:18:32Z.


Thanks, this is a clean way to do it. I went through every subgroup operation the SPIR-V backend emits: the ballots, the shuffles (readlane, readfirstlane and DPP go through Shuffle), EmitDsMaskedLaneRead, the lane-active check and the append/consume broadcast all go through the new mapping, and FirstLane works on the already reduced ballot, so I couldn't find a path that still sees the other wave's lanes. On a 32-wide target every helper returns its input, so the SPIR-V there is unchanged.

I can only run it on 32-wide subgroups, so here the new wave32_wide_subgroup test is the part that shows the fix: it passes on this branch and doesn't build on main's code. The wide-target passes added to the pixel helper and wave32 tests also pass on main on 32-wide hardware, as expected, since the whole subgroup is partition 0 there. A run from the AMD reporter in #487 would be the real check, as you say.

Heads-up: #513, #515 and #522 (DPP) edit lines next to yours in SpirvSubgroup.hpp/.cpp, so whichever lands second needs a small rebase. #515's new source-lane check uses ctx.Ballot with the guest lane, so it stays correct with this change.

This doesn't affect PPSA21564 on my setup (32-wide subgroups). Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986482729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/587#issuecomment-5986482729). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T01:18:32Z. --- Thanks, this is a clean way to do it. I went through every subgroup operation the SPIR-V backend emits: the ballots, the shuffles (readlane, readfirstlane and DPP go through `Shuffle`), `EmitDsMaskedLaneRead`, the lane-active check and the append/consume broadcast all go through the new mapping, and `FirstLane` works on the already reduced ballot, so I couldn't find a path that still sees the other wave's lanes. On a 32-wide target every helper returns its input, so the SPIR-V there is unchanged. I can only run it on 32-wide subgroups, so here the new `wave32_wide_subgroup` test is the part that shows the fix: it passes on this branch and doesn't build on main's code. The wide-target passes added to the pixel helper and wave32 tests also pass on main on 32-wide hardware, as expected, since the whole subgroup is partition 0 there. A run from the AMD reporter in #487 would be the real check, as you say. Heads-up: #513, #515 and #522 (DPP) edit lines next to yours in `SpirvSubgroup.hpp`/`.cpp`, so whichever lands second needs a small rebase. #515's new source-lane check uses `ctx.Ballot` with the guest lane, so it stays correct with this change. This doesn't affect PPSA21564 on my setup (32-wide subgroups). Ready to merge from my side.
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!587
No description provided.