Skip to content

game: Ocarina of Time at 40 fps, frame step in ticks of 1/120 s - #2840

Closed
cagatay-io wants to merge 3 commits into
seedds:mainfrom
cagatay-io:oot-40fps-ticks
Closed

cagatay-io wants to merge 3 commits into
seedds:mainfrom
cagatay-io:oot-40fps-ticks

Conversation

@cagatay-io

@cagatay-io cagatay-io commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2837: this branch's first commit is that PR's commit, and only the second commit belongs here. It extends dm_fps_target_set / dm_fps_target_live (40 while running), the Mac Performance › Frame Rate menu (a 40 item) and that PR's t_fstep / t_nro cases, and does not apply without it.

What and why

The host's frame step hands the game whole 1/60 s vsyncs, so Ocarina of Time runs at 60, 30 or 20 only. On a 120 Hz screen 40 fps (25 ms, three refreshes) is the rate between them. On an iPhone with an A20 Pro the game does not hold 60 on a heavy route and fell to 30 (72 % of frames at 33.3 ms, none at 25), and DM_FPS_TARGET=40 was refused. The game's time hook already takes a ratio; its stub divided the step by 60.

  • Capability FRAME_STEP_120: the ratio stub divides the step by the unit at state +0x38 (120 = ticks of 1/120 s; 0 keeps /60, so every other stub and page stays in vsyncs).
  • loader.c writes the unit at every start and accepts 40 (at start and while running) only for such a stub (dm_fps_40_able); elsewhere 40 holds 30 with a red line.
  • The frame step counts holds in ticks at every cap (2 / 3 / 4 = 60 / 40 / 30); 60 and 30 still move by whole vsyncs, 40 by one tick. The late margin, debt and largest step are scaled to stay the same real time, including main's rate window (over_sum): a 40 that does not hold steps to 30 at the 12th late frame. A movie and the thermal cap still decide over the target.
  • 40 needs a screen at a multiple of 120 Hz and no Low Power Mode (else 30 with one line); at 40 the display link runs at 120 Hz. Main's display link now holds each present for the whole ticks of its period (Present on the Mac: MetalFX scales at the snapshot, and pacing leaves the display link when the screen shifts under it #1045), which covers 25 ms at 40 fps (3 ticks at 120 Hz); this PR's own hold threshold was removed in the merge of main.
  • Settings: settings.tsv offers 40 for fixups:FRAME_STEP_120; the iOS in-game menu and the Mac's Performance › Frame Rate offer it where it applies.
  • Reference entry: Ocarina of Time at 40 fps (new), the game's note.

Checked

  • Tests (M3 Max, macOS 27.0.1, Xcode 27.2): t_fstep 153 / 0, t_nvn 368 / 0, t_link_ticks 70 / 0 + 4 / 0, t_thermal 26 / 0, t_present_hold40 7 / 0 (new); dm/host/tests t_nro OK (the 40 fps loader case); Python: test_frame_ratio_stub (new: the stub at 2 / 3 / 4 ticks, run natively), test_settings, test_launcher_settings, test_fps_target, test_game_profile, test_docs, test_gfx_tests_makefile, test_lint_c, test_lint_python OK; test_env_switches fails as on main (DM_GL_RENDERPROGS); Duo harness on the iPhone 17 Pro Simulator 36 / 1 skipped / 0 failures (with the two link stubs of the Duo harness link fix PR applied temporarily).
  • Games run on this branch: Ocarina of Time 0400486024DEC000 v131072, Mac headless (M3 Max), host from this branch, game files rewritten with a tree on main 2da2c14 that shares this branch's shader chain (82cb7bb335cc), with FRAME_STEP_120 (that tree's render-scale stub in those files stays inert at 1.0), water route, docked, render scale 1.0, Dynamic resolution off:
    • 40 fps, 180 s: frame step in ticks of 1/120 s decided by the host, capped at 40 fps; in the window (100-178 s) all 3,116 frames at 3 ticks, frame p50 / p95 25.00 / 26.05 ms, GPU 22.27 / 23.72 ms, game speed 1.000; the 30 s lines: held … 3 … 1,800 of 1,800, game time 45.00 s in 45.00 s. One step to 4 ticks after the opening movie (3 late frames), back to 3 by a trial 61 presents later.
    • 60 fps, 180 s: all 1,892 frames at 2 ticks, 16.66 / 17.67 ms, GPU 13.37 / 14.50 ms, game speed 1.001. The memory guard stopped this run at 131.9 s (system wired 12.91 GB over its 12.8 GB limit, a whole-machine figure), so its window is 100-131.9 s.
    • Not measured headless: present intervals on screen (headless has no presented times).
  • Devices (earlier base, not this branch): iPhone Duo (A20 Pro, iOS 27.2, 120 Hz), water route, battery, cold start, one run per target, from its TSV (120-595 s): at 60 34.5 frames a second on screen, 27 % / 0 % / 72 % of intervals at 16.7 / 25 / 33.3 ms, thermal state serious at 444 s; at 40 39.4 a second, 0 % / 96.0 % / 3.7 %, game time 1.000 in every summary, never serious. Single runs; run-to-run spread on this phone is large.
  • Not checked: a 120 Hz Mac window or screen (headless only); the Duo on this branch; regress.py check (BotW / TotK keep the vsync ABI: their pages leave +0x38 at 0; no dumps here).

Front ends

Front-ends: new: DM_FPS_TARGET takes 40 for a game whose frame-step stub declares FRAME_STEP_120 (dm_fps_40_able), on a screen at a multiple of 120 Hz.

Docs

  • docs/reference/frame-rate.md entry and the game's note; docs_symptoms.py and docs_patches.py run.
  • Chain tool: not changed (the rewriter's patch_nso.py changed; no shader rebuild).
  • No game files, keys or extracted data.

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) rewriter The NSO rewriter and per-build patches ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) tools Tools and scripts (dm/tools, scripts) docs Documentation game: 0400486024DEC000 A game labels Nov 16, 2026
…DM_CTL fps)

A game whose frame step the host decides through its state page took the
Frame rate setting (DM_FPS_TARGET, 30 or 60) only at start; the iPhone's
in-game menu could not offer it and a Mac app had no way to change it while
playing, though the frame step already changes its cap while the game runs
for a movie or the thermal cap.

loader.c dm_fps_target_set writes 30 or 60 into the page's target while the
game runs (nvn_fstep_target_change; refused for a target of 0, which hands
the stubs back to the game's own interval logic, for a game without a page,
and where an engine frame limit the host writes takes it at the next
start). fps_step_cap reads the page at every present, so the next frame
steps at the new cap and the frame step handles it as a movie's start and
end. dm_fps_target_live tells a front end whether the running game takes a
change at once.

- iOS: the in-game menu offers Frame rate where dm_fps_target_live says it
  applies at once and saves the pick as the settings screen does.
- Mac: a new menu-bar menu, Performance › Frame Rate (60 / 30), in such
  games; disabled with a note elsewhere. The choice holds until the game
  quits; the settings window's choice is the next start's.
- DM_CTL: a line `fps <30|60>` calls dm_fps_target_set as the menu does,
  so a run without a window (scripts/bench.py, a headless host) can measure
  one standing scene at 60 and at 30 in one process.
- Docs: docs/reference/frame-rate.md (new entry), settings.md,
  env_switches.tsv, the Duo harness README.

