fix(agc): own resolved dispatch state through thread exit #3661
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3661"
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 Celegans12 on 2026-10-11T15:01:37Z.
What
A queue worker can access freed TLS storage while destroying its resolved-dispatch map on Windows. I traced a shutdown access violation from a draw-cache test to that map's destructor in MinGW's TLS callback. The test still returned zero and CTest reported a pass.
The map now uses the existing
ThreadOwnedhelper: a trivial TLS pointer refers to a heap-owned map destroyed by its pthread-key callback. This applies the ownership rule from #590 to the map introduced by #1864. Dispatch lookup and clearing stay unchanged.Both draw-cache test modes now fail on
FATAL:output, including a background crash followed by exit zero. #3528's shader-ABI shutdown handling and #1202's draw-pipeline work leave this map unchanged.The observed failure is intermittent; no deterministic RED is claimed. The separate stackless heap-corruption failure is not proven to have the same cause, and finite passing runs do not prove universal absence of the fault.
Tested
maina11c8f7f. Windows 11/NVIDIA and Linux/llvmpipe: Release-DBUILD_TESTING=ON, builds, libs and registration pass.guest_kernel_sys,windows_exceptions,guest_filesystem,agc_driver_emulated_color_compare. All match exact main1e8fff68, whose core matchesa11c8f7f.agc_driver_emulated_color_comparematches1e8fff68;agc_driver_depth_compare_copyfails unchanged write-watch admission.agc_driver_image_plane_address_on_line_implicit_lodandguest_kernel_stack_protectonly have historical0f863c10signature matches, not exact-current-main controls.agc_write_tracking(exit 1).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T15:22:57Z.
The fix is the right shape, and I checked whether it is complete rather than partial — it is.
The interesting part is not the map itself but that the same file holds five more
thread_locals, so this could easily have been a partial fix. It isn't:GroupCaptureStats(Driver.hpp:226-230) isuint64_t/double/time_pointmembers, andcurrentPacketOffset,resolvingAheadandgateOpenedare scalars — all trivially destructible, so the compiler's TLS callback for them has nothing to do at teardown and they never had this problem. Thestd::mapwas the only object in this file — and in the rest of theDispatch/directory, whereDispatchTiming.cpp'sPendingDispatchPhasesis likewise trivially destructible — whose destructor the late callback could run against freed storage, and it is the one this changes.ThreadOwneddoes what the description says it does:ThreadOwned.hppkeeps apthread_key_twhose destructor walks a per-threadvector<Owned>in reverse and destroys each entry, so the map is released by pthread's thread-exit path instead of the compiler's TLS callback, and the TLS object itself is now a bare pointer with a trivial destructor.The
FAIL_REGULAR_EXPRESSION "FATAL:"line is the part I would not drop in review. A background access violation whose process still exits zero is invisible to CTest — the suite reports a pass while a thread died badly — so adding the fatal-output guard turns a silent pass into a failure for both draw-cache modes. That is worth as much as the fix itself, because it is what makes the next occurrence visible, and it is the same reasoning that makes the honest "no deterministic RED is claimed" line credible. (The one caveat: the guard only bites if the crash's text reaches the output CTest captures, and a hard fault mid-buffer can lose it — so it makes the next occurrence visible more reliably rather than guaranteeing it.)The ordering question is settled by this repo's own #590, not open. That PR describes exactly this hazard: with MinGW GCC,
thread_localis emutls, and thread exit happens in two steps in the wrong order — winpthread's key destructors, including libgcc's emutls one, free the thread's TLS blocks first, and the CRT'stls_callback→run_dtor_listthen runs the C++thread_localdestructors on those already freed blocks.ThreadOwnedremoves that dependency rather than reordering it: the object is reached through a key the helper owns, so nothing reads emutls at teardown, and the window is closed rather than narrowed. That makes theFATAL:guard defence in depth for the next occurrence rather than a required companion to this fix.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T16:16:52Z.
Independent Windows validation of unchanged head
09894076against exact maina11c8f7f(AI-assisted).Release, GCC 15.2/MinGW, Ryzen 9 9950X3D, RTX 5080; bundled dependencies, SPIRV-Tools OFF. Fresh full build,
libs, registration and conventions passed. CTest used--timeout 30, full suites-j4; Vulkan required and shader cache disabled. No test reached 30 s.FATAL:fixture on peer/restored peer; main accepts it. This checks the CTest guard, not the original native shutdown fault.ThreadOwnedhelper probe: 2,560 native thread lifetimes destroyed their owned maps; omitting ownership was detected in five controls. This is a helper check, not a resolved-dispatch fault reproducer.guest_kernel_sys,windows_exceptions,guest_filesystem,agc_driver_emulated_color_compare.The three extra peer failures reported
0xc0000374. Repeated serial controls also reproduced that signature on main foragc_driver_prepared_shaders_debugandagc_driver_prepared_shaders_deferred_undecodable, and on restored peer.agc_driver_compute_user_data_calls_registeredsubsequently passed 20 repetitions on each. These results do not establish a regression caused by this PR; they also do not show that all heap faults are fixed.I did not independently reproduce or capture a stack for the specific TLS callback access violation. Linux and game startup were not run for this validation. The focused tests and output guard pass, with the full-suite failures and causal limitation above.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:33:38Z.
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/Dispatch/DispatchAhead.cppL13-14