agc: the driver's idle flush stores another device's pending storage images on its own command buffer (commonparent, lost device) #10791

Closed
opened 2026-10-25 00:54:05 +00:00 by TechLevelZero · 0 comments
TechLevelZero commented 2026-10-25 00:54:05 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by TechLevelZero on 2026-10-25T00:54:05Z.


What happens
agc_driver_depth_clear_hle fails at random when ctest runs tests in parallel, with VUID-*-commonparent validation errors followed by a lost device:

vkCmdCopyBuffer(): srcBuffer (VkBuffer 0x3610000000361) was created, allocated or retrieved from VkDevice 0x55d2b8b77fd0, but command is using (or its dispatchable parameter is associated with) VkDevice 0x7fece820c760
...
driver submit, lever: AGC graphics: vkWaitForFences recorder: Vulkan result -4

The test runs two devices in one process: its own test device and the driver's. When the driver's device goes idle, VulkanDevice::StoreIdleResults calls StorageTexture::FlushAllPending("idle"). That walks the process-wide pending list, which has no device filter, so it also stores the test device's images. StorageTexture::writeBackWindows then records each write-back into Recorder::Active(), the driver's recorder, without checking that the recorder belongs to the image's device. (RecorderFor in DepthSurface.cpp does check this.) The driver's command buffer then copies the test device's buffers and images, and the submission loses the device.

