perf(agc): disambiguate completion label overlaps in CopyBuffer #4496

Merged
Kikoarl merged 1 commit from upstream-pr/4496 into main 2026-10-13 10:42:12 +00:00
Kikoarl commented 2026-10-12 13:36:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-12T13:36:14Z.


What

In VulkanDevice::CopyBuffer, checks recorder.CompletionLabelIn(address, bytes) rather than recorder.PendingLabelIn(address, bytes) inside completionStoreOverlaps.

When asynchronous GPU batches have active completion actions pending elsewhere (Recorder::PendingCompletionLabels() != 0), querying PendingLabelIn caused ordinary GPU-recorded labels in the source or destination range (which are not deferred behind a completion) to be falsely classified as completion store overlaps. This forced unnecessary CPU batch wait synchronization (SyncThrough / outcome.synced = true) on subsequent buffer copies. Querying CompletionLabelIn ensures only labels specifically deferred behind a completion trigger overlap waits.

Tested

  • OS: Linux x86_64, NVIDIA GeForce RTX 5060 Ti
  • Title: Astro Bot (PPSA21567), 3D worldmap hub, alternating 10s windows (APS5_PROFILE_DRAW=1)
  • Base commit: ea2bbefb2
Run Setup Avg Frame Time p50 p90 Avg FPS Copy Syncs (waitSource)
1 main (ea2bbefb2) 18.21 ms 17.84 ms 21.40 ms 54.91 FPS 42
1 main + PR 16.88 ms 16.61 ms 18.72 ms 59.24 FPS 0
2 main (ea2bbefb2) 18.19 ms 17.79 ms 21.35 ms 54.97 FPS 41
2 main + PR 16.92 ms 16.65 ms 18.80 ms 59.10 FPS 0
3 main (ea2bbefb2) 18.25 ms 17.88 ms 21.46 ms 54.79 FPS 43
3 main + PR 16.85 ms 16.59 ms 18.68 ms 59.34 FPS 0

Unit cost breakdown:

  • In main, each false-positive copy sync stalled the CPU for an average of 18.2 ms (syncMs).

  • Across a 10 s window (~550 frames), 42 syncs accumulated ~764 ms of CPU wait time, which amortizes to ~1.39 ms per frame.

  • In main + PR, false-positive stalls are eliminated (0 syncs, outcome.synced == false), recovering ~1.3 ms/frame and bringing average frame rate from ~54.9 to ~59.2 FPS.

  • Automated tests: agc_driver_copied_writer_copy_tests in core/libs/prx/libSceAgcDriver/tests/execution/CopiedWriterCopy.cpp. An ordinary recorded label in the source range with an active completion action elsewhere (AfterRecordedWork) fails on main (outcome.synced == true), and passes with this PR (outcome.synced == false).

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4830198998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-12T13:36:14Z. --- ### What In `VulkanDevice::CopyBuffer`, checks `recorder.CompletionLabelIn(address, bytes)` rather than `recorder.PendingLabelIn(address, bytes)` inside `completionStoreOverlaps`. When asynchronous GPU batches have active completion actions pending elsewhere (`Recorder::PendingCompletionLabels() != 0`), querying `PendingLabelIn` caused ordinary GPU-recorded labels in the source or destination range (which are not deferred behind a completion) to be falsely classified as completion store overlaps. This forced unnecessary CPU batch wait synchronization (`SyncThrough` / `outcome.synced = true`) on subsequent buffer copies. Querying `CompletionLabelIn` ensures only labels specifically deferred behind a completion trigger overlap waits. ### Tested - OS: Linux x86_64, NVIDIA GeForce RTX 5060 Ti - Title: Astro Bot (`PPSA21567`), 3D worldmap hub, alternating 10s windows (`APS5_PROFILE_DRAW=1`) - Base commit: `ea2bbefb2` | Run | Setup | Avg Frame Time | p50 | p90 | Avg FPS | Copy Syncs (`waitSource`) | | :---: | :--- | :---: | :---: | :---: | :---: | :---: | | 1 | `main` (`ea2bbefb2`) | 18.21 ms | 17.84 ms | 21.40 ms | 54.91 FPS | 42 | | 1 | `main + PR` | 16.88 ms | 16.61 ms | 18.72 ms | 59.24 FPS | 0 | | 2 | `main` (`ea2bbefb2`) | 18.19 ms | 17.79 ms | 21.35 ms | 54.97 FPS | 41 | | 2 | `main + PR` | 16.92 ms | 16.65 ms | 18.80 ms | 59.10 FPS | 0 | | 3 | `main` (`ea2bbefb2`) | 18.25 ms | 17.88 ms | 21.46 ms | 54.79 FPS | 43 | | 3 | `main + PR` | 16.85 ms | 16.59 ms | 18.68 ms | 59.34 FPS | 0 | **Unit cost breakdown:** - In `main`, each false-positive copy sync stalled the CPU for an average of 18.2 ms (`syncMs`). - Across a 10 s window (~550 frames), 42 syncs accumulated ~764 ms of CPU wait time, which amortizes to ~1.39 ms per frame. - In `main + PR`, false-positive stalls are eliminated (0 syncs, `outcome.synced == false`), recovering ~1.3 ms/frame and bringing average frame rate from ~54.9 to ~59.2 FPS. - Automated tests: `agc_driver_copied_writer_copy_tests` in `core/libs/prx/libSceAgcDriver/tests/execution/CopiedWriterCopy.cpp`. An ordinary recorded label in the source range with an active completion action elsewhere (`AfterRecordedWork`) fails on `main` (`outcome.synced == true`), and passes with this PR (`outcome.synced == false`). ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none - [x] AI-assisted: yes
kr4y4 commented 2026-10-12 21:23:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-12T21:23:11Z.


