fix(agc): defer host import retirement until the GPU lock is held #4017
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4017"
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 jweidenh on 2026-10-11T21:24:33Z.
What
When a newly mapped GPU range grows or overlaps a host import, the map observer can retire the old import on its unlocked fast path. Retirement accesses shadow and recorder state that requires
GuestMemory::GpuMutex, including opening a recorder batch to retain the old Vulkan objects. This can race the worker recording, submitting or reaping work.Before replacing an overlapping import, return to the observer's existing GPU-locked retry. The overlap check and import lookup remain under the imports mutex; the fast path never acquires the GPU mutex while holding it. Fresh, disjoint and unchanged imports keep their unlocked path. The production change is 13 lines in
GuestBufferMemory.cpp.Related to #3463's identified host-import retirement path. Current
Recorder::Idle()already includes submitted batches; this change addresses the unlocked map-observer path. It does not establish that the reported Wobbly Life device loss is fixed. #3976 handles imports retained across different devices and is independent.Head
b00bd9fa11ffa30c11215d59c195a857dda3dd85also addresses the test portability feedback: the focused retirement mode returns CTest's skip code 77 when host imports are unavailable or require alignment above 64 KiB. It prints the unavailable alignment instead of failing an assertion. The supported-device regression and the production patch are unchanged.The rebase adopts blawesom’s handoff onto
main4bf963d660c8144a91340c7058e41bd26dd6e692, preserving original commit authorship. The CMake resolution retains both upstream parked-import unmap and this PR’s retirement test, including their Windows library paths. Source review confirms the production fix, retirement fixture, skip guard and map-time fixture are preserved.Tested
Windows 11 / RTX 5090 / NVIDIA 617.42, portable WinLibs GCC 15.2.0 r7, Release, SPIRV-Tools enabled and pipeline LTO disabled: all four selected tests passed without skips across the initial run and one limited continuation:
agc_host_import_retirement(0.421 s),agc_host_import_unmap(0.443 s),agc_parked_import_unmap(0.526 s), andagc_driver_host_import_at_map(2.229 s). Retirement verified all three GPU readbacks withdeferred=1andrecorder preserved=1. Validation uses exact published sourceb00bd9fa11ffa30c11215d59c195a857dda3dd85, with no source overlays. Its base includes merged #4021 directly.Both focused executables and the full
libstarget built successfully. Source pins, clean gitlinks, exact CTest inventory/environments, raw JUnit/logs, device identities, completion markers and 30-second limits are checked. The parked-import case covers upstream’s newly integrated device-replacement release path. Conventions and whitespace checks pass. Historical negative controls and synthetic capability skips were not repeated.The initial retirement and unmap launches exited before test output with
0xc0e90002; Windows CodeIntegrity events identified Smart App Control blockinglibc.prx. The later parked-import test successfully loaded the same recorder executable and unconditional library dependency. That new readiness evidence justified one retry of only the two blocked starts. Both then passed, with the same source, executable/library hashes, build configuration, controlled environment and cache paths. No rebuild, signing, relocation or security-policy change was made. The two original blocked launches and rejected verification remain preserved; the two passing controls were not rerun. This does not establish why the policy block cleared.The contributor reports a Linux/RADV Release build and 953/953 passing tests at the same handoff head in the linked comment. Those are contributor-reported results; this run does not independently reproduce or audit that full Linux suite. Our local Linux runner still lacks SDL PipeWire/PulseAudio/ALSA development dependencies, so its unchanged configuration blocker was not repeated.
Automatic upstream checks do not substitute for these focused native tests. On the preceding published head, full Linux and Windows jobs were skipped. This account has only READ access upstream and cannot dispatch its full workflow. No current full-suite result from our own infrastructure is claimed.
Historical portability validation
The following results apply to preceding published head
c7ab53b56c0debe4b547002b7af1441990fa9c50, before the current rebase.Windows 11 / RTX 5090 / NVIDIA 617.42, portable WinLibs GCC 15.2.0 r7, Release, SPIRV-Tools enabled and pipeline LTO disabled: the changed
agc_host_import_retirementtest passed in 3.471 s without skipping. All three shapes completed real GPU readback withdeferred=1andrecorder preserved=1. The recorder executable and fulllibstarget built successfully. Source pins, JUnit, complete logs, device identity and the 30-second limit were checked. Unchanged unmap/map-time controls and the historical baseline were not rerun.The supported-device source pin is
647d43ce4795b79c7e8cc252cd22bbbbe58be4fa: publishedc7ab53b56plus the reviewed Windows build fix from #4021 at121b16fb4bbd47ff4ce9302c40631bab858e3e71. OnlySocket.cppdiffers from the published head. #4021 is now merged, but that historical revision's base5aaf26bd325607f65bde28741a4e82ceaaf586c0predates it, so the historical-base Windows build still uses the identified overlay. That validation-only overlay was excluded from that published revision; the current base includes the merged guard directly.Separate validation-only source
7e2f5388d767bfe00c87097d8fa27f6a2ba8f0ceadds two CLI aliases and CTest registrations that supply local alignment values 0 and 131072 to the unchanged skip guard. They do not change the actual device or context and return before the retirement fixture. Both were classified by CTest asSKIP_RETURN_CODE=77, with the exact alignment-specific reason and no retirement readback/completion marker: alignment 0 in 0.476 s, alignment 131072 in 1.282 s. These are synthetic capability-path checks, not two passing GPU regressions or evidence from actual unsupported devices; they are excluded from the published branch.Conventions and whitespace checks pass for
c7ab53b56. On the preceding head, upstream's full Linux and Windows workflow jobs were SKIPPED; green automatic checks do not establish that the AGC retirement regression ran. This account has only READ access upstream and cannot dispatch its full workflow. No upstream full-scope pass is claimed.Historical validation
At preceding head
f405af80e7ed31ecb3e2abe27d060028ac58dee0, based on5aaf26bd325607f65bde28741a4e82ceaaf586c0, Windows 11 / RTX 5090 / NVIDIA 617.42 passed all three selected checks without skips: retirement (0.598 s), map-time imports (2.412 s), and host-import unmap lifetime (0.207 s). The retirement fixture completed all three GPU readbacks. Release executables and patched libraries were rebuilt with WinLibs GCC 15.2.0 r7 and SPIRV-Tools. Actual sourcee16b25e05dcdae1c943396c8e5f125bbf7de3085added only the same #4021Socket.cppoverlay. These results predate the skip fix and do not test its unsupported-capability paths.That run's initial verifier rejected two passing cases because it expected one device banner. A source-reviewed verifier correction accepted the saved JUnit and complete logs containing the same physical device before and after creation; the original rejection is retained. No tests were rerun for that reporting correction.
Earlier paired validation used base
b3ae112012d84ac519525b39c65a91e4d7e87430, test-only baselineac05be11b28e7285346d6a37c2742ca7702087a8, and candidatef343554530bf8f58b4b0212a2d2b017fafa71e8d, with identical test files. These historical results apply to those pins, not the current head:The deterministic regression grows a same-base import, grows from an earlier base, and splits an import at a window boundary. Each uses a completed but unreaped submission, verifies the unlocked attempt leaves recorder state alone, copies from the old import, retries under the GPU lock and checks readback. The baseline reaches all three readbacks safely before failing; it never deliberately destroys an in-use GPU resource. The map-time control reserves unregistered gaps so its disjoint contention case cannot accidentally coalesce imports.
No retail-title startup, frame-rate or driver/device-loss improvement is claimed. Implementation and review were AI-assisted.
Checklist
mainat4bf963d660c8144a91340c7058e41bd26dd6e692; no other open PR implements this correctionImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T01:18:55Z.
Traced every acquisition of the GPU mutex and the imports mutex in this file to check the one thing that matters for a change like this: no deadlock or lock-order inversion. The new guard itself acquires nothing — it only reads
HeldByThisThread()on the (reentrant, owner-tracked) GPU mutex — and the only place that locks the imports mutex releases it before returningfalse, so by the time the retry takes the GPU lock, nothing else is held. Every acquisition elsewhere in the file takes the GPU mutex first and the imports lock second, never the reverse, so there's no cycle to form. The retry path this relies on already existed upstream (the map observer's locked second attempt) — this PR only makes that retry trigger in a case it previously didn't.One real finding, test-only but worth fixing before merge: the new test's entry guard (
Require(context.hostImportAlignment != 0 && <= 65536, ...)) throws and exits 1 on a device without host-import support, rather than returning theSKIP_RETURN_CODE 77theCMakeLists.txtregistration expects — every sibling host-import test in this file skips gracefully the same way, and this one doesn't. On a device that lacks host-import support, this test will hard-fail instead of skip.On the testing narrative: the parts that can be checked from here hold up well — all six pinned commit hashes resolve in the author's fork, the historical and rebased patches are byte-identical, and the stated #4021 dependency is genuinely merged. The one piece that doesn't check out is the linked third-party CI run (
hammerlab-dev/anyps5-validation) — it 404s unauthenticated from here, so that specific Linux/lavapipe reproduction rests on assertion, not something a reviewer can independently confirm. Not a reason to distrust the PR, but worth flagging as unverifiable rather than corroborated.Separately: no CI lane on this PR actually runs the new
agc_host_import_retirementtest — the only jobs that build the full tree and run the AGC suite are gated to push/workflow_dispatch, so the green checks here don't exercise the locking fix. Worth a dispatched full run before merge, partly to confirm the fix and partly to catch the skip-vs-fail issue above on whatever runner that uses.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:25:03Z.
Conflicts with main in
core/libs/prx/libSceAgcDriver/CMakeLists.txt; please rebase. I'll merge after that.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T12:58:57Z.
Rebase handoff — rebased onto current
main, authorship unchanged.One conflict in
CMakeLists.txt: both this PR and main added different recorder tests at the same registration spot — the resolution registers both (main'sagc_parked_import_unmapand this PR'sagc_host_import_retirement), with the WindowsENVIRONMENT_MODIFICATIONlist taking the union.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesTo pick it up:
Head is
b00bd9fa1.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T13:51:53Z.
Preparing Windows cross-test of headc7ab53b56c0debe4b547002b7af1441990fa9c50 on our older007 hull integration: local5dd442e66757ddf7ed56ae79b06d81624e9278c1. Your three commits retained/credited; CMake adapter preserves our existing alias tests and excludes absent multisample test. Also adapted SleglJan's added window-completion fixture to require false from the unlocked replacement, then retry true under GpuMutex. Not built/staged yet: the current game trace664 is still running.
Reason for testing this approach: even with SleglJan8a441394f's holder parking, 007 logged an import retired outside the device lock losing6 shadowed units. RetireShadow is called before the holder's lock test there, so GPU-locked retry is relevant to preserving publication as well as recorder access. This is observed metadata/source analysis, not a #4017 runtime result or proof of a terrain root cause. Will run your GPU-readback fixture and a production-only negative control after this game run. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:04:21Z.
Windows native cross-test now completed for adapted head5dd442e66757ddf7ed56ae79b06d81624e9278c1 (public #4017 c7ab53b56 changes, existing SleglJan holder parking retained). Six CTest entries pass (no CTest skip status): host_import_retirement, driver_host_import_at_map, unit_shadow, storage_cpu_snapshot, storage_upload_lifetime/failure, 1.85s restored run on RTX5070Ti. Coverage caveat from LastTest.log: unit_shadow returns early with "host imports are compared, not watched: unit shadows not tested" on this Windows device; its publication body was NOT exercised. The retirement fixture itself executes all three shapes with GPU readback verified, deferred=1 and recorder preserved=1.
Production-only negative control: restoring GuestBufferMemory.cpp to664d9df34 while retaining all fixtures makes both retirement and at-map tests fail (unlocked replacement failed to request GPU lock). Restored the fix, rebuilt and all six pass again. Author fixture verifies GPU readback for same-base growth, earlier-base overlap and predecessor split. No claim that this alone solves 007 shadow/terrain failures or the earlier Windows heap corruption.
Now starting guarded warm 007 run with graphics SHA2563ECA82847321ED40EBFCD465055122C4DD8D8D821A010E37151BE1CFCDAC3F8B; identical trace664 settings/cache, #1359 not yet combined. Public branch: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-locked-retirement-cross-test . AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T19:26:53Z.
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/Graphics/src/GuestBufferMemory.cppL2028-2032