fix(agc): land GPU writes over guest memory before a host write into it #6926
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6926"
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 EagleBearerYS on 2026-10-16T19:28:57Z.
What
A host write into guest memory doesn't wait for the GPU writes recorded or in flight over the same memory, and doesn't store the storage-image results still pending there.
GuestArena::HostWritescope. That covers the APR read (libkernel/Apr/src/Apr.cpp:159-170), AIO,read/pread/readv,recv/recvfromin libkernel and libSceNet, thefcntl/ioctloutputs, libc's file reads and WebKit'smkstemp.GuestWriteWatchBeginHostWriteis Apple-only.Why that loses data: a storage image's write-back into host-imported guest memory is recorded, not made, while a recorder is active.
StorageTexture::writeBackLayers(Graphics/src/Texture.cpp) decides which 64 KiB blocks to keep for the CPU, records the retile and the copy into the open batch, and notes a pending write. The bytes land when that batch runs.Related: #6636, where the crash below was traced; #6234, the read direction (pending GPU results flushed before file writes), whose hook this one pairs with.
The title. Epic Mickey: Rebrushed (PPSA15657, UE 4.27) crashes now and then while it loads its first level. johnmaia ran it on Linux, RX 7600 (RADV, Mesa 25.2.8), on
main5d9dcc42d+ #6236 with no other changes (#6636, comment):APS5_STORE_AT_FLIP=1ObjectSerializationErroronSM_MachineSet_01b(UE's "Serial size mismatch");LowLevelFatalError [Line: 1609]right after the title opens/savedata0/ue4savegame.dpx.sav;main, about 2 runs in 5 crash this way. In those, a 64 KiB block of file data the title had just read is zeroed about 18 ms after the read, with no CPU write path of the driver involved (#6636, comment).APS5_STORE_AT_FLIP=1stores pending results at every flip, which closes that window. This PR closes it at the host write itself.mainfrom 2026-10-24 the crash no longer shows without this PR either (johnmaia's follow-up); johnmaia names #8126 and #8751, merged on 10-23, as plausible changes that cover the same path.The fix:
GuestArenaBeginHostWrite_nid_postfixnow calls a hook first, on every platform, for every non-empty range. The setter isGuestArenaSetHostWriteHook_nid_no_patch, so everyHostWriteuser above gets it with no change at the call site.GuestMemory::PrepareHostWriteinDriver::Driverand clears it in~Driver.PrepareHostWritecallsFlushGpuWritesunderReadSiteScope(ReadSite::Store), as the driver's own guest stores (GuestMemory::Write,WriteChanged) already do. That call:2ff4ed6470, from CnRJay's review): the hook is an atomic pointer (GuestArena.cpp).Driver::stop()now clears it first, before the worker joins, then sets a stopped flag and waits up to 1 s for calls already inside the hook to leave.PrepareHostWritecounts itself in flight (seq_cst) before it checks the flag and returns at once if it is set, so either a call sees the flag orstop()sees the call. The wait is bounded because on WindowsExitProcesscan end a thread inside the hook before~Driverruns; if the bound expires,stop()logs it and goes on.~Driverstill clears the hook as before.HostWritescope under the tracker lock, so it skips the hook through a thread-local guard and can't re-enter the tracker.g_mutexbefore itsHostWrite.DescriptorControl'slockis the guest record-lock struct, not a mutex.c2720073b9, from CnRJay's review): a host write made while the thread holds the GPU mutex is counted (GuestMemory::LockedHostWrites) and logged once with its thread, address and size, then goes on. WithAPS5_ASSERT_GPU_LOCK=1, the switchAssertGpuLockHeldalready reads, it aborts with a[lock] ASSERT:line instead. It doesn't throw in a normal run: with the mutex held, the hook takesFlushForAccess's nested locked wait, which hangs only if completing needs another thread to take the GPU mutex, so a throw would turn a possible hang into a certain crash. The debt file states the rule.docs/dev/debt/libSceAgcDriver.md) narrowsmain's late-store sentence (#1970) to the title's own CPU stores, which still aren't ordered after a recorded store: they survive only in the 64 KiB blocks the write watch saw written. Its CPU reads after a label still read stale memory.Cost: the hook adds about 75-90 ns to a 64 KiB host write with nothing to wait for (82.5-97.7 ns against 6.9-7.1 ns, the test's
--costmode). That's the flush hook's fast path, well under theread()it precedes.276f67d366, from CnRJay's review): withAPS5_PROFILE_DRAW=1, a[hostwrite]line every 10 s counts the host writes, those that waited for GPU work over their range, and the total and longest wait, e.g.[hostwrite] 2 host writes, 1 waited for GPU work over their range: 1.34 ms in total, 1.34 ms at most. Without the switch nothing is counted. The title's numbers aren't measured yet.How:
fix(agc): land GPU writes over guest memory before a host write into it: the hook, the driver's registration, the debt entry and the new testagc_driver_host_write_pending_storage(tests/execution/HostWritePendingStorage.cpp)._readFiledoes it,std::ifstream::readinside aGuestArena::HostWritescope. A laterFlushGpuWritesplays the guest's read.refactor(agc): name the host write hook as a pair to the host read hook: names the setter and the driver function after #6234's host read hook (GuestArenaSetHostReadHook_nid_no_patch,PrepareHostRead). The_nid_no_patchsuffix follows CONTRIBUTING.md for helper symbols that must not become NIDs.Tested
Epic Mickey: Rebrushed (PPSA15657), johnmaia's runs: Linux, RX 7600 (RADV, Mesa 25.2.8), short runs to the first level,
APS5_STORE_AT_FLIPunset (#6636, comment). Currentmainrarely shows the crash, so they ran the fix on the base where it fails:main5d9dcc42d+ #623699af947b18,082c3268ac)maine751dd205ObjectSerializationError, theLowLevelFatalError [Line: 1609]or the SIGSEGV.APS5_TRACE_APR=1 APS5_TRACE_FLUSH=1), 23 APR reads were each followed at once by the hook storing a pending image over their destination, before the read's bytes were written:PrepareHostWritestill callsFlushGpuWritesover the written range.Alone in the Dark (PPSA08240, v1.00), LeoFeitosa's runs (comment): Windows 11 (26200), RTX 5070 Ti (driver 617.42), WinLibs GCC 15.2.0, Release.
APS5_PLAYGO_UNLISTED_CHUNKS=installed, and has no input until the main menu.maincd700fe9e2c5b77231)main+APS5_STORE_AT_FLIP=1main, all while loading:LowLevelFatalError [Line: 3230], "Serial size mismatch" on UI textures;0xc000001donFAsyncLoadingThread;0xc0000005atAlone in the Dark.exe+0x20ec0bc.0xc0000005at+0x20ec0bc. Whether it shares the cause isn't traced.APS5_TRACE_APR=1 APS5_TRACE_FLUSH=1all reached the main menu, so this PR (2c5b77231; the head since only mergesmain) has reached it in 13 of 14 runs (comment). The tracing changes the timing, so those eight runs don't rule the remaining crash out.Linux (lavapipe, Mesa 25.2.8, gcc 13.3, CI's Linux configure), on main
66e290f1c0. Each check ran in all three write-watch modes: userfaultfd user-mode only (unprivileged), full userfaultfd (root), and unwatched (APS5_NO_WRITE_WATCH=1).ctest -R '^agc' --parallel 4 --timeout 120: 625/625 at the head, 43 skipped as expected.ctest -R 'guest|libc|kernel': the same as main on that machine. The 5 failures are IPv6 tests the container always fails.GitHub runners (run 38952984815), with only the registration reverted for the red:
guest_kqueuefails there with and without the change.Merged with #6234 (0f5651f0fb) and with #6184 (
4a9640677f), each on its own, on lavapipe. The new test passes 10/10 on both merges.agc_driver_storage_file_writepasses 10/10 and^agc626/626.agc_driver_graphicspasses 10/10 and^agc624/625. The one failure isagc_driver_preparation_scope_settle, which passes 5/5 alone.Windows code: MinGW
-fsyntax-onlyofGuestMemory.cpp,Lifecycle.cpp,GuestArena.cppand the test: 0 errors.The review follow-ups (Linux, lavapipe, CI's configuration), each with its case in the new
agc_driver_host_write_hook, in the same commit as its change:Driver::Shutdown, a host write over a range with a recorded store must not reach the driver's flush hook. Red at the previous head: "a host write over a range with a recorded store reached the driver's flush hook 1 time(s) after Driver::Shutdown".APS5_ASSERT_GPU_LOCK=1the test aborts at the[lock] ASSERT:line, as intended.agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass 20/20 in each of the three write-watch modes, and^agcpasses 626/626.^agcsweeps' only failures areagc_driver_preparation_scope_settleon Linux, a timing check under parallel load, andagc_driver_pm4_replay_tool(0xc0000139) on Windows, which fails onmainthere too.AMD Radeon 780M (RDNA 3, AMD driver 25.10.20.01), Windows 11 (WinLibs GCC 15.2.0, Release), run by keravyn-ops at
276f67d36(comment):agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass.NVIDIA GeForce RTX 3080 (NVIDIA 617.42), Windows 10 Pro 22H2 (WinLibs GCC 15.2.0, Release), run by TheSovietWaffle at
276f67d36(comment):agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass 5 of 5 runs each, and the 12guest_socket_host_write_*tests, which go through the changedGuestArenahost-write path, pass.NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04 (GCC 15.2, Release), run by jotitadev at
276f67d36merged ontomain12a71f3f5(review): both new tests pass, 3/3 on the 3070.^agchas no new failures againstmain: 636 of 638 on the 3070, whereagc_driver_f16_fma_denormal_modesandagc_driver_fma_mix_f16_denormal_modesfail onmaintoo, and 638 of 638 on lavapipe. With only the hook's registration inDriver::Driverremoved, the same three cases fail on both devices as in the red above, and the whole-block case passes.Merged with
maincd700fe9eand86b84244fb(2c5b772311, then9f5745d7dd, the head). Each conflicted only in the debt file, where both sides' entries are kept. On GitHub's runners at the head (run),agc_driver_host_write_pending_storage,agc_driver_host_write_hook,agc_driver_storage_file_writeandagc_driver_graphicspass 3 runs in a row on Linux. On Windows three of the four skip without Vulkan andagc_driver_graphicspasses. The libc and libkernel suites pass on both.Merged with
main0d078f75d3(46d8f39271, no conflicts), on GitHub's runners (run): in one run on Linux the^agctests pass, 711 tests: 662 pass, 49 skip, 0 fail. The libc and libkernel suites pass on both runners. On Windows, of 711^agctests 173 pass and 536 skip, since the runner has no Vulkan device; the only failures areagc_driver_pm4_replay_toolandagc_shader_replay_tool, which fail the same way on that runner for an unrelated branch (run).Merged with
main5949d8bf92and5d48c6233e(3080b8f66f, thenb7794a5f1c, the head; run).main's #9685 excepts drawn resident linear targets from the pending storage-image results debt entry this PR rewrites, and adds two entries after it; the merge keepsmain's opening, this PR's text,main's two entries, then this PR's host-write entry.main's #10369 opens a watched import's host-write window only when the import may write guest memory; the merge keeps this PR'sOwnHostWritemark, thenmain's optional window. Theagc_driver_host_write_andagc_driver_linear_target_tests,agc_driver_address_passes_draw_transitions,agc_driver_graphics,agc_driver_preparation_scope_settle,agc_driver_storage_file_write,guest_kqueueandpublic_headerspass 10 runs in a row. Linux: 18 run, 17 pass, 1 skip (agc_driver_linear_target_direct_write_completion), 0 fail. Windows: 18 run, 3 pass, 15 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (144 and 208) and on Windows (171 and 224). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.LEGO Horizon Adventures (PPSA14632), run by winstrex (comment): Windows 11, NVIDIA GeForce RTX 5070 Ti (NVIDIA 591.86), warm shader cache, the same input script each run.
[hostwrite]line shows host writes landing on pending GPU work over their range in every run (4 to 60 per run).FAsyncLoadingThreadcrash withObjectSerializationError ... Serial size mismatchafter the graphics quality screen came in 2 of 2 runs onmain7ce3b1df3, 1 of 6 on this PR's base86b84244fand 0 of 7 with this PR (9f5745d7d). winstrex calls that not conclusive at these counts.UObjectHash.cppline 42).Epic Mickey: Rebrushed (PPSA15657) on newer
main, johnmaia's follow-up (comment): the same setup (i3-12100, RX 7600, RADV), where a run fails onObjectSerializationError/ Serial size mismatch,LowLevelFatalErroror a crash before the level.main5d9dcc42d, earlier runs: 5 of 8 reach the level cleanly.main933c0e4f1/bfb080619(10-24), without this PR: 5 of 5.mainbfb080619with #8091 and #10304, at about 7 fps in the level, the speed where the old failure showed: 14 of 14. johnmaia puts the chance of 14 clean runs at about 0.1 % if the old 3 of 8 still held.mainthis crash no longer shows a failure this PR fixes. The Alone in the Dark (cd700fe9e) and LEGO Horizon Adventures (7ce3b1df3) runs above were also onmainfrom before #8126 and #8751.Alone in the Dark (PPSA08240) on current
main, LeoFeitosa's rerun (comment):mainb1f023dda3(10-25) without this PR, the same harness (Windows 11 26200, RTX 5070 Ti, driver 617.42,APS5_PLAYGO_UNLISTED_CHUNKS=installed, the exe and.guest.prxrelinked with this build's relinker).LowLevelFatalError [Line: 3230]"Serial size mismatch" on a loading-screen texture, and two crash in the async loader right after the menu (0xc0000005onFAsyncLoadingThread, andLowLevelFatalError [Line: 197]allocating 34043592704 bytes).main, unlike Epic Mickey.b7794a5f1cmerged cleanly onto the sameb1f023dda3, the same harness and machine, the installedlibSceAgcDriver.prxchecked against the package), 6 of 6 runs reach the main menu with no fatal error (menu at 260, 90, 90, 90, 90 and 90 s) (comment).LEGO Horizon Adventures (PPSA14632) on current
main, winstrex's pair (comment): Windows 11 (26300), RTX 5070 Ti (driver 621.01). Onmainabed035468all 12 runs, with and without this PR, stopped 19 to 40 s in on the refusal from #11425 (a compute shader reading or writing a converted float image with 16-bit data), so both sides had #11580 merged, which fixes it. 240 s per run, alternating, with the saves and a warm shader cache restored before each run.mainabed035468+ #11580: 6 of 6 reached the load after the graphics quality screen, with noSerial size mismatchorFAsyncLoadingThreadcrash.bc288ffa6d): 5 of 6, with no loader crash; the sixth stopped onVK_ERROR_DEVICE_LOSTat 81 s, which winstrex also saw once without this PR, in a warm-up run that isn't counted.tools/check_conventions.py: passed.Overlap. On main
1b1f8483ca, the overlap check finds three open PRs that conflict with this one. 37 others that touch the same files conflict with main themselves, so they couldn't be checked.GuestArena.hppandGuestArena.cpp, and the debt entry, which both PRs rewrite. Each resolves by keeping both sides.FlushGpuWrites.GuestArenaWriteWatched_nid_postfix.GuestArenaBeginHostWrite, so the two compose independently.Execution/src/Driver/Lifecycle.cpp. Whichever lands second takes a one-line merge.main32b7331c44andmainwithb7794a5f1cmerged (clean), the sameapp.exe, save state and pad script, runs alternated, 125 s from launch through the New Game load, 6 runs each. Onmain, 4 stop at the #7048 refusal at about 20 s, 1 on an access violation before the menu, and the one that reached the New Game load crashed there (Serial size mismatch). With this PR, 2 are clean, 2 stop at the #7048 refusal and 1 on an access violation before the menu; of the 3 that reached the load, 1 crashed there (anFAsyncLoadingThreadaccess violation). So the loader crash still occurred once with this PR. He notes that the rate drifts a lot with the state of the machine, so counts this small are only indicative.APS5_PLAYGO_UNLISTED_CHUNKS=installed, 60 s from boot. The title sometimes crashes during its first load, with a UE4 "Serial size mismatch" LowLevelFatalError or a SIGSEGV in package loading. JJenkx traced it with local read diagnostics that aren't in any PR. The file reads match the pak, but the failing exports are read into memory that held one of the title's colour targets about a second earlier, and the driver's idle store then writes that target's drawn rectangle over the file data (5.6 ms after the read, in the logged crash). This PR's host-write hook stores the pending target before the read.main1e24993fa3crashed in 5 of 12 runs, andmainwith this PR at75ffc81473in 0 of 12 (one-sided Fisher p ≈ 0.019). The write-backs over the failing buffers within 300 ms of each read were 47 idle stores onmain, 26 of them after the read, and with this PR 4 stores by its hook before the read, 1 idle store and none after.maincrashed in about 1 run in 5, but in this paired series both arms ran 0 of 12, so those runs say nothing either way.bc288ffa6d, a merge ofmain263eee0a77(run). thuanquang's #9879 adds a "Linear color targets" entry todocs/dev/debt/libSceAgcDriver.mdwhere this PR adds its "Host writes into guest memory" entry; the merge keeps both, and this PR's changed lines are the same.agc_driver_host_write_hookandagc_driver_host_write_pending_storage, with the tests for the files the merge changes, pass 10 runs in a row. Linux: 326 run, 316 pass, 10 skip (seven AGC tests on lavapipe and three video-out tests with no display or Vulkan device), 0 fail. Windows: 344 run, 256 pass, 88 skip (85 AGC tests, this PR's two among them, and the same three video-out tests, no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (145 and 212) and on Windows (174 and 233). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.d0b755a486, a merge ofmainfacac6a4c5(run). The one conflict was the include block ofGuestMemory.cpp, wheremainnow has the<thread>include this PR added and adds<system_error>next to it; the merge keepsmain's lines, and this PR's other changed lines are the same.agc_driver_host_write_pending_storage,agc_driver_host_write_hook,agc_driver_graphics,agc_driver_linear_target_direct_write_completion,agc_driver_preparation_scope_settleandagc_driver_storage_file_writeran 10 times in a row with no failure. Linux: 6 run, 5 pass, 1 skip, 0 fail. Windows: 6 run, 1 pass, 5 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (166 and 264). On Windows libc passes (194), and libkernel has 4 failures of 286.guest_raise_exceptionaborted with 0xc0000409 after "address waking round 37: the handler did not run within 5 s". Run again on this commit (run) it aborted the same way at round 7, and so didmain9fc181dde5in the same verify setup (run, round 5). That is #11813, which traces it to #10666 onmain; this PR doesn't touch libkernel. The other three,exec_arguments,guest_timed_join_import_libkernel_sysandguest_timed_join_import_libkernel_web, fail at their setup in the verify's Windows build (FileNotFoundErrorstarting the title, or copying the libraries they load), and pass inmain's own Windows job at1829def9bf(job). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.11cd12b90b, a merge ofmainba627802e2(run, validation run).docs/dev/debt/libSceAgcDriver.md. Gonic0's #13499 (label read traps, macOS) adds a "Label read traps" entry right after the "Pending storage-image results" entry this PR rewrites, and #13678 has since changed it. The merge keeps this PR's Pending entry, thenmain's Label read traps entry, each unchanged. The other files merged on their own, and this PR's diff againstmainis the same as before in every file.maine67cc81869, result):GuestArenaBeginHostWritecalls this PR's host-write hook first, which stores a trapped image whole and releases its trap. Only then does the write watch'sBeginHostWriteresolve any trap left on the range and open the pages. On Linux every trap path is under#if defined(__APPLE__), so only this PR's path is compiled there.agc_driver_host_write_pending_storageandagc_driver_host_write_hook, withagc_driver_graphics,agc_driver_linear_readback_label_off,agc_driver_linear_target_direct_write_completion,agc_driver_preparation_scope_settle,agc_driver_storage_file_writeandagc_recorder_completion_labels. Linux: 8 run, 7 pass, 1 skip, 0 fail. Windows: 8 run, 1 pass, 7 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 208 and 308 tests on Linux and 235 and 330 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.VERIFY_VALIDATION=1on GitHub's Linux runner,mainagainst this head, the same tests wheremainhas them): both pass. The loader insertedVK_LAYER_KHRONOS_validation9 times onmainand 13 with this head, and neither log haswas not found. Both report onlyVUID-VkDeviceCreateInfo-pNext-pNext, so the change adds none.3c3c2ca24a, the Pending storage-image results entry cut to the gap still open, for fogydes' review. This PR's rewrite of the entry had grown it frommain's 985 characters to 1,396, overcheck_conventions.py's 1,000-character warning, and described the new ordering. It's nowmain's entry with only the late-store sentence narrowed to a title's own CPU stores, 993 characters. Docs only:check_conventions.py --base ba627802e2passes with no warnings.59a6f5e41e, a merge ofmain3c3b3cda73(run). The one conflict was indocs/dev/debt/libSceAgcDriver.md: this PR's narrowed "Pending storage-image results" entry and its "Host writes into guest memory" entry sit besidemain's new active-recorder entry and two write-watch entries, and the merge keeps all of them. This PR's diff overmainis unchanged. This PR'sagc_driver_host_write_pending_storageandagc_driver_host_write_hook, withagc_driver_graphics,agc_driver_linear_readback_label_off,agc_driver_linear_target_direct_write_completion,agc_driver_preparation_scope_settle,agc_driver_storage_file_writeandagc_recorder_completion_labels, ran 10 times with no failure. Linux: 8 run, 7 pass, 1 skip (agc_driver_linear_target_direct_write_completion), 0 fail. Windows: 8 run, 1 pass, 7 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (214 and 316) and on Windows (241 and 337). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.75ffc81473, a merge ofmainb611e634f7(×10, everyagctest), which brings mrfelek's #15783 (moved read-only draw inputs kept within the draw snapshot cap).docs/dev/debt/libSceAgcDriver.md, where #15783 extends the "Draw input snapshots" entry next to this PR's narrowed "Pending storage-image results" entry. The merge keeps both. The code merged without conflicts,GuestMemory.cppandGuestArena.cppincluded, whichmainchanged since3c3b3cda73. This PR's diff overmainis unchanged.agc_driver_host_write_pending_storageandagc_driver_host_write_hook, withagc_driver_graphics,agc_driver_linear_readback_label_off,agc_driver_linear_target_direct_write_completion,agc_driver_preparation_scope_settle,agc_driver_storage_file_writeandagc_recorder_completion_labels. Linux: 8 run, 7 pass, 1 skip (agc_driver_linear_target_direct_write_completion), 0 fail. Windows: 8 run, 1 pass, 7 skip (no Vulkan device), 0 fail.guest_kernel_stack_protectfailed once (GuestKernelStackProtect failed at line 276, themprotectof the test's own host pages). This PR changes no libkernel code, and in theagcrun the same head's libkernel suite passed all 329. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.agctest, once: Linux: 1,334 run, 1,247 pass, 85 skip, 2 fail. Windows: 1,373 run, 411 pass, 962 skip (no Vulkan device), 0 fail. Both failures aremain's:agc_driver_image_gather_volume("the vertex shader was not emitted in the device's module form") fails the same way inmain's ownlinuxcheck on638187daec, the #15855 merge (job). JJenkx's #15875, merged afterb611e634f7, updates the test for the specialized vertex form #14265 emits.agc_driver_pipeline_journal's 120-second timeout (778/1334 Test #1431: agc_driver_pipeline_journal ***Timeout 120.06 sec),main's own cold run.mainb611e63, Mesa 25.2.8, Ubuntu 26.04.1, 3,899 of 3,946 tests selected. 3,819 passed, 18 failed and 62 skipped. None of the failures is new: 13 also fail onmain, and 5 are unstable onmain. WithVK_LAYER_KHRONOS_validation, there are no new validation IDs againstmain, over 1,391 tests on the GPU.mainacac7c8, driver 595.99.02, Ubuntu 26.04.1, 3,913 of 3,960 tests selected. 3,848 passed, 6 failed and 59 skipped. None of the failures is new: 2 also fail onmain, and 4 are unstable onmain. WithVK_LAYER_KHRONOS_validation, there are no new validation IDs againstmain, over 1,399 tests on the GPU.59a6f5e41e):git range-difffrom59a6f5e41eshows this PR's six commits unchanged. On this head merged ontomain78e4248fea, Windows 11, AMD Radeon RX 9070 XT (driver 32.0.32015.12012), WinLibs GCC 15.2.0, Release, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the validation layer:agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass, 2 of 2, the hook's GPU path ran ([hostwrite] 2 host writes, 1 waited for GPU work over their range), and there's noVUID-message.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.mdfiles or images added to the repository (attach them to this PR)main(LeoFeitosa: onmainb1f023dda3, the main menu with no fatal error in 3 of 6 runs without this PR and 6 of 6 with it; earlier, 13 of 14 runs with this PR and 1 of 6 onmaincd700fe9e). It has no Game bring-up discussion yet. Epic Mickey: Rebrushed (PPSA15657, #2255) was the first title: its first-level load crash from #6636's thread, onmain5d9dcc42d(johnmaia: 0 of 12 runs failed with the fix, 6 of 24 without), no longer reproduces onmainfrom 10-24 without this PR.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T22:07:30Z.
Review: COMMENTED
The right place to fix this (the host write itself, rather than a store at every flip), and the fast path is cheap (82-98 ns against 7 ns for a 64 KiB write with nothing to wait for). Three questions on the slow path and on teardown.
PrepareHostWritewaits for the in-flight batches and the store. The call comes from whatever thread did theread()/recv()/APR read: file I/O threads, the network thread, and the title's own loader threads. A loader that streams into a buffer the GPU is still writing now stalls on a GPU round trip per read, which is the stall the description describes as the cost of the flip-time store, only moved. The PR measures the empty case only. Please add counters (hook calls, calls that waited, time waited) to the[rescache]-style profile line and post them for Epic Mickey's first-level load, so the cost of the slow path is seen on a real title, not only in the test.GuestArenaSetHostWriteHook_nid_no_patch(&PrepareHostWrite)is registered inDriver::Driverand cleared in~Driver. A thread inside aHostWritescope when the driver is destroyed can call the hook after the clear started, or whileDrivermembers it uses are gone. State that the hook is an atomic pointer and what makesPrepareHostWritesafe once the driver is stopping (it should do nothing afterstop()).HostWritecall under a mutex the GPU wait needs (the GPU mutex, a libSceNet lock) deadlocks. Add a check in the hook that throws when the thread holds the GPU mutex outside the supported case, the wayDrawPipeline::Draindoes, so a violation is an error and not a hang.Also: the description says the title has not run the fix yet ("Related", not "Fixes"). A log line from Epic Mickey (PPSA15657) on this branch reaching the first level is what the maintainers will ask for; it is worth getting from the reporter before this is looked at in detail.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-17T00:43:16Z.
@CnRJay Thanks. All three are in, each with its test in the same commit:
276f67d366): withAPS5_PROFILE_DRAW=1, a[hostwrite]line every 10 s gives the host writes, those that waited for GPU work over their range, and the total and longest wait. For example, from the test:[hostwrite] 2 host writes, 1 waited for GPU work over their range: 1.34 ms in total, 1.34 ms at most. @johnmaia, when you next run Epic Mickey: Rebrushed (PPSA15657) on this branch, could you addAPS5_PROFILE_DRAW=1and post the[hostwrite]lines from the first-level load? That run would also give the log line for "Fixes".2ff4ed6470): the hook is an atomic pointer.Driver::stop()now clears it first, then sets a stopped flag and waits up to 1 s for calls already inside the hook.PrepareHostWritecounts itself in flight before it checks the flag and returns immediately once it's set, so it does nothing afterstop(). The wait is bounded because on WindowsExitProcesscan end a thread inside the hook before~Driverruns. The new test shuts the driver down and checks that a host write over a recorded store no longer reaches it; it reached it once at the previous head.c2720073b9): a host write made while the thread holds the GPU mutex is counted and logged once, with its thread, address and size. UnderAPS5_ASSERT_GPU_LOCK=1(the switchAssertGpuLockHeldreads) it aborts instead. I didn't make it throw in a normal run. With the mutex held, the hook takesFlushForAccess's nested locked wait, which only hangs if completing needs another thread to take the GPU mutex, so a throw would turn a possible hang into a certain crash. The debt file now states the rule.Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T09:59:31Z.
AMD / Windows run of this PR at
276f67d36: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.Every ctest entry built from the test targets this PR changes passes (2):
agc_driver_host_write_hook(0.37 s):463: host write hook tests passedagc_driver_host_write_pending_storage(0.40 s):464: host write pending storage tests passedAI-assisted: yes (runs made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-17T10:09:11Z.
Thanks @keravyn-ops for the AMD runs here, on #6911 and on #6944; they're in each PR's Tested and GPUs-tested lines now.
Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-17T11:36:24Z.
NVIDIA data point for this PR: head
276f67d36, RTX 3080 (NVIDIA 617.42), Ryzen 7 7800X3D, Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, libraries rebuilt from the head.agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass 5 of 5 runs each on the RTX 3080 (device selected in the log, not skipped).guest_socket_host_write_*tests, which go through the changedGuestArenahost-write path, pass.Not checked: whether the new tests fail on
mainwithout the change on this GPU, and titles (I don't have Epic Mickey: Rebrushed).AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-17T11:39:08Z.
Thanks @TheSovietWaffle for the RTX 3080 runs; they're in the Tested and GPUs-tested lines now.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T13:35:51Z.
Review: COMMENTED
A Linux run on NVIDIA and lavapipe, with the hook taken out to see what the new tests catch.
Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged ontomain12a71f3f5(clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.agc_driver_host_write_hook,agc_driver_host_write_pending_storage^agc(638 tests), PR vsmainagc_driver_f16_fma_denormal_modesandagc_driver_fma_mix_f16_denormal_modesfail onmainon this GPU too)The tests don't build on
main(they useHostWritesCounted), so as the negative control I removed only theGuestArenaSetHostWriteHook_nid_no_patch(&GuestMemory::PrepareHostWrite)line fromDriver::Driver. Both tests fail on both devices, 3/3 on the 3070:So on Linux the file-read path reaches the driver only through this hook, and three of the four cases catch it missing. The third case, a 64 KiB host write over pending results, passes without the hook on both devices, so it does not cover the fix on this platform.
Run on
276f67d36; the current headbe2be36b5only mergesmain, the PR's five commits are unchanged.Not run: Windows, AMD, Epic Mickey or any title.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-17T13:44:37Z.
Thanks for the Linux runs and the negative control. Your three failures are the same ones the red in Tested shows, and the whole-block case passes on
mainthere too, as Tested says. That case isn't a red/green case: it checks that after a whole-block host write over pending results, the file's bytes survive and the image's texels land around them, whichmainalready gets right. I've added your runs to Tested and the GPU list.Imported from boykopovar/AnyPS5. Originally posted by LeoFeitosa on 2026-10-21T07:13:07Z.
Windows / NVIDIA data point, another UE4 title: Alone in the Dark (PPSA08240, v1.00).
Windows 11 (build 26200), RTX 5070 Ti, driver 617.42, WinLibs GCC 15.2.0 r7, Release. Both sides built from the same tree:
maincd700fe9e(the main this PR last merged) and this PR's head2c5b77231. Same converted title, shader cache directory and save state for every run. The dump has no PlayGo files, so every run setsAPS5_PLAYGO_UNLISTED_CHUNKS=installed. No input until the main menu is up.Six alternating pairs, each run from launch to the main menu or the crash (
anyps5.logof every run kept):maincd700fe9emain+APS5_STORE_AT_FLIP=1The
maincrashes, all during the boot to the menu:LowLevelFatalError [Line: 3230]with "Serial size mismatch" on UI textures (T_img_loading_french_quarter,T_Gfx_Derceto_Map_Background);0xc000001donFAsyncLoadingThreadatAlone in the Dark.exe+0x21925a0;0xc0000005atAlone in the Dark.exe+0x20ec0bc(Windows event 1000; nothing inanyps5.log).The one crash with this PR is the last kind:
0xc0000005atAlone in the Dark.exe+0x20ec0bc. I have not traced whether that one shares the cause.Earlier, not alternated, on
main559f35d685: 2 of 4 runs crashed with these signatures (one of them withAPS5_TRACE_LABELset), and the one run withAPS5_STORE_AT_FLIP=1reached the menu.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T07:49:43Z.
@LeoFeitosa, thank you, that's a clear pair: the main menu in 1 of 6 runs on
mainand in 5 of 6 with this PR, and in 3 of 3 withAPS5_STORE_AT_FLIP=1. Thatmain's crashes also go away when pending results are stored at every flip points at the window this PR closes at the host write: a file or APR read landing in memory that a pending GPU store then overwrites.The remaining
0xc0000005at+0x20ec0bcmay have another cause. This PR orders only host writes (file, AIO and APR reads, socket receives) after pending stores. The title's own CPU stores and reads aren't ordered (the debt entry says so), whileAPS5_STORE_AT_FLIP=1stores everything pending at each flip, whoever touches the memory next. If you have time for more runs, theanyps5.logof a crash with this PR underAPS5_TRACE_APR=1 APS5_TRACE_FLUSH=1would show which reads met pending images before it: each one prints a[flush] image … for memory access …line right after its[apr] read.I've added your runs to the description.
Imported from boykopovar/AnyPS5. Originally posted by LeoFeitosa on 2026-10-21T08:57:31Z.
@EagleBearerYS I ran it with
APS5_TRACE_APR=1 APS5_TRACE_FLUSH=1on the same head (2c5b77231), same setup as before: 8 runs, all 8 reached the main menu, so there is no crash log to show yet. Each log has about 26,000[apr]lines and about 110,000[flush]lines, so the tracing was active.With the untraced runs, this head has now reached the menu in 13 of 14 runs. The tracing changes the timing, so it may be hiding the remaining
+0x20ec0bccrash; if it shows up in later runs I'll post its log here.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T09:37:33Z.
@LeoFeitosa, thanks for the eight traced runs. 13 of 14 with this PR against 1 of 6 on
mainis now in the description. If the+0x20ec0bccrash comes back in a later run, its log is welcome, but there's no need to run more for it.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T13:16:11Z.
Second title with the same failure signature, for the record (not a test of this PR).
Setup: Code Violet (PPSA26528) 01.000.028 on Linux, RX 6650 XT, RADV (Mesa 26.2.4).
mainb5d763770awith #4449 merged locally,APS5_UNIT_SHADOW_MIB=4096, andAPS5_STORE_AT_FLIPunset.Failure: 1 of 8 cold starts ended 8 s after launch with:
It was followed by a segmentation fault. The other 7 starts loaded past it to the menus.
I have not run this PR or
APS5_STORE_AT_FLIP=1on this title, so this only adds a second Unreal title where an asset read during async loading sees a wrong size early in startup.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T13:23:19Z.
@JJenkx, thank you for the Code Violet (PPSA26528) data point. It's the same signature this PR fixed in Epic Mickey: Rebrushed (PPSA15657), where a storage image's write-back landed after an APR read into the same memory.
If you have time, could you merge this PR (
9f5745d7dd; it merges cleanly withmain) onto the same tree,mainb5d763770awith #4449, and run Code Violet the same way: cold starts on RADV withAPS5_STORE_AT_FLIPunset, alternated with that tree without it? At 1 failure in 8, a clean run with the PR only means something over enough starts: 16 per side is a start, and 24 or more would make it clear. A run withAPS5_STORE_AT_FLIP=1and no PR would also show whether it's the same late store.Imported from boykopovar/AnyPS5. Originally posted by winstrex on 2026-10-22T05:17:45Z.
Another data point, LEGO Horizon Adventures (PPSA14632), Windows 11, RTX 5070 Ti (NVIDIA 591.86), warm shader cache, same input script each run:
[hostwrite]line shows host writes landing on pending GPU work over their range in every run (4 to 60 per run).FAsyncLoadingThreadcrash withObjectSerializationError ... Serial size mismatchafter the graphics quality screen: 2/2 runs onmain7ce3b1df3, 1/6 on this PR's base86b84244f, 0/7 with this PR (9f5745d7d). Not conclusive at these counts.UObjectHash.cpp [Line: 42] ... hash itself may be corrupted.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T05:40:22Z.
@winstrex thanks for the LEGO Horizon Adventures (PPSA14632) runs, and for keeping the input script the same across them. The
[hostwrite]counts show this PR's path taken in every run, and the crash counts are in Tested now, with your note that they aren't conclusive yet.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T23:14:38Z.
Review: APPROVED
Here's the Windows/AMD run this PR didn't have yet. Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT, with this head merged onto current
main:agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass, nothing skipped. The hook's path ran on the GPU, not just the fast path: the log shows[hostwrite] 2 host writes, 1 waited for GPU work over their range: 0.08 ms in total, 0.08 ms at mostandhost write waits: the write over the recorded store waited, the one over the idle range did not. Withmain'sGuestMemory,Lifecycle.cppandGuestArenasources the tests don't build (HostWritesCountedis new), so a runtime negative control isn't possible here. jotitadev's run without the hook covers that.CnRJay's slow-path and teardown questions are answered in
276f67d366(the[hostwrite]accounting) and2ff4ed6470(clearing the hook and waiting for calls in flight at stop), and the paired Alone in the Dark runs on currentmain(3 of 6 without, 6 of 6 with) back the Unblocks line.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T09:01:46Z.
Review: APPROVED
Reviewed — approved
The host-write hook (libc →
GuestMemory::PrepareHostWrite→FlushGpuWrites) builds and both new tests pass on lavapipe with no new VUIDs. Removing the hook's registration or the teardown instop()makes the tests fail exactly as the description says. I found nothing blocking.What I ran
59a6f5e41e82a2a7049715f0844da5ffb24a45f4main4f41f4c375f5abb487dbd184fbc150f31994d762d1a8dc054612ad49da165b21bf50e32b6d0a6f79Results
git diff --checkcheck_conventions.pylibs(script)maincheck_skips.pyguest_net_ctlskipped, which also happens onmain(not this PR)agc_driver_host_write_hookwith the validation layerVUID-agc_driver_host_write_pending_storagewith the validation layerVUID-agc_driver_native_depth_uniform_planes,VUID-vkCmdDispatch-groupCountX-00386, "test not run on main". The test was added tomainafter the baselined1ae628bc2. Withmain's production files restored it reports the same VUID 4 times, as on the merged tree, so it comes frommain.storage_file_write,graphics,preparation_scope_settle,linear_target_direct_write_completionlinear_target_direct_write_completion, as in the description's runs)New tests, merged tree
Negative control
Both new tests call new API (
HostWritesCounted,GuestArenaSetHostWriteHook_nid_no_patch), so they can't build againstmain's production files. I ran two narrower controls instead.Only the
GuestArenaSetHostWriteHook_nid_no_patch(&GuestMemory::PrepareHostWrite)line removed fromDriver::Driver: both tests fail.agc_driver_host_write_hook: "a host write over a recorded store counted 0 call(s), 0 that waited".agc_driver_host_write_pending_storage: the same three cases fail as in the description and jotitadev's review. The whole-block case over pending results passes, as already noted there.Output
Only the two teardown lines in
Driver::stop()removed (the hook clear andStopHostWrites(1000)):agc_driver_host_write_hookfails with "a host write over a range with a recorded store reached the driver's flush hook 1 time(s) after Driver::Shutdown".After the controls I restored the merged files and rebuilt.
git status --porcelainis empty, and the tests above pass again.Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cpp:16): the PR adds#include "prx/libc/include/GuestArena.hpp", butmainalready includes it two lines below (line 18). The duplicate is left over from the merge with #6641'sShaderDiskCache.hppinclude. It does no harm, but the PR's line can be dropped.main. Only the Alone in the Dark pair onmainb1f023dda3(3 of 6 without, 6 of 6 with) is current evidence, so the Unblocks claim rests on that title.hostWritesStoppedis never reset (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp,StopHostWrites): this is correct today, sinceDriver::Get()is a function-local static andstop()is final. If the driver ever restarts afterShutdown, though, the hook would be registered again but return at once. Worth keeping in mind if restart support is added.Not verified
OwnHostWriteimport window is__APPLE__-only), and any title. The title results are the reporters' runs, quoted in the description and discussion.APS5_NO_WRITE_WATCH=1modes.--costtiming claim (75–90 ns on the fast path).agc_driver_graphicstook 36 s here, under parallel load. This PR doesn't change that test, and I didn't compare its time withmain.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T15:46:47Z.
Review: APPROVED
@EagleBearerYS re-checked at
75ffc81473. The only new commits are merges ofmain.git range-difffrom59a6f5e41e, the head I approved, shows all six of your commits unchanged.On
75ffc81473merged ontomain78e4248fea(Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT, driver 32.0.32015.12012),ctest -VwithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:agc_driver_host_write_hookandagc_driver_host_write_pending_storagepass, 2 of 2, and the hook's GPU path ran again ([hostwrite] 2 host writes, 1 waited for GPU work over their range). No missing-layer line and noVUID-message. As in my first review, a runtime negative control can't be built here: the tests useHostWritesCounted, whichmaindoesn't have.check_conventions.pypasses.pr_overlap.py --branchfinds no shared exports; #8707 shares lines indocs/dev/debt/libSceAgcDriver.md, and 60 PRs that conflict withmaincouldn't be compared.Approving again at
75ffc81473.AI-assisted: yes (Claude Code)