test(agc): keep the import-probe hook one-shot on libc++ #10857

Merged
maximilianfv merged 1 commit from upstream-pr/10857 into main 2026-10-26 21:32:40 +00:00
maximilianfv commented 2026-10-25 05:51:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-25T05:51:17Z.


What

agc_driver_graphics hangs until the test timeout on macOS. The cause is in the test helper, not in the driver.

ImportAllocationProbe::Allocate in core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp takes the onImport hook with std::move and then calls it. The standard leaves the state of a moved-from std::function unspecified. libstdc++ and MSVC leave it empty. libc++ leaves a small stored functor in place, so the hook is still callable:

  • importMappedFailureGenerationTests registers an unrelated range from the hook.
  • On libc++ the hook fires again on the next import, while HostImportFor holds the guest buffer memory mutex (state.mutex, not recursive).
  • Replacing the unrelated range removes the first one. That goes through GuestAllocationsRequireUnpinned, WaitForLeasesAndImports and releaseParkedImports, which locks state.mutex again on the same thread, and the thread deadlocks.

This change takes the hook with std::exchange(active->onImport, nullptr), which leaves it empty on every standard library, and includes <utility>. It changes only test code. On Linux and Windows the behaviour does not change, because their moved-from std::function was already empty.

Ported from Himansh Raj's commit c932f1072b "test(agc): keep the import-probe hook one-shot on macOS" (2026-10-21) in #8658, the closed whole macOS port; the commit carries a Co-authored-by: trailer for him. That commit found the same deadlock and cleared the hook after the move, under #ifdef __APPLE__ and with a code comment. This version is unconditional and has no comment. None of the PRs #8658 was split into (#10362, #10419) carries this change. No other open or closed PR touches onImport, apart from #8802, which added the hook.

Tested

Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2, Vulkan through MoltenVK from the LunarG Vulkan SDK 1.4.363.

main alone does not build on macOS. I tested in a tree made of mugurc's macOS series (ci/macos-series-2, 27e968974) merged with main at 522e32e3b6. The tree also has the other open macOS fixes of this series: #10540, #10562, #10641, #10642, #10650, #10651, #10652 and the build parts of #10419. Only this change was toggled between the runs.

Both runs used ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and ctest -R '^agc_driver_graphics$' -E 'audio_in|voice' --timeout 420 -V.

  • Without this change, agc_driver_graphics times out after 420.05 s.
  • With this change, it passes 3 of 3 runs (12.16 s, 11.05 s and 11.22 s).
  • Neither log has a Validation Error line or a was not found but was requested by env var VK_INSTANCE_LAYERS line.
  • Not tested on Linux or Windows.

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: Apple M1 Pro, MoltenVK (Vulkan SDK 1.4.363), macOS 27.0.1
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5002225129 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10857). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-25T05:51:17Z. --- ### What `agc_driver_graphics` hangs until the test timeout on macOS. The cause is in the test helper, not in the driver. `ImportAllocationProbe::Allocate` in `core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` takes the `onImport` hook with `std::move` and then calls it. The standard leaves the state of a moved-from `std::function` unspecified. libstdc++ and MSVC leave it empty. libc++ leaves a small stored functor in place, so the hook is still callable: - `importMappedFailureGenerationTests` registers an unrelated range from the hook. - On libc++ the hook fires again on the next import, while `HostImportFor` holds the guest buffer memory mutex (`state.mutex`, not recursive). - Replacing the unrelated range removes the first one. That goes through `GuestAllocationsRequireUnpinned`, `WaitForLeasesAndImports` and `releaseParkedImports`, which locks `state.mutex` again on the same thread, and the thread deadlocks. This change takes the hook with `std::exchange(active->onImport, nullptr)`, which leaves it empty on every standard library, and includes `<utility>`. It changes only test code. On Linux and Windows the behaviour does not change, because their moved-from `std::function` was already empty. Ported from Himansh Raj's commit c932f1072b "test(agc): keep the import-probe hook one-shot on macOS" (2026-10-21) in #8658, the closed whole macOS port; the commit carries a `Co-authored-by:` trailer for him. That commit found the same deadlock and cleared the hook after the move, under `#ifdef __APPLE__` and with a code comment. This version is unconditional and has no comment. None of the PRs #8658 was split into (#10362, #10419) carries this change. No other open or closed PR touches `onImport`, apart from #8802, which added the hook. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2, Vulkan through MoltenVK from the LunarG Vulkan SDK 1.4.363. `main` alone does not build on macOS. I tested in a tree made of mugurc's macOS series (`ci/macos-series-2`, 27e968974) merged with `main` at 522e32e3b6. The tree also has the other open macOS fixes of this series: #10540, #10562, #10641, #10642, #10650, #10651, #10652 and the build parts of #10419. Only this change was toggled between the runs. Both runs used `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `ctest -R '^agc_driver_graphics$' -E 'audio_in|voice' --timeout 420 -V`. - Without this change, `agc_driver_graphics` times out after 420.05 s. - With this change, it passes 3 of 3 runs (12.16 s, 11.05 s and 11.22 s). - Neither log has a `Validation Error` line or a `was not found but was requested by env var VK_INSTANCE_LAYERS` line. - Not tested on Linux or Windows. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> Apple M1 Pro, MoltenVK (Vulkan SDK 1.4.363), macOS 27.0.1 - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 05:53:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T05:53:38Z.

