perf(agc): wait once per unit run when a storage image captures its guest bytes #4468

Merged
GustavoGamarra95 merged 4 commits from upstream-pr/4468 into main 2026-10-13 01:54:25 +00:00
GustavoGamarra95 commented 2026-10-12 12:44:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T12:44:42Z.


What

StorageTexture::captureGuestBytes read the image's guest bytes with one ReadCommitted per tracked unit. Each call runs the flush hook, so for a block-unit image every 64 KiB unit published its unit shadows and waited for that copy on its own (SyncThrough), one batch per unit.

The capture now runs the flush hook once per contiguous run of the selected units, then copies the units with the new GuestMemory::ReadCommittedUnsynced, which is ReadCommitted without the hook (the counterpart of EqualsCommittedUnsynced). compareUntracked already flushes once and compares unsynced the same way. What is published and waited for is unchanged: the same units, in one hook call per run.

Found on Beast of Reincarnation (PPSA29343): a backtrace of the hook's recorded-store syncs put about 98% of them under ShaderResources::buildComplete/Revalidate -> lookupStorageTexture -> StorageTexture::Refresh -> upload -> captureGuestBytes, about 35 per upload.

Tested

Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, RTX 3050 Laptop 4 GB (NVIDIA 615.78.08), GCC, Release.

  • Built on current main; tools/check_conventions.py passes.
  • Full ctest on the RTX 3050: 950 of 950 pass (6 of them skipped: 5 video_out_flip/frame_dump tests and agc_driver_stencil_ref_export); the storage, unit shadow, guest memory, pending write, upload and import tests are 324 of them.
  • PPSA29343, title screen, APS5_PROFILE_DRAW=1, on a local branch that also carries the title's rendering fixes: recorded-store syncs from about 23000 to about 890 per 10 s, presents from 8 to 15-16 per 10 s (1.1 to 1.56 FPS from frame dump timestamps). The title frame is the same as before the change. APS5_NO_UNIT_SHADOW=1 without this change gives the same rate.
  • It merges without conflict with #3991, which changes the first line of the same function.

No automated test is added: the change keeps what is published and read and only drops the repeated hook calls; the existing unit shadow and storage tests cover the paths.

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:4829591612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4468). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T12:44:42Z. --- ### What `StorageTexture::captureGuestBytes` read the image's guest bytes with one `ReadCommitted` per tracked unit. Each call runs the flush hook, so for a block-unit image every 64 KiB unit published its unit shadows and waited for that copy on its own (`SyncThrough`), one batch per unit. The capture now runs the flush hook once per contiguous run of the selected units, then copies the units with the new `GuestMemory::ReadCommittedUnsynced`, which is `ReadCommitted` without the hook (the counterpart of `EqualsCommittedUnsynced`). `compareUntracked` already flushes once and compares unsynced the same way. What is published and waited for is unchanged: the same units, in one hook call per run. Found on Beast of Reincarnation (PPSA29343): a backtrace of the hook's recorded-store syncs put about 98% of them under `ShaderResources::buildComplete`/`Revalidate` -> `lookupStorageTexture` -> `StorageTexture::Refresh` -> `upload` -> `captureGuestBytes`, about 35 per upload. ### Tested Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, RTX 3050 Laptop 4 GB (NVIDIA 615.78.08), GCC, Release. - Built on current `main`; `tools/check_conventions.py` passes. - Full `ctest` on the RTX 3050: 950 of 950 pass (6 of them skipped: 5 `video_out_flip`/`frame_dump` tests and `agc_driver_stencil_ref_export`); the storage, unit shadow, guest memory, pending write, upload and import tests are 324 of them. - PPSA29343, title screen, `APS5_PROFILE_DRAW=1`, on a local branch that also carries the title's rendering fixes: recorded-store syncs from about 23000 to about 890 per 10 s, presents from 8 to 15-16 per 10 s (1.1 to 1.56 FPS from frame dump timestamps). The title frame is the same as before the change. `APS5_NO_UNIT_SHADOW=1` without this change gives the same rate. - It merges without conflict with #3991, which changes the first line of the same function. No automated test is added: the change keeps what is published and read and only drops the repeated hook calls; the existing unit shadow and storage tests cover the paths. ### 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
oneandonlydean commented 2026-10-13 00:20:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:20:30Z.


ReadCommittedUnsynced also skips the read guard that ReadCommitted runs before the flush hook (GuestMemory.cpp:1786), so a capture over a multisampled target's range no longer throws. Please run the guard in ReadCommittedUnsynced too, or once per run next to the FlushGpuWrites call in captureGuestBytes. The rest is fine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135178411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4468#issuecomment-6135178411). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:20:30Z. --- `ReadCommittedUnsynced` also skips the read guard that `ReadCommitted` runs before the flush hook (`GuestMemory.cpp:1786`), so a capture over a multisampled target's range no longer throws. Please run the guard in `ReadCommittedUnsynced` too, or once per run next to the `FlushGpuWrites` call in `captureGuestBytes`. The rest is fine.
GustavoGamarra95 commented 2026-10-13 00:52:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-13T00:52:15Z.


@oneandonlydean good catch. fa28772 makes ReadCommittedUnsynced run the read guard as ReadCommitted does (which still runs it before its flush hook); both now share the copy. e260f24 extends agc_multisample_guest_access to read the target's memory through both and expect both to throw; the unsynced one did not throw before this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135623968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4468#issuecomment-6135623968). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-13T00:52:15Z. --- @oneandonlydean good catch. fa28772 makes `ReadCommittedUnsynced` run the read guard as `ReadCommitted` does (which still runs it before its flush hook); both now share the copy. e260f24 extends `agc_multisample_guest_access` to read the target's memory through both and expect both to throw; the unsynced one did not throw before this change.
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!4468
No description provided.