Skip to content
Closed
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
2 changes: 2 additions & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk
- **Fullscreen play on the same Mac.** With `0def324d` plus #2308 and #2573, the MetalFX upscaler, a 30 fps cap and docked 1920×1080 3D rendering with dynamic resolution off, Kokiri Forest and Hyrule Field ran near 30 fps with dips to 18–23. The Deku Tree held 30 fps. Hyrule Castle Town ran at 13–15 fps with GPU p50 of 35–46 ms and frame times of 60–90 ms. Some Kokiri runs showed GPU spans about twice the summed GPU time. [GPU idle gaps](../../../docs/reference/frame-rate.md#the-gpu-idles-with-the-next-command-buffer-already-committed) · [Memory](#memory)
- **Separate base M4 Mac mini run.** A 117-minute session used docked mode, the 0.8 render-scale tier (`DM_GFX_SCALE=1`), guest files, both MetalFX upscalers, dynamic resolution off and a 60 fps target with frame hold. Of 898 timing windows, 402 had a median near 60 fps and 493 near 30 fps. All 17 frames lasting 1–2.6 s coincided with first-use pipeline builds. [Follow-up report](https://github.com/seedds/nxnative/pull/2783#issuecomment-6929249107)
- Current: the title and menu, a movie behind them, are a locked 60 fps (p50 16.67 ms, GPU span 15.6 ms).
- Current on an M6 Mac mini (2 performance and 4 efficiency cores, 32 GB, macOS 27.0.1, 2026-11-18), `field-run` from a player's save in Kokiri Forest, a Mac app of this checkout (chain `32d41df88b32`): 59.9 fps, frame p50 16.68 / p99 17.43 ms, GPU p50 11.3 ms, 2 frames over budget in 45 s, no red line. Resolved there: each time the display link went silent or came back (the window covered, then visible) the hold stepped 1 → 2 → 3 at a GPU time under one vsync, 20 fps for up to a second ([A display-link silence read as the game's late frames](../../../docs/reference/frame-rate.md#a-display-link-silence-read-as-the-games-late-frames)); with a 3 s silence forced in the route, 56.4 → 59.4 fps and frame p99 51.2 → 17.8 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.
- Resolved for frames of two vsyncs ([issue 1501](https://github.com/seedds/nxnative/issues/1501)): parts of the opening played with no sound, the mix silent for about a minute. The movie's picture was behind its sound, which ended first: [the game's movie player takes one picture a frame](../../../docs/reference/movies.md#a-player-limited-to-one-picture-a-frame-falls-behind-its-sound), so each frame of two vsyncs left the picture one further behind, for the rest of the movie. Measured on an M4 (10-core GPU, 24 GB, VideoToolbox), headless, from an empty save into the opening's first movie (`Dm_Kokiri_0000`, 9,254 pictures, 154.2 s), by a host that logs the pictures' stream time and the renderer's silent frames each second:
- at the 60 fps target on `78671525`, one run while the Mac was busy (GPU p50 14.5 to 26 ms, the hold going between 1 and 2): 154.00 s of the movie took 216.85 s, and the mix was silent for the last 59 s of it (62.85 s behind at the end). A run with the Mac idle held 60 fps and lost nothing (153.98 s);
Expand Down Expand Up @@ -321,6 +322,7 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25

- [Autoreleased temporaries collect during background pipeline builds](../../../docs/reference/memory.md#autoreleased-temporaries-collect-during-background-pipeline-builds). The audit finding is resolved in the host.
- [The display link started before fullscreen's mode switch](../../../docs/reference/frame-rate.md#the-display-link-started-before-fullscreens-mode-switch): startup silences and rescues on a variable-refresh screen, and repeated fullscreen mode switches / stale variable-refresh flags ([Fullscreen switches the screen to a rate the frame rate divides](../../../docs/reference/frame-rate.md#fullscreen-switches-the-screen-to-a-rate-the-frame-rate-divides)).
- [A display-link silence read as the game's late frames](../../../docs/reference/frame-rate.md#a-display-link-silence-read-as-the-games-late-frames): the hold stepped to 20 fps when the window was covered and shown again.
- [Upload retirement can block Metal 4 feedback](../../../docs/reference/memory.md#upload-retirement-can-block-metal-4-feedback). NX18 reported a freeze on an iPhone 18 Pro Max after loading a save. A synthetic lock stall reproduced the feedback blockage. The cause of the device freeze remains open.
- [Going to the background while graphics do not drain](../../../docs/reference/nvn-objects.md#going-to-the-background-while-graphics-do-not-drain): NX18's iPhone 18 Pro Max run froze before the background transition. The host now bounds the transition's graphics wait and starts persistence independently. The cause of the initial freeze and the revised iOS behavior are open.

Expand Down
12 changes: 12 additions & 0 deletions dm/gfx/nvn/hle_nvn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2780,6 +2780,18 @@ static void fstep_tick(const win_t *o, int c) {
slow_bits = (uint16_t)(slow_bits << 1 | (shown > k + FSTEP_LATE));
if (__builtin_popcount(slow_bits) >= 12) g_fs.screen = 2;
}
// While the display link is silent and for FSTEP_LINK_QUIET frames after any of its events (a stall's start or end, a rescue's start or end, a pacing mode change:
// mtl_link_events), the frames' start-to-start time holds waits for the screen, not the game's work, and so does their CPU cost: the acquire's wait for a present the
// silent link never takes is not in the pacing wait. A frame whose GPU time fits its hold is on time there; one whose GPU time does not is still judged as before.
// Ocarina of Time on an M6 (2 performance cores), as the link went silent or came back (the window covered; DM_TEST_LINK_STALL=95,3 on the field-run route): three frames of
// GPU 0.66-0.99 vsyncs (CPU cost 0.96-6.31 with the wait) and the hold stepped 1 → 2 → 3 (20 fps) within 8 frames, for 1-2 s
{
enum { FSTEP_LINK_QUIET = 30 };
static uint64_t ev_seen; static int quiet; uint64_t ev = mtl_link_events();
if (ev != ev_seen) { ev_seen = ev; quiet = FSTEP_LINK_QUIET; }
int disturbed = quiet > 0 || mtl_link_stalled(); if (quiet > 0) quiet--;
if (disturbed && !g_fs.screen && gpu <= (g_fs.k ? g_fs.k : kmin) + FSTEP_LATE) g_fs.screen = 1;
}
// A probe's grace lasts while its frames keep getting cheaper (nvn_fstep.h FSTEP_RAMP): macOS raises the GPU clock for the shorter deadline over seconds, not the iPhone's 30 frames
// (Breath of the Wild on an M5 Pro: the probe's 33 frames took the clock 338 → 432 MHz and its GPU time 24.8 → 18.5 ms, then it failed at 22 ms frames; hold 1 needed about 560 MHz)
g_fs.ramp = mtl_probe_ramp_on();
Expand Down
14 changes: 10 additions & 4 deletions dm/gfx/nvn/nvn_mtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -19942,6 +19942,10 @@ @interface NvMetalDisplayLinkDelegate : NSObject <CAMetalDisplayLinkDelegate>
#define STALL_NS 100000000ull
#define STALL_RED_NS 2000000000ull
static uint64_t g_stall_t0, g_stall_drop, g_stall_n; static int g_stall_red, g_stall_logged;
// Display-link events the frame step must not read as the game's lateness (hle_nvn.c fstep_tick): a stall's start and end, a rescue's start and end, a pacing mode change.
// Around each the frames' start-to-start time holds waits for the screen, not the game's work
static uint64_t g_link_events;
static inline void link_event(void) { __atomic_add_fetch(&g_link_events, 1, __ATOMIC_RELAXED); }
// When the display link stays silent for LINK_RESCUE_NS while the app is active, presents stop waiting for it: mode 0 (the present thread takes drawables itself), so the
// picture keeps moving instead of standing still on dropped frames (d2r-mobile afad65c, via MacNativeGames cf1e629: an iPhone's link stopped while active and the picture
// froze for 80 s; macOS also pauses the link of a window it takes for covered). The link is tried again after g_rescue_back_ns (link_sync), which doubles on each new
Expand Down Expand Up @@ -19997,7 +20001,7 @@ - (void)metalDisplayLink:(CAMetalDisplayLink *)link needsUpdate:(CAMetalDisplayL
// A callback that cannot take a present must not reset the watchdog or count a pacing tick. The next enqueue that hands off the layer may be waiting for a texture.
if (!g_dm_present_link || g_rescue_mode) { pthread_mutex_unlock(&g_pq_mu); return; }
g_link_probe_at = 0; // the tried link called back: off probation
if (g_stall_t0) { uint64_t since = dm_focus_in_since(), t = now_ns();
if (g_stall_t0) { uint64_t since = dm_focus_in_since(), t = now_ns(); link_event();
MLOG("display link recovered: stalled %.0f ms (%.0f ms of it active), fallback dropped %llu frames (stall #%llu)", (t - g_stall_t0) / 1e6, (t - (g_stall_t0 > since ? g_stall_t0 : since)) / 1e6, (unsigned long long)g_stall_drop, (unsigned long long)g_stall_n); g_stall_t0 = 0; }
pthread_mutex_unlock(&g_pq_mu);
double vp = g_link_vperiod, tick_time = update.targetPresentationTimestamp;
Expand Down Expand Up @@ -20189,7 +20193,7 @@ static void link_sync(void) { // Called every frame by the game's present thre
int want = g_dm_present_link;
if (want < 0 || want > 2) { g_dm_present_link = applied == 3 ? 1 : applied; pthread_mutex_unlock(&g_pq_mu); return; }
if (g_rescue_mode && (want != g_rescue_mode || now_ns() >= g_rescue_back_at)) {
g_rescue_mode = 0; g_stall_t0 = 0; __atomic_store_n(&g_link_tick_ns, now_ns(), __ATOMIC_RELAXED);
g_rescue_mode = 0; g_stall_t0 = 0; __atomic_store_n(&g_link_tick_ns, now_ns(), __ATOMIC_RELAXED); link_event();
g_link_probe_pending = want != 0; g_link_probe_at = 0; // probation starts once the link is live on its run loop
MLOG("display link: rescue ended, trying pacing mode %d (frame %llu)", want, (unsigned long long)atomic_load(&g_cur_frame));
}
Expand Down Expand Up @@ -20235,6 +20239,7 @@ static void link_sync(void) { // Called every frame by the game's present thre
else { CFRunLoopRef rl = g_link_rl; g_link = nil; CFRunLoopPerformBlock(rl, kCFRunLoopDefaultMode, ^{ [link invalidate]; pthread_mutex_lock(&g_pq_mu); g_link_owns_layer = 0; pthread_cond_broadcast(&g_pq_cv); pthread_mutex_unlock(&g_pq_mu); CFRunLoopStop(rl); }); CFRunLoopWakeUp(rl); }
if (want == applied) MLOG("display link: returning the layer to the present thread during startup (frame %llu)", (unsigned long long)atomic_load(&g_cur_frame));
else MLOG("present pacing mode %d → %d (frame %llu)", applied, want, (unsigned long long)atomic_load(&g_cur_frame));
link_event();
applied = want;
pthread_mutex_lock(&g_pq_mu); pthread_cond_broadcast(&g_pq_cv); pthread_mutex_unlock(&g_pq_mu);
}
Expand Down Expand Up @@ -20594,7 +20599,7 @@ void mtl_present_wait(uint64_t tk) {
while (g_pq_inflight) pthread_cond_wait(&g_pq_cv, &g_pq_mu);
if (g_pq_done < tk) g_pq_done = tk;
pthread_cond_broadcast(&g_pq_cv);
if (!g_stall_t0) { g_stall_t0 = last ? last : now; g_stall_drop = 0; g_stall_red = 0; g_stall_logged = 0; g_stall_n++; }
if (!g_stall_t0) { g_stall_t0 = last ? last : now; g_stall_drop = 0; g_stall_red = 0; g_stall_logged = 0; g_stall_n++; link_event(); }
g_stall_drop += n;
active = dm_focus_now() == 1; since = dm_focus_in_since();
uint64_t from = g_stall_t0 > since ? g_stall_t0 : since;
Expand All @@ -20605,7 +20610,7 @@ void mtl_present_wait(uint64_t tk) {
if (active && !g_stall_logged && elapsed >= STALL_NS) { g_stall_logged = 1;
MLOG("display link silent for %.0f ms (active): dropping %llu queued frames not yet displayed, the game continues (stall #%llu; back to normal when the link returns)", elapsed / 1e6, (unsigned long long)n, (unsigned long long)g_stall_n); }
if (active && !g_rescue_mode && g_dm_present_link && (probe_failed || elapsed >= LINK_RESCUE_NS)) {
g_rescue_mode = g_dm_present_link; g_rescue_n++; g_rescue_back_at = now + g_rescue_back_ns;
g_rescue_mode = g_dm_present_link; g_rescue_n++; g_rescue_back_at = now + g_rescue_back_ns; link_event();
if (probe_failed) { g_link_probe_fail++; MLOG("display link tried again and silent for %.0f ms: the present thread takes drawables again (rescue #%llu, %llu tries failed), the link is tried again in %.0f s", pelapsed / 1e6, (unsigned long long)g_rescue_n, (unsigned long long)g_link_probe_fail, g_rescue_back_ns / 1e9); }
else MLOG("display link silent for %.0f ms while active: the present thread takes drawables itself (rescue #%llu), the link is tried again in %.0f s", elapsed / 1e6, (unsigned long long)g_rescue_n, g_rescue_back_ns / 1e9);
g_link_probe_pending = 0; g_link_probe_at = 0;
Expand All @@ -20629,6 +20634,7 @@ void mtl_vbuf_stats(uint64_t *resolve, uint64_t *reuse, uint64_t *set, uint64_t
int mtl_has_window(void) { return front_metal_layer() != NULL; }
int mtl_link_active(void) { return link_on(); }
int mtl_link_stalled(void) { return __atomic_load_n(&g_stall_t0, __ATOMIC_RELAXED) != 0; } // the display link has gone silent and mtl_present_wait drops frames (see STALL_NS) until it calls back
uint64_t mtl_link_events(void) { return __atomic_load_n(&g_link_events, __ATOMIC_RELAXED); }
void mtl_link_pause(int on) { CAMetalDisplayLink *l = g_link; if (l) l.paused = on != 0; } // For testing (DM_TEST_BG): imitates the system stopping the display-link callback in the background
int mtl_link_wait_tick(int vsyncs, uint64_t timeout_ns) {
if (!mtl_link_active()) return 0;
Expand Down
1 change: 1 addition & 0 deletions dm/gfx/nvn/nvn_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ void mtl_link_mode_set(int mode); // the display link's pacing mode (DM_PRESEN
double mtl_presented_time(uint64_t n);
int mtl_link_tick(uint64_t n, double *target, double *lead_ms, int *ticks, double *gap_ms); // the display-link tick that took the n-th present (0 = none: no display link, or not taken yet)
int mtl_link_stalled(void); // the display link is silent (background, occluded window, a stall) and queued frames are dropped instead of shown
uint64_t mtl_link_events(void); // display-link stalls, recoveries, rescues and pacing mode changes so far: the frames around one waited for the screen
int mtl_snap_on(void); uint64_t mtl_snap_acquire_wait(void); // present snapshots (DM_PRESENT_SNAP): on, and acquire's wait for ring capacity (returns ns spent pacing)
// Actual presentation time (seconds) of the n-th present (counted from 1); 0 = not ready, −1 = dropped
// Texture release (at Finalize)
Expand Down
1 change: 1 addition & 0 deletions docs/agents/symptoms.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
- on a Mac whose frames take longer than a vsync, the game runs in slow motion rather than at a lower frame rate: movement, animation and the game's clocks fall behind real time, while the frame counter shows 30-45 fps. → [A fixed frame step plays in slow motion on a slow Mac](../reference/frame-rate.md#a-fixed-frame-step-plays-in-slow-motion-on-a-slow-mac)
- a game that holds about 60 fps with `DM_FPS_HOLD=off` runs at about 40 with the hold on, stuttering: the `frame step: game time …` lines count many frames held 2 and 3 vsyncs, `up / down` climbs to 30 or more a session, and the long frames come out at 33 and 50 ms with little GPU time in them. → [Three late frames among frames on time raised the hold](../reference/frame-rate.md#three-late-frames-among-frames-on-time-raised-the-hold)
- a game that holds 60 fps with the frame step drops to 30 for about a second (30 presents, sometimes 60) a few times in a few minutes of play, each time just after one long frame (`[longframe]` at 43 to 68 ms). The `frame step: hold 1 → 2` line says `3 late frames`, and its cost is what hold 1 holds at. → [A lone stall among near-misses raised the hold](../reference/frame-rate.md#a-lone-stall-among-near-misses-raised-the-hold)
- a game at 60 fps drops to 30 and then 20 within a few frames when the display link goes silent or comes back (the window covered, then visible; `display link silent`, `rescue ended`, `present pacing mode` lines), and returns about half a second to a second later. The `frame step: hold 1 → 2` and `2 → 3` lines say `3 late frames` with a GPU time well under one vsync (0.6 to 1.0) and a cost far above it (1.3 to 6.3). → [A display-link silence read as the game's late frames](../reference/frame-rate.md#a-display-link-silence-read-as-the-games-late-frames)
- a game plays slightly slow (`game time … 0.977 of real time`) in windows where the frame step held frames 3 vsyncs. → [Frames held longer than the game's largest step](../reference/frame-rate.md#frames-held-longer-than-the-games-largest-step)
- `scripts/regress.py` reports a hang (`no frame after … s`, a state dump with every game thread waiting) in some runs of Tears of the Kingdom, baseline and candidate alike; the log's last focus line before it is `oe focus state → 2`, with no `→ 1` after it. → [A regress run stops when another app takes the key window](../reference/frame-rate.md#a-regress-run-stops-when-another-app-takes-the-key-window)
- otherwise stationary gameplay benchmarks show roughly 125–135 ms frame spikes at their verification screenshots; adaptive-cap results vary between runs. → [Benchmark captures perturb the measured frame pacing](../reference/frame-rate.md#benchmark-captures-perturb-the-measured-frame-pacing)
Expand Down
Loading