GPU: honour scheduled frame-event offsets #321

Open
github-bot wants to merge 2 commits from github-bot/gh-321 into main AGit
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 02:16 UTC · original
Quat3rnion:victory-frame-offsets → main · +82 −16 · 1 files · 2 commits · open

What

Frame events were treated as happening exactly on the tick: schedule()
discarded the offset the title supplied. This stores the offset per event
kind (origin, vblank, flip) and places each wait at that point within the
next free tick. Offsets of a whole tick or more move the event into a later
tick, and the once-per-tick rule still applies. This is part of the plan's
frame-pacing work for the world path.

It overlaps the next_tick area touched by PR #174, which fixes a separate
race in the same function. The two should be reconciled before merging.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace with PR #112's Linux build fix applied locally (not part of this PR): 166 passed, 0 failed, 3 ignored. Three frame tests cover offsets within and across ticks and the scheduling call.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. No Windows host here.
  • cargo xtask policy passes (150 files ok). No game files or data from them were added.
  • Not tested: a real title or its frame pacing; the new timing helper is tested deterministically.

Checklist

  • Workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.
**@⁠Quat3rnion** on GitHub · 2026-11-24 02:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/321) `Quat3rnion:victory-frame-offsets` → `main` · +82 −16 · 1 files · 2 commits · open ## What Frame events were treated as happening exactly on the tick: `schedule()` discarded the offset the title supplied. This stores the offset per event kind (origin, vblank, flip) and places each wait at that point within the next free tick. Offsets of a whole tick or more move the event into a later tick, and the once-per-tick rule still applies. This is part of the plan's frame-pacing work for the world path. It overlaps the `next_tick` area touched by PR #174, which fixes a separate race in the same function. The two should be reconciled before merging. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace` with PR #112's Linux build fix applied locally (not part of this PR): 166 passed, 0 failed, 3 ignored. Three frame tests cover offsets within and across ticks and the scheduling call. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. No Windows host here. - `cargo xtask policy` passes (150 files ok). No game files or data from them were added. - Not tested: a real title or its frame pacing; the new timing helper is tested deterministically. ## Checklist - [x] Workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
Frame events were treated as happening exactly on the tick; schedule() discarded the offset. Store the offset per event kind and place waits at that point within the next free tick, keeping the once-per-tick rule. Add deterministic tests for offsets spanning a tick and for the scheduling call.
event_after always advanced to the next tick before considering the offset, so a wait between a tick and its offset skipped that tick's still-pending event. Step to the next tick only once its scheduled instant has passed. Addresses the review note on #321.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:10 +00:00
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 03:30 UTC · original

Review note with a small repro (built on main d2a4bae). With a 1 ms period and a 0.3 ms offset, asking for the next event at 1.1 ms returns (2, 1200000): the event of tick 2, 1.2 ms away. The event of tick 1 at 1.3 ms is still ahead at that moment (0.2 ms away) and is skipped; I expected (1, 200000). It looks like event_after advances to the next tick before considering the current tick's offset.

main has no offset handling at all, so this is not a regression, but a title pacing itself by these events would miss one event per period whenever it asks between a tick and that tick's offset.

From a synthetic test only; I have no copy of the title.

**@⁠r4tedx** on GitHub · 2026-11-24 03:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7121159396) Review note with a small repro (built on `main` `d2a4bae`). With a 1 ms period and a 0.3 ms offset, asking for the next event at 1.1 ms returns `(2, 1200000)`: the event of tick 2, 1.2 ms away. The event of tick 1 at 1.3 ms is still ahead at that moment (0.2 ms away) and is skipped; I expected `(1, 200000)`. It looks like `event_after` advances to the next tick before considering the current tick's offset. `main` has no offset handling at all, so this is not a regression, but a title pacing itself by these events would miss one event per period whenever it asks between a tick and that tick's offset. From a synthetic test only; I have no copy of the title.
Author
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 07:30 UTC · original

Rebased on current main. Fixed event_after so a pending event in the current tick is no longer skipped: it steps to the next tick only once the offset instant has passed. Added your 1.1 ms / 0.3 ms case as a regression. New head 3ff5566.

**@⁠Quat3rnion** on GitHub · 2026-11-24 07:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7125059127) Rebased on current main. Fixed event_after so a pending event in the current tick is no longer skipped: it steps to the next tick only once the offset instant has passed. Added your 1.1 ms / 0.3 ms case as a regression. New head 3ff5566.
Author
Owner

@⁠akimfomin on GitHub · 2026-11-24 11:53 UTC · original · edited 2026-11-24 14:40 UTC

PortBridge linked this work to Continued #402. I ran the three existing frame.rs tests from 3ff5566 in a standalone native Windows harness (Rust 1.100.0). All three passed.

I also replayed r4tedx’s case through the Continued FramePacer at d743662: period 1,000 µs, call at 1,100 µs, offset 300 µs. It was pending at 1,299 µs and returned token 1 at 1,300 µs, matching the corrected VIctory timing. Continued rejects an offset of a full period, while #321 carries offsets across ticks. The sub-period case is a shared regression the teams can compare. This is a synthetic timing check. AI-assisted with Codex.

_Originally posted by @⁠akimfomin in #321

Follow-up on combining #321 with #174. I tested Quat3rnion's scheduling at d674d9e2 together with AndyLatimer's tick reservation at 882664e1. A three-way merge from d2a4bae gives two conflicts in next_tick. The resolution keeps event_after and reserves its chosen tick under the existing clock lock only when the delay fits the timeout.

All five standalone frame.rs tests passed on native Windows with Rust 1.100.0, in 40 runs with default test threading and 20 with four threads. At elapsed 11 s with a 10 s period and a 3 s offset, a zero-timeout call leaves tick 101 pending. Two eligible waits then reserve 101 and 102. Removing either the offset or the reservation breaks that test. The tests that modify shared state use a test-only lock. This is a synthetic CPU module check.

Core of the checked change against d674d9e2
-fn next_tick(kind: u32) -> (u64, Duration) {
+fn next_tick(kind: u32, limit: Duration) -> (u64, Duration) {
@@ after event_after, with the clock lock still held
-    (tick, Duration::from_nanos(delay.min(u64::MAX as u128) as u64))
+    let wait = Duration::from_nanos(delay.min(u64::MAX as u128) as u64);
+    if wait <= limit {
+        last(kind).fetch_max(tick, Ordering::Relaxed);
+    }
+    (tick, wait)
@@ wait: calculate the timeout first
-    let (tick, wait) = next_tick(kind);
     let limit = Duration::from_millis(u64::from(timeout_ms));
+    let (tick, wait) = next_tick(kind, limit);
@@ successful wait after sleeping
-        last(kind).fetch_max(tick, Ordering::Relaxed);

PortBridge case PB-0008. AI-assisted with Codex.

**@⁠akimfomin** on GitHub · 2026-11-24 11:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7130689676) · edited 2026-11-24 14:40 UTC [PortBridge](https://github.com/akimfomin/PortBridge) linked this work to [Continued #402](https://github.com/ubiquitarianism/leonida/pull/402). I ran the three existing `frame.rs` tests from `3ff5566` in a standalone native Windows harness (Rust 1.100.0). All three passed. I also replayed r4tedx’s case through the Continued `FramePacer` at `d743662`: period 1,000 µs, call at 1,100 µs, offset 300 µs. It was pending at 1,299 µs and returned token 1 at 1,300 µs, matching the corrected VIctory timing. Continued rejects an offset of a full period, while #321 carries offsets across ticks. The sub-period case is a shared regression the teams can compare. This is a synthetic timing check. AI-assisted with Codex. _Originally posted by @⁠akimfomin in https://git.gtahub.st/github/Marvisak--VIctory/issues/321 **Follow-up on combining #321 with #174.** I tested Quat3rnion's scheduling at `d674d9e2` together with AndyLatimer's tick reservation at `882664e1`. A three-way merge from `d2a4bae` gives two conflicts in `next_tick`. The resolution keeps `event_after` and reserves its chosen tick under the existing clock lock only when the delay fits the timeout. All five standalone `frame.rs` tests passed on native Windows with Rust 1.100.0, in 40 runs with default test threading and 20 with four threads. At elapsed 11 s with a 10 s period and a 3 s offset, a zero-timeout call leaves tick 101 pending. Two eligible waits then reserve 101 and 102. Removing either the offset or the reservation breaks that test. The tests that modify shared state use a test-only lock. This is a synthetic CPU module check. <details> <summary>Core of the checked change against d674d9e2</summary> ```diff -fn next_tick(kind: u32) -> (u64, Duration) { +fn next_tick(kind: u32, limit: Duration) -> (u64, Duration) { @@ after event_after, with the clock lock still held - (tick, Duration::from_nanos(delay.min(u64::MAX as u128) as u64)) + let wait = Duration::from_nanos(delay.min(u64::MAX as u128) as u64); + if wait <= limit { + last(kind).fetch_max(tick, Ordering::Relaxed); + } + (tick, wait) @@ wait: calculate the timeout first - let (tick, wait) = next_tick(kind); let limit = Duration::from_millis(u64::from(timeout_ms)); + let (tick, wait) = next_tick(kind, limit); @@ successful wait after sleeping - last(kind).fetch_max(tick, Ordering::Relaxed); ``` </details> [PortBridge case PB-0008](https://akimfomin.github.io/PortBridge/cases/pb-0008.html). AI-assisted with Codex.
Author
Owner

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

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/frame.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7148592975) · edited 2026-11-25 01:15 UTC <!-- victory-triage v1 head=d674d9e2bbaa3220565b75070be62e6b968012a2 verdict=needs-rebase at=2026-11-25T01:15:53Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/frame.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/321/head:github-bot/gh-321'
git switch 'github-bot/gh-321'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-321'
git switch 'github-bot/gh-321'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-321'
git switch 'github-bot/gh-321'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-321'
git switch 'main'
git merge --squash 'github-bot/gh-321'
git switch 'main'
git merge --ff-only 'github-bot/gh-321'
git switch 'main'
git merge 'github-bot/gh-321'
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!321
No description provided.