fix(agc): check the deferred destruction resolver only against live devices #11705

Merged
jotitadev merged 2 commits from upstream-pr/11705 into main 2026-10-28 04:02:16 +00:00
jotitadev commented 2026-10-27 04:16:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T04:16:15Z.


What

Deferred destruction (#10062, MoltenVK only) keeps the vkGetDeviceProcAddr of the first device in a process-wide registry and throws deferred destruction found two different device resolvers when a later device brings a different pointer. The registry never forgets it: it is still there after its device is gone.

VulkanDevice unloads the Vulkan loader with SDL_UnloadObject when the device goes, and on macOS the next SDL_LoadObject can map libvulkan.1.dylib at another address. In an x86_64 probe, three dlopen/dlsym("vkGetDeviceProcAddr")/dlclose rounds returned 0x10937b240, 0x1094ea240 and 0x10937b240. So every test that opens a second VulkanDevice in the same process fails at device setup. imellag saw the same message on 9 tests in #11551, changing from run to run.

The registry now keeps the resolver of every device it set up and passes each device's calls through its own one, so a wrapper returned for an earlier device keeps reaching that device's loader after a later device is set up. The most recent resolver is used only for devices the registry never set up. A device set up after the last deferred device went may bring a different resolver; two live devices with different resolvers still throw.

agc_deferred_destruction gets a case that sets up a device, destroys its deferred objects, and sets up the next one with a different resolver, as after a loader reload. It checks that the next device is accepted and passes through to its own resolver, that the earlier device's wrapper still passes through to the earlier resolver (MarcZX10's review), and that a second live device with the first resolver is still refused.

Tested