Checked: t_fstep (60 → 30 → 60 while running, game time = real time; 120,
45 and 0 refused), t_nvn (fps_present_cap, present_itv and nvn_game_fps
follow the page at their next call), dm/host/tests t_nro, t_symbols and
t_hid; the Duo harness on the iPhone 17 Pro Simulator (36 tests, 1 skipped,
0 failures; main's harness needs the two link stubs of the separate
harness PR to link at all); the Mac host builds. A headless Ocarina of Time
run on this branch switched 60 → 30 → 60 → 30 over DM_CTL (numbers in the
PR). The menus themselves were used in play only on an earlier tree.
The host's frame step hands the game whole 1/60 s vsyncs, so Ocarina of
Time can run at 60, 30 or 20 only. On a 120 Hz screen 40 fps (25 ms, three
refreshes) is the rate between them: on the iPhone Duo (A20 Pro) the game
does not hold 60 on a heavy route and fell to 30 (72 % of frames at
33.3 ms, none at 25), and DM_FPS_TARGET=40 was refused. The game's own time
hook already takes a ratio; its stub divided the step by 60.

- patch_nso.py / patches.py: capability FRAME_STEP_120. The ratio stub
  divides the step by the unit at state +0x38: 120 = ticks of 1/120 s; 0
  keeps the division by 60, so every other stub and page stays in vsyncs.
- loader.c writes the unit at every start (fixed for the run) and accepts
  DM_FPS_TARGET=40, and a change to 40 while the game runs, only for such a
  stub (dm_fps_40_able); elsewhere 40 holds 30 with a red line.
- nvn_fstep.h / hle_nvn.c: with the unit the frame step counts holds in
  ticks at every cap: 2 / 3 / 4 for 60 / 40 / 30. Holds at 60 and 30 still
  move by whole vsyncs, at 40 by one tick (3 or 4, never 5). The late
  margin, the debt and the largest step (and the stub's STEP_MAX) are
  scaled so they stay the same real time, including main's rate window
  (over_sum); a 40 that does not hold steps to 30 at the 12th late frame.
  A movie's picture rate and the thermal cap still decide over the target.
- 40 needs a screen at a multiple of 120 Hz and no Low Power Mode, else the
  cap is 30 with one log line; at 40 the display link runs at 120 Hz and
  the acquire waits 3 ticks. nvn_mtl.m holds presents over 20 ms
  (HOLD_PERIOD_MIN, was 25 ms) for their whole period, so a 25 ms frame
  stays three ticks.
- settings.tsv offers 40 for a game with FRAME_STEP_120; the iOS in-game
  menu and the Mac's Performance › Frame Rate offer it where it applies.
- Docs: docs/reference/frame-rate.md (new entry), the game's note,
  settings.md, env_switches.tsv.

Checked: t_fstep 153 checks, t_nvn 368, t_link_ticks 70 + 4, t_thermal 26,
t_present_hold40 7 (new), 0 failed; dm/host/tests t_nro (the 40 fps loader
case) OK; test_frame_ratio_stub (new: the stub at 2 / 3 / 4 ticks, run
natively), test_settings, test_launcher_settings, test_fps_target,
test_game_profile, test_docs, test_gfx_tests_makefile, test_lint_c,
test_lint_python OK; the Duo harness on the iPhone 17 Pro Simulator (36
tests, 1 skipped, 0 failures, with the link stubs of the separate harness
PR). Headless on an M3 Max with this branch's host (numbers in the PR): at
40, 1,800 of 1,800 frames a 30 s line held 3 ticks, frame p50 25.00 ms,
game time 1.000; at 60, frames at 2 ticks, 16.66 ms p50, game time 1.000.
On the iPhone Duo (an earlier base, water route, battery, one run per
target): 39.4 fps delivered at 40, 96 % of intervals at 25 ms, game time
1.000; the camera turns as far at 40 as at 30 and 60. The game needs the
rewriter run again; no shader rebuild of its own.

Front-ends: new: DM_FPS_TARGET takes 40 for a game whose frame-step stub declares FRAME_STEP_120 (dm_fps_40_able), on a screen at a multiple of 120 Hz.
@cagatay-io

Copy link
Copy Markdown
Contributor Author

Rebased onto main 5d54b88. The one conflict was the DM_FPS_TARGET row in dm/games/settings.tsv and its line in docs/settings.md: main now offers 120 fps beyond the Mac; the row keeps main's 120 condition and adds the 40 option. Rerun on the rebased branch: t_fstep 153 checks, 0 failed; t_link_ticks 70 / 0; t_present_hold40 7 / 0; test_settings, test_launcher_settings, test_docs OK; env_switches.py --check reports the same list as main (the ten DM_NVN_* rows and DM_GL_RENDERPROGS).

@gnavarro24

Copy link
Copy Markdown
Contributor

Hi! This branch is based on a main from before commit c70c242 ("ci: repair host and tool test failures on main"). Most of the failing checks here (Host unit tests, Tool tests, clang-tidy, Build check) come from that older base, not from this change.

To pick up the fix, merge the current main into this branch and push:

git fetch origin
git merge origin/main
git push

If the merge has conflicts, ask here if you want help with them.

# Conflicts:
#	dm/gfx/nvn/nvn_mtl.m
#	dm/gfx/tests/Makefile
#	dm/host/dm.h
#	docs/reference/frame-rate.md
@seedds

seedds commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @cagatay-io for the 1/120 s tick design, Ocarina of Time stub, tests, and iPhone/Mac measurements!

This landed standalone on main in 5fc927d (with you credited as co-author), unstacked from #2837 and updated for current main. Alongside the tick-unit frame step and Ocarina of Time 40 fps support, we kept the display link's automatic 120 Hz selection inside the graphics layer, preserved a Mac ProMotion display's native 120 Hz capability across fullscreen mode switches (so 40 fps resumes after a 30 fps movie), hid 40 fps in the iOS launcher on 60 Hz screens and in Low Power Mode, and matched virtual-tick slack to the active link rate.

Checked: host build for Ocarina of Time, iOS launcher Swift type-check, native ARM64 stub tests, loader/settings/docs/lint tests, and graphics frame-step and display-link unit tests (including Metal).

Still open: live in-game 40 fps switching (part of #2837), retesting 40 fps in a window and fullscreen on a 120 Hz Mac and on an iPhone with current main, and the truncating ratio reader at main+0xa682ec.

@seedds seedds closed this Nov 23, 2026
dsi-hub added a commit to dsi-hub/nxnative that referenced this pull request Nov 28, 2026
…'s measured frame time kept

Ocarina of Time's frame-step stub now divides the step by the page's tick unit (state +0x38, 120 for FRAME_STEP_120: 2 / 3 / 4 ticks are 60 / 40 / 30 fps; nxnative main PR seedds#2840) and declares the capability, and still never steps below the measured frame time, which moves to state +0x1c0 / +0x1c4 (FSTEP_FT_OFF, FSTEP_FT_MARK_OFF; +0x38 is main's unit now). The v0 (1.0.0) main gets the frame ratio and the dynamic resolution (main PR seedds#3319's fingerprints, the division at +0x108); its other sites are v131072's fixed addresses, so render scale, wide view and half rate stay v131072's.
Frame rate mode 4, 40 fps (DM_FRAME_MODE: DM_FPS_TARGET 40, hold on, no frame generation), offered on a 120 Hz screen in a build with FRAME_STEP_120 (offeredOptions); the Play panel's tap goes 60 → 40 → 30 there; frame generation on from 40 goes to 30 + frame generation. DM_FPS_TARGET offers 40 as main does. The half-rate request counts the hold in vsyncs (2 * kv), so 40 fps (3 ticks) is not half rate.
test_frame_ratio_stub's tick cases and test_settings' 40 fps case run again and pass; t_fstep 186, t_link_ticks 94, t_nvn 580; the v131072 main rewrites with FRAME_STEP_120, RENDER_SCALE, DYNAMIC_RESOLUTION and HALF_RATE; the iOS Swift sources type-check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400486024DEC000 A game host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) rewriter The NSO rewriter and per-build patches tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants