fix(agc): keep a host import dropped mid-hold for every batch that hold opens #4385
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4385"
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 AlxcBTW on 2026-10-12T08:30:33Z.
What
A host import that
refreshImportsorimportAllocationdrops in the middle of a GpuMutex hold can be freed before the GPU runs the commands that the same hold still records with it. The GPU then reads an unmapped page and the device is lost. In Sword of the Sea (PPSA25344, UE5) this happens in about 1 of 8 start-ups, at the first scene frame (VK_ERROR_DEVICE_LOST, nvlddmkm 153 on NVIDIA).Mechanism.
const HostImport*:UploadFinishflushes pending images between regions, and a flush can reconcile the imports);retireImporterased its map node and handed itsRetiredImportholder to the batch open at that moment. If the recorder was idle, it destroyed the holder at once.SubmitorSynccame in between, the command lands in a later batch. The import is freed when the earlier batch completes, before the later batch runs. With an idle recorder the import is gone before the command is even recorded. In both cases the pointer names an erased map node.Deterministic evidence:
test(agc).agc_host_import_retire(mock device, no GPU) grows an imported run and reconciles inside one hold. It covers two cases:Submitbetween the batch that keeps the import and a later batch of the same hold, where the keeping batch completes first.In both cases the dropped import must stay alive until every batch of the hold has completed. On
mainboth checks fail:Field evidence: Sword of the Sea start-up.
VK_EXT_device_faultreportsREAD_INVALIDat one page in every device loss.VK_EXT_device_address_binding_reportlogged (6 device losses), that page lay inside a host import retired 2.2-3.0 s before the device-loss report each time. The report lags the fault by about 2 s.0x1e40000000, or its shader code region at0x1540000000.fix(agc).retireImportmoves the dropped import's map node into its holder (std::map::extract), so pointers taken earlier stay valid.Recorder::KeepThroughHold, tied to the hold byGuestMemory::GpuHoldSerial, a count of outermost GpuMutex acquisitions. Whatever the hold records with the import completes before the import is destroyed.FlushDeferredReleasesalso lets go of what an ended hold kept, so the waiter is not left waiting on pinned ranges.Related. #290 also drops imports (least-recent eviction under the budget). If both land, its evictions should go through
retireImportso they get the same lifetime. That is how we run the two together in our Sword of the Sea test stack.Tested
Windows 11 (26200), WinLibs GCC 15.2.0, Release, on
maind06c06565.mainplus only the test commit:agc_host_import_retirefails with the two messages above (Lenovo node, non-GPU suite, ond146ec1b6; the retire path is the same ind06c06565).agc_host_import_retirepasses (Lenovo node).ctest -E "^agc_driver|^video_out|^guest_video", Lenovo node): 587 of 588 pass. The one failure,log_macros("a short line differs"), fails the same way onmainwith only the test commit.agc_driver_recorder(full, and--host-import-unmap-only),agc_driver_host_import_at_map,agc_driver_host_import_teardown,agc_driver_sampled_cache_budget,agc_driver_graphicsandagc_host_import_retire: 7 of 7 pass.tools/check_conventions.py --base origin/mainpasses.READ_INVALIDat one page, while the async 120x68 pass of the first scene frame was running. One event cannot show a rate, so I'll add the larger series as a comment.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T09:17:37Z.
Windows cross-test of #4385
e785a902bon our 007 stack: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-host-import-hold-cross-test head a5c0c9a363fecd06fa1c187742974974e2f27b04. Your test/fix commits and author are preserved with cherry-pick attribution as 3f9f2e2c8 / a5c0c9a36. Base is our public-perf + cache-preserving sparse WIP cc495f66d, not current main.Baseline check: built the test-only commit 3f9f2e2c8 against that stack's existing production code/headers (no mixed-layout DLL comparison). agc_host_import_retire fails both reported checks: dropped while recorder idle; dropped holder destroyed before a later batch of the same hold completes. With the fix, that test and agc_driver_graphics pass, 2/2 in 8.12 s. Rebuilt dependent recorder fixtures: host_import_at_map, host_import_teardown and sampled_cache_budget pass on RTX 5070 Ti, 3/3 in 2.59 s. Recorder executable full run and --host-import-unmap-only also exit 0; full run says snapshot patching not tested because Windows direct imports here are compared rather than watched. No full-suite claim.
Port detail: our older base lacks main's device-change parking state. The one textual conflict retains its existing immediate destruction on device change, using the extracted node's mapped entry. Mid-hold node ownership/KeepThroughHold behavior is your fix. This does not claim coverage of the newer main parking path or a device-loss frequency result.
Only graphics is staged, SHA256 4B9C9D2BD018E5B7606CDB2B84AA504964270D7A138DC388C920D42F443D8A8D; no other staged module directly uses Recorder's private layout. Quiet 007 startup cross-test now launched, same warm cache/config. Game result pending; no duplicate upstream PR. Windows 11 26200, GCC 15.2 Release, RTX 5070 Ti. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T09:26:04Z.
Quiet 007 startup on the #4385 port a5c0c9a36 reached the rendered title at frame 979, ~1.49 FPS, ~19.9 GB private memory, one bounded trim. Prior cache guard cc495 title was ~1.56. One run each/different camera positions; no significant speed claim or device-loss-rate conclusion. No device loss in this startup. Continuing to offline menu/campaign to record the current stop. Same staged graphics SHA 4B9C9D2B, other modules/cache unchanged. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T09:35:26Z.
@Scramblrrrr thanks for the independent cross-test. It's good to see the test fail both checks on your stack too, and the fix plus the recorder fixtures pass on a 5070 Ti. Your note on the device-change path is right. On current
maina drop at device change still goes to main's parking state; this PR only hands the parked holder the extracted map node instead of the map entry, so the parking behaviour itself is unchanged.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T12:54:03Z.
Merged current
main(ffa198407) into this branch, plus one fix commit (eaf5ca240). #4291 renamedRetiredImport::entrytonode, soreleaseParkedImportsnow reads a parked import's range through(*it)->node.mapped(). Behaviour is unchanged: parked imports belong to replaced devices and never go throughKeepThroughHold.Tested on this head: Lenovo (Ryzen 7 7730U, GCC 15.2) non-GPU ctest 600/601, where
log_macrosis the only failure, as onmain. On an RTX 5070 Laptop (driver 616.92) 8/8 GPU tests pass, among themagc_host_import_retire,agc_driver_graphics, andagc_driver_recorderincluding #4291's--parked-import-unmap-only.AI-assisted: yes (Claude Code)