fix(agc): shut the driver down before frame replay exits with an error #14100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14100"
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-10-31T18:58:44Z.
What
agc_frame_replaynow shuts the driver down on every exit path. It used to do so only after a successful replay.On a replay error,
maincalledstd::_Exit(code)with the driver still running. On Windows that goes throughExitProcess, which ends the worker threads and then detaches the DLLs. Detaching the prx runs the staticDriver's destructor, and itsstop()waits on workers that are already gone. The process then hangs, or aborts, instead of returning its exit code.AgcDriverShutdown_nid_postfix()before exiting, including exit code 3 (unfinished submissions).Framesnow outlives the driver. It lived onrun()'s stack while the driver keptReplayOutputs that reference it, so a failure reported duringstop()would touch dead memory. Found by reading the code; no run has triggered it.thuanquang found the hang and tested this approach on an RX 6700 XT, and savvaniss confirmed it on an RX 9070 XT, both on #12568. This PR is that fix against
main, so it doesn't have to wait for that stack.agc_driver_frame_replay_reservation_error, which #11435 adds, is the first test to reach this path with the driver running.Tested
Windows 11, RTX 3080, NVIDIA 621.01, WinLibs GCC 15.2.0 r7, Release.
The bug on
main+ #11435 (9392228b5c), with and without this PR. Direct runs ofagc_frame_replayon thereservation_errorcapture, 6 each. A run still alive after 15 s counts as hung. All 24 runs print the expectedEOP flip token is reserved for a different flip.FATAL: abort()at exit, exit code 127, about 0.95 sFATAL, about 0.64 sFATAL, about 0.63 sThe test itself passes on this machine with the layer either way, because it only checks for a non-zero exit. A hung process here is left with one thread and refuses
taskkill, which fits a process already inExitProcess.Focused tests.
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R "frame_(replay|capture)":mainca073ec3admain+ #11435Neither side logged a
VUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS, in the ctest logs or the tool's own logs. With this PR, 15 of 15 also pass without the layer, andreservation_errorpasses 5 of 5 on repeat both with and without it.Exit code 3 on
main+ #11435. A capture with a registered video output and submissions that can never finish, so a Vulkan device is alive. Drain limit lowered from 600 s to 10 s locally:FATAL, test fails, about 11 sFATAL, about 11 sFATAL, about 11 sOn
mainalone this capture starts no device, so exit 3 behaves the same either way. No test for it is added here, because with #11435's 600 s limit it would take 10 minutes per run.Final head
659a6eecb4. Onmain0836dfdf4f: 11 of 11, with and without the layer. With #114359392228b5cmerged, its test registrations carried over by hand because it conflicts withmain: 15 of 15, with and without the layer. NoVUID-lines.Linux / RADV. janzezno ran
f18a18ee45on an RX 7900 GRE: 17 of 17 three times, and the error exit took about 0.056 s. This did not cover exit code 3 or theFramescommit.Not tested: exit code 3 and the
Framescommit on AMD or Linux. A real GPU wedge can still block shutdown, because a fence wait orvkDeviceWaitIdlein~Staterelies on TDR or device loss to return.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-10-31T19:11:16Z.
Review: COMMENTED
Reviewed — code 3 path remains unverified
The new shutdown call runs after
run()returns exit code 3, but the review evidence does not exercise that path.What I ran
Reviewed head
f18a18ee4508e0e602806ea8432ea3e8f714409aagainst base16452da93473aa42d8054da95f89e44a2a1d8d97. Diff, conventions and merge-preview checks passed; the hosted Windows job passed. I did not build or run C++ tests locally.Findings
I have not approved this PR yet because the exit-code-3 path needs evidence.
FrameReplay.cppnow calls shutdown for every nonzero result, including 3. Shutdown joins driver workers and then callsDrawFinisher::Drain(); when jobs remain, that drain waits for the queue to empty with no timeout (implementation). The PR reports only a source inspection for exit code 3. Please run a controlled unfinished-submission replay through shutdown and report that it exits, or adjust the shutdown path if it can remain blocked.Not verified
The author's Windows exit-code-2 reproduction is reported in the PR description; I did not independently reproduce it. Exit code 3 and its pending draw-finisher behavior were not tested.
Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:18:38Z.
Review: COMMENTED
Audited the shutdown sequencing and Windows process exit lifecycle:
ExitProcessdeadlock resolution: The analysis ofstd::_Exit()on Windows is spot on. Win32ExitProcessterminates all secondary worker threads before running static destructors during DLL teardown. When the staticDriverdestructor subsequently invokedstop(), attempting to join worker threads that had already been killed by the OS resulted in a permanent deadlock/hang. CallingAgcDriverShutdown_nid_postfix()explicitly inmainensures the driver workers are signaled viastopping = trueand joined cleanly while still alive.try/catchblock followingrun()ensures that any exceptions during shutdown are reported tostderrrather than dropped, correctly setscode = 2if a nominally clean replay fails during teardown, and guaranteesstdout/stderrare flushed before process exit.DrawFinisher::Drain(): AuditedDrawFinisherbehavior inDrawPipeline.cpp:DrawFinisherjobs are CPU-side completion/retirement callbacks rather than GPU hardware fence waits. BecauseDriver::stop()halts and joins the driver worker threads before callingDrawFinisher::Get().Drain(), no new jobs can be enqueued while the finisher thread drains the remaining queue. Furthermore,Driver::stop()wrapsDrawFinisher::Get().Drain()intry ... catch (...), preventing any trapped callback error from wedging driver termination.python tools/check_conventions.py --base upstream/main --head HEADpasses cleanly with 0 findings.Solid fix that cleanly eliminates the hung process issue on Windows replay errors.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T21:18:54Z.
Review: APPROVED
Reviewed — looks good
At head
659a6eecb4b4c82c7f76c808f0ce3833c07fe204against base16452da93473aa42d8054da95f89e44a2a1d8d97, the requested unfinished-submission exit-code-3 path is now covered by the author's Windows RTX 3080 run (6/6 exits with code 3, with and without validation), and the hosted Windows job passes. I ran the no-build precheck, diff and conventions checks, and inspected the shutdown and frame-lifetime paths; I did not build or run tests locally. Linux/RADV evidence covers exit code 2, not exit code 3, and the reported hardware runs are author-provided rather than independently reproduced. The precheck's ABI/test-quality helpers were unavailable in its isolated checkout.