Rebase pending flips when the frame interval changes #1992

Merged
leonida/mandy
lgr123 merged 2 commits from lgr123/frame-interval-pending-vblank into main 2026-11-28 17:55:27 +00:00

Pull request successfully merged and closed

lgr123 commented 2026-11-25 17:37:48 +00:00

Claimed as RT-FRAME-INTERVAL-PENDING-VBLANK.

In a native fake-clock reproduction, changing from 30 to 60 FPS with one old frame still queued placed the next flip at 83,333 µs. The new vblanks were at 56,667, 73,334 and 90,001 µs. The no-pending control displayed at 73,334 µs. Both cases now display at 73,334 µs.

At the interval change, retire flips whose original time already passed, then assign the remaining flips consecutive slots on the rebased grid in FIFO order. The regression asserts that the first retired timestamp is preserved, two pending frames keep their order, and a new frame gets the next slot. This changes rate transitions. The separate mailbox-overflow behavior in #671 is outside the patch. I ran the same reproduction on that branch and it still produced 83,333 µs.

Tested

  • Windows x64, MSVC, native frame_pacer_test. The new test fails with the unchanged header and the full suite passes with the patch.
  • Standalone fake-clock 30-to-60 FPS control and reproduction both reported 73,334 µs with the patch.
  • Rebased onto public main fd33a31, whose pacing and test files are identical to the measured fe15534 base. git diff --check and the source-only policy check passed.
  • This verifies the runtime timing model with synthetic data. No game files or GPU are needed.

GPUs tested: n/a.

AI-assisted: yes.

Checklist

  • Based on current main.
  • One topic.
  • No game data, keys or decryption.

Independent review follow-up

The independent review on an RTX 4060 confirmed the changed-period regression and found that reapplying the same 16,000 µs period moved a frame from 32,000 to 40,000 µs. The follow-up keeps existing flip deadlines on a repeated period while preserving the event epoch update. The new manual-clock check observes the frame at 32,000 µs and the next origin at 40,000 µs. The previous PR head failed the new frame assertion. The native frame-pacer suite passed three runs with the follow-up.

Independent review

