fix(libSceAgc): serialize command buffer allocation per buffer #20017
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20017"
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 slopezjur on 2026-11-14T11:57:32Z.
What
Agc::Command::Allocatereadcursor_up, reserved space and advanced the cursor with no synchronization. Ghost of Yōtei's main thread and one of its job workers append packets to the same compute command buffer at the same time, so both threads could get the same range and overwrite each other's packets. The driver then rejected the submission (aDISPATCH_DIRECTheader where the previous dispatch's group counts belong) and the title terminated at about frame 470.Allocatenow serializesReserveand the cursor advance per buffer. The state is 64 mutexes striped by theCommandBufferaddress, so no state is added to the guest-visibleCommandBufferstruct.2fc3b2c44a, after a review note from @Celegans12 in #675: two buffers can share a stripe, so a callback waiting for a thread that appends to another buffer on the same stripe would deadlock). Instead the buffer is marked as growing: other threads appending to that buffer wait until the callback returns, the callback's own thread can still append to it, and other buffers on the stripe are not blocked.Allocatereturns, outside the lock, into ranges no other thread can be given.agc_concurrent_allocation, three cases. Eight threads append 20,000 NOPs each to one buffer, each thread with its own NOP size; it checks that the cursor ends exactly at the total size, that every packet has an intact NOP header and zero payload, and that each thread's packet count is complete. A buffer whose callback waits for another thread to append to 256 other buffers must not block those appends. An append to a buffer whose callback is running waits for it, lands in the grown storage and does not call the callback a second time; the callback itself appends to the buffer.Tested
The branch was rebased onto
main4aa2f8b694after the runs below (4d15524ac3was 38f7e5c8da,2fc3b2c44awas cc8992ea95); the code is unchanged and the runs were not repeated on the new base.Windows 11, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4080 SUPER (driver 621.14), Vulkan SDK 1.4.363.0 validation layer.
agc_concurrent_allocationagainstmain'sPacket.cpp(test only, without the lock): fails 3 of 3 runs (concurrent allocations lost cursor advances).agc_concurrent_allocationon this branch (2fc3b2c44a): passes 5 of 5 runs. With the first commit's lock (stripe mutex held across the callback) the second case fails:appends to other buffers waited for a buffer that was growing.main2cebbe43eeand on this branch, same machine, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer(ctest -R <pattern> -V):agc_initialization,agc_commands,agc_rewind_patch,agc_static_buffer,agc_nop_and_compute_event, plus the draw write range, write-tracking, snapshot, BDA, GDS and shader disk cache tests.VUID-main2fc3b2c44a)Ghost of Yōtei
PPSA26344 v02.002.000, DRS 1080p patch, same save restored before every run, runs alternated between the two builds, each capped at 400 s:
unsupported PM4 packet typeabortsmain2cebbe43ee0x00000008and0x40010000, payload dwords read as headers)The game runs in this section were made with the first commit (
4d15524ac3) and have not been repeated with2fc3b2c44a.Over all 21 runs with this PR (including runs with two other changes measured on top of it, 150–400 s each) there was no PM4 abort. Three of them still stopped: twice an access violation in title code during the load (48 s;
mainhits it too), and oncesceAgcAcbPopMarker: invalid command buffer cursorsat 35 s. Inside libSceAgc onlyAllocatemovescursor_up, so the cursors were changed by the title's own code while another thread appended; this lock cannot cover that, and I have no general fix for it yet.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 MarcZX10 on 2026-11-14T12:40:51Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; I reviewed all three changed files, and no verified blocking defect was found.
What I ran
Reviewed head
38f7e5c8da2a31e0fde7a27187472debeacc1d76usingrepo_read.pyto inspect the prepared diff and source. No test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. The reported Windows and console results were not independently verified.
review/files.jsonwas not available through the reader; the manifest lists three changed files, all included and read. Excluded files were not listed in the available bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T19:20:11Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected allocator and callback paths support the per-buffer serialization described in the PR.
What I ran
cc8992ea952d945181a570212dc0d04f6d26dfee, plus targeted packet writer and caller context throughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgc/CMakeLists.txt,core/libs/prx/libSceAgc/Command/src/Packet.cpp,core/libs/prx/libSceAgc/tests/ConcurrentAllocation.cpp; targeted context:core/libs/prx/libSceAgc/Cb/src/Sync.cpp,core/libs/prx/libSceAgc/Command/src/Memory.cpp,core/libs/prx/libSceAgc/Acb/src/Control.cpp.files.jsonwas not available as a review document.To get this to a good state
Nothing is required.