Title, test or build step
ctest agc_driver_depth_clear_hle. In one batch of parallel runs it failed "only with the PR" on 4 unrelated PRs (#6959, #10515, #9551, #9049), and on main beside a fifth (#10632). Each time it passed 3 of 3 serial reruns on both main and the PR.

AnyPS5 commit
main c8d34aa8f4.

System
NVIDIA A800 80GB PCIe, NVIDIA 610.57.04, RHEL 10.2 host, Ubuntu 26.04 container, GCC 15.2, Release. Run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.

Steps to reproduce
Run 12 copies of build/tests/agc_driver_depth_clear_hle_tests at once, a few times over. Serial runs don't show it.

Log

Runs failed with commonparent
30 serial 0 0
48 parallel (4 rounds of 12) 2 2
120 parallel (10 rounds of 12) 7 6

With the validation layer's break action (VK_KHRONOS_VALIDATION_DEBUG_ACTION=VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_BREAK) under gdb, the first commonparent error stops on the driver's thread:

#11 AgcDriver::Graphics::StorageTexture::writeBackWindows(...)
#12 AgcDriver::Graphics::StorageTexture::writeBackLayers(...)
#13 AgcDriver::Graphics::StorageTexture::writeBack(unsigned long, unsigned long)
#14 AgcDriver::Graphics::StorageTexture::FlushPending(...)
#15 AgcDriver::Graphics::StorageTexture::FlushAllPending(char const*)
#16 AgcDriver::VulkanDevice::StoreIdleResults(bool)
#17 AgcDriver::DriverDetail::Driver::run(unsigned int)

Another trapped run reached the same flush and, through writeBackLayers → HostImportFor → ProbeImportWriteProtection, submitted on the test device's queue from the driver's thread while the test thread was using it (UNASSIGNED-Threading-MultipleThreads-Write on vkQueueSubmit).

What was checked

  • Waiting for the test device to go idle before the driver's dispatch does not help: 14 of 120 parallel runs failed with the wait, against 7 of 120 without it.
  • A title has one device. When Driver::AttachWindow replaces the headless device, PrepareForReplacement first stores the old device's images (FlushCachedTextures(device), filtered by device). So as far as I can see only processes with two live devices hit this: tests that open their own device next to the driver's. Under parallel ctest those tests fail at random.

A fix is on TechLevelZero/AnyPS5 branch fix/storage-idle-flush-own-device:

  • FlushPending leaves the images of a device whose recorder is not active pending. Their own device stores them when it flushes. One device behaves as before.
  • A debt entry records that, while another device's recorder is active, a read of such memory sees what its device last stored.
  • A new execution test, agc_driver_two_device_pending_store, shows the bug deterministically. Device A leaves an image store pending; device B opens and flushes, and A's results must stay pending and must not reach memory. Then A flushes and the value must arrive.

The before/after runs, with the validation layer, are in progress; I'll add the results here. I'll open the branch as a pull request once my first one is merged (open-PR limit).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6019377974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10791). Originally posted by [TechLevelZero](https://github.com/TechLevelZero) on 2026-10-25T00:54:05Z. --- **What happens** `agc_driver_depth_clear_hle` fails at random when ctest runs tests in parallel, with `VUID-*-commonparent` validation errors followed by a lost device: ``` vkCmdCopyBuffer(): srcBuffer (VkBuffer 0x3610000000361) was created, allocated or retrieved from VkDevice 0x55d2b8b77fd0, but command is using (or its dispatchable parameter is associated with) VkDevice 0x7fece820c760 ... driver submit, lever: AGC graphics: vkWaitForFences recorder: Vulkan result -4 ``` The test runs two devices in one process: its own test device and the driver's. When the driver's device goes idle, `VulkanDevice::StoreIdleResults` calls `StorageTexture::FlushAllPending("idle")`. That walks the process-wide pending list, which has no device filter, so it also stores the test device's images. `StorageTexture::writeBackWindows` then records each write-back into `Recorder::Active()`, the driver's recorder, without checking that the recorder belongs to the image's device. (`RecorderFor` in `DepthSurface.cpp` does check this.) The driver's command buffer then copies the test device's buffers and images, and the submission loses the device. **Title, test or build step** ctest `agc_driver_depth_clear_hle`. In one batch of parallel runs it failed "only with the PR" on 4 unrelated PRs (#6959, #10515, #9551, #9049), and on `main` beside a fifth (#10632). Each time it passed 3 of 3 serial reruns on both `main` and the PR. **AnyPS5 commit** `main` c8d34aa8f4. **System** NVIDIA A800 80GB PCIe, NVIDIA 610.57.04, RHEL 10.2 host, Ubuntu 26.04 container, GCC 15.2, Release. Run with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. **Steps to reproduce** Run 12 copies of `build/tests/agc_driver_depth_clear_hle_tests` at once, a few times over. Serial runs don't show it. **Log** | Runs | failed | with `commonparent` | | --- | --- | --- | | 30 serial | 0 | 0 | | 48 parallel (4 rounds of 12) | 2 | 2 | | 120 parallel (10 rounds of 12) | 7 | 6 | With the validation layer's break action (`VK_KHRONOS_VALIDATION_DEBUG_ACTION=VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_BREAK`) under gdb, the first `commonparent` error stops on the driver's thread: ``` #11 AgcDriver::Graphics::StorageTexture::writeBackWindows(...) #12 AgcDriver::Graphics::StorageTexture::writeBackLayers(...) #13 AgcDriver::Graphics::StorageTexture::writeBack(unsigned long, unsigned long) #14 AgcDriver::Graphics::StorageTexture::FlushPending(...) #15 AgcDriver::Graphics::StorageTexture::FlushAllPending(char const*) #16 AgcDriver::VulkanDevice::StoreIdleResults(bool) #17 AgcDriver::DriverDetail::Driver::run(unsigned int) ``` Another trapped run reached the same flush and, through `writeBackLayers` → `HostImportFor` → `ProbeImportWriteProtection`, submitted on the test device's queue from the driver's thread while the test thread was using it (`UNASSIGNED-Threading-MultipleThreads-Write` on `vkQueueSubmit`). **What was checked** - Waiting for the test device to go idle before the driver's dispatch does not help: 14 of 120 parallel runs failed with the wait, against 7 of 120 without it. - A title has one device. When `Driver::AttachWindow` replaces the headless device, `PrepareForReplacement` first stores the old device's images (`FlushCachedTextures(device)`, filtered by device). So as far as I can see only processes with two live devices hit this: tests that open their own device next to the driver's. Under parallel ctest those tests fail at random. A fix is on `TechLevelZero/AnyPS5` branch [`fix/storage-idle-flush-own-device`](https://github.com/TechLevelZero/AnyPS5/tree/fix/storage-idle-flush-own-device): - `FlushPending` leaves the images of a device whose recorder is not active pending. Their own device stores them when it flushes. One device behaves as before. - A debt entry records that, while another device's recorder is active, a read of such memory sees what its device last stored. - A new execution test, `agc_driver_two_device_pending_store`, shows the bug deterministically. Device A leaves an image store pending; device B opens and flushes, and A's results must stay pending and must not reach memory. Then A flushes and the value must arrive. The before/after runs, with the validation layer, are in progress; I'll add the results here. I'll open the branch as a pull request once my first one is merged (open-PR limit). AI-assisted: yes (Claude Code)
Sign in to join this conversation.
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#10791
No description provided.