fix(agc): record a multisampled target's commands on its own device #6522

Merged
meh7an merged 1 commit from upstream-pr/6522 into main 2026-10-20 21:35:30 +00:00
meh7an commented 2026-10-15 18:39:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-15T18:39:07Z.


What

Fixes #6512.

recordCommands in Graphics/src/MultisampleTarget.cpp records into Recorder::Active() whenever one exists, whatever device the target was made on. The target's layout barrier and clear, at creation and for a fast clear, then go into the active recorder's command buffer even when the target's image belongs to another VkDevice. A command buffer of one device naming an image of another is undefined behaviour. The Khronos validation layer reports it when agc_driver_multisample_fill_host_only runs (VUID-vkCmdClearColorImage-commonparent, UNASSIGNED-vkCmdPipelineBarrier-commandBuffer-commonparent).

That test makes its multisampled targets on its own device (OpenVulkanTestDevice), while the fills it submits run on the driver's. The foreign clear goes out in the batch of the absorbed fill, and the next batch's sentinel fill (the second Settle()) is lost now and then: that batch's fence signals, no completion action runs, and the guest page keeps round 1's value, still 100 ms later. These are the failures #6512 describes.

recordCommands now uses the active recorder only when it is on the target's device. Otherwise it records on the target's own device in a one-shot batch, as it already does when no recorder is active. With one device, as in a running game, nothing changes.

