macOS (Apple Silicon) support: native build running under Rosetta 2 with MoltenVK #102

Manually merged
github merged 8 commits from gh-pr/102/head into gh-pr/102/base 2026-11-26 09:10:28 +00:00
Owner

@⁠m1abdullahh on GitHub · 2026-07-23 01:31 UTC · original
m1abdullahh:macos-support → main · +577 −39 · 16 files · 8 commits · merged 2026-07-28 17:03 UTC

Overview

This adds a native macOS build target for Apple Silicon. The emulator compiles and runs as an x86_64 binary under Rosetta 2 (guest PS5 code executes natively as x86_64; the emulator itself is translated), with graphics going through Vulkan to MoltenVK to Metal. It builds on the current tree, boots a commercial title into gameplay, and responds to controller input.

What was tested

Raiden III x MIKADO MANIAX boots through the loader, Vulkan init, swapchain, and window creation into guest execution, renders frames continuously, and takes controller input; the audio pipeline is wired up. It is a functional port with a couple of known rendering artifacts and performance still to improve (see Known issues), not a finished product, but well past proof of concept.

Verified locally on an M3 Pro MacBook Pro: clean configure, build, link, JIT codesign, and launch under Rosetta 2.

Building on macOS

Prerequisites: Apple Silicon Mac, Rosetta 2, Xcode Command Line Tools, CMake, Ninja, and a Vulkan runtime that provides MoltenVK (for example the LunarG Vulkan SDK for macOS).

git clone --recursive https://github.com/<you>/KytyPS5
cd KytyPS5
cmake -S src -B _Build/macos -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_OSX_ARCHITECTURES=x86_64
cmake --build _Build/macos --target kyty_emulator --parallel

The build produces an x86_64 binary and codesigns it with the JIT entitlements automatically. Run a game with --game <dir|elf> (see --help for options). If the window fails to appear because of a Rosetta issue in the macOS window chrome, set KYTY_BORDERLESS=1 for a borderless window.

Known issues

  • Some rendering artifacts remain: video noise during cutscenes and a black box around certain sprites. These are on the texture-upload side and under investigation; they do not block boot or input.
  • Frame rate is modest (around 26 fps in the tested title). This appears consistent with the title's general performance and is not macOS-specific.
  • The guest Ngs2 audio path uses a stub for one call, which may leave a gap in some in-game audio.
**@⁠m1abdullahh** on GitHub · 2026-07-23 01:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102) `m1abdullahh:macos-support` → `main` · +577 −39 · 16 files · 8 commits · merged 2026-07-28 17:03 UTC ## Overview This adds a native macOS build target for Apple Silicon. The emulator compiles and runs as an x86_64 binary under Rosetta 2 (guest PS5 code executes natively as x86_64; the emulator itself is translated), with graphics going through Vulkan to MoltenVK to Metal. It builds on the current tree, boots a commercial title into gameplay, and responds to controller input. ## What was tested Raiden III x MIKADO MANIAX boots through the loader, Vulkan init, swapchain, and window creation into guest execution, renders frames continuously, and takes controller input; the audio pipeline is wired up. It is a functional port with a couple of known rendering artifacts and performance still to improve (see Known issues), not a finished product, but well past proof of concept. Verified locally on an M3 Pro MacBook Pro: clean configure, build, link, JIT codesign, and launch under Rosetta 2. ## Building on macOS Prerequisites: Apple Silicon Mac, Rosetta 2, Xcode Command Line Tools, CMake, Ninja, and a Vulkan runtime that provides MoltenVK (for example the LunarG Vulkan SDK for macOS). ```sh git clone --recursive https://github.com/<you>/KytyPS5 cd KytyPS5 cmake -S src -B _Build/macos -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_OSX_ARCHITECTURES=x86_64 cmake --build _Build/macos --target kyty_emulator --parallel ``` The build produces an x86_64 binary and codesigns it with the JIT entitlements automatically. Run a game with `--game <dir|elf>` (see `--help` for options). If the window fails to appear because of a Rosetta issue in the macOS window chrome, set `KYTY_BORDERLESS=1` for a borderless window. ## Known issues - Some rendering artifacts remain: video noise during cutscenes and a black box around certain sprites. These are on the texture-upload side and under investigation; they do not block boot or input. - Frame rate is modest (around 26 fps in the tested title). This appears consistent with the title's general performance and is not macOS-specific. - The guest Ngs2 audio path uses a stub for one call, which may leave a gap in some in-game audio.
- hostException: Mach/POSIX signal-based host fault handler mirroring the
  Windows vectored handler (SIGSEGV/SIGBUS/SIGILL), behind
  '#elif defined(__APPLE__)'. Windows and Linux branches are untouched.
- sysLinuxVirtual: mach_vm_region-based is_mapped (no /proc/self/maps on
  macOS), PTHREAD_MUTEX_NORMAL, and a MAP_FIXED carve-in-place allocator that
  never leaves an unmapped hole for dyld/Rosetta/Metal to claim. All
  __APPLE__-guarded; the original Linux allocator path is preserved verbatim.
- sysLinuxDbg/sysLinuxFileIO: libgen.h for basename(), and a POSIX
  opendir/readdir implementation of SysFileGetDents (previously a stub).
- memory/memoryAddressSpace: anonymous shm_open backing (macOS has no
  memfd_create) and re-reserve-on-unmap so a guest MAP_FIXED remap never
  destroys a host mapping (__APPLE__-guarded). Drops host <sys/mman.h> MAP_*
  macros so the guest's constexpr MAP_* constants compile (no-op on Windows).
- pthread: undef the host PTHREAD_STACK_MIN macro; on non-Windows, pin the
  stack-switch asm's guest rsp/rbp to callee-saved r14/r15 (the template
  clobbers r12/r13); __APPLE__ no-op for the absent pthread_condattr_setclock.
  The Windows stack-switch asm is byte-identical.
- network: define SOCKET/INVALID_SOCKET for the non-Windows paths (were
  undefined at 20+ use sites), and rename the non-Windows kernel_clock_*
  helpers to the CamelCase names the callers already use. Both repair the
  shared non-Windows build. Integer reinterpret_cast -> static_cast.
RunEntry switches to the guest stack with an asm template that clobbers
r12/r13 before consuming its inputs. With plain "r" constraints the compiler
may place func/guest_rsp/guest_rbp into r12/r13, so 'callq *func' jumps
through the saved host rsp -- a latent miscompile on every platform that any
unrelated codegen change can trigger. Pin the inputs to rbx/r14/r15, which the
template never touches and the SysV callee preserves.

General correctness fix (not macOS-specific); the same fix is applied to
pthread RunOnGuestStack.
- pageManager: GPU write-tracking via Mach VM queries + mprotect (mprotect
  cannot report the previous protection, so the expected-old check is dropped),
  thread id via pthread_mach_thread_np, 4 KB page-size check -- __APPLE__-guarded.
- shaders/renderDraw/vulkanWindow: MoltenVK lacks VK_EXT_color_write_enable,
  VK_EXT_depth_clip_enable and depthBounds; fall back to static color-write
  masks and default depth clipping, request VK_KHR_portability_subset, and
  reuse the graphics queue for present when only one queue is exposed. Non-Apple
  pipeline/extension setup is unchanged.
- window: optional borderless window (KYTY_BORDERLESS) to sidestep a Rosetta
  NSException in macOS window chrome.
Region-ownership locks resolve the current thread via GetCurrentThreadId()
on Windows and EXIT elsewhere. Use the Mach thread port on macOS (nonzero
per-thread id; 0 stays the no-owner sentinel).
The present worker thread shows the window, updates its icon and title, and
recreates a lost Vulkan surface. AppKit traps with 'Must only be used from the
main thread' when these run off the main thread. Route them through a small
task queue drained by the SDL main loop (an SDL_USEREVENT wakes the loop when
it is blocked in SDL_WaitEvent). Title updates are fire-and-forget; showing
the window and surface recreation wait for completion.

Windows and Linux call the SDL functions directly, as before.
_Build is the conventional out-of-tree build location (only _Build/vscode-clang
was ignored); a stray git add could sweep build artifacts into a commit.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:10:27 +00:00
github manually merged commit d128139f15 into gh-pr/102/base 2026-11-26 09:10:28 +00:00
Author
Owner

@⁠ADEMOLA200 on GitHub · 2026-07-26 14:53 UTC · original

@⁠Nmzik What's the progress on this, is it going to get merge after conflicts are resolved?

**@⁠ADEMOLA200** on GitHub · 2026-07-26 14:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5084006282) @⁠Nmzik What's the progress on this, is it going to get merge after conflicts are resolved?
Author
Owner

@⁠Nmzik on GitHub · 2026-07-26 15:51 UTC · original

@⁠m1abdullahh @⁠ADEMOLA200 I’m currently rewriting the entire renderer implementation, rewrite TextureCache, moving D16 processing to a compute shader, removing colorWriteEnable from the Vulkan requirements, and adding Linux support. So, of course, I’ll merge it.

**@⁠Nmzik** on GitHub · 2026-07-26 15:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5084220810) @⁠m1abdullahh @⁠ADEMOLA200 I’m currently rewriting the entire renderer implementation, rewrite TextureCache, moving D16 processing to a compute shader, removing colorWriteEnable from the Vulkan requirements, and adding Linux support. So, of course, I’ll merge it.
Author
Owner

@⁠ADEMOLA200 on GitHub · 2026-07-26 17:41 UTC · original

@⁠m1abdullahh @⁠ADEMOLA200 I’m currently rewriting the entire renderer implementation, rewrite TextureCache, moving D16 processing to a compute shader, removing colorWriteEnable from the Vulkan requirements, and adding Linux support. So, of course, I’ll merge it.

That's awesome man keep up the good work

