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
1 change: 1 addition & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,4 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25
- [AV1 movies stop an M1 iPad with SIGILL in dav1d](../../../docs/reference/movies.md#av1-movies-stop-an-m1-ipad-with-sigill-in-dav1d): the title movie on an M1 iPad Pro.
- [`devicectl` copies a large RomFS image through the Mac's memory](../../../docs/reference/packing.md#devicectl-copies-a-large-romfs-image-through-the-macs-memory): the 26.2 GB image's pushes to an iPad filled a 16 GB Mac's swap and failed; now sent over AFC.
- [`devicectl`'s `--remove-existing-content` empties the app's whole container](../../../docs/reference/packing.md#devicectls---remove-existing-content-empties-the-apps-whole-container): the first complete copy of the image, deleted by the DLC step after it.
- [Fixed-rate display-link delay remains at latency 1](../../../docs/reference/frame-rate.md#fixed-rate-display-link-delay-remains-at-latency-1): current, open. In fullscreen on an external fixed 60 Hz 5K screen (M5 Pro) the display link shows 44% of the presents a refresh late and one frame in six takes two vsyncs; the same walk has 83 long frames in a window and 103 in fullscreen with `DM_PRESENT_LINK=0`, against 1,021-1,245 with the link. The host now turns the link off itself in fullscreen when presents keep turning late (`link_late_note`): 59 long frames on that screen with the lid closed. On the same Mac's built-in screen in fullscreen the walk has 8 long frames with the link. Open: with the MacBook's ProMotion screen lit beside the external one the fullscreen walk has 205-257 long frames in every mode, at 30 fps for most of it; 22 with the MacBook's screen set to a fixed 60 Hz, 21 in a window.
35 changes: 35 additions & 0 deletions dm/gfx/nvn/nvn_mtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@
}
id<MTLBuffer> out = [g_dev newBufferWithLength:w * h * 4 options:MTLResourceStorageModeShared];
id<MTLBlitCommandEncoder> b = [cb blitCommandEncoder];
[b copyFromTexture:t sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(0, 0, 0) sourceSize:MTLSizeMake(w, h, 1) toBuffer:out destinationOffset:0

Check failure on line 646 in dm/gfx/nvn/nvn_mtl.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] (19 in this file, the baseline has 15)
destinationBytesPerRow:w * 4 destinationBytesPerImage:w * h * 4 options:depth ? MTLBlitOptionDepthFromDepthStencil : MTLBlitOptionNone];
[b endEncoding]; [cb commit]; [cb waitUntilCompleted];
const uint32_t *px = out.contents; NSUInteger bad = 0; for (NSUInteger i = 0; i < w * h; i++) if (px[i] != px[0]) bad++;
Expand Down Expand Up @@ -1633,11 +1633,11 @@
static inline void enc_b_end(id e) { m4_end(e); }
static inline void enc_b_copy_buffer(id e, id<MTLBuffer> s, NSUInteger so, id<MTLBuffer> d, NSUInteger doff, NSUInteger n) { [e copyFromBuffer:s sourceOffset:so toBuffer:d destinationOffset:doff size:n]; }
static inline void enc_b_copy_buffer_texture(id e, id<MTLBuffer> s, NSUInteger so, NSUInteger row, NSUInteger img, MTLSize z, id<MTLTexture> d, NSUInteger sl, NSUInteger lv, MTLOrigin o) { [e copyFromBuffer:s sourceOffset:so sourceBytesPerRow:row sourceBytesPerImage:img sourceSize:z toTexture:d destinationSlice:sl destinationLevel:lv destinationOrigin:o]; }
static inline void enc_b_copy_texture_buffer(id e, id<MTLTexture> s, NSUInteger sl, NSUInteger lv, MTLOrigin o, MTLSize z, id<MTLBuffer> d, NSUInteger doff, NSUInteger row, NSUInteger img) { [e copyFromTexture:s sourceSlice:sl sourceLevel:lv sourceOrigin:o sourceSize:z toBuffer:d destinationOffset:doff destinationBytesPerRow:row destinationBytesPerImage:img]; }

Check failure on line 1636 in dm/gfx/nvn/nvn_mtl.m

View workflow job for this annotation

GitHub Actions / clang-tidy (ratchet)

Nullable pointer is passed to a callee that requires a non-null 6th parameter [clang-analyzer-nullability.NullablePassedToNonnull] (19 in this file, the baseline has 15)
// The same with a blit option: one plane of a combined depth / stencil texture (MTLBlitOptionDepthFromDepthStencil)
static inline void enc_b_copy_buffer_texture_opt(id e, id<MTLBuffer> s, NSUInteger so, NSUInteger row, NSUInteger img, MTLSize z, id<MTLTexture> d, NSUInteger sl, NSUInteger lv, MTLOrigin o, MTLBlitOption opt) { [e copyFromBuffer:s sourceOffset:so sourceBytesPerRow:row sourceBytesPerImage:img sourceSize:z toTexture:d destinationSlice:sl destinationLevel:lv destinationOrigin:o options:opt]; }
static inline void enc_b_copy_texture_buffer_opt(id e, id<MTLTexture> s, NSUInteger sl, NSUInteger lv, MTLOrigin o, MTLSize z, id<MTLBuffer> d, NSUInteger doff, NSUInteger row, NSUInteger img, MTLBlitOption opt) { [e copyFromTexture:s sourceSlice:sl sourceLevel:lv sourceOrigin:o sourceSize:z toBuffer:d destinationOffset:doff destinationBytesPerRow:row destinationBytesPerImage:img options:opt]; }

Check failure on line 1639 in dm/gfx/nvn/nvn_mtl.m

View workflow job for this annotation

GitHub Actions / clang-tidy (ratchet)

Nullable pointer is passed to a callee that requires a non-null 6th parameter [clang-analyzer-nullability.NullablePassedToNonnull] (19 in this file, the baseline has 15)
static inline void enc_b_copy_texture(id e, id<MTLTexture> s, NSUInteger sl, NSUInteger lv, MTLOrigin so, MTLSize z, id<MTLTexture> d, NSUInteger dl, NSUInteger dv, MTLOrigin doo) { [e copyFromTexture:s sourceSlice:sl sourceLevel:lv sourceOrigin:so sourceSize:z toTexture:d destinationSlice:dl destinationLevel:dv destinationOrigin:doo]; }

Check failure on line 1640 in dm/gfx/nvn/nvn_mtl.m

View workflow job for this annotation

GitHub Actions / clang-tidy (ratchet)

Nullable pointer is passed to a callee that requires a non-null 6th parameter [clang-analyzer-nullability.NullablePassedToNonnull] (19 in this file, the baseline has 15)
static void blit_note(void); // Per-pass dump: a copy / buffer update ended the render pass (defined after PD)
// Ordering inside the copy encoder: Metal 4 does not order copies / fills within one encoder (no automatic hazard tracking); an operation reading or writing a range an earlier one wrote needs an intra-encoder barrier.
// Without it, SMBW's two updates per frame to the same uniform slot ("write 4 bytes −1, then 16 bytes of coefficients") occasionally landed in reverse order; the fountain water wave simulation took −1 as its self coefficient, diverged, and the water vertices were pushed to the top of the screen.
Expand Down Expand Up @@ -2247,7 +2247,7 @@
const char *e = getenv("DM_GPU_CAPTURE_DIR"); NSString *dir;
if (e && *e) dir = @(e); else { char cwd[1024]; if (!getcwd(cwd, sizeof cwd)) strcpy(cwd, "."); dir = [@(cwd) stringByAppendingPathComponent:@"gpu_captures"]; }
NSError *err = nil;
if (![NSFileManager.defaultManager createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:&err]) { MLOG("[RED] DM_GPU_CAPTURE: cannot make the folder %s: %s", dir.UTF8String, err.localizedDescription.UTF8String); return nil; }

Check failure on line 2250 in dm/gfx/nvn/nvn_mtl.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] (19 in this file, the baseline has 15)
return dir;
}
static void gpu_capture_prune(NSString *dir) { // only dm_*.gputrace entries directly in the capture folder; the newest DM_GPU_CAPTURE_KEEP - 1 stay
Expand Down Expand Up @@ -3495,7 +3495,7 @@
}
up_begin();
id<MTLBuffer> stg = [g_dev newBufferWithLength:total ? total : 16 options:MTLResourceStorageModeShared];
res_add(stg); [g_up_keep addObject:stg];

