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:
src/gui/apple.m (Objective-C) is the menu's side: the data folder, the game the menu plays, and the SDL window's
UIWindow or NSWindow for the Swift to present over.dist/apple/Frontend.swift (Swift) is the system's side, called from apple.m through @_cdecl functions: on iOS,
the document picker SDL lacks there.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 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:
SNX_KOSMICKRISP (its own folder holds the driver, its loader and the
ICD JSON, and a game's folder gets the same three from the deploy), elsemesa (/opt/homebrew/share/vulkan/icd.d, or /usr/local), else$HOME/VulkanSDK, the newest first.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.
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:
dumps/ (a game's .nsp or .xci), keys/ (prod.keys), recompiled/ (what the app makes, each game as
recompiled/<id>/<id>_code.snxobj with _data/) and logs/. The menu's settings, state and caches are in the app's
Library/scarletnx/, which the Files app does not show (Running a game on iOS).host: when another app runs ScarletNX. Preparing a dump
runs the driver on a thread of the app, since an app may not start a process. A dump picked outside dumps/ is
copied into it first. The thread has a 64 MiB stack, where an iOS thread's default is 512 KiB.src/nx/runtime/entry.c): the runtime starts once per
process, so the app ends with the game.scarletnx-logs-<date>.zip or scarletnx.log in logs/share/ of its Documents
and opens that folder in the Files app, or opens logs/.logs/scarletnx-console-<date>.log in its
Documents (the 14 newest days kept), after a banner with the
device, the system and the limits the app has, with the menu's own lines (GUI), and a fatal error, the
menu's or a game's, is also written to logs/scarletnx-error.log. A phone shows no console, so these are what to read
when a run fails; Share Log sends both. The banner also gives the disk space free for the app, and the menu's start
says if the last start ended without an exit of the menu or of its game: a crash, the memory limit, or a close from
the app switcher. logs/.running-<pid> is the mark (GUI).picker: is each step of the document picker: its open, its answer, the item and its security scope. An
open with no answer after it is a pick that iOS did not end. lifecycle: is the app going to the background and
back, and the low memory warnings, on iOS, from the menu's start to the end of the process. run: and recompile:
are each start and end, with the status, the time and the disk space free, and on iOS the app's memory. On iOS a
game gets a start line only: it runs in the app's process once the menu closes, and its end ends that process, so
the next start's banner tells if it ended with an exit. state: is each change of
the thermal state and of the low power mode. folders: lists dumps/, keys/ and recompiled/ at the start, by
name and size, and the folders the player added. dialog: is the answer of each picker, or the error of SDL. The
banner always gives the app's bundle and the program of its process. When the program is not in the bundle, a host
such as LiveContainer runs the app, and the banner says so in a host: line. In the lines of this level and in the
bundle and program of the banner, a path in the home folder starts with ~.logs/metrickit-<date>_<time>.json, named by the end of the time that it covers. The console log
gets one line for each payload, with its file (or the file and why it was not written) and what it holds. The
payloads that the system gave before this start are read again at each start, and a file that already holds one is
not written again.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.