fix(libSceAgcDriver): mask WAIT_REG_MEM addresses and elide non-overlapping pipeline drains #6660
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6660"
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 al3w0f205 on 2026-10-16T02:57:35Z.
What
This pull request resolves a critical abort and removes heavy pipeline drains during WAIT_REG_MEM command processing in libSceAgcDriver:
Tested
Checklist
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T03:24:16Z.
Could you add focused regression cases for the two behaviors changed here? I don't see test files in this PR's diff. In particular, a PM4 case for misaligned 32-bit and 64-bit WAIT_REG_MEM addresses would verify the correct low bits are masked consistently through validation, decoding, and execution. A queue test could also verify that an already-satisfied wait on a non-overlapping range avoids the pipeline drain, while an overlapping pending write still takes the drain/wait path. The Overcooked run is useful evidence for the reported 32-bit abort, but does not cover the 64-bit form or the drain-elision branch.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T03:30:47Z.
Review: COMMENTED
The new masking uses two different alignments for one packet shape:
WAIT_REG_MEM_64(0x93) with a zero high mask dword (packet[7] == 0).WaitMemory.cppand thePacketExecution.cppgate mask withawaitedBytes == 8 ? ~7 : ~3.WaitAwaitedBytesreturns 4 for that packet, so they keep the address 4-aligned.Pm4.cppWaitSatisfied,WaitSatisfiedUncheckedandDecodeWaitmask withwide ? ~7 : ~3, so they use 8 bytes for the same packet.When the address is 4 mod 8,
waitMemorychecks the range, looks up labels and reports timeouts atA. Its satisfaction checks (WaitSatisfiedUnchecked, lines 137 and 334 on the head) read the qword atA - 4. With the high mask dword 0, that compares the dword atA - 4, not the dword atA. Before this PR,Validaterejected that address, so this combination could not happen.I compiled a standalone copy of the head's expressions (
WaitAwaitedBytes,waitCompares,WaitSatisfiedUncheckedand theWaitMemory.cppmask) with Apple clang,-std=c++20, on arm64. Packet: 0x93, compare==, reference 1, mask0x00000000ffffffff, address at offset 4 of an 8-aligned buffer.So a title that writes the label at the packet's address keeps waiting, and a write to the neighbouring dword releases the wait. One mask in both places would remove the mismatch: either
wideinWaitMemory.cppandPacketExecution.cpp, orWaitAwaitedBytes(packet) == 8inPm4.cpp. A PM4 case for this exact shape would also cover the "masked consistently" test requested above. Separately,LabelHistory.cpp:53still records the unmasked address for WAIT_REG_MEM. That only affects diagnostics.Static review against main
5d9dcc42d, head 97e531811. No full build and no GPU run.Written with AI assistance (Claude Code). I ran the checks above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T03:37:52Z.
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/Synchronization/WaitMemory.cppL376-377Some 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/Synchronization/WaitMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/tests/Pm4.cppcore/libs/prx/libSceAgcDriver/tests/Pm4.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/LabelHistory.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppcore/libs/prx/libSceAgcDriver/tests/Pm4.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/LabelHistory.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/Pm4.cppcore/libs/prx/libSceAgcDriver/tests/Pm4.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/tests/Pm4.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppcore/libs/prx/libSceAgcDriver/tests/Pm4.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:03:20Z.
Review: COMMENTED
The follow-up review found a concrete mismatch in the 64-bit WAIT_REG_MEM path: with a zero high mask dword, the execution/validation path treats the wait as 4-byte aligned while the PM4 satisfaction/decode path aligns it as 8-byte. For an address that is 4 mod 8, those paths inspect different dwords, so a write at the packet address may not release the wait. Could you reconcile the alignment rule across these three files and add a focused PM4 regression for opcode 0x93 with packet[7] == 0 and an address 4 mod 8? The separate queue drain-elision coverage I asked about earlier remains useful too.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:03:33Z.
Review: COMMENTED
I found one concrete mismatch in the 64-bit WAIT_REG_MEM path: with a zero high mask dword, execution/validation treats the wait as 4-byte aligned while PM4 satisfaction/decode aligns it as 8-byte. For an address that is 4 mod 8, those paths inspect different dwords, so a write at the packet address may not release the wait. Please reconcile the alignment rule across these files and add a focused regression for opcode 0x93 with packet[7] == 0 and an address 4 mod 8. The queue drain-elision coverage from my earlier comment remains useful too.
Imported from boykopovar/AnyPS5. Originally posted by al3w0f205 on 2026-10-16T04:18:27Z.
Added focused regression test coverage in
core/libs/prx/libSceAgcDriver/tests/Pm4.cpp:WAIT_REG_MEM, masking to& ~3ull) and 64-bit (WAIT_REG_MEM_64, masking to& ~7ull) addresses across all low-bit offset variations, verifying consistency acrossValidate,DecodeWait,WaitSatisfied, andWaitSatisfiedUnchecked.wide ? ~7ull : ~3ullacrossWaitMemory.cpp,PacketExecution.cpp, andLabelHistory.cpp, resolving the alignment mismatch on 64-bit waits with zero high mask dword and covering that shape in the test.All checks passed in
agc_driver_pm4_tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:20:30Z.
Thanks for adding the focused cases. I checked the updated diff: the 64-bit opcode now uses 8-byte address masking consistently in validation/execution, decoding and satisfaction checks, including the zero-high-mask case; the queue test also exercises both non-overlap elision and overlap draining. This addresses the gaps I raised. I have not run the full PR build.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T04:36:04Z.
Review: COMMENTED
Re-checked at head
6ab4e09fdagainst my earlier note on97e531811. The mask is nowwide ? ~7 : ~3in all three places, so the mismatch I reported is gone. I also ran the tests, and the new zero-high-mask case does not catch that mismatch.main5d9dcc42d.agc_driver_pm4_testsdoes not need a GPU. I ran it with no Vulkan driver available (VK_DRIVER_FILESpointing to a missing file). Understraceit opens nolibvulkan,/dev/nvidia*or/dev/drifile, and it passes.Results:
6ab4e09fd:agc_driver_pm4,agc_driver_pm4_failureandagc_driver_pm4_failure_inlinepass.mainwith only the newtests/Pm4.cpp: fails withmisaligned WAIT_REG_MEM address, as expected.97e531811with the newtests/Pm4.cpp: passes.testWaitRegMemMasking, zero-high-mask case included, only callsPm4::Validate,DecodeWait,WaitSatisfiedandWaitSatisfiedUnchecked. Those helpers already masked withwide ? ~7 : ~3at97e531811. The mismatch was inWaitMemory.cppand thePacketExecution.cppelision gate, and no new case submits a 0x93 packet withpacket[7] == 0at an address that is 4 mod 8. So the test would not catch a regression back toawaitedBytes == 8 ? ~7 : ~3there.This submission-level case does catch it. It uses the same pattern as
testWaitRegMemPipelineDrain: a pending pipeline item covers the dword the wait compares, and the wait must not skip the drain.I called it after
testWaitRegMemPipelineDrain()and ran it 3 times on each head:6ab4e09fd97e531811[A, A+4)for overlap, finds none, and then opens on the qword atA-4, whose low dword is the one with the pending writeFeel free to take it as is if it's useful.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-17T06:53:09Z.
Besiege (PPSA20313), Windows, RTX 4070 SUPER, Ancient Grounds sandbox (about 1000 draws per frame), head ffeae6826 on top of current main plus open perf PRs: 22.3 -> 24.4 FPS with this PR, pipeline drains per 10 s 11,000 -> 1,700. A 10 minute run in the level had no errors and the frame looks the same.
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-17T14:11:34Z.
Correction to my earlier numbers here: stacked with #6082 this change shows stale frames in Besiege (PPSA20313, Windows, RTX 4070 SUPER). In the cube-selection menu with the window unfocused the full-screen background is occasionally drawn with a diagonal split (one triangle stale). The cause is the new branch in Driver::execute that skips a wait satisfied at entry (
!Queue0().Overlaps(...) && Pm4::WaitSatisfiedUnchecked(packet)): waitMemory bumps the collect epoch at entry even when the wait is already satisfied, and #6082's UnwrittenDrawSnapshot reuse relies on that bump to notice a CPU write to a small buffer. AddingbumpEpoch(&EpochBumps::waits);before thecontinuein that branch removes it: 90 s of the menu unfocused, 5,000 captures, no changed frames (before: about 1,600 spike frames); frame rate unchanged. The same capture is also clean with APS5_PACKET_EPOCH=1 and with APS5_DRAW_UPLOAD_MAX=0.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-17T21:52:04Z.
Two titles hit the 64-bit form of this, PS5NES (PPSA99204, v1.0.0.9) and PS5N64 (PPSA99206, v.1.0.0.7). Both are converted with
--trap-sdk-syscall-stubs. Setup: Windows 11, RTX 5070 Ti (NVIDIA 617.42), WinLibs GCC 15.2.0, Release. Titles are the authors' GitHub releases, unwrapped withtools/unwrap_self.pyand converted with--windows. "main" is922dc8999. For "this PR", the PR was cherry-picked onto11acfdd84and only the PR's own.prxwas swapped into the922dc8999library set.On main. PS5NES aborts in 3 of 3 runs (17–21 s) and PS5N64 in 2 of 3 with
AGC driver: WAIT_REG_MEM_64 at DWORD 0: misaligned WAIT_REG_MEM address. The rejected packet (APS5_DUMP_REJECTED) is:That is a 64-bit equal wait on
0x2_00dfebfc, which is only 4-byte aligned, with mask0x00000000_ffffffff. It comes from the titles' PS5_Vulkan driver:ps5vk_marker_wait_wordswaits on the queue's marker, the last word of its buffer. The packet is only emitted when the previous submission hasn't finished, so it is timing dependent.With this PR (
ffeae6826). Masking to~7polls0x200dfebf8, so the value the title wrote lands in the high dword, which the mask drops:PS5NES then ends with
VideoOut: cannot unregister a buffer with a pending flipin 1 of 3 runs, and PS5N64 likewise in 1 of 3.Experiment, not proposed. Accepting a 4-byte-aligned 64-bit address and reading at the exact address let 3 of 3 runs of each title reach the 70 s limit, with no timeouts and no rejected packets. AMD PAL's
PM4_MEC_WAIT_REG_MEM64marks address bits [2:0] reserved, so what the console's CP does with this packet is the open question. For these two titles, masking to~7turns the abort into a wait on the wrong qword.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by al3w0f205 on 2026-10-18T01:01:26Z.
Updated with fixes for both reported cases and rebased onto current main:
Verified with ctest -R agc_driver_pm4 passing 100% and ools/check_conventions.py passing cleanly.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T01:56:26Z.
Re-tested head
cdedb1e87with PS5NES (PPSA99204, v1.0.0.9) and PS5N64 (PPSA99206, v.1.0.0.7), converted with--windows --trap-sdk-syscall-stubs. Before ismain0bb238b4a; after is the same build with this PR cherry-picked (clean), so both use one base. 70 s per run, 3 runs each, no input. Windows 11, RTX 5070 Ti (617.42), WinLibs GCC 15.2.0.WAIT_REG_MEM_64)_64 timed outmainmainmain.timed out ... at 0x200dfebf8no longer appears.ctest -R agc_driveron the PR build: 516 of 516 passed, 4 skipped.Not checked on Linux or on a console. These runs show the new handling matches what the titles expect. They don't measure what the CP does with a 4-byte-aligned 64-bit wait whose high mask is 0; PAL marks address bits [2:0] reserved.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T01:58:16Z.
Thanks for the exact-base title comparison. I verified the PR is still at the tested head
cdedb1e87and is clean/mergeable. The 3/3 PS5NES and PS5N64 runs on the same main base confirm the misalignedWAIT_REG_MEM_64abort is gone in those runs; the hosted build/test jobs remain skipped by path filters, so I’m treating the hardware report as the runtime evidence.Imported from boykopovar/AnyPS5. Originally posted by al3w0f205 on 2026-10-18T01:59:07Z.
Added the submission-level regression test
testWaitRegMem64ZeroHighMaskDrain()incore/libs/prx/libSceAgcDriver/tests/Pm4.cppcovering opcode 0x93 with packet[7] == 0 at 4 mod 8 against a pending pipeline write. Verified locally withctest -R agc_driver_pm4passing cleanly and conventions passing 100%.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T02:16:55Z.
That regression assertion covers the specific opcode/mask/alignment combination from the title report, and the focused PM4 test plus conventions pass on the updated head. Thanks for adding it. The earlier 3/3 PS5NES and PS5N64 comparison remains useful title evidence; both reports are now recorded on this PR.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T11:17:39Z.
The full Build failed on
agc_driver_pm4:testWaitRegMemPipelineDrainassertedQueue0().Outstanding() == 0right afterAgcDriverWaitIdle, but with the drain elidedWaitIdleno longer waits for queue 0, so the check raced with the draw pipeline finishing. I pushed two test-only commits that poll the draw pipeline to idle (bounded at 5 s) before both assertions, rebased on main, and reran the AgcDriver/Agc tests plus a repeat run for flakes; all green. Logic unchanged; merged.