GPU: honour scheduled frame-event offsets #321

Open
Quat3rnion wants to merge 2 commits from upstream-pr/321 into main
Quat3rnion commented 2026-11-24 02:16:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T02:16:45Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5464813002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T02:16:45Z. --- ## 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.
r4tedx commented 2026-11-24 06:55:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:30:15Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121159396 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7121159396). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T03:30:15Z. --- 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.
Quat3rnion commented 2026-11-24 08:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T07:30:03Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125059127 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7125059127). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T07:30:03Z. --- 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 commented 2026-11-24 12:04:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-24T11:53:45Z.


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 https://github.com/Marvisak/VIctory/issues/321#issuecomment-7130689676

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7130689676 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7130689676). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-24T11:53:45Z. --- [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://github.com/Marvisak/VIctory/issues/321#issuecomment-7130689676_ **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.
Marvisak commented 2026-11-25 01:07:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:31:17Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148592975 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7148592975). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:31:17Z. --- <!-- 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)_
DenRakEiw commented 2026-11-25 03:34:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T03:34:00Z.

Review: COMMENTED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6051466877 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321#pullrequestreview-6051466877). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T03:34:00Z. **Review:** COMMENTED --- 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).
cloph-dsp commented 2026-11-27 19:41:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T19:41:07Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7226769870 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/321#issuecomment-7226769870). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T19:41:07Z. --- 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/321:upstream-pr/321'
git switch 'upstream-pr/321'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/321'
git switch 'upstream-pr/321'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/321'
git switch 'upstream-pr/321'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/321'
git switch 'main'
git merge --squash 'upstream-pr/321'
git switch 'main'
git merge --ff-only 'upstream-pr/321'
git switch 'main'
git merge 'upstream-pr/321'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!321
No description provided.