Skip to content

Mac: GPU filler only while frames come late, between the game's submissions (#71) - #81

Closed
v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:gpu-filler
Closed

v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:gpu-filler

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

A narrower version of #62's GPU filler for #71 (Breath of the Wild's frame rate drops on the Mac as macOS lowers the GPU clock). Split out of #76. Draft. The alternative that changes presentation instead is now #87 (present snapshots plus a frame step that judges lateness by the screen). In Zora's Domain it held 60 fps at 444 MHz without this filler. Which one to keep, or both, is up to you; see the comparison in the comments.

Your two objections on #62, and how this version handles them:

  • It ran for every game, all the time: it now starts only when 1 in 20 of 120 presents come late, late meaning more than a tenth over the frame period, as the frame step counts it. It stops after a hold without late frames. The hold doubles at each start, from 60 s up to 16 min. An independent M3 Pro run (comments) found this automatic mode flaps on BotW, whose late frames come in bursts, and suggests DM_GPU_FILL=1 as the macOS default.
  • It shared the GPU with the game's work, whose times the frame step reads: it now dispatches only while none of the game's submissions is on the GPU, from the completion of the last one in flight to the next commit. It never adds to the game's own GPU time.

Measured on BotW at 60 fps (M2 Max, macmon every second for 180 s):

  • Without the filler: the clock fell to 444 MHz after 70 s and stayed there, with 304–346 late frames every 30 s.
  • With the filler: 1398 MHz throughout, with 11–17 late frames every 30 s.

I see this as a workaround to ship now rather than the fix. macOS has no API for the GPU clock. On the developer forums an Apple engineer advised against GPU busy-work and asked for feedback reports (thread 768160). Instruments' "Performance State" setting is for profiling only. A fundamental fix still has to be found: one that removes the idle GPU time macOS reacts to, or gets macOS to treat the game's work as latency-bound. One known approach is LASRecomp's: nvnSyncWait waits for the fence before the newest, so the GPU runs one frame behind (PR #241). That approach brings readback and race questions of its own, and I don't want to settle on it yet. I'll look for a proper solution separately and propose it on its own. Until then the filler is off unless frames come late, and DM_GPU_FILL=0 turns it off entirely.

Limits. The filler fixes the clock, not every long frame. Three other sources remain:

  • Pipeline builds on first use: 40–140 ms each in BotW.
  • The game's own object placement: CPU work, with no uploads and no pipeline builds (found in the M3 Pro run).
  • Evicted compiled pipelines: with dmhost started without an Info.plist, the Metal shader cache is shared with other command-line tools and keeps only three rotating files.

@v0lumehi

Copy link
Copy Markdown
Contributor Author

Measured in a heavier scene: Zora's Domain, from a converted Cemu save, on an M2 Max with a 144 Hz screen matched to 120 Hz. Each run lasted 120 s with no input.

Configuration GPU clock GPU time per frame Late frames
Filler off (DM_GPU_FILL=0) 444 MHz 12.9 ms (77% busy) about 190 per 30 s
Filler automatic, previous trigger 444 MHz (never started) 12.9 ms about 200 per 30 s
Filler on from the start (DM_GPU_FILL=1) 1398 MHz 8.2 ms (49% busy) about 8 per 30 s
Filler automatic, new trigger 1398 MHz 8.3 ms about 3 per 30 s

With the new trigger the filler started, went off after its 60 s hold, and the clock fell to about 1,100 MHz. Frames came late again, and the filler came back on with a 120 s hold.

The previous trigger needed 1 in 10 presents to be more than a quarter over the frame period. Here frames came late by less than that, so the filler never started. The new trigger (9f32f9a) counts a present as late at a tenth over the period, as the frame step does, and starts the filler when 1 in 20 presents are late.

Present snapshots, which decouple the swapchain texture, did not help here. Without the filler they left the clock at 444 MHz and the frame step dropped to 30 fps.

…he game's submissions