Claimed as [RT-FRAME-INTERVAL-PENDING-VBLANK](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7169639524). In a native fake-clock reproduction, changing from 30 to 60 FPS with one old frame still queued placed the next flip at **83,333 µs**. The new vblanks were at **56,667, 73,334 and 90,001 µs**. The no-pending control displayed at 73,334 µs. Both cases now display at 73,334 µs. At the interval change, retire flips whose original time already passed, then assign the remaining flips consecutive slots on the rebased grid in FIFO order. The regression asserts that the first retired timestamp is preserved, two pending frames keep their order, and a new frame gets the next slot. This changes rate transitions. The separate mailbox-overflow behavior in #671 is outside the patch. I ran the same reproduction on that branch and it still produced 83,333 µs. ### Tested - Windows x64, MSVC, native `frame_pacer_test`. The new test fails with the unchanged header and the full suite passes with the patch. - Standalone fake-clock 30-to-60 FPS control and reproduction both reported 73,334 µs with the patch. - Rebased onto public main `fd33a31`, whose pacing and test files are identical to the measured `fe15534` base. `git diff --check` and the source-only policy check passed. - This verifies the runtime timing model with synthetic data. No game files or GPU are needed. GPUs tested: n/a. AI-assisted: yes. ### Checklist - [x] Based on current main. - [x] One topic. - [x] No game data, keys or decryption. ### Independent review follow-up The independent review on an RTX 4060 confirmed the changed-period regression and found that reapplying the same 16,000 µs period moved a frame from 32,000 to 40,000 µs. The follow-up keeps existing flip deadlines on a repeated period while preserving the event epoch update. The new manual-clock check observes the frame at 32,000 µs and the next origin at 40,000 µs. The previous PR head failed the new frame assertion. The native frame-pacer suite passed three runs with the follow-up. [Independent review](https://github.com/ubiquitarianism/leonida/pull/1992#pullrequestreview-6062814451)
MoonEyes reviewed 2026-11-25 18:22:45 +00:00
MoonEyes left a comment
No description provided.
**LGTM**, with one question (not blocking). Setup: Windows 11 Pro 26300, NVIDIA GeForce RTX 4060, driver 610.88, Vulkan SDK 1.4.363.0, MSVC 19.44.35230.0 (VS 2022), CMake 3.31.6 + Ninja, RelWithDebInfo, `-DLEONIDA_REQUIRE_VULKAN=ON`. `main` = `b9320a118`. Only `frame_pacer_test` was built and run (`ctest -R "^frame_pacer$"`). Not run: the whole `ctest` set, any game boot. Head `a14f74c2b`. - PR head: `frame_pacer` Passed (1/1). - `main`: `frame_pacer` Passed (1/1). - PR merged into `main` locally (no conflict): Passed (1/1). - Mutant (PR test, `runtime/src/frame_pacer.h` of `main`): Failed, `line 346: displayed_at(second) == new_epoch + new_period`. So the new block does catch the old behaviour; the first assertion (the retired frame keeps its timestamp) passes on `main` too, which is expected. Question: `set_frame_interval` now moves the queued flips on every call, not only when the period changes. I measured it with a local probe (not part of the PR): period 16000 us, one frame queued for 32000 us, a second `set_frame_interval(16000, 3, 0)` at 24000 us. On `main` the frame is displayed at 32000 us, with this PR at 40000 us. 40000 is the first vblank of the re-based grid, so it is consistent with the PR's rule, but a title that repeats `SetFrameIntervalX` with an unchanged interval would see queued frames slip. Is that intended, or should an unchanged period leave the queue alone? A test case for it would settle it either way. AI-assisted: yes (Claude Code built and ran the tests)
zmasi commented 2026-11-28 13:07:20 +00:00

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main d48a957bb + 61c3421875 (claim #2570#issuecomment-7239583640):

  • Line-by-line diff audit: Clean (runtime/src/frame_pacer.h, runtime/test/frame_pacer_test.cpp); retires already-displayed frames at now and assigns remaining queued frames consecutive vblank deadlines on the new grid whenever FramePacer::set_frame_interval changes period_us, while keeping queued display deadlines intact when reapplying the same period. check_no_game_data.py clean.
  • Red (d48a957bb + PR test): frame_pacer_test.exe fails (rc=1, line 346: displayed_at(second) == new_epoch + new_period).
  • Green (d48a957bb + 61c3421875 merge): Auto-merges cleanly (rc=0), compiles with 0 warnings under /W4 /permissive-, and passes (frame_pacer_test: all cases pass, rc=0).

AI-assisted.

Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `d48a957bb` + `61c3421875` (claim `#2570#issuecomment-7239583640`): - **Line-by-line diff audit**: Clean (`runtime/src/frame_pacer.h`, `runtime/test/frame_pacer_test.cpp`); retires already-displayed frames at `now` and assigns remaining queued frames consecutive vblank deadlines on the new grid whenever `FramePacer::set_frame_interval` changes `period_us`, while keeping queued display deadlines intact when reapplying the same period. `check_no_game_data.py` clean. - **Red (`d48a957bb` + PR test)**: `frame_pacer_test.exe` fails (`rc=1`, `line 346: displayed_at(second) == new_epoch + new_period`). - **Green (`d48a957bb` + `61c3421875` merge)**: Auto-merges cleanly (`rc=0`), compiles with `0` warnings under `/W4 /permissive-`, and passes (`frame_pacer_test: all cases pass`, `rc=0`). AI-assisted.
MoonEyes commented 2026-11-28 17:55:24 +00:00

Red/green: On main frame_pacer_test fails at line 451 (pending flips are not rebased when the frame interval changes), and with the PR ctest -R "^frame_pacer$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

Red/green: On main frame_pacer_test fails at line 451 (pending flips are not rebased when the frame interval changes), and with the PR ctest -R "^frame_pacer$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:57:35 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head 61c342187; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: ctest -R ^frame_pacer$
  • Red on main: 1 failure (line 451: displayed_at(second) != new_epoch + new_period)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `61c342187`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `ctest -R ^frame_pacer$` - Red on main: 1 failure (line 451: displayed_at(second) != new_epoch + new_period) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.