macOS 27.2, Apple M2 Max, x86_64 Release under Rosetta 2. main alone doesn't build on macOS yet, so the GPU runs use main 27ad7244d2 plus the open macOS build PRs (#10366, #7631, #10659, #10660, #11249, #11358, #10669, #10552, #7804, #10540, #10676, #11447, #11437) and #11554, which loads libvulkan.1.dylib and makes this reachable. ANYPS5_NO_SHADER_CACHE=1, ctest -R '^agc' -j1 --timeout 30, without the flip, display and lds_atomics64 tests (1027 tests).

  • MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), same tree with and without this change:
    • without: 156 failures, 118 of them stop at deferred destruction found two different device resolvers (2 of those as 30 s timeouts);
    • with: 41 failures, none with that message. 115 of the 118 pass. The other 3 now get further and fail on something else: agc_driver_indirect_arguments_pending_producer loads libvulkan.so.1 on macOS, agc_driver_stencil_ref_export_unused hits a MoltenVK MSL compile error, agc_driver_rect_list_indirect passes on MoltenVK main with KhronosGroup/SPIRV-Cross#2704 (signed zero). No test fails with the change that passes without it.
  • MoltenVK main + SPIRV-Cross#2704, with the change: 40 failures, none with that message.
  • agc_deferred_destruction (the test and DeferredDestruction.cpp built alone, macOS x86_64 Apple clang and Linux Ubuntu GCC 15.2, same results): on main's DeferredDestruction.cpp the new case fails with "a device set up after the last one went could not use a resolver from a reloaded Vulkan loader"; on the first head of this PR (be7db251a) it fails with "an earlier device's wrapper passed through to a later device's resolver"; at the current head the whole test passes.
  • The GPU numbers above were measured with the first head of this PR (be7db251a), not re-run at the current head. Both heads pass a live device's calls to that device's own resolver; they differ only for calls on a device after a later device was set up, which VulkanDevice doesn't make (it destroys the device right after DestroyDeferredObjects).
  • 6 of the 118 (agc_driver_address_passes, clamped_global_fill, compute_table_calls, depth_copy_draw, host_import_teardown, indexed_copy) with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_REQUIRE_VULKAN=1, ctest -V: all pass, the layer loads, no VUID- errors. Without the change they stop at device setup, so there is no run to compare against.
  • python3 tools/check_conventions.py --base origin/main passes.

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 (reachable on macOS once #11554 is in)
  • Unblocks: none
  • GPUs tested: Apple M2 Max (MoltenVK 1.4.2, Vulkan SDK 1.4.363.0; and MoltenVK main + SPIRV-Cross#2704), macOS 27.2
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5028485342 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11705). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T04:16:15Z. --- ### What Deferred destruction (#10062, MoltenVK only) keeps the `vkGetDeviceProcAddr` of the first device in a process-wide registry and throws `deferred destruction found two different device resolvers` when a later device brings a different pointer. The registry never forgets it: it is still there after its device is gone. `VulkanDevice` unloads the Vulkan loader with `SDL_UnloadObject` when the device goes, and on macOS the next `SDL_LoadObject` can map `libvulkan.1.dylib` at another address. In an x86_64 probe, three `dlopen`/`dlsym("vkGetDeviceProcAddr")`/`dlclose` rounds returned `0x10937b240`, `0x1094ea240` and `0x10937b240`. So every test that opens a second `VulkanDevice` in the same process fails at device setup. imellag saw the same message on 9 tests in #11551, changing from run to run. The registry now keeps the resolver of every device it set up and passes each device's calls through its own one, so a wrapper returned for an earlier device keeps reaching that device's loader after a later device is set up. The most recent resolver is used only for devices the registry never set up. A device set up after the last deferred device went may bring a different resolver; two live devices with different resolvers still throw. `agc_deferred_destruction` gets a case that sets up a device, destroys its deferred objects, and sets up the next one with a different resolver, as after a loader reload. It checks that the next device is accepted and passes through to its own resolver, that the earlier device's wrapper still passes through to the earlier resolver (MarcZX10's review), and that a second live device with the first resolver is still refused. ### Tested macOS 27.2, Apple M2 Max, x86_64 Release under Rosetta 2. `main` alone doesn't build on macOS yet, so the GPU runs use `main` `27ad7244d2` plus the open macOS build PRs (#10366, #7631, #10659, #10660, #11249, #11358, #10669, #10552, #7804, #10540, #10676, #11447, #11437) and #11554, which loads `libvulkan.1.dylib` and makes this reachable. `ANYPS5_NO_SHADER_CACHE=1`, `ctest -R '^agc' -j1 --timeout 30`, without the flip, display and `lds_atomics64` tests (1027 tests). - MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), same tree with and without this change: - without: 156 failures, 118 of them stop at `deferred destruction found two different device resolvers` (2 of those as 30 s timeouts); - with: 41 failures, none with that message. 115 of the 118 pass. The other 3 now get further and fail on something else: `agc_driver_indirect_arguments_pending_producer` loads `libvulkan.so.1` on macOS, `agc_driver_stencil_ref_export_unused` hits a MoltenVK MSL compile error, `agc_driver_rect_list_indirect` passes on MoltenVK main with KhronosGroup/SPIRV-Cross#2704 (signed zero). No test fails with the change that passes without it. - MoltenVK main + SPIRV-Cross#2704, with the change: 40 failures, none with that message. - `agc_deferred_destruction` (the test and `DeferredDestruction.cpp` built alone, macOS x86_64 Apple clang and Linux Ubuntu GCC 15.2, same results): on `main`'s `DeferredDestruction.cpp` the new case fails with "a device set up after the last one went could not use a resolver from a reloaded Vulkan loader"; on the first head of this PR (be7db251a) it fails with "an earlier device's wrapper passed through to a later device's resolver"; at the current head the whole test passes. - The GPU numbers above were measured with the first head of this PR (be7db251a), not re-run at the current head. Both heads pass a live device's calls to that device's own resolver; they differ only for calls on a device after a later device was set up, which `VulkanDevice` doesn't make (it destroys the device right after `DestroyDeferredObjects`). - 6 of the 118 (`agc_driver_address_passes`, `clamped_global_fill`, `compute_table_calls`, `depth_copy_draw`, `host_import_teardown`, `indexed_copy`) with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_REQUIRE_VULKAN=1`, `ctest -V`: all pass, the layer loads, no `VUID-` errors. Without the change they stop at device setup, so there is no run to compare against. - `python3 tools/check_conventions.py --base origin/main` passes. ### 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 (reachable on macOS once #11554 is in) - [x] Unblocks: none - [x] GPUs tested: Apple M2 Max (MoltenVK 1.4.2, Vulkan SDK 1.4.363.0; and MoltenVK main + SPIRV-Cross#2704), macOS 27.2 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-27 04:55:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T04:55:21Z.

Review: CHANGES_REQUESTED


Reviewed exact head be7db251ad005c9ead50177d190b9f04a17743f9 against current main ddd72f488b6070c3864c8782cc5691ca3e30e680. Changes requested for one reproduced resolver-routing regression.

[P2] Preserve the resolver for a previously returned device-proc wrapper across reload. deferringDeviceProc routes passthrough calls through the single process-wide registry().resolver. This change replaces that resolver whenever the registry has no deferred devices. After DeferDestructionToIdle(first, mockProc) and DestroyDeferredObjects(first), setting up second with reloadedProc changes what the already-returned firstProc routes to: firstProc(first, "vkQueueWaitIdle") now returns reloadedQueueWaitIdle, not mockQueueWaitIdle. I reproduced this by compiling the exact PR implementation/test with that additional assertion; it fails. DestroyDeferredObjects only removes deferred tracking; production VulkanDevice calls it before vkDestroyDevice, so the old device may still be live during this interval. The existing test explicitly expects a previously returned wrapper to pass through after DestroyDeferredObjects, but does not cover a subsequent resolver replacement.

Please preserve resolver routing for that old wrapper/device across the reload (or establish that this transition is unsupported and remove the stale-wrapper behavior contract), and add a regression for the sequence above. The requested loader-reload case and the two-live-device rejection should both remain covered.

Current-main conventions and git diff --check pass. Hosted policy checks pass; product test jobs are skipped by path policy. This review's additional focused resolver regression was compiled and executed locally; it did not run the full AGC suite.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662376437 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11705#pullrequestreview-5662376437). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T04:55:21Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head `be7db251ad005c9ead50177d190b9f04a17743f9` against current main `ddd72f488b6070c3864c8782cc5691ca3e30e680`. Changes requested for one reproduced resolver-routing regression. **[P2] Preserve the resolver for a previously returned device-proc wrapper across reload.** `deferringDeviceProc` routes passthrough calls through the single process-wide `registry().resolver`. This change replaces that resolver whenever the registry has no deferred devices. After `DeferDestructionToIdle(first, mockProc)` and `DestroyDeferredObjects(first)`, setting up `second` with `reloadedProc` changes what the already-returned `firstProc` routes to: `firstProc(first, "vkQueueWaitIdle")` now returns `reloadedQueueWaitIdle`, not `mockQueueWaitIdle`. I reproduced this by compiling the exact PR implementation/test with that additional assertion; it fails. `DestroyDeferredObjects` only removes deferred tracking; production `VulkanDevice` calls it before `vkDestroyDevice`, so the old device may still be live during this interval. The existing test explicitly expects a previously returned wrapper to pass through after `DestroyDeferredObjects`, but does not cover a subsequent resolver replacement. Please preserve resolver routing for that old wrapper/device across the reload (or establish that this transition is unsupported and remove the stale-wrapper behavior contract), and add a regression for the sequence above. The requested loader-reload case and the two-live-device rejection should both remain covered. Current-main conventions and `git diff --check` pass. Hosted policy checks pass; product test jobs are skipped by path policy. This review's additional focused resolver regression was compiled and executed locally; it did not run the full AGC suite.
MarcZX10 commented 2026-10-27 05:18:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T05:18:34Z.

Review: APPROVED


Re-reviewed exact head 846e2989232e60ebb4c1720c7bdb8d68b095b928.

The updated per-device resolver map fixes the earlier-wrapper regression: a wrapper returned for the first device retains that device's resolver after a later loader reload, while the new device uses its own resolver. The live-device resolver mismatch guard remains, and the regression test now checks both routing directions plus rejection of two live devices with different resolvers.

I applied the exact PR changes since the current-main merge base in a disposable review tree, built agc_deferred_destruction_tests, and ran ctest -R '^agc_deferred_destruction$': 1/1 passed. The normal host CPU guard was bypassed only in that scratch tree for this CPU-only test, then restored; tracked source is clean. The PR correctly distinguishes GPU-suite numbers from its previous head; its current-head focused tests pass on Linux and macOS per the author. Hosted eligibility, conventions and label checks pass; product jobs are skipped by path policy.

No blocking issue found in the updated diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662548998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11705#pullrequestreview-5662548998). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T05:18:34Z. **Review:** APPROVED --- Re-reviewed exact head `846e2989232e60ebb4c1720c7bdb8d68b095b928`. The updated per-device resolver map fixes the earlier-wrapper regression: a wrapper returned for the first device retains that device's resolver after a later loader reload, while the new device uses its own resolver. The live-device resolver mismatch guard remains, and the regression test now checks both routing directions plus rejection of two live devices with different resolvers. I applied the exact PR changes since the current-main merge base in a disposable review tree, built `agc_deferred_destruction_tests`, and ran `ctest -R '^agc_deferred_destruction$'`: 1/1 passed. The normal host CPU guard was bypassed only in that scratch tree for this CPU-only test, then restored; tracked source is clean. The PR correctly distinguishes GPU-suite numbers from its previous head; its current-head focused tests pass on Linux and macOS per the author. Hosted eligibility, conventions and label checks pass; product jobs are skipped by path policy. No blocking issue found in the updated diff.
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!11705
No description provided.