fix(agc): keep guest stores over freed storage-image memory #6960
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6960"
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 romainveurrier on 2026-10-16T21:19:40Z.
What
SONIC SUPERSTARS crashes in its allocator after respawns: the free-list links at the start of a freed 64 KiB block hold
0x00ffffff00ffffff, the texels of a 32x32 RGBA8 R64KBX storage image at that address (#5934). The image's results stay on the GPU past the label after its dispatch and are stored later, when the title may have freed the block. Two cases lose the title's stores:decideImportWatch), a CPU store is found only by comparing with the bytes saved at upload. A free that writes the links the block already held reads as no store, and the results are stored over it. Deterministic.writeBackLayerschooses the 64 KiB blocks the CPU owns, then stores the others after a GPU round trip (CPU path) or when the recorded copy runs (import path). A CPU store landing in between is overwritten. On the CPU path the bytes the store compares against were also read after the decision.Changes:
GuestMemory::WriteChangedOverOriginal[Committed]: each changed 8-byte word is stored by compare-exchange against the bytes the decision used, now read before the decision. A refused range leaves its layers stale, so they re-upload.StorageTexture::StoreBeforeGuestCompletion, called fromWriteLabelOnGpuand for end-of-pipe interrupts without a label: pending results over compared memory are stored in queue order before the label.APS5_DEFER_COMPARED_RESULTS=1andAPS5_RECORDED_WRITEBACK=1restore the previous behaviour of each part, for comparison.New tests, through
AgcDriver::Submit(PM4 dispatch, then a RELEASE_MEM label the test waits for, then CPU stores; no hooks):StorageWriteBackWindowR64Kbx: links stored at random times around a driver read that triggers the write-back, in compared and in watched memory.StorageSameBytesReuseR64Kbx: the block freed with the links it held at upload.Not addressed:
unchangedSinceBaseline(dfe147fea) stores over a stamped block equal to its baseline, a rule for stamps on unchanged bytes (PPSA12544).APS5_TEST_WATCHED_SAME_BYTES=1runs that case; it fails before and after this change.main-> this PR: RTX 2050 2.7 -> 18.6 (import) and 2.6 -> 32.3 (CPU path), Iris Xe 4.6 -> 21.4 (import) and 4.5 -> 33.9 (CPU path); for 256 KiB images RTX 2050 0.22 -> 1.29 (import). Watched memory is unaffected. No title measured.Tested
Fedora 44, Release build of
mainat4986aca62with and without this change, tests only (no title run).StorageWriteBackWindowR64Kbx, links lost of 96 attempts per memory kind:main4-21 per GPU, path and memory kind; this PR 0 in every case. In watched memory 16–29 attempts per run had the compare-exchange keep a store made after the decision.StorageSameBytesReuseR64Kbx:main8/8 lost; this PR 0/8.APS5_NO_HOST_IMPORT=1(CPU path) and with the host import.main129 passed per GPU, this PR 131. The two new tests account for the difference. The one remaining failure fails onmaintoo:agc_driver_store_over_untrackedon the RTX 2050 ("the result did not reach a block the CPU left alone") andagc_driver_sample_multisample_targeton the Iris Xe.Investigation report and logs attached.
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 file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by romainveurrier on 2026-10-16T21:40:35Z.
Overlap check:
UntrackedCompares(), counter nearkeyFlipKept); trivial to reconcile. #6914 is the same family (a deferred write-back landing in recycled memory); its hold inpendingUnitInsidealso applies to the stores this PR makes before a label, since they go throughFlushPending.HostImportForlookup ofwriteBackLayersbefore the keep decision; if #6197 goes first, that moved lookup becomesHostImportSpanning.This PR is a draft until the #5934 reporter tests it in-game, so the others can go first; I'll rebase. Depends on: none.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T22:07:27Z.
Review: COMMENTED
The bug is real and the two tests show it (
mainloses 4-21 of 96 stores, this PR 0). The cost is the problem, and the PR already measures it."Results in compared memory that were never written back before are now stored at every label": 2.7 to 18.6 ms per frame (RTX 2050, import path) and 2.6 to 32.3 ms (CPU path) for 4 MiB images, 4.6 to 21.4 / 4.5 to 33.9 ms on the Iris Xe, 0.22 to 1.29 ms for 256 KiB images. That is a GPU-to-CPU round trip of every pending storage image at every label, on by default, for every title on every Windows host import. A title that writes a few large GPU-only render targets and has a label per frame goes from 60 fps to about 30 for this fix alone. "No title measured" does not make that acceptable, and storing at every label is the wrong approach: the SONIC SUPERSTARS case is a 32x32 RGBA8 image in a 64 KiB block, and the large images never needed this.
What I would do instead:
StorageTexture::SmallStoreBytes, 64 KiB), which is the class that shares a block with something a title allocates over. Large render targets stay on the current path.Please also post the cost on the title this was found on (SONIC SUPERSTARS), with the summary lines of main and this PR from the same scene, no
APS5_PROFILE_*. The report asks the reporter to test the branch; until they have, the PR can't show that the crash is gone or what it costs.#6948 stores linear storage images after every dispatch for a similar reason and touches the same write-back path; the two should be reconciled so that a label does not store the same image twice.
Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T09:21:44Z.
AMD / Windows run of this PR at
36df6631b: 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.agc_driver_storage_same_bytes_reuse_r64_kbx: pass (0.39 s)agc_driver_storage_write_back_window_r64_kbx: pass (0.56 s)AI-assisted: yes (runs made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-18T19:43:21Z.
Data point from Linux, AMD Radeon RX 9070 XT, RADV (Mesa 26.2.5): EA SPORTS FC 25 (PPSA20049),
maine5f18ea99with #6343, #7606 and #7413.0xff1b181cwhere its heap headers should be, and that memory lies inside a 1920x1080 RGBA8 storage image created earlier at 0x10f4800000. Another reached Kick Off but sat on its tunnel scene with no menu and did not react to input. The third lost the GPU under gdb before that.36df6631bmerged on top, 2 runs. Both reached Kick Off's menus; one went on through team and kit selection to the pre-match cutscene, where it lost the GPU (VK_ERROR_DEVICE_LOST, amdgpuring gfx_0.0.0 timeout). That also happened once without this PR, so I'm treating it as a separate issue.Few runs, so this is a hint, not proof.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T06:39:34Z.
I am investigating issue #8152, where a CPU write to the right half of a resident linear target shares 64 KiB blocks with a recorded draw to the left. I added a local regression variant that seeds the left half, draws only there, writes
0x42to the right half, and checks that both results survive. It compiles, but this host's CPU guard prevents the AGC test from running.Does #6960's GPU-direct imported write-back path cover that partial-draw case? The current-main block selection can retain a whole touched block, preserving the CPU bytes while dropping GPU output elsewhere in that block. I want to coordinate this with your write-back changes before opening a related PR.
Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-22T00:33:30Z.
Data point: Cult of the Lamb (PPSA06465, 01.000.023) hits the same corruption as #5934 on
main, and does not with this PR.Build
main6b6c70163636df6631b6, cherry-picked onto thatmain(it conflicts today). InTexture.hppI kept bothWaitForFlushingandStoreBeforeGuestCompletion; inTexture.cppI kept both atomic blocks and took this PR's side of the third hunk (the lateReadCommittedblock removed).Host: Windows 11 Pro 26200, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti, driver 616.64, 239 Hz display, AC. Shader cache warm.
Method:
APS5_PROFILE_DRAW=1, input from anAPS5_PAD_INPUT_FILEtimeline (cross at the splash, Play, then New Save), each run 250 s from launch, all on 2026-10-21. The machine was in normal desktop use during the runs.mainBoth crashes are an access violation inside Unity's TLSF allocator (
ALLOC_GFX_THREAD), unlinking a free block whose header is no longer valid (mov [rdx+0x18], rbxwithrdx = 0). The broken headers sat at0x2359bbff0and0x235ec4ff8, in the region where the title sub-allocates its textures and storage images.Earlier runs on the same
main, driven by keyboard, toggling one switch at a time:APS5_GPU_NO_WRITEBACK=1APS5_STORE_AT_LABEL=1APS5_NO_UNIT_SHADOW=1No
VUID-lines in any log; presents per 10 s are the same on both builds (about 430 to 590).Analysis (AI-assisted, not measured): the switches point at a deferred write-back of a GPU-written 64 KiB unit landing after the title's label, over memory the allocator had already freed and reused for the next block's header, which is what this PR stops.
Logs on request.
Pull request closed