Skip to content

iOS: the host learns the refresh rate of the screen the game's view is on - #590

Closed
oliverames wants to merge 2 commits into
seedds:mainfrom
oliverames:codex/ios-rendering-scene-metrics
Closed

oliverames wants to merge 2 commits into
seedds:mainfrom
oliverames:codex/ios-rendering-scene-metrics

Conversation

@oliverames

@oliverames oliverames commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

On an iPhone or iPad the host doesn't know how fast the screen refreshes. front_screen_max_fps has no definition on iOS, so the graphics layer's weak default answers 0, and the host reads that as a screen below 120 Hz. With DM_FPS_TARGET=120 in a game whose profile has fps_max 120, a 120 Hz iPhone logs 120 fps: cap 0 → 60 fps (the screen is below 120 Hz) and stays at 60, and the display link never counts virtual ticks.

This PR used to move the pixel scale to the view's own screen as well. Main has done that since a5bf542 and e2fadf2, so I've rebuilt the PR on current main as the one thing main still lacks: the rate. The drawableSize rounding is gone too; it's in #1145.

front_ios.m now defines front_screen_max_fps as the maximumFramesPerSecond of the screen the game's view is on, kept in an atomic. The view reads it on the main thread when it joins a window (at the start, and on its move to a TV's window and back) and when its scene's geometry changes, which UIKit also reports when a scene moves to another screen. I left mtl_display_hz alone: it reads UIScreen.mainScreen, but both of its callers only ask whether it's 0.

What changes at run time, all through code that already runs on the Mac:

  • A 120 Hz iPhone or iPad with DM_FPS_TARGET=120 and fps_max 120 gets a cap of 120 and a 120 Hz display link. The launcher still offers 120 on the Mac only, so this takes the switch set by hand. A 60 Hz device keeps the cap of 60.
  • With the picture on a TV, the TV's rate counts. A 60 Hz TV brings the cap back to 60 and unplugging it gives 120 again.
  • A screen whose rate isn't a multiple of the link's (a 144 Hz monitor on an iPad, a 50 Hz TV with the 30 Hz link) gets virtual ticks and the frame step's shown_slack, as on the Mac.
  • Every other game, at 30 or 60, keeps the same display link range. link_sync sets it once more when it first sees the rate.
  • An iPhone with two screens changes rate only if UIKit reports them as two screens of different rates.

The reference entry is An iPhone or iPad tells the host its screen's rate.

Checked

  • Tests: dm/ios/tests/screen_rate_check.m is a small app of the production game view and scene delegate with the host's entry points empty, built by dm/ios/tools/build_screen_rate_check.py (no game files). In the iPhone 18 Pro simulator on iOS 27.3 it passes 6 checks, 0 failed: no rate before the view is in a window, the scene's screen's rate once it is, the rate kept while the view is off every window, read again on its return and on the geometry callback, and the same value on another thread. Its device build compiles. The iOS compile check passes (262 files, 0 failed) and the unsigned iOS app builds and links with synthetic modules. test_docs.py (6) and test_env_switches.py (1) pass. The Python lint ratchet has 0 new findings and clang-tidy has none above the baseline.
  • Games run, with title ID and version: none.
  • Devices and OS: none. Simulator only (iPhone 18 Pro, iOS 27.3, Xcode 27.3), where the screen reports 60 Hz.
  • scripts/regress.py check --games: not run. The engine side is one comment; the change is in the iOS front end, which regress doesn't reach.
  • Not checked: a game at 120 on an iPhone or iPad; a TV or monitor on either, so also what maximumFramesPerSecond says for one and whether the geometry callback comes when an iPad's window goes to another screen; an iPhone with two screens; Low Power Mode, which holds a 120 Hz iPhone's screen to 60.

Rebuilt as one commit on main fd8188c9 on 2026-11-10 (head e65f4fdf).

Front ends

Nothing to act on. A front end that links front_ios.m gets this with it, and one with its own iOS view keeps the weak default of 0 as before.

Docs

  • The finding is in its game note or its docs/reference/<subsystem>.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index). The entry is in docs/reference/frame-rate.md; the earlier rendering.md entry is gone with the scale and rounding work.
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change. Not applicable.
  • No game files, keys or data extracted from a game in the change or the attachments.

@oliverames
oliverames force-pushed the codex/ios-rendering-scene-metrics branch from 0e64322 to 4f83140 Compare October 29, 2026 18:43
@oliverames
oliverames force-pushed the codex/ios-rendering-scene-metrics branch 2 times, most recently from 3bb1a4f to 21987cd Compare October 31, 2026 12:19
@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) ios The iPhone and iPad app (dm/ios) docs Documentation labels Nov 3, 2026
@oliverames
oliverames force-pushed the codex/ios-rendering-scene-metrics branch from 21987cd to ff9bfc3 Compare November 5, 2026 14:49
@oliverames
oliverames force-pushed the codex/ios-rendering-scene-metrics branch 3 times, most recently from ef551be to 40e91f1 Compare November 10, 2026 03:19
… the screen the game's view is on: 120 fps can run on a 120 Hz screen there, and a TV's rate counts while the picture is on it

