fix(agc): store pending storage results before a use writes the same memory as a buffer #4654
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4654"
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 GustavoGamarra95 on 2026-10-12T17:56:46Z.
What
Before a dispatch or draw that writes buffer ranges is recorded, the results of storage images still pending in those ranges are now stored (
GuestBufferMemory::UploadFinish), whatever path serves the range: in place, copied, or a leased address-based heap, which the per-region flush exempts. A revalidated resource set also includes its written ranges in the pending scan.Without it, the image's write-back could follow the buffer write in two ways:
Unreal Engine's render graph transient allocator reuses the same memory for textures and buffers within a frame. In Beast of Reincarnation (PPSA29343) at 1080p output,
APS5_CAPTURE_TRACEshowed a 60x34 R16G16 float tile image written by a compute pass and left pending, then a 40800-byte buffer written at the same address by another dispatch, then the image written back when a later pass read the buffer. The title screen showed 64x64-pixel blocks of stale content, a stepped dark area and stray fragments.r.RDG.TransientAllocator=0in the title'ssaved/ps5/engine.iniremoves them, which is how the aliasing was first confirmed.Tested
Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, GCC, Release. RTX 3050 Laptop 4 GB (NVIDIA 615.78.08) and Radeon 660M (RADV, Mesa).
main;tools/check_conventions.pypasses.cteston the RTX 3050: 964 of 964 pass (7 of them skipped: thevideo_out_flip/frame_dumptests andagc_driver_stencil_ref_export).agc_storage_written_buffer_order: a storage image is written on the GPU and left pending, then a leased address-based use writes the first 40800 bytes of the same memory as a buffer and every pending image is flushed; guest memory must hold the buffer's bytes where it wrote and the image's texels everywhere else. It runs with watched and compared imports and returns 77 when host imports or write watching are unavailable. Drivers selected withVK_DRIVER_FILES:r.RDG.TransientAllocator=0the title is unchanged.The title was not run on the Radeon 660M (too slow there to reach it); the RADV coverage is the test above.
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 Scramblrrrr on 2026-10-12T18:03:55Z.
Preparing a Windows/RTX5070Ti cross-test in the older 007 integration, preserving your authorship: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-written-buffer-order head24d8fe68efaffac18dadaf898228c6f547138f66. Your production/test commits ported as91ca6f84f and24d8fe68e. UploadFinish conflict resolved by retaining the existing CompletePendingCpuWrites pass before uploaded=true, then your written-range flush before import lookup; both CTest registrations retained. Conventions pass. Source-only, not built/staged or a claimed fix yet; current game still runs preceding5b8661ad2. Will run your native regression and an isolated production negative control before the next game comparison. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T18:13:10Z.
Windows native validation complete on the credited port24d8fe68e, RTX5070Ti/compared host imports: agc_storage_written_buffer_order PASS0.51s, no skip. Isolated negative: restoring only your two production files to preceding5b8661ad2, leaving the fixture unchanged, FAIL0.42s with storage results outside the written buffer did not reach guest memory. Restoring the fix:6/6 focused ordering tests PASS2.24s (your regression, copied_direct_ordering, depth_surface_last_writer, image_indirect_arguments_written_ahead, original indirect_arguments_written_ahead, write_data_written_ahead), no skips. Added a separate public synthetic image-to-indirect fixture in c9774f7265c08cf835864e12b92ed879834fa575; default GPU-capable path passes and logs the expected argument flush. Its optional thread-dimension mode reproduces a different stale-read case on this integration, not a claimed current-main defect or #4654 regression. Conventions pass. Starting the007 comparison with graphics SHA2569C990502..., same libc7540B4D8... and12GiB config. No title/FPS effect claimed yet. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T18:18:35Z.
@Scramblrrrr thanks for validating it on Windows with the RTX 5070 Ti and compared imports, and for the isolated negative control: that is the platform and import mode I could only cover with RADV and lavapipe here. Looking forward to the 007 comparison.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T18:29:10Z.
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/CMakeLists.txtL904core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL2911Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T18:41:16Z.
@TibixDev #1359 and this PR overlap in the first lines of
GuestBufferMemory::UploadFinishand in neighbouring test registrations inCMakeLists.txt. The changes are independent: the resolution keeps yourCompletePendingCpuWritespass beforeuploaded = true, then this PR's written-range flush, with both ctest entries (Scramblrrrr merged them that way in their 007 integration and the tests pass). Either order works for me; if #1359 lands first I'll rebase this one.Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-13T00:54:32Z.
@oneandonlydean when you have time, could you also take a look at this one? It touches the same storage write-back paths as #4468: it stores an image's pending results before a use writes the same memory as a buffer. Scramblrrrr validated it on Windows with compared imports, including a negative control. It overlaps #1359 in the first lines of
UploadFinish; the resolution is described above.Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T03:46:41Z.
A Windows run on NVIDIA and Intel, to add to the Linux drivers in the table.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head
554e61552merged intomain495bf91a0, which passes 1023 of 1023 on both GPUs.agc_storage_written_buffer_orderand the other 16 recorder and graphics entries the changed test file feeds pass on both GPUs with--repeat until-fail:3. The new test ran on both, without returning 77. The full suite (ctest --timeout 120 --parallel 4) passes 1024 of 1024 on both.GuestBufferMemory.cppandShaderResources.cppas onmain,agc_storage_written_buffer_orderfails on both GPUs withthe storage results outside the written buffer did not reach guest memory, and the other 16 pass.Written with AI assistance.