Tested

Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14.

  • On main b7cedd900 with this change, the full ctest suite passes: 1297 of 1298. The one not run is agc_driver_gpu_indirect_arguments_misaligned_writer_ahead, which main itself does not compile with MinGW (alignas(65536) exceeds the object file's 8192 limit).
  • agc_driver_multisample_fill_host_only, run directly with the ctest environment, several copies at a time. Same tree, the same evening, with and without this line:
APS5_PIPELINED_DRAWS Copies at a time main b7cedd900 With this change
0 4 156 of 400 failed 0 of 400
default (on) 8 46 of 200 failed 0 of 200
  • With the validation layer (Vulkan SDK 1.4.363.0, synchronization validation on), one run without this change reports the two cross-device errors above for the targets' barriers and clears (four clears), and one run with it reports none. One message stays either way: VUID-vkDestroyDevice-device-05137, objects still alive when the test destroys its device.
  • How it was found: traces showed the lost fill recorded into its own command buffer, through a live direct import of the sentinel's block, submitted, and its fence signaled, with the page unchanged afterwards. They ruled out the read sync, the pending-write snapshot, completion write-backs, shadow publishes, store runs, command buffer and fence reuse, import retirement and a page remap. The validation layer then named the cross-device clear in the batch before it.

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: none
  • GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4878121056 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6522). Originally posted by [meh7an](https://github.com/meh7an) on 2026-10-15T18:39:07Z. --- ### What Fixes #6512. `recordCommands` in `Graphics/src/MultisampleTarget.cpp` records into `Recorder::Active()` whenever one exists, whatever device the target was made on. The target's layout barrier and clear, at creation and for a fast clear, then go into the active recorder's command buffer even when the target's image belongs to another `VkDevice`. A command buffer of one device naming an image of another is undefined behaviour. The Khronos validation layer reports it when `agc_driver_multisample_fill_host_only` runs (`VUID-vkCmdClearColorImage-commonparent`, `UNASSIGNED-vkCmdPipelineBarrier-commandBuffer-commonparent`). That test makes its multisampled targets on its own device (`OpenVulkanTestDevice`), while the fills it submits run on the driver's. The foreign clear goes out in the batch of the absorbed fill, and the next batch's sentinel fill (the second `Settle()`) is lost now and then: that batch's fence signals, no completion action runs, and the guest page keeps round 1's value, still 100 ms later. These are the failures #6512 describes. `recordCommands` now uses the active recorder only when it is on the target's device. Otherwise it records on the target's own device in a one-shot batch, as it already does when no recorder is active. With one device, as in a running game, nothing changes. ### Tested Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14. - On main b7cedd900 with this change, the full ctest suite passes: 1297 of 1298. The one not run is `agc_driver_gpu_indirect_arguments_misaligned_writer_ahead`, which main itself does not compile with MinGW (`alignas(65536)` exceeds the object file's 8192 limit). - `agc_driver_multisample_fill_host_only`, run directly with the ctest environment, several copies at a time. Same tree, the same evening, with and without this line: | `APS5_PIPELINED_DRAWS` | Copies at a time | main b7cedd900 | With this change | | --- | ---: | ---: | ---: | | `0` | 4 | 156 of 400 failed | 0 of 400 | | default (on) | 8 | 46 of 200 failed | 0 of 200 | - With the validation layer (Vulkan SDK 1.4.363.0, synchronization validation on), one run without this change reports the two cross-device errors above for the targets' barriers and clears (four clears), and one run with it reports none. One message stays either way: `VUID-vkDestroyDevice-device-05137`, objects still alive when the test destroys its device. - How it was found: traces showed the lost fill recorded into its own command buffer, through a live direct import of the sentinel's block, submitted, and its fence signaled, with the page unchanged afterwards. They ruled out the read sync, the pending-write snapshot, completion write-backs, shadow publishes, store runs, command buffer and fence reuse, import retirement and a page remap. The validation layer then named the cross-device clear in the batch before it. ### 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: none - [x] GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11 - [x] AI-assisted: yes
fma-rc commented 2026-10-16 00:16:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-16T00:16:24Z.


I checked this on Linux at 09f574989 against main 5d9dcc42d, on an RTX 5080, RADV (Radeon 610M) and lavapipe.

The random failure from issue 6512 did not show up here: 0 failures in 200 ctest runs per device, on main and with the PR alike. Under the Khronos validation layer (1.4.363), one run of agc_driver_multisample_fill_host_only on main reports 4 VUID-vkCmdClearColorImage-commonparent, 2 UNASSIGNED-vkCmdPipelineBarrier-commandBuffer-commonparent and 4 UNASSIGNED-Threading-Info on each of the three devices. With the PR the same run reports none of them, and the test passes on all three.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6205045625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6522#issuecomment-6205045625). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-16T00:16:24Z. --- I checked this on Linux at 09f574989 against main 5d9dcc42d, on an RTX 5080, RADV (Radeon 610M) and lavapipe. The random failure from issue 6512 did not show up here: 0 failures in 200 ctest runs per device, on main and with the PR alike. Under the Khronos validation layer (1.4.363), one run of `agc_driver_multisample_fill_host_only` on main reports 4 `VUID-vkCmdClearColorImage-commonparent`, 2 `UNASSIGNED-vkCmdPipelineBarrier-commandBuffer-commonparent` and 4 `UNASSIGNED-Threading-Info` on each of the three devices. With the PR the same run reports none of them, and the test passes on all three.
Amoenus commented 2026-10-16 21:34:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T21:34:24Z.


Independent validation, including Windows AMD: your exact head 09f574989e8cf1f84709c7bfff4d87b2fb276477 merges cleanly with main 0dc15620d2a649779dedebae6169d1975c5c3265 at e8c6d2c23. The resulting main diff is exactly your one-line recorder-device check. The original two-device fill fixture is byte-identical to main; no test isolation patch or other pending PR was included.

relinker, libs and agc_driver_multisample_fill_host_only_tests build on Windows GCC 15.2r7 and Ubuntu 24.04 WSL2 GCC 13.3. The fill test passes 200 fresh processes per device, 600 total, with no skips:

Device Driver / OS Maximum individual test
NVIDIA GeForce RTX 5080 610.62 / 32.0.16.1062, Windows 11 Enterprise 26200 0.71 s
AMD Radeon(TM) Graphics, device 0x13c0 32.0.21036.18, same Windows 0.50 s
llvmpipe, LLVM 20.1.2 Mesa 25.2.8, Ubuntu 24.04 WSL2 0.16 s

Physical-device selection is verified in each log. Serial CTest, --repeat until-fail:200 --timeout 30 -V, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1; driver caches uncontrolled.

I independently reached the same ownership diagnosis during native-color initialization work, then found this PR during the duplicate search. The deterministic CPU ownership check and separate fixture-isolation experiment are recorded in #6512. That experiment stays on the fork; retaining the original two-device fixture here preserves regression coverage. I will use your actual commit in our integration.

This adds runtime evidence on these configurations, not a new validation-layer run or proof about every historical sentinel failure. No game startup or FPS claim. AI-assisted: Codex; tests performed locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225135127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6522#issuecomment-6225135127). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-16T21:34:24Z. --- Independent validation, including Windows AMD: your exact head `09f574989e8cf1f84709c7bfff4d87b2fb276477` merges cleanly with main `0dc15620d2a649779dedebae6169d1975c5c3265` at [e8c6d2c23](https://github.com/Amoenus/AnyPS5/commit/e8c6d2c23cc145ce91582b1c2f3054cb886ab2b3). The resulting main diff is exactly your one-line recorder-device check. The original two-device fill fixture is byte-identical to main; no test isolation patch or other pending PR was included. `relinker`, `libs` and `agc_driver_multisample_fill_host_only_tests` build on Windows GCC 15.2r7 and Ubuntu 24.04 WSL2 GCC 13.3. The fill test passes **200 fresh processes per device, 600 total**, with no skips: | Device | Driver / OS | Maximum individual test | | --- | --- | --- | | NVIDIA GeForce RTX 5080 | 610.62 / 32.0.16.1062, Windows 11 Enterprise 26200 | 0.71 s | | AMD Radeon(TM) Graphics, device 0x13c0 | 32.0.21036.18, same Windows | 0.50 s | | llvmpipe, LLVM 20.1.2 | Mesa 25.2.8, Ubuntu 24.04 WSL2 | 0.16 s | Physical-device selection is verified in each log. Serial CTest, `--repeat until-fail:200 --timeout 30 -V`, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`; driver caches uncontrolled. I independently reached the same ownership diagnosis during native-color initialization work, then found this PR during the duplicate search. [The deterministic CPU ownership check and separate fixture-isolation experiment are recorded in #6512](https://github.com/boykopovar/AnyPS5/issues/6512#issuecomment-6225007000). That experiment stays on the fork; retaining the original two-device fixture here preserves regression coverage. I will use your actual commit in our integration. This adds runtime evidence on these configurations, not a new validation-layer run or proof about every historical sentinel failure. No game startup or FPS claim. AI-assisted: Codex; tests performed 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!6522
No description provided.