The frontend

The menu and the runtime are SDL's window, as on Android. The parts the system does are a thin frontend over it, in the same shape as Android's MainActivity and src/gui/android.c:

macOS

ScarletNX.app is the desktop program in a bundle: scarletnx in Contents/MacOS, the themes and the licenses in Contents/share, where an installed copy looks for them. It works as on Linux. The menu extracts and recompiles through the driver as a child process, with SDL's own file and folder dialogs. Its data folder is ~/Library/Application Support/scarletnx. Share Log saves the logs' zip in the Logs folder's share/ and opens it in the Finder. The app is signed ad hoc, as Apple silicon runs no unsigned code. A copy from a download may need Open from the Finder's menu the first time.

The Vulkan driver the apps carry is MoltenVK, Ryujinx's build of it (V380-Ori/Ryujinx.MoltenVK), which carries the patches an emulator's pipelines need and mainline MoltenVK lacks. Both apps carry it in their Frameworks, and a game's folder gets that library beside its copy of the runtime (snx_deploy_runtime), a second name where the disk allows one and a copy where it does not, as a read-only app image or one macOS translocated leaves. A game plays as <data folder>/recompiled/<id>/<id>, outside the bundle, where SDL's own search of @executable_path/../Frameworks reaches nothing. The runtime hands SDL the library its own folder holds (backend/sdl3.c), and a run with no window loads the same file without SDL's video. The bare scarletnx of a checkout has no library to deploy and no bundle around it, so it uses the system's Vulkan loader (Homebrew's molten-vk and vulkan-loader). Where the Mac has KosmicKrisp, vulkan_driver=auto takes it before either (below).

The 3DS and the Vita's windows open through common/gpu/vk/window.c, which names the same library to SDL and takes its own entry points from it. One process must hold one copy of MoltenVK: a second copy's MVKInstance is a different type, so the surface call hands one copy's instance to the other's vkGetInstanceProcAddr and the process segfaults. That is what a Mac with Homebrew's molten-vk in the loader's ICD folders saw when volk took the system loader and SDL took the bundle's library.

KosmicKrisp (experimental)

KosmicKrisp is Mesa's Vulkan driver on Metal, and a game runs on it where the Mac has it. vulkan_driver = auto, the default, takes KosmicKrisp where the Mac has it and runs it, else the MoltenVK the app carries, else the system's Vulkan loader. vulkan_driver = moltenvk in the game's .ini, or --vulkan-driver=moltenvk, keeps MoltenVK, and kosmickrisp asks for KosmicKrisp alone. The option is in Graphics in the launcher's Settings and in the game's menu. The first vulkan: line of the log names the driver that runs and why.

The support is experimental: a game may draw wrong or stop on KosmicKrisp. Nor is one driver the faster everywhere. On an M4 Max, with KosmicKrisp vulkan-sdk-1.4.363 and MoltenVK 1.4.2, one game's first cutscene ran at 55 fps on KosmicKrisp (48 to 58 over 5 runs) and at about 2 on MoltenVK, which has no VK_EXT_conditional_rendering: each occlusion-tested draw makes the CPU wait for the GPU (#777). The same game's station scene ran at 48 to 52 fps on MoltenVK and 27 on KosmicKrisp; there, vulkan_driver = moltenvk is the faster one.

Where KosmicKrisp lacks an extension or a feature that the renderer asks for, the runtime takes the path it has for a driver without it, as it does for the features MoltenVK lacks. The game keeps running on KosmicKrisp, and a run does not change driver half way. What that costs today: transform feedback is not captured, a sampler with a border colour of its own takes the nearest of black and white, wireframe draws solid, and the frame pacing falls back to its timer. One game's title screen has run on it, at the frames a second the game caps itself to.

KosmicKrisp runs through the Vulkan loader: the runtime gives SDL the loader and sets VK_DRIVER_FILES to the ICD, and SDL and volk take that one library. MoltenVK loads directly. auto leaves a driver the environment already names: with VK_DRIVER_FILES (or VK_ICD_FILENAMES) set it loads the loader and lets that variable pick, and with SDL_VULKAN_LIBRARY set it loads that library. moltenvk and kosmickrisp go over both.

KosmicKrisp needs an Apple silicon Mac with macOS 26 or later, and the Vulkan loader. auto passes over it on an older Mac, or in a build for Intel Macs, and the log says why. The runtime finds it:

The loader comes from the same folders, or from /opt/homebrew/lib/libvulkan.1.dylib or /usr/local/lib when the driver and the loader are installed apart. LunarG's build is self-contained, and Homebrew's links the prefix's libraries. Homebrew's build can also need a newer macOS than the SDK's, so the SDK's driver is the one to carry. Do not put Homebrew's driver in the app. A driver the setting names and the Mac does not have is a warning in the log, which names the driver that plays in its place (auto's), so a game still starts.

The setting is the app's, for its Switch games. The 3DS and Vita frontends take the driver through the Vulkan loader, and a Mac without VK_DRIVER_FILES gives them MoltenVK. Their own settings do not name a driver yet.

The app carries KosmicKrisp when the build gets the SDK's macOS folder:

cmake --preset macos -DSNX_MOLTENVK=$HOME/moltenvk-macos -DSNX_KOSMICKRISP=$HOME/VulkanSDK/1.4.363.0/macOS

The app then carries both drivers. The build takes the SDK's lib/libvulkan_kosmickrisp.dylib, its lib/libvulkan.1.dylib and the API version of its ICD JSON, and writes an ICD JSON whose library path is relative. The CI's app is built without it, so on a Mac without Homebrew's mesa or the SDK, auto plays the app's MoltenVK.

The Vulkan tests run on the driver that the Vulkan loader picks. To run them on KosmicKrisp, name its ICD:

VK_DRIVER_FILES=/opt/homebrew/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json \
    ctest --test-dir build/macos -R '^(3ds_vk_.*|vulkan_.*|vk_.*)$' --output-on-failure

They pass on both drivers on a Mac that has KosmicKrisp. The vulkan_driver test makes a device through the ICD where the Mac has one, and checks nothing where it has none, as a machine without mesa or the SDK does.

iOS

An iOS app runs one process and may not start another, so the iOS app works like Android's game activity without its menu's driver:

The IPA is unsigned: AltStore, SideStore or a developer account signs it for the device (a Mac can too: Installing from a Mac), with dist/apple/ScarletNX.entitlements (the larger address space and memory limit a game needs). It holds MoltenVK's framework.

Code compiled while a game runs on macOS, 32-bit games' blocks and the runtime JIT's functions, goes through the runtime's own loader (src/common/cpu/recompiler/loader/code_loader.c). The arm64 back end (src/common/cpu/recompiler/arm64) writes it as ELF objects with Darwin's calling convention, and the loader places them in MAP_JIT memory, which each thread sees either writable or executable. The app is signed without the hardened runtime, so MAP_JIT needs no entitlement.


Made from docs/hosts/apple.md at 69237645142c. GPL-3.0-or-later.