fix(agc): keep guest stores over freed storage-image memory #6960

Closed
romainveurrier wants to merge 1 commit from upstream-pr/6960 into main
romainveurrier commented 2026-10-16 21:19:40 +00:00 (Migrated from github.com)

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:

  1. Same bytes. Outside the write watch (every Windows host import, see 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.
  2. Decision to store. writeBackLayers chooses 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 from WriteLabelOnGpu and for end-of-pipe interrupts without a label: pending results over compared memory are stored in queue order before the label.
  • The recorded GPU-direct store is used only while no label or interrupt has passed since the results became pending; later results take the compare-exchange store.
  • APS5_DEFER_COMPARED_RESULTS=1 and APS5_RECORDED_WRITEBACK=1 restore 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:

  • In watched memory an identical-byte store is still lost: unchangedSinceBaseline (dfe147fea) stores over a stamped block equal to its baseline, a rule for stamps on unchanged bytes (PPSA12544). APS5_TEST_WATCHED_SAME_BYTES=1 runs that case; it fails before and after this change.
  • Results in compared memory that were never written back before are now stored at every label: a synthetic cost probe (not part of this PR; 8 GPU-only images, a label per frame) measured, in ms per frame for 4 MiB images on 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.
  • Not yet confirmed on the title; the report asks the reporter to test this branch.

Tested

Fedora 44, Release build of main at 4986aca62 with and without this change, tests only (no title run).

  • StorageWriteBackWindowR64Kbx, links lost of 96 attempts per memory kind: main 4-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: main 8/8 lost; this PR 0/8.
  • Each with APS5_NO_HOST_IMPORT=1 (CPU path) and with the host import.
  • lavapipe: 0.4 s and 0.2 s.
  • AGC ctest selection, 132 tests (execution tests touching storage images, imports and labels; recorder, driver, graphics, pm4 and flip suites): main 129 passed per GPU, this PR 131. The two new tests account for the difference. The one remaining failure fails on main too: agc_driver_store_over_untracked on the RTX 2050 ("the result did not reach a block the CPU left alone") and agc_driver_sample_multisample_target on the Iris Xe.

Investigation report and logs attached.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA06888 #5382
  • GPUs tested: NVIDIA GeForce RTX 2050 (driver 615.71.09) and Intel Iris Xe (Mesa), Fedora 44; lavapipe
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4894399181 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960). Originally posted by [romainveurrier](https://github.com/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: 1. **Same bytes.** Outside the write watch (every Windows host import, see `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. 2. **Decision to store.** `writeBackLayers` chooses 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 from `WriteLabelOnGpu` and for end-of-pipe interrupts without a label: pending results over compared memory are stored in queue order before the label. - The recorded GPU-direct store is used only while no label or interrupt has passed since the results became pending; later results take the compare-exchange store. - `APS5_DEFER_COMPARED_RESULTS=1` and `APS5_RECORDED_WRITEBACK=1` restore 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: - In watched memory an identical-byte store is still lost: `unchangedSinceBaseline` (dfe147fea) stores over a stamped block equal to its baseline, a rule for stamps on unchanged bytes (PPSA12544). `APS5_TEST_WATCHED_SAME_BYTES=1` runs that case; it fails before and after this change. - Results in compared memory that were never written back before are now stored at every label: a synthetic cost probe (not part of this PR; 8 GPU-only images, a label per frame) measured, in ms per frame for 4 MiB images on `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. - Not yet confirmed on the title; the report asks the reporter to test this branch. ### Tested Fedora 44, Release build of `main` at 4986aca62 with and without this change, tests only (no title run). - `StorageWriteBackWindowR64Kbx`, links lost of 96 attempts per memory kind: `main` 4-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`: `main` 8/8 lost; this PR 0/8. - Each with `APS5_NO_HOST_IMPORT=1` (CPU path) and with the host import. - lavapipe: 0.4 s and 0.2 s. - AGC ctest selection, 132 tests (execution tests touching storage images, imports and labels; recorder, driver, graphics, pm4 and flip suites): `main` 129 passed per GPU, this PR 131. The two new tests account for the difference. The one remaining failure fails on `main` too: `agc_driver_store_over_untracked` on the RTX 2050 ("the result did not reach a block the CPU left alone") and `agc_driver_sample_multisample_target` on the Iris Xe. Investigation report and logs attached. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA06888 #5382 - [x] GPUs tested: NVIDIA GeForce RTX 2050 (driver 615.71.09) and Intel Iris Xe (Mesa), Fedora 44; lavapipe - [x] AI-assisted: yes
romainveurrier commented 2026-10-16 21:40:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by romainveurrier on 2026-10-16T21:40:35Z.


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.
Pull request Conflicting files (lines on main) Same exports Same new files
PR 6108 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp L351
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L2056
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L4682-4683
PR 6367 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L4863-4865
PR 6820 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L4863-4865
PR 6914 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L89

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.
Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 1896 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4048 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4072 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 4472 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4650 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4891 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5390 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5431 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5441 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5480 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5499 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5761 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5987 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6177 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6222 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6259 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6503 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6539 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6553 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6718 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp

Overlap check:

  • #6108, #6914: adjacent additions only (accessor next to UntrackedCompares(), counter near keyFlipKept); trivial to reconcile. #6914 is the same family (a deferred write-back landing in recycled memory); its hold in pendingUnitInside also applies to the stores this PR makes before a label, since they go through FlushPending.
  • #6197: this PR moves the HostImportFor lookup of writeBackLayers before the keep decision; if #6197 goes first, that moved lookup becomes HostImportSpanning.
  • #6367 (and #6820 through it): both change the CPU path's read of unsaved guest bytes. This PR needs that read before the keep decision (it is what the compare-exchange expects); #6367 restricts it to the kept ranges, which are only known after. Reconciled, the read stays before the decision, restricted to registered ranges. @Zenodeon, I'm happy to rebase on #6367 once it's merged.

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225223255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960#issuecomment-6225223255). Originally posted by [romainveurrier](https://github.com/romainveurrier) on 2026-10-16T21:40:35Z. --- > 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**. > Pull request Conflicting files (lines on `main`) Same exports Same new files > [PR 6108](https://www.github.com/boykopovar/AnyPS5/pull/6108) `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` [L351](https://github.com/boykopovar/AnyPS5/blob/c7b6f2d12e90a0b935326469dc52f331fbb56c38/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp#L351) > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L2056](https://github.com/boykopovar/AnyPS5/blob/c7b6f2d12e90a0b935326469dc52f331fbb56c38/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L2056) > [PR 6197](https://www.github.com/boykopovar/AnyPS5/pull/6197) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L4682-4683](https://github.com/boykopovar/AnyPS5/blob/c7b6f2d12e90a0b935326469dc52f331fbb56c38/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L4682-L4683) > [PR 6367](https://www.github.com/boykopovar/AnyPS5/pull/6367) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L4863-4865](https://github.com/boykopovar/AnyPS5/blob/c7b6f2d12e90a0b935326469dc52f331fbb56c38/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L4863-L4865) > [PR 6820](https://www.github.com/boykopovar/AnyPS5/pull/6820) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L4863-4865](https://github.com/boykopovar/AnyPS5/blob/c7b6f2d12e90a0b935326469dc52f331fbb56c38/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L4863-L4865) > [PR 6914](https://www.github.com/boykopovar/AnyPS5/pull/6914) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L89](https://github.com/boykopovar/AnyPS5/blob/c7b6f2d12e90a0b935326469dc52f331fbb56c38/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L89) > > 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. > Pull request Shared files not compared > [PR 1368](https://www.github.com/boykopovar/AnyPS5/pull/1368) `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 1896](https://www.github.com/boykopovar/AnyPS5/pull/1896) `core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp` > `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp` > `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 4040](https://www.github.com/boykopovar/AnyPS5/pull/4040) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 4048](https://www.github.com/boykopovar/AnyPS5/pull/4048) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 4072](https://www.github.com/boykopovar/AnyPS5/pull/4072) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 4448](https://www.github.com/boykopovar/AnyPS5/pull/4448) `core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp` > `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 4472](https://www.github.com/boykopovar/AnyPS5/pull/4472) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 4650](https://www.github.com/boykopovar/AnyPS5/pull/4650) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 4891](https://www.github.com/boykopovar/AnyPS5/pull/4891) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` > `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 5390](https://www.github.com/boykopovar/AnyPS5/pull/5390) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 5431](https://www.github.com/boykopovar/AnyPS5/pull/5431) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 5441](https://www.github.com/boykopovar/AnyPS5/pull/5441) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 5480](https://www.github.com/boykopovar/AnyPS5/pull/5480) `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp` > `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 5499](https://www.github.com/boykopovar/AnyPS5/pull/5499) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 5609](https://www.github.com/boykopovar/AnyPS5/pull/5609) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 5761](https://www.github.com/boykopovar/AnyPS5/pull/5761) `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 5987](https://www.github.com/boykopovar/AnyPS5/pull/5987) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) `core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp` > `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` > `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp` > `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 6259](https://www.github.com/boykopovar/AnyPS5/pull/6259) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 6503](https://www.github.com/boykopovar/AnyPS5/pull/6503) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > [PR 6539](https://www.github.com/boykopovar/AnyPS5/pull/6539) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 6553](https://www.github.com/boykopovar/AnyPS5/pull/6553) `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` > [PR 6718](https://www.github.com/boykopovar/AnyPS5/pull/6718) `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` > `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` > `core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` Overlap check: - #6108, #6914: adjacent additions only (accessor next to `UntrackedCompares()`, counter near `keyFlipKept`); trivial to reconcile. #6914 is the same family (a deferred write-back landing in recycled memory); its hold in `pendingUnitInside` also applies to the stores this PR makes before a label, since they go through `FlushPending`. - #6197: this PR moves the `HostImportFor` lookup of `writeBackLayers` before the keep decision; if #6197 goes first, that moved lookup becomes `HostImportSpanning`. - #6367 (and #6820 through it): both change the CPU path's read of unsaved guest bytes. This PR needs that read before the keep decision (it is what the compare-exchange expects); #6367 restricts it to the kept ranges, which are only known after. Reconciled, the read stays before the decision, restricted to registered ranges. @Zenodeon, I'm happy to rebase on #6367 once it's merged. 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.
CnRJay commented 2026-10-16 22:07:27 +00:00 (Migrated from github.com)

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 (main loses 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:

  • Bound the label store to the surfaces the existing small-store rule covers (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.
  • Or gate the new store on the image's results having been read back before (the image is known to be CPU-visible), so GPU-only targets are never touched.
  • Whichever is chosen, the per-frame cost on a title with several large GPU-only targets and a label per frame belongs in the test, as a bound, not in the description as a known limit.

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5554223130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960#pullrequestreview-5554223130). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-16T22:07:27Z. **Review:** COMMENTED --- The bug is real and the two tests show it (`main` loses 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: - Bound the label store to the surfaces the existing small-store rule covers (`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. - Or gate the new store on the image's results having been read back before (the image is known to be CPU-visible), so GPU-only targets are never touched. - Whichever is chosen, the per-frame cost on a title with several large GPU-only targets and a label per frame belongs in the test, as a bound, not in the description as a known limit. 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.
keravyn-ops commented 2026-10-17 09:21:44 +00:00 (Migrated from github.com)

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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232233938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960#issuecomment-6232233938). Originally posted by [keravyn-ops](https://github.com/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).
hugodearaujo commented 2026-10-18 19:43:21 +00:00 (Migrated from github.com)

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), main e5f18ea99 with #6343, #7606 and #7413.

  • Without this PR, 3 runs. One crashed in the title's own allocator 280 s after start with the signature of #5934: the memory around the chunk it was splitting (0x10f4ae7e00–0x10f4ae8800) held the repeated texel 0xff1b181c where 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.
  • With this PR's head 36df6631b merged 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, amdgpu ring 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254309327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960#issuecomment-6254309327). Originally posted by [hugodearaujo](https://github.com/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), `main` e5f18ea99 with #6343, #7606 and #7413. - Without this PR, 3 runs. One crashed in the title's own allocator 280 s after start with the signature of #5934: the memory around the chunk it was splitting (0x10f4ae7e00–0x10f4ae8800) held the repeated texel `0xff1b181c` where 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. - With this PR's head 36df6631b merged 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`, amdgpu `ring 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.
MarcZX10 commented 2026-10-20 06:39:34 +00:00 (Migrated from github.com)

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 0x42 to 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285023745 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960#issuecomment-6285023745). Originally posted by [MarcZX10](https://github.com/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 `0x42` to 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.
orezraey commented 2026-10-22 00:33:30 +00:00 (Migrated from github.com)

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

  • main 6b6c701636
  • this PR at 36df6631b6, cherry-picked onto that main (it conflicts today). In Texture.hpp I kept both WaitForFlushing and StoreBeforeGuestCompletion; in Texture.cpp I kept both atomic blocks and took this PR's side of the third hunk (the late ReadCommitted block 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 an APS5_PAD_INPUT_FILE timeline (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.

Build Runs Crashed Reached gameplay
main 5 2 (40 s in the menu; 165 s while loading the new save) 3
this PR 5 0 5

Both 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], rbx with rdx = 0). The broken headers sat at 0x2359bbff0 and 0x235ec4ff8, 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:

