Skip to content

Frame step: keep what held 60 fps across a 30 fps cap (movies, thermal cap) - #253

Closed
RahulRex0 wants to merge 1 commit into
seedds:mainfrom
RahulRex0:fstep-cap-reference
Closed

RahulRex0 wants to merge 1 commit into
seedds:mainfrom
RahulRex0:fstep-cap-reference

Conversation

@RahulRex0

@RahulRex0 RahulRex0 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

The frame step can get stuck at 30 fps after a 30 fps cap ends. Main has two caps that fall and then rise: Tears of the Kingdom's prerendered movies (the +4 movie flag) and the iOS thermal cap from #220. #220 notes that the way back to 60 hasn't been observed yet.

In both cases, when the cap rose, nvn_fstep_next set the hold back to 1 with no grace while the clocks were still set for 30 fps, so three late frames stepped it straight back up. What kept it at 30 after that differs per cap:

  • After a movie, the cap change had wiped cref (the cost that held hold 1), so the same-cost probe couldn't fire.
  • After the thermal cap, nvn_fgpu's reference had been learned during the cap, at the clock the cap left, so the same work at hold 2 didn't look slowed.

A GPU-bound game whose cost sits near FSTEP_FIT at either hold never triggers the fit trial either, so it stays at 30.

This change keeps cref and the GPU reference per kmin, and it treats the frames after the cap rises as a probe with the usual 30 frames of grace. There's no change to hle_nvn.c.

Keeping cref undoes a choice from b53bb89, which reset it on every cap change (its check "movie flag (kmin 2): the cost that held kmin 1 is dropped" becomes "is set aside"). I think keeping it is safe for the scene after a movie: a kept cref only starts a probe when the cost at hold 2 is within FSTEP_SAME (1.1x) of it, and failed probes back off from 1 s to 8 s like any other probe. The tradeoff is on a device that really can't hold 60 after the cap. The end of the cap now allows up to 30 late frames of grace instead of 3, and if it steps up again soon after, that counts as a failed probe and the hold-off doubles.

I first ran into this with a 30 fps mode in a downstream fork, which main doesn't have. The new t_fstep cases model main's own paths instead, using the movie flag and the BotW iPhone GPU times already quoted in nvn_fstep.h (14.4 ms at hold 1, about 25 ms at hold 2). Built against main's nvn_fstep.h:

  movie ends (kmin 1): the cost that held kmin 1 comes back                    ✗
  a hitch 1 s after a movie: the cost that held hold 1 starts a probe (k 2, at hold 1 0 of the last 600) ✗
thermal cap ends: the probe's grace covers the clock, hold 1 at once and it stays (k 2, 1 steps up after the cap, at hold 1 0 of the last 600) ✗
  the clock takes 1 s: the probe fails, the GPU against hold 1's own reference starts another (k 2, 1 steps up, at hold 1 0 of the last 600) ✗
== 56 checks, 4 failed ==

With the fix all 56 pass, and main's original 51 checks still pass. I also took the parts out one at a time. Without the per-kmin cref, both movie checks fail. Without the per-kmin GPU reference, "the clock takes 1 s" fails and the game stays at 30. Without the cap-rise probe, the thermal case still ends at hold 1, but it dips to 30 once right after the cap. So the first two parts are what get it back to 60, and the probe saves that short dip.

Docs: a new entry in docs/reference/frame-rate.md ("The frame step after a 30 fps cap ends"), and I regenerated the symptom index.

Checked

  • t_fstep 56/56. Host tests, the TSan targets, check_t_thermal thermal-tsan, and the CPU-only gfx tests from tests.yml all pass, and every gfx test compiles.
  • dmhost builds for Wonder, Hades, Digimon, BotW and TOTK. The iOS compile check passes (133 files), and so do the docs tests.
  • Tool tests: 18 of 136 couldn't run because capstone isn't installed here. The rest pass.

🤖 Generated with Claude Code

