perf(agc): pipeline DMA_DATA when APS5_PIPELINE_DMA=1 #6208
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6208"
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 ivica00 on 2026-10-15T02:56:10Z.
What
DMA_DATAon queue 0 joins the draw pipeline whenAPS5_PIPELINE_DMA=1.keepsDrawPipelineuses that same switch: with it unset, everyDMA_DATAdrains, including a non-overlapping copy and aDST_SELnowhere prefetch. A copy whose source or destination overlaps an uncommitted draw drains first. A copy that does not, aSET_PREDICATION, and a NOP from the allow-list (plain NOP, dispatch reset, marker push and pop, context state) leave the queue in place. Other custom NOP packets still drain.SET_PREDICATION(opcode0x20) only stores the predicate address and operation on the queue. It does not read that memory. The later predicated packet drains when the predicate overlaps a queued write.A copy reads its source when the pipeline runs it, so it sees an earlier fill. An immediate fill above 64 KiB is still stored as a buffer fill, a copy into host memory is still counted, and a predication that reads an uncommitted range waits for that range. Marker push and pop still update the marker stack.
Tested
Not re-run in this update. The previous run of
agc_driver_pipelined_dma_testsandagc_driver_testswas on an AMD Radeon RX 9070 XT, Windows 10. The DMA test setsAPS5_PIPELINE_DMA=1and covers fill-then-copy ordering, a prefetch (DST_SELnowhere), a zero-byte copy, a GDS copy, an unaligned copy off a pending write, onto a pending write, and of a pending write,SET_PREDICATION, marker push/pop, a predicated packet whose predicate overlaps a pending write, andDISPATCH_RESETstaying on the pipeline.No new title-session numbers from this machine. The measurements already on this PR (Borderlands 4, Stellar Blade) do not show a frame-time win for copies and fills on by default, so pipelining stays opt-in. @Pacuka measured The Smurfs - Dreams with
APS5_PIPELINE_DMA=1(about 7.9 to 9.4 fps in the village). @TheAggie measured the prefetch case on RetroArch's PCSX2 core; that part is #6538, which is still open, so the nowhere case stays here until that lands.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-15T03:31:42Z.
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/Packets/PacketExecution.cppL26core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL26core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL35Some 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/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T09:30:40Z.
Review: DISMISSED
Built this on its own commit (the stack below it is not merged; #6203, its base, was closed as a duplicate of #1201) and ran the libSceAgcDriver tests:
agc_driver_pipelined_dma(added here) fails: "the copy did not see the fill before it, or wrote past its bytes". Please make it pass and check it fails without theenqueueDmaPacketchange.agc_driver_pm4segfaults: the PR drops the marker push/pop inPm4.cpp:986-991, buttests/Pm4.cpp:220still checksstate.markers.back() == "abc"and the unbalanced-pop case at:223. Either keep the marker stack behaviour or update those tests and say why nothing readsqueue.markers.PacketMemory.cpp,APS5_NO_PIPELINE_DMA) is a perf change with no numbers. Please post before/after (same scene, several runs) and a Linux test that covers the overlap cases ofkeepsDrawPipelinecase 0x50 (copy overlapping an uncommitted draw write, dst == 1/2, 0 bytes) and the predication wait.mainand stacks on #6203, which was closed as a duplicate of #1201: please rebase it on #1201 (or onmainonce #1201 is in) and it can be re-reviewed then.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T10:22:29Z.
Heads-up from testing #1202 on current main (#1201 merged): with
APS5_PIPELINE_DMA=1,agc_driverfails attests/Submit.cpp:537("a copy into host memory drained instead of syncing its source"). The bytes are right; the copy is enqueued on the pipeline, socopiesToHostMemorynever counts it. With DMA on by default here, that check (or the enqueue path's count) needs updating in this PR.Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-15T19:24:27Z.
@ivica00 one data point for the
keepsDrawPipelinecase 0x50 part of this, from a title where it is almost the whole cost: RetroArch's PCSX2 core (Ratchet & Clank) under RADV issues aDMA_DATAprefetch (DST_SEL nowhere) per draw, about 120,000 per 10 s, and with pipelined draws every one drained the pipeline. Keeping the pipeline for that destination alone, with copies and fills still draining, took the heavy intro scenes from 24-25% of real time to 37-43% here over three runs, and the lighter scenes to real time.Since this PR is being reworked onto #1201 and that part needs no snapshotting, I have opened it on its own as #6538, with a test that holds the pipeline busy and counts the drains for a prefetch and for a copy. If you would rather fold it in here, say so and I will close mine.
AI-assisted (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-16T21:05:49Z.
Rebased onto current
main(#1201is merged; the closed#6203stack is no longer the base).agc_driver_pipelined_dmafailed because a copy of at most 64 KiB snapshotted its source while being enqueued, before the fill ahead of it had run. The copy now reads the source when the pipeline runs it, in order. The same test passes here, and it is what fails if that read moves back to enqueue time.keepsDrawPipelinealready leaves those NOPs on the pipeline; dropping the stack madeagc_driver_pm4callmarkers.back()on an empty vector.DISPATCH_RESETstill drains.copiesToHostMemoryon the same path-2 condition as the synchronous path, and an immediate fill above 64 KiB is still a buffer fill (dmaFills).agc_driver_testspasses with DMA on by default.SET_PREDICATION, and a predicated packet whose predicate overlaps an uncommitted write.Locally, on an RX 9070 XT:
agc_driver_pipelined_dma_testsandagc_driver_testspassed.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T03:58:58Z.
A data point from a title where
DMA_DATAdrains are frequent: Borderlands 4 (PPSA01494). Linux 6.8, RTX 4070 Ti (595.99.02), Release, pad input, warm cache, 130 s runs.mainea5c27b53eagainst the samemainwith this PR's head (4a2b7d34f2) merged (clean merge).Profiled runs (
APS5_PROFILE_DRAW=1), the last[draw] pipelinedline:main0x3c1,017,0x50763,0x10/0x20/flip 255 each0x3c358,0x10/0x3f/flip 90 each,0x1587The
DMA_DATAdrains are gone, and the count ofWAIT_REG_MEMdrains also falls by about two thirds. The worker's total time in the remaining drains doesn't fall, though: each one now waits longer.Frame rate in the 100–110 s window, no
APS5_PROFILE_*switch, two rounds interleaved:That scene hitches hard either way (p90 350–690 ms), so these windows don't show a difference. All 6 runs (3 per build) reached their limits.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-17T11:47:15Z.
Review: DISMISSED
Thanks for the rebase; the points from the earlier review are addressed in the diff (copy reads its source when the pipeline runs it, marker stack kept,
copiesToHostMemorycounted, overlap/GDS/zero-byte/predication tests). Remaining:DST_SELnowhere prefetch (@TheAggie, 24-25% → 37-43% on a PCSX2 scene), and that case is already in #6538 (keepsDrawPipelinecase 0x50, same file). Please rebase on top of it once merged and drop the duplicate part.APS5_PIPELINE_DMA=1.PacketExecution.cpp:46changes the NOP rule from an allow-list (0, 0x09, 0x0b, 0x0c, 0x1a) to "everything except 0x09". Please say which other NOP operations exist and why none needs the pipeline drained (or keep the allow-list plus 0x0b/0x0c).Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-17T13:22:29Z.
Tested this on Windows (RX 9070 XT, AMD 26.8.1) with Stellar Blade, which issues a lot of DMA_DATA on queue 0, merged on top of current main together with other draw-pipeline work. Measured with
APS5_PROFILE_DRAW=1(per 10 s intervals, same scenes, before = this PR not applied, after = this PR's default):No pipeline failures or crashes across three ~10 minute runs with it on by default, and nothing looked wrong while playing.
agc_driver_pipelined_dmapasses on the merged tree.Frame time in Stellar Blade did not move much, because the queue-0 worker now waits on the draw committer at other packets instead, so this does not show up as FPS here yet. The drain removal itself works as described.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-17T15:41:52Z.
A possible ordering gap in
keepsDrawPipelinefor DMA_DATA (PacketExecution.cpp, thecase 0x50this PR adds). It decides whether a DMA_DATA that stays on the inline path needs a drain by checking only the destination against queued writes:The source is never checked. A memory-to-memory copy that
enqueueDmaPacketrefuses (for example an unaligned destination or size) therefore runs inline without a drain, even when a queued item still has to write its source. The copy then reads the source before that item commits and stores stale bytes.I hit it while working on a change that keeps some small copies off the pipeline: a fill followed by a copy of the filled range read zeros. Checking the source as well fixed it:
I haven't reproduced it on this PR's head alone, only on a branch that sends more copies down the inline path. On this PR's head an unaligned copy of a range a queued fill writes should show it. I can write that test if it helps.
Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-17T22:15:09Z.
Addressing the remaining review:
APS5_PIPELINE_DMA=1). The Borderlands 4 and Stellar Blade numbers on this PR do not show a frame-time win, and the PCSX2 gain was theDST_SELnowhere prefetch. That part is #6538, which is still open, so it stays here until that lands and can be dropped.0x10is the allow-list again: plain NOP,DISPATCH_RESET(0x09), marker push/pop (0x0b/0x0c) and context state (0x1a). The other custom operations (DRAW_RESET,WAIT_FLIP_DONE,ACQUIRE_MEM,WRITE_DATA,FLIP,RELEASE_MEM,DMA_DATA_CUSTOM) are not NOPs and still drain.keepsDrawPipelineforDMA_DATAalso drains when a memory source (selector 0 or 3) overlaps a queued write. An unaligned copy that stays on the worker then cannot read that range early. The DMA test covers a 2-byte copy of a range a queued item still writes.Pushed in
bf47f840e.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T02:53:23Z.
Picking this up while @adriadam10 is away. Thanks: the enqueue is opt-in now and the NOP allow-list is back. Two things remain. (1)
keepsDrawPipeline's newcase 0x50still applies withoutAPS5_PIPELINE_DMA, so by default non-overlapping DMA_DATA no longer drains. Please gate it on the same switch, or post a before/after showing a win. Please also say why opcode 0x20 joins the keep list. (2) Once #6538 merges, please rebase on it and drop the DST_SEL-nowhere case it already covers.Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-18T11:53:50Z.
Data point where this helps: The Smurfs - Dreams (PPSA21607, Unreal Engine), Linux, RX 6650 XT / RADV Mesa 26.2.4, main
9f25d0bf5+ this PR (plus local unrelated rendering fixes). In the Smurfs' Village,APS5_PROFILE_DRAW=1shows ~10kDMA_DATAper 10 s on queue 0 taking ~3.8 s (each a drain). WithAPS5_PIPELINE_DMA=1: 76–84 → 92–96 presents per 10 s (~7.9 → ~9.4 fps, about +19%), steady over ~15 windows;DMA_DATAdrops out of the top packets. Time shifts partly into fill HLE dispatches (65 ms → 1.1 s per 10 s) and packet drains (1.2 s → 4.2 s), but the net is a clear win here. No rendering differences noticed.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-18T12:14:45Z.
Addressed on
2d96ff77a.keepsDrawPipelineforDMA_DATA(0x50) now uses the sameAPS5_PIPELINE_DMAcheck asenqueueDmaPacket. With the switch unset, everyDMA_DATAdrains, including a non-overlapping copy and aDST_SELnowhere prefetch. @Pacuka's Smurfs numbers are with the switch on, so they stay the measurement for the opt-in path. The default path is a drain again.Opcode
0x20isSET_PREDICATION. It only stores the predicate address and operation on the queue; it does not read that memory. The packet that is actually predicated still drains when the predicate overlaps a queued write. The DMA test covers that with opcode0x13, and it expects0x20itself not to drain. That is why0x20is on the keep list.DST_SELnowhere case stays in thiscase 0x50until that merges. I will rebase onto it and drop the duplicate then.The DMA test sets
APS5_PIPELINE_DMA=1before it counts drains, so this gate does not change that run. I did not re-run it on a GPU for this push.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T18:25:40Z.
Merged while @adriadam10 is away. Of your three points, the NOP allow-list and the opt-in gating are done, and the overlap with #6538 now sits inside the opt-in path, so whichever of the two lands second resolves one small conflict. Full CI is green on this head.