fix(agc): finish an idle store's write-back before returning #16011

Merged
JJenkx merged 5 commits from upstream-pr/16011 into main 2026-11-15 19:50:26 +00:00
JJenkx commented 2026-11-05 09:50:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-05T09:50:18Z.


What

The idle store (VulkanDevice::StoreIdleResults → StorageTexture::FlushAllPendingUntil("idle")) records each pending storage image's write-back into the open recorder batch. FlushPending synced the recorder after an idle flush only when it published unit shadows (db3af40970). A plain write-back into the host import publishes none, so its copies stayed in the open batch until the store's final submit, and nothing waited for them. The same held for depth and stencil planes, which FlushDepthPlanes stores inside the idle FlushPending under the reason "depth plane store".

Nothing ties the idle store to a point the title can observe. A CPU store made after the idle flush returned and before the GPU ran the copy was overwritten with the image's contents.

FlushPending now syncs after an idle flush that stored any image or any depth or stencil plane, also when nothing is published. Other flush reasons are unchanged; the access that triggers them orders them.

One window remains, recorded in the queue-idle debt entry: a CPU store made while a piece's copies are running is still not ordered against them.

#13863 and #13920 re-indent the same block in FlushPending. That is a textual conflict only; neither changes this condition.

#6926 is related but separate. It orders host writes (GuestArena::HostWrite: file and APR reads, recv) after the GPU writes pending over their destination. This PR makes the idle store itself complete before it returns, which also covers the title's own CPU stores. Those do not go through a host-write scope.

Tested

Current integration and regression qualification — 2026-11-09. Head 71aae52449a184e854753088f04a77cbe16d1c93 includes main 7259cce11195f360698772da8c0b3af756bf7c8f and preserves the production idle-store fix. The storage fixture now compiles a real image-store shader and drives a retained VulkanDevice on the flushing thread. After the idle flush returns it asserts that the active recorder has no pending write for the stored range. It drains pending work before reporting a failure, so the old-source control has safe cleanup.

Linux 7.2.14-arch1-1, GCC 16.2.1 Release, AMD Radeon RX 6650 XT / RADV NAVI23, Mesa 26.2.6. With required Vulkan, no shader cache and the confirmed Khronos layer, the strengthened fixture passes 3/3, fails against exact main's Texture.cpp at the outstanding-write assertion, then passes 3/3 after exact restoration. Zero skips or VUIDs; all ten recorded source, module and executable hashes match after restoration. This addresses the later review that the earlier fixtures could pass without the fix; their old observations below retain their original pins and are not reliable negative controls on this refreshed tree. An initial attempt without the validation layer is explicitly excluded from this qualification.

Current main automatically registers execution fixtures. The recorded CTest JSON confirms agc_driver_storage_idle_store_completes is registered; the shared registration supplies SKIP_RETURN_CODE 77 and the Windows runtime PATH setup. No duplicate add_test was added. The existing depth-plane case is preserved, but no new negative-control claim is made for that case.

Build logs, frozen fixture, main/source control, exact restoration and validation receipts, SHA-256 e3db99d95de12d09ea6dbd5d1345dacd3b0cc58054b68cd5256ca6a65135ff9a (download and all 36 manifest files verified). No new Windows, title, FPS, full-SDK or hosted-CI pass is claimed; current full CI needs a maintainer dispatch.

Earlier qualifications retain their stated source/platform scope.

Linux 7.2.11, AMD RX 6650 XT (RADV Mesa 26.2.6), Release. The tests ran on main 1e24993fa3 with this commit. The branch is the same commit cherry-picked cleanly onto 7ad9749ed0; there Texture.cpp differs only by #12813's log gating.

Historical tests at the original pins

  • agc_driver_storage_idle_store_completes: a CPU store made after the idle flush returns must survive the image's write-back.
    • On main it fails 5 of 5 runs: 983,040 of 1,048,576 bytes are overwritten over 8 rounds.
    • With this change it passes 20 of 20 runs: 0 bytes are overwritten.
  • agc_driver_depth_plane_cpu_store_after_idle_flush (a new case in DepthPlanePartialStore): the same check for a depth plane.
    • On main it fails: unit 0 holds 0 of its 16,384 CPU-written texels.
    • With this change it passes, and so do the other 16 agc_driver_depth_plane* tests.

