Skip to content

GPU: honour scheduled frame-event offsets - #321

Open
Quat3rnion wants to merge 2 commits into
Marvisak:mainfrom
Quat3rnion:victory-frame-offsets
Open

Quat3rnion wants to merge 2 commits into
Marvisak:mainfrom
Quat3rnion:victory-frame-offsets

Conversation

@Quat3rnion

Copy link
Copy Markdown
Contributor

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 Build: Linux workspace, contributor setup and CI #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.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@ghost ghost mentioned this pull request Nov 24, 2026
Quat3rnion added a commit to Quat3rnion/VIctory that referenced this pull request Nov 24, 2026
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 Marvisak#321.
@Quat3rnion
Quat3rnion force-pushed the victory-frame-offsets branch from 87800db to 3ff5566 Compare November 24, 2026 07:24
@Quat3rnion

Copy link
Copy Markdown
Contributor Author

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.

@akimfomin

akimfomin commented Nov 24, 2026 •

Copy link
Copy Markdown

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 (comment)

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 d674d9e
-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.

Quat3rnion added a commit to Quat3rnion/VIctory that referenced this pull request Nov 24, 2026
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 Marvisak#321.
@Quat3rnion
Quat3rnion force-pushed the victory-frame-offsets branch from 3ff5566 to d674d9e Compare November 24, 2026 14:10

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested PR head directly on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib frame:: — 3 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets — 1 warning: warning: value assigned to 'at' is never read
  • cargo xtask policy — ok
  • Merge status: Currently CONFLICTING with origin/main (940d32f). Please rebase onto main and clear the unused assignment warning on at.

AI-assisted (Gemini 4 Neon).

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 Marvisak#321.
@Quat3rnion
Quat3rnion force-pushed the victory-frame-offsets branch from d674d9e to 0e0013d Compare November 27, 2026 02:46
@cloph-dsp

Copy link
Copy Markdown

Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.

  • PR head: 0e0013d731cb93f8c9ed12a0b46622d994befc82, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Command: cargo test --locked -p victory-gpu --lib -- frame::tests::events_happen_at_their_offset_within_the_tick --exact --test-threads=1 --quiet
  • Result: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 232 filtered out, exit 0.
  • Negative control: git grep -F -c events_happen_at_their_offset_within_the_tick 63bcca43 -- . → exit 1 / 0 hits (test genuinely new); present on PR head.
  • git diff --check 63bcca43 HEAD → exit 0.
  • Caveat: only the named synthetic frame-clock arithmetic test was replayed; no D3D12 device and no full crate suite.
  • GPU/driver: N/A (CPU-only test). No game data, assets, extracted shaders or DRM involved.
  • AI-assisted: Hy4 flash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants