You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a188613
Browse filesBrowse the repository at this point in the historyBrowse files
Add opt-in frame buffering with safe snapshot pacing and suspend
Integrate the present snapshots and frame-step work from #87 together with
the encode-thread support and wait ledger from #157. Keep snapshots off
by default on both platforms pending wider device validation.
Offer Frame buffering in the iOS launcher for NVN builds. The existing
launcher remembers the choice and preserves env.txt overrides. Pass the
packer's detected graphics API to the settings generator.
Wait for snapshot capacity at acquire; a present reaching a busy slot
falls back to its original texture ticket. Drain snapshot commits and GPU
completion during suspend even when display tickets were discarded.
Regression tests cover both waits, fallback tickets and copied pixels.
Validated on M4 Pro: full gfx run list, 38 snapshot lifecycle checks,
219 checks with encoding and snapshots enabled, Mac host build, 133-file
iOS compile check, and eight launcher/docs/packing tests. The host unit
suite cannot link t_heap_size because dm_ue_heap_owns is missing, reproduced
on unchanged main cbbb600. No iPhone runtime performance claim.
Co-authored-by: v0lumehi <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -174,6 +174,8 @@ With an Apple developer account you can instead build and install from Xcode: `-
174
174
175
175
**Settings.** A screen before the game starts offers what the game supports: frame rate, render scale, docked or handheld mode, game language, the frame-rate counter and Apple's performance HUD. Tap **Play** to start; the app remembers your choices.
176
176
177
+
**Frame buffering.** NVN games also offer this toggle, off by default. It may reduce stutter by buffering completed frames, at the cost of extra display latency. The app remembers your choice. `DM_PRESENT_SNAP=1` or `0` in `Documents/env.txt` overrides it; fully close and reopen the app after editing the file.
178
+
177
179
**Touch controls.** Tap **2D** / **3D** at the top to switch layouts; the app remembers your choice. Wonder, Engage, Dread, 13 Sentinels, Link's Awakening, Ace Attorney Investigations Collection, Unicorn Overlord, Rhythm Heaven Groove, Octopath Traveler 0, Pokémon Legends: Z-A, Cuphead, Absolum, Brain Memory Training Academy, The Great Ace Attorney Chronicles, STEINS;GATE RE:BOOT, Big Brain Academy: Brain vs. Brain, Patrick's Parabox, Celeste, Raging Loop and Mario vs. Donkey Kong start in 2D, the other games in 3D (STEINS;GATE RE:BOOT's quick save is R3, in the 3D layout). In 3D, the right stick (the camera in most games) is not drawn: swipe on the right third of the screen, starting anywhere off the buttons. In Super Mario Galaxy and Super Mario Galaxy 2, other touches outside the controls move the pointer; in Captain Toad: Treasure Tracker they touch the game's screen (touch blocks, stun enemies), and in Big Brain Academy: Brain vs. Brain too (its menus and activities).
178
180
A connected game controller hides the touch controls and keeps every button.
Copy file name to clipboardExpand all lines: dm/games/01007EF00011E000/README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,8 @@ Used at `DM_FPS_TARGET=0` and for the interval the framework keeps while the VFR
63
63
- **Outdoors (2026-10-21, the user's Great Plateau save, Mac M4 Pro).** A frame had about 386 render passes and loaded and stored about 900 MB of attachments (on an iPhone at 60 fps about 55 GB/s, near the memory's bandwidth). 220 passes ended only because the game updates the first 64 bytes of a 64 KB vertex uniform block (`0x70c38c0000`) before each draw group while its shaders read up to 544 bytes of it (the terrain pixel shader `eb0afe555b86da79` indexes the whole block). Partial-cover uniform shadows (`ubp_get`, `DM_NVN_UB_PARTIAL`) and `cb_extent.tsv` keep those passes open: 386 → about 165 passes, GPU p50 about 9.3 → 6.5 ms, submit 5.7 → 4.9 ms; `DM_NVN_UBP_CHECK=1` found every shadow equal to the GPU's memory (968,000 checked). Lazy clears fold the four clear-only passes before the G-buffer into its first pass (about 30 MB less a frame at 1600x900). The frame still loads and stores about 800 MB: the NintendoWare VFX GPU particles run one compute dispatch per emitter between draws (ten 800x450 half-resolution passes and two G-buffer passes, about 190 MB a frame; the G-buffer ones read the depth being drawn), and decals sample the G-buffer right after the game sets it again. Tried and dropped: `DM_NVN_TBDR=1` (10–15% fewer stores, more CPU, red ledger lines, deferred uniform updates off), `DM_NVN_BARRIER=game` (no gain), same-target continuation outside TBDR mode.
64
64
- Same-pass feedback: over a thousand draws a frame sample the G-buffer of their own pass (`4d3d5a4408c2e8d9`, `753d0169ae3ce4f0` and others on the 1600×900 G-buffer); snapshotting all of them took the Mac frame time from 16.6 to 36.6 ms, and none has shown magenta blocks on the iPhone so far. The decals that sample targets of their own pass read the stored content on the Mac; `DM_NVN_FB_SNAP=all` would snapshot them at a large cost.
65
65
66
+
-**Present snapshots (Mac).** The game's two swapchain textures held its CPU work to display ticks and the GPU at 444 MHz on an M2 Max ([present snapshots](../../../docs/reference/frame-rate.md#present-snapshots-the-games-swapchain-texture-free-at-once)). Judged by cost, the frame step stepped to 30 at a GPU time of 0.75 vsyncs. Zora's Domain from a Cemu save (120 Hz), frames on screen longer than 1/60 s by a quarter: 64 of 8,684 with neither, 41 with the GPU filler alone, 4 of 10,800 with snapshots alone (no step to 30 in 3 minutes, at 444 MHz throughout).
67
+
66
68
## Rendering
67
69
68
70
-**Resolved: the 3D scene black, only particles and the HUD drawn.** The engine binds almost every texture with `nvnCommandBufferBindTexturesDeferred` (`main+0xec2e64`, one handle, the pointer being the handle field inside the texture-sampler object): the GPU reads the handle when the command executes, and the game records its command blocks once and writes the handles afterwards. The host copied them at recording, mostly zeros, so the deferred-lighting composite read the dummy texture 0. The bind record keeps the source address and replay refreshes the handles first (`bh_fresh`). Found with a data-flow table from `DM_NVN_PASSDUMP_ALL`: the composite's `B` lines were all `tid=0 dummy` (without `_ALL` only the first draw of each pass is listed).
Copy file name to clipboardExpand all lines: dm/games/settings.tsv
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,11 @@
4
4
# variable the environment variable the setting sets
5
5
# kind choice: values value=label,... (languages: the game's own, from its control data); range: values low:high:step, shown as a percentage; toggle: 1 / 0, values -
6
6
# default a value; DM_GAME_<NAME>: the host's own default from the game profile (game_profile.h, game.py); build:<VAR>: the IPA build's setting (build_ipa.sh)
7
-
# shown always; DM_GAME_<NAME>!=<value> or ==<value>; fixups:<KEY>: main's rewriter table has that key (a stub in the game's build, patch_nso.py); languages>1
7
+
# shown always; DM_GAME_<NAME>!=<value> or ==<value>; fixups:<KEY>: main's rewriter table has that key (a stub in the game's build, patch_nso.py); languages>1; gfxapi:<API>: the packer's GFXAPI
8
8
# label, note the setting's name and the line under it (the note may be empty)
if (rtp&&rt_period!=rtp) { rt_period=rtp; set_time_constraint(rtp); }
1265
1268
rt_comp_tick(rtp);
1266
-
uint64_tp0=now_ns();
1267
-
if (mtl_link_active()) { if (!mtl_link_wait_tick(present_itv(o), period ? 2*period : 33333333ull) &&wait) sleep_until_ns(at); } // DM_PRESENT_LINK: pacing fully follows the display link (wait for the present interval's display-link ticks when running fast, go immediately when behind); our own 60 Hz clock is only the fallback when no display-link tick arrives
1269
+
uint64_tp0=now_ns(); intsnap=mtl_snap_on();
1270
+
if (snap&&mtl_link_active()) { if (wait&&mtl_link_stalled()) sleep_until_ns(at); } // present snapshots (nvn_mtl.m): the acquire's wait for a free ring slot below paces it.
1271
+
// While the display link is silent (the window in the background or covered) frames are dropped as fast as they come and
1272
+
// nothing frees a slot later, so the texture's slot time paces the game as without snapshots: unpaced, Breath of the Wild ran 3 to 4.5 times real time there
1273
+
elseif (mtl_link_active()) { if (!mtl_link_wait_tick(present_itv(o), period ? 2*period : 33333333ull) &&wait) sleep_until_ns(at); } // DM_PRESENT_LINK: pacing fully follows the display link (wait for the present interval's display-link ticks when running fast, go immediately when behind); our own 60 Hz clock is only the fallback when no display-link tick arrives
1268
1274
elseif (wait) sleep_until_ns(at);
1269
1275
pace_ns=now_ns() -p0;
1270
1276
} else { // DM_DETCLOCK_PACE=1 (used by the screenshot gate): while the guest clock advances per frame, each frame's wall clock is no shorter than one step -- frame count and in-game time are deterministic, and the background loading thread has at least one step of wall clock available per frame;
// The previous present of this texture has not yet been processed by the present thread (display cannot keep up, a whole swapchain round behind): wait for it to be returned, then hand it to the game to draw
1278
1285
uint64_ttk=*idx<4 ? o->ticket[*idx] : 0;
1279
1286
if (tk) { uint64_tw0=now_ns(); mtl_present_wait(tk); g_pq_wait_ns+=now_ns() -w0; }
1280
-
if (s) { ((sync_t*)s)->fenced=1; ((sync_t*)s)->fence=mtl_last_fence(); } // The swapchain texture becomes available once the commits before this point have completed
1287
+
if (s) { ((sync_t*)s)->fenced=2; ((sync_t*)s)->fence=mtl_last_fence(); } // The swapchain texture becomes available once the commits before this point have completed (fenced 2: an acquire sync, for the wait ledger)
1281
1288
if (!g_fs_start) { g_fs_start=now_ns(); g_fs_wait=pace_ns; } // the frame starts when the first acquire after a present returns: on a display-link tick when on time
intcslow=fstep_cpu_slowed(o->presents), gslow=nvn_fstep_gpu_slowed(&g_fg, gpu, k0 ? k0 : kmin, kmin, probe0) &&dm_thermal_now() <= 1&& !dm_low_power_now(); // same gates as the CPU's
1619
+
// Present snapshots (nvn_mtl.m snap_take): the game runs up to a frame ahead of the screen, so a frame whose work runs long is absorbed instead of shown late, and its cost is
1620
+
// no evidence against the hold (Breath of the Wild in Zora's Domain stepped to 30 at a GPU time of 0.75 vsyncs: the frame's CPU time held its waits on its own GPU work).
1621
+
// Lateness is then what the screen shows: the on-screen interval of the frame 8 presents back against its hold (pres_expect_ms), late by a quarter or dropped
1622
+
// A game that is slower than its hold frame after frame (not a few long frames: 12 of the last 16 started late) is late too, though the screen misses only every few frames:
1623
+
// 18.9 ms frames at hold 1 missed one refresh in 7, never three in a row, and ran at a jittering 53 fps with a payback every few frames instead of a steady 30
1624
+
if (mtl_snap_on() &&mtl_link_active() && !mtl_link_stalled() &&o->presents>9) { // (frames the stall fallback drops say nothing about the game: judged by cost then)
// Slow-frame attribution (taken only when DM_NVN_TSV is on): this frame's present-thread CPU time (−1 if the thread changed), CPU of all threads in the process, acquire wait accumulated per frame, present call time (same base as the GPU / on-screen present times: ms since process start)
Copy file name to clipboardExpand all lines: dm/gfx/nvn/nvn_fstep.h
+8-3Lines changed: 8 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,8 @@ typedef struct {
35
35
intprobe, grace; // 1: the trial in progress is a probe; 2: a probe held and its run at kmin has not ended yet; frames left of the probe's grace
36
36
doublehold, since; // vsyncs a trial waits for after a step up; vsyncs since the last step up
37
37
doubleshown_slack; // vsyncs a frame on time may show longer than k (set by the caller): one refresh on screens whose rate is not a multiple of 60; the cost keeps FSTEP_LATE
38
+
intscreen; // set by the caller before each call, then cleared: 0 = judge lateness by shown and cost; 1 = the screen showed a recent frame on time, 2 = late. With present
39
+
// snapshots (nvn_mtl.m) the game runs ahead of the screen and a frame that runs long is absorbed, so only what the screen shows counts
38
40
doublerun, crun, cref; // vsyncs at kmin in a row; the cost of its frames on time (running mean; not during a probe's trial, whose frames run while the clock rises);
39
41
// crun when the last run of FSTEP_HOLD_MAX or more ended in a step up (0 = none yet)
40
42
doubleccur; intck, cn; // the cost of the frames on time at the longer hold ck (running mean) and their count
@@ -69,16 +71,19 @@ static inline int nvn_fstep_next(nvn_fstep *s, double shown, double cost, int km
69
71
if (kmin<s->kmin||s->k<kmin) s->k=kmin; // the cap rose (a movie or the game's own step ended) or fell
// The cost of the frames on time (a hitch is not what the scene costs): at kmin, and at the longer hold
76
79
if (kmin!=s->ckmin) { s->ckmin=kmin; s->run=s->crun=s->cref=0; }
77
-
if (held <= kmin) { s->run+=shown; s->cn=0; if (!late&&s->probe!=1) s->crun=s->crun>0 ? s->crun+ (cost-s->crun) / 32 : cost; }
80
+
// A frame the screen showed on time while its cost did not fit (absorbed by present snapshots) is not what the hold costs: the probes would take it for the scene that held kmin
81
+
intfits= !scr||cost <= held;
82
+
if (held <= kmin) { s->run+=shown; s->cn=0; if (!late&&fits&&s->probe!=1) s->crun=s->crun>0 ? s->crun+ (cost-s->crun) / 32 : cost; }
Copy file name to clipboardExpand all lines: dm/gfx/nvn/nvn_mtl.h
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,7 @@ uint64_t mtl_sub_commit(void);
37
37
38
38
uint64_tmtl_last_fence(void); // Fence value of the most recent submit (0 = never submitted)
39
39
intmtl_wait(uint64_tfence, uint64_ttimeout_ns); // Returns 1 when the GPU has completed up to fence, 0 on timeout
40
+
intmtl_wait_acq(uint64_tfence, uint64_ttimeout_ns); // the same for a sync WindowAcquireTexture handed out (its own line in the wait ledger, DM_NVN_WAITS)
40
41
voidmtl_finish(void); // Wait for all submitted commands to complete
41
42
voidmtl_drain(void); // Wait for all commands on the queue (including presents) to complete: submit an empty command buffer and wait for it
42
43
voidmtl_xv_window_tex(uint64_tserial); // Register a window (swapchain) texture: the cross-submit validity ledger never collects it
0 commit comments