Review: APPROVED


Reviewed exact head f0fee97510a202d780930f8aca146a5d4484f596 against current main. The test hook is now removed from active->onImport with std::exchange before invocation, so callback behavior no longer depends on the unspecified state of a moved-from std::function. The returned callable is invoked exactly once, and <utility> supplies the exchange utility. Scope is limited to test support code; production code is unchanged.

The PR reports a macOS/MoltenVK control where agc_driver_graphics times out without the fix and passes 3/3 with it, with the validation layer present. I did not independently run the macOS test. Hosted eligibility, conventions, intake, labels and report checks pass; product jobs are skipped under repository policy. I found no blocker in this focused test portability fix.

AI-assisted review: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641771749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10857#pullrequestreview-5641771749). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T05:53:38Z. **Review:** APPROVED --- Reviewed exact head `f0fee97510a202d780930f8aca146a5d4484f596` against current main. The test hook is now removed from `active->onImport` with `std::exchange` before invocation, so callback behavior no longer depends on the unspecified state of a moved-from `std::function`. The returned callable is invoked exactly once, and `<utility>` supplies the exchange utility. Scope is limited to test support code; production code is unchanged. The PR reports a macOS/MoltenVK control where `agc_driver_graphics` times out without the fix and passes 3/3 with it, with the validation layer present. I did not independently run the macOS test. Hosted eligibility, conventions, intake, labels and report checks pass; product jobs are skipped under repository policy. I found no blocker in this focused test portability fix. AI-assisted review: yes.
imellag commented 2026-10-25 07:16:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-25T07:16:07Z.

Review: APPROVED


Tested head f0fee97510 on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2, MoltenVK from the Vulkan SDK 1.4.363.0.

The tree is main 61fc572cee plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries; only this change was toggled. With ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and ctest -R '^agc_driver_graphics$' --timeout 420 -V:

  • Without this change, agc_driver_graphics times out after 420.04 s. I saw the same timeout yesterday on the previous main.
  • With it, the test passes 3 runs out of 3 (6.25 s, 5.75 s and 5.90 s).
  • No log has a VUID- line or was not found but was requested by env var VK_INSTANCE_LAYERS. With VK_LOADER_DEBUG=all the test prints no loader output, so it runs on the mocked device and the validation layer is not loaded here.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642041456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10857#pullrequestreview-5642041456). Originally posted by [imellag](https://github.com/imellag) on 2026-10-25T07:16:07Z. **Review:** APPROVED --- Tested head `f0fee97510` on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2, MoltenVK from the Vulkan SDK 1.4.363.0. The tree is `main` `61fc572cee` plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries; only this change was toggled. With `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `ctest -R '^agc_driver_graphics$' --timeout 420 -V`: - Without this change, `agc_driver_graphics` times out after 420.04 s. I saw the same timeout yesterday on the previous `main`. - With it, the test passes 3 runs out of 3 (6.25 s, 5.75 s and 5.90 s). - No log has a `VUID-` line or `was not found but was requested by env var VK_INSTANCE_LAYERS`. With `VK_LOADER_DEBUG=all` the test prints no loader output, so it runs on the mocked device and the validation layer is not loaded here. 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!10857
No description provided.