GPU: end a late flip wait on the tick it missed, not the next #319

Open
github-bot wants to merge 1 commit from github-bot/gh-319 into main AGit
Owner

@⁠xmvo on GitHub · 2026-11-24 02:16 UTC · original
xmvo:gpu/late-flip-waits → main · +28 −2 · 1 files · 1 commits · open

What

frame::next_tick always returned the next tick after now. When a frame took a little longer than one interval, its flip wait started just after the tick it should have flipped on, and so waited for the whole following interval. Frame times rounded up to whole intervals: at a 33.3 ms interval, a 40 ms frame was shown at 66.7 ms (30 fps falling straight to 15, then 10).

Now a non-origin wait (flip, vblank) that begins after a tick nobody has taken yet ends immediately, on that tick. A late frame costs only its own lateness:

  • 40 ms of work: about 25 fps instead of 15,
  • on-time frames still wait for their tick, so the rate never exceeds the interval,
  • each tick is still taken once (last(kind) advances to it),
  • origin waits are unchanged, so the title's "token on time-out" origin poll behaves as before.

Why

A user on slower hardware saw menus at 15 fps and frame times clustered at exactly 66/100 ms, which matches this rounding.

Testing

  • cargo test -p victory-gpu frame: passes, with a new case added to waits_end_on_ticks_and_count_frames: a flip wait begun 25 ms after a flip at a 20 ms interval returns at once, on the next tick.
  • Not yet measured in the title. A before/after fps reading on a machine whose menus run below 30 would confirm the gain.

Open to gating this behind a flag if you'd rather keep strict tick pacing by default.

**@⁠xmvo** on GitHub · 2026-11-24 02:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/319) `xmvo:gpu/late-flip-waits` → `main` · +28 −2 · 1 files · 1 commits · open ## What `frame::next_tick` always returned the next tick after now. When a frame took a little longer than one interval, its flip wait started just after the tick it should have flipped on, and so waited for the whole following interval. Frame times rounded up to whole intervals: at a 33.3 ms interval, a 40 ms frame was shown at 66.7 ms (30 fps falling straight to 15, then 10). Now a non-origin wait (flip, vblank) that begins after a tick nobody has taken yet ends immediately, on that tick. A late frame costs only its own lateness: - 40 ms of work: about 25 fps instead of 15, - on-time frames still wait for their tick, so the rate never exceeds the interval, - each tick is still taken once (`last(kind)` advances to it), - origin waits are unchanged, so the title's "token on time-out" origin poll behaves as before. ## Why A user on slower hardware saw menus at 15 fps and frame times clustered at exactly 66/100 ms, which matches this rounding. ## Testing - `cargo test -p victory-gpu frame`: passes, with a new case added to `waits_end_on_ticks_and_count_frames`: a flip wait begun 25 ms after a flip at a 20 ms interval returns at once, on the next tick. - **Not yet measured** in the title. A before/after fps reading on a machine whose menus run below 30 would confirm the gain. Open to gating this behind a flag if you'd rather keep strict tick pacing by default.
A flip (or vblank) wait always ended on the next tick after now. A frame
that took a little longer than an interval therefore waited for the
whole following interval: at 30 fps, a 40 ms frame was shown after
66 ms, and frame times rounded up to whole intervals (30 fps falling
straight to 15, then 10). A non-origin wait that begins after a tick
nobody has taken now ends at once on that tick; on-time frames are
paced as before. Origin waits are unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:07 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:20 UTC · original

Tested PR #319 at head b36bd4c1d655f4d2f2069e4369a402a2828091e2 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at b36bd4c1d655f4d2f2069e4369a402a2828091e2.

  • cargo test --locked -p victory-gpu frame::tests — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 43 filtered out; finished in 0.07s ); cases: frame::tests::waits_end_on_ticks_and_count_frames.

Behavior covered: Checks the frame timing tests for late flip waits ending on the missed tick instead of waiting another interval.
Code: crates/victory-gpu/src/frame.rs

**@⁠jeremygold02** on GitHub · 2026-11-24 04:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7121925187) Tested PR #319 at head `b36bd4c1d655f4d2f2069e4369a402a2828091e2` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `b36bd4c1d655f4d2f2069e4369a402a2828091e2`. - `cargo test --locked -p victory-gpu frame::tests` — passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 43 filtered out; finished in 0.07s ); cases: frame::tests::waits_end_on_ticks_and_count_frames. Behavior covered: Checks the frame timing tests for late flip waits ending on the missed tick instead of waiting another interval. Code: [crates/victory-gpu/src/frame.rs](https://github.com/Marvisak/VIctory/blob/b36bd4c1d655f4d2f2069e4369a402a2828091e2/crates/victory-gpu/src/frame.rs)
Author
Owner

@⁠etcetera-yt on GitHub · 2026-11-24 05:36 UTC · original

Each PR passes on its own; merged together on main (d2a4bae), the frame-wait test fails:

main + #319:        frame::tests::waits_end_on_ticks_and_count_frames ... ok
main + #174 + #319: frame::tests::waits_end_on_ticks_and_count_frames ... FAILED
  crates\victory-gpu\src\frame.rs:252:9  left: 10  right: 11

Both change when a frame wait ends: #174 takes the wait's tick before it sleeps, #319 ends a late flip wait on
the tick it missed rather than the next. Together a frame is counted one tick short. Whichever lands second
probably needs to rebase its tick accounting (and the test's expected count) on the other.

Merged with plain git merge, no text conflict. Windows 10 19045, RTX 5060 Ti, Rust 1.98.1,
cargo test -p victory-gpu -- --test-threads=4 waits_end.

AI use: Claude Code, Claude Opus 5.5.

On a title (added after a local run)

With #174 and #319 both merged (plus #175 for Windows 10), the title never left its first black screen and the
host presented about 1,100 frames per second at 3 draws per frame. The same build with only #319 reverted runs at
30.0 fps and reaches the start screen. (RTX 5060 Ti, driver 621.14, Windows 10 19045, release build.)

**@⁠etcetera-yt** on GitHub · 2026-11-24 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7123106351) Each PR passes on its own; merged together on `main` (`d2a4bae`), the frame-wait test fails: ``` main + #319: frame::tests::waits_end_on_ticks_and_count_frames ... ok main + #174 + #319: frame::tests::waits_end_on_ticks_and_count_frames ... FAILED crates\victory-gpu\src\frame.rs:252:9 left: 10 right: 11 ``` Both change when a frame wait ends: #174 takes the wait's tick before it sleeps, #319 ends a late flip wait on the tick it missed rather than the next. Together a frame is counted one tick short. Whichever lands second probably needs to rebase its tick accounting (and the test's expected count) on the other. Merged with plain `git merge`, no text conflict. Windows 10 19045, RTX 5060 Ti, Rust 1.98.1, `cargo test -p victory-gpu -- --test-threads=4 waits_end`. AI use: Claude Code, Claude Opus 5.5. ## On a title (added after a local run) With #174 and #319 both merged (plus #175 for Windows 10), the title never left its first black screen and the host presented about 1,100 frames per second at 3 draws per frame. The same build with only #319 reverted runs at 30.0 fps and reaches the start screen. (RTX 5060 Ti, driver 621.14, Windows 10 19045, release build.)
Author
Owner

@⁠KevinPratap on GitHub · 2026-11-24 07:18 UTC · original

A fix for the clash with #174 reported above. With #174, a wait takes its tick inside next_tick (before it sleeps) instead of after, so this PR's late-flip early return has to take its tick there too; otherwise nobody records it and the next flip ends on the same tick again:

     if kind != ORIGIN && passed > last_tick && passed > c.first {
+        // Taken now, as any wait takes its tick before it would sleep.
+        last(kind).fetch_max(passed, Ordering::Relaxed);
         return (passed, Duration::ZERO);
     }

