fix(agc): keep a device's idle stores and storage write-backs on its own recorder #10940

Merged
TechLevelZero merged 7 commits from upstream-pr/10940 into main 2026-11-02 10:25:18 +00:00
TechLevelZero commented 2026-10-25 11:09:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TechLevelZero on 2026-10-25T11:09:15Z.


What

With two live devices in a process, the driver's idle store recorded the other device's storage images on its own command buffer, as #10791 describes. The validation layer reports this as commonparent and UNASSIGNED-Threading errors, and the submission loses the device. agc_driver_depth_clear_hle fails this way at random under parallel ctest. Two things combine:

  • VulkanDevice::StoreIdleResults (and the label and flip stores) called StorageTexture::FlushAllPending, which takes every device's pending images.
  • The write-back reads Recorder::Active(), which is one per process. Recorder::Activate switches it without the GPU mutex, so it can be either device's at any moment.

What changes:

  • FlushPending and FlushAllPending take an optional device. VulkanDevice's idle, label and flip stores pass their own, so they take only their own images. Without a device, as in the memory-access flushes, every image is still taken.
  • writeBackWindows, writeBackLayers and commitStoredSave use the active recorder only when it is the image's device's (recorderFor). Otherwise they take their existing no-recorder path, which submits on the image's own device. awaitStoredSave then uses the image's own recorder, which is the one that committed.
  • With one device the active recorder is always the image's, so a title behaves as before. A title's device replacement already stores the old device's images first (PrepareForReplacement, FlushCachedTextures).
  • A debt entry records that other users of Recorder::Active() still don't check the device.

Fixes #10791.

Overlap: tools/pr_overlap.py lists #9685, #9879 and #10656, which change the label store's line in VulkanDevice.cpp (FlushAllPending("label")). It also lists #9521 for the FlushAllPending definition in Texture.cpp, and #6926 for the debt file line this entry goes next to. Whichever merges second needs a one-line rebase. #9521 also adds two FlushAllPending("idle") calls, which should pass their device too if both are merged.

Tested

