Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ One [NUP container](../../../docs/development.md#the-packing-script-in-detail) o
Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk.sh` in the work folder).

- Current on an M5 Pro MacBook Pro (16-inch, 20-core GPU, 24 GB, macOS 27.2, 2026-11-09), `kokiri-deck` from a deck autosave with the full library of chain `dedc9391c30b`, at full resolution (Dynamic resolution off), two runs a variant: in a window a locked 60 fps (59.8–60.0, frame p99 16.8–19.4 ms, GPU p50 10.2 ms). In fullscreen on its ProMotion screen it held 40 fps (39.6–40.1) at the same GPU time, with every present a 120 Hz refresh late and every other link tick skipped: [The 60 Hz link at 40 fps in fullscreen on a ProMotion screen](../../../docs/reference/frame-rate.md#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen). With the 120 Hz link there, 58.8–59.6 fps, frame p99 25.3 ms; with the screen held at its fixed 60 Hz mode, 60.0 fps, frame p99 16.9 ms, which fullscreen now switches to. MetalFX present upscaling to the 3456-wide fullscreen cost no measurable GPU time (59.4–59.7 fps). Resident about 10 GB, GPU allocated 11.2–11.4 GB; the prepare step took 7.3 s on a first start.
- Current on an M4 Pro (20-core GPU, 24 GB, macOS 27.2, 2026-11-10, chain `cb2e91c138e3`, full resolution, `DM_FPS_HOLD=off`), headless from a save on the castle town drawbridge looking over Hyrule Field (about 2,720 draws a frame): the game's own GPU time is 14.5–15.0 ms a frame, and it ran at 52–55 fps, not 60.
- Other apps: a terminal app and WindowServer took 1.7–3.9 ms of GPU per game frame ([Other apps' GPU work inside the game's frame](../../../docs/reference/frame-rate.md#other-apps-gpu-work-inside-the-games-frame)); the log's `GPU by process` line names them. With the terminal drawing most (a coding agent's progress line), 47.7–50.4 fps over five runs, GPU span p50 17.4–18.1 ms; in the player's windowed session with its window hidden it still drew 60–72 ms/s and the game held 54–56 fps.
- In fullscreen on the MacBook's own screen (ProMotion, `DM_SCREEN_MATCH=0`, `DM_METAL_HUD=1`, `DM_FPS_HOLD=off`, the same save, 2026-11-10, the last 1,200 frames of 95 s runs): on the default 120 Hz link 54.5–55.9 fps in six runs (frame p50 16.7 ms, p95 25.0–25.5 ms, 3–13 frames of 300 held too long), with `DM_PRESENT_LINK=0` 59.5 and 59.7 fps (frame p50 16.1–16.2 ms, p95 19.9–20.0 ms, 0–1 of 300), runs interleaved; the game's GPU time was 14.7–15.3 ms a frame and other apps took 71–107 ms/s in all of them, and the title paced alike on both (60.00 fps). The GPU span is the same on both (p50 16.1 ms, p90 19.5–19.8 ms); the link costs a refresh for each late frame: [A GPU-bound game on the 120 Hz link pays a refresh for every late frame](../../../docs/reference/frame-rate.md#a-gpu-bound-game-on-the-120-hz-link-pays-a-refresh-for-every-late-frame). Not a locked 60 either way: the span's p90 is over a vsync.
- Disproved here (2026-11-10): Apple's Metal HUD as the cost of the window (without it 59.0, 59.0 and 56.0 fps on the link: the first two were the link's fast state, not the HUD); `DM_NVN_TBDR=1` (57.7 against 59.2 fps headless, one run each, as on the village walk).
- Open: Kakariko Village, the same Mac and settings (2026-11-10, headless from a save in the village, about 2,940 draws, one run a variant unless said): 49.2 fps, the game's GPU 17.2–17.4 ms a frame. The frame has Hyrule Field's shape; what it adds is grass, drawn as `DrawMeshTasks` (in a pass dump `vs=- vc=3`, 3 task groups each, which earlier text here took for full-screen triangles). In the depth `EQUAL` colour pass 11 such draws cost 2.1 of its 2.7 ms (fragment shaders `96dbc0392691b437` 0.83 ms, `1019c4564aa0d265` 0.63, `0fb4823639295a2d` 0.54, `4a1bf8a23dd76493` 0.15, the others about 0), the same at render scale 1, 0.75, 0.62 and 0.5 (2.12–2.17 ms) though the samples passed fall fourfold; with every one of their fragment shaders a constant colour 0.57 ms remains (task, mesh, raster). Without those draws the game's GPU is 14.85 ms and the frame rate 57.2 fps; without 16 of the 21 grass shaders of the depth-only passes (prepass, shadow maps) 14.8–15.3 ms. The host encodes them one to one as Metal mesh draws. Disproved for the colour pass: a late depth test (`[[early_fragment_tests]]` on all 11, three runs a side, 2.73–2.81 against 2.72–2.74 ms), occlusion counting (Boolean mode 2.72 ms), the light loop (0–1 lights a cluster), the GPU clock, the 36 indexed strips of the pass (0.2 ms), and the fragment translation's overhead (an overlay of the four shaders at `-O2`, without their uniform bound guards and NaN selects, or both: 2.62–2.79 against 2.71–2.72 ms). Inferred, not measured: 2x2 quad shading of sub-pixel blades. Not tried: the mesh entry's per-meshlet setup on the current chain (a 2,845-word zero fill, an 800-word payload copy, four barriers; shrinking that memory did not help on an earlier chain, see Open).
- Open lead, not tried: the frame's 1536x864 colour and depth pair is drawn in about 20 render passes, each loading and storing both (100–340 µs apiece with 1–6 draws); the game's compute dispatches between its draws end most of them, and `tbdr_pass_merge.py` counts 11 splits where the later pass loads everything and samples none of it (98 MB of attachment traffic a frame).
- Current: the title and menu, a movie behind them, are a locked 60 fps (p50 16.67 ms, GPU span 15.6 ms).
- Resolved: the title movie and the cutscene movies stuttered in small regular jerks at that steady 60 fps on a Mac that decodes AV1 with dav1d (M1, M2). The frames were on time and the movie's pictures were not: the player's `advance` (`main+0x3b61ea0`) found no new picture in 546 and 569 of about 2,900 frames of the title on an M2 Pro, and showed the last one again. Two causes, both general: [packets decoded inside the submission](../../../docs/reference/movies.md#nncodec-packets-decoded-inside-the-submission), on the player's one reader thread, which also gives the shown pictures back, and [dav1d one frame at a time](../../../docs/reference/movies.md#dav1d-decoded-one-frame-at-a-time) (15.4 ms a packet in the movie's heaviest five seconds, 122 ms the longest). After: 0 or 1 in 2,567 to 3,036 frames a run (eight runs of 54 s, headless, `DM_PROBE=main:3b61ed8,main:3b61f80` counting the failed and the good calls), and `DecodeAsync` returns in 0.1 ms at the median and 1.1 ms at the 99th percentile, from 1.9 and 120 ms. Open: not run on an M1 or M2 with four performance cores, nor on an iPad; a Mac with a hardware AV1 decoder (M3 on) decodes with VideoToolbox, where only the first cause applied, not measured.
- Game speed: the game steps its time by a frame ratio, its base rate (60, or 30) / its int frame rate, whatever the frame took (`main+0x6e6cc4` on v131072), so frames longer than a vsync played in slow motion (seen by the user on a slower Mac; [issue 1375](https://github.com/seedds/nxnative/issues/1375)'s M1 Max ran the title at about 28 fps). With `fps_target 60` the ratio is the host's frame step × base / 60 ([A fixed frame step plays in slow motion on a slow Mac](../../../docs/reference/frame-rate.md#a-fixed-frame-step-plays-in-slow-motion-on-a-slow-mac)), a stub placed by its function's fingerprint ([`patches.py`](patches.py)). Mac runs on the M6 (2026-11-08, a test host on the libraries of chain `3ee493b2c3a4`): the user's play sessions held 60 fps with 2- and 3-vsync holds while areas loaded, game time 1.000 of real time by the host's count. That count is the stub's own; no run on a Mac slow enough to show the slow motion before and after.
Expand Down Expand Up @@ -139,6 +145,8 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25
- [A NaN colour under a zero blend weight](../../../docs/reference/shaders.md#a-nan-colour-under-a-zero-blend-weight): resolved, white clouds over the ground mist between Kokiri Forest and Hyrule Field and over the ferns at the camera in Kokiri Forest ([issue #1839](https://github.com/seedds/nxnative/issues/1839)). The mist shader `5ad65c0eefd09c7f` writes NaN at alpha 0 where its layer has density 0; NVIDIA's blender, with the option NVN's driver sets, adds nothing there, Apple's stored the NaN.
- [A first start builds every base of the prewarm list before the first frame](../../../docs/reference/rendering.md#a-first-start-builds-every-base-of-the-prewarm-list-before-the-first-frame): the 450-475 s first-start prepare on an M5 Max; the Mac app now bundles the list's pipelines (`--prebake`, on by default) and it took 4.3 s.
- [The 60 Hz link at 40 fps in fullscreen on a ProMotion screen](../../../docs/reference/frame-rate.md#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen): 40 fps in fullscreen on an M5 Pro MacBook Pro with the GPU at 10 ms of the 16.7, every present one 120 Hz refresh late and every other display-link tick skipped; the screen's fixed 60 Hz mode held 60.0 fps there and fullscreen now switches to it, with the 120 Hz link (59 fps) for screens with no such mode.
- [A GPU-bound game on the 120 Hz link pays a refresh for every late frame](../../../docs/reference/frame-rate.md#a-gpu-bound-game-on-the-120-hz-link-pays-a-refresh-for-every-late-frame): open. In fullscreen on an M4 Pro MacBook Pro's own screen 54.5–55.9 fps on the default 120 Hz link against 59.5 and 59.7 with `DM_PRESENT_LINK=0`, the GPU span the same on both.
- [Other apps' GPU work inside the game's frame](../../../docs/reference/frame-rate.md#other-apps-gpu-work-inside-the-games-frame): 48–50 fps in a heavy area with late frames every four to six, the game's own GPU time a steady 14.75 ms a frame; a terminal app and WindowServer had 3.9 ms of each frame.
- [The shader package and the shader map come from different splits](../../../docs/reference/packing.md#the-shader-package-and-the-shader-map-come-from-different-splits): resolved, a black screen with sound in a build through NX2Apple ([issue #1841](https://github.com/seedds/nxnative/issues/1841)); the present pass was translated from a terrain shader's record. Records now carry their keys, and the shader build finds them by key.
- [Native mesh pipelines compiled at their first draw](../../../docs/reference/shaders.md#native-mesh-pipelines-compiled-at-their-first-draw): resolved. The foliage, shadows and enemies drawn with task and mesh shaders stalled at their first draw on a cold Metal cache (59.5 s of builds at the Kokiri Forest entry on an M5 Max, one frame of 42.9 s), as nothing recorded or kept their pipelines; `pso_manifest.tsv` now carries 164 `M` rows (Kokiri Forest, Hyrule Field, Castle Town, Hyrule Castle, and 41 from later play, Death Mountain Trail among it), and with the prepare step they are built before the first frame. Pipelines outside the list still stall once, then go into `pso_user.tsv`. With the first 123 alone, a cold first start (empty Metal cache and pipeline archive, M4 Pro) on a Death Mountain Trail save built 9 and 10 at their first draw in two runs, 2.7 and 4.2 s, frames of 1,775 and 1,657 ms; with all 164, none, worst frame 25.6 and 18.5 ms, the prepare step 29.6 and 29.3 s → 32.1 and 31.0 s.
- [Early fragment tests from the control section](../../../docs/reference/shaders.md#early-fragment-tests-from-the-control-section): 746 of its 22,352 pixel shaders set the NVN2 flag (control +0x5b), none of them writes depth; before, no NVN2 shader got the attribute.
Expand Down
2 changes: 2 additions & 0 deletions dm/gfx/nvn/hle_nvn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,7 @@ static int dcmp(const void *a, const void *b) { double x = *(const double *)a, y
// Power over the window since the last summary, for the whole process: CPU energy (task_energy in nJ, Apple silicon), CPU time (100% = one core) and the share of it on performance cores,
// wakeups per second (interrupt / out of platform idle), GPU time per second (task_gpu_utilisation), thermal state, and the guest threads that yielded most (hle_thread.c);
// then render-target traffic per frame (attachment load / store bytes, passes that load and store everything, stores saved by DM_NVN_UNWRITTEN_DC) and guest-thread CPU by Switch priority
__attribute__((weak)) void dm_gpu_share_line(uint64_t frame, double frames) { (void)frame; (void)frames; } // the Mac host's is in memstat.m
static void power_line(uint64_t frame) {
static uint64_t pt, pe, pcpu, pp, piw, ppw, pg, pf, pld, pst, pfu, pudc; static mach_timebase_info_data_t tb; if (!tb.denom) mach_timebase_info(&tb);
task_power_info_v2_data_t pw; mach_msg_type_number_t n = TASK_POWER_INFO_V2_COUNT;
Expand All @@ -1986,6 +1987,7 @@ static void power_line(uint64_t frame) {
if (dg + dc + du + dn != pdg + pdc + pdu + pdn) LOG("[nvn] compute dispatches up to frame %llu: %llu after a barrier of the game's, %llu after a copy's range, %llu in the full order (a binding with no range), %llu with no barrier (DM_NVN_DISPATCH_BARRIER)", frame,
(unsigned long long)(dg - pdg), (unsigned long long)(dc - pdc), (unsigned long long)(du - pdu), (unsigned long long)(dn - pdn));
pdg = dg; pdc = dc; pdu = du; pdn = dn;
dm_gpu_share_line(frame, nf);
char rs[400]; mtl_res_stats(rs, sizeof rs); static uint64_t pbs, pbf; uint64_t bs, bf; mtl_barrier_stats(&bs, &bf);
uint64_t mtl_cut_count(void), mtl_copy_cut_count(void), mtl_blit_splits(void); void mtl_ubd_stats(uint64_t *, uint64_t *); static uint64_t pcut, pccut, pbsp, pud, puc; uint64_t cut = mtl_cut_count(), ccut = mtl_copy_cut_count(), bsp = mtl_blit_splits(), ud, uc; mtl_ubd_stats(&ud, &uc);
void mtl_ubp_stats(uint64_t *, uint64_t *, uint64_t *); static uint64_t ppm, ppr, ppf; uint64_t pm, pr, pf_; mtl_ubp_stats(&pm, &pr, &pf_);
Expand Down
10 changes: 9 additions & 1 deletion dm/host/front_mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,15 @@ void front_run(void (*guest)(void)) {
// stay unset: mode=default forces this layer's HUD on, so the Metal HUD menu's Hide HUD left it on screen
if (getenv("DM_METAL_HUD") && atoi(getenv("DM_METAL_HUD"))) LOG("front end: Metal performance HUD on (DM_METAL_HUD)");
v.layer = g_layer; [(DmGameView *)v fitDrawable];
[win center];
NSScreen *home = nil; const char *ws = getenv("DM_WINDOW_SCREEN");
if (ws && *ws) {
NSArray<NSScreen *> *all = NSScreen.screens;
if (!strcmp(ws, "builtin")) { for (NSScreen *sc in all) if (CGDisplayIsBuiltin([sc.deviceDescription[@"NSScreenNumber"] unsignedIntValue])) { home = sc; break; } }
else if (atoi(ws) >= 0 && (NSUInteger)atoi(ws) < all.count) home = all[atoi(ws)];
if (home) LOG("front end: window on screen %s (DM_WINDOW_SCREEN=%s)", home.localizedName.UTF8String, ws); else LOG("[RED] front end: no screen for DM_WINDOW_SCREEN=%s", ws);
}
if (home) { NSRect vf = home.visibleFrame; [win setFrameOrigin:NSMakePoint(NSMidX(vf) - win.frame.size.width / 2, NSMidY(vf) - win.frame.size.height / 2)]; }
else [win center];
[win makeKeyAndOrderFront:nil];
screen_refresh(win.screen ?: NSScreen.mainScreen);
g_win = win;
Expand Down
49 changes: 49 additions & 0 deletions dm/host/memstat.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,52 @@
#endif
pthread_t th; pthread_create(&th, NULL, thrcpu_thread, spec); pthread_detach(th);
}

#if TARGET_OS_OSX
#include <IOKit/IOKitLib.h>
// GPU time by process over the window since the last line (hle_nvn.c's power summary calls it): the accelerator's user clients each list their creator and, per command queue,
// the GPU time it has run (AppUsage accumulatedGPUTime, ns). A game whose frame leaves the GPU little time to spare misses its frame rate when other apps draw, and nothing in
// the game's own timing says so: its command buffers' GPU spans include the time the GPU ran someone else's work (docs/reference/frame-rate.md "Other apps' GPU work")
enum { GU_N = 96 };
typedef struct { int pid; char name[24]; uint64_t ns; } gpu_user;
static int gpu_users(gpu_user *u) {
io_iterator_t accs = 0; int n = 0;
if (IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceMatching("IOAccelerator"), &accs) != KERN_SUCCESS) return 0;
for (io_service_t acc; (acc = IOIteratorNext(accs)); IOObjectRelease(acc)) {
io_iterator_t kids = 0; if (IORegistryEntryGetChildIterator(acc, kIOServicePlane, &kids) != KERN_SUCCESS) continue;
for (io_registry_entry_t c; (c = IOIteratorNext(kids)); IOObjectRelease(c)) {
NSString *who = CFBridgingRelease(IORegistryEntryCreateCFProperty(c, CFSTR("IOUserClientCreator"), NULL, 0));
NSArray *use = CFBridgingRelease(IORegistryEntryCreateCFProperty(c, CFSTR("AppUsage"), NULL, 0));
int pid = 0; char name[24] = "";
if (![who isKindOfClass:NSString.class] || ![use isKindOfClass:NSArray.class] || sscanf(who.UTF8String, "pid %d, %23[^\n]", &pid, name) < 1) continue;

Check failure on line 173 in dm/host/memstat.m

View workflow job for this annotation

GitHub Actions / clang-tidy (ratchet)

Nullable pointer is passed to a callee that requires a non-null 1st parameter [clang-analyzer-nullability.NullablePassedToNonnull] (1 in this file, the baseline has 0)
uint64_t ns = 0; for (NSDictionary *q in use) if ([q isKindOfClass:NSDictionary.class]) ns += [q[@"accumulatedGPUTime"] unsignedLongLongValue];
int k = 0; while (k < n && u[k].pid != pid) k++;
if (k < n) u[k].ns += ns;
else if (n < GU_N && ns) { u[n].pid = pid; snprintf(u[n].name, sizeof u[n].name, "%s", name); u[n].ns = ns; n++; }
}
IOObjectRelease(kids);
}
IOObjectRelease(accs); return n;
}
void dm_gpu_share_line(uint64_t frame, double frames) {
static dispatch_queue_t q; if (!q) q = dispatch_queue_create("dm.gpu-share", dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0));
dispatch_async(q, ^{ @autoreleasepool { // off the frame's thread: the registry walk takes a few milliseconds
static gpu_user prev[GU_N]; static int pn; static uint64_t pt;
gpu_user u[GU_N]; int n = gpu_users(u), me = getpid(); uint64_t t = now_ns();
if (pt && t > pt && n) {
double s = (t - pt) / 1e9, own = 0, others = 0; struct { double ms; const char *name; } top[4] = {{0}};
for (int i = 0; i < n; i++) {
int k = 0; while (k < pn && prev[k].pid != u[i].pid) k++;
uint64_t was = k < pn ? prev[k].ns : 0; double ms = u[i].ns > was ? (u[i].ns - was) / 1e6 / s : 0; // a closed command queue takes its time out of the sum
if (u[i].pid == me) { own = ms; continue; }
others += ms;
for (int j = 0; j < 4; j++) if (ms > top[j].ms) { memmove(&top[j + 1], &top[j], sizeof top[0] * (size_t)(3 - j)); top[j].ms = ms; top[j].name = u[i].name; break; }
}
char list[160] = ""; size_t o = 0;
for (int j = 0; j < 4 && top[j].ms >= 1 && o < sizeof list; j++) o += (size_t)snprintf(list + o, sizeof list - o, "%s%s %.0f", j ? ", " : ": ", top[j].name, top[j].ms);
LOG("[nvn] GPU by process up to frame %llu: the game %.0f ms/s (%.2f ms per frame), other processes %.0f ms/s%s", (unsigned long long)frame, own, frames > 0 ? own * s / frames : 0, others, list);
}
memcpy(prev, u, sizeof u); pn = n; pt = t;
} });
}
#endif
Loading
Loading