Verified on main (d2a4bae) + #174 (810f442) + #319 (b36bd4c), Windows 11:

before:  cargo test -p victory-gpu --lib frame::   1 passed; 1 failed (waits_end_on_ticks_and_count_frames)
after:   cargo test -p victory-gpu --lib frame::   2 passed; 0 failed

On this branch alone the line is harmless (the caller's later fetch_max takes the same tick), so it can go into whichever of the two lands second. AI-assisted.

**@⁠KevinPratap** on GitHub · 2026-11-24 07:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7124840531) A fix for the clash with #174 reported above. With #174, a wait takes its tick inside `next_tick` (before it sleeps) instead of after, so this PR's late-flip early return has to take its tick there too; otherwise nobody records it and the next flip ends on the same tick again: ```diff if kind != ORIGIN && passed > last_tick && passed > c.first { + // Taken now, as any wait takes its tick before it would sleep. + last(kind).fetch_max(passed, Ordering::Relaxed); return (passed, Duration::ZERO); } ``` Verified on `main` (`d2a4bae`) + #174 (`810f442`) + #319 (`b36bd4c`), Windows 11: ``` before: cargo test -p victory-gpu --lib frame:: 1 passed; 1 failed (waits_end_on_ticks_and_count_frames) after: cargo test -p victory-gpu --lib frame:: 2 passed; 0 failed ``` On this branch alone the line is harmless (the caller's later `fetch_max` takes the same tick), so it can go into whichever of the two lands second. AI-assisted.
Author
Owner

@⁠mercuryVM on GitHub · 2026-11-24 08:26 UTC · original

Heads-up: #174 changes next_tick so the tick is taken inside it rather than in wait. With both PRs applied, this PR's early-return branch never takes its tick, and frame::tests::waits_end_on_ticks_and_count_frames fails at the LAST == flipped + 1 check (verified by merging both). Whichever lands second should add last(kind).fetch_max(passed, Ordering::Relaxed); before the early return (passed, Duration::ZERO). Details are in my review on #174.

AI-assisted (Claude Code).

**@⁠mercuryVM** on GitHub · 2026-11-24 08:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7126146238) Heads-up: #174 changes `next_tick` so the tick is taken inside it rather than in `wait`. With both PRs applied, this PR's early-return branch never takes its tick, and `frame::tests::waits_end_on_ticks_and_count_frames` fails at the `LAST == flipped + 1` check (verified by merging both). Whichever lands second should add `last(kind).fetch_max(passed, Ordering::Relaxed);` before the early `return (passed, Duration::ZERO)`. Details are in my review on #174. AI-assisted (Claude Code).
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 18:45 UTC · original

Heads-up: #319 (b36bd4c1) and #174 (882664e1) each pass on main, but merged together frame::tests::waits_end_on_ticks_and_count_frames fails on every run (left: 10, right: 11 at frame.rs:254).

#174 moves taking the tick (last(kind).fetch_max) into next_tick. #319 adds an early return (passed, Duration::ZERO) for a late flip wait, before that point, so the late wait's tick is never taken. Taking it in the early return too fixes it. The tests pass (710 in the merge train):

if kind != ORIGIN && passed > last_tick && passed > c.first {
    last(kind).fetch_max(passed, Ordering::Relaxed);
    return (passed, Duration::ZERO);
}

Whichever of the two lands second needs this. It is in e3f72c57 on the train branch.