Measured on main c8d34aa8f4 with GCC 15 in Ubuntu 26.04 containers. The branch is now rebased onto main b91a6a60c5 without conflicts; the same comparisons are running again on the three GPUs below, and I will add the results here.

  • agc_driver_two_device_pending_store (new):

    1. Device A leaves an image store pending.
    2. Device B opens and runs StoreIdleResults. A's results must stay pending and must not reach memory.
    3. A flush with B still active must then bring them to memory through A.

    On unmodified main the test loses the device in step 2 (vkWaitForFences recorder: Vulkan result -4). With this change it passes on the three GPUs below.

  • agc_driver_depth_clear_hle on the A800: 240 runs, 12 at a time, alternating main and this branch, validation layer on. main failed 39 of 120 (35 with commonparent and UNASSIGNED-Threading errors); this branch failed 0 of 120. The first two versions of this change, which filtered by the active recorder in one place, still failed (18 of 120, then 16 of 120). gdb backtraces from those runs found the remaining lookups.

  • On each GPU, the 1,305 tests tools/select_tests.py selects for this change ran on main and on the branch with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and ctest -V. The validation layer loaded on every run. No test fails only on the branch, and the only VUID- message on either side is VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, which main already logs (#6782).

    • A800: pr_overlap_encoding fails on both sides. agc_submit_progress_no_timeline failed once on main.
    • RX 9070 XT and gfx1036: 4 tests fail on both sides. pr_overlap_encoding, conventions_git_errors and test_script_registration need git, which that container lacks. agc_driver_guest_memory_lifetime_direct needs /dev/udmabuf, which that container has no access to.
  • python3 tools/check_conventions.py --base origin/main: all checks pass.

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: #10791
  • Unblocks: none
  • GPUs tested: NVIDIA A800 80GB PCIe, NVIDIA 610.57.04, RHEL 10.2 (Ubuntu 26.04 container); AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.0.8, Fedora 44 Linux 7.2.7 (Ubuntu 26.04 container); AMD Ryzen 7 9700X integrated graphics (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.0.8, Fedora 44 Linux 7.2.7 (Ubuntu 26.04 container)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004170547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10940). Originally posted by [TechLevelZero](https://github.com/TechLevelZero) on 2026-10-25T11:09:15Z. --- ### What With two live devices in a process, the driver's idle store recorded the other device's storage images on its own command buffer, as #10791 describes. The validation layer reports this as `commonparent` and `UNASSIGNED-Threading` errors, and the submission loses the device. `agc_driver_depth_clear_hle` fails this way at random under parallel ctest. Two things combine: - `VulkanDevice::StoreIdleResults` (and the label and flip stores) called `StorageTexture::FlushAllPending`, which takes every device's pending images. - The write-back reads `Recorder::Active()`, which is one per process. `Recorder::Activate` switches it without the GPU mutex, so it can be either device's at any moment. What changes: - `FlushPending` and `FlushAllPending` take an optional device. `VulkanDevice`'s idle, label and flip stores pass their own, so they take only their own images. Without a device, as in the memory-access flushes, every image is still taken. - `writeBackWindows`, `writeBackLayers` and `commitStoredSave` use the active recorder only when it is the image's device's (`recorderFor`). Otherwise they take their existing no-recorder path, which submits on the image's own device. `awaitStoredSave` then uses the image's own recorder, which is the one that committed. - With one device the active recorder is always the image's, so a title behaves as before. A title's device replacement already stores the old device's images first (`PrepareForReplacement`, `FlushCachedTextures`). - A debt entry records that other users of `Recorder::Active()` still don't check the device. Fixes #10791. Overlap: `tools/pr_overlap.py` lists #9685, #9879 and #10656, which change the label store's line in `VulkanDevice.cpp` (`FlushAllPending("label")`). It also lists #9521 for the `FlushAllPending` definition in `Texture.cpp`, and #6926 for the debt file line this entry goes next to. Whichever merges second needs a one-line rebase. #9521 also adds two `FlushAllPending("idle")` calls, which should pass their device too if both are merged. ### Tested Measured on `main` `c8d34aa8f4` with GCC 15 in Ubuntu 26.04 containers. The branch is now rebased onto `main` `b91a6a60c5` without conflicts; the same comparisons are running again on the three GPUs below, and I will add the results here. - `agc_driver_two_device_pending_store` (new): 1. Device A leaves an image store pending. 2. Device B opens and runs `StoreIdleResults`. A's results must stay pending and must not reach memory. 3. A flush with B still active must then bring them to memory through A. On unmodified `main` the test loses the device in step 2 (`vkWaitForFences recorder: Vulkan result -4`). With this change it passes on the three GPUs below. - `agc_driver_depth_clear_hle` on the A800: 240 runs, 12 at a time, alternating `main` and this branch, validation layer on. `main` failed 39 of 120 (35 with `commonparent` and `UNASSIGNED-Threading` errors); this branch failed 0 of 120. The first two versions of this change, which filtered by the active recorder in one place, still failed (18 of 120, then 16 of 120). gdb backtraces from those runs found the remaining lookups. - On each GPU, the 1,305 tests `tools/select_tests.py` selects for this change ran on `main` and on the branch with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `ctest -V`. The validation layer loaded on every run. No test fails only on the branch, and the only `VUID-` message on either side is `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`, which `main` already logs (#6782). - A800: `pr_overlap_encoding` fails on both sides. `agc_submit_progress_no_timeline` failed once on `main`. - RX 9070 XT and gfx1036: 4 tests fail on both sides. `pr_overlap_encoding`, `conventions_git_errors` and `test_script_registration` need `git`, which that container lacks. `agc_driver_guest_memory_lifetime_direct` needs `/dev/udmabuf`, which that container has no access to. - `python3 tools/check_conventions.py --base origin/main`: all checks pass. ### 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: #10791 - [x] Unblocks: none - [x] GPUs tested: NVIDIA A800 80GB PCIe, NVIDIA 610.57.04, RHEL 10.2 (Ubuntu 26.04 container); AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.0.8, Fedora 44 Linux 7.2.7 (Ubuntu 26.04 container); AMD Ryzen 7 9700X integrated graphics (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.0.8, Fedora 44 Linux 7.2.7 (Ubuntu 26.04 container) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 11:23:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:23:55Z.

Review: APPROVED


Reviewed exact head 01f2e70. Pending flushes are filtered by the owning VkDevice for device idle/label/flip stores, and write-back recording falls back to the texture's own device when the global active recorder belongs elsewhere. The regression uses two devices to verify that the second device's idle store neither consumes nor publishes the first device's pending image, then checks that a later memory-access flush publishes it. Local conventions and diff checks passed; the author reports multi-GPU validation and full selected test comparisons. I did not rerun Vulkan hardware tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642913298 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10940#pullrequestreview-5642913298). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T11:23:55Z. **Review:** APPROVED --- Reviewed exact head 01f2e70. Pending flushes are filtered by the owning VkDevice for device idle/label/flip stores, and write-back recording falls back to the texture's own device when the global active recorder belongs elsewhere. The regression uses two devices to verify that the second device's idle store neither consumes nor publishes the first device's pending image, then checks that a later memory-access flush publishes it. Local conventions and diff checks passed; the author reports multi-GPU validation and full selected test comparisons. I did not rerun Vulkan hardware tests locally.
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!10940
No description provided.