perf(agc): take a storage image's generation baseline only when its guest bytes are settled #2791

Merged
alfalfa-star merged 1 commit from upstream-pr/2791 into main 2026-10-10 19:45:15 +00:00
alfalfa-star commented 2026-10-10 15:13:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-10T15:13:40Z.


What

#1599 keeps a baseline of a storage image's guest bytes (images up to 1 MiB) when its layers get their generation, so a write-back can store the GPU results over CPU-stamped blocks whose bytes didn't change. The upload takes it with GuestMemory::ReadCommitted, also on the host-import path, where the upload itself runs on the GPU.

That read goes through the flush hook. When a unit shadow, another image's pending results or a recorded GPU store covers the surface, the hook publishes the shadow and the worker waits for the GPU on every such upload. Stack from PPSA14632, sampled at those waits: Driver::dispatch → ShaderResources::buildComplete / Revalidate → lookupStorageTexture → StorageTexture::Refresh → upload → (generation stamp) → ReadCommitted → FlushForAccess.

The baseline is now taken only when nothing of that kind overlaps the surface (StorageTexture::guestBytesSettled: AnyShadowedOverlaps, AnyPendingOverlaps, Recorder::PendingWriteOverlaps). Otherwise the image has no baseline, and its write-back keeps the CPU's bytes for stamped blocks, the rule before #1599. The TechnicalDebt entry from #1599 now names the condition.

New ctest agc_storage_baseline_settled (agc_driver_recorder_tests --settled-baseline-only): it creates a storage image over a watched host import while a recorded store is pending over part of it, and checks that the upload did not submit the open batch. Without this change it fails ("an upload over a pending recorded store submitted the open batch to read its generation baseline"). agc_unchanged_cpu_stamps (#1599) still passes, so settled surfaces keep the baseline.

Tested

Linux (Arch), RX 9070 XT, RADV, Release:

  • Full ctest: 699/699.
  • PPSA14632 (LEGO Horizon Adventures), on my test branch (main db343a93 plus #1157, #425, #2699, #423/#1077 and local stand-ins needed to reach gameplay), steady state per 10 s:
flush-hook recorded-store syncs waited queue 0 direct dispatch, device call
without ~3,400 ~4.0 s 356 us
with this PR ~630 ~0.3 s 107 us

On its own this barely moves presents (~100 → ~104 per 10 s): the GPU wait moves to DMA_DATA copies, which #2792 addresses.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4812225483 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2791). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-10T15:13:40Z. --- ### What #1599 keeps a baseline of a storage image's guest bytes (images up to 1 MiB) when its layers get their generation, so a write-back can store the GPU results over CPU-stamped blocks whose bytes didn't change. The upload takes it with `GuestMemory::ReadCommitted`, also on the host-import path, where the upload itself runs on the GPU. That read goes through the flush hook. When a unit shadow, another image's pending results or a recorded GPU store covers the surface, the hook publishes the shadow and the worker waits for the GPU on every such upload. Stack from PPSA14632, sampled at those waits: `Driver::dispatch` → `ShaderResources::buildComplete` / `Revalidate` → `lookupStorageTexture` → `StorageTexture::Refresh` → `upload` → (generation stamp) → `ReadCommitted` → `FlushForAccess`. The baseline is now taken only when nothing of that kind overlaps the surface (`StorageTexture::guestBytesSettled`: `AnyShadowedOverlaps`, `AnyPendingOverlaps`, `Recorder::PendingWriteOverlaps`). Otherwise the image has no baseline, and its write-back keeps the CPU's bytes for stamped blocks, the rule before #1599. The TechnicalDebt entry from #1599 now names the condition. New ctest `agc_storage_baseline_settled` (`agc_driver_recorder_tests --settled-baseline-only`): it creates a storage image over a watched host import while a recorded store is pending over part of it, and checks that the upload did not submit the open batch. Without this change it fails ("an upload over a pending recorded store submitted the open batch to read its generation baseline"). `agc_unchanged_cpu_stamps` (#1599) still passes, so settled surfaces keep the baseline. ### Tested Linux (Arch), RX 9070 XT, RADV, Release: - Full ctest: 699/699. - PPSA14632 (LEGO Horizon Adventures), on my test branch (`main` db343a93 plus #1157, #425, #2699, #423/#1077 and local stand-ins needed to reach gameplay), steady state per 10 s: | | flush-hook recorded-store syncs | waited | queue 0 direct dispatch, device call | |---|---|---|---| | without | ~3,400 | ~4.0 s | 356 us | | with this PR | ~630 | ~0.3 s | 107 us | On its own this barely moves presents (~100 → ~104 per 10 s): the GPU wait moves to DMA_DATA copies, which #2792 addresses. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
popcoder565 commented 2026-10-10 15:57:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-10T15:57:44Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 75b540c2, merged onto main 57f96fd2b in one build with 4 other new PRs.

  • agc_driver_recorder_tests (not in ctest), which holds this PR's test change, passes 10 of 10, built explicitly.
  • Full ctest in that build: 711 of 711.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099394880 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2791#issuecomment-6099394880). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-10T15:57:44Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `75b540c2`, merged onto `main` 57f96fd2b in one build with 4 other new PRs. - `agc_driver_recorder_tests` (not in ctest), which holds this PR's test change, passes 10 of 10, built explicitly. - Full ctest in that build: 711 of 711. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
orbz22 commented 2026-10-10 16:37:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-10T16:37:33Z.


Checked on Windows with Hollow Knight: Silksong (PPSA12544), the title whose boxed menu letters #1599 fixed.

Setup: Windows 11 Pro (26300), i7-11800H, RTX 3060 Laptop (driver 617.42), WinLibs GCC 15.2.0 r7, Release. main de5e541d + #846 (for the plugins), with and without this PR. Each run used the same scripted input for 250 s (title menu, profile select, New Game, the opening, into Moss Grotto) with APS5_PROFILE_DRAW=1.

  • No regression: the menu and profile-select text is intact in frames dumped at 960x540. The opening and Moss Grotto look the same as without the PR.
  • Waits: the pending write syncs from FlushForAccess dropped to 0 with this PR. Without it there were 3 to 5 per run, in three runs. They took no measurable time here. The other GPU waits did not change, and most of them come from WaitForKeyWriters.
  • #1970: the 8 keeping the CPU's blocks lines appear with and without the PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099776683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2791#issuecomment-6099776683). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-10T16:37:33Z. --- Checked on Windows with Hollow Knight: Silksong (PPSA12544), the title whose boxed menu letters #1599 fixed. **Setup:** Windows 11 Pro (26300), i7-11800H, RTX 3060 Laptop (driver 617.42), WinLibs GCC 15.2.0 r7, Release. `main` de5e541d + #846 (for the plugins), with and without this PR. Each run used the same scripted input for 250 s (title menu, profile select, New Game, the opening, into Moss Grotto) with `APS5_PROFILE_DRAW=1`. - **No regression:** the menu and profile-select text is intact in frames dumped at 960x540. The opening and Moss Grotto look the same as without the PR. - **Waits:** the `pending write` syncs from `FlushForAccess` dropped to 0 with this PR. Without it there were 3 to 5 per run, in three runs. They took no measurable time here. The other GPU waits did not change, and most of them come from `WaitForKeyWriters`. - **#1970:** the 8 `keeping the CPU's blocks` lines appear with and without the PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!2791
No description provided.