Check failure on line 3498 in dm/gfx/nvn/nvn_mtl.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] (19 in this file, the baseline has 15)
size_t off = 0;
int zb = zblock_on() && t->d.format >= 0x79 && t->d.format <= 0x94; if (zb) { g_zb_ser = t->serial; g_zb_n = (int)MIN(d.mipmapLevelCount, 16u); memset(g_zb, 0, sizeof g_zb); memset(g_zb_tot, 0, sizeof g_zb_tot); }
for (unsigned l = 0; l < d.mipmapLevelCount; l++) {
Expand Down Expand Up @@ -15797,6 +15797,37 @@
link_ent e = g_link_ring[n % PRING]; if (e.n != n) return 0;
*target = e.target; *lead_ms = e.lead_ms; *ticks = e.ticks; *gap_ms = e.gap_ms; return 1;
}
// Fullscreen on a fixed-rate screen runs the display link at frame latency 1 (link_latency). On some screens the system then shows presents a refresh after the link's target, on
// and off: each present that turns late after one on time stays behind a frame shown 33 ms, and the next acquire waits a tick more. Ocarina of Time on an M5 Pro in fullscreen on an
// external fixed 60 Hz 5K screen: 14-29 such turns per 300 presents, one frame in six over 25 ms; in a window, or at latency 2, 0-3 (docs/reference/frame-rate.md, "Fixed-rate
// display-link delay remains at latency 1"). Late presents alone do no harm: a window showed 600 in a row a refresh late at a steady 16.7 ms. So the turns are counted, per
// LINK_LATE_WIN presents at one frame per tick; two windows in a row with LINK_LATE_TURNS or more turn the link off until the window leaves fullscreen (link_sync, link_late_mode):
// the present thread takes the drawables itself, as with DM_PRESENT_LINK=0, which had 103 frames over 25 ms on that walk against 950-1,245. Frame latency 2 did not help there
// (950, set by an earlier version of this policy at frame 606). A workaround: why the system misses the target at a 32 ms lead is open. DM_PRESENT_LINK_AUTO=0 keeps the link;
// a set DM_PRESENT_LINK or DM_PRESENT_LATENCY is left alone.
enum { LINK_LATE_WIN = 300, LINK_LATE_TURNS = 8 };
static _Atomic int g_link_late_off; // fullscreen on this fixed-rate screen presents without the display link (link_late_mode)
int front_fullscreen(void); int front_screen_variable_refresh(void); int front_screen_max_fps(void);
static pthread_mutex_t g_link_late_mu = PTHREAD_MUTEX_INITIALIZER;
static int g_link_late_n, g_link_late_turns, g_link_late_was, g_link_late_bad;
static void link_late_reset(void) { pthread_mutex_lock(&g_link_late_mu); g_link_late_n = g_link_late_turns = g_link_late_was = g_link_late_bad = 0; pthread_mutex_unlock(&g_link_late_mu); }
static int link_late_mode(int want) { return want == 1 && atomic_load(&g_link_late_off) ? 0 : want; }
static void link_late_note(int late, int held) { // a present's presented handler: late = shown over half a refresh after its tick's target; held = its frame's period is over a tick
static int on = -1; if (on < 0) { const char *e = getenv("DM_PRESENT_LINK_AUTO"); on = !(e && !strcmp(e, "0")); }
if (!on || g_present_latency > 0 || g_present_link_env || g_dm_present_link != 1 || atomic_load(&g_link_late_off) || !front_fullscreen() || front_screen_variable_refresh()) return;
pthread_mutex_lock(&g_link_late_mu);
if (held) g_link_late_was = late; // a frame kept for its present interval says nothing about the link
else {
if (late && !g_link_late_was) g_link_late_turns++;
g_link_late_was = late;
if (++g_link_late_n == LINK_LATE_WIN) {
int turns = g_link_late_turns; g_link_late_bad = turns >= LINK_LATE_TURNS ? g_link_late_bad + 1 : 0; g_link_late_n = g_link_late_turns = 0;
if (g_link_late_bad == 2) { atomic_store(&g_link_late_off, 1); g_link_late_bad = 0;
MLOG("display link: %d of the last %d presents turned a refresh late in fullscreen, as in the %d before: off until the window leaves fullscreen, the present thread takes the drawables (DM_PRESENT_LINK_AUTO=0 keeps the link)", turns, LINK_LATE_WIN, LINK_LATE_WIN); }
}
}
pthread_mutex_unlock(&g_link_late_mu);
}
static _Atomic uint64_t g_drawable_ns; // Accumulated wall clock waiting for nextDrawable in present (timing instrumentation)
uint64_t mtl_drawable_ns_take(void) { return atomic_exchange(&g_drawable_ns, 0); }
// Maximum refresh rate (Hz) of the screen when there is a window; returns 0 without a window. Mac uses CoreGraphics display modes (thread-safe C interface; the present configuration is read on the game thread)
Expand Down Expand Up @@ -16314,6 +16345,8 @@
[dr addPresentedHandler:^(id<MTLDrawable> d) { // Actual presentation time (the time this frame is really put on screen, CACurrentMediaTime base)
CFTimeInterval tt = d.presentedTime;
g_pres[pn % PRING] = (pres_ent){pn, tt > 0 ? tt : -1};
link_ent le = g_link_ring[pn % PRING]; int shz = front_screen_max_fps(); // the tick that took this present: was it shown on its target (link_late_note)
if (le.n == pn && tt > 0) link_late_note(tt - le.target > 0.5 / (shz > 0 ? shz : 60), period > 0.025);
}];
// Each frame is displayed for at least one present period: when the GPU completion time jitters around a 120 Hz refresh boundary, the paired "25 ms + 8.33 ms" stutter no longer appears
if (target_ts > 0) [dr present];
Expand Down Expand Up @@ -16492,6 +16525,8 @@
static int vrr_was; int vrr = want == 1 && link_vrr_120(); // variable-refresh fullscreen that kept its mode: the 120 Hz link paces the 60 (link_vrr_120)
if (vrr != vrr_was) { vrr_was = vrr; MLOG("display link: %s (frame %llu)", vrr ? "120 Hz in fullscreen on a variable-refresh screen, a frame every other tick (DM_PRESENT_LINK=1 keeps 60 Hz)" : "60 Hz again (window, fixed-rate screen or another frame rate)", (unsigned long long)atomic_load(&g_cur_frame)); }
if (vrr) want = 2;
if (!front_fullscreen() || front_screen_variable_refresh()) { if (atomic_exchange(&g_link_late_off, 0)) { link_late_reset(); MLOG("display link: on again (the window left fullscreen or the fixed-rate screen; frame %llu)", (unsigned long long)atomic_load(&g_cur_frame)); } }
want = link_late_mode(want); // this screen's presents kept turning late in fullscreen: the present thread takes the drawables (link_late_note)
// The screen's rate changed (switched by front_screen_match, or another screen): the range again, virtual ticks or none. Taken only once the link object exists, so a change
// while its thread starts (after link_main read the rate) is not lost
static int hz_was; int hz = front_screen_max_fps(); CAMetalDisplayLink *lk = g_link;
Expand Down
25 changes: 24 additions & 1 deletion dm/gfx/tests/t_present_rescue.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,33 @@ static void metal_lifecycle(void) {
CHECK("present thread can take a real drawable after rescue", drawable != nil);
[drawable present]; g_link_started = 0;
}
static void late_feed(int presents, int every) { // presents at one frame per tick; every > 0: one in `every` turns a refresh late after one on time
for (int i = 0; i < presents; i++) link_late_note(every > 0 && i % every == 0, 0);
}
static void late(void) { // Fullscreen on a fixed-rate screen drops the display link only once presents keep turning late (link_late_note, link_late_mode).
reset(); g_present_latency = 0; g_present_link_env = 0; test_fullscreen = 1; test_variable_refresh = 0; atomic_store(&g_link_late_off, 0); link_late_reset();
late_feed(3 * LINK_LATE_WIN, 0); CHECK("presents on their targets keep the link", link_late_mode(1) == 1);
for (int i = 0; i < 3 * LINK_LATE_WIN; i++) link_late_note(1, 0);
CHECK("presents all a refresh late, steadily, keep the link", link_late_mode(1) == 1);
link_late_reset(); late_feed(LINK_LATE_WIN, 15); late_feed(LINK_LATE_WIN, 0); late_feed(LINK_LATE_WIN, 15);
CHECK("one window of late turns at a time keeps the link", link_late_mode(1) == 1);
link_late_reset(); for (int i = 0; i < 2 * LINK_LATE_WIN; i++) link_late_note(i % 15 == 0, 1);
CHECK("frames held for a present interval of 2 are not counted", link_late_mode(1) == 1);
g_present_latency = 1; late_feed(2 * LINK_LATE_WIN, 15); CHECK("a set DM_PRESENT_LATENCY is left alone", link_late_mode(1) == 1);
g_present_latency = 0; g_present_link_env = 1; late_feed(2 * LINK_LATE_WIN, 15); CHECK("a set DM_PRESENT_LINK is left alone", link_late_mode(1) == 1);
g_present_link_env = 0; test_fullscreen = 0; late_feed(2 * LINK_LATE_WIN, 15); test_fullscreen = 1;
CHECK("late presents in a window are not counted", link_late_mode(1) == 1);
link_late_reset(); late_feed(2 * LINK_LATE_WIN, 15);
CHECK("two windows of late turns in a row turn the 60 Hz link off", link_late_mode(1) == 0);
CHECK("the 120 Hz and 30 Hz links are left alone", link_late_mode(2) == 2 && link_late_mode(3) == 3 && link_late_mode(0) == 0);
late_feed(3 * LINK_LATE_WIN, 0); CHECK("the link stays off while the window is fullscreen", link_late_mode(1) == 0);
test_fullscreen = 0; g_dm_present_link = 0; link_sync(); g_dm_present_link = 1; // mode 0 here: the test has no link thread to start
CHECK("leaving fullscreen gives the link back", link_late_mode(1) == 1 && !atomic_load(&g_link_late_off));
}
int main(int argc, char **argv) { @autoreleasepool {
alarm(10); setbuf(stdout, NULL);
if (argc > 2 || (argc == 2 && strcmp(argv[1], "--metal"))) return 2;
thresholds(); backoff(); settings(); lifecycle(); latency(); thirty(); vrr120();
thresholds(); backoff(); settings(); lifecycle(); latency(); late(); thirty(); vrr120();
if (argc == 2) metal_lifecycle();
printf("present rescue: %d checks, %d failed\n", checks, failed); return failed != 0;
} }
1 change: 1 addition & 0 deletions docs/env_switches.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ DM_PRESENT_HZ switch `=<N>`: the frequency of presentation pacing (default 60);
DM_PRESENT_INTERVAL switch `display` presents one frame per display-link tick whatever interval the game sets; `game` follows the game's present interval (default: the profile's `present_interval`)
DM_PRESENT_LATENCY switch `=1` or `2`: overrides the display link's preferred frame latency for every screen and window mode; larger positive values use 2 (default 2 in variable-refresh fullscreen, 1 otherwise)
DM_PRESENT_LINK switch Present pacing: `0` acquires the drawable itself, `1` (the default) presents on a 60 Hz display link, `2` uses a 120 Hz display link with a frame every other tick. Unset, a 60 fps game in fullscreen on a variable-refresh screen that keeps its variable mode (no fixed-rate mode, or `DM_SCREEN_MATCH=0`) at a multiple of 120 Hz takes the 120 Hz link of `2`; a value set here holds in every window and screen mode
DM_PRESENT_LINK_AUTO switch `0` keeps the 60 Hz display link in fullscreen on a fixed-rate screen whose presents keep turning a refresh late; by default two windows of 300 presents with 8 or more such turns turn it off until the window leaves fullscreen, and the present thread takes the drawables
DM_PRESENT_SNAP player `=<n>`: present snapshots, a ring of n host textures (2 to 4; `1` = 2) the presents are copied to so the game's swapchain texture is free at once; `0` off (default: the profile's `present_snap`)
DM_PRESENT_UPSCALE player `metalfx` scales a picture smaller than its rectangle on the screen through MetalFX's spatial scaler; `off` (the default) scales it bilinearly
DM_PREV_PROGRAM switch What `oe::GetPreviousProgramIndex` answers (default -1, started from HOME); `oe::ExecuteProgram` sets it for the program it starts; a relaunch removes it
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/frame-rate.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ Frame pacing: the host's frame step, engine frame limiters, present intervals an
- **Cause:** **open**. The reported callback lead was 32.8 ms at both latency settings. Applying the ProMotion latency-2 workaround to fixed-rate fullscreen was an overly broad policy, but requesting latency 1 did not remove this delay in the reporter's measurements. No local fixed-rate timing reproduction or raw trace is available.
- **Fix:** **open**. Fixed-rate screens now request latency 1 by default, as described [above](#frame-latency-2-for-the-display-link-in-fullscreen); this only corrects the workaround's scope. The display link remains enabled, and the remaining presentation delay needs its own diagnosis.
- **Found on:** [issue #822](https://github.com/seedds/nxnative/issues/822), Lollipop Chainsaw RePOP (`0100DD301A686000`, [PR #684](https://github.com/seedds/nxnative/pull/684)'s profile), macOS 27, `--platform mac-app`.
- **Also found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#frame-rate), v131072, main `ced36121`, M5 Pro (16-core GPU, macOS 27.2), fullscreen on an external fixed 60 Hz 5K screen (drawable 5120x2880, `display link: frame latency 1 (fullscreen, fixed refresh)`), a scripted 150 s walk of Kakariko Village from one autosave (2026-11-11, one run each, GPU p50 11-13 ms in all). With the display link, 1,021-1,245 `[longframe]` lines of about 7,500 frames in three runs, 1 of 26 windows of 300 frames with frame p95 under 20 ms, and the frame step raised to 2 and 3 vsyncs on frames costing 0.8-1.3. The `DM_NVN_TSV` rows of one run: 3,190 of 7,201 presents shown a refresh after the link's target (`@pres_at_ms` − `@link_target_ms` = 16.7 ms), callback lead 32 ms, and 817 of the 1,274 frames over 25 ms were such a present or the frame after one; 5 had a GPU sync wait over 8 ms. The same walk in a window (lead 49 ms): 83 `[longframe]` lines, 3 late presents among the long frames. In fullscreen with `DM_PRESENT_LINK=0`: 103 `[longframe]` lines, 24 of 28 windows with frame p95 under 20 ms, but frame interval p99 48 ms in one window against 17.5 in a window. So on this screen the fullscreen link at latency 1 costs about one frame in six. Frame latency 2 is not measured on this screen alone: the one run with it (set at frame 606; 950 `[longframe]` lines, 16-43 late turns per 300 presents, enqueue to the target display p50 60 ms against 33-51 at latency 1) had the MacBook's own screen lit beside the external one, where every mode is slow (below). Late presents alone are harmless: the window run showed 600 presents in a row a refresh late at frame p95 17.3 ms. The turns count: presents late after one on time, 14-29 per 300 presents in fullscreen at latency 1 during play, 0-3 in a window. On the same Mac's built-in ProMotion screen, switched to its fixed 60 Hz mode in fullscreen (drawable 3024x1898, latency 1 or 2), the walk had 8 and 127 `[longframe]` lines and 0-2 turns per 300 presents: the late turns are this external screen's, not every fixed-rate fullscreen's. Not tried: the 120 Hz link on this screen.
- **Fix for the late turns (a workaround; why the system misses the target at a 32 ms lead is open):** `link_late_note` (`nvn_mtl.m`) counts those turns from each present's presented time and its tick's target, per 300 presents at one frame per tick, in fullscreen on a fixed-rate screen with the 60 Hz link. Two windows in a row with 8 or more turn the link off until the window leaves fullscreen (`link_late_mode` in `link_sync`): the present thread takes the drawables itself, as `DM_PRESENT_LINK=0` does and as the rescue of a silent link does; the log says `display link: … presents turned a refresh late in fullscreen … off until the window leaves fullscreen`. Screens that show presents on their targets keep the link. `DM_PRESENT_LINK_AUTO=0` keeps it; a set `DM_PRESENT_LINK` or `DM_PRESENT_LATENCY` is left alone. Known cost, from the `DM_PRESENT_LINK=0` run: frame interval p99 48 ms in one window of 300 frames. `t_present_rescue` (`late`): on-time presents, steadily late ones, a single bad window, held frames, window presents and set switches keep the link; two bad windows turn the 60 Hz link off and leave the 120 and 30 Hz links; leaving fullscreen gives it back (112 checks, 0 failed). Result on the walk above with the external screen as the only one (lid closed, mains power, one run; like two of the three runs above, on a tree with `DM_NVN_ENC_THREAD=1` and a local change, not in main, that ends a submission without waiting for the encode thread): the menus kept the link (no bad window), play turned it off at frame 2864 (25 turns of 300), and the route had 59 `[longframe]` lines, 28 of 30 windows with frame p95 under 20 ms and 4 frame-step changes, against 1,021-1,086 with the link. An earlier version asked for latency 2 instead; its one run does not show whether that helps (above). Not checked: other games (no `regress.py` run).
- **Open, two screens lit:** with the MacBook's lid open and its screen lit beside the external one (the game fullscreen on the external screen, which is the main display), the same walk is slow in every mode, from the title menu on: 205 and 257 `[longframe]` lines with this policy (link off at frames 606 and 638), 207 with `DM_PRESENT_LINK=0` from the start, 950 with latency 2; 0 of 15 windows with frame p95 under 20 ms, the frame step at 2 vsyncs for most of the route, frame interval p99 34 ms in the menu at a GPU time of 7.5 ms. Battery or mains made no difference (205 and 257). The morning runs (1,021-1,245 with the link, 103 without) match the lid-closed run; the lid's state was not recorded then. It is the fullscreen window's: in a window on the external screen with both lit, the walk had 21 `[longframe]` lines and 29 of 30 windows with frame p95 under 20 ms. In fullscreen the display link itself skips ticks from the title menu on: 47 of 300 tick gaps over 25 ms (`@link_gap_ms` 33.6) in frames 300-600 at a GPU time of 7.5 ms, against 2 with the lid closed and 0 in the window; without the link, 12 of 300 drawable waits over 20 ms there. It follows the built-in screen's refresh mode: with that screen set from ProMotion to a fixed 60 Hz in System Settings (lid open, both lit, one run), the same fullscreen walk had 22 `[longframe]` lines, 30 of 30 windows with frame p95 under 20 ms, no frame-step change and 1 of 300 tick gaps over 25 ms in the menu; the link was still turned off in play (30 turns of 300, frame 2776). So a variable-refresh screen lit beside the fixed 60 Hz screen that holds the fullscreen window makes the system skip that window's refreshes. The host does nothing about it yet (`front_screen_match` only moves the screen the window is on). Not tried: mirrored screens, another external screen or Mac; why the system does it is not known.

### The 30 Hz display link in fullscreen on a fixed-rate screen

Expand Down
Loading