perf(agc): dispatch-cache recipe hits as ordered commit items #1747
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1747"
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 MichonGoddijn231849 on 2026-10-08T18:23:02Z.
What
With pipelined draws (#1201, on by default since #1202), every compute dispatch on queue 0 still drains the pipeline before it runs, so the committer goes idle and the worker waits. Titles with many dispatches between draws pay that on each one: Demon's Souls issues about 3,800 queue-0 dispatches per frame in its tutorial level, most of them one chain of small ones (measured by @fisherjoey on #1202).
APS5_PIPELINE_DISPATCH=1(off by default; needs pipelined draws) makes aDISPATCH_DIRECTwhose dispatch-cache entry hits with a recipe an ordered commit item, like the draws around it. The capture and the cache lookup run on the worker; the recording runs on the committer in order. A dispatch still drains, as today, when:DrawPipeline::DrainRequestsByOpcodecounts drains per opcode andDrawPipeline::QueuedItemsreports the queue size, both for the tests.DispatchWriteRangesgives the commit item the dispatch's write ranges, so later draws that read them wait for it.Tests (
tests/execution/PipelinedDispatch.cpp):agc_driver_pipelined_dispatch(switch off): a dispatch after an immediate fill of its input, in one DCB, over several rounds; each dispatch drains once and reads the fill.agc_driver_pipelined_dispatch_item(switch on): repeated dispatches that read nothing pending do not drain; a round whose descriptor table a pending fill retargets drains and reads the new buffer. That round holds the committer behind a gate item, waits until the fills are queued, and only then submits the dispatch, so the order is exact rather than timed. With the read-side check removed it reads the buffer the table named before the fill (0x6a6a0002 for 0x6b6b0003), every run; with the commit-item path removed, the first round fails ("a dispatch that reads nothing pending drained the pipeline").Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.
agc_tests pass with the switch off and on.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)main)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:58:14Z.
@MichonGoddijn231849 here are the Demon's Souls numbers for
APS5_PIPELINE_DISPATCH. On this title it doesn't change anything, and the reason looks like the dispatch cache rather than the pipelining itself.Setup: Nobara 44 x86-64, RTX 5070 Ti (driver 595.91.07), Ryzen 5 7600X, Demon's Souls PPSA01341 v1.07, tutorial level (Outpost Passage) through the debug start menu. Base is main
df16c4c2+ #1202 (incl. #1201, the revision before 569252ba) + our local patches: #1184, #1071, a job-worker idle backoff, a higherAPS5_BINDLESS_SLOTSclamp, a per-device entry point cache, shared/resident staging shadows, a pending-image overlap index, a Linux page-table cache and an NVIDIA dma-buf guard. I cherry-picked only the last commit (c7cc7b78). The one real conflict was inDispatch.cpp, against a resolve-ahead path we carry; I kept your candidate check outside the resolve-only branch and took the rest as in the PR. Allagc_drivertests pass (173/173), including both new ones.Method: one build, the switch unset vs
=1, 3 + 3 runs interleaved, 240 s each, last 8 level windows (t+150 to t+230), base envAPS5_PROFILE_DRAW=1 APS5_BINDLESS_SLOTS=128. The game window was on-screen in every run.APS5_PIPELINE_DISPATCH=1(3 runs)DISPATCH_DIRECTus per dispatch[dispatch-item]drained instead / 10 s* Run 345 lost three windows to unrelated CPU load on the box (16, 8 and 14 presents). Run 350's first window was the tail of the level load (12).
No new errors: 0/6 fatal, no GPU hangs or timeouts, and both sides show the same boot-time notes (missing debug-menu concommands, one ALSA underrun).
Why it doesn't help here: only about 2.5k of the ~85k queue-0 direct dispatches per 10 s are dispatch-cache hits. The rest miss by-value validation because the captured data differs every frame, so they never get a recipe and drain as before (~2k items per 10 s against ~82k "no recipe"). The pre-lookup scan of the cache entry runs for every candidate, which probably accounts for most of the +2 us per dispatch. The drain wait isn't where the time goes either. Dispatches here mostly come back to back, so the pipeline is already empty for all but ~1.7k of them per 10 s, and the cost is capture plus the device call on the worker. One suggestion: split "no recipe" into "validation miss" and "hit without a recipe". On this title those are very different numbers.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:33:05Z.
Parked as a draft with the rest of the pipelined stack while it is ported onto #639. @fisherjoey thanks for the Demon's Souls numbers: if the dispatch cache rather than the pipelining is what limits that title, that is where I'll look after the port.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T16:33:48Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppL168core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppL34core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppL87core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL317-318Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Memory/DrawWriteRanges.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Memory/DrawWriteRanges.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Memory/DrawWriteRanges.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppImported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-15T15:57:59Z.
Rebased onto current
main(92e50418f); with #1201 and #1202 merged it is one commit (da1833f62). What changed againstmain's rework:main'sdispatchnow resolves dispatch groups ahead (resolving,fromAhead). A dispatch being resolved or adopted from a group resolved ahead keeps the drained path. The candidate check sits inmain's non-resolving branch, after its fill HLE, and also excludesmain's stream-copy kernel next to the copy kernel.maindrains the pipeline at every dispatch group to resolve it ahead (PacketExecution.cpp, thegateOpenedbranch). WithAPS5_PIPELINE_DISPATCHon, queue 0 skips that resolve, since it would drain before every group and leave nothing to pipeline. Off by default, somain's path is unchanged without the switch.main's own checks already drained for is not counted twice.Mutation::Addtakesmain'sgpuflag (false, as before), and the buffer descriptors setOOB_SELECT3 (raw), sincemainbounds-checks structured buffers with a zero stride.agc|shaderctest on Windows (MinGW): 600 of 601, bothagc_driver_pipelined_dispatchtests pass. The failure,agc_driver_image_plane_address_on_line, also fails onmain92e50418f.@fisherjoey, your Demon's Souls numbers pointed at the dispatch cache rather than the pipelining. On this base the queue-0 resolve-ahead skip is a new trade, so a before/after on that title would show whether the items or
main's group resolve wins there.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T10:58:14Z.
Checked on this branch merged onto current
main: AgcDriver build + ctest pass (the one failure,agc_driver_tessellation, segfaults insidelibvulkan_radeon.soand is unrelated to the change), and the agc tests pass on lavapipe. Both mutations you describe (read-side check removed, commit-item path removed) makeagc_driver_pipelined_dispatch_itemfail.Added on your branch as our own commits:
test(agc): wait for the pipeline to empty between descriptor rounds: the test assertedQueuedItems() == 0right afterAgcDriverWaitIdle, which flaked under load on lavapipe (3 of 6 parallel runs failed before, 180 parallel runs pass after).docs(architecture): describe dispatches queued as pipeline items:APS5_PIPELINE_DISPATCHand its drain conditions in the queue-0 pipeline paragraph.Merging once CI is green.