Full suites with this change

  • CPU: 2,962 of 2,962 passed.
  • GPU (agc_driver*, video_out*, vulkan*): 996 of 996 passed. Rerun on head 4ff434e1a4 (the follow-up that takes the GPU mutex in the idle wait only for an idle flush): 996 of 996, including both new tests.

Windows, RDNA3 (report by @DonRyuzaki): head 4ff434e1a4 on main d23df92b38, Windows 11, RX 7800 XT, WinLibs GCC 15.2, Release, validation layer on. agc_driver_storage_idle_store_completes passed 5 runs and agc_driver_depth_plane_cpu_store_after_idle_flush passed 3. Their layer reported only VUID-VkDeviceCreateInfo-pNext-pNext at device creation, also on a main control. They did not repeat the main-side failure.

Cost check on a slow title: Thymesia (PPSA05213) runs at about 6 FPS here. Its frame gaps exceed the 50 ms idle threshold, so idle stores start between frames, which is where this change adds waits. Eight 185 s runs with the same input, alternating in two orders, main 1e24993fa3 against the same base with this change, no compiler running. Median FPS after 90 s: main 6.47, 5.76, 5.60, 6.38 (mean 6.05); this change 6.29, 5.70, 6.38, 5.62 (mean 6.00). That is -0.9%, inside the spread of either arm, so I measured no cost. All eight runs exit 0. No performance claim either way.

