fix(agc): build the frame recorder and the resident heap mirror test on macOS #10540

Merged
maximilianfv merged 2 commits from upstream-pr/10540 into main 2026-10-27 03:52:22 +00:00
maximilianfv commented 2026-10-24 09:05:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-24T09:05:05Z.


What

Two macOS build errors in libSceAgcDriver on current main:

  • Execution/src/FrameRecorder.cpp (added in #8740) reads environ in captureEnvironment(), but macOS headers do not declare it: error: use of undeclared identifier 'environ'. This declares extern char** environ; in the existing non-Windows branch after #include <unistd.h>, as PerformanceTrace.cpp already does.
  • tests/execution/ResidentHeapMirror.cpp (the mapping line came in with #7647) passes MAP_FIXED_NOREPLACE when the heap is placed at an address, and that flag exists only on Linux: error: use of undeclared identifier 'MAP_FIXED_NOREPLACE'. This keeps the flag on Linux. On macOS, where mmap treats a non-null address only as a hint, a heap placed at an address is allocated with mach_vm_allocate and VM_FLAGS_FIXED, which maps exactly there or fails with KERN_NO_SPACE without replacing an existing mapping, as MAP_FIXED_NOREPLACE does (a standalone probe: an occupied range gives KERN_NO_SPACE and leaves the address unchanged; a freed range is mapped at exactly that address, writable, and munmap releases it). The existing Require(raw != MAP_FAILED && (at == nullptr || raw == at), ...) stays.

Prior art: #8658 by iamthehimansh (closed, split into smaller PRs such as #10419) made the same test change on macOS in commit 771424ae22 (2026-10-23). It defined MAP_FIXED_NOREPLACE as 0 under __APPLE__, which has the same effect on macOS as this change. That PR covers only the test, not environ in FrameRecorder.cpp, and it uses a macro instead of a __linux__ guard. None of the PRs it was split into carries that change. No earlier PR declares environ in FrameRecorder.cpp, which #8740 added after the whole-port PRs.

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 (KosmicKrisp in that SDK is arm64-only).

main alone does not build on macOS, so this was tested in a tree made of mugurc's macOS series (ci/macos-series-2, 27e968974) merged with main at 1e20650e84, plus the macOS build parts of #10419 (StandardExceptions.cpp, FileStream.hpp).

  • Without this change, the build of that tree stops at exactly the two errors above. With it, the build finishes.
  • With ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R 'agc_driver_resident_heap_mirror|agc_recorder|agc_resident_present' -V: 8 of 9 pass (agc_recorder_device_selection, agc_recorder_read_list, agc_recorder_deferred_failure_report, agc_recorder_completion_labels, agc_recorder_cmask, agc_recorder_cube, agc_recorder_kept_bytes, agc_resident_present). The log has no was not found but was requested by env var VK_INSTANCE_LAYERS line. The only validation errors are 6 VUID-VkDeviceCreateInfo-pProperties-04451: the validation layer flags vkCreateDevice without VK_KHR_portability_subset on MoltenVK. This change does not touch device creation. A validation comparison against main is not possible because the tree without this change does not build.
  • agc_driver_resident_heap_mirror now builds and runs and passes the mapping check, then fails later at ResidentHeapMirror.cpp:218: first dispatch: the heap mirrors of two 8192 KiB heaps hold 16384 KiB of device memory; the guest and the GPU wrote 192 KiB of them. The log also shows host import budget: 0 MiB live of 0 MiB (APS5_HOST_IMPORT_MIB); 1 imports (8 MiB) refused so far, 0 of them remembered. That is a separate macOS gap, and this PR does not fix it. No open PR covers it: #8380 edits the same test and the heap mirror code but does not touch the mapping line. Closed #8658 handled it on the test side, running only the copied-mirror checks on devices without sparse residency (commit 83463c6f6e).
  • The test stopped at :218 before it reached the at != nullptr placement path (ReusedAddressTests), so that path is not exercised on macOS by this run; the mach_vm_allocate placement itself was checked with the probe above.
  • Not tested on Linux or Windows. Linux keeps MAP_FIXED_NOREPLACE, and the Windows code is unchanged.

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:4994083508 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10540). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-24T09:05:05Z. --- ### What Two macOS build errors in libSceAgcDriver on current `main`: - `Execution/src/FrameRecorder.cpp` (added in #8740) reads `environ` in `captureEnvironment()`, but macOS headers do not declare it: `error: use of undeclared identifier 'environ'`. This declares `extern char** environ;` in the existing non-Windows branch after `#include <unistd.h>`, as `PerformanceTrace.cpp` already does. - `tests/execution/ResidentHeapMirror.cpp` (the mapping line came in with #7647) passes `MAP_FIXED_NOREPLACE` when the heap is placed at an address, and that flag exists only on Linux: `error: use of undeclared identifier 'MAP_FIXED_NOREPLACE'`. This keeps the flag on Linux. On macOS, where `mmap` treats a non-null address only as a hint, a heap placed at an address is allocated with `mach_vm_allocate` and `VM_FLAGS_FIXED`, which maps exactly there or fails with `KERN_NO_SPACE` without replacing an existing mapping, as `MAP_FIXED_NOREPLACE` does (a standalone probe: an occupied range gives `KERN_NO_SPACE` and leaves the address unchanged; a freed range is mapped at exactly that address, writable, and `munmap` releases it). The existing `Require(raw != MAP_FAILED && (at == nullptr || raw == at), ...)` stays. Prior art: #8658 by iamthehimansh (closed, split into smaller PRs such as #10419) made the same test change on macOS in commit 771424ae22 (2026-10-23). It defined `MAP_FIXED_NOREPLACE` as `0` under `__APPLE__`, which has the same effect on macOS as this change. That PR covers only the test, not `environ` in `FrameRecorder.cpp`, and it uses a macro instead of a `__linux__` guard. None of the PRs it was split into carries that change. No earlier PR declares `environ` in `FrameRecorder.cpp`, which #8740 added after the whole-port PRs. ### 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 (KosmicKrisp in that SDK is arm64-only). `main` alone does not build on macOS, so this was tested in a tree made of mugurc's macOS series (`ci/macos-series-2`, 27e968974) merged with `main` at 1e20650e84, plus the macOS build parts of #10419 (`StandardExceptions.cpp`, `FileStream.hpp`). - Without this change, the build of that tree stops at exactly the two errors above. With it, the build finishes. - With `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -R 'agc_driver_resident_heap_mirror|agc_recorder|agc_resident_present' -V`: 8 of 9 pass (`agc_recorder_device_selection`, `agc_recorder_read_list`, `agc_recorder_deferred_failure_report`, `agc_recorder_completion_labels`, `agc_recorder_cmask`, `agc_recorder_cube`, `agc_recorder_kept_bytes`, `agc_resident_present`). The log has no `was not found but was requested by env var VK_INSTANCE_LAYERS` line. The only validation errors are 6 `VUID-VkDeviceCreateInfo-pProperties-04451`: the validation layer flags `vkCreateDevice` without `VK_KHR_portability_subset` on MoltenVK. This change does not touch device creation. A validation comparison against `main` is not possible because the tree without this change does not build. - `agc_driver_resident_heap_mirror` now builds and runs and passes the mapping check, then fails later at `ResidentHeapMirror.cpp:218`: `first dispatch: the heap mirrors of two 8192 KiB heaps hold 16384 KiB of device memory; the guest and the GPU wrote 192 KiB of them`. The log also shows `host import budget: 0 MiB live of 0 MiB (APS5_HOST_IMPORT_MIB); 1 imports (8 MiB) refused so far, 0 of them remembered`. That is a separate macOS gap, and this PR does not fix it. No open PR covers it: #8380 edits the same test and the heap mirror code but does not touch the mapping line. Closed #8658 handled it on the test side, running only the copied-mirror checks on devices without sparse residency (commit 83463c6f6e). - The test stopped at `:218` before it reached the `at != nullptr` placement path (`ReusedAddressTests`), so that path is not exercised on macOS by this run; the `mach_vm_allocate` placement itself was checked with the probe above. - Not tested on Linux or Windows. Linux keeps `MAP_FIXED_NOREPLACE`, and the Windows code is unchanged. ### 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-24 10:54:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:54:23Z.

Review: DISMISSED


The non-Linux mmap path now passes at with placement = 0, but the constructor still requires raw == at. On macOS, mmap documents a non-null addr as a hint and explicitly allows the returned address to differ; ReusedAddressTests relies on exact reuse. If the hint is not honored, this new path fails at the Require instead of building a stable test. Since the PR report says the macOS run stops in ResidentTests before reaching ReusedAddressTests, that address-reuse path has not been exercised there. Please make it deterministic with a safe exact-address strategy available on the platform, or skip only that subtest when exact no-replace placement is unavailable (and make sure any unexpected successful mapping is unmapped before throwing). Apple mmap reference: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mmap.2.html}

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637988632 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10540#pullrequestreview-5637988632). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T10:54:23Z. **Review:** DISMISSED --- The non-Linux `mmap` path now passes `at` with `placement = 0`, but the constructor still requires `raw == at`. On macOS, `mmap` documents a non-null `addr` as a hint and explicitly allows the returned address to differ; `ReusedAddressTests` relies on exact reuse. If the hint is not honored, this new path fails at the `Require` instead of building a stable test. Since the PR report says the macOS run stops in `ResidentTests` before reaching `ReusedAddressTests`, that address-reuse path has not been exercised there. Please make it deterministic with a safe exact-address strategy available on the platform, or skip only that subtest when exact no-replace placement is unavailable (and make sure any unexpected successful mapping is unmapped before throwing). Apple mmap reference: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mmap.2.html}
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!10540
No description provided.