feat(agc): batch a dispatch run's staged copy-ins ahead of it #9289
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9289"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-21T17:29:05Z.
What
The #9176 and #9287 prerequisites have merged. This branch contains the staged-copy prelude on top of
main; #13863 and #13920 build on it.Stage a run's copy-ins in a prelude before its dispatches, preserving command-buffer order. Copy-backs share a trailing barrier except where guest ranges overlap. Queries, open passes, validation and copy captures retain the inline path;
APS5_NO_BATCHED_STAGING=1selects it. The pool bounds retained free allocations, not buffers held in flight. By default its small tier and large host tier retain up to 64 MiB and 512 MiB; the device tier uses the greater of 512 MiB and one eighth of the device-local heap size (or its reported budget if smaller); for system-memory heaps it uses the greater of 128 MiB and one sixty-fourth of that size.APS5_STAGING_POOL_MIBoverrides the device tier. Returning an oversized allocation destroys it; otherwise least-recently-used free entries are evicted to fit the budget and slot cap.With main's changed-dword copy-back, a later merged copy-back over a range an earlier one in the same batch wrote takes a plain copy, so it wins there (oneandonlydean's commit, kept as its own commit); the batched barriers include the compute stage. The debt file records the trade-off.
A run split also moves the recorder's graphics command state (#16752) to the new command buffer. Without that, draws later in the batch bound their pipeline and dynamic state into the ended buffer; BunnyFl's ASTRO BOT run on an AMD card stopped at startup on that merge.
Preserve #6185's copy rules when combining its
RecordCopyBackschange; #9508 also overlapsRecorder.cppand #14260 touches the environment docs.Historical Yōtei menu counters (baseline, change) omit CPU and worker/phase fields and do not establish a speed gain.
Tested
Based on
main1adc0e2f4b(rebased 2026-11-17; the only conflict was the test'smain(), where main's per-round changed-copy snapshot check is kept and this PR's extra runs follow it; the eleven cases were rerun on this head). Windows 11 / MinGW-w64 GCC 15.2.0, Release with-DBUILD_TESTING=ON: eleven staged-copy, inline, dispatch-overlap, recorder, barrier and graphics-state cases, includingagc_bda_staging_overlap_barrierandagc_graphics_state_recorder, passed three times on RTX 3080 Laptop / 621.14 with validation 1.4.363 (synchronization validation for the barrier case). No VUIDs, hazards or skips.With the graphics-state call removed from the split,
agc_graphics_state_recorderand its unsuppressed variant failed 2 of 2 ("the graphics state still records into the command buffer the run split ended"). The two controls below were run on the previous head, onmainb4a82720a8, and not repeated. With the later-copy-back fix reverted,agc_bda_staging_overlap_barrierfailed 2 of 2 with incorrect bytes. With the overlap barrier removed it failed 2 of 2 withSYNC-HAZARD-WRITE-AFTER-WRITEunderAPS5_NO_CHANGED_COPY_BACK=1; on the default path synchronization validation does not see the changed-dword kernel's device-address writes, so it passed there. On an earlier head, moving the prelude failed the read-before-write fixture. Not tested on this head: Linux, macOS, AMD, titles/FPS (ASTRO BOT not rerun) or console behavior.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T17:29:19Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T00:42:11Z.
AMD/Linux data point for this stack (#9176 → #9287 → this PR) on another compute-dispatch-heavy title. Here it makes no measurable difference.
Setup
mainmerge base (de4ef842b5), plus #4449 (with a local descriptor guard) and #8908, which this title needs to reach the menu: base a1002a098e, with this PR merged on top 14555838d7.APS5_TRACE_SECONDS=200:30with 4194304 events; every trace reports dropped false.Vulkan.Dispatch.shader_resourcesms/frameDriver.Packet.dispatchms/frameIn this scene the dispatch cost is CPU-side shader-resource setup, which this stack does not target. GPU time per present is a little lower in both PR runs, but there is only one base run, so I would not call that a gain. No regression and no new errors.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T04:40:31Z.
@Celegans12 a merge-order note: #9565 (a draft) frees a completed batch's command buffer in
Recorder::release(Recorder.cpp) instead of keeping it for reuse. That is on the same lines where this PR keeps idle chunk command buffers for reuse and keepsmain's reuse of the batch's own command buffer. Composed, the batch's own command buffer is freed and the chunk command buffers are handled as this PR has them. As #9565 is the smaller change, it proposes going first, and this PR would rebase over it. If you'd rather this one went first, say so and #9565 will list it under Depends on.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-22T10:19:18Z.
Thanks for flagging it. Agreed, #9565 should go first: it's the smaller change, and #9289 is the deepest of a stack of three anyway (#9176, then #9287, then this one). Once #9565 lands I'll rebase #9289 over it. The split-off chunk buffers keep the handling this PR has, and the batch's own command buffer is freed the way #9565 does it. No need to list this PR under Depends on.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:25:32Z.
I verified the stated order against the current heads: #9565 is at
1da6feaf1699ecdaaee9eaa1a124cf22466edafc, while this PR is at2f412bb25fd3c389381ad6cac1cabda75137438c; a direct merge-tree currently conflicts inGraphics/src/Recorder.cpp. The #9565 author’s stated order is for it to land first and for this branch to rebase over it. Since this PR needs that change first, please add #9565 to the checklist’sDepends online under CONTRIBUTING, and retain the existing #9176 → #9287 dependencies and all command-buffer/chunk recycling behavior when rebasing. This is merge-order coordination; I found no separate code finding in this note.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:58:11Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.1. No performance evidence for a
perfPR. The body says the Yōtei menu counters "do not establish an FPS gain", and the linked summaries are baseline vs change JSONL from a historical build with CPU and worker/phase fields omitted. Please attachtools/trace_digest.pysummaries ofmainand of this head from the same machine and scene, or retitle it so it does not claim a speed change. Batching copy-ins into a prelude also changes how long every staged buffer stays live in the pool ("split buffers use a bounded pool"); the bound and what happens when it is hit are not stated.2. Scope and base. The PR targets
mainbut carries three commits (the compute-ring unordered dispatch change, the in-run staged copies, and this one) while the body says "stacked on #9287; review the last commit only". The diff onmainis therefore all three, includingRecorder.cppandPacketExecution.cppordering changes that this PR's description does not explain. Please say which of those belong to #9287 and rebase once it lands, or retarget.3. Test coverage. Two test cases (
agc_driver_overlap_staged_copiesand its_inlinevariant), run once each. There is no run of the AGC tests onmainagainst this head with the validation layer for comparison, and "Earlier negative controls are historical" means the current head has no demonstrated negative control for the new ordering: doesagc_driver_overlap_staged_copiesfail if the prelude copy-in is recorded after the dispatch it feeds, or if the shared trailing barrier is applied to overlapping ranges? Please show that failing run.4. Title. No title ID and log line showing a game reaches the batched path on
main; the Unblocks field should name one.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:22:58Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected change blocks merging; optional feedback is listed below.
What I ran
Reviewed head
dcace4d719541c4a80b48f4d32f84ab5c0eae156. I read the prepared description, commits, diff and manifest, then inspected targeted source context throughrepo_read.py. No tests or builds were run by me; the test results below are author-reported.Results
Negative control
Not run by me. The description reports negative controls for the graphics state, overlapping copy-back ordering and the overlap barrier; they were not repeated on this head.
Findings
Blocking
None in the inspected code.
Non-blocking
Sources
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp.core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp.Not verified
core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp,core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp,core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_overlap_staged_copies_tests.cmake,core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_recorder_tests.cmake,core/libs/prx/libSceAgcDriver/tests/execution/OverlapStagedCopies.cpp,docs/dev/ENVIRONMENT.mdanddocs/dev/debt/libSceAgcDriver.md.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppandcore/libs/prx/libSceAgcDriver/tests/Recorder.cppwas excluded from the prepared folder due to size; their targeted changed sections were inspected viarepo_read.py. Other portions of those files were not read.To get this to a good state
Nothing is required. Optional: retain the documented CPU-write trade-off when using merged overlapping copy-backs.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.