fix(shader): throw for constant lane reads outside the host subgroup #997

Merged
Celegans12 merged 1 commit from upstream-pr/997 into main 2026-10-07 12:08:56 +00:00
Celegans12 commented 2026-10-06 22:29:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T22:29:37Z.


What

On a 32-lane host, the pixel, vertex and tessellation stages of a wave64 program run one guest lane per invocation (compute and mesh hold two), so lanes 32-63 have no invocation, yet v_readlane_b32 still shuffled from them.

  • When a non-compute wave runs one lane per invocation on a narrower host subgroup, EmitReadLane throws for a constant lane at or above the subgroup size, and EmitPermlane16U32 throws for v_permlanex16_b32 on subgroups of 16 lanes or fewer.
  • Register lanes still build, so s_ff1_i32_b64 waterfalls are unaffected.
  • Permlane takes the source lane's EXEC from a ballot, as DPP does, instead of shuffling it from a possibly inactive invocation. TechnicalDebt notes what is still inexact.
  • PPSA26344 v1.008: the "UI Post Fade" pixel shader (0x80003c5100) reads lanes 31 and 63 after a DPP min scan; with lane 63 undefined, its loop can spin forever and hang the GPU (at about 160 s in our runs). It now fails to build on 32-lane hosts, so its draws are skipped. Ten more pixel programs in the title also read a constant lane 63, 0x80002f0b00 among them; on main they stop earlier, at image-table descriptors (#920). Running them exactly needs lane reads across subgroups, which is a design question.
  • No open PR edits these functions; pr_overlap reports none.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main c1241ad0: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 365/365 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 364/364 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New verifyLanesOutsideHostSubgroup in agc_shader_memory (CPU only): lane 63 throws on 32 and 8 lanes but builds on 64 and as compute on 32 and 8, lane 31 throws only on 8, an s_ff1_i32_b64 waterfall builds, v_permlanex16_b32 throws on 8; the four throws fail on main.
  • PPSA26344 v1.008 with #920 and #944: five lane-63 pixel programs, 0x80003c5100 and 0x80002f0b00 among them, are skipped; no GPU hang up to 268 s.
  • Not tested: Linux (CI), console behaviour.

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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4765359442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/997). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T22:29:37Z. --- ### What On a 32-lane host, the pixel, vertex and tessellation stages of a wave64 program run one guest lane per invocation (compute and mesh hold two), so lanes 32-63 have no invocation, yet `v_readlane_b32` still shuffled from them. - When a non-compute wave runs one lane per invocation on a narrower host subgroup, `EmitReadLane` throws for a constant lane at or above the subgroup size, and `EmitPermlane16U32` throws for `v_permlanex16_b32` on subgroups of 16 lanes or fewer. - Register lanes still build, so `s_ff1_i32_b64` waterfalls are unaffected. - Permlane takes the source lane's EXEC from a ballot, as DPP does, instead of shuffling it from a possibly inactive invocation. TechnicalDebt notes what is still inexact. - PPSA26344 v1.008: the "UI Post Fade" pixel shader (0x80003c5100) reads lanes 31 and 63 after a DPP min scan; with lane 63 undefined, its loop can spin forever and hang the GPU (at about 160 s in our runs). It now fails to build on 32-lane hosts, so its draws are skipped. Ten more pixel programs in the title also read a constant lane 63, 0x80002f0b00 among them; on `main` they stop earlier, at image-table descriptors (#920). Running them exactly needs lane reads across subgroups, which is a design question. - No open PR edits these functions; pr_overlap reports none. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` c1241ad0: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 365/365 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 364/364 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `verifyLanesOutsideHostSubgroup` in `agc_shader_memory` (CPU only): lane 63 throws on 32 and 8 lanes but builds on 64 and as compute on 32 and 8, lane 31 throws only on 8, an `s_ff1_i32_b64` waterfall builds, `v_permlanex16_b32` throws on 8; the four throws fail on `main`. - PPSA26344 v1.008 with #920 and #944: five lane-63 pixel programs, 0x80003c5100 and 0x80002f0b00 among them, are skipped; no GPU hang up to 268 s. - Not tested: Linux (CI), console behaviour. ### 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: none - [x] AI-assisted: yes
NahuelGenchi commented 2026-10-06 23:58:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-06T23:58:47Z.


Since this was only tested on 32 and 8 lane hosts, here's a run on a native 64 lane subgroup: R9 380 (Tonga, GFX8, RADV, Mesa 26.0.8), Ubuntu 26.04, GCC 15.2, Release build of a40fe0b4.

The full suite passes, 367 tests with lod_clamp skipped as on main (no shaderResourceMinLod on this card). That includes the read_lane, write_lane, read_first_lane, permlane16, wave32_subgroup and pixel lane tests, so the 64 lane path still builds and gives correct results here. All agc_driver_* binaries are also clean under the Khronos validation layer with VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true, same as main at ab9437e3.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027750177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/997#issuecomment-6027750177). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-06T23:58:47Z. --- Since this was only tested on 32 and 8 lane hosts, here's a run on a native 64 lane subgroup: R9 380 (Tonga, GFX8, RADV, Mesa 26.0.8), Ubuntu 26.04, GCC 15.2, Release build of a40fe0b4. The full suite passes, 367 tests with lod_clamp skipped as on main (no shaderResourceMinLod on this card). That includes the read_lane, write_lane, read_first_lane, permlane16, wave32_subgroup and pixel lane tests, so the 64 lane path still builds and gives correct results here. All agc_driver_* binaries are also clean under the Khronos validation layer with VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true, same as main at ab9437e3.
Celegans12 commented 2026-10-07 00:03:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T00:03:02Z.


Thanks for running it on a real 64-lane card. That was the case I couldn't check here, and it's good to see the read_lane, permlane16 and pixel lane tests come out right on GCN as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027801386 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/997#issuecomment-6027801386). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T00:03:02Z. --- Thanks for running it on a real 64-lane card. That was the case I couldn't check here, and it's good to see the read_lane, permlane16 and pixel lane tests come out right on GCN as well.
adriadam10 commented 2026-10-07 12:08:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T12:08:52Z.


Checked on RADV (build + full ctest on current main, 393/393; agc_shader_memory fails without the change). Measured on RDNA2 (gfx1035) with the HW oracle: with an inactive source lane, v_permlane16_b32/v_permlanex16_b32 keep the old value without fetch-inactive (0 with bound_ctrl) and read the lane's VGPR with fetch-inactive, and v_readlane_b32 of an inactive lane reads its VGPR. That matches the ballot-based source EXEC and both TechnicalDebt lines. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6037584808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/997#issuecomment-6037584808). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T12:08:52Z. --- Checked on RADV (build + full ctest on current main, 393/393; `agc_shader_memory` fails without the change). Measured on RDNA2 (gfx1035) with the HW oracle: with an inactive source lane, `v_permlane16_b32`/`v_permlanex16_b32` keep the old value without fetch-inactive (0 with bound_ctrl) and read the lane's VGPR with fetch-inactive, and `v_readlane_b32` of an inactive lane reads its VGPR. That matches the ballot-based source EXEC and both TechnicalDebt lines. Merging.
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!997
No description provided.