diff --git a/dm/games/0400486024DEC000/README.md b/dm/games/0400486024DEC000/README.md index 1487d7b177..74975d1d2d 100644 --- a/dm/games/0400486024DEC000/README.md +++ b/dm/games/0400486024DEC000/README.md @@ -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. @@ -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. diff --git a/dm/gfx/nvn/hle_nvn.c b/dm/gfx/nvn/hle_nvn.c index a4d838a0d1..79216bde8d 100644 --- a/dm/gfx/nvn/hle_nvn.c +++ b/dm/gfx/nvn/hle_nvn.c @@ -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; @@ -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_); diff --git a/dm/host/front_mac.m b/dm/host/front_mac.m index 278bf27240..98f6d63094 100644 --- a/dm/host/front_mac.m +++ b/dm/host/front_mac.m @@ -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 *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; diff --git a/dm/host/memstat.m b/dm/host/memstat.m index b2e4f28ba9..51ce082b96 100644 --- a/dm/host/memstat.m +++ b/dm/host/memstat.m @@ -153,3 +153,52 @@ static void sample(FILE *f, double t, id dev) { #endif pthread_t th; pthread_create(&th, NULL, thrcpu_thread, spec); pthread_detach(th); } + +#if TARGET_OS_OSX +#include +// 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; + 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 diff --git a/docs/agents/symptoms.md b/docs/agents/symptoms.md index 2df94ddc79..137f1223ae 100644 --- a/docs/agents/symptoms.md +++ b/docs/agents/symptoms.md @@ -543,9 +543,11 @@ One line per symptom in the [subsystem references](../reference/): what you see - asked for 60 Hz, the system fires the display link on every third refresh of a 165 Hz screen, 55 Hz, so games paced by it ran at 55 fps (27.5 at 30). → [Virtual 60 Hz ticks on screens that are not a multiple of 60](../reference/frame-rate.md#virtual-60-hz-ticks-on-screens-that-are-not-a-multiple-of-60) - virtual ticks keep the average, but a frame still stays up two or three refreshes in turn (13.9 / 20.8 ms at 144 Hz), and Apple's HUD showed the frame interval jumping between them. → [Fullscreen switches the screen to a rate the frame rate divides](../reference/frame-rate.md#fullscreen-switches-the-screen-to-a-rate-the-frame-rate-divides) - a Mac game in fullscreen holds 60 fps for 45 s to 3 minutes, then the same work takes about twice the GPU time (Tears of the Kingdom 10.5 → 19.7 ms) and the frame step falls to 30 fps. `powermetrics` shows the GPU at its lowest clock (338 MHz on an M4 Pro) while it is 72–98% busy, with thermal pressure nominal. Probes back to 60 fail, because the clock does not rise within a probe. `gamepolicyd` logs `Game mode enabled` and `Set DPS to 2`. → [macOS Game Mode holds the GPU at its lowest clock](../reference/frame-rate.md#macos-game-mode-holds-the-gpu-at-its-lowest-clock) +- a GPU-bound scene misses its frame rate with a late frame every few frames, while the game issues the same calls, draws and passes in the fast and the slow frames. The real GPU span (`@gpu_end_ms − @gpu_beg_ms`) of a quarter to a third of the frames is 5–15 ms over the others; runs with identical settings differ by several fps; in `DM_NVN_GPUPROF` a slow frame has encoders that normally take tens of microseconds taking 1–3 ms (a 128x128 pass of one draw at 2,972 µs), or one large pass at three times its usual time, in different places from one slow frame to the next. → [Other apps' GPU work inside the game's frame](../reference/frame-rate.md#other-apps-gpu-work-inside-the-games-frame) - a Mac game started with `DM_FULLSCREEN=1` from an app that is itself in fullscreen (the launcher's console mode) came up as a window. → [A game opened from a fullscreen app stays a window](../reference/frame-rate.md#a-game-opened-from-a-fullscreen-app-stays-a-window) - on a ProMotion built-in screen, only in fullscreen, the frame step went 1 → 2 → 3 vsyncs on frames costing 0.1–0.6 vsyncs (`3 late frames; cost 0.32 vsyncs`) and the game presented 15 frames a second; a window, or the screen set to a fixed 60 Hz, did not do it. The `DM_NVN_TSV` rows show presents shown one 120 Hz refresh late (`@pres_at_ms` − `@link_target_ms` = 8.3 ms) with a skipped tick after each (`@link_gap_ms` 33 ms), and `@link_lead_ms` about 16 ms against about 50 ms in a window. → [Frame latency 2 for the display link in fullscreen](../reference/frame-rate.md#frame-latency-2-for-the-display-link-in-fullscreen) - in fullscreen on a MacBook Pro's ProMotion screen, a 60 fps game held 40 fps with its GPU at 10 ms a frame: frame times alternated 16.7 and 33.3 ms, and each `on-screen` line counted half its frames as held too long (`dropped 150` of 300, `discarded 0`). The same route in a window held 60.0 fps, and the title screen showed the same 40 fps in fullscreen. → [The 60 Hz link at 40 fps in fullscreen on a ProMotion screen](../reference/frame-rate.md#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen) +- in fullscreen on a variable-refresh screen that keeps its mode (`DM_SCREEN_MATCH=0`, or no fixed-rate mode), a game whose GPU work takes about a vsync runs 4–5 fps below what the same build does with no window, with the same GPU time. Frame times sit at 16.7 ms with 25 ms and 33 ms ones between (`@presented_ms` in 8.3 ms steps), the `on-screen` line counts 6–12 of 300 frames held too long, and the frame's fence wait (`@sync_ms`) is 3–5 ms where the GPU-bound run with no window has 10. → [A GPU-bound game on the 120 Hz link pays a refresh for every late frame](../reference/frame-rate.md#a-gpu-bound-game-on-the-120-hz-link-pays-a-refresh-for-every-late-frame) - on a MacBook Air M2's fixed 60 Hz built-in display, the reporter measured about 50 ms from the game's present call to on-screen presentation with the display link, at both requested frame latencies 1 and 2, versus 29 ms with `DM_PRESENT_LINK=0`. After loading, all three runs held 60 fps with 0.3% of on-screen intervals outside 16.7 ± 2 ms and no frame-step changes. → [Fixed-rate display-link delay remains at latency 1](../reference/frame-rate.md#fixed-rate-display-link-delay-remains-at-latency-1) - at a 30 fps target, in fullscreen on a fixed 60 Hz screen, frames stay on screen 66.7 ms, often many in a row; in a window a late frame stays 50 ms. The `display link up to tick` lines count 300 ticks per 300 presents, but over 12-18 s instead of 10. → [The 30 Hz display link in fullscreen on a fixed-rate screen](../reference/frame-rate.md#the-30-hz-display-link-in-fullscreen-on-a-fixed-rate-screen) - autorelease work takes a measurable share of replay time, with temporary arena-buffer ownership traffic a few times per draw. → [Arena buffer ownership on allocation](../reference/frame-rate.md#arena-buffer-ownership-on-allocation) diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv index e23e305512..d106a04b4d 100644 --- a/docs/env_switches.tsv +++ b/docs/env_switches.tsv @@ -410,6 +410,7 @@ DM_WATCH_SAMPLE diagnostic `=` (Mac): when the stall watchdog fires, sampl DM_WATCH_STALL diagnostic `=`: when the frame loop makes no progress for that long (default 15 with `DM_WATCH`), logs a red line, dumps the threads and exits DM_WEB_LOG diagnostic `1` logs each key an offline HTML page is given and where the focus is after it DM_WINDOW switch When set (to any value, `0` included) opens a Mac window with keyboard and controller input; unset runs headless with the guest on the current thread; the Mac launcher sets it +DM_WINDOW_SCREEN diagnostic `builtin` or `=` (Mac, with `DM_WINDOW`): opens the game window on the Mac's built-in display, or on that entry of `NSScreen.screens`, instead of the primary screen; fullscreen then takes that screen DM_WINDOW_TOP diagnostic `1` (Mac, with `DM_WINDOW`) orders the game window in front without activating it and keeps it above other apps' windows, so a covered window does not slow the run; `regress.py` sets it DM_XCODE_DERIVED_DATA path Xcode derived data folder for `build_ipa.sh` (default `$W/build/ios/xcode-dd`); the NSP script points it into the game's build folder DM_XCODE_PROJECT_DIR path Folder of the per-game Xcode project that `build_ipa.sh --prepare-xcode` makes (default `$W/xcode`); the NSP script sets it diff --git a/docs/reference/frame-rate.md b/docs/reference/frame-rate.md index 69f0b16947..2d7f6335ad 100644 --- a/docs/reference/frame-rate.md +++ b/docs/reference/frame-rate.md @@ -393,6 +393,16 @@ Frame pacing: the host's frame step, engine frame limiters, present intervals an - **Check:** `test_nsp_mac_app.py` checks the key. To see a game's state: `/usr/bin/log show --last 10m --predicate 'process == "gamepolicyd"' --style compact | grep -E "Found game|Game mode|DPS"`. - **Not checked:** a game packed with the key false (the reporter's runs turned Game Mode off with the Game Overlay switch and with the category); other Apple chips; iOS, whose project still declares the key true (the same collapse is only suspected there, PR #314). +### Other apps' GPU work inside the game's frame + +- **Symptom:** a GPU-bound scene misses its frame rate with a late frame every few frames, while the game issues the same calls, draws and passes in the fast and the slow frames. The real GPU span (`@gpu_end_ms − @gpu_beg_ms`) of a quarter to a third of the frames is 5–15 ms over the others; runs with identical settings differ by several fps; in `DM_NVN_GPUPROF` a slow frame has encoders that normally take tens of microseconds taking 1–3 ms (a 128x128 pass of one draw at 2,972 µs), or one large pass at three times its usual time, in different places from one slow frame to the next. +- **Cause:** not the host. The GPU runs one context at a time, and another app's work is scheduled into the game's frame: a command buffer's GPU start and end, and every timestamp between them, span whatever ran in between, so the game's own figures show a longer frame and not who took the time. Ocarina of Time on an M4 Pro (20-core GPU, macOS 27.2, 2026-11-10), headless from a save in a heavy area (about 2,720 draws): the game's own GPU time was 14.5–14.8 ms a frame in every 300-frame window and every second sampled (mean 14.75, standard deviation 0.42 over 37 s), which leaves 1.9 ms of a 16.67 ms frame. Meanwhile the terminal the run was started from (Warp, redrawing a coding agent's progress line about 30 times a second at about 4 ms of GPU a redraw) took 115–250 ms of GPU a second and WindowServer 55–150, together 3.9 ms per game frame. The GPU was 92–93 % busy, the frame rate 47.7–50.4 fps over five runs (span p50 17.4–18.1 ms, p90 26–29 ms), and per second the frame rate fell as the others' time rose (correlation −0.63). +- **Fix:** none in the host for the cause; a diagnostic for it. On the Mac the periodic summary has a line `GPU by process up to frame N: the game … ms/s (… ms per frame), other processes … ms/s: , …` (`dm_gpu_share_line` in `dm/host/memstat.m`, from the accelerator's user clients in the I/O registry: `AppUsage` `accumulatedGPUTime` by creating process, read off the frame's thread). The game's `ms per frame` is its real cost; the others' `ms/s` divided by the frame rate is what they take of each frame. Quit or hide the app it names. macOS's Game Mode gives a game priority on the GPU, but is off for [the clock it holds](#macos-game-mode-holds-the-gpu-at-its-lowest-clock). +- **Ruled out for these slow frames (measured):** frames overlapping on the GPU (a frame started before the one before ended by more than 0.2 ms in 21–48 of 1,200 frames); pipeline builds and texture uploads (none in the window); the game's work (the same encoders, in a fast frame 13.7 ms summed). +- **Not the whole gap:** in the player's windowed session with the terminal's window hidden it still drew 60–72 ms/s, the others' total fell from 132–156 to 93–105 ms/s, and the game held 54–56 fps instead of 48–53: the rest was GPU idle at each frame's start (2.03–2.19 ms a frame with no command buffer of the game on the GPU). +- **Not checked:** the GPU clock (`powermetrics` needs root); the same scene with no other app drawing at all. +- **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#frame-rate). + ### A game opened from a fullscreen app stays a window - **Symptom:** a Mac game started with `DM_FULLSCREEN=1` from an app that is itself in fullscreen (the launcher's console mode) came up as a window. @@ -424,6 +434,14 @@ Frame pacing: the host's frame step, engine frame limiters, present intervals an - **Measured for the fixed mode:** with the screen held at its fixed 60 Hz mode (`CGConfigureDisplayWithDisplayMode` for one app, before this change), the same route in fullscreen held 60.0 fps, frame p99 16.9 ms, 2 frames over 1.5 vsyncs in two runs, on the 60 Hz link at latency 1 ("fullscreen, fixed refresh"), as in a window; against the 120 Hz link's 59.2 fps, p99 25.3 ms and 62. The GPU took 14.0 ms there against 10.0, at the lower clock the system chose. Issue #347's reporters also saw no misses with the screen set to a fixed 60 Hz. The cost: the switch changes the screen's mode while the game is fullscreen, for this app only, as on 144 Hz screens. - **Not checked:** the host's own switch on a ProMotion screen (the measurement above set the mode by hand), and its log lines; external variable-refresh screens, whose fixed modes may not be listed apart from the variable one (then the 120 Hz link paces them); other ProMotion Macs and macOS versions; input latency; iOS, where nothing changes (`front_fullscreen` is 0 there). +### A GPU-bound game on the 120 Hz link pays a refresh for every late frame + +- **Symptom:** in fullscreen on a variable-refresh screen that keeps its mode (`DM_SCREEN_MATCH=0`, or no fixed-rate mode), a game whose GPU work takes about a vsync runs 4–5 fps below what the same build does with no window, with the same GPU time. Frame times sit at 16.7 ms with 25 ms and 33 ms ones between (`@presented_ms` in 8.3 ms steps), the `on-screen` line counts 6–12 of 300 frames held too long, and the frame's fence wait (`@sync_ms`) is 3–5 ms where the GPU-bound run with no window has 10. +- **Cause, as far as measured:** on the 120 Hz link ([the fallback of the 40 fps entry](#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen)) the acquire waits two ticks per vsync, so a game that is ahead waits for its tick and one that finishes a millisecond after it goes up a whole 8.3 ms refresh later, with the GPU idle meanwhile. With a GPU span of p50 16.1 ms and p90 19.5 ms, about a fifth of the frames pay that refresh. The same runs sometimes fall into a second state where the game never waits for a tick and the frames follow the GPU (frame p50 16.4 ms, p95 20.2 ms, 59.0 fps, 0–4 of 300 held too long): two of nine runs on the link. What puts a run into one state or the other is **open**; a stack sample of the slow state had the game's presentation thread in `svcSleepThread` for 10 % of the time and its main thread 8 % of the time on the host's submission lock (`g_sub_mu` in `nvn_queue_submit`), neither followed further. +- **Fix:** none in the defaults yet. `DM_PRESENT_LINK=0` (the host acquires the drawable itself; the screen's variable refresh shows each frame when it is ready) held the fast state in both runs tried: 59.5 and 59.7 fps, frame p95 19.9–20.0 ms, 0–1 of 300 held too long, against 54.5–55.9 fps on the link in the six runs around them; at the title, with the GPU at 8.4 ms, both paced alike (60.00 fps, 1,186–1,198 of 1,200 frames up for 16.7 ms). Whether the fallback should present without the link is **open**: on an M5 Pro the title did a little better on the 120 Hz link (59.7 fps, p99 19.2 ms, against 59.3 and 25.2). +- **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#frame-rate) on an M4 Pro MacBook Pro (macOS 27.2), fullscreen on its built-in screen, a GPU-bound Hyrule Field scene. +- **Not checked:** other games; the external 144 Hz screen (virtual ticks); input latency; iOS. + ### Fixed-rate display-link delay remains at latency 1 - **Symptom:** on a MacBook Air M2's fixed 60 Hz built-in display, the reporter measured about 50 ms from the game's present call to on-screen presentation with the display link, at both requested frame latencies 1 and 2, versus 29 ms with `DM_PRESENT_LINK=0`. After loading, all three runs held 60 fps with 0.3% of on-screen intervals outside 16.7 ± 2 ms and no frame-step changes.