Not claimed: no title result or performance change. I found the race while investigating an intermittent ASTRONEER (PPSA27623) load crash (#8746). This change does not stop that crash: 3 of 12 runs crashed with it, against about 4 of 11 on main.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6650 XT (RADV NAVI23), Mesa 26.2.6, Linux 7.2.14 (current qualification); AMD Radeon RX 7800 XT, Windows 11 (historical independent report linked above)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5169508794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16011). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-05T09:50:18Z. --- ### What The idle store (`VulkanDevice::StoreIdleResults` → `StorageTexture::FlushAllPendingUntil("idle")`) records each pending storage image's write-back into the open recorder batch. `FlushPending` synced the recorder after an idle flush only when it published unit shadows (db3af40970). A plain write-back into the host import publishes none, so its copies stayed in the open batch until the store's final submit, and nothing waited for them. The same held for depth and stencil planes, which `FlushDepthPlanes` stores inside the idle `FlushPending` under the reason "depth plane store". Nothing ties the idle store to a point the title can observe. A CPU store made after the idle flush returned and before the GPU ran the copy was overwritten with the image's contents. `FlushPending` now syncs after an idle flush that stored any image or any depth or stencil plane, also when nothing is published. Other flush reasons are unchanged; the access that triggers them orders them. One window remains, recorded in the queue-idle debt entry: a CPU store made while a piece's copies are running is still not ordered against them. #13863 and #13920 re-indent the same block in `FlushPending`. That is a textual conflict only; neither changes this condition. #6926 is related but separate. It orders host writes (`GuestArena::HostWrite`: file and APR reads, `recv`) after the GPU writes pending over their destination. This PR makes the idle store itself complete before it returns, which also covers the title's own CPU stores. Those do not go through a host-write scope. ### Tested <!-- codex-nov9-idle-recorder-71aae524 --> **Current integration and regression qualification — 2026-11-09.** Head `71aae52449a184e854753088f04a77cbe16d1c93` includes main `7259cce11195f360698772da8c0b3af756bf7c8f` and preserves the production idle-store fix. The storage fixture now compiles a real image-store shader and drives a retained `VulkanDevice` on the flushing thread. After the idle flush returns it asserts that the active recorder has no pending write for the stored range. It drains pending work before reporting a failure, so the old-source control has safe cleanup. Linux 7.2.14-arch1-1, GCC 16.2.1 Release, AMD Radeon RX 6650 XT / RADV NAVI23, Mesa 26.2.6. With required Vulkan, no shader cache and the confirmed Khronos layer, the strengthened fixture passes **3/3**, fails against exact main's `Texture.cpp` at the outstanding-write assertion, then passes **3/3** after exact restoration. Zero skips or VUIDs; all ten recorded source, module and executable hashes match after restoration. This addresses the later review that the earlier fixtures could pass without the fix; their old observations below retain their original pins and are not reliable negative controls on this refreshed tree. An initial attempt without the validation layer is explicitly excluded from this qualification. Current main automatically registers execution fixtures. The recorded CTest JSON confirms `agc_driver_storage_idle_store_completes` is registered; the shared registration supplies `SKIP_RETURN_CODE 77` and the Windows runtime PATH setup. No duplicate `add_test` was added. The existing depth-plane case is preserved, but no new negative-control claim is made for that case. [Build logs, frozen fixture, main/source control, exact restoration and validation receipts](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr16011-71aae524-main7259-idle-recorder-linux-20261109.tar.gz), SHA-256 `e3db99d95de12d09ea6dbd5d1345dacd3b0cc58054b68cd5256ca6a65135ff9a` (download and all 36 manifest files verified). No new Windows, title, FPS, full-SDK or hosted-CI pass is claimed; current full CI needs a maintainer dispatch. Earlier qualifications retain their stated source/platform scope. Linux 7.2.11, AMD RX 6650 XT (RADV Mesa 26.2.6), Release. The tests ran on `main` `1e24993fa3` with this commit. The branch is the same commit cherry-picked cleanly onto `7ad9749ed0`; there `Texture.cpp` differs only by #12813's log gating. **Historical tests at the original pins** - `agc_driver_storage_idle_store_completes`: a CPU store made after the idle flush returns must survive the image's write-back. - On `main` it fails 5 of 5 runs: 983,040 of 1,048,576 bytes are overwritten over 8 rounds. - With this change it passes 20 of 20 runs: 0 bytes are overwritten. - `agc_driver_depth_plane_cpu_store_after_idle_flush` (a new case in `DepthPlanePartialStore`): the same check for a depth plane. - On `main` it fails: unit 0 holds 0 of its 16,384 CPU-written texels. - With this change it passes, and so do the other 16 `agc_driver_depth_plane*` tests. **Full suites with this change** - CPU: 2,962 of 2,962 passed. - GPU (`agc_driver*`, `video_out*`, `vulkan*`): 996 of 996 passed. Rerun on head `4ff434e1a4` (the follow-up that takes the GPU mutex in the idle wait only for an idle flush): 996 of 996, including both new tests. **Windows, RDNA3** ([report by @DonRyuzaki](https://github.com/boykopovar/AnyPS5/pull/16011#issuecomment-6658504972)): head `4ff434e1a4` on `main` `d23df92b38`, Windows 11, RX 7800 XT, WinLibs GCC 15.2, Release, validation layer on. `agc_driver_storage_idle_store_completes` passed 5 runs and `agc_driver_depth_plane_cpu_store_after_idle_flush` passed 3. Their layer reported only `VUID-VkDeviceCreateInfo-pNext-pNext` at device creation, also on a `main` control. They did not repeat the `main`-side failure. **Cost check on a slow title:** Thymesia (PPSA05213) runs at about 6 FPS here. Its frame gaps exceed the 50 ms idle threshold, so idle stores start between frames, which is where this change adds waits. Eight 185 s runs with the same input, alternating in two orders, `main` `1e24993fa3` against the same base with this change, no compiler running. Median FPS after 90 s: `main` 6.47, 5.76, 5.60, 6.38 (mean 6.05); this change 6.29, 5.70, 6.38, 5.62 (mean 6.00). That is -0.9%, inside the spread of either arm, so I measured no cost. All eight runs exit 0. No performance claim either way. **Not claimed:** no title result or performance change. I found the race while investigating an intermittent ASTRONEER (PPSA27623) load crash (#8746). This change does not stop that crash: 3 of 12 runs crashed with it, against about 4 of 11 on `main`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 6650 XT (RADV NAVI23), Mesa 26.2.6, Linux 7.2.14 (current qualification); AMD Radeon RX 7800 XT, Windows 11 (historical independent report linked above) - [x] AI-assisted: yes
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!16011
No description provided.