**@⁠ADEMOLA200** on GitHub · 2026-07-26 17:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5084640281) > @⁠m1abdullahh @⁠ADEMOLA200 I’m currently rewriting the entire renderer implementation, rewrite TextureCache, moving D16 processing to a compute shader, removing colorWriteEnable from the Vulkan requirements, and adding Linux support. So, of course, I’ll merge it. That's awesome man keep up the good work
Author
Owner

@⁠m1abdullahh on GitHub · 2026-07-26 19:54 UTC · original

@⁠Nmzik Nice, that all sounds great for this port to mac too. MoltenVK doesn't expose colorWriteEnable so dropping that requirement kills one of my workarounds.

Since the renderer files are moving right now, I'll wait for the rewrite to settle before fixing the conflicts here. Just ping me when it's a good time and I'll have it green and re-tested on Apple Silicon within a day or so if needed. Also happy to test any WIP branches on real Apple hardware if that helps.

**@⁠m1abdullahh** on GitHub · 2026-07-26 19:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5085133098) @⁠Nmzik Nice, that all sounds great for this port to mac too. MoltenVK doesn't expose colorWriteEnable so dropping that requirement kills one of my workarounds. Since the renderer files are moving right now, I'll wait for the rewrite to settle before fixing the conflicts here. Just ping me when it's a good time and I'll have it green and re-tested on Apple Silicon within a day or so if needed. Also happy to test any WIP branches on real Apple hardware if that helps.
Author
Owner

@⁠Nmzik on GitHub · 2026-07-28 00:29 UTC · original

@⁠m1abdullahh Hi! I don’t want to bother you, but could you please rebase your changes onto the latest version? I’ve cherry-picked many of your fixes already, of course keeping you credited as the contributor. you can disable colorWriteEnable for now on APPLE platform. Some of changes are no longer needed (one Vulkan queue etc)

**@⁠Nmzik** on GitHub · 2026-07-28 00:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5098406790) @⁠m1abdullahh Hi! I don’t want to bother you, but could you please rebase your changes onto the latest version? I’ve cherry-picked many of your fixes already, of course keeping you credited as the contributor. you can disable colorWriteEnable for now on APPLE platform. Some of changes are no longer needed (one Vulkan queue etc)
Author
Owner

@⁠m1abdullahh on GitHub · 2026-07-28 01:54 UTC · original

@⁠Nmzik Rebased onto latest main, conflicts resolved and all checks green. It got a lot smaller since you already picked up several of the fixes, thanks for that.

Notes from the rebase:

  • colorWriteEnable and depthClipEnable are now gated off on APPLE like you suggested, MoltenVK exposes neither.
  • Your new present thread was the only real issue: AppKit aborts if a window is shown or its title/surface is touched off the main thread, so on macOS those calls now get marshaled to the SDL main loop. Windows/Linux paths are unchanged.
  • Retested Raiden III on the M3 Pro, boots and renders fine on the rewritten renderer.
**@⁠m1abdullahh** on GitHub · 2026-07-28 01:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5099019635) @⁠Nmzik Rebased onto latest main, conflicts resolved and all checks green. It got a lot smaller since you already picked up several of the fixes, thanks for that. Notes from the rebase: - colorWriteEnable and depthClipEnable are now gated off on APPLE like you suggested, MoltenVK exposes neither. - Your new present thread was the only real issue: AppKit aborts if a window is shown or its title/surface is touched off the main thread, so on macOS those calls now get marshaled to the SDL main loop. Windows/Linux paths are unchanged. - Retested Raiden III on the M3 Pro, boots and renders fine on the rewritten renderer.
Author
Owner

@⁠Nmzik on GitHub · 2026-07-28 17:03 UTC · original

@⁠m1abdullahh Thanks! This looks very clean. I guarded RunEntry just in case. Merged.
One note for a future PR: I suspect TryEmulate may not work correctly on Apple platforms under Rosetta 2. Some games like Legacy of Kain (PPSA18152) executes AMD-specific x86-64 instructions, whereas Rosetta 2 appears to emulate Intel behavior. This does not need immediate attention; I just wanted to mention it for future investigation github.com/KytyPS5/KytyPS5@8520cdb30b/src/common/hostException.cpp (L153-L177)

**@⁠Nmzik** on GitHub · 2026-07-28 17:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/102#issuecomment-5107254410) @⁠m1abdullahh Thanks! This looks very clean. I guarded `RunEntry` just in case. Merged. One note for a future PR: I suspect `TryEmulate` may not work correctly on Apple platforms under Rosetta 2. Some games like Legacy of Kain (PPSA18152) executes AMD-specific x86-64 instructions, whereas Rosetta 2 appears to emulate Intel behavior. This does not need immediate attention; I just wanted to mention it for future investigation https://github.com/KytyPS5/KytyPS5/blob/8520cdb30b6a8a1a4a9838441de06cbd0a554d8d/src/common/hostException.cpp#L153-L177
This discussion has been locked. Commenting is limited to contributors.
No description provided.