**@⁠alexdeliu** on GitHub · 2026-11-24 18:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7141115637) Heads-up: #319 (`b36bd4c1`) and #174 (`882664e1`) each pass on `main`, but merged together `frame::tests::waits_end_on_ticks_and_count_frames` fails on every run (`left: 10, right: 11` at `frame.rs:254`). #174 moves taking the tick (`last(kind).fetch_max`) into `next_tick`. #319 adds an early `return (passed, Duration::ZERO)` for a late flip wait, before that point, so the late wait's tick is never taken. Taking it in the early return too fixes it. The tests pass (710 in the merge train): ```rust if kind != ORIGIN && passed > last_tick && passed > c.first { last(kind).fetch_max(passed, Ordering::Relaxed); return (passed, Duration::ZERO); } ``` Whichever of the two lands second needs this. It is in [`e3f72c57`](https://github.com/alexdeliu/VIctory/commit/e3f72c5768173be7a1cf44ceaecffc3a685d6b56) on the train branch.
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 20:31 UTC · original

The clash is real on this head, and here is a patch that fixes it

Chasing TEST-FRAME-WAITS in #1633 (find which pull request this test combines badly with) landed on this pair, and the answer is #174 — as @⁠etcetera-yt, @⁠mercuryVM, @⁠KevinPratap and @⁠alexdeliu already reported above. What I can add is the measured form and a fix that I ran.

Reproduction, on the forge train (KevinPratap/VIctory forge/main, which merges #174 as 5c8275a and this pull request as 07a6fc0, so its tree is ffe310e + #174 + #319):

$ cargo test -p victory-gpu --locked waits_end_on_ticks_and_count_frames
panicked at crates\victory-gpu\src\frame.rs:254:
assertion `left == right` failed
  left: 8
 right: 9

Ten runs out of ten, so it is not the test's timing being flaky. The same command at ffe310e passes five out of five, and at 07a6fc0 fails five out of five: this pull request's merge in forge already carries #174, and the clash appears there.

Why. #174 moves the "take the tick" from wait() into next_tick(). This pull request's late-flip early return

    if kind != ORIGIN && passed > last_tick && passed > c.first {
        return (passed, Duration::ZERO);
    }

returns before that, so a wait that ends on the tick it missed never records it, LAST[2] stays where it was, and the assertion this pull request adds (LAST[2] == flipped + 1) fails with 8 against 9. The pull request's own doc comment already says what should happen: "A wait that comes within limit takes the tick here, under the clock's lock, so two threads waiting for one kind never take the same tick."

Patch (against b36bd4c1, the current head, in crates/victory-gpu/src/frame.rs):

     if kind != ORIGIN && passed > last_tick && passed > c.first {
+        // Taken here as the blocking path does: the wait that ends on this
+        // tick is the one that counted it.
+        last(kind).fetch_max(passed, Ordering::Relaxed);
         return (passed, Duration::ZERO);
     }

Verified with it applied:

  • waits_end_on_ticks_and_count_frames → 5 passes out of 5 (0 out of 5 without it).
  • waits_begun_together_take_different_ticks, the other test this pull request adds → still passes.
  • cargo test -p victory-gpu --locked on the patched forge tree → 88 passed, 0 failed, 3 ignored.

The two waits that begin together still take different ticks, because the blocking path takes its tick under the same lock; only the late path, which returned without taking one, changes.

No game data is involved; this is a unit test of the frame clock.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 20:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7143683245) **The clash is real on this head, and here is a patch that fixes it** Chasing `TEST-FRAME-WAITS` in #1633 (find which pull request this test combines badly with) landed on this pair, and the answer is #174 — as @⁠etcetera-yt, @⁠mercuryVM, @⁠KevinPratap and @⁠alexdeliu already reported above. What I can add is the measured form and a fix that I ran. **Reproduction, on the forge train** (`KevinPratap/VIctory` `forge/main`, which merges #174 as `5c8275a` and this pull request as `07a6fc0`, so its tree is `ffe310e` + #174 + #319): ``` $ cargo test -p victory-gpu --locked waits_end_on_ticks_and_count_frames panicked at crates\victory-gpu\src\frame.rs:254: assertion `left == right` failed left: 8 right: 9 ``` Ten runs out of ten, so it is not the test's timing being flaky. The same command at `ffe310e` passes five out of five, and at `07a6fc0` fails five out of five: this pull request's merge in forge already carries #174, and the clash appears there. **Why.** #174 moves the "take the tick" from `wait()` into `next_tick()`. This pull request's late-flip early return ```rust if kind != ORIGIN && passed > last_tick && passed > c.first { return (passed, Duration::ZERO); } ``` returns before that, so a wait that ends on the tick it missed never records it, `LAST[2]` stays where it was, and the assertion this pull request adds (`LAST[2] == flipped + 1`) fails with `8` against `9`. The pull request's own doc comment already says what should happen: *"A wait that comes within `limit` takes the tick here, under the clock's lock, so two threads waiting for one kind never take the same tick."* **Patch** (against `b36bd4c1`, the current head, in `crates/victory-gpu/src/frame.rs`): ```diff if kind != ORIGIN && passed > last_tick && passed > c.first { + // Taken here as the blocking path does: the wait that ends on this + // tick is the one that counted it. + last(kind).fetch_max(passed, Ordering::Relaxed); return (passed, Duration::ZERO); } ``` **Verified with it applied:** - `waits_end_on_ticks_and_count_frames` → 5 passes out of 5 (0 out of 5 without it). - `waits_begun_together_take_different_ticks`, the other test this pull request adds → still passes. - `cargo test -p victory-gpu --locked` on the patched forge tree → **88 passed, 0 failed, 3 ignored**. The two waits that begin together still take different ticks, because the blocking path takes its tick under the same lock; only the late path, which returned without taking one, changes. No game data is involved; this is a unit test of the frame clock. Written with an AI assistant.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:31 UTC · original · edited 2026-11-25 15:56 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/frame.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7148588708) · edited 2026-11-25 15:56 UTC <!-- victory-triage v1 head=b36bd4c1d655f4d2f2069e4369a402a2828091e2 verdict=needs-rebase at=2026-11-25T15:56:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/frame.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠oddmaniv on GitHub · 2026-11-25 11:42 UTC · original

