fix(agc): run wave32 compute programs on 32-wide subgroups #316

Merged
adriadam10 merged 2 commits from upstream-pr/316 into main 2026-10-04 07:09:16 +00:00
adriadam10 commented 2026-10-02 04:29:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T04:29:14Z.


What

On devices whose default subgroup is 64 lanes (RADV; AMD on Windows reports 64 too), a wave32 compute program was compiled for a 64-wide host subgroup. With more than 32 threads per workgroup, two guest waves then share one host subgroup, so everything wave-wide in the second wave sees the first one: v_mbcnt lane ids, ballots/VCC, EXEC saved or changed by v_cmpx, v_readlane. On RADV, a 64-thread wave32 dispatch gives v_mbcnt_lo = 32..63 in the second wave instead of 0..31.

Fix, with VK_EXT_subgroup_size_control:

  • VulkanDevice enables subgroupSizeControl when the default subgroup is wider than 32, 32 lies in [minSubgroupSize, maxSubgroupSize] and compute is in requiredSubgroupSizeStages.
  • VulkanDevice::ComputeTarget(waveSize) returns Target() with subgroupSize = 32 for wave32 programs on such devices. Dispatch.cpp uses it, so the program is recompiled for a 32-wide host subgroup, the path NVIDIA already takes.
  • RecompileResult::hostSubgroupSize records the width the program was laid out for. It is stored in the disk cache and fills existing padding, so the struct size is unchanged. The compute pipeline adds VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT{32} when it is 32 and the device's default is not.

Wave64 programs and devices whose default is already 32 (NVIDIA) are unchanged. The cache key already includes target.subgroupSize.

Not in this PR: graphics stages. RADV can require 32 for fragment/mesh/task, but not vertex. That needs per-stage widths in Pipeline.cpp and its own tests, so it is a follow-up.

Test agc_driver_wave32_subgroup: one 64-thread wave32 dispatch, hand-assembled (words from llvm-mc -mcpu=gfx1013). Each lane checks v_mbcnt_lo (lane in its wave), s_bcnt1 of a VCC compare (8 per wave), v_readlane_b32 lane 3 (its own wave's lane 3), and the EXEC save → v_cmpx → restore pattern. It is skipped when the device cannot run wave32 on 32-wide subgroups (lavapipe: 8).

Tested

Linux, full ctest (99) passes.

  • RADV (Radeon 660M): test passes; the log shows "Compute wave32 programs run on subgroups of 32".
  • Same test with device->Target() (the old path): thread 32 v_mbcnt_lo_u32_b32 is 32, expected 0.
  • lavapipe: skipped.
  • Merges cleanly with the open PRs touching VulkanDevice / Recompiler / ShaderDiskCache (#218 #261 #278 #282 #290 #291).

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
  • 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: #251 (test harness); review only the last commit
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4712689370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/316). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T04:29:14Z. --- ### What On devices whose default subgroup is 64 lanes (RADV; AMD on Windows reports 64 too), a wave32 compute program was compiled for a 64-wide host subgroup. With more than 32 threads per workgroup, two guest waves then share one host subgroup, so everything wave-wide in the second wave sees the first one: `v_mbcnt` lane ids, ballots/VCC, EXEC saved or changed by `v_cmpx`, `v_readlane`. On RADV, a 64-thread wave32 dispatch gives `v_mbcnt_lo` = 32..63 in the second wave instead of 0..31. Fix, with `VK_EXT_subgroup_size_control`: - `VulkanDevice` enables `subgroupSizeControl` when the default subgroup is wider than 32, 32 lies in `[minSubgroupSize, maxSubgroupSize]` and compute is in `requiredSubgroupSizeStages`. - `VulkanDevice::ComputeTarget(waveSize)` returns `Target()` with `subgroupSize = 32` for wave32 programs on such devices. `Dispatch.cpp` uses it, so the program is recompiled for a 32-wide host subgroup, the path NVIDIA already takes. - `RecompileResult::hostSubgroupSize` records the width the program was laid out for. It is stored in the disk cache and fills existing padding, so the struct size is unchanged. The compute pipeline adds `VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT{32}` when it is 32 and the device's default is not. Wave64 programs and devices whose default is already 32 (NVIDIA) are unchanged. The cache key already includes `target.subgroupSize`. Not in this PR: graphics stages. RADV can require 32 for fragment/mesh/task, but not vertex. That needs per-stage widths in `Pipeline.cpp` and its own tests, so it is a follow-up. Test `agc_driver_wave32_subgroup`: one 64-thread wave32 dispatch, hand-assembled (words from `llvm-mc -mcpu=gfx1013`). Each lane checks `v_mbcnt_lo` (lane in its wave), `s_bcnt1` of a VCC compare (8 per wave), `v_readlane_b32 lane 3` (its own wave's lane 3), and the EXEC save → `v_cmpx` → restore pattern. It is skipped when the device cannot run wave32 on 32-wide subgroups (lavapipe: 8). ### Tested Linux, full ctest (99) passes. - RADV (Radeon 660M): test passes; the log shows "Compute wave32 programs run on subgroups of 32". - Same test with `device->Target()` (the old path): `thread 32 v_mbcnt_lo_u32_b32 is 32, expected 0`. - lavapipe: skipped. - Merges cleanly with the open PRs touching `VulkanDevice` / `Recompiler` / `ShaderDiskCache` (#218 #261 #278 #282 #290 #291). ### 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) - [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: #251 (test harness); review only the last commit - [x] AI-assisted: yes
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!316
No description provided.