fix(agc): build the guarded mapped compare on macOS #27739

Closed
Gonic0 wants to merge 1 commit from upstream-pr/27739 into main
Gonic0 commented 2026-11-27 06:57:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-11-27T06:57:01Z.


What

#24031 (4cb7752e50) stopped main from building on macOS. In the Linux and macOS branch of GuestMemory::CompareMapped, std::min(end, at + PageBytes - (address + at) % PageBytes) mixes std::size_t with std::uint64_t, because address is a std::uint64_t. On macOS these are unsigned long and unsigned long long, so template deduction fails:

GuestMemory.cpp:4175:20: error: no matching function for call to 'min'

The remainder of the division by PageBytes is below 4096, so it is cast to std::size_t and std::min is called on std::size_t. On Linux both types are already unsigned long, so nothing changes there; the Windows branch is not touched.

Tested

Apple M5 Pro, macOS 27.3, Apple clang, x86_64 Release under Rosetta 2, BUILD_TESTING=ON. The tree is main 4cb7752e50 plus #17425, #11049, #26739 and #27621, which macOS needs to build; they are not part of this PR.

  • main: libSceAgcDriver and every test that compiles GuestMemory.cpp fail with the error above.
  • This PR: everything builds except agc_driver_pipelined_flush_read_order_tests, which fails on main too (mapped undeclared in PipelinedFlushReadOrder.cpp) and is unrelated.
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '^(agc_compare_hook_[a-z]+|agc_mapped_copy_[a-z]+|agc_driver_guest_memory_lifetime[a-z_]*|agc_shader_memory|guest_allocations_[a-z]+|guest_memory[a-z_]*|write_watch[a-z_]*)$' -V, three rounds on MoltenVK from Vulkan SDK 1.4.363.0: 37 of 37 pass each round, including #24031's agc_mapped_copy_* cases. Every Vulkan test log shows the layer inserted, none reports it missing, and there are no VUID- lines. main cannot run them on macOS because it does not build.
  • Grand Theft Auto V (PPSA04264) starts and renders with the fix on top of main.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 M5 Pro, MoltenVK (Vulkan SDK 1.4.363.0), macOS 27.3
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved mapped-memory comparisons on Linux and Apple platforms by making page-boundary calculations more consistent. This helps avoid incorrect results when comparing memory near a page boundary. No user-facing features or settings have changed.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5522573224 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27739). Originally posted by [Gonic0](https://github.com/Gonic0) on 2026-11-27T06:57:01Z. --- ### What #24031 (`4cb7752e50`) stopped `main` from building on macOS. In the Linux and macOS branch of `GuestMemory::CompareMapped`, `std::min(end, at + PageBytes - (address + at) % PageBytes)` mixes `std::size_t` with `std::uint64_t`, because `address` is a `std::uint64_t`. On macOS these are `unsigned long` and `unsigned long long`, so template deduction fails: ``` GuestMemory.cpp:4175:20: error: no matching function for call to 'min' ``` The remainder of the division by `PageBytes` is below 4096, so it is cast to `std::size_t` and `std::min` is called on `std::size_t`. On Linux both types are already `unsigned long`, so nothing changes there; the Windows branch is not touched. ### Tested Apple M5 Pro, macOS 27.3, Apple clang, x86_64 Release under Rosetta 2, `BUILD_TESTING=ON`. The tree is `main` `4cb7752e50` plus #17425, #11049, #26739 and #27621, which macOS needs to build; they are not part of this PR. - `main`: `libSceAgcDriver` and every test that compiles `GuestMemory.cpp` fail with the error above. - This PR: everything builds except `agc_driver_pipelined_flush_read_order_tests`, which fails on `main` too (`mapped` undeclared in `PipelinedFlushReadOrder.cpp`) and is unrelated. - `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '^(agc_compare_hook_[a-z]+|agc_mapped_copy_[a-z]+|agc_driver_guest_memory_lifetime[a-z_]*|agc_shader_memory|guest_allocations_[a-z]+|guest_memory[a-z_]*|write_watch[a-z_]*)$' -V`, three rounds on MoltenVK from Vulkan SDK 1.4.363.0: 37 of 37 pass each round, including #24031's `agc_mapped_copy_*` cases. Every Vulkan test log shows the layer inserted, none reports it missing, and there are no `VUID-` lines. `main` cannot run them on macOS because it does not build. - Grand Theft Auto V (PPSA04264) starts and renders with the fix on top of `main`. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: Apple M5 Pro, MoltenVK (Vulkan SDK 1.4.363.0), macOS 27.3 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved mapped-memory comparisons on Linux and Apple platforms by making page-boundary calculations more consistent. This helps avoid incorrect results when comparing memory near a page boundary. No user-facing features or settings have changed. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-27 07:36:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T07:36:36Z.

Review: APPROVED


Reviewed — looks good

Nothing in the changed line shows a defect; the explicit std::size_t conversion addresses the stated template deduction issue, and the remainder modulo PageBytes is bounded below one page.

What I ran

Reviewed head 478f9722ecfc9b90a26beae8eda5ce84eff59377. No build or tests were run. Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and the changed function context in GuestMemory.cpp. The changed file was included; files.json was unavailable in the prepared review folder.

Results

Check Result Note
Diff and changed function passed One-line conversion inspected
Build and tests not run Author-reported results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

Builds, tests, reported game behavior, and files excluded by preparation rules were not independently checked. The prepared file listing identifies one changed file, and its full text was available for targeted reading.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6084885488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27739#pullrequestreview-6084885488). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T07:36:36Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the changed line shows a defect; the explicit `std::size_t` conversion addresses the stated template deduction issue, and the remainder modulo `PageBytes` is bounded below one page. ## What I ran Reviewed head `478f9722ecfc9b90a26beae8eda5ce84eff59377`. No build or tests were run. Read `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, and the changed function context in `GuestMemory.cpp`. The changed file was included; `files.json` was unavailable in the prepared review folder. ## Results | Check | Result | Note | |---|---|---| | Diff and changed function | passed | One-line conversion inspected | | Build and tests | not run | Author-reported results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Builds, tests, reported game behavior, and files excluded by preparation rules were not independently checked. The prepared file listing identifies one changed file, and its full text was available for targeted reading. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 21:02:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:02:27Z.

Review: COMMENTED


I reproduced the template-deduction failure using the changed expression with size_t and unsigned long long on Linux. The revised expression compiled and passed three page-boundary cases. The remainder is below the page size, so converting it to size_t preserves the value. Native macOS coverage comes from the author’s runs.

Source review at 478f9722ec. The head trial-merges onto 6ef4f2f73b. Focused Linux checks are queued.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6178493624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27739#pullrequestreview-6178493624). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T21:02:27Z. **Review:** COMMENTED --- I reproduced the template-deduction failure using the changed expression with `size_t` and `unsigned long long` on Linux. The revised expression compiled and passed three page-boundary cases. The remainder is below the page size, so converting it to `size_t` preserves the value. Native macOS coverage comes from the author’s runs. Source review at `478f9722ec`. The head trial-merges onto `6ef4f2f73b`. Focused Linux checks are queued. AI-assisted: yes.

Pull request closed

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!27739
No description provided.