When the frame-step cap drops to 30 and comes back (Tears of the
Kingdom's prerendered movies, the iOS thermal cap from seedds#220),
nvn_fstep_next put the hold back to 1 with no grace while the clocks
were still set for 30 fps, so three late frames stepped it up again.
After a movie, the cap change had dropped the cost that held hold 1
(cref), so the same-cost probe could not fire. After the thermal cap,
the GPU reference had been learned during the cap, at the clock it
left, so the same work at hold 2 did not look slowed. A GPU-bound game
whose cost sits near the fit line at either hold then stays at 30.

Keep cref and the GPU reference for each kmin, and treat the frames
after the cap rises as a probe with the usual 30 frames of grace. This
undoes b53bb89's reset of cref on a cap change; a kept cref still only
starts a probe when the cost at hold 2 is within FSTEP_SAME of it, and
failed probes back off as before. Add a frame-rate reference entry and
regenerate the symptom index.

I first ran into this with a 30 fps mode in a downstream fork. The new
t_fstep cases model main's own paths instead, using the movie flag and
the BotW iPhone GPU times already quoted in nvn_fstep.h.

Validated: t_fstep 56/56; built against main's nvn_fstep.h, the four
movie and thermal cap checks fail. Host tests, the TSan targets, the
thermal checks, the CPU-only gfx tests, every gfx test compiled, dmhost
for Wonder, Hades, Digimon, BotW and TOTK, the iOS compile check (133
files), and the docs tests pass. Not validated: no game was run on a
Mac or an iPhone, so the clock behaviour after a cap is modelled, not
measured; 18 tool tests that import capstone could not run here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seedds added a commit that referenced this pull request Oct 26, 2026
Keep the proven frame cost and GPU reference for each cap, and probe the
shorter hold when a movie or thermal cap ends. Otherwise a GPU-bound game
can fall straight back to 30 fps without a usable recovery reference.

Save an uninterrupted sustained run when a cap begins, even if no earlier
hitch populated cref. Keep the earlier reference through short runs and
update it after another sustained run. Count cap-release probes and give
them all 30 grace frames: the completed frame at the old cap consumes none.

Add movie and thermal recovery regressions, including first movies,
repeated caps, full grace and failed-probe backoff. Document the mechanism
and link it from both Zelda game notes.

Validated: 64/64 frame-step checks, including ASan/UBSan; six checks fail
against the original PR. Production thermal tests and ThreadSanitizer,
docs tests and diff checks pass; the BotW Mac host builds. Device clock
recovery remains modelled, without a new gameplay observation.

Co-authored-by: RAHUL REX <75500427+RahulRex0@users.noreply.github.com>
@seedds

seedds commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thanks @RahulRex0. Confirmed the recovery failures and incorporated your changes into main in 4acde72, with you credited as co-author.

The per-cap cost/GPU references and cap-release probe are retained. Review also found and fixed two remaining cases:

  • An uninterrupted successful run had not populated cref, so the first movie could still discard the proven cost. Entering a cap now saves a qualifying sustained run; short runs retain the earlier reference.
  • The completed capped frame consumed one recovery grace frame. The probe now gets all 30 frames at the shorter hold and is included in the probe count.

The expanded frame-step suite passes 64/64 checks; six checks fail against the original PR head. ASan/UBSan, the production thermal tests and ThreadSanitizer, docs tests and diff checks pass, and the BotW Mac host builds. The device clock behavior is still modelled; no new iPhone recovery observation is claimed.

Closing this PR because the changes, corrections and regression coverage are now on main.

@seedds seedds closed this Oct 26, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Keep the proven frame cost and GPU reference for each cap, and probe the
shorter hold when a movie or thermal cap ends. Otherwise a GPU-bound game
can fall straight back to 30 fps without a usable recovery reference.

Save an uninterrupted sustained run when a cap begins, even if no earlier
hitch populated cref. Keep the earlier reference through short runs and
update it after another sustained run. Count cap-release probes and give
them all 30 grace frames: the completed frame at the old cap consumes none.

Add movie and thermal recovery regressions, including first movies,
repeated caps, full grace and failed-probe backoff. Document the mechanism
and link it from both Zelda game notes.

Validated: 64/64 frame-step checks, including ASan/UBSan; six checks fail
against the original PR. Production thermal tests and ThreadSanitizer,
docs tests and diff checks pass; the BotW Mac host builds. Device clock
recovery remains modelled, without a new gameplay observation.

Co-authored-by: RAHUL REX <75500427+RahulRex0@users.noreply.github.com>
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.

2 participants