Repository navigation
Donkey Kong Bananza runs its own VRR mode on a 120 Hz screen: the rate vi::SetLayerExtendedSwapInterval asks for paces presentation, so frames just past a vsync show at 40-58 fps instead of 30 - #1389
Open
miknios wants to merge 1 commit into
Conversation
…e vi::SetLayerExtendedSwapInterval asks for paces presentation, so frames just past a vsync show at 40-58 fps instead of 30 The game has two frame-rate controllers, chosen per frame by what vi::QueryDisplayVrrSupported answered (main+0x2036b0). The fixed-refresh one (main+0x204a18) has only whole present intervals, so a frame a little over 16.7 ms took the game to 30 fps. The VRR one (main+0x204640) asks for 40 to 60 fps in steps through SetLayerExtendedSwapInterval(layer, 1, fps) and leaves VRR for interval 2 below 40. The host answered that the display has no VRR, so only the first ever ran. A profile key, vrr on, answers yes on the Mac when the game's window is on a screen of 120 Hz or more (front_screen_max_fps, which follows the window to another screen; hle_vi.c). Docked too, a deliberate difference from the Switch 2, whose VRR is handheld only: docked is what the Mac shows by default, and the game's VRR controller does not look at the operation mode. iOS never answers VRR, as it is untested there. The rate replaces the present interval the game leaves set (hle_nvn.c nvn_vrr_set): a period of 1 / fps, no 30 Hz link, and the acquire waits the rate's ticks of a 120 Hz display link with the fractional tick carried, as display mode does above 60 Hz. SetDisplayVrrCapability(false) and ClearLayerExtendedSwapInterval clear it; a frame step page or 120 fps ignore it. A key and not a rule for every game: a game's VRR mode must keep its speed between whole vsyncs, and only this one has been played that way. DM_VRR=0 / 1 overrides it on the Mac. Tested on an M1 Pro's built-in ProMotion screen, in a Mac app packed at 975bb4c with this change on top: the game asked for 40 to 60 fps in 2 fps steps and ran 47.6-52.5 fps a 300-frame window in the first two minutes, with no shader failures and no red lines. Played by hand, the picture and the speed looked normal. That app's host was this patch on 975bb4c, the commit its shaders were built for; this commit's own host was not run in the game. Not measured: the speed against interval pacing over the same scripted inputs, the same spots without the key, an external screen. Checked: t_nvn (245 checks, 10 of them new for VRR), the rest of the graphics tests and the host tests, the docs, env switch, game profile, settings, launcher and player env tool tests, the Python lint ratchet (0 new findings), and both changed C files compile for iOS. clang-tidy was not run locally. regress.py check was not run: the change acts only with the key, which only this profile sets, and this game has no smoke route. Co-authored-by: Mikolaj Wojcik <miknios@gmail.com>
miknios
force-pushed
the
dk-bananza-vrr
branch
from
November 6, 2026 12:40
c129a5a to
d9f7349
Compare
2 of 3 tasks
g8row
added a commit
to g8row/nxnative
that referenced
this pull request
Nov 26, 2026
In a busy view the host's translation of each frame is the frame's critical path: the game waits for an older frame's fence before it records the next. On Donkey Kong Bananza's checkpoint route (a save in a view of about 26,200 draws a frame) the replay thread translated for 14-18 ms a frame after main's per-draw changes, spread thinly over the draw path: no phase of DM_NVN_DRAWPROF above 5 ms, ~8,100 instructions a draw. Profiles of the leaf samples and the hot functions' disassembly found the same few patterns everywhere: answers asked again at every draw that change only at a bind, lookups that miss a single-entry cache, ARC traffic, thread-local reads and stack probes. Every change keeps what is encoded the same and has an off switch for A/B runs. - Diagnostics first: za_note_ formatted its text at every draw past its log limit (a fifth of draw_ in snprintf for one geometry shader whose slots stay 0); now it only counts there. DM_NVN_DRAWPROF=1 gives the replay thread's exclusive time by phase (@dp_<phase>_ms). - Binding scans that find nothing keep that answer with what it was made from (DM_NVN_FB_CACHE, DM_NVN_UBDT_CACHE), on the shader, and a uniform rebind asks again only the bindings that read a uniform slot (DM_NVN_UBSC_PART, DM_NVN_UBD_FAST). These sit on main's per-shader binding lists (sh_tex_list, sh_buf_list). - Argument blocks: after a mesh draw only the geometry stage is encoded again (DM_NVN_GEO_ARGS_KEEP); per-slot pool lookup memos (DM_NVN_CBMEMO, DM_NVN_CBRANGE); uniform-only patches take only the slots that changed, from a compact list (DM_NVN_CB_SLOTGEN, DM_NVN_CB_PATCH_IX); the size table handed out again (DM_NVN_CBSIZE_CACHE); blocks keep their CPU address (ab_cpu); fragment table addresses not written again (DM_NVN_FT_CACHE). - Vertex input: pool-range memos for streams, pulling layouts and index buffers (DM_NVN_VBMEMO), a dirty mask over the vertex table (DM_NVN_VBUF_DIRTY), a pulling layout cache (DM_NVN_PULL_CACHE, keyed by the attribute state, the streams with a buffer and those the shader reads, so main's absent-attribute W=1.0 rule is kept), and an off switch for main's read-streams-only rule (DM_NVN_VB_USED). - Draw state: a dirty bitmask for dynamic state (DM_NVN_DYN_DIRTY), each program's last pipeline (DM_NVN_PSO_PROG_CACHE), per-draw memos in bz_bind, border_need, vbuf_prepare, fb_prepare and udc_note_draw (DM_NVN_DRAW_MEMO); csh_dispatch_ahead no longer reads its 4,096-op scan limit as a dispatch ahead (about 300 needless stops a frame). - Geometry mesh runs: vertex table writes shadowed while a run is open (DM_NVN_GEO_SHADOW_VT) and a continuation path for draws 2..n of an unchanged run (DM_NVN_GEO_RUN_FAST). - Storage writes: a range already noted this submission returns at once, 64-page and wider ranges go to the interval list (DM_NVN_GW_WIDE), the page hash is cache-line grouped, rc_change remembers its last empty gap. A GPU write still arms main's sparse-pool shadow writeback first. - ARC, thread-locals and stack: arena / uniform / size-table buffers handed back unretained, plain-pointer program and pipeline lookups (PROG_GET, pso_get_v), the replay thread's pool table as a plain global chosen by its thread pointer (pc_tp, mtl_pc_claim), the pool generation read relaxed and fenced only when it moved (pool_gen_cur; ~90,000 LDARs a frame), recorded encoder calls written as C records (RO_R_*), and the large-frame paths of geo_draw and draw_ split into functions of their own (no ___chkstk_darwin on the common path). - The pass split limit is a profile key, pass_split_max (default 2, as before; DM_NVN_PASS_SPLIT_MAX still overrides), and pass_split_try counts why it declines (@psplit_*). Merged with main's own replay work (PR seedds#3239) rather than beside it: the 64 KB pool region table stays and the replay's last-hit entry is looked at before it; main's vertex-stream rule, binding lists, image pool bindings (IMGP), fam_is_valid, tex_fast_rid_meta, fbd_draw_note and the indirect-draw pool note are all kept on the faster paths. Measured step by step on the checkpoint route (M1 Max, scripts/bench.py, 2 runs a variant) on the branch before it was rebased onto main, with PRs seedds#1389 and seedds#1765 under it: replay CPU about 30 -> 22.5 ms a frame over the first round (za notes, binding scans, unretained buffers, mesh draws' blocks), then 8,138 -> 4,028 instructions a draw and 15.8 -> 9.4 ms of submit CPU over the later rounds, the frame at the game's 60 Hz cap (p50 16.7 ms, p99 17.6 ms). Each entry's own figure is in its reference entry. On main, this commit with the others of the branch: see the game note and the PR. Checked: the host builds; make -C dm/gfx/tests GAME=040074A01BF12000 run (MTL_DEBUG_LAYER=1 where the Makefile sets it); dm/tools/tests test_docs.py and test_env_switches.py. The reference entries are in docs/reference/frame-rate.md, one per area above, with a line each in Donkey Kong Bananza's note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nks8VtXWAu8ZQS6PeS1FPv
g8row
added a commit
to g8row/nxnative
that referenced
this pull request
Nov 27, 2026
In a busy view the host's translation of each frame is the frame's critical path: the game waits for an older frame's fence before it records the next. On Donkey Kong Bananza's checkpoint route (a save in a view of about 26,200 draws a frame) the replay thread translated for 14-18 ms a frame after main's per-draw changes, spread thinly over the draw path: no phase of DM_NVN_DRAWPROF above 5 ms, ~8,100 instructions a draw. Profiles of the leaf samples and the hot functions' disassembly found the same few patterns everywhere: answers asked again at every draw that change only at a bind, lookups that miss a single-entry cache, ARC traffic, thread-local reads and stack probes. Every change keeps what is encoded the same and has an off switch for A/B runs. - Diagnostics first: za_note_ formatted its text at every draw past its log limit (a fifth of draw_ in snprintf for one geometry shader whose slots stay 0); now it only counts there. DM_NVN_DRAWPROF=1 gives the replay thread's exclusive time by phase (@dp_<phase>_ms). - Binding scans that find nothing keep that answer with what it was made from (DM_NVN_FB_CACHE, DM_NVN_UBDT_CACHE), on the shader, and a uniform rebind asks again only the bindings that read a uniform slot (DM_NVN_UBSC_PART, DM_NVN_UBD_FAST). These sit on main's per-shader binding lists (sh_tex_list, sh_buf_list). - Argument blocks: after a mesh draw only the geometry stage is encoded again (DM_NVN_GEO_ARGS_KEEP); per-slot pool lookup memos (DM_NVN_CBMEMO, DM_NVN_CBRANGE); uniform-only patches take only the slots that changed, from a compact list (DM_NVN_CB_SLOTGEN, DM_NVN_CB_PATCH_IX); the size table handed out again (DM_NVN_CBSIZE_CACHE); blocks keep their CPU address (ab_cpu); fragment table addresses not written again (DM_NVN_FT_CACHE). - Vertex input: pool-range memos for streams, pulling layouts and index buffers (DM_NVN_VBMEMO), a dirty mask over the vertex table (DM_NVN_VBUF_DIRTY), a pulling layout cache (DM_NVN_PULL_CACHE, keyed by the attribute state, the streams with a buffer and those the shader reads, so main's absent-attribute W=1.0 rule is kept), and an off switch for main's read-streams-only rule (DM_NVN_VB_USED). - Draw state: a dirty bitmask for dynamic state (DM_NVN_DYN_DIRTY), each program's last pipeline (DM_NVN_PSO_PROG_CACHE), per-draw memos in bz_bind, border_need, vbuf_prepare, fb_prepare and udc_note_draw (DM_NVN_DRAW_MEMO); csh_dispatch_ahead no longer reads its 4,096-op scan limit as a dispatch ahead (about 300 needless stops a frame). - Geometry mesh runs: vertex table writes shadowed while a run is open (DM_NVN_GEO_SHADOW_VT) and a continuation path for draws 2..n of an unchanged run (DM_NVN_GEO_RUN_FAST). - Storage writes: a range already noted this submission returns at once, 64-page and wider ranges go to the interval list (DM_NVN_GW_WIDE), the page hash is cache-line grouped, rc_change remembers its last empty gap. A GPU write still arms main's sparse-pool shadow writeback first. - ARC, thread-locals and stack: arena / uniform / size-table buffers handed back unretained, plain-pointer program and pipeline lookups (PROG_GET, pso_get_v), the replay thread's pool table as a plain global chosen by its thread pointer (pc_tp, mtl_pc_claim), the pool generation read relaxed and fenced only when it moved (pool_gen_cur; ~90,000 LDARs a frame), recorded encoder calls written as C records (RO_R_*), and the large-frame paths of geo_draw and draw_ split into functions of their own (no ___chkstk_darwin on the common path). - The pass split limit is a profile key, pass_split_max (default 2, as before; DM_NVN_PASS_SPLIT_MAX still overrides), and pass_split_try counts why it declines (@psplit_*). Merged with main's own replay work (PR seedds#3239) rather than beside it: the 64 KB pool region table stays and the replay's last-hit entry is looked at before it; main's vertex-stream rule, binding lists, image pool bindings (IMGP), fam_is_valid, tex_fast_rid_meta, fbd_draw_note and the indirect-draw pool note are all kept on the faster paths. Measured step by step on the checkpoint route (M1 Max, scripts/bench.py, 2 runs a variant) on the branch before it was rebased onto main, with PRs seedds#1389 and seedds#1765 under it: replay CPU about 30 -> 22.5 ms a frame over the first round (za notes, binding scans, unretained buffers, mesh draws' blocks), then 8,138 -> 4,028 instructions a draw and 15.8 -> 9.4 ms of submit CPU over the later rounds, the frame at the game's 60 Hz cap (p50 16.7 ms, p99 17.6 ms). Each entry's own figure is in its reference entry. On main, this commit with the others of the branch: see the game note and the PR. Checked: the host builds; make -C dm/gfx/tests GAME=040074A01BF12000 run (MTL_DEBUG_LAYER=1 where the Makefile sets it); dm/tools/tests test_docs.py and test_env_switches.py. The reference entries are in docs/reference/frame-rate.md, one per area above, with a line each in Donkey Kong Bananza's note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nks8VtXWAu8ZQS6PeS1FPv
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
Donkey Kong Bananza (
040074A01BF12000, v458752) drops from 60 straight to 30 fps whenever a frame runs a little past one vsync, on Macs whose ProMotion screens could show 40-60 fps.The game has two frame-rate controllers, chosen per frame by what
vi::QueryDisplayVrrSupportedanswered (main+0x2036b0). The fixed-refresh one (main+0x204a18) has only whole present intervals (60, 30 or 20 fps). The VRR one (main+0x204640) asks for 40 to 60 fps in 2 fps steps throughvi::SetLayerExtendedSwapInterval(layer, 1, fps)and leaves VRR for interval 2 below 40. The host answered that the display has no VRR, so only the first ever ran.A new profile key,
vrr on, set for this game only:QueryDisplayVrrSupportedanswers yes on the Mac when the game's window is on a screen of 120 Hz or more (front_screen_max_fps, which follows the window to another screen;hle_vi.c). Docked too, a deliberate difference from the Switch 2, whose VRR is handheld only. iOS never answers VRR, as it is untested there.hle_nvn.cnvn_vrr_set): a period of 1 / fps, no 30 Hz link, and the acquire waits the rate's ticks of a 120 Hz display link with the fractional tick carried, as display mode does above 60 Hz.SetDisplayVrrCapability(false)andClearLayerExtendedSwapIntervalclear it; a frame step page or 120 fps ignore it.DM_VRR=0/1overrides it on the Mac.Reference entry: A Switch 2 game's VRR rate paces presentation; the game note's "What it needs", "Open" and "Found on this game" have it too.
Checked
make -C dm/gfx/tests GAME=040074A01BF12000 run(all pass;t_nvn245 checks, 10 of them new for VRR: the rate replaces the interval and the 30 Hz link, its period at 45 and 60, clamped at 120, cleared back to the interval, ignored with a frame step page),make -C dm/host/tests GAME=040074A01BF12000, and the docs, env switch, game profile, settings, launcher and player env tool tests. The Python lint ratchet: 0 new findings (384 against 384 in the baseline, on b4318c7). Both changed C files compile for iOS. clang-tidy was not run locally; its CI check fails on 9 file/check pairs above the baseline, all in files this change does not touch (dm/gfx/nvn/nvn_mtl.m: BitwiseShift, RetainCount, ArrayBound;dm/gfx/tests/t_depth16_clear.m,t_dlss_mfx.m,t_upscaler_mfx.m: StackAddressEscape;t_feedback.m: signed-char-misuse, RetainCount;t_pso_stall.m: NullablePassedToNonnull). They come from main: the same 9 fail other pull requests' clang-tidy runs today (for examplepr/metal-bracket-depth,pr/mdx-prescan), andhle_nvn.candhle_vi.chave no new findings. The Tool tests check fails on one test this change does not touch,test_dmsh_pool_arrays.pyReflect.test_table_of_uniform_handles(its expected pool index has nodm_pool_mark); it fails the same way on main's tip, e0dc79c.040074A01BF12000v458752 + DLC, packed from a NUP with this branch (--platform mac-app, chain 223f10d34f97). About a minute and a half of play from a save: the game asked for every rate from 40 to 60 fps (about 40 changes, mostly 50-54), left VRR for 30 fps 4 times in heavier moments by its own rule, and ran 29-55 fps a 300-frame window; no shader failures and no red lines. An earlier build of the same change on 975bb4c was played by hand for a few minutes: the picture and the speed looked normal. Not measured: the speed against interval pacing over the same scripted inputs, the same spots without the key, an external screen. The log's on-screen dropped-frame counts still assume a 60 fps target, so a 20 ms VRR frame counts as dropped.regress.py check: not run.regress.py impactlists Breath of the Wild, Pokémon Scarlet and Tears of the Kingdom throughnvnQueuePresentTexture/nvnWindowAcquireTexture, but the new paths act only while a VRR rate is set, which needs the key (only this profile sets it) orDM_VRR=1; none of those games is on this Mac, and Donkey Kong Bananza has no smoke route.Docs
docs/reference/<subsystem>.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)dmsh_chain.py --headerwas run anddm/gfx/nvn/dmsh_chain.his part of the change (no chain tool changed)