macOS lowers the GPU clock while the GPU idles part of each frame, even when the frames then miss their
deadline, and offers no interface to ask for a clock. Breath of the Wild waits for each frame's GPU work, so
its GPU idles while the host translates the next frame (GitHub issue seedds#71). The filler of PR seedds#62 ran for every
game all the time and shared the GPU with the game's work. Now it starts only when a tenth of 120 presents
come late (mtl_gpu_fill_frame), keeps one small dispatch on a queue of its own only while none of the game's
submissions is on the GPU (from the completion of the last in flight to the next commit), so it never adds
to the GPU time the frame step reads, and stops after a hold without late frames that doubles at each start
(60 s up to 16 min). DM_GPU_FILL=0 never, =1 from the start (also on iOS, where it is off by default).

Breath of the Wild at 60 fps (M2 Max, macmon each second for 180 s): without it the clock fell to 444 MHz
after 70 s and stayed (304-346 late frames every 30 s); with it 1398 MHz throughout (11-17).
…nth, as the frame step counts late frames (a quarter and one in 10 never started it in Breath of the Wild's Zora's Domain, which ran at 444 MHz with 11% of its frames late)
@HougeLangley

Copy link
Copy Markdown
Contributor

Independent validation on Apple silicon M3 Pro, and two notes that may matter for the default.

Machine / title: M3 Pro 12-core, 36 GB, macOS 26A434 (Darwin 27.0.0); Breath of the Wild 01007EF00011E000 v1114112 (1.9.0), 19,593 shaders, chain b-9176263692e9. PR applied cleanly on eab15b5 and builds with the stock make -C dm/host GAME=… dmhost (2,159,320 → 2,160,552 bytes).

Method: one save snapshot restored before every arm (rm -rf run/save && cp -R /tmp/save_snap run/save), otherwise each run starts where the last one stopped and scene weight drifts more than the effect. 300 s arms, same DM_KEYS route, DM_FPS_HOLD=off, audio running with the system output at 0, draws/frame ≈ 35.8 k in both arms.

>60 ms >100 ms >300 ms excess over 16.7 ms GPU p50 first → last window
DM_GPU_FILL=0 86 49 5 13.4 s 3.16 → 12.3 ms
DM_GPU_FILL=1 21 9 1 3.8 s 1.07 → 5.05 ms

The GPU-time trend is the clearest part: at constant workload the no-filler arm ends the run spending ~4× the GPU time per frame it started with, and the filler arm ~2.4× less than that end state. That is exactly the 1398 → 444 MHz story from the issue, and it also explains why 60–150 s smoke tests look perfect: the onset lands after the run ended.

Note 1 — mode 2 flaps on this title. Two identical DM_GPU_FILL unset arms read 12 and 49 frames over 60 ms, and the log shows it going on for 62 s, off after 60 s without late frames, then on again for 203 s. The spread between two identical default runs is wider than the effect, so 1 is the only mode that measures consistently here; the cost is small (1.32 → 1.44 W, 21.9 → 24.1 mJ/frame). Please consider macOS defaulting to 1, or at least documenting that 2 is not a good fit for a title whose late frames arrive in bursts.

Note 2 — it fixes the clock, not everything. With the filler on, one 300 s arm still had 6 frames over 300 ms and a 1,018 ms maximum. Those frames show GPU 5–7 ms, new pipelines 0, ~0 MB of uploads and no fs read in the preceding 1.5 s, and power up to frame names top yielders: PlacementMgr … (back-off sleeps 0), so they are the game's own object placement, not GPU pacing. Worth saying in the PR description so nobody expects a fully smooth title from this alone.

Also measured and not worth blaming: DM_QOS_MAP=1 was worse (27 vs 16 frames over 100 ms), and audio on/off lands inside the noise band once the save is controlled (17/18 vs 36/29 frames over 60 ms — the muted arms were worse).

@v0lumehi

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the independent run, and for controlling the save. That's exactly what my early runs lacked.

Note 1, mode 2 flaps: I see the same thing. In Zora's Domain the filler started, went off after its 60 s hold, the clock fell to about 1,100 MHz, frames came late again, and it came back on with a 120 s hold. Your two identical default runs (12 vs 49 frames over 60 ms) show that this matters more than I thought. If this PR goes in, defaulting macOS to 1 looks right to me given your numbers: the cost is small (1.32 → 1.44 W) and the measurements are consistent. That's a one-line change. I'll make it if seedds wants to go this way.

There is also an alternative now that needs no filler at all: #87.

  • Each present is copied into a host texture, so the game can run up to a frame ahead of the screen.
  • The frame step then judges lateness by the drawables' presented times instead of the frame's cost.
  • With it, BotW held 60 fps in Zora's Domain at 444 MHz: 4 of 10,800 frames were late on screen. Without it, 64 of 8,684 were late, and with the filler alone 41 of 8,692.
  • The cost is up to one frame of extra latency.

If you have time, an M3 Pro run of #87 with your method (same save, same route, DM_PRESENT_SNAP=1 DM_GPU_FILL=0) would be very useful.

Note 2, it fixes the clock, not everything: agreed. I'll add a limits section to the description. I found two other sources of long frames, which may also matter for your method:

  • Pipeline builds on first use, 40–140 ms each in BotW. The bundled pso_manifest.tsv for BotW is empty.
  • The Metal shader cache. dmhost started without an Info.plist uses the shared Metal cache for command-line tools, which keeps only three rotating files. Running another game in between can evict BotW's compiled pipelines, so a later run builds them again and stutters again. A packed Mac app has its own bundle ID and cache, so it isn't affected. For A/B arms it's worth keeping the Metal cache state the same, e.g. by running nothing else in between.

Your PlacementMgr frames (CPU, no uploads, no pipelines) are a third source on top of these.

@v0lumehi

Copy link
Copy Markdown
Contributor Author

Parking this PR. With #87 (present snapshots plus a frame step that judges lateness by the screen), the filler made no visible difference on my M2 Max. In Zora's Domain the GPU stays at 444 MHz and 60 fps holds: 0–1 frames late on screen per 300 with the filler on (1398 MHz) and with it off.

The reasoning behind that:

  • A fast GPU idles, so macOS lowers the clock, but the work still fits, and the snapshot buffer absorbs the variance.
  • A slow GPU has no idle time, so macOS has no reason to lower the clock in the first place.
  • The case in between is a GPU whose work at the floor clock just doesn't fit. With snapshots that GPU would be saturated, so macOS should raise the clock by itself. The open risk is that the frame step steps to 30 before macOS reacts. Nobody has seen this yet.

So I'd rather wait for feedback than ship busy work. @HougeLangley, if you have time, a run of #87 on your M3 Pro with your method (same save and route, DM_PRESENT_SNAP=1 DM_GPU_FILL=0) would be the most useful data point.

Kept locally in case it comes back: a version stacked on #87 whose automatic mode counts frames late on screen. It still started during BotW's load, so it would also need a check on GPU time.

@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Thanks for the investigation and the detailed measurements. I’m closing this in favor of pursuing #87. Your latest results show no visible benefit from the filler with present snapshots enabled, and the automatic mode’s inconsistent behavior adds maintenance cost without a demonstrated remaining need. We can revisit this if testing on other hardware identifies a reproducible case that #87 cannot address.

@seedds seedds closed this Oct 24, 2026
@v0lumehi
v0lumehi deleted the gpu-filler branch October 24, 2026 07:58
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 24, 2026
…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/development.md says so
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 24, 2026
…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/development.md says so
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 24, 2026
…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/development.md says so
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 24, 2026
…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/development.md says so
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 25, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants