fix(agc): read a released REWIND tail before replay restores later memory #17642
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17642"
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 chitters2004 on 2026-11-09T06:22:55Z.
What
A queue copies a REWIND tail, and every indirect buffer the tail calls, only when it reaches the tail.
agc_frame_replayreleased a tail and went straight on to the next memory delta. That delta could overwrite the indirect buffer the tail still pointed at, so the queue read the newer bytes with the older length. On a GTA V capture the result wastruncated PM4 packet: a 4-dword indirect buffer whose memory a later delta had refilled with an 8-dword packet. The drain then waited 10 minutes on a worker that had already failed.Submitor when a copied tail chains another, and removed whenexecuteRewindTailcopies it. A copy removes one record of its queue and address, so when one REWIND buffer is submitted twice, the second submission's record stays until it copies the tail too. The list is cleared on a driver failure.AgcDriverRewindTailsUnread_nid_postfixreports a released tail that is still unread, unless its queue is parked on a wait that only the title can satisfy and that is not satisfied yet. The comparison is shared with the PM4 wait throughPm4::WaitCompares.--strict.AgcDriverCheckFailure_nid_postfix, so a driver failure ends the replay instead of hanging it.Related: #15136 changes how the capture reads deltas; this change is on the replay side and does not overlap it in behaviour.
Tested
This head
95e6f02b70isf5d6a66a0aplus two commits:2d35c8804b: copying a tail removed every record with its address, so after the first of two submissions of one REWIND buffer copied the tail, the replay counted the second submission's copy as read.agc_driver_frame_replay_rewind_shared_tailsubmits the buffer twice, releases it and holds the first copy's flip inWaitForFlipRoom; it fails onf5d6a66a0a("the second submission's unread copy of the same tail was forgotten") and passes 5 of 5 with the change.95e6f02b70(test only):awaitTailsReadruns inside the replay's settled hold, where a worker leaving a wait cannot move. It returns at once there because the driver does not settle while a released tail is unread: the stalled serial completes afterexecute(tail), andparkedOnTitlere-reads the control.agc_driver_frame_replay_rewind_settled_tailreleases a parked REWIND inside a hold and requires the driver not to report settled, then requires the next hold to find the tail read. A REWIND park counted as parked whatever its control holds fails it.Linux (Ubuntu 24.04, lavapipe, Mesa llvmpipe LLVM 20.1.2) on
95e6f02b70:ctest -R agc_driver_frame_replay: 47 of 47 pass.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerwith layer 1.4.363.1 andVK_KHRONOS_VALIDATION_VALIDATE_SYNC=1,ctest -R '^agc_driver_frame_replay(_rewind.*|_busy_queue)?$' -V: 13 of 13 pass, 31Insert instance layer "VK_LAYER_KHRONOS_validation"lines, no missing-layer line, 0VUID-and 0SYNC-HAZARDlines. No sync canary ran, so this is not a synchronization-validation claim.Windows 11, RTX 3080, driver 621.24, on
95e6f02b70, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer. Each of these exits 0:ctest --test-dir build -R "^agc_driver_frame_replay" -Vagc_driver_frame_replay_rewind_reusewith--repeat until-fail:20VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1 ctest -V -R '^agc_driver_frame_replay(_rewind.*|_busy_queue)?$': the rewind and busy-queue frame_replay tests with synchronization validation on. No sync canary ran, so this is not a synchronization-validation claim.Across the 28 replay logs, 0 lines contain
VUID-.Earlier, on
0363616cf8(Windows 11 26220, RTX 3080, driver 621.01,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "^agc_driver_frame_replay" -V),mainwith the newagc_driver_frame_replay_rewind_reusetest passed 33 of 34: the new test fails on its first run withthe replay did not run the REWIND tail as captured. With this change it passes. The test and its registration are unchanged between0363616cf8and95e6f02b70.A GTA V (PPSA04264) prologue capture recorded before calls format 2, replayed with the version check relaxed locally, using
--repeat 5 --no-pace,APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1.The replay needs #17338: without it, it stops at
guest writes over native multisample depth are not implemented. So it ran on95e6f02b70merged with #17338's head025f5a150e, built with #20845 for an upright picture onmainafter #16053.Before this change, 7 runs logged
truncated PM4 packet, and the drain then hung onblocked on nothing. With it, all 5 runs exit 0 and replay all 5 passes:pixels_identical1.000000, maximum channel difference 0);VUID-lines;truncated PM4 packet, unread-tail orblocked on nothingline.Replay time: 29.4 s on the cold first run, then 16.2 to 19.6 s.
A second GTA V capture (rk4),
--repeat 5 --no-pace, same pipeline environment, same RTX 3080, 5 runs per build. Without this change (main7085a08145awith #17338, without #20845), all 5 runs stop withtruncated PM4 packet. With it (95e6f02b70merged with #17338's head025f5a150e, plus #20845), all 5 runs exit 0 withpixels_identical1.000000 and maximum channel difference 0. Every frame of every run is identical to the captured one.Merging with #17338:
restoreGrouptakes #17338's REWIND candidate loop unchanged. It holds every candidate control word out of the bulk copy and writes it afterwards with a release store; on a repeated restore it writes only the clear words. That covers this PR's kept words, including those whose valid bit is clear, so this PR's own loop over them is dropped. Intests/cmake/agc_driver_frame_replay_tests.cmake, the conflict cuts this PR'srewind_shared_tail/rewind_settled_tailforeach before itsif(WIN32)PATH block andendforeach(), which sit in the shared lines after the conflict. Both foreach blocks keep their ownif(WIN32)block.Unread REWIND tails are recorded only after
agc_frame_replaycallsAgcDriverTrackRewindTails_nid_postfixat start-up, so title runs pay one relaxed atomic load per tail instead oftailsMutex.python3 tools/check_conventions.py --base origin/mainpasses.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 milescoviello on 2026-11-09T11:54:11Z.
Review: APPROVED
Linux check, to go with your Windows runs. On this host the new test also catches the bug on
main.Setup: Ubuntu 26.04.1, RTX 4070 Ti, NVIDIA 615.71.09, GCC 15.2, Release.
ctest -R '^agc_driver_frame_replay', 3 runs per build:a55d18f626tests/FrameReplay.cppand its cmake (70f3d12ded)agc_driver_frame_replay_rewind_reusefails in 2 of 3 runs withFAILED: the replay did not run the REWIND tail as captured; the other 33 pass9bd5d256f5With
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.341,VK_LOADER_DEBUG=layer),ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1,ctest -V, re-run on the current head939088a0d4against its merge base4b71464421:VUID-lines on either side;^agc_driver_frame_replayset has grown withmainsince the table above. The loader inserted the layer 34 and 36 times, once per Vulkan device created, so the layer had work.The failure on base is intermittent (1 of 3 runs passed), which fits a race between the queue's tail copy and the next delta.
From reading:
SubmitEndpath (PacketExecution.cpp:620-628) and the non-pipelined end of the same function (:650-652), go throughexecuteRewindTail. So every tail added atSubmitis removed when its copy runs.awaitsTitleis a global quiescence check (no running workers, no order holders, no pending completions, no recorder write over the address). So the parked chain reads as waiting on the title, andRewindTailsUnreadreturns false.drain()try/catch plusAgcDriverCheckFailure_nid_postfixin its loop surface the failure throughfailure.One small cost note, not a blocker:
noteTailReadtakestailsMutexon everySubmitwith a REWIND tail and everyexecuteRewindTail, in title runs too, while onlyagc_frame_replayreads the list. If a title with many tails shows it, the list could be kept only while a replay is attached.Edited 11-09: the validation numbers above come from a re-run with layer 1.4.341, where
VK_LOADER_DEBUG=layershows the loader inserting it in every test. The 1.4.363 layer my first run pointed at wasn't installed, and these test programs don't print the loader's "not found" error, so that run validated nothing (#17896).AI-assisted: yes (Claude Code)