feat: macOS host support (Apple Silicon via Rosetta 2, Vulkan on MoltenVK) #8658
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8658"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-20T20:13:04Z.
What
macOS host support for AnyPS5 on Apple Silicon: the emulator runs as x86_64 under Rosetta 2 and renders through Vulkan on MoltenVK. The relinker and the web converter build natively.
Every platform-specific change is behind
__APPLE__/elseif(APPLE)or sits inspecifics/macos/. Before every commit I compared the Linux and Windows preprocessed views of each changed file againstmain; they are unchanged.Graphics driver address
0xfe0000000for itself;mmapthere fails withEPERMeven in an empty process, natively and under Rosetta.0xee0000000, and the converted shaders are retargeted to that address.Kernel, libc and networking
nanosleeperrno, precise waits, and kqueue file and socket events.SO_ACCEPTCONN, the UDP pending-bytes count and the stream-send error after a peer close.EPROTOTYPE→NET_EPROTONOSUPPORTinsceNetSocket, which is what FreeBSD reports.acosfprecision under Rosetta.__eh_frame.Graphics and video output
uint/intfragment outputs.Relinker
Build
link.h,if_link.h,AF_PACKETand--exclude-libs.SIGUSR1).Tested
Machine: macOS 26 (Darwin 25.6, arm64) on an Apple M2 Pro. The emulator ran as x86_64 under Rosetta 2, with the Vulkan SDK 1.4.363.0 and MoltenVK 1.4.2. To test the GPU path,
source setup-env.shfrom the SDK and pointVK_DRIVER_FILESatMoltenVK_icd.json. The SDK also installs the arm64-only KosmicKrisp ICD, which an x86_64 process cannot load; withVK_DRIVER_FILESset, it no longer logs that.Builds and conventions:
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ONwith the full build: 0 failed objects.tools/test_web.pypasses.python3 tools/check_conventions.py --base origin/main: all checks pass.Full ctest on this machine (M2 Pro, macOS 26.6, at
51a06b126): 1,804 tests; 90 are skipped by the tests themselves, and 19 fail. Main does not build on macOS, so before this branch none of these ran. Full runs on an M1 (@Mauro42K) and an M4 (@prosperkartik) are in the thread.16 of the 19 failures are graphics features that Apple GPUs or MoltenVK do not provide, or graphics paths still open:
agc_driver_sample_order, which passes with #9193The other 3:
guest_floating_point: Rosetta ignores the MXCSR exception mask bits.guest_math_exact: Rosetta canonicalises x87 pseudo-denormals.agc_write_tracking: on macOS a host import opens its whole range for writing, so an untouched block in the import window is reported as possibly written by the CPU.On the M4,
agc_driver_ds_permutealso fails. SPIRV-Cross forwards the recompiler's unconditionalOpGroupNonUniformShuffleinto a short-circuit&&/?:operand, which makes the shuffle conditional in MSL; @prosperkartik reduced and filed it as KhronosGroup/SPIRV-Cross#2722.On the M1 (@Mauro42K, macOS 27.0.1),
agc_driver_pass_input_hazardandagc_driver_uint8x4_color_targetalso fail; both pass on the M2 Pro and the M4 with the same MoltenVK, and the cause is still open.I have not tested on Linux or Windows. For every changed C/C++ file I compare its Linux and Windows preprocessor views (
unifdefwith__APPLE__undefined) withmain. 14 files are not macOS-only, and they change what Linux and Windows compile:ExportMacros.hpp,DisplayWindow.cpp,ApplicationProcessParameters.cpp.MainThread.hpp,DriverMemory.hpp.FileStream.hppcallsfeof_unlocked/ferror_unlockedunqualified, so macOS can supply them.CxxAbiSupport.cppnames the__cxa_thread_atexitlambda.Jit.cppadds#include <filesystem>.QueuedIndexReadOrder.cppchanges 4reinterpret_casts tostatic_cast.GuestGenericCategory.cppaddsconst_castbefore the vtable casts.Formatting.cppadds<cstdarg>and a clang__builtin_sysv_va_listalias.GuestRaiseException.cpprenames itsSIGUSR1constant toGuestSigUsr1and uses the shared assembly macros.MacOsImage.cpp) and the web converter's"macos"target option (wasm/Bindings.cpp).Every other changed file has identical Linux and Windows views.
Homebrew: ccleste (PPSA59322) converts, gets signed, starts, reads its settings and assets and runs into gameplay. It stops at its first mesh-path draw whose pixel shader reads barycentrics, because MoltenVK exposes neither
VK_EXT_mesh_shadernor a usableVK_KHR_fragment_shader_barycentric. That needs a non-mesh fallback and is left for a follow-up PR.Checklist
main; no other open PR implements the same functions. Overlap: #7201 is another full macOS port and conflicts withmain. The smaller macOS PRs (#4630, #7631, #7804, #7850, #7937, #8118, #8279, #8477) cover parts of the same ground, and I am happy to rebase onto whichever lands first. The following open PRs each change one hunk that this PR also changes; whichever lands first, the other drops its copy:ShaderRegistry.cpplifecycle mutex.GuestHostStandardError.cpp.Udp.cppshutdown_nid_postfix.Math.cppacosf.State.cpp, theuint4output for raw 32-bit exports into a UINT target (heremetalUintOutput, macOS only).libSceNetCtl/Export.cppHostTrafficon macOS. Here it reads each interface's 64-bit counters fromIFMIB_IFDATA, as @jotitadev measured; #9728 readsgetifaddrs, which wraps every 4 GiB.PerformanceOverlay.cppReadProcessPrivateBytes, the sameTASK_VM_INFO/phys_footprinthunk split out by @tkcm01. #9971 lands first and this branch takesmain's copy.__APPLE__blocks carry one-line comments explaining the macOS difference; I will move them intodocs/dev/debt/if you prefer.NotImplemented_nid_no_patch); no new silent stubs..mdfiles or images added to the repository.VK_LAYER_KHRONOS_validationcomparison againstmain, becausemaindoes not build on macOS.cc @boykopovar @oneandonlydean @adriadam10. It would help if one of you could start the full Linux/Windows build for this PR (
gh workflow run build.yml --repo boykopovar/AnyPS5 --ref main --field pr=8658).Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-21T01:41:07Z.
The branch is merged with
mainata806c69bf, so the conflict is gone. The one conflict was thedocs/dev/debt/libkernel.mdline @MarcZX10 pointed out in #7741: I kept "Linux and macOS" on the SIGUSR1 line and took the new Windows line frommain.Checked on an Apple M2 Pro (macOS, x86_64 under Rosetta 2, Vulkan through MoltenVK):
tools/test_web.py: passedmainare the macOS-gated files this PR already touched; nothing new from the mergetools/check_conventions.py --base origin/main: passedOn #7741: the two PRs change different parts of
MacOsImage.cpp. #7741 adds bytes toEntryStub; this PR changes where the stub is placed after the load commands. As @MarcZX10 found, they merge without a conflict and neither needs changes for the other. @jotitadev's Rosetta 2 run in #7741 showed the guest0x9fc0MXCSR takes effect under Rosetta. Once #7741 lands, I'll recheck whetherguest_floating_pointstill fails on macOS; it is one of the three failures I currently attribute to Rosetta.Requesting review. @boykopovar @oneandonlydean @adriadam10, and @MarcZX10 and @jotitadev, who checked the macOS entry stub in #7741 and its overlap with this PR. Please take a look when you have time.
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-21T01:48:46Z.
Follow-up on the
guest_floating_pointnote above: I applied #7741 on top of this branch and rebuilt (0 failed objects).guest_floating_pointandguest_math_exactstill abort on macOS with exactly the same output as without it.guest_mathpasses either way.guest_floating_pointstops at "floating-point environment: flag updates preserve exception masks". That check is outside the entry MXCSR that #7741 sets, so #7741 doesn't change these two failures. Both PRs are still independent.Imported from boykopovar/AnyPS5. Originally posted by Mauro42K on 2026-10-21T11:41:58Z.
Hi @iamthehimansh,
I’ve recently completed the Apple M1 MoltenVK shader comparisons requested by @imellag for #8578 and #8612.
I noticed that your macOS host support PR has been tested on an M2 Pro. I have an M1 MacBook Pro (8 GB RAM, macOS 27.0.1) with MoltenVK 1.4.2 and the Vulkan SDK already configured.
I’d be happy to independently validate this PR on M1 hardware, including a focused build/test run and, if useful, a small open-source homebrew title such as ccleste.
Would an M1 validation be helpful, and is there a specific commit or test scenario you would prefer?
I’d like to coordinate first to avoid duplicating existing work. Thanks!
Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-21T14:40:35Z.
Tried this PR with two retail Unity titles on Apple silicon. The build is clean, but neither title gets past loading yet.
Machine: Apple M4 Pro (24 GB), macOS 27.0.1, x86-64 under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), Apple clang 21.0.0.
Build: this PR at its current head
1f687d621(withmain1b5d7021amerged in), and earlier at4a7efd236merged withmain27bcd6a29; the results below are the same on both.cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64 -DBUILD_TESTING=ON, full build: 0 failed objects, 361 system libraries. Both titles converted with--macos --to-rosetta --registryand theirMedia/ModulesandMedia/Pluginsdirectories. Both titles reach gameplay on the closed #7332 branch on the same machine.God of War Sons of Sparta (PPSA28997): stops about 4 s after start, right after opening the first scene's assets:
Same result in five runs (two with only this PR, three with #8083 and #8339 also merged). It is a managed (IL2CPP) exception, and the title's
devlog/app/debug.logstays empty. What I could rule out:NotImplemented_nid_no_patchstub is reached: with a local log line in it, nothing is printed before the exception.APS5_TRACE_MEMORY=1shows only reserve, allocate and remap calls between the.resSopen and the exception, so the new macOS filemmappath (#7974) is not involved.openof/dev/urandom; here that call never comes.Planet of Lana (PPSA19450): stops at its first draw whose pixel shader reads barycentrics:
That is the ccleste stop from the description on the vertex path. On #7332 these draws do not need the emulation: yripper's
376079ada4(fragmentBarycentricBuiltins, the I/J reads fromBaryCoordKHRon MoltenVK) handles them, andmaindoes not have it. With #8083 and #8339 merged on top, Lana gets past that draw and then stops with the sameIl2CppExceptionWrapperas God of War, right after openinglevel7.resS.Not checked: where the exception is raised. Under lldb the process exits on its own before that point, so I have no backtrace yet. Also not checked: Linux and Windows, the CTest suite and the validation layer.
If you have an idea which call could make IL2CPP throw while loading a scene, I can test a candidate on both titles.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-21T15:31:56Z.
@imellag thank you for testing on the M1 Pro, and for #9193.
Planet of Lana: #9193 is the right fix for that stop, so I'm not adding a copy of it here. The cause: MoltenVK does report
VK_KHR_fragment_shader_barycentric(an M2 Pro showsfragmentShaderBarycentric = true), butFragmentBarycentric.hppswitches it off for MoltenVK because Metal rejectsPerVertexKHRinputs. With no geometry shaders either, a pixel shader that reads I/J falls back to the triangle-list emulation inDraw.cpp, and that game's draw isn't a plain triangle list. Reading I/J from the built-ins, as #9193 does, avoids the fallback. #9193 merges onto this branch with no conflicts. On an M2 Pro (macOS, x86_64 under Rosetta 2, MoltenVK), #9193 merged on top of this PR builds with no failed objects, and the tests it lists pass:request_serializer,agc_shader_memory,agc_driver_graphics,agc_fragment_barycentric,agc_driver_pixel_barycentric_emulation, plusagc_driver_interpolation_modesandinterpolation_reference_range. I have no copy of Planet of Lana here, so this covers the tests, not the game.SteamWorld Dig and Sonic Mania Plus: I have neither game here, so I can't reproduce them yet. Two things should narrow it down:
APS5_TRACE_CALLS=libkernel,libc,libSceAgc(comma-separated library names, orall).The last few calls before
Il2CppExceptionWrappershould show which one returns something IL2CPP doesn't expect.sharedassets0.assets.resSis the/dev/urandomopen, and here it never happens. So the failure is inside the asset load itself, not in random-number setup. On macOS, the paths that behave differently there are file-backedmmap(16 KiB host pages, andPROT_EXECis removed while mapping, then restored),st_blocks/st_blksizecopied straight from APFS, andfreadpassing through to the host. A short trace from (1) would tell us which one, and I'll fix it here.If you can post the trace for either title, I'll take it from there.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-21T15:31:57Z.
@Mauro42K yes please, M1 results would help. Everything so far has been checked on an M2 Pro (and imellag's M1 Pro and M4 Pro reports), so another machine catches anything that depends on the chip or the macOS version.
Please test the PR's head commit as it stands (
0a6c0fdd2right now), built as in the PR description (x86_64 under Rosetta 2, Vulkan through MoltenVK):ctest --test-dir build-macos -j6 --timeout 300. On the M2 Pro, 22 of 1774 tests fail at this commit. Post the names of the ones that fail for you and I'll compare them with that list; anything new is what I'm after, and the test name plus its output is enough.Please include your chip, RAM, macOS version, and MoltenVK / Vulkan SDK version.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-21T17:00:42Z.
@iamthehimansh thanks. A small correction first: my machine is an M4 Pro (not M1 Pro), and SteamWorld Dig and Sonic Mania Plus are not from my report; my two titles are God of War Sons of Sparta (PPSA28997) and Planet of Lana (PPSA19450).
APS5_TRACE_CALLSis not available on macOS (docs/dev/debt/libc.mdon this branch says call tracing is missing there), so instead I printed the managed exception insceKernelDebugWriteCppExceptionInfowith a local, never-pushed log line (class name and message read from theIl2CppExceptionthe wrapper points to). That found two causes, both fixed on the closed #7332 branch but in no open PR. With the two fixes below on top of this PR and #9193, both titles reach gameplay.Machine: Apple M4 Pro (24 GB), macOS 27.0.1, x86-64 under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0).
Build: this PR at
0a6c0fdd2+ #9193, full Release build, 0 failed objects.1. The
Il2CppExceptionWrapperat load is aSystem.DllNotFoundException. Could you add the fix to this PR?So it is not the asset load:
libfmodstudioimports fromlibfmod, whichsceKernelLoadStartModuleopenedRTLD_LOCAL, and dyld's flat lookup skips local images. Ycaro Gabriel fixed this on #7332 in2d500a0d36("make guest modules visible to later modules' imports on macOS": hostdlopenalwaysRTLD_GLOBALon macOS,dlsymwith the default handle still skips modules the guest opened locally, plus aguest_dynamic_loadercheck and a debt line) and split it out as #8481, which the open-PR limit closed. It cannot go tomainon its own, because the macOSDefaultScopeSymbol/FromGuestModuleit changes exist only in this PR, so this PR is the place for it. It applies here with two trivial conflicts: the newimagefield goes in its own#ifdef __APPLE__next toglobalOrderinModule, and the debt line goes after the existing entries.2. God of War then stops on an exception it is meant to catch: opened as #9263.
sceKernelGetModuleInfoForUnwindlefteh_frame_addr/eh_frame_sizeat zero for a relinked image on macOS, andsceSysmoduleGetModuleInfoForUnwindthrew on every call (failed to open /proc/self/maps), so the title's own unwinder could not reach its handler. #9263 fixes both onmain(carried over from mugurc's92d7098f1on #7332). Your DWARF unwind tables in the libraries already cover the host frames, so #7332's libunwind fallback is not needed on top of this PR.2d500a0d36FMODUnity.BusNotFoundExceptionends interminateduring the first scene loadFrames dumped through menus and gameplay in both titles look correct. Each cell is one run (automated input, restored save), so the fps values are a reference, not an A/B.
Tests on this stack:
guest_dynamic_loader,guest_dynamic_loader_variant_names,guest_sysmodule,guest_unwind_module_info(new on macOS in #9263),unwind_record_boundsand theunwind_callback_abi_*tests pass.Not checked: Linux and Windows, the full CTest suite and the validation layer on this stack.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-21T17:26:02Z.
@imellag thank you, and sorry for both mistakes in my last reply: your machine is an M4 Pro, your titles are God of War Sons of Sparta and Planet of Lana (SteamWorld Dig and Sonic Mania Plus were my mix-up), and
APS5_TRACE_CALLSdoes not work on macOS, asdocs/dev/debt/libc.mdsays. Printing the managed exception was the right way to find it.Ycaro Gabriel's fix is now in this PR:
2d500a0d36is cherry-picked asc8a1d75e5with Ycaro Gabriel as author (-xkeeps the reference), resolved as you described: theimagefield sits in its own#ifdef __APPLE__next toglobalOrderinModule, and the debt line goes after the existing entries.One change from the original: on this branch git applied the
RTLD_LOCALfilter to the LinuxDefaultScopeSymbolrather than the macOS one, since both have the same body here. I moved it into the macOSDefaultScopeSymboland put the newguest_dynamic_loaderchecks under#ifdef __APPLE__, so the Linux and Windows views ofDynamicLoader.cppandGuestDynamicLoader.cppare unchanged.Checked on an M2 Pro (x86-64 under Rosetta 2, MoltenVK, Vulkan SDK 1.4.363.0):
guest_dynamic_loader,guest_dynamic_loader_variant_names,guest_sysmodule,guest_needed_modules,guest_deferred_dependenciespassI don't have either title, so the gameplay result is yours, not mine. #9263 stays a separate PR against
main, as you opened it.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Mauro42K on 2026-10-21T22:45:06Z.
Hi @iamthehimansh — I completed the full CTest suite on an Apple M1 MacBook Pro (MacBookPro17,1; 8 GB RAM).
Environment: macOS 27.0.1 (build 26A434), with the test binaries built for x86_64 and run under Rosetta 2. The build used Release, Ninja, Apple clang 21.0.0, CMake 4.4.0, and -j2. Vulkan SDK 1.4.363.0 and MoltenVK 1.4.2 were available; Vulkan reported an Apple M1 device.
Tested commit:
3d649b8a47from #8658.The unfiltered CTest run discovered 1,780 tests:
CTest exited with code 8. I then reran two failures individually three times each with -j1:
All 25 failures from the full run
Comparison with the M2 Pro report
The PR description reports 1,650 passes, 40 failures, and 83 skips on an M2 Pro. Both reports therefore have 1,690 non-skipped tests, while this M1 run has seven more skipped tests. The report identifies 37 of the M2 failures broadly as graphics-related and names three Rosetta/macOS failures—guest_floating_point, guest_math_exact, and guest_path_name_length—which also failed here.
This is not a controlled hardware comparison: the exact M2-tested SHA is not identified in the PR description, and the machines and macOS environments differ. The description does not list the 37 graphics failure names, so their overlap with the M1 failures cannot be established. These results alone do not demonstrate an M1-specific regression.
AI-assisted: yes. Codex was used to run and document the tests; logs and results were retained locally.
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-21T22:54:54Z.
@Mauro42K thank you, this is very useful. It's the first full M1 run of this branch.
I compared your 25 failures with my M2 Pro (macOS 26.6, Rosetta 2, MoltenVK 1.4.2). The PR head is now
a1fb8e3e9.20 match failures I already track on M2. These are MoltenVK device limits (clip/cull distance, sampler min/max reduction, multisample storage, robust buffer reads, no geometry shaders), Rosetta x87/FP-environment limits (
guest_floating_point,guest_math_exact), the import write-protection trade-off (agc_write_tracking), and the tessellation/rect-list draws that are still open.agc_driver_sample_orderpasses once #9193 lands.guest_path_name_lengthis fixed since your commit (4ebe71f2e). Darwin'sPATH_MAXis 1024, the same as the guest limit, so a 1023-byte guest path overflowed once the host root was prepended.5 do not fail on M2. Each one passes 3/3 alone and in my full run at
a1fb8e3e9:guest_kernel_app_archive_plain: you saw it pass 3/3 alone too, so I'm treating it as load-sensitive for now.agc_driver_vertex_target_range_imported,agc_driver_pass_input_hazard,agc_driver_uint8x4_color_target: could you rerun these three alone with-j1? If they still fail on M1, they are an M1 GPU / MoltenVK difference and I'll look at them.guest_refused_connect: failing 3/3 alone on M1 looks real. The test makes one blocking connect to a closed loopback port, through libkernel and through libSceNet, and expects ECONNREFUSED (61). The host errno passes straight through on macOS, so EINVAL (22) would mean Darwin'sconnect()itself returned EINVAL on your machine. That could be a macOS 27 change. A backtrace would show whichRequirefires:The skip difference (90 vs 83) comes from tests added upstream since the description was written. I'll update the numbers in the PR description.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-10-21T23:52:23Z.
One data point on
guest_refused_connect: at this PR's heada1fb8e3e9it passes 3/3 alone (-j1) on an M5 Pro with macOS 27.2 (26B5086k), Release x86_64 under Rosetta 2, Apple clang 21. So it isn't macOS 27 as a whole. It's either something in 27.0.1 or specific to the M1.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Mauro42K on 2026-10-22T00:08:14Z.
Hi @iamthehimansh — thanks for comparing the M1 and M2 Pro results!
I completed the requested focused retests on my Apple M1 MacBook Pro (8 GB RAM, macOS 27.0.1), using the existing Release x86_64 / Rosetta 2 build with Vulkan SDK 1.4.363.0 and MoltenVK 1.4.2.
Tested commit:
3d649b8a47from #8658.All three AGC tests were run individually, three times each, with -j1:
Test M1 result
agc_driver_vertex_target_range_imported 3/3 PASS
agc_driver_pass_input_hazard 3/3 FAIL
agc_driver_uint8x4_color_target 3/3 FAIL
The vertex target test now passes consistently in isolation, although it failed in my earlier full suite.
The other two failures are reproducible:
Regarding guest_refused_connect:
I attempted the requested LLDB investigation. LLDB recognized the x86_64 executable but remained blocked during run, without producing a backtrace. A separate isolated CTest attempt also stalled beyond its configured timeout.
Earlier isolated runs had failed 3/3 with SIGABRT, but these new attempts did not provide a usable backtrace or confirm which Require failed. I therefore cannot establish whether EINVAL is the actual cause.
I also saw @Gonic0’s M5 Pro/macOS 27.2 result (3/3 PASS). That is useful additional evidence, although our macOS versions and tested commits differ.
Additional homebrew result — ccleste (PPSA59322):
I independently tested ccleste v1.00 on this M1 using the same #8658 commit. The official package passed SHA-256 verification, SELF extraction succeeded, and conversion with --macos --to-rosetta completed successfully.
At runtime, Vulkan initialized, game resources loaded, and stereo audio initialized at 48 kHz. Audio playback was not audibly verified.
The process then aborted with exit code 134 at the first mesh-path draw due to the barycentric/mesh capabilities unavailable through this MoltenVK path. It did not reach the menu or playable levels.
This matches the ccleste limitation already documented in the PR description.
All worktrees remain unchanged, and the detailed logs are retained locally.
These comparisons are preliminary because the M1 and M2/M5 reference runs do not all use identical commits or macOS versions.
AI-assisted: yes. Codex was used to run and document the tests; I reviewed the reported results.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T03:39:39Z.
Review: COMMENTED
Checked the
MacOsImage.cppload-command reserve on its own, since no relinker test covers it.Machine: Apple M2 Max, macOS 27.2 (26B5091g), Xcode 27.0 (27A266a), relinker-only Release build, arm64.
Method: only the
core/relinker/elfpatcher/src/macos/MacOsImage.cpphunk from head31163870c, applied tomain6ef5a1c4c(the PR's merge base). Relinked theimport_fixtureandtls_fixtureguests fromtest_macos_output.pywith--macos --skip-sce-module, rancodesign -s - -fon the output, and compared the 32 bytes atLC_MAIN'sentryoffbefore and after signing.codesign -s -codesign -vmain6ef5a1c4c, importLC_CODE_SIGNATURE(itsdataoff/datasize)main6ef5a1c4c, tlsLC_CODE_SIGNATURE(1d000000 10000000 ...)So on
mainan ad-hoc signature silently overwrites the start of the entry stub andcodesign -vstill reports the file as valid; with the reserve the stub survives. Relinker-onlyctestwith the hunk: 229/229 (arm64;macos_guest_weak_importsruns its x86_64 output under Rosetta).Two notes:
install_name_toolalso uses that space. With Xcode 27'sinstall_name_tool -add_rpath /opt/anyps5/libs, both outputs (with and without the reserve) are refused with "larger updated load commands do not fit".__TEXThas no sections in this layout; I did not dig into howinstall_name_toolfinds the end of the header padding.test_macos_output.py'scheck_structure, requiremacho.entryoff - macho.end >= 0x400for executables. On Darwin the test could also sign a copy and compare the stub bytes, as above.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-22T11:05:59Z.
@jotitadev thank you, that is exactly the check this reserve was missing.
I reproduced it on an M2 Pro (macOS 26.6.2, Xcode 27.1, x86_64 relinker output):
codesign -s - -fcodesign -vinstall_name_tool -add_rpath /opt/anyps5/libsYou were right about the comment. It no longer says install_name_tool uses that space. It now says what the reserve is for: codesign appends
LC_CODE_SIGNATUREthere, and when that lands on the entry stub it corrupts the stub's first instructions whilecodesign -vstill passes. Run paths are written at relink time with--rpath, so install_name_tool is not needed for this output. Like you, I have not looked into why it refuses this layout.I added both guards you suggested to
test_macos_output.py:check_structurerequiresentryoff - end >= 0x400for executables.check_signing_keeps_entry_stubad-hoc signs a copy of the import and tls outputs and requires the 32 bytes atentryoffto be unchanged.To check that the guards fail when they should, I set the reserve to 0. The test then fails with
import: only 8 bytes between the load commands and the entry stub, so codesign overwrites the stub. With the reserve back it passes, and the converter suite passes (230/230).Commit: https://github.com/boykopovar/AnyPS5/pull/8658/commits/0c74e5edd426cbf8b3a067b6e7dc1c58909e53a8,
test(relinker): guard the macOS load-command reserve against codesign.AI-assisted: yes (Cana)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:54:08Z.
Open #9738 is a standalone PR for the shutdown-order fix already present at this PR head: both make
RegistrationPreparePool::Lifecycle()return a never-destroyednew std::mutexon Apple. Their pairwise merge conflicts inShaderRegistry.cpp. Please coordinate with #9738’s author on which change lands first and ensure the merged result contains this hunk only once; the current overlap is not declared by itsDepends online.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T12:11:33Z.
@iamthehimansh three of my open PRs touch lines this port also changes, and reviewers asked us to agree an order. None depends on this PR, and each is small, so I suggest this: whichever lands first, the other drops its copy of the hunk.
core/libs/tests/GuestHostStandardError.cpp: now the same construction as yours on macOS (throw through__cxa_allocate_exception_nid_postfixand__cxa_throw_nid_postfix, original assertion kept), so the hunk becomes a no-op either way.core/libs/prx/libkernel/Socket/src/Udp.cppshutdown_nid_postfix: treats XNU'sENOTCONNfor an already-shut direction as success only whengetpeernamestill reports a peer, and retriesSHUT_WRafterSHUT_RDWR. If yours lands first I rebase and keep whatever your version already handles.core/libs/prx/libc/src/Math.cppacosf: ports msun'se_acosf.cfor|x| <= 1on every host, which replaces the__APPLE__double-precision computation on those lines. If yours lands first I rebase onto it; if mine does, youracosfhunk can go.If you would rather fold any of them into this PR, say so and I will close that one.
Imported from boykopovar/AnyPS5. Originally posted by prosperkartik on 2026-10-22T12:23:07Z.
Full build and ctest of the current head on a base M4, including the GPU tests.
Machine: Mac mini, Apple M4 (10-core GPU), 16 GB, macOS 26.5.1 (25F80), x86_64 under Rosetta 2, Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2. Vulkan SDK 1.4.363.0 (core component only, no system-global install), MoltenVK 1.4.2,
apiVersion1.4.357.Commit:
1688e5abb(this PR withmainmerged in).Build:
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON, full build: 0 failed objects. For comparison,mainatcc0078595on the same machine stops with 52 failed objects (feof_unlocked/ferror_unlockedmacros inFileStream.hpp,SIGUSR1, missing<initializer_list>, Mach-O inline asm).ctest:
ctest --test-dir build -j6 --timeout 300, then the GPU tests again with-j4once the SDK was set up (source setup-env.sh,VK_DRIVER_FILESpointed atMoltenVK_icd.json). Combined over 1,801 tests: 1,689 pass, 91 skip, 21 fail.Not on any list in this thread:
agc_driver_ds_permutefails every run, alone included (-j1):ds permute: lane 8 permute is 0x00000000, expected 0x00001019. Lanes 0 to 7 pass. The device reportssubgroup=32. The test has been onmainsincedbb76aa51(Oct 4) and is not in the M1 or M2 Pro failure lists, so it passes there; it may be specific to the M4's GPU family or to macOS 26.5.1.guest_app_archive_presentandguest_app_archive_damagedfail when they run at the same time: both shared one temp root. Fix in #9741 (113 of 300 concurrent pairs fail without it, 0 with it). Not specific to this PR.Same as the M1 and M2 Pro lists:
agc_driver_f32_constant_factor_tininess,agc_driver_f32_denormal_flush,agc_driver_image_plane_bias_on_single_level_volume,agc_driver_multisample_retirement,agc_driver_pixel_interlock(MoltenVK:type 'const constant spvDescriptorSetBuffer0 &' is not valid for attribute 'buffer'),agc_driver_pixel_sample_iteration,agc_driver_pooled_buffer_range,agc_driver_rect_list_indirect,agc_driver_sample_mask_multisample,agc_driver_sample_order,agc_driver_tessellation, the four clip/cull distance tests,agc_write_tracking,guest_floating_point,guest_math_exact.Fail on the M1, pass here:
agc_driver_image_table_reuse,agc_driver_pass_input_hazard,agc_driver_uint8x4_color_target,agc_driver_vertex_target_range_imported,guest_kernel_app_archive_plain,guest_path_name_length,guest_refused_connect(also 3/3 alone; it now passes on 26.5.1, 26.6 and 27.2, and fails only on 27.0.1).Skips: device limits (13 no
shaderFloat64, 8 noshaderBufferInt64Atomics, 8 no graphics pipeline libraries, 2 noVK_EXT_mesh_shader, 2 no native f16 RTE with kept denormals, 2 multisample counts), 2 udmabuf Linux-only, 13 with no message, and display tests that cannot open a window in a ctest run: 16 "Vulkan support is either not configured in SDL", 7 "NSWindow should only be instantiated on the main thread!", 2vkCreateInstanceresult -9.Setup note for other testers: SDK 1.4.363.0 also installs the KosmicKrisp ICD, which is arm64 only; an x86_64 process logs
incompatible architecture (have 'arm64', need 'x86_64')for it and continues on MoltenVK. PointingVK_DRIVER_FILESatMoltenVK_icd.jsonremoves the noise.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-22T14:19:54Z.
Thanks all. Answers in one place.
@rooklz, agreed: whichever lands first, the other drops its copy of the hunk.
GuestHostStandardError.cpp): same construction as mine. If #9654 lands first, I drop my hunk on the next rebase.shutdown_nid_postfix): this covers what my hunk does: ENOTCONN counts as success whilegetpeernamestill finds a peer. It also handles theSHUT_RDWR→SHUT_WRretry, which mine does not, so yours is the better version.acosf): porting msun'se_acosf.cfor every host is better than my__APPLE__double-precision workaround, and it is what the console does. If it lands first, my hunk goes.guest_math_exact. Whichever lands second has to rebase onto the first anyway. I'm happy to run the macOS socket and math tests on the rebased version and post the results.@MarcZX10 / @mugurc, #9738: right, both make
RegistrationPreparePool::Lifecycle()return a never-destroyednew std::mutex. Here it is under#ifdef __APPLE__; #9738 does it on every host, which is simpler. I suggest #9738 lands first. On the next rebase I drop my#ifdefblock, so the merged result has the hunk once. I've added #9738, #9625, #9654 and #9668 to the overlap line in the description.@MarcZX10, one more of the same kind, from #7233:
Driver::WaitIdlenow takesGuestMemory::GpuMutex(), and it runs from the driver's destructor at exit. The mutex is a function-local static that is constructed after the driver, so it is destroyed first. glibc locks a destroyed mutex without complaint, but macOS returns EINVAL, so every video-out test that skips without a display aborted at exit (recursive_mutex lock failed: Invalid argument). Here I fixed it under#ifdef __APPLE__the same way (new GpuMutexType, never destroyed). It is still undefined behaviour on Linux, so you may want the same change for every host, like #9738.@prosperkartik, thank you for the full M4 run.
agc_driver_ds_permute: it passes on my M2 Pro. The recompiler lowersDS_PERMUTE_B32withOpGroupNonUniformShuffleonly, with no LDS and no barrier: it shuffles each of the 32 source lanes and keeps the one whose target is this lane (SpirvAluEmitterMath.cpparound line 1170). Lane 8's expected0x1019comes from source lane 25, so a lane-8 zero means the shuffle from lane 25 didn't return its value or its active bit. Since lanes 0 to 7 pass and the code has no Apple special case, this looks like an M4 GPU family or MoltenVK shuffle issue across 8-lane groups rather than something in this PR. If you can run it once withMVK_CONFIG_LOG_LEVEL=4and attach the generated Metal for the compute shader, I'll check whether the shuffle survives the translation.guest_refused_connectfailing only on 27.0.1: that fits @Mauro42K's M1 report, so it looks like a macOS 27.0.1connect()regression.VK_DRIVER_FILESnote is useful, and it is now in the description's machine section.Rebase: merged
mainup to8b3e39832intof3bc0258f; GitHub now shows it as mergeable. The merge needed two macOS follow-ups: theGpuMutexexit fix above, and theStdio.cppconflict with #9303. Linux and Windows keep #9303 exactly as written, and the macOSgetdirentriesuses the same/app0symlink-type lookup. The full macOS suite shows no new failures.AI-assisted: yes (Cana)
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-22T14:27:35Z.
Sorry for the slow reply to these two; I missed them in the thread.
@Gonic0, thank you, that narrows it a lot. With @prosperkartik's M4 run,
guest_refused_connectnow passes on macOS 26.5.1 (M4), 26.6 (M2 Pro) and 27.2 (M5 Pro). The only failure is @Mauro42K's M1 on 27.0.1. So it is either a 27.0.1connect()change or something M1-specific, not this PR on macOS 27 in general.@Mauro42K, thank you for the focused retests and the ccleste run.
agc_driver_vertex_target_range_importedpassing 3/3 alone means its full-suite failure was load-sensitive, like the few I already treat that way.agc_driver_pass_input_hazardandagc_driver_uint8x4_color_targetfail 3/3 on your M1, but pass on my M2 Pro and on @prosperkartik's M4. That points at the M1's GPU family under MoltenVK rather than at this PR's code. If you have time, the output of one run of each withMVK_CONFIG_LOG_LEVEL=4would show whether MoltenVK reports anything for those pipelines.guest_refused_connect: no need for LLDB. Running the test binary directly prints the failing check before it aborts: The stall past the timeout is new information too. If it hangs again,sample <pid> 5from a second terminal shows where it is waiting.3d649b8a4is a few merges behind. The current head isf3bc0258f, which adds the 1023-byte path fix (guest_path_name_length), the JSON underflow fix and the exit-time GPU mutex fix. None of those should change the three AGC results above.AI-assisted: yes (Cana)
Imported from boykopovar/AnyPS5. Originally posted by prosperkartik on 2026-10-22T14:44:14Z.
@iamthehimansh, here is the
agc_driver_ds_permuterun you asked for, at the current headf3bc0258fon the same M4 (macOS 26.5.1, MoltenVK 1.4.2), withMVK_CONFIG_LOG_LEVEL=4 MVK_CONFIG_DEBUG=1 MVK_CONFIG_SHADER_DUMP_DIR=<dir> ANYPS5_NO_SHADER_CACHE=1. Same result:ds permute: lane 8 permute is 0x00000000, expected 0x00001019. MoltenVK logs no warnings or errors. Of the 12 compute shaders dumped, one contains the shuffles:shader-cs-6a936899f53064c2(full Metal below).What the translation does. In the SPIR-V, each candidate source lane gets three unconditional shuffles before any logic (
.spvasmline 225 on):SPIRV-Cross forwards those shuffles into MSL's short-circuit operators (
.metalline 131):So the second and third shuffles only run on lanes whose own condition held. A lane that reads from a source lane which skipped that
simd_shufflegets no defined value, which fits lane 8 missing lane 25's0x1019.Native check on the M4, without AnyPS5. A minimal Metal kernel (
repro.swiftbelow), 32 threads, lane 8 reads lane 25, 200 runs each:hoisted:uint got = simd_shuffle(v, from); out = c ? got : x;0x1019inlined:out = c ? simd_shuffle(v, from) : x;0x1008inlined_and: shuffle behind&&, then in?:0x1019So on this GPU a shuffle inside a divergent
?:arm does not see the source lane's value, while the&&form happens to be compiled flat. Whether the M2 Pro compiles theinlinedform flat is the open question; runningxcrun swiftc -O -o repro repro.swift -framework Metal && ./reprothere would show it. If the M2 Pro also prints 200 wrong runs forinlined, the difference is in how the full shader gets compiled per GPU family. Either way, the shuffles in the SPIR-V are unconditional and the MSL makes them conditional, which looks like a SPIRV-Cross issue rather than something in this PR.repro.swiftGenerated Metal:
shader-cs-6a936899f53064c2.metalAI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-22T15:01:16Z.
@prosperkartik thank you, that is a very clear diagnosis.
Your
repro.swifton my M2 Pro (macOS 26.6.2):So the M2 Pro also gives a wrong value for a
simd_shuffleinside a divergent?:arm. The difference is not in the hardware rule, only in how Metal compiles the fullds_permuteshader for each GPU family: on the M2 Pro the forwarded shuffles happen to come out flat, and on the M4 at least lane 25's does not.I agree it is a SPIRV-Cross issue. The SPIR-V has the shuffles unconditional, and forwarding them into
&&/?:operands makes them conditional, which is not valid for subgroup operations. Your reduced kernel is exactly what a KhronosGroup/SPIRV-Cross issue needs. Since you found it, it should be filed under your name; if you file it, I'll link it from this PR's description next toagc_driver_ds_permute.On our side, I could stop the forwarding by giving each shuffle result a second use, so SPIRV-Cross has to keep it in a temporary. That would change the emitted shader on every host, so I would rather not add it to this PR. A separate small PR could do it, if a maintainer prefers a workaround until SPIRV-Cross is fixed.
AI-assisted: yes (Cana)
Imported from boykopovar/AnyPS5. Originally posted by prosperkartik on 2026-10-22T15:19:37Z.
@iamthehimansh, filed: https://github.com/KhronosGroup/SPIRV-Cross/issues/2722. It reproduces on SPIRV-Cross
main(300681b) with an 11-line shader; the generated MSL is wrong 200/200 on the M4 and correct when the shuffle is kept in a temporary.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T18:37:18Z.
Review: CHANGES_REQUESTED
Thanks for the work and the thorough testing notes. This is too large to land as one PR (135 files, ~10 libraries plus relinker, web converter and shader recompiler), and it currently needs changes before it can go in:
main:core/libs/prx/libc/src/Interfaces.cpp,core/libs/tests/GuestInterfaces.cppandcore/libs/tests/GuestNetCtlAp.cppconflict on logic, not just adjacency (reports above also mentionGraphics/src/Texture.cppandDynamicLoader.cpp).//comment lines (e.g. the0xfe0040000/ driver block explanation inDriverMemory.hpp,ShaderRegistry.cpp). CONTRIBUTING allows none outside technical debt; move them todocs/dev/debt/<library>.md, as your description offers.maincompile on macOS first, then kernel/libc/net per library, then the AGC driver address move + shader retargeting, then relinker/web. Each PR with its own tests andDepends on.Depends on.DEVICE_LIMITATION-matching reason (tools/check_skips.py) instead of failing, and the rest (agc_write_tracking,guest_refused_connectflakes) need a fix or a documented debt line in the PR that introduces the code.Formatting.cpp,QueuedIndexReadOrder.cpp,FileStream.hpp,Jit.cpp...) in a small first PR lets the full Linux/Windows Build prove them cheaply.Welcome to push the split PRs; they'll be reviewed individually.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T19:36:18Z.
Review: CHANGES_REQUESTED
Re-reviewed against
6ee81b979: since the last review the range-diff only has merges ofmainand a reworded commit message, so the earlier points still stand://comment lines (e.g.DriverMemory.hpp,ShaderRegistry.cpp); CONTRIBUTING allows none, move the notes todocs/dev/debt/<library>.md.DEVICE_LIMITATION-matching skip or a debt line in the PR that introduces the code.You've already agreed to the split, so please continue with the topic PRs. The open-PR limit is what closed #10362, so close this PR (or reduce it to a tracking list) once the first split PRs are up; they will be reviewed individually.
Pull request closed