fix(recompiler): start pixel waves without their helper invocations in EXEC #305

Merged
oneandonlydean merged 1 commit from upstream-pr/305 into main 2026-10-03 06:47:30 +00:00
oneandonlydean commented 2026-10-02 00:24:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T00:24:31Z.


What

A pixel wave starts with EXEC holding only its covered pixels. The other lanes of a partly covered quad run as helpers outside EXEC until the shader asks for whole quads (s_wqm). emitEntryPrologue starts every stage with initialExec = true, so a pixel shader starts with Vulkan's helper invocations in EXEC too. Helper invocations take part in subgroup operations, so on main they:

  • count in ballots: v_mbcnt_* ranks, s_bcnt1 of EXEC, v_readfirstlane and the first-lane choices built on them;
  • can be the lane that performs a wave's single ds_append/ds_consume or atomic. An atomic in a helper invocation does nothing and returns an undefined value.

Changes:

  • New StageInputKind::HelperInvocation, declared as the HelperInvocation builtin (bool) and read as 1/0. ShaderInfoCollector collects it and validates its component, and ShaderValidation accepts it as a fragment builtin.
  • The prologue starts a pixel shader's EXEC as HelperInvocation == 0. s_wqm still adds the helpers of every quad with a covered pixel, so derivative code keeps them, as on the GPU.

Found on my integration branch: a PPSA21564 title-screen pixel shader allocates light-list nodes with a GDS ds_append and links them with image_atomic_swap. With helpers in EXEC, a test of that pattern on the RTX 4090 saw waves reuse node indices (867 duplicates among 7817 pixels), which can link a node to itself. Main cannot bind GDS in shaders yet (#285 adds that), but the ballot and atomic cases above apply to any pixel shader.

Tested

  • Linux (CachyOS, RTX 4090, NVIDIA 610.57.04).
  • New agc_driver_pixel_helper_lanes execution test (tests/execution/PixelHelperLanes.cpp, so ctest runs it like the other tests there; it uses no GDS and no mesh shader). Like the other execution tests it exits 77 (skipped) without a Vulkan device, and it also skips on a subgroup narrower than 32 (lavapipe's is 8), which cannot hold a wave32.
    • Draw: a recompiled vertex shader reads 24 triangles of assorted slopes from a vertex buffer. They leave partly covered quads across a 192x128 target.
    • Pixel shader: it stores, at each covered pixel's slot, its v_mbcnt_lo/hi rank in EXEC, the s_bcnt1_i32_b64 count of EXEC and the v_readfirstlane_b32 of the pixel's index.
    • Check: grouped by that first-lane index, every wave's covered pixels must be lanes 0..n-1 of an n-lane EXEC, and the first lane must be one of those pixels. Uncovered pixels must store nothing. This runs 4 passes each in wave64 and wave32.
    • Result: on main it fails with pixel helper lanes wave64: the wave whose first lane is pixel 392 has 25 covered pixels, but pixel 584 is lane 2 of EXEC. With the fix it passes.
  • agc_driver_mesh_tests and agc_driver_bda_device_tests pass.
  • ctest: 106/106 pass, including the execution tests.
  • PPSA21564: this change has been on my integration branch through repeated passes of my visual regression check (from the intro video through the title and save menu into gameplay; checkpoint frames, flicker, video tearing and FPS).

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none. #375 and #423 edit the same fragment built-in check in ShaderValidation.cpp; whichever merges second keeps both.
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4711181029 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/305). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T00:24:31Z. --- ### What A pixel wave starts with EXEC holding only its covered pixels. The other lanes of a partly covered quad run as helpers outside EXEC until the shader asks for whole quads (`s_wqm`). `emitEntryPrologue` starts every stage with `initialExec = true`, so a pixel shader starts with Vulkan's helper invocations in EXEC too. Helper invocations take part in subgroup operations, so on main they: - count in ballots: `v_mbcnt_*` ranks, `s_bcnt1` of EXEC, `v_readfirstlane` and the first-lane choices built on them; - can be the lane that performs a wave's single `ds_append`/`ds_consume` or atomic. An atomic in a helper invocation does nothing and returns an undefined value. Changes: - New `StageInputKind::HelperInvocation`, declared as the `HelperInvocation` builtin (bool) and read as 1/0. `ShaderInfoCollector` collects it and validates its component, and `ShaderValidation` accepts it as a fragment builtin. - The prologue starts a pixel shader's EXEC as `HelperInvocation == 0`. `s_wqm` still adds the helpers of every quad with a covered pixel, so derivative code keeps them, as on the GPU. Found on my integration branch: a PPSA21564 title-screen pixel shader allocates light-list nodes with a GDS `ds_append` and links them with `image_atomic_swap`. With helpers in EXEC, a test of that pattern on the RTX 4090 saw waves reuse node indices (867 duplicates among 7817 pixels), which can link a node to itself. Main cannot bind GDS in shaders yet (#285 adds that), but the ballot and atomic cases above apply to any pixel shader. ### Tested - Linux (CachyOS, RTX 4090, NVIDIA 610.57.04). - New `agc_driver_pixel_helper_lanes` execution test (`tests/execution/PixelHelperLanes.cpp`, so ctest runs it like the other tests there; it uses no GDS and no mesh shader). Like the other execution tests it exits 77 (skipped) without a Vulkan device, and it also skips on a subgroup narrower than 32 (lavapipe's is 8), which cannot hold a wave32. - **Draw:** a recompiled vertex shader reads 24 triangles of assorted slopes from a vertex buffer. They leave partly covered quads across a 192x128 target. - **Pixel shader:** it stores, at each covered pixel's slot, its `v_mbcnt_lo/hi` rank in EXEC, the `s_bcnt1_i32_b64` count of EXEC and the `v_readfirstlane_b32` of the pixel's index. - **Check:** grouped by that first-lane index, every wave's covered pixels must be lanes 0..n-1 of an n-lane EXEC, and the first lane must be one of those pixels. Uncovered pixels must store nothing. This runs 4 passes each in wave64 and wave32. - **Result:** on main it fails with `pixel helper lanes wave64: the wave whose first lane is pixel 392 has 25 covered pixels, but pixel 584 is lane 2 of EXEC`. With the fix it passes. - `agc_driver_mesh_tests` and `agc_driver_bda_device_tests` pass. - `ctest`: 106/106 pass, including the execution tests. - PPSA21564: this change has been on my integration branch through repeated passes of my visual regression check (from the intro video through the title and save menu into gameplay; checkpoint frames, flicker, video tearing and FPS). ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none. #375 and #423 edit the same fragment built-in check in `ShaderValidation.cpp`; whichever merges second keeps both. - [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!305
No description provided.