front_screen_max_fps had no definition on iOS, so the graphics layer's weak default answered 0 there. The host took that as a screen below 120 Hz: with DM_FPS_TARGET=120 in a game whose profile has fps_max 120, the cap stayed at 60 on a 120 Hz iPhone or iPad ("120 fps: cap 0 → 60 fps (the screen is below 120 Hz)"), and the display link never counted virtual ticks. mtl_display_hz reads UIScreen.mainScreen on iOS, but its two callers only ask whether it is 0, so it is left as it is. The pixel scale already comes from the view's own screen (a5bf542, e2fadf2); this does the same for the rate.

front_ios.m now defines front_screen_max_fps: the maximumFramesPerSecond of view.window.windowScene.screen, kept in an atomic. The game's view reads it on the main thread when it joins a window (at the start, and on its move to a TV's window and back) and when its scene's geometry changes (windowScene:didUpdateEffectiveGeometry:, which UIKit also calls when a scene moves to another screen), and logs each change.

What changes at run time, all through code that already runs on the Mac (high_cap_tick and the frame step's shown_slack in hle_nvn.c, link_range and link_sync in nvn_mtl.m):
- A 120 Hz iPhone or iPad with DM_FPS_TARGET=120 and fps_max 120: the cap is 120 and the display link runs at 120 Hz. The launcher still offers 120 on the Mac only, so this takes the switch set by hand. A 60 Hz iPhone or iPad keeps the cap of 60.
- The picture on a TV: the TV's rate counts, so with the 120 above a 60 Hz TV brings the cap back to 60, and unplugging it gives 120 again. The phone's own screen would have said 120 there, and a game that steps by its target would have run at half speed.
- A screen whose rate is not a multiple of the link's (a 144 Hz monitor on an iPad, a 50 Hz TV with the 30 Hz link): virtual ticks and shown_slack, as on the Mac.
- Every other game, at 30 or 60 on a 60 or 120 Hz screen: the same display link range as before, set once more when link_sync first sees the rate or sees it change.
- An iPhone with two screens changes rate only if UIKit reports them as two screens of different rates.

No Front-ends line: a front end that links front_ios.m gets this with it, and one with its own iOS view keeps the weak default of 0 as before.

Checked: dm/ios/tests/screen_rate_check.m, an app of the production game view and scene delegate with the host's entry points empty (tools/build_screen_rate_check.py builds it, no game files), in the iPhone 18 Pro simulator on iOS 27.3: 6 checks, 0 failed (no rate before the view is in a window, the scene's screen's rate once it is, kept while the view is off every window, read again on its return and on the geometry callback, the same on another thread); its device build compiles. The iOS compile check passes (262 files), the unsigned iOS app builds and links with synthetic modules, test_docs (6) and test_env_switches (1) pass, the Python lint ratchet has 0 new findings and clang-tidy none above the baseline. Not run: anything on a device, so no game at 120 on an iPhone or iPad, no TV or monitor on either (nor what maximumFramesPerSecond says for one, nor that the callback comes when an iPad's window goes to another screen), no iPhone with two screens, and Low Power Mode, which holds a 120 Hz iPhone's screen to 60.
@oliverames
oliverames force-pushed the codex/ios-rendering-scene-metrics branch from 40e91f1 to e65f4fd Compare November 10, 2026 13:32
@oliverames oliverames changed the title iOS: derive drawable metrics from the rendering scene iOS: the host learns the refresh rate of the screen the game's view is on Nov 10, 2026
@seedds

seedds commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Design verdict: Superseded by the landed iOS screen-rate implementation; closing.

Should it exist? Yes: the host needs the actual game screen’s rate for its frame cap and timing. Main now implements that contract.

c8744e4f (#2792) provides front_screen_max_fps from the game view’s window scene and updates it as the screen changes. The shared setting availability also filters the 120 Hz option. This replaces the missing weak-default contract addressed here. Closing the duplicate does not add physical ProMotion/TV/multi-screen testing beyond the existing implementation’s own validation.

Review base: 82c354b0.

  • Confidence: High confidence in the source/history comparison; this triage adds no fresh gameplay validation.
  • Binding now / loosest correct: General: host/frontend → host/frontend; screen capability is not game-specific.
  • Root cause or workaround? Root-cause fix: report the screen the game uses, rather than infer it from the simulator or another display.
  • Design from scratch? Yes: retain the current screen/scene lifecycle implementation.
  • Performance impact: None expected from this triage; only a reply/tracker-state update, with no code or shader change.
  • Regression level / games run: Low risk for this action. No games or regression suite run; source, diff, history and discussion review only.
  • Should we just leave it? Yes: we should leave main’s implementation.

@seedds seedds closed this Nov 17, 2026
@oliverames
oliverames deleted the codex/ios-rendering-scene-metrics branch November 28, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants