Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Kikoarl:perf/agc-gds-dma-and-completion-label-sync
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Kikoarl:perf/agc-gds-dma-and-completion-label-sync

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added docs agc libSceAgc* labels Oct 12, 2026
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed labels Oct 12, 2026
@Kikoarl
Kikoarl force-pushed the perf/agc-gds-dma-and-completion-label-sync branch from e1acd3f to b0ce20c Compare October 12, 2026 18:44
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@kr4y4

kr4y4 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

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 b0ce20c merged into main 42496c5.

  • 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

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@Kikoarl
Kikoarl force-pushed the perf/agc-gds-dma-and-completion-label-sync branch from b0ce20c to 40cbac4 Compare October 13, 2026 06:26
@Kikoarl Kikoarl changed the title perf(agc): optimize GDS DMA transfers and disambiguate completion label overlaps perf(agc): disambiguate completion label overlaps in CopyBuffer Oct 13, 2026
@Kikoarl

Kikoarl commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

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

  1. Split into 3 PRs: Following standard perf(shader): cut hot-path overhead in recompile cache lookups #218, I have isolated this PR (perf(agc): disambiguate completion label overlaps in CopyBuffer #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.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 (perf(shader): cut hot-path overhead in recompile cache lookups #218).

@Kikoarl
Kikoarl force-pushed the perf/agc-gds-dma-and-completion-label-sync branch from 40cbac4 to 396b518 Compare October 13, 2026 07:56
@Kikoarl

Kikoarl commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@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 (perf(shader): cut hot-path overhead in recompile cache lookups #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

Copy link
Copy Markdown
Collaborator

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

Kikoarl commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@oneandonlydean
oneandonlydean merged commit 1d7b075 into boykopovar:main Oct 13, 2026
9 of 10 checks passed
Zenodeon added a commit to Zenodeon/AnyPS5 that referenced this pull request Oct 22, 2026
Use the existing completion-store range query when deciding whether resource acquisition needs a CPU write-back wait. An unrelated pending host completion must not turn an ordinary GPU label into a CPU dependency. This applies the distinction already used in CopyBuffer by merged PR boykopovar#4496.

Cover fresh and cached direct consumers with an unrelated host completion, exact GPU output and deferred completion execution. The focused regression fails with the broad label query and passes with the completion-store query on an RTX 4070 under Vulkan validation. No gameplay speed claim.
teepean pushed a commit to teepean/AnyPS5 that referenced this pull request Oct 23, 2026
Use the existing completion-store range query when deciding whether resource acquisition needs a CPU write-back wait. An unrelated pending host completion must not turn an ordinary GPU label into a CPU dependency. This applies the distinction already used in CopyBuffer by merged PR boykopovar#4496.

Cover fresh and cached direct consumers with an unrelated host completion, exact GPU output and deferred completion execution. The focused regression fails with the broad label query and passes with the completion-store query on an RTX 4070 under Vulkan validation. No gameplay speed claim.

(cherry picked from commit a9209d9)
Zenodeon added a commit to Zenodeon/AnyPS5 that referenced this pull request Oct 23, 2026
Use the existing completion-store range query when deciding whether resource acquisition needs a CPU write-back wait. An unrelated pending host completion must not turn an ordinary GPU label into a CPU dependency. This applies the distinction already used in CopyBuffer by merged PR boykopovar#4496.

Cover fresh and cached direct consumers with an unrelated host completion, exact GPU output and deferred completion execution. The focused regression fails with the broad label query and passes with the completion-store query on an RTX 4070 under Vulkan validation. No gameplay speed claim.
oneandonlydean pushed a commit that referenced this pull request Nov 2, 2026
Use the existing completion-store range query when deciding whether resource acquisition needs a CPU write-back wait. An unrelated pending host completion must not turn an ordinary GPU label into a CPU dependency. This applies the distinction already used in CopyBuffer by merged PR #4496.

Cover fresh and cached direct consumers with an unrelated host completion, exact GPU output and deferred completion execution. The focused regression fails with the broad label query and passes with the completion-store query on an RTX 4070 under Vulkan validation. No gameplay speed claim.
slopezjur pushed a commit to slopezjur/AnyPS5 that referenced this pull request Nov 13, 2026
Use the existing completion-store range query when deciding whether resource acquisition needs a CPU write-back wait. An unrelated pending host completion must not turn an ordinary GPU label into a CPU dependency. This applies the distinction already used in CopyBuffer by merged PR boykopovar#4496.

Cover fresh and cached direct consumers with an unrelated host completion, exact GPU output and deferred completion execution.

Port of upstream 7ac63cb: the fork's merges kept its own libSceAgcDriver, so the condition and its regression test were lost. On the Ghost of Yotei DLC screen the draw committer synced once per frame, under the GPU mutex, on a queue 0x52 GPU label in a cached build's address space (GuestBufferMemory::ResumeSpace). With the port its locked GPU waits drop from 265-468 to 131-151 ms per 10 s; fps 5.666 -> 5.730 (interleaved, 3 runs, +1.1 %). agc_copied_direct_ordering passes; the focused label tests show the same results and VUIDs as the base under Vulkan validation.

(cherry picked from commit 7ac63cb)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Celegans12 pushed a commit to Celegans12/AnyPS5-Ghost-of-Yotei that referenced this pull request Nov 14, 2026
Use the existing completion-store range query when deciding whether resource acquisition needs a CPU write-back wait. An unrelated pending host completion must not turn an ordinary GPU label into a CPU dependency. This applies the distinction already used in CopyBuffer by merged PR boykopovar#4496.

Cover fresh and cached direct consumers with an unrelated host completion, exact GPU output and deferred completion execution.

Port of upstream 7ac63cb: the fork's merges kept its own libSceAgcDriver, so the condition and its regression test were lost. On the Ghost of Yotei DLC screen the draw committer synced once per frame, under the GPU mutex, on a queue 0x52 GPU label in a cached build's address space (GuestBufferMemory::ResumeSpace). With the port its locked GPU waits drop from 265-468 to 131-151 ms per 10 s; fps 5.666 -> 5.730 (interleaved, 3 runs, +1.1 %). agc_copied_direct_ordering passes; the focused label tests show the same results and VUIDs as the base under Vulkan validation.

(cherry picked from commit 7ac63cb)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit efff1fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants