Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Route C shell: the performance HUD follows each game's setting at Play, with MetalFX's rows

v0lumehi759d9f4199d9
diff --git a/patches/0038-dm-framework-env-switch-row.patch b/patches/0038-dm-framework-env-switch-row.patch
index 3c56d489..a98b455e 100644
--- a/patches/0038-dm-framework-env-switch-row.patch
+++ b/patches/0038-dm-framework-env-switch-row.patch
@@ -12,11 +12,11 @@ Upstream-Status: fork-only (waits for the runtime profile, seedds/nxnative#492)
Reason: opt-in game framework for the launcher (route C M1): it carries profile.tsv and sets DM_PROFILE, which exist only with the runtime-profile patch (seedds/nxnative#492 is still a design note), so it goes upstream after that
Issue: LNPANDY/NX2Apple#144
---
- docs/env_switches.tsv | 7 +++++++
- 1 file changed, 7 insertions(+)
+ docs/env_switches.tsv | 8 ++++++++
+ 1 file changed, 8 insertions(+)
diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv
-index 6993f8dc..aee6d49a 100644
+index 6993f8dc..ec096fad 100644
--- a/docs/env_switches.tsv
+++ b/docs/env_switches.tsv
@@ -34,9 +34,12 @@ DM_FD_LOG diagnostic `=<seconds>` logs, every that many seconds, the number and
@@ -32,7 +32,15 @@ index 6993f8dc..aee6d49a 100644
DM_FS diagnostic When set, logs file opens, paths not found or not mounted, and a read summary every 64 MiB or 1000 reads
DM_FSLOG diagnostic `=<file>` writes one TSV line per ReadFile: seconds since boot, guest path, offset, length and guest buffer address
DM_FSLOG_HASH diagnostic With `DM_FSLOG`, adds a column with the FNV-1a 64 hash of the bytes read
-@@ -273,6 +276,10 @@ DM_SF_TRACE diagnostic `=1` logs every request on the game's own HIPC client ses
+@@ -60,6 +63,7 @@ DM_GPU_CAPTURE_KEEP diagnostic Before each GPU capture, prunes the capture folde
+ DM_GUEST_SPAWN_TEST diagnostic `=1` runs a self-test before `nnMain`: a host-started guest thread does SDK malloc / free and locks an `nn::os` mutex, and the result is logged; `=2` also keeps a resident thread
+ DM_HITCH_DUMP diagnostic `=<ms>[:<s>]`: when no frame has been presented for that long (from s seconds on), logs every guest thread once per stall: wait, last SVC, pc, lr, frames and registers
+ DM_HLECOUNT diagnostic `=<file>` (`%d` = process ID) writes at exit a TSV of how many times the guest called each HLE function, zero counts included
++DM_HUD_PER_LAYER switch `1`: the shell app sets it at start together with `MTL_HUD_ENABLED`, and the game view then turns Apple's Metal HUD off on its layer unless `DM_METAL_HUD` is `1`
+ DM_ICON path `=<image>` gives `build_ipa.sh` another app icon (default the `icon.jpg` beside the RomFS)
+ DM_IMPORTS diagnostic When set, logs each import the loader binds to a host function and each forced takeover
+ DM_KBD switch `=<text>`: the system keyboard returns that text as OK without showing an input box; unset with no window, it returns cancel
+@@ -273,6 +277,10 @@ DM_SF_TRACE diagnostic `=1` logs every request on the game's own HIPC client ses
DM_SHAKE_G switch `=<G>`: on iOS, the acceleration beyond gravity above which a flick of the phone shakes the controller's six-axis sensor (default 1.5)
DM_SHARED_FONT path Font file served for every shared-font type except the Nintendo extension (default `$DM_FONT_DIR/standard.ttf`, then macOS's Arial Unicode)
DM_SHARED_FONT_EXT path Font file served for shared-font type 5, the Nintendo extension with the button icons (default `$DM_FONT_DIR/nintendo_ext.ttf`, made by `make_ext_font.py`)
diff --git a/patches/0039-route-c-shell.patch b/patches/0039-route-c-shell.patch
index 2424068b..80140de6 100644
--- a/patches/0039-route-c-shell.patch
+++ b/patches/0039-route-c-shell.patch
@@ -16,15 +16,16 @@ Reason: the route C shell (M2): its library is the fork's frontend-ios package a
Issue: LNPANDY/NX2Apple#144
---
dm/ios/Shell/Shell-Bridging-Header.h | 2 +
- dm/ios/Shell/ShellApp.swift | 73 +++++++++++
+ dm/ios/Shell/ShellApp.swift | 73 ++++++++++++
dm/ios/Shell/ShellEngine.h | 10 ++
- dm/ios/Shell/ShellMain.m | 187 +++++++++++++++++++++++++++
- dm/ios/project-shell.yml | 113 ++++++++++++++++
- dm/ios/tests/test_shell_build.py | 157 ++++++++++++++++++++++
+ dm/ios/Shell/ShellMain.m | 172 +++++++++++++++++++++++++++
+ dm/ios/Sources/front_ios.m | 1 +
+ dm/ios/project-shell.yml | 113 ++++++++++++++++++
+ dm/ios/tests/test_shell_build.py | 157 ++++++++++++++++++++++++
dm/ios/tools/build_ipa.sh | 39 +++++-
- dm/ios/tools/build_shell.sh | 117 +++++++++++++++++
+ dm/ios/tools/build_shell.sh | 117 ++++++++++++++++++
dm/ios/tools/gen_manifest.py | 9 +-
- 9 files changed, 703 insertions(+), 4 deletions(-)
+ 10 files changed, 689 insertions(+), 4 deletions(-)
create mode 100644 dm/ios/Shell/Shell-Bridging-Header.h
create mode 100644 dm/ios/Shell/ShellApp.swift
create mode 100644 dm/ios/Shell/ShellEngine.h
@@ -138,10 +139,10 @@ index 00000000..40f6f04e
+void dm_shell_present_game(void);
diff --git a/dm/ios/Shell/ShellMain.m b/dm/ios/Shell/ShellMain.m
new file mode 100644
-index 00000000..28a43902
+index 00000000..a0312068
--- /dev/null
+++ b/dm/ios/Shell/ShellMain.m
-@@ -0,0 +1,187 @@
+@@ -0,0 +1,172 @@
+// Route C shell (docs/launcher-c-plan.md M2): the app that hosts the engine and several games' frameworks. It starts on the
+// library (frontend-ios's ShellHost views, ShellApp.swift) instead of booting a game at launch as dm/ios/Sources/main.m does, and
+// when the player presses Play, dm_shell_start_game() does what main.m's boot_env() does before UIApplicationMain, for the chosen
@@ -184,13 +185,6 @@ index 00000000..28a43902
+ fprintf(stderr, "fork patches: %s\n", [fork_patches isKindOfClass:NSString.class] && fork_patches.length ? fork_patches.UTF8String : "none");
+}
+
-+// The variables worth a line of their own: what makes a report readable (which game, which data, which profile)
-+static int logged_key(const char *k) {
-+ static const char *keys[] = {"DM_PROFILE", "DM_ROMFS", "DM_SAVE", "DM_TEMP", "DM_MSL_DIR", "DM_PSO_BUNDLE", "DM_NVN_SHMAP", "DM_AOC_DIR", "DM_SAVE_SYNC", "DM_LANG", "DM_ENV_FILE_KEYS"};
-+ for (size_t i = 0; i < sizeof keys / sizeof *keys; i++) if (!strcmp(k, keys[i])) return 1;
-+ return 0;
-+}
-+
+const char *dm_shell_start_game(const char *const *keys, const char *const *values, int n, const char *const *argv, int argc,
+ const char *executable, const char *marker, const char *log_path, const char *cwd) {
+ static char err[512];
@@ -201,7 +195,7 @@ index 00000000..28a43902
+ fprintf(stderr, "shell: starting %s (%s)\n", argv[1], executable);
+ for (int i = 0; i < n; i++) {
+ setenv(keys[i], values[i], 1);
-+ if (logged_key(keys[i])) fprintf(stderr, "boot: %s=%s\n", keys[i], values[i]);
++ fprintf(stderr, "boot: %s=%s\n", keys[i], values[i]); // every one: a report then shows which of the game's settings reached the engine
+ }
+ if (cwd && *cwd) chdir(cwd);
+ front_hud_env(); // before the early loading below can make a device (main.m's order)
@@ -293,25 +287,17 @@ index 00000000..28a43902
+@end
+
+// The performance HUD (the per-game setting DM_METAL_HUD) needs MTL_HUD_ENABLED in the environment before Metal starts in this
-+// process, and the library's views start it long before Play: set at Play (front_hud_env) it came too late and the HUD stayed off,
-+// although front_ios.m logged it on (verified on a device: the same variable given at launch shows it). So it is decided here, before
-+// UIApplicationMain, from the game played last, the one Play most likely starts again. A change of the setting made in this session
-+// takes effect at the next start of the app (front_hud_env still sets it at Play, for the layer's own HUD properties).
-+static void metal_hud_at_start(void) {
-+ if (getenv("MTL_HUD_ENABLED")) return; // given at launch (Xcode, devicectl): it wins
-+ NSString *last = nil; NSDate *when = nil;
-+ for (NSString *fw in [NSFileManager.defaultManager contentsOfDirectoryAtPath:NSBundle.mainBundle.privateFrameworksPath error:nil]) {
-+ if (![fw hasPrefix:@"DmGame"] || ![fw hasSuffix:@".framework"]) continue;
-+ NSString *tid = [fw substringWithRange:NSMakeRange(6, fw.length - 6 - 10)];
-+ NSDate *d = [[NSUserDefaults alloc] initWithSuiteName:[@"dev.nx2apple.shell.game." stringByAppendingString:tid]].dictionaryRepresentation[@"shell.lastPlayed"];
-+ if ([d isKindOfClass:NSDate.class] && (!when || [d compare:when] == NSOrderedDescending)) { when = d; last = tid; }
-+ }
-+ if (!last) return;
-+ id hud = [[NSUserDefaults alloc] initWithSuiteName:[@"dev.nx2apple.shell.game." stringByAppendingString:last]].dictionaryRepresentation[@"launcher.DM_METAL_HUD"];
-+ if ([hud isKindOfClass:NSString.class] && [hud intValue]) {
-+ setenv("MTL_HUD_ENABLED", "1", 1); setenv("MTL_HUD_HIDE_METALFX_METRICS", "1", 0); // as front_hud_env does
-+ fprintf(stderr, "shell: performance HUD on for this start (%s, played last, has it on)\n", last.UTF8String);
-+ }
++// process, and the library's views start it long before Play: set at Play it comes too late and the HUD stays off. So the shell turns
++// Metal's HUD on for every start, here before UIApplicationMain, and the game's own setting decides at Play: front_ios.m sets the game
++// layer's developerHUDProperties mode to default, or with DM_HUD_PER_LAYER to disabled. A change of the setting in the library applies
++// at the next Play, as every other setting does (verified on an iPhone 2026-10-30: on and off in one start each, no HUD over the
++// library). MTL_HUD_HIDE_METALFX_METRICS stays unset, so the HUD shows MetalFX's rows (input and output size) while the Upscaling
++// setting MetalFX scales the picture.
++static void metal_hud_per_layer(void) {
++ if (getenv("MTL_HUD_ENABLED")) { fprintf(stderr, "shell: MTL_HUD_ENABLED given at launch, the HUD follows it\n"); return; } // Xcode, devicectl: it wins
++ setenv("MTL_HUD_ENABLED", "1", 1);
++ setenv("DM_HUD_PER_LAYER", "1", 1);
++ fprintf(stderr, "shell: Metal's HUD is ready, each game's Performance HUD setting turns it on at Play\n");
+}
+
+int main(int argc, char **argv) {
@@ -325,10 +311,22 @@ index 00000000..28a43902
+ fprintf(stderr, "shell: free space %lld bytes\n", avail ? avail.longLongValue : -1LL);
+ for (NSString *fw in [NSFileManager.defaultManager contentsOfDirectoryAtPath:NSBundle.mainBundle.privateFrameworksPath error:nil])
+ fprintf(stderr, "shell: framework %s\n", fw.UTF8String);
-+ metal_hud_at_start();
++ metal_hud_per_layer();
+ }
+ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass(App.class)); }
+}
+diff --git a/dm/ios/Sources/front_ios.m b/dm/ios/Sources/front_ios.m
+index ec3d5548..0184365d 100644
+--- a/dm/ios/Sources/front_ios.m
++++ b/dm/ios/Sources/front_ios.m
+@@ -88,6 +88,7 @@ static void launcher_done(void) { [g_root startGame]; }
+ [self.view addSubview:self.game];
+ g_layer = (CAMetalLayer *)self.game.layer;
+ if (getenv("DM_METAL_HUD") && atoi(getenv("DM_METAL_HUD"))) { g_layer.developerHUDProperties = @{@"mode": @"default"}; LOG("front end: Metal performance HUD on (DM_METAL_HUD)"); } // Apple's HUD over the game: frame rate, frame and GPU time, memory
++ else if (getenv("DM_HUD_PER_LAYER")) { g_layer.developerHUDProperties = @{@"mode": @"disabled"}; LOG("front end: Metal performance HUD off (DM_METAL_HUD)"); } // the shell turns Metal's HUD on for every start (ShellMain.m)
+ dm_haptics_apple_init();
+ self.pad = dm_gamepad_view(self.view.bounds);
+ self.pad.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
diff --git a/dm/ios/project-shell.yml b/dm/ios/project-shell.yml
new file mode 100644
index 00000000..b66a730e
diff --git a/patches/series b/patches/series
index 76cfdd49..0b1fbb12 100644
--- a/patches/series
+++ b/patches/series
@@ -31,7 +31,7 @@
0036-route-c-framework-build.patch
0037-route-c-framework-tests.patch
0038-dm-framework-env-switch-row.patch
+0041-front-progress-hook.patch
0039-route-c-shell.patch
0040-nsp-shell-framework.patch
-0041-front-progress-hook.patch
0042-runtime-profile-every-site.patch