Switch Runs Crashed
none 6 4
APS5_GPU_NO_WRITEBACK=1 4 0
APS5_STORE_AT_LABEL=1 3 0
APS5_NO_UNIT_SHADOW=1 3 0

No 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329738834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6960#issuecomment-6329738834). Originally posted by [orezraey](https://github.com/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** - `main` 6b6c701636 - this PR at 36df6631b6, cherry-picked onto that `main` (it conflicts today). In `Texture.hpp` I kept both `WaitForFlushing` and `StoreBeforeGuestCompletion`; in `Texture.cpp` I kept both atomic blocks and took this PR's side of the third hunk (the late `ReadCommitted` block 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 an `APS5_PAD_INPUT_FILE` timeline (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. | Build | Runs | Crashed | Reached gameplay | |---|---:|---:|---:| | `main` | 5 | 2 (40 s in the menu; 165 s while loading the new save) | 3 | | this PR | 5 | 0 | 5 | Both 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], rbx` with `rdx = 0`). The broken headers sat at `0x2359bbff0` and `0x235ec4ff8`, 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: | Switch | Runs | Crashed | |---|---:|---:| | none | 6 | 4 | | `APS5_GPU_NO_WRITEBACK=1` | 4 | 0 | | `APS5_STORE_AT_LABEL=1` | 3 | 0 | | `APS5_NO_UNIT_SHADOW=1` | 3 | 0 | No `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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6960
No description provided.