feat(agc): compute dispatches with scratch memory #1182

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/1182 into main 2026-10-08 09:15:46 +00:00
MichonGoddijn231849 commented 2026-10-07 16:44:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T16:44:34Z.


What

A compute program with COMPUTE_PGM_RSRC2.SCRATCH_EN takes its per-lane private size from the AGC shader header (scratch_size_dw_per_thread), instead of being refused. The size travels in ShaderComputeStageInfo to the translator, whose scratch accesses already lower to a per-invocation Function array of that many dwords. It is part of the recompile cache key and of the request serialization (version 10).

A header without a scratch size throws. tests/Graphics.cpp covers the decode.

Note: #423 also moves the request serialization to version 10. Whichever of the two is merged second moves to 11.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.

  • GTA V PPSA04264 (01.005) runs with this change on the combined gta-v/testing branch (Performance mode, the prologue).
  • On this branch: builds, and ctest passes. Not run here: the relinker's Python tests (my local Python does not find their helper modules) and guest_gameupdate.

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. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4775677683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1182). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T16:44:34Z. --- ### What A compute program with COMPUTE_PGM_RSRC2.SCRATCH_EN takes its per-lane private size from the AGC shader header (`scratch_size_dw_per_thread`), instead of being refused. The size travels in `ShaderComputeStageInfo` to the translator, whose scratch accesses already lower to a per-invocation Function array of that many dwords. It is part of the recompile cache key and of the request serialization (version 10). A header without a scratch size throws. `tests/Graphics.cpp` covers the decode. Note: #423 also moves the request serialization to version 10. Whichever of the two is merged second moves to 11. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0. - GTA V PPSA04264 (01.005) runs with this change on the combined [`gta-v/testing`](https://github.com/MichonGoddijn231849/AnyPS5-fork/tree/gta-v/testing) branch (Performance mode, the prologue). - On this branch: builds, and `ctest` passes. Not run here: the relinker's Python tests (my local Python does not find their helper modules) and `guest_gameupdate`. ### 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. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Celegans12 commented 2026-10-07 18:30:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T18:30:09Z.


I'd been working on the same thing for Ghost of Yōtei (PPSA26344), so here's what I found with this PR, in case it helps.

Yōtei has seven compute programs with SCRATCH_EN, all ray-traversal kernels (image_bvh_intersect_ray). Each ray keeps the first 16-18 levels of its traversal stack in LDS and spills deeper levels to scratch. After New Game, the game dispatches them about four times per submission on queue 0x51; on main all 84 dispatches in a 45-minute run stop at COMPUTE_PGM_RSRC2.SCRATCH_EN is unsupported. I replayed the seven programs' requests offline with this PR. The two big kernels 0x800014e300 and 0x8000167500 now recompile (about 1.06M SPIR-V words each), and their next stop is unrelated: they declare 63.5 KiB of LDS, over NVIDIA's 48 KiB. The other five stop later on things outside this PR: a runtime formatted V#, and src_shared_base, which #1190 covers.

I also ran an execution test I'd written against it: the kernels' real prologue (the scratch ring descriptor from the global table, s_setreg FLAT_SCRATCH_LO/HI with the wave offset), then scratch_* dword/x2/x4 stores and loads with VGPR, SGPR, negative and lane-divergent offsets, plus byte/short stores and signed loads, in wave32 and wave64. It passes on this PR on an RTX 3080 and on lavapipe.

Two small things I noticed:

  • A live read of the scratch wave-offset SGPR (anything other than feeding the FLAT_SCRATCH s_setreg) isn't rejected, so a program that did its own scratch addressing from it would read a wrong value silently. Yōtei's kernels don't, so this is only a hardening idea.
  • This writes request serializer version 10, which #1130, #448 and #423 also write, so whichever lands later needs the next number.

If the execution test is useful, I'm happy to send it as a follow-up on top of this.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6044265764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1182#issuecomment-6044265764). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T18:30:09Z. --- I'd been working on the same thing for Ghost of Yōtei (PPSA26344), so here's what I found with this PR, in case it helps. Yōtei has seven compute programs with SCRATCH_EN, all ray-traversal kernels (`image_bvh_intersect_ray`). Each ray keeps the first 16-18 levels of its traversal stack in LDS and spills deeper levels to scratch. After New Game, the game dispatches them about four times per submission on queue 0x51; on `main` all 84 dispatches in a 45-minute run stop at `COMPUTE_PGM_RSRC2.SCRATCH_EN is unsupported`. I replayed the seven programs' requests offline with this PR. The two big kernels 0x800014e300 and 0x8000167500 now recompile (about 1.06M SPIR-V words each), and their next stop is unrelated: they declare 63.5 KiB of LDS, over NVIDIA's 48 KiB. The other five stop later on things outside this PR: a runtime formatted V#, and `src_shared_base`, which #1190 covers. I also ran an execution test I'd written against it: the kernels' real prologue (the scratch ring descriptor from the global table, `s_setreg` FLAT_SCRATCH_LO/HI with the wave offset), then `scratch_*` dword/x2/x4 stores and loads with VGPR, SGPR, negative and lane-divergent offsets, plus byte/short stores and signed loads, in wave32 and wave64. It passes on this PR on an RTX 3080 and on lavapipe. Two small things I noticed: - A live read of the scratch wave-offset SGPR (anything other than feeding the FLAT_SCRATCH `s_setreg`) isn't rejected, so a program that did its own scratch addressing from it would read a wrong value silently. Yōtei's kernels don't, so this is only a hardening idea. - This writes request serializer version 10, which #1130, #448 and #423 also write, so whichever lands later needs the next number. If the execution test is useful, I'm happy to send it as a follow-up on top of this.
adriadam10 commented 2026-10-08 08:47:37 +00:00 (Migrated from github.com)

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


Checked on Linux (RADV): build and ctest green, also after rebasing onto current main (only an include-adjacency conflict in tests/Graphics.cpp, resolved by keeping both). The new tests don't build without the change (DecodeComputeStageInfo signature) and pin the scratch size (24), the zero-size throw, no scratch without SCRATCH_EN, and the serialization round-trip.
The scratch lowering already on main is untouched; this only feeds it the header's scratch_size_dw_per_thread.
Note for #423: it also takes request version 10, so whichever merges second moves to 11. Not verified here: the title runs on Windows/NVIDIA. Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056211780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1182#issuecomment-6056211780). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T08:47:37Z. --- Checked on Linux (RADV): build and ctest green, also after rebasing onto current `main` (only an include-adjacency conflict in `tests/Graphics.cpp`, resolved by keeping both). The new tests don't build without the change (`DecodeComputeStageInfo` signature) and pin the scratch size (24), the zero-size throw, no scratch without `SCRATCH_EN`, and the serialization round-trip. The scratch lowering already on `main` is untouched; this only feeds it the header's `scratch_size_dw_per_thread`. Note for #423: it also takes request version 10, so whichever merges second moves to 11. Not verified here: the title runs on Windows/NVIDIA. Merging once CI is green on the rebased head.
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!1182
No description provided.