fix(agc): store an image-copied buffer copy's destination before later labels #6324
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6324"
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 ps54all on 2026-10-15T11:42:27Z.
What
VulkanDevice::CopyBufferturns a copy whose source range is exactly a live storage image into a device copy between storage images (AliasCopy,StorageTexture::CopyFrom). The copied bytes then stay in the destination image as pending results, like a shader's: they reach guest memory only when something in the driver reads that range (FlushPendingthrough the flush hook), at the idle store, or at a flip/label whenAPS5_STORE_AT_LABEL/APS5_STORE_AT_FLIPis set. A guest that reads the destination on the CPU after waiting for a label that follows the copy, which is how a GPU readback works, reads the bytes that were there before the copy: the CPU read does not go through the driver.HOT WHEELS Infinite Rush (PPSA22408, Unreal Engine) copies its 256 KiB GPU message buffer into a readback buffer every frame with a DMA copy, waits for the frame's label and walks the records (
[count][id, payload dwords, payload...]). The message buffer's range is also exactly the surface of a live storage image the driver still caches (transient memory the engine reuses), so the copy takes the image path, the readback buffer keeps old vertex data, the walker reads a float as a record length and faults (RenderThread 0,app.exe+0x93f044, read of0x125...4758) at 115-140 s into every run. With a temporary trace of copies into the readback range:The source holds an empty message buffer (count 0); the destination still holds floats when the CPU reads it.
After
AliasCopysucceeds,CopyBuffernow stores the destination image's results at once (FlushPending(destination, bytes, nullptr, "buffer copy destination", PublishScope::Whole)). The store is recorded in the same batch behind the image copy, so a label recorded after the copy is ordered behind it, as it is for the transfer path. The destination image stays cached, so GPU readers of the destination keep using it.Tested
New test
agc_driver_alias_copy_label(tests/execution/AliasCopyLabel.cpp): a compute store leaves a pending 256x256 R32_UINT image over a 256 KiB source,CopyBuffercopies it to a second 256 KiB range (asserts the image-copy path), a label is recorded on the GPU after it and submitted, the test spins on the label with plain CPU reads and then compares the destination's raw bytes with the source. On main: 262144 of 262144 bytes still unwritten (5 of 5 runs). With the change: 0 (5 of 5 runs).ctest -R agc_589/589 passed (3 skipped for device features);tools/check_conventions.py --base origin/mainandtools/check_test_registration.pypass.0afa6a607the crash above in every run (3 of 3). With the change: alive in 3 runs of 420/420/300 s, title screen at 4.9-5.3 FPS (4.5-4.9 withAPS5_NO_COPY_ALIAS=1, 2.0-2.9 withAPS5_STORE_AT_LABEL=1, both of which also avoid the crash); "PRESS ANY BUTTON", then the first-run settings screen. Gameplay not reached yet (the title runs at ~5 FPS).Related: #6249 (alias copies of surfaces with padding lose bytes outside the image) changes
AliasCopy's eligibility; this PR does not touch it and the two apply independently. #5480 moves alias selection intoPlanAlias; the store here belongs after whichever alias path succeeds.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:18:45Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppImported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T20:43:39Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with
21cdb8f05merged into maince991f1ec:agc_driver_alias_copy_labelpasses.AGC graphics: a CPU read after the label that followed the image copy found 262144 of 262144 destination bytes still unwritten.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-16T00:21:12Z.
Hot Wheels (PPSA22408) at head
21cdb8f05: segfault about three minutes in, not fixed by this PRSetup
21cdb8f05, clean worktree, Release, with itslibstargets builtResult
app.elf+0x5641523, a null read right after a virtual call.mainwithout this PR, so we cannot say yet whether the crash is new.What the debugger showed
Not established
mainrun to compare).@coltken95 you reported the Hot Wheels crash earlier. If you have symbols or a
mainrun for this title, that would show whether the crash is new. We will keep the debugger captures if they are useful.AI-assisted; the build and runs are from my machine, and the analysis is from disassembly, not a symbolized build.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-16T06:49:06Z.
Thanks for the runs. On Windows (RTX 3080, NVIDIA 610.74) the crash this PR addresses looks different: without the change the title dies at 115-295 s on the RenderThread with a wild read in a loop that walks UE's GPUMessage readback stream (a record length read back as float bits, e.g. 0xc43fd1d5, sends the index negative). With the change, three runs stayed alive for 420, 420 and 300 s with no fault and reached the first-run settings screen at about 5 FPS.
Your fault (a null read after a virtual call that returns zero from an empty lookup table) does not match that signature, so it is probably a separate stop further on; it would help to know whether
mainwithout this PR dies earlier (at the readback crash) or at the same+0x5641523. Ifmaindies earlier, that also confirms the PR on Linux. I have not run the title on Linux.AI-assisted (Claude Code); numbers from runs on my machine.
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-16T09:15:30Z.
Hot Wheels (PPSA22408): correction, the crash we reported here was caused by our setup
The null read at
app.elf+0x5641523(Linux) andapp.exe+0x5651523(Windows) came from our runtime, not from AnyPS5 or this PR. We had replaced the title's EOS SDK (EOSSDK-PS5-Shipping) with a stub that returns 0 from every call. The title then never registers itsMILESTONEEOSonline subsystem, and later looks it up and dereferences null.Relinking the title's own
prx/modules (eossdk-ps5-shipping.prxand thekittmodules) removes that crash. The title then reaches the shader abort from #6117, which #6160 fixes (results on #6160).For this PR: no regression on Linux, and the crash above happens with or without it.
AI-assisted: this comment was drafted with the help of Claude Code and checked against the logs by us.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-17T13:10:12Z.
Intel and AMD Windows data: the new test passes on both GPUs with this change and fails on both without it, as on the RTX 3080.
Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. "Without" means this PR's test files onmainc9e6c45de, with none of its other changes.21cdb8f05merged intomain673f7406c:agc_driver_alias_copy_label, ×3a CPU read after the label that followed the image copy found 262144 of 262144 destination bytes still unwrittenFull CTest (
--parallel 4) onmainc9e6c45dewith seven open GPU PRs merged (#6258, #6657, #6324, #6246, #6174, #6360, #6598): UHD 770 1381 of 1389, RX 9070 XT 1383 of 1389.mainalone passes 1378 of 1385 and 1381 of 1385. The merge adds only two failures:agc_buffer_pool(#6174, both GPUs) andagc_driver_indirect_dispatch_limit(#6360, RX 9070 XT).AI-assisted: yes (Claude Code)