Additional synthetic-clock regression coverage tested against this PR at b36bd4c1d655f4d2f2069e4369a402a2828091e2 checks multi-tick late flip/vblank waits, future origin waits, and that consumed ticks are not reused. The added test runs in an isolated process and leaves this PR's production code unchanged.

The new regression fails on unchanged main (tick 106 instead of 105) and passes with this PR. Both frame tests passed together twice; workspace Clippy with and without all features, changed-file formatting and asset policy passed on the test-instrumented PR checkout, on Windows with Rust/Cargo 1.98.1.

This is additional regression coverage, not evidence of console late-flip behaviour, gameplay performance, or resolution of the #174 interaction. No full workspace suite, game or GPU execution was performed. AI-assisted.

**@⁠oddmaniv** on GitHub · 2026-11-25 11:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/319#issuecomment-7161392177) Additional synthetic-clock regression coverage tested against this PR at `b36bd4c1d655f4d2f2069e4369a402a2828091e2` checks multi-tick late flip/vblank waits, future origin waits, and that consumed ticks are not reused. The added test runs in an isolated process and leaves this PR's production code unchanged. The new regression fails on unchanged main (tick 106 instead of 105) and passes with this PR. Both frame tests passed together twice; workspace Clippy with and without all features, changed-file formatting and asset policy passed on the test-instrumented PR checkout, on Windows with Rust/Cargo 1.98.1. This is additional regression coverage, not evidence of console late-flip behaviour, gameplay performance, or resolution of the #174 interaction. No full workspace suite, game or GPU execution was performed. AI-assisted.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/frame.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/319/head:github-bot/gh-319'
git switch 'github-bot/gh-319'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-319'
git switch 'github-bot/gh-319'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-319'
git switch 'github-bot/gh-319'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-319'
git switch 'main'
git merge --squash 'github-bot/gh-319'
git switch 'main'
git merge --ff-only 'github-bot/gh-319'
git switch 'main'
git merge 'github-bot/gh-319'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!319
No description provided.