perf(agc): sync only the source for DMA_DATA copies into host-only memory #1157
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1157"
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 alfalfa-star on 2026-10-07T15:35:49Z.
What
A DMA_DATA copy larger than the store limit (64 KiB) runs as a transfer between host imports. When its destination is not registered guest memory, there's no import for it (the GPU can neither read nor write that memory), so the transfer was refused. The packet then drained the device: every batch recorded so far was submitted and waited for, and then the CPU copied.
Such a copy only has to see the source's results:
Recorder::SyncThrough). Then it copies on the CPU without a drain.[sync]line counts these copies (copies into host memory synced on their source).Tested
Linux 7.2.9 (Arch), Mesa 26.2.4 RADV, RX 9070 XT.
ctest: 396 of 396 pass.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:42:53Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
9653aa91, merged ontomain8b393b6ein one build with 31 other PRs that had no Windows run.guest_offline_imports, broken by #2359 (reported there).No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:27:52Z.
Review: CHANGES_REQUESTED
Thanks. The idea is sound, but one case changes behaviour compared with the drain it replaces:
PacketMemory.cpp:148-153: the new branch runs for everyCopyBufferoutcome other than path 1/3 and never looks atoutcome.reason. For a host-only destination the GPU can't read or write it, butCopyBufferalso refuses withLabel(PendingLabelIncoverslabels, wide labels andqueuedLabels) andDestinationUnsettled(VulkanDevice.cpp:1670-1677): CPU stores that are still pending over the destination. The drain let them land before the CPU copy; now they can land after it and overwrite the copied bytes. Please either keep the drain when the reason isLabel/DestinationUnsettled/DestinationPending/Reader/Shadow, or show that none of them can happen with a non-registered destination.SyncThroughthere is wasted work. Restricting it to path 2/8 would keep it to the case the PR describes.Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-10T04:23:47Z.
Windows run of this PR alone on current
main. Head9653aa91merged ontoc72d5ce1(clean, no conflict with the files the overlap bot lists); Windows 11 10.0.26200, RTX 4090 (NVIDIA 616.92, subgroup 32), MinGW-w64 GCC 15.2.0 r7, Release,BUILD_TESTING=ON.video_out_flip_lifetime,video_out_flip_controls,guest_video_out_wqhd_detection_no_vulkan), identical tomainon this machine.SDL_DIRECTINPUT_ENABLED=0was set for the run because of #1042.No title was run. Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-10T08:10:39Z.
Thanks. Rebased onto current
mainand reworked in 481c27bd:CopyBufferwithcpuMax = 0, sorefusal()stops at its first test andoutcome.reasonis alwaysSizehere; checking the reason would not have guarded anything. The branch now asks the device directly: newVulkanDevice::StoresPendingOver(destination, bytes)is true for a recorded write, a label (recorded or queued,PendingLabelIn), a copied write-back (CopiedWriterOverlaps), a storage image's pending write-back or a unit shadow over the destination. Any of those keeps the drain.outcome.path == 2. Path 8 can't occur from this call (gpuMaxisSIZE_MAX), and path 0 can't either withcpuMax = 0.testCopyIntoHostMemoryinagc_driver_tests(Submit.cpp): a 128 KiB DMA_DATA writes a registered buffer on the GPU (path 1), then a 128 KiB DMA_DATA copies it into unregistered host memory (path 2). It runs twice, the second time with a WRITE_DATA label into the destination between the two copies. It checks the final bytes and thatcopiesToHostMemorycounted the copy (no drain).One caveat on the test: I couldn't make it fail on the unguarded version, because no reachable state leaves a store pending over a destination without an import when
CopyBufferreturns path 2:WriteLabelOnGpureturns 3 (not imported) while anything is recorded, so the label packet drains, and the label case above lands before the copy that way.MarkGpuWrites→NotePendingWrites).CopyBufferwaits for it (waitDestination→SyncThrough) before it reaches the import lookup that returns path 2.CopyBufferalso flushes storage images over the destination (FlushPending(destination, …)) before that lookup.So the guard is defensive. It costs a few range lookups, and it keeps the branch correct if either of those paths changes. The test pins the ordering for both cases you named. It also turned out the CPU copy's own read of the source would see the GPU result even without the explicit
SyncThrough(the guest-memory read path syncs pending writes), so the test checks the outcome, not that particular wait.ctest: 638/638 on RADV (RX 9070 XT), andagc_driver_tests(not registered in ctest) passes. Not re-run on the title.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T09:27:49Z.
Review: CHANGES_REQUESTED
Thanks for the rework; the
StoresPendingOverguard and the path 2 restriction address the earlier points. Two things left:core/libs/prx/libSceAgcDriver/tests/Submit.cpp:445-471:testCopyIntoHostMemorylives inagc_driver_tests, which isEXCLUDE_FROM_ALLand not registered in ctest (core/libs/prx/libSceAgcDriver/CMakeLists.txt:267), so it never runs in CI. New tests must be registered in ctest. Please put it in a target that is (e.g. one of theagc_driver_*_testsexecution targets that useVulkanTestDevice), with a skip (exit 77) when there is no Vulkan device.main:VulkanDevice.hpp/VulkanDevice.cppnext to the newRecordedWritesSettled. I rebased it locally by keeping both functions; the scoped libSceAgcDriver ctest (319 tests) andagc_driver_testspass on the result.Once the test is registered and the branch is rebased this is good to merge.
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-10T14:12:44Z.
@adriadam10 Thanks. I rebased onto
maindb343a93in14c2eca3, keeping bothRecordedWritesSettledandStoresPendingOveras you did.On the test registration:
agc_driver_testsis already in ctest. Its definition atCMakeLists.txt:282isEXCLUDE_FROM_ALL, but underif(BUILD_TESTING)the loop atCMakeLists.txt:911names it (foreach(agcTest IN ITEMS agc_shared_write_tests agc_driver_tests ...)), turnsEXCLUDE_FROM_ALLoff and callsadd_test(NAME agc_driver ...)withSKIP_RETURN_CODE 77.Submit.cpp'smainalready returnsVulkanTestSkipped(77) when there is no Vulkan device. In my build tree:testCopyIntoHostMemoryruns inside that test. If you'd still like it in its owntests/execution/target, I can move it.Full
cteston the rebased head: 698/698 (4 video-out flip tests skipped, no display), RX 9070 XT, RADV.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T14:16:04Z.
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/PacketMemory.cppL7core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cppL7Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T18:15:51Z.
On the two remaining points, checked on
14c2eca3merged onto currentmain(57f96fd2; clean merge,RecordedWritesSettledandStoresPendingOverboth present):agc_driver_testsis in theforeach(agcTest ...)list atcore/libs/prx/libSceAgcDriver/CMakeLists.txt:911, which clearsEXCLUDE_FROM_ALLand registers it asagc_driverwithSKIP_RETURN_CODE 77;ctest -Nlists it (Test #114: agc_driver) and it runs here on llvmpipe (passes, 3.2 s), sotestCopyIntoHostMemorydoes run under ctest. Whether it runs in CI is a separate matter: thelinux/windowsjobs are gated to pushes, so no library test runs on any PR.PacketMemory.cppalone reverted tomain(theVulkanDeviceand statistics changes kept),agc_driverfails witha copy into host memory drained instead of syncing its source. Restored, it passes again, and the agc driver set is green.AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:14:44Z.
Review: APPROVED
Checked on the PR merged onto current
main: scoped build + ctest of libSceAgcDriver 713/713 (agc_driverruns the new test, also repeated 10x), and the test fails to build without the change (copiesToHostMemory), so it pins the new path, including the pending-label-over-destination case. TheStoresPendingOverguard and the path 2 restriction cover the earlier review points;agc_driver_testsis registered in ctest through the loop inCMakeLists.txt:911. Merging.