Repository navigation
Conversation
macOS sets the GPU's clock from how busy it was. A game that picks its own present interval and holds two vsyncs leaves the GPU idle half of each frame, the clock falls, and the same frame takes longer: Donkey Kong Bananza drew about 5,000 draws in 12 ms of GPU at 60 fps and in 20.4-22.4 ms at 30 fps (main at e693bb8). Its frame-rate controller returns to one vsync only once a frame fits 1.2 vsyncs, so it stayed at 30 fps for tens of seconds, until a lighter view let it back. On the Switch the GPU clock does not follow the load. The host already declares the shorter deadline to the CPU scheduler for this reason (rt_period_ns); nothing did it for the GPU. The GPU clock keeper (Mac only) probes instead of spinning whenever frames are slow, as PR seedds#1847's did. Its decisions are pure, in nvn_gpu_keep.h: when a present's period is over 1.5 times the shortest seen and a frame's GPU time is above 0.6 of that period, it keeps one 32-thread threadgroup spinning on a queue of its own for up to 4 s, only while the game's queue has nothing in flight (each spin about 0.8 ms). It stops as soon as the period shortens. A lost probe waits 8 s, doubled after each further loss, and after 4 in a row it waits until the period shortens by itself. It never runs at the shortest hold. The thread (gpu_keep_main in nvn_mtl.m) sleeps on a condition variable at the shortest hold, stops while the window is not focused or is covered, while nothing is presented, while presents are discarded for a suspend, at thermal state serious and in Low Power Mode, and is stopped and waited for at quit. DM_GPU_KEEP=0 turns it off. The log has a line for each probe, written before the thread sleeps. Checked: t_gpu_keep (30 checks, new, in the CI list), t_link_latch_cb, t_present_rescue, t_gfx_suspend, check_t_present_snap, test_docs and test_env_switches; the host builds for Bananza. Played on an M3 Max MacBook Pro, 8 sessions alternating on and off from one restored save: with it, 23 probes, all won within 0.3-0.7 s, no 300-frame window at 30 fps; without it, two windows at 30 fps (GPU p50 24.6-25.3 ms). powermetrics: GPU power 10.4-12.8 W with it, 11.9-12.5 W without. regress.py check against 1dae211 on Bananza, Star Fox, Mario Kart World, Metroid Prime Remastered and Ocarina of Time: PASS on the first four; Ocarina of Time flagged for p99 on its first check (the baseline run's own p99 is 33.5 ms on a second check, same as the keeper's 33.4) and on its second for one slow residency commit at startup, which it logs now and then on main too. Not checked: other Macs, a fanless one above all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
On the Mac, Donkey Kong Bananza drops from 60 to 30 fps in a heavy moment and stays at 30 for tens of seconds, until a pause or a view of a wall lets it back. The game picks its own present interval: its frame-rate controller (
main+0x204a18) returns to one vsync only once a frame fits 1.2 vsyncs (20 ms). At two vsyncs the GPU idles half of each frame, macOS lowers the GPU clock, and the same frame takes longer. On main ate693bb89(M3 Max MacBook Pro, a window, MetalFX), about 5,000 draws took 12 ms of GPU at 60 fps and 20.4–22.4 ms at 30 fps, so the frames never fit again. On the Switch the GPU clock does not follow the load, so the game's rule is right there. The host already gives the CPU scheduler the shorter deadline for the same reason (rt_period_ns); nothing did it for the GPU.This is the "focused PR with fresh main measurements and suspend/quit handling" asked for when #1847 was closed. Unlike #1847's keeper, it does not spin whenever frames are slow. It probes, and only while the game sits at a longer hold:
rx_inflight), about 0.8 ms per spin, for at most 4 s.dm_focus_now) or covered, while nothing is presented, while presents are discarded for a suspend, at thermal state serious or worse, or in Low Power Mode. At quit it is stopped and waited for (atexit). At the shortest hold its thread sleeps on a condition variable.DM_GPU_KEEP=0turns it off. The log has a line for each probe (started, won, lost, stopped and why).The decisions are pure, in
dm/gfx/nvn/nvn_gpu_keep.h, with a test,t_gpu_keep. The thread isgpu_keep_maininnvn_mtl.m. Reference entry: A game's own 30 fps fallback held by the GPU clock its longer hold lowered. Bananza's note links it.Checked
t_gpu_keep(30 checks, new, added to the CI list),t_link_latch_cb,t_present_rescue,t_gfx_suspend,check_t_present_snap,test_docs,test_env_switches. The fullmake -C dm/gfx/tests runon the branch rebased onto1ca449bc9: five checks fail, all on main at1ca449bc9too, with the same messages (t_cpu_tex"late descriptor views retire at submission end" ×2,t_gl_importsabort,t_mdx_prescanindirect barrier after a shader write,t_pool_chunksline 176,t_transform_feedbackcapture after an inline update); the rest pass.040074A01BF12000v458752, played by hand. Eight sessions alternated with the keeper on and off (DM_GPU_KEEP=0), each starting from the same restored save. The last pair visited six layers and zoomed the map out and turned it.DM_KEYSdid not stay on its path, since walking into the warp gongs does not land the same twice.DM_DETCLOCKwould make it repeat, but it hands the game a fixed clock, and the controller measures that clock, so the 30 fps hold could not happen under it.)powermetrics, the same eight sessions): mean GPU power 10.4–12.8 W with the keeper, 11.9–12.5 W without.scripts/regress.py checkagainst1dae211a9.regress.py impactnames every NVN game (the present path); of the profiles with a usage manifest none is local, so these five cover the present path, two frame-rate controllers that switch intervals, and three games that never do:040074A01BF120000400E88025B1A0000400C3F00006E000010012101468C0000400486024DEC000cb58c93e5(regress.py: a late first frame fails Ocarina of Time's screenshot check #3513: route seconds count from the first presented frame); the run used the harness before it.slow residency commit(145 ms, 1,898 adds, 526 MB) at startup in the keeper run, where the keeper never probed. Its game note lists that line as its usual[RED].b1f95bdb9after the regress run; the shader chain changed on main (e885e184f677→da51882ee408), not here. The one conflict was the CI test list (t_gpu_keepadded aftert_link_latch). On the rebased branch the host builds, andt_gpu_keep,t_link_latch_cb,t_link_latch,t_link_drain,t_fstep,t_present_rescue,t_gfx_suspend, every mode ofcheck_t_present_snapandtest_docspass.test_env_switchesfails, with the same output onb1f95bdb9itself (DM_YAZ0_NATIVEhas no row, and some removed switches are still quoted);DM_GPU_KEEPhas its row. The full graphics suite ran on1ca449bc9, as above. The regress run is on1dae211a9, before main'scb58c93e5.Docs
docs/reference/frame-rate.mdentry and Bananza's note, andpython3 dm/tools/docs_symptoms.pywas run