perf(agc): stage read and written buffer elements a dispatch sweeps #2681

Merged
oneandonlydean merged 2 commits from upstream-pr/2681 into main 2026-10-10 15:36:16 +00:00
oneandonlydean commented 2026-10-10 10:50:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T10:50:19Z.


What

A written V# element bound in place in a host import makes every load a PCIe round trip. In one title's particle update, a kernel loads and stores a 10 MiB pool (2048x64 threads over 131072 records of 80 bytes). That is above the 2 MiB written window, so it stayed in place and took about 4.8 ms of GPU per frame.

Two commits:

  1. feat(shader): DescriptorBinding gains bufferRead next to bufferWritten and bufferAtomic, filled from the resource tracker's existing per-buffer read flag. It is kept in the shader disk cache, which bumps the format to 24. No key or ABI change.
  2. perf(agc): an element is now staged in device-local memory up to 16 MiB when all of these hold:
    • the shader also reads it;
    • it is written by a direct dispatch;
    • the dispatch's threads times the V# stride cover at least half of it.

The coverage test keeps a kernel that updates about 12k records of a 16 MiB pool in place: staging all of it would cost about 1.3 ms of copies for a 0.08 ms kernel. Write-only elements, indirect dispatches and raw (stride 0) buffers keep the 2 MiB window.

Tested

  • Linux (CachyOS, x86-64, GCC, RTX 4090), Release with BUILD_TESTING=ON: ctest -R "agc|shader" passes 320/321. The one failure, agc_driver_dcc_keys_first_write, fails the same way on current main.
  • agc_shader_disk_cache_tests: bufferRead survives the disk cache round trip and the binding plan.
  • agc_driver_recorder_tests, new readWrittenStagingTests, run on its own on the RTX 4090 (the full binary stops earlier on main with a 60 s lease wait, unrelated):
    • a read and written 4 MiB element is staged;
    • the same element written only stays in place;
    • a dispatch touching 16 KiB of it, or of unknown size, keeps it in place;
    • copy-backs leave the guest bytes unchanged.
  • Astro Bot (PPSA21564), measured on our fork, which carries the same change: the particle update 0x500779a00 went from about 4.8 ms of GPU per frame to 0.06 ms plus about 0.9 ms of copies.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810640573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2681). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T10:50:19Z. --- ### What A written V# element bound in place in a host import makes every load a PCIe round trip. In one title's particle update, a kernel loads and stores a 10 MiB pool (2048x64 threads over 131072 records of 80 bytes). That is above the 2 MiB written window, so it stayed in place and took about 4.8 ms of GPU per frame. Two commits: 1. `feat(shader)`: `DescriptorBinding` gains `bufferRead` next to `bufferWritten` and `bufferAtomic`, filled from the resource tracker's existing per-buffer `read` flag. It is kept in the shader disk cache, which bumps the format to 24. No key or ABI change. 2. `perf(agc)`: an element is now staged in device-local memory up to 16 MiB when all of these hold: - the shader also reads it; - it is written by a direct dispatch; - the dispatch's threads times the V# stride cover at least half of it. The coverage test keeps a kernel that updates about 12k records of a 16 MiB pool in place: staging all of it would cost about 1.3 ms of copies for a 0.08 ms kernel. Write-only elements, indirect dispatches and raw (stride 0) buffers keep the 2 MiB window. ### Tested - Linux (CachyOS, x86-64, GCC, RTX 4090), Release with `BUILD_TESTING=ON`: `ctest -R "agc|shader"` passes 320/321. The one failure, `agc_driver_dcc_keys_first_write`, fails the same way on current `main`. - `agc_shader_disk_cache_tests`: `bufferRead` survives the disk cache round trip and the binding plan. - `agc_driver_recorder_tests`, new `readWrittenStagingTests`, run on its own on the RTX 4090 (the full binary stops earlier on `main` with a 60 s lease wait, unrelated): - a read and written 4 MiB element is staged; - the same element written only stays in place; - a dispatch touching 16 KiB of it, or of unknown size, keeps it in place; - copy-backs leave the guest bytes unchanged. - Astro Bot (PPSA21564), measured on our fork, which carries the same change: the particle update `0x500779a00` went from about 4.8 ms of GPU per frame to 0.06 ms plus about 0.9 ms of copies. ### 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 (Claude Code)
github-actions[bot] commented 2026-10-10 10:54:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T10:54:15Z.


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
#757 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp L44
core/shader/recompiler/ShaderDiskCache.cpp L68-70
core/shader/recompiler/ShaderDiskCache.hpp L15
#758 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp L44
core/shader/recompiler/ShaderDiskCache.cpp L68-70
core/shader/recompiler/ShaderDiskCache.hpp L15
#822 core/shader/recompiler/ShaderDiskCache.hpp L15
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096754139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2681#issuecomment-6096754139). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T10:54:15Z. --- <!-- 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 | |---|---|---|---| | #757 | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` [L44](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp#L44)<br>`core/shader/recompiler/ShaderDiskCache.cpp` [L68-70](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/shader/recompiler/ShaderDiskCache.cpp#L68-L70)<br>`core/shader/recompiler/ShaderDiskCache.hpp` [L15](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/shader/recompiler/ShaderDiskCache.hpp#L15) | | | | #758 | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` [L44](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp#L44)<br>`core/shader/recompiler/ShaderDiskCache.cpp` [L68-70](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/shader/recompiler/ShaderDiskCache.cpp#L68-L70)<br>`core/shader/recompiler/ShaderDiskCache.hpp` [L15](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/shader/recompiler/ShaderDiskCache.hpp#L15) | | | | #822 | `core/shader/recompiler/ShaderDiskCache.hpp` [L15](https://github.com/boykopovar/AnyPS5/blob/de5e541d8fe6e9e990987ef74c953b4c761546c2/core/shader/recompiler/ShaderDiskCache.hpp#L15) | | |
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!2681
No description provided.