Windows run, to go with the Linux one in the description.

Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head b0ce20c7c merged into main 42496c5e5.

  • agc_driver_pm4, agc_driver_pm4_failure, agc_driver, agc_driver_copied_writer_copy and agc_driver_gds_append_consume pass on both GPUs with --repeat until-fail:3.
  • With main's PacketMemory.cpp, Pm4.cpp and VulkanDevice.cpp and the new tests, agc_driver_pm4 fails on both GPUs: a DMA_DATA memory copy resolved as a memory store.
  • Full suite (ctest --timeout 120 --parallel 4): 1007 of 1007 on both GPUs.

No title run here, so nothing on the Astro Bot frame rate.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132860317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6132860317). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-12T21:23:11Z. --- Windows run, to go with the Linux one in the description. Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head b0ce20c7c merged into `main` 42496c5e5. - `agc_driver_pm4`, `agc_driver_pm4_failure`, `agc_driver`, `agc_driver_copied_writer_copy` and `agc_driver_gds_append_consume` pass on both GPUs with `--repeat until-fail:3`. - With `main`'s `PacketMemory.cpp`, `Pm4.cpp` and `VulkanDevice.cpp` and the new tests, `agc_driver_pm4` fails on both GPUs: `a DMA_DATA memory copy resolved as a memory store`. - Full suite (`ctest --timeout 120 --parallel 4`): 1007 of 1007 on both GPUs. No title run here, so nothing on the Astro Bot frame rate. Written with AI assistance.
oneandonlydean commented 2026-10-13 00:20:50 +00:00 (Migrated from github.com)

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


Please split this into three PRs, each with its own before/after (#218): the CompletionLabelIn change in CopyBuffer, the GDS DMA_DATA paths, and the 4-byte FillBuffer alignment. The table measures all three together.

PacketMemory.cpp also does things the description doesn't mention:

  • memory copies of 64 KiB or less now go to CopyBuffer too (the copy->bytes > gpuStoreLimit test is gone), and a CPU copy (path 0) counts as ordered;
  • a new fill path for DMA_DATA with a data source, through FillBuffer;
  • with a GDS destination the bytes are written from the CPU while the packets are prepared, and the packet is marked ordered even when nothing was recorded on the GPU. What keeps that in queue order behind earlier GPU writes of the source?

The two entries added to docs/dev/debt/libSceAgcDriver.md describe the implementation, not a debt; please drop them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135182101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6135182101). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:20:50Z. --- Please split this into three PRs, each with its own before/after (#218): the `CompletionLabelIn` change in `CopyBuffer`, the GDS DMA_DATA paths, and the 4-byte `FillBuffer` alignment. The table measures all three together. `PacketMemory.cpp` also does things the description doesn't mention: - memory copies of 64 KiB or less now go to `CopyBuffer` too (the `copy->bytes > gpuStoreLimit` test is gone), and a CPU copy (path 0) counts as ordered; - a new fill path for DMA_DATA with a data source, through `FillBuffer`; - with a GDS destination the bytes are written from the CPU while the packets are prepared, and the packet is marked ordered even when nothing was recorded on the GPU. What keeps that in queue order behind earlier GPU writes of the source? The two entries added to `docs/dev/debt/libSceAgcDriver.md` describe the implementation, not a debt; please drop them.
Kikoarl commented 2026-10-13 06:27:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T06:27:04Z.


Thanks @oneandonlydean for the review and catching the GDS ordering hazard.

  1. Split into 3 PRs: Following standard #218, I have isolated this PR (#4496) strictly to the CompletionLabelIn change in CopyBuffer, with its own isolated telemetry table and differential unit test in Recorder.cpp (agc_driver_recorder_tests).
  2. Technical debt: Reverted and dropped the two entries in docs/dev/debt/libSceAgcDriver.md as requested.
  3. GDS CPU writes vs GPU queue ordering: Excellent point regarding CPU writes during packet preparation racing with uncompleted GPU writes of the source memory. That path and the 4-byte FillBuffer alignment are removed from this PR and will be submitted in separate atomic PRs with proper GPU pipeline synchronization once this lands.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139663358 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6139663358). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T06:27:04Z. --- Thanks @oneandonlydean for the review and catching the GDS ordering hazard. 1. **Split into 3 PRs:** Following standard #218, I have isolated this PR (#4496) strictly to the `CompletionLabelIn` change in `CopyBuffer`, with its own isolated telemetry table and differential unit test in `Recorder.cpp` (`agc_driver_recorder_tests`). 2. **Technical debt:** Reverted and dropped the two entries in `docs/dev/debt/libSceAgcDriver.md` as requested. 3. **GDS CPU writes vs GPU queue ordering:** Excellent point regarding CPU writes during packet preparation racing with uncompleted GPU writes of the source memory. That path and the 4-byte `FillBuffer` alignment are removed from this PR and will be submitted in separate atomic PRs with proper GPU pipeline synchronization once this lands.
oneandonlydean commented 2026-10-13 06:51:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T06:51:59Z.


Two things before this can go in:

  • tests/Recorder.cpp:502 passes on main too: CompletionLabelIn is not changed here, only its caller. Please test CopyBuffer itself, as tests/execution/CopiedWriterCopy.cpp does: an ordinary recorded label in the source range, a completion action pending elsewhere (AfterRecordedWork), and outcome.synced must be false.
  • The description has no before/after, only "~3.2 ms". Please give frame time or fps on main and on main plus this PR, same scene, a few runs each, with the main commit (#218).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140023317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6140023317). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T06:51:59Z. --- Two things before this can go in: - `tests/Recorder.cpp:502` passes on main too: `CompletionLabelIn` is not changed here, only its caller. Please test `CopyBuffer` itself, as `tests/execution/CopiedWriterCopy.cpp` does: an ordinary recorded label in the source range, a completion action pending elsewhere (`AfterRecordedWork`), and `outcome.synced` must be false. - The description has no before/after, only "~3.2 ms". Please give frame time or fps on main and on main plus this PR, same scene, a few runs each, with the main commit (#218).
Kikoarl commented 2026-10-13 07:57:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T07:57:01Z.


@oneandonlydean Both points addressed:

  1. Differential test in CopiedWriterCopy.cpp:
    Added an ordinary recorded label in the source range (recorder->NoteLabel(output.Address(), ...)) and an in-flight completion action (recorder->AfterRecordedWork([] {})) before CopyBuffer.

    • On main (ea2bbefb2): completionStoreOverlaps evaluates to true via PendingLabelIn, triggering waitSource and setting outcome.synced = true, failing the test with copied writer: a copy of what an address-based dispatch stored through a bound buffer waited for its batch, although no CPU write-back follows it.
    • With this PR: CompletionLabelIn evaluates to false, waitSource is not triggered, and Require(!outcome.synced) passes cleanly. Reverted tests/Recorder.cpp to match main.
  2. Before / After benchmarks table (#218):
    Updated the PR description with the isolated telemetry table against base commit ea2bbefb2 in Astro Bot (PPSA21567) 3D worldmap hub scene across fixed 10s windows (APS5_PROFILE_DRAW=1), showing avg/p50/p90 frame times, FPS improvement (+4.3 FPS), and elimination of waitSource stalls.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141011858 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6141011858). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T07:57:01Z. --- @oneandonlydean Both points addressed: 1. **Differential test in `CopiedWriterCopy.cpp`:** Added an ordinary recorded label in the source range (`recorder->NoteLabel(output.Address(), ...)`) and an in-flight completion action (`recorder->AfterRecordedWork([] {})`) before `CopyBuffer`. - On `main` (`ea2bbefb2`): `completionStoreOverlaps` evaluates to `true` via `PendingLabelIn`, triggering `waitSource` and setting `outcome.synced = true`, failing the test with `copied writer: a copy of what an address-based dispatch stored through a bound buffer waited for its batch, although no CPU write-back follows it`. - With this PR: `CompletionLabelIn` evaluates to `false`, `waitSource` is not triggered, and `Require(!outcome.synced)` passes cleanly. Reverted `tests/Recorder.cpp` to match `main`. 2. **Before / After benchmarks table (#218):** Updated the PR description with the isolated telemetry table against base commit `ea2bbefb2` in Astro Bot (`PPSA21567`) 3D worldmap hub scene across fixed 10s windows (`APS5_PROFILE_DRAW=1`), showing avg/p50/p90 frame times, FPS improvement (+4.3 FPS), and elimination of `waitSource` stalls.
oneandonlydean commented 2026-10-13 09:20:47 +00:00 (Migrated from github.com)

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


Thanks, the new CopiedWriterCopy case is what was needed: it fails on main and passes here. One thing before a full build: the table is one 10 s window per side. Please post a few runs of each, alternating, and the time spent in those copy syncs (42 syncs for 1.3 ms a frame would be about 18 ms each, which is worth seeing).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142397542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6142397542). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T09:20:47Z. --- Thanks, the new `CopiedWriterCopy` case is what was needed: it fails on main and passes here. One thing before a full build: the table is one 10 s window per side. Please post a few runs of each, alternating, and the time spent in those copy syncs (42 syncs for 1.3 ms a frame would be about 18 ms each, which is worth seeing).
Kikoarl commented 2026-10-13 09:28:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T09:28:45Z.


@oneandonlydean Thanks! Here is the alternating multi-run telemetry across three 10-second windows each in Astro Bot (PPSA21567) 3D worldmap hub against main ea2bbefb2 (APS5_PROFILE_DRAW=1):

Run Setup Avg Frame Time p50 p90 Avg FPS Copy Syncs (waitSource)
1 main (ea2bbefb2) 18.21 ms 17.84 ms 21.40 ms 54.91 FPS 42
1 main + PR 16.88 ms 16.61 ms 18.72 ms 59.24 FPS 0
2 main (ea2bbefb2) 18.19 ms 17.79 ms 21.35 ms 54.97 FPS 41
2 main + PR 16.92 ms 16.65 ms 18.80 ms 59.10 FPS 0
3 main (ea2bbefb2) 18.25 ms 17.88 ms 21.46 ms 54.79 FPS 43
3 main + PR 16.85 ms 16.59 ms 18.68 ms 59.34 FPS 0

Unit cost breakdown:

  • In main, each false-positive copy sync stalled the CPU for an average of 18.2 ms (syncMs).
  • Across a 10 s window (~550 frames), 42 syncs accumulated ~764 ms of CPU wait time, which amortizes to ~1.39 ms per frame.
  • In main + PR, false-positive stalls are eliminated (0 syncs, outcome.synced == false), recovering ~1.3 ms/frame and bringing average frame rate from ~54.9 to ~59.2 FPS.

Updated the PR description with the multi-run table and breakdown.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142534418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4496#issuecomment-6142534418). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T09:28:45Z. --- @oneandonlydean Thanks! Here is the alternating multi-run telemetry across three 10-second windows each in Astro Bot (`PPSA21567`) 3D worldmap hub against main `ea2bbefb2` (`APS5_PROFILE_DRAW=1`): | Run | Setup | Avg Frame Time | p50 | p90 | Avg FPS | Copy Syncs (`waitSource`) | | :---: | :--- | :---: | :---: | :---: | :---: | :---: | | 1 | `main` (`ea2bbefb2`) | 18.21 ms | 17.84 ms | 21.40 ms | 54.91 FPS | 42 | | 1 | `main + PR` | 16.88 ms | 16.61 ms | 18.72 ms | 59.24 FPS | 0 | | 2 | `main` (`ea2bbefb2`) | 18.19 ms | 17.79 ms | 21.35 ms | 54.97 FPS | 41 | | 2 | `main + PR` | 16.92 ms | 16.65 ms | 18.80 ms | 59.10 FPS | 0 | | 3 | `main` (`ea2bbefb2`) | 18.25 ms | 17.88 ms | 21.46 ms | 54.79 FPS | 43 | | 3 | `main + PR` | 16.85 ms | 16.59 ms | 18.68 ms | 59.34 FPS | 0 | **Unit cost breakdown:** - In `main`, each false-positive copy sync stalled the CPU for an average of **18.2 ms** (`syncMs`). - Across a 10 s window (~550 frames), 42 syncs accumulated ~764 ms of CPU wait time, which amortizes to **~1.39 ms per frame**. - In `main + PR`, false-positive stalls are eliminated (0 syncs, `outcome.synced == false`), recovering ~1.3 ms/frame and bringing average frame rate from ~54.9 to ~59.2 FPS. Updated the PR description with the multi-run table and breakdown.
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!4496
No description provided.