perf(agc): take a 2D storage image's results for a one-slice array on the device #2479

Merged
NahuelGenchi merged 2 commits from upstream-pr/2479 into main 2026-10-11 07:27:07 +00:00
NahuelGenchi commented 2026-10-09 22:47:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T22:47:53Z.


What

A 2D surface and a one-slice 2D array over the same memory get separate storage images, because the storage key holds the dimension. While one of them holds pending results, a refresh of the other has to bring those results over. pendingAlias already does that on the device (borrowUnits) for a pending image of another format with the same element size. It required the same dimension, though, so for this pair the refresh wrote the pending image back and uploaded it again.

Sonic Origins Plus (PPSA05324) uses both views of the same surfaces in its opening animation, about 50 times a frame. Each switch paid a full write-back and a re-upload, and that held the animation at about 3 fps on my machine.

pendingAlias now counts a 2D surface and a one-slice 2D array as the same dimension. Nothing else in the shape test changes (size, array range, mips, tiling, element size, image layers and depth, tracked units). The conditions for the device copy don't change either: uncompressed keys, a host import, and the surface's write stamps.

A follow-up could give both views one image (one storage key for a 2D surface and its one-slice array), which would also remove the device copies. That is a larger change to the storage cache, so it isn't in this PR.

Tested

Ubuntu 26.04, GCC 15.2, Release build, AMD Radeon R9 380 (RADV, Mesa 26.0.8), and lavapipe (LLVM 21.1.8).

  • New test, agc_driver_storage_one_slice_alias. It stores through the 2D view and loads through the array view, twice.

    • It checks the texels read through the array, and the guest memory after the final flush.
    • Where the imported block is write-watched, it also checks that the 2D image is still pending after the array image's refresh.
    • On lavapipe, the block stays watched. The test passes with the change and fails without it: the array image's refresh wrote the 2D image's results back instead of taking them on the device.
    • On RADV, the import probe leaves host imports of anonymous memory to comparisons, so only the texels and the flush are checked there. The test prints a note saying so and passes. The title's surfaces are in dma-buf heaps, which stay watched on RADV, so the device copy is used in the game.
  • Sonic Origins Plus, opening animation, 960x540 (--res_x=960 --res_y=540, APS5_PROFILE_GPU=1). I used the testing branch from #2021, built with and without this change. Per 10 s of the animation:

    Without With
    Presents 29–31 101–105
    storage-writeback ~1550, 4.5 s, 11.9 GiB (144 ms per present) ~103, 0.12 s, 0.86 GiB (1.2 ms per present)
    storage-upload 1643, 2.8 s (92 ms per present) 5453, 2.8 s (28 ms per present); most of them are now device copies

    The animation now runs at about 10 fps. Its frames look the same in both runs: the same scenes, with the same colors and layers. Frames were dumped every 15 presents, so frames in the "before" sheet are about 5 s apart and frames in the "after" sheet about 1.5 s apart.

    Frame dumps

    Before (boot, notice, title emblem and the start of the animation):
    before

    After (notice, title emblem and the animation further on):
    after

  • tools/check_conventions.py --base origin/main and git diff --check pass.

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)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4806680153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2479). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T22:47:53Z. --- ### What A 2D surface and a one-slice 2D array over the same memory get separate storage images, because the storage key holds the dimension. While one of them holds pending results, a refresh of the other has to bring those results over. `pendingAlias` already does that on the device (`borrowUnits`) for a pending image of another format with the same element size. It required the same dimension, though, so for this pair the refresh wrote the pending image back and uploaded it again. Sonic Origins Plus (PPSA05324) uses both views of the same surfaces in its opening animation, about 50 times a frame. Each switch paid a full write-back and a re-upload, and that held the animation at about 3 fps on my machine. `pendingAlias` now counts a 2D surface and a one-slice 2D array as the same dimension. Nothing else in the shape test changes (size, array range, mips, tiling, element size, image layers and depth, tracked units). The conditions for the device copy don't change either: uncompressed keys, a host import, and the surface's write stamps. A follow-up could give both views one image (one storage key for a 2D surface and its one-slice array), which would also remove the device copies. That is a larger change to the storage cache, so it isn't in this PR. ### Tested Ubuntu 26.04, GCC 15.2, Release build, AMD Radeon R9 380 (RADV, Mesa 26.0.8), and lavapipe (LLVM 21.1.8). - **New test, `agc_driver_storage_one_slice_alias`.** It stores through the 2D view and loads through the array view, twice. - It checks the texels read through the array, and the guest memory after the final flush. - Where the imported block is write-watched, it also checks that the 2D image is still pending after the array image's refresh. - On lavapipe, the block stays watched. The test passes with the change and fails without it: `the array image's refresh wrote the 2D image's results back instead of taking them on the device`. - On RADV, the import probe leaves host imports of anonymous memory to comparisons, so only the texels and the flush are checked there. The test prints a note saying so and passes. The title's surfaces are in dma-buf heaps, which stay watched on RADV, so the device copy is used in the game. - **Sonic Origins Plus, opening animation, 960x540** (`--res_x=960 --res_y=540`, `APS5_PROFILE_GPU=1`). I used the testing branch from #2021, built with and without this change. Per 10 s of the animation: | | Without | With | |---|---|---| | Presents | 29–31 | 101–105 | | `storage-writeback` | ~1550, 4.5 s, 11.9 GiB (144 ms per present) | ~103, 0.12 s, 0.86 GiB (1.2 ms per present) | | `storage-upload` | 1643, 2.8 s (92 ms per present) | 5453, 2.8 s (28 ms per present); most of them are now device copies | The animation now runs at about 10 fps. Its frames look the same in both runs: the same scenes, with the same colors and layers. Frames were dumped every 15 presents, so frames in the "before" sheet are about 5 s apart and frames in the "after" sheet about 1.5 s apart. <details><summary>Frame dumps</summary> Before (boot, notice, title emblem and the start of the animation): ![before](https://raw.githubusercontent.com/NahuelGenchi/AnyPS5/bringup-media/sonic/2026-10-09/opening-before-alias-fix.png) After (notice, title emblem and the animation further on): ![after](https://raw.githubusercontent.com/NahuelGenchi/AnyPS5/bringup-media/sonic/2026-10-09/opening-after-alias-fix.png) </details> - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-09 23:05:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T23:05:36Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090768335 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2479#issuecomment-6090768335). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T23:05:36Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
adriadam10 commented 2026-10-11 07:16:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:16:51Z.


Rebased onto current main and added one commit:

  • StorageOneSliceAlias.cpp:84: GuestAllocations::Mutation().Add takes a fifth gpu argument on main now, so the test no longer compiled; passing true, like FlatApertures and HostImportAtMap.

Checked: scoped build and ctest for libSceAgcDriver green (355/355); on lavapipe the new test passes with the change and fails without it (the array image's refresh wrote the 2D image's results back...); on RADV only the texels and the flush are checked, as the test notes. The Sonic Origins Plus numbers are the author's, not reproduced here. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106591643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2479#issuecomment-6106591643). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:16:51Z. --- Rebased onto current main and added one commit: - `StorageOneSliceAlias.cpp:84`: `GuestAllocations::Mutation().Add` takes a fifth `gpu` argument on main now, so the test no longer compiled; passing `true`, like `FlatApertures` and `HostImportAtMap`. Checked: scoped build and ctest for libSceAgcDriver green (355/355); on lavapipe the new test passes with the change and fails without it (`the array image's refresh wrote the 2D image's results back...`); on RADV only the texels and the flush are checked, as the test notes. The Sonic Origins Plus numbers are the author's, not reproduced here. Merging once CI is green.
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!2479
No description provided.