Repository navigation
Mac: present snapshots (DM_PRESENT_SNAP=1): a game with two swapchain textures runs a frame ahead, and the frame step judges lateness by the screen - #87
Conversation
f0e5a6d to
a1c71af
Compare
|
Correction: the first version of this description compared the last few 300-frame windows of each run, which happened to be clean. Over the whole runs, snapshots alone barely help (53 against 64 late frames). Only the combination with #81 holds 60 fps cleanly (4 late frames). I updated the description, the commit message and docs/development.md. |
a1c71af to
5a0ba01
Compare
|
Update: a second commit makes the frame step judge lateness by what the screen shows while snapshots are on. With it, snapshots alone hold 60 fps in the Zora's Domain test at 444 MHz: 4 of 10,800 frames late on screen, no step to 30, no GPU filler. The description has the new table. |
ad64a74 to
667dd1e
Compare
|
Measured on the M3 Pro (12-core, 36 GB, macOS 27.0.1 / Darwin 27.0.0) you asked about, across four 400 s arms tonight: same save snapshot restored before every arm, same key script (title → field, then continuous walk + sprint + right-stick pans), scenes 32 k–97 k draws/frame,
Two observations from this box:
So on this combination the parked #81 remains the right ship, and #87 does not replace it. Fine to keep #81 parked upstream on your data; just noting the M3 Pro / macOS 27 combination disagrees, in case another report comes in from that generation. |
|
Thanks for measuring on the M3 Pro! A few things before I'd read this as snapshots being a net negative:
The latency point is fair: snapshots let the game run one frame ahead. I'd be curious whether you notice it in full screen too, where we measured 58 ms from present to screen against 91 ms in a window. |
1f1c9f9 to
b667d7c
Compare
e4f5e7c to
5314ec2
Compare
|
I've now checked this myself on the iPhone as well. On an iPhone 17 Pro Max, present snapshots together with the encode thread (a small follow-up PR, coming, that builds on this one) held Breath of the Wild at a steady 60 fps at the docked resolution:
On the Mac it has held 60 fps since the measurements above. Main has moved since, so I'll rebase this PR in the next hours. #142 lists how it fits with the other PRs. |
5314ec2 to
95ebb0c
Compare
…ain textures can run a frame ahead of the screen Breath of the Wild has two swapchain textures and gets one back only when the display link has taken its previous present, so each frame's CPU work starts on a tick and the GPU idles from the end of one frame to the first work of the next. macOS reads that idle time as room and holds the GPU at its lowest clock (444 MHz on an M2 Max) even while frames miss the screen. With DM_PRESENT_SNAP=1 each present is copied on the game's queue, right after the frame's work, into one of two host textures (nvn_mtl.m snap_take), the display link shows the copy, and the game's texture is free at once: the game runs up to a frame ahead of the screen and a frame whose GPU work runs long is absorbed instead of shown late. The presenting thread's wait for a free ring slot paces the game; AcquireTexture then does not wait for a display link tick, and the frame step counts the slot wait as waiting, not as the frame's cost (counted as cost, it stepped Breath of the Wild down to 30 fps). Presents from another thread while Metal encoding runs on its own thread (DM_NVN_ENC_THREAD) are not copied. Off by default. Checked on the same change on the previous base (the Breath of the Wild Mac shader library here is of that chain): Zora's Domain from a Cemu save, M2 Max, 144 Hz screen at 120 Hz, about 145 s each, frames on screen longer than 1/60 s by a quarter: 64 of 8,684 with neither, 53 with snapshots alone (at 444 MHz the GPU work does not fit for stretches, which no buffer absorbs), 41 with the GPU filler of PR seedds#81 alone, 4 of 9,000 with both. On this branch the Mac host builds and t_present_crop, t_pace and t_fstep pass. docs/reference/frame-rate.md (Present snapshots) and the note of Breath of the Wild say so
… not the frame's cost With snapshots 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 no evidence against the hold. Judged by cost, Breath of the Wild in Zora's Domain stepped to 30 fps five times in 145 s, three of them at a GPU time of 0.75-0.89 vsyncs: the frame's CPU time held the game's waits on its own GPU work, which runs a frame later now. fstep_tick now hands the controller the screen's verdict (nvn_fstep.screen): the on-screen interval of the frame 8 presents back against its hold (pres_expect_ms), late by a quarter or dropped. Without snapshots, or without presented times, nothing changes. t_fstep: costly frames shown on time keep hold 1, three frames late on screen step up whatever their cost, the verdict holds for one call (50 checks pass). Checked on the same change on the previous base: Zora's Domain from a Cemu save, M2 Max, 144 Hz screen at 120 Hz, snapshots without the GPU filler, 180 s with a shader build running beside it: 4 of 10,800 frames on screen longer than 1/60 s by a quarter (53 of 8,700 judged by cost, 64 of 8,684 without snapshots), no step to 30, the GPU at 444 MHz throughout. docs/reference/frame-rate.md (Present snapshots) and the note of Breath of the Wild say so
…after frame is late too, and frames the buffer absorbed stay out of the probes' reference Judged by the screen alone, a game steadily slower than its hold never stepped up: with 18.9 ms frames at hold 1 (DM_TEST_PRESENT_LAG=1,12 on Breath of the Wild) the screen missed one refresh in 7, never three in a row, and the game ran at a jittering 53 fps with a payback every few frames instead of a steady 30. fstep_tick now also counts a frame late when 12 of the last 16 started later than their hold (the bits are cleared when the hold changes, so a step is judged against the hold in force). The controller's probe reference (crun, ccur) takes only frames whose cost fit their hold while the screen judges: frames the buffer absorbed made the scene look as cheap as the one that held hold 1, and the probes flapped between 60 and 30 about once a second. t_fstep: a steadily too slow game shown on time, then late, stays at hold 2 with no probes (51 checks pass). Checked on the same change on the previous base: the same test now holds hold 2 (31.7 ms frames, 10-12 of 300 late on screen) where it ran at 53 fps with 40 of 300 late
…d by time and the frame step does not judge by the screen With snapshots a frame starts as soon as a ring slot is free, and a slot frees when the display link has taken its present. While the link is silent (the window in the background or covered; mtl_present_wait's stall fallback, STALL_NS) frames are dropped as fast as they come, so nothing paced the game, and the dropped frames counted as late on screen and stepped the frame step to 3 vsyncs: Breath of the Wild ran at 2.5 to 4.8 times real time behind another window. AcquireTexture now sleeps to the texture's slot time while the link is stalled (mtl_link_stalled), as without snapshots, and fstep_tick takes no screen verdict then (frames the fallback drops say nothing about the game; it judges by cost). Checked on the same change on the previous base, Breath of the Wild with the display link paused for 40 s (DM_TEST_LINK_STALL=45,40): game time against real time during the pause 1.000 (2.48 and 4.83 before), after it 1.003 and 1.000 (2.29 before). On this branch the Mac host builds and t_fstep, t_pace and t_present_crop pass
95ebb0c to
ef812da
Compare
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]>
|
Incorporated this PR together with #157 into main in a188613, with contributor credit. The integrated version includes the snapshot/frame-step work, encode-thread support, fixes for suspend draining and blocking present calls, and an NVN-only Frame buffering launcher toggle. Snapshots default off on iOS and Mac; the launcher remembers the user's choice, and The full graphics suite, 38 snapshot regression checks, encoder-enabled checks, Mac build, iOS compile check and launcher/docs/packing tests pass. Details and the existing main host-unit-test build failure are recorded in #157 (comment). No new iPhone runtime benchmark was performed here. Closing as incorporated. Thank you for this work. |
Integrate the present snapshots and frame-step work from seedds#87 together with the encode-thread support and wait ledger from seedds#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 57ebf66. No iPhone runtime performance claim. Co-authored-by: v0lumehi <[email protected]>
Part of #71 (Breath of the Wild below 60 fps on the Mac). With this PR, Breath of the Wild holds 60 fps in a heavy scene at the GPU's lowest clock, without the GPU filler of #81.
Problem
Breath of the Wild has two swapchain textures. It gets one back only after the display link has taken that texture's previous present, so each frame's CPU work starts on a tick. The GPU then idles from the end of one frame until the next frame's first work arrives: about 7–9 ms per frame. The dozen gaps between submissions inside a frame add up to only about 0.2 ms.
macOS treats that idle time as spare capacity and keeps the GPU at its lowest clock (444 MHz on an M2 Max), even while frames miss the screen. Giving the game more work doesn't change that: at render scale 1.25 and 1.5 the clock stayed around 450 MHz and the frames just got slower.
Change
DM_PRESENT_SNAP=1, Mac, off by default).nvn_mtl.msnap_take). The display link shows the copy, and the game's swapchain texture is free at once.AcquireTextureno longer waits for a display link tick.DM_NVN_ENC_THREAD).fstep_tick,nvn_fstep.screen).DM_TEST_PRESENT_LAG=1,12) missed only one refresh in seven and never three in a row, so the game ran at a jittering 53 fps instead of a steady 30.AcquireTexturenow sleeps to the texture's slot time while the link is stalled, as without snapshots.DM_TEST_LINK_STALL=45,40), game time against real time is 1.000 during the pause and 1.003 right after it.The cost is up to one frame more latency.
Measurements
Zora's Domain from a converted Cemu save, M2 Max, 144 Hz screen matched to 120 Hz, no input. "Late on screen" counts frames shown longer than 1/60 s by a quarter, taken from the drawables' presented times, counted from frame 1200.
In the last run there was no step to 30 fps in 3 minutes, even with a shader build running alongside. Two later runs with the third commit gave 13 of 9,000 and 29 of 12,600, about one frame every 10–30 s; the second had another build running alongside. That is still well below the 0.74% without snapshots, and neither run stepped to 30 fps. The scene is not identical from run to run: GPU load varied between 50 and 80% across runs.
These numbers come from the same change on the previous base (4c7adf4), because the Breath of the Wild Mac shader library on this machine is built for that chain. On this branch, the Mac host builds and
t_fstep(50 checks, 3 of them new),t_paceandt_present_croppass.I haven't tried other games or the iPhone yet. Whether snapshots should become the default, at least on the Mac, is up to you once more games are tried. With this PR the GPU filler (#81) made no visible difference on my Mac, so I've parked #81.