feat(agc): capture submissions and replay their decode and wait releases offline #4969
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4969"
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 fdfawef324 on 2026-10-13T06:51:18Z.
What
A hang with threads in
Driver::waitMemorytakes a ten-minute boot to reproduce, and the existing switches show only the first submissions of one queue (APS5_DUMP_QUEUE) or a rejected one (APS5_DUMP_REJECTED). This adds a capture of every submission and an offline tool that sorts the captured waits into three groups: those the capture proves released, those no captured store can release, and those it cannot decide.Capture.
APS5_DUMP_SUBMITS=<dir>writes every submission the driver accepts.<dir>/index.txtstarts withaps5-submissions 1and the column lineordinal queue type serial time_us dwords kind file held conditional, then one line per submission.heldlists the dword offsets of the waits whose value passed their compare at submit (Submission::heldAtSubmit, which the driver then does not wait for).conditionallists the COND_EXEC and predicated indirect buffer ranges asstart:end(fromSubmission::conditionalEnds).submission_<ordinal>.binholds the copied dwords with indirect buffers inlined. REWIND tails and suspend points are listed too.SubmissionCapture::Preparecopies the commands before the driver lock. Under the lock,Takesets only the ordinal, the time and the held waits, afterreserveOutputs, and does not allocate (it isnoexcept). The file and then its index line are written after the lock is released. A failed write reports the error to the driver (Driver::ReportFailure) and throws: the call that made the submission throws after the submission was queued, and every later driver call throws the same error. When the switch is unset,Submitonly tests a static pointer.An index written by an earlier build, whose column line is
ordinal queue type serial time_us dwords kind file, is still read. Its held waits and conditional ranges are unknown (CapturedSubmission::heldKnown,conditionalKnown), and the report says so.Analysis.
agc_pm4_replay <dir> [--full]decodes each submission and throws if the driver would reject a packet, since that means the capture is corrupt.The tool does not model cross-queue timing. A store of another queue can run before, between or after the stores of the waiting queue, whatever order the submissions entered the driver in, so the tool never uses submit order across queues.
Each WAIT_REG_MEM, WAIT_REG_MEM_64 and REWIND gets one of three outcomes.
KeepsLabelStore: 4-byte aligned, at most 64 bytes; not conditional). Fewer thanLabelStoreHistory(4) other stores to the awaited bytes may run between the label and the wait.storedSince(LabelHistory.cpp:21) finds a store only if its stamp is above the waiting submission'sreceived. The capture proves that only for a store in the same submission.noteLabelStore(LabelHistory.cpp:9-19) keeps one history per dword, shared by all queues. So the count includes the stores between the label and the wait on the waiting queue, plus every store of another queue to those bytes, whatever its submit order.unreleased by the GPU; a CPU store could release it.unknown: depends on cross-queue timing (stores on queue 0x20 at #377, #427, #477; ...)when another queue stores to the awaited bytes and no route above holds. For each queue, the list gives the 4 stores nearest the waiting submission in submit order and how many more there are.The outcomes depend only on the order of each queue's own stores and on which stores the other queues make. They never depend on the submit order across queues.
This revision removes the fixed-point machinery of the previous one (two sets of waits grown and alternated, store run states). Each wait is now matched once, against the stores to its bytes.
The report counts waits per outcome and route, and the unknown waits that depend on cross-queue timing. It says when the index lacks the held and conditional columns. It lists up to 32 unreleased and then unknown waits, newest first, each with the packets around it and the stores to the awaited bytes. It ends with the last two submissions of each queue. The exit code is 1 when a wait is unreleased and 2 on errors.
Shared decode. The store and wait fields come from new
Pm4helpers:DecodeStores,DecodeWait,DecodeConditionalWrite,DecodeConstantRamDump,CopyDataSource/CopyDataImmediate/CopyDataBytes/CopyDataToRegister,DmaBytesand the DMA select constants,SampleDump/SampleDumpAddressand the sample-dump layout constants, andRewindValid.Pm4::Execute,ResolveStore,Validate,DecodeMemoryCopy,PacketMemory/PacketExecution(sample dump),VulkanDevice::DumpSamplesOnGpu,noteHeldAtSubmitandexecuteRewindTailnow use them in place of their own copies.LabelStoreHistoryandKeepsLabelStoremoved toDriver/Synchronization/LabelStores.hpp, andnoteLabelStoreusesKeepsLabelStore. There is no EVENT_WRITE_EOP decoding:Validaterejects opcode 0x47.Tests.
agc_driver_pm4_replaybuilds command buffers with the libSceAgc builders and submits them through the driver with the switch set. It checks:It then checks hand-made captures:
every capture from the reviews, with its exact dwords:
deadlock,stale,stale-held,evict3,evict4andevict-own4. No wait may be released, except the compute wait ofstale-held, which is held at submit. Every other wait must beunknown: depends on cross-queue timing (stores on queue ..., and the report must exit with 0.each provable route:
the limits of those routes:
unreleased: a store later on the waiting queue, a value of another queue the compare rejects, and a REWIND without a tail, reported newest first.
permutations: five groups of waits, each on its own queues and addresses, written in eight submission orders: in sequence, reversed, round robin both ways and four pseudo-random interleavings. The groups are:
stalepattern;All 13 waits must get the same verdict, route and cross-queue flag in every order.
an index without the held and conditional columns.
corrupt captures: EVENT_WRITE_EOP, a held offset that is no wait, and a range that starts at no COND_EXEC.
Last, a directory in place of the next submission file makes the capture write fail. The submit throws
cannot write, the next submit throws the same error, the index gets no line for it, and shutdown throws the error too.agc_driver_pm4_replay_tool(tests/Pm4ReplayTool.cmake) runs the tool on the driver capture. It checks:--full;Tested
Windows Server 2025, RTX 3060, GCC 15.2 (winlibs), build-dev configuration, rebased on
mainatea2bbefb2.agc_driver_pm4_replayandagc_driver_pm4_replay_toolpass.agc_driver_pm4_replayfail:the reviewer capture evict-own4 reports the wait at #0 +12 as 0 route 3;a store of 1 in an earlier submission, overwritten by a store of 0, does not leave the wait unknown.deadlock,stale,evict3,evict4,evict-own4:released 0,unknown 2 (cross-queue timing 2),unreleased 0.stale-held:released 1 (... held at submit 1 ...),unknown 1 (cross-queue timing 1).ctest -R "^agc" -j 4, with every test executable built: 462 tests, 461 pass andagc_driver_stencil_ref_exportskips. The tests listed as failing onmainon this machine (agc_driver_flat_loads*,agc_driver_global_loads*,agc_driver_flat_apertures_2,_5,agc_driver_pixel_interlock) pass on this base.diff -r). An earlier build wrote both without theheldandconditionalcolumns, so no wait can be unreleased: a wait that would be is unknown instead. I did not convert them, because writing-would claim that no wait was held.capture2: 488 index lines (469 submissions with commands, 19 suspend points), 293,334 dwords, 60,433 packets, 6,978 stores.capture3: 513 index lines (493 submissions with commands, 20 suspend points), 308,366 dwords, 63,535 packets, 7,337 stores.capture2#75+0x005egraphicsWAIT_REG_MEM [0x242dff7e0] == 0x1was released by current value and is now released by the label history:WRITE_DATA 1at #75+0x0054, with 3 compute stores to the address in the whole capture. Because compute stores to that address, the current value no longer proves the release.capture2waits on the same label are unknown by cross-queue timing:+0x0141and+0x038eof #380, #430 and #480. In each, the last graphics store before the wait (#75) stores 1, and so do the 3 compute stores (#377, #427, #477). The waits would pass whichever store ran last, but proving that needs a route over the stores of other queues, which this revision deliberately does not have.capture20.29, 0.31 and 0.25 s;capture30.28, 0.34 and 0.34 s. These are runtimes of the new tool only. No speed change of the emulator is claimed.python -I tools/check_test_registration.py build-devand the conventions check pass.A final review found that a REWIND valid at submit was reported released although the driver reads its valid bit again when the queue reaches it; such a REWIND without a captured tail is now unknown, covered by a new case in
agc_driver_pm4_replay(a REWIND that was valid at submit without its tail), which fails with the previous rule.agc_driver_pm4_replayandagc_driver_pm4_replay_toolpass on the final commit.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:40:13Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
534451426together with six other open GPU PRs (their own commits applied, no merge conflicts), so only the tests that belong to this PR say something about it:tests/Pm4Replay.cpp, whichctestruns asagc_driver_pm4_replay: 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T15:50:45Z.
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/Pm4.cppL135-137, L152-154, L604-606, L989core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppL14Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:21:02Z.
Checked on the PR merged onto current
main: scoped build and ctest oflibSceAgcDriver(524 tests), includingagc_driver_pm4_replayandagc_driver_pm4_replay_tool(pass); the sharedPm4decode helpers keepExecute/ResolveStore/Validatebehaviour; the capture does nothing but test a static pointer whenAPS5_DUMP_SUBMITSis unset.agc_driver_tessellationandagc_recorder_kept_bytesfail here, and both fail the same way onmainwithout this PR. Windows is covered by the full Build before merging; merging once it is green.