feat(agc): implement primitive-ordered pixel shaders with fragment shader interlock #1130

Merged
Celegans12 merged 1 commit from upstream-pr/1130 into main 2026-10-08 10:01:04 +00:00
Celegans12 commented 2026-10-07 13:20:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T13:20:32Z.


What

DecodeState and the draw precheck rejected DB_SHADER_CONTROL bit 16, PRIMITIVE_ORDERED_PIXEL_SHADER (field), which orders the pixel shaders of overlapping primitives.

  • The bit becomes the pixel stage field orderedPixelShader, and such a shader runs in a PixelInterlockOrderedEXT interlock (extension) up to its return, not to ORDERED_PS_DONE. Its collision SGPRs read 0, so the title skips its POPS wait and runs its per-collision loop once (TechnicalDebt). An invocation that a BDA read fault kills ends the interlock before its OpKill.
  • Without fragmentShaderPixelInterlock the recompile throws, as does a nonzero POPS_OVERLAP_NUM_SAMPLES. The field is in the cache and draw keys and the serialized request (version 11, after #1182's 10); the disk cache format stays 7, as only the key grows.
  • An image_load still reads a sampled binding, so it misses an earlier overlapping primitive's image_store in the same draw (TechnicalDebt); glc buffer accesses are already Coherent.
  • PPSA26344 v1.008: 80 pixel programs (200 instances, e.g. 0x806efa2800) set 0x30600 or 0x30640, each with one glc image_load/image_store pair; a run skipped 962 of their draws.
  • Overlaps: #423, #448 and #1077 also edit the ValidateShaders mode line with PixelInterlockOrderedEXT. #423, #448, #1077, #1190, #1383 and #1442 change the serialized request too; #448, #1190, #1383 and #1442 write version 10 as well, so they need a later number now, and whichever of them lands after this one needs 12 or more. #1112 and #1184 add lines next to ours in VulkanDevice.cpp, #1112, #1252 and #1333 in tests/Graphics.cpp, and #1190 in ShaderMemory.cpp.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 0e173a46: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 424/424 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 423/423 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New orderedPixelShaderTests (agc_driver_graphics) also walks every path of an ordered shader with BDA reads and requires one OpEndInvocationInterlockEXT before each exit, 5 fault kills included; without the End in StopBdaInvocationIf it fails. It does not compile on main.
  • New GPU test agc_driver_pixel_interlock: 64 overlapping triangles add 1 to a dword per pixel; every pixel counts 64 on an RTX 3080 and lavapipe (2 on the RTX 3080 without the interlock); when a BDA read fault kills every 8th column, the others still count 64. It does not compile on main.
  • PPSA26344 v1.008: a 2,700 s run has no 0x30600/0x30640 skips (1,243 in 1,500 s before); those draws now stop at a null SRT read first.
  • Not tested: PPSA21564, Dreaming Sarah, 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:4773253428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1130). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T13:20:32Z. --- ### What `DecodeState` and the draw precheck rejected DB_SHADER_CONTROL bit 16, PRIMITIVE_ORDERED_PIXEL_SHADER ([field](https://github.com/torvalds/linux/blob/v6.12/drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_3_0_sh_mask.h#L22551-L22553)), which orders the pixel shaders of overlapping primitives. - The bit becomes the pixel stage field `orderedPixelShader`, and such a shader runs in a `PixelInterlockOrderedEXT` interlock ([extension](https://github.khronos.org/SPIRV-Registry/extensions/EXT/SPV_EXT_fragment_shader_interlock.html)) up to its return, not to ORDERED_PS_DONE. Its collision SGPRs read 0, so the title skips its POPS wait and runs its per-collision loop once (TechnicalDebt). An invocation that a BDA read fault kills ends the interlock before its `OpKill`. - Without `fragmentShaderPixelInterlock` the recompile throws, as does a nonzero POPS_OVERLAP_NUM_SAMPLES. The field is in the cache and draw keys and the serialized request (version 11, after #1182's 10); the disk cache format stays 7, as only the key grows. - An image_load still reads a sampled binding, so it misses an earlier overlapping primitive's image_store in the same draw (TechnicalDebt); glc buffer accesses are already Coherent. - PPSA26344 v1.008: 80 pixel programs (200 instances, e.g. 0x806efa2800) set 0x30600 or 0x30640, each with one glc image_load/image_store pair; a run skipped 962 of their draws. - Overlaps: #423, #448 and #1077 also edit the `ValidateShaders` mode line with `PixelInterlockOrderedEXT`. #423, #448, #1077, #1190, #1383 and #1442 change the serialized request too; #448, #1190, #1383 and #1442 write version 10 as well, so they need a later number now, and whichever of them lands after this one needs 12 or more. #1112 and #1184 add lines next to ours in `VulkanDevice.cpp`, #1112, #1252 and #1333 in `tests/Graphics.cpp`, and #1190 in `ShaderMemory.cpp`. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 0e173a46: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 424/424 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 423/423 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `orderedPixelShaderTests` (`agc_driver_graphics`) also walks every path of an ordered shader with BDA reads and requires one `OpEndInvocationInterlockEXT` before each exit, 5 fault kills included; without the End in `StopBdaInvocationIf` it fails. It does not compile on `main`. - New GPU test `agc_driver_pixel_interlock`: 64 overlapping triangles add 1 to a dword per pixel; every pixel counts 64 on an RTX 3080 and lavapipe (2 on the RTX 3080 without the interlock); when a BDA read fault kills every 8th column, the others still count 64. It does not compile on `main`. - PPSA26344 v1.008: a 2,700 s run has no 0x30600/0x30640 skips (1,243 in 1,500 s before); those draws now stop at a null SRT read first. - Not tested: PPSA21564, Dreaming Sarah, 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
github-actions[bot] commented 2026-10-07 21:29:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T21:29:05Z.


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
#1139 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L67
#1252 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp L1887
#1383 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L759-760, L764
#1442 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L759-760, L764
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6047217495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1130#issuecomment-6047217495). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T21:29:05Z. --- <!-- 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 | |---|---|---|---| | #1139 | `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp` [L67](https://github.com/boykopovar/AnyPS5/blob/bc1fbe81583df3aa28b1f45f1d639090b2278215/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp#L67) | | | | #1252 | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` [L1887](https://github.com/boykopovar/AnyPS5/blob/bc1fbe81583df3aa28b1f45f1d639090b2278215/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp#L1887) | | | | #1383 | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L759-760](https://github.com/boykopovar/AnyPS5/blob/bc1fbe81583df3aa28b1f45f1d639090b2278215/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L759-L760), [L764](https://github.com/boykopovar/AnyPS5/blob/bc1fbe81583df3aa28b1f45f1d639090b2278215/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L764) | | | | #1442 | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L759-760](https://github.com/boykopovar/AnyPS5/blob/bc1fbe81583df3aa28b1f45f1d639090b2278215/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L759-L760), [L764](https://github.com/boykopovar/AnyPS5/blob/bc1fbe81583df3aa28b1f45f1d639090b2278215/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L764) | | |
Celegans12 commented 2026-10-07 21:51:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T21:51:55Z.


The linux job here didn't get to the build: it hung on apt-get update (the Ubuntu mirror) and was cancelled at the 30-minute limit. Windows, conventions and report pass, so a re-run of the linux job should be all it needs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6047577667 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1130#issuecomment-6047577667). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T21:51:55Z. --- The linux job here didn't get to the build: it hung on `apt-get update` (the Ubuntu mirror) and was cancelled at the 30-minute limit. Windows, conventions and report pass, so a re-run of the linux job should be all it needs.
adriadam10 commented 2026-10-08 08:12:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:12:20Z.

Review: CHANGES_REQUESTED


Checked on current main (build + ctest 425/425, agc_driver_pixel_interlock runs on a device with fragmentShaderPixelInterlock; the new tests don't compile without the change). The linux job failed on a hung apt-get update; I re-ran it.

One thing before merging:

  • SPV_EXT_fragment_shader_interlock requires each invocation to dynamically execute OpBeginInvocationInterlockEXT and then OpEndInvocationInterlockEXT exactly once. An End before every OpReturn (SpirvFlowEmitter.cpp:91) is fine for that, but StopBdaInvocationIf (SpirvBdaFault.cpp:95) emits OpKill in pixel shaders between Begin and End when a BDA read faults (the four call sites in SpirvBdaRead.cpp), so that invocation leaves the critical section without End. Please emit End before that OpKill when the ordered mode is on, and add a test case where an ordered pixel shader takes the fault path.

Everything else (key/serializer v10, legacy request, TechnicalDebt placement) looks right. Note #423/#448/#1182/#1190 also take request version 10: whichever lands second moves to the next one.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5453658575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1130#pullrequestreview-5453658575). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T08:12:20Z. **Review:** CHANGES_REQUESTED --- Checked on current `main` (build + ctest 425/425, `agc_driver_pixel_interlock` runs on a device with `fragmentShaderPixelInterlock`; the new tests don't compile without the change). The linux job failed on a hung `apt-get update`; I re-ran it. One thing before merging: - SPV_EXT_fragment_shader_interlock requires each invocation to dynamically execute `OpBeginInvocationInterlockEXT` and then `OpEndInvocationInterlockEXT` exactly once. An End before every `OpReturn` (`SpirvFlowEmitter.cpp:91`) is fine for that, but `StopBdaInvocationIf` (`SpirvBdaFault.cpp:95`) emits `OpKill` in pixel shaders between Begin and End when a BDA read faults (the four call sites in `SpirvBdaRead.cpp`), so that invocation leaves the critical section without End. Please emit End before that `OpKill` when the ordered mode is on, and add a test case where an ordered pixel shader takes the fault path. Everything else (key/serializer v10, legacy request, TechnicalDebt placement) looks right. Note #423/#448/#1182/#1190 also take request version 10: whichever lands second moves to the next one.
adriadam10 commented 2026-10-08 09:33:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:33:46Z.

Review: APPROVED


main now uses request version 10 for the compute scratch size (#1182), so I rebased this onto it and moved the ordered-pixel field to version 11 (RequestSerializer.cpp write/read/limit, ShaderMemory.cpp: new prefix, unsupported versions 0 and 12, a legacy v10 request added, mapping offset unchanged at +163). Build + ctest 431/431 on Linux (RADV); the new tests don't compile without the change. The OpKill/End fix from the earlier review is in and the mutation without it fails.

Pushing the rebase now; merging once CI is green on the new head. The PR description still says "version 10": it is 11 now.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5454546977 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1130#pullrequestreview-5454546977). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T09:33:46Z. **Review:** APPROVED --- `main` now uses request version 10 for the compute scratch size (#1182), so I rebased this onto it and moved the ordered-pixel field to version 11 (`RequestSerializer.cpp` write/read/limit, `ShaderMemory.cpp`: new prefix, unsupported versions 0 and 12, a legacy v10 request added, mapping offset unchanged at +163). Build + ctest 431/431 on Linux (RADV); the new tests don't compile without the change. The OpKill/End fix from the earlier review is in and the mutation without it fails. Pushing the rebase now; merging once CI is green on the new head. The PR description still says "version 10": it is 11 now.
Celegans12 commented 2026-10-08 09:38:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T09:38:29Z.


Thanks for doing the rebase and the move to version 11 yourself, and for checking the mutation. I've updated the description: it now says version 11 and lists which of the other request-changing PRs still write 10. I'll move our #1485 and #1492, which also wrote 10, to 12 and 13 so they don't collide with this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6057044754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1130#issuecomment-6057044754). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-08T09:38:29Z. --- Thanks for doing the rebase and the move to version 11 yourself, and for checking the mutation. I've updated the description: it now says version 11 and lists which of the other request-changing PRs still write 10. I'll move our #1485 and #1492, which also wrote 10, to 12 and 13 so they don't collide with this one.
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!1130
No description provided.