Repository navigation
GPU: make frame pacing tests deterministic with a virtual clock - #2877
alexandruiulian201-bot wants to merge 1 commit into
Conversation
After 9c179ea, waits_end_on_ticks_and_count_frames can fail on Windows CI when a 2 ms sleep oversleeps past the next tick (causing a zero-timeout poll to return S_OK instead of TIMEOUT), when a 50 ms interval skips a tick under load, or when the two frame tests race on the global CLOCK/LAST statics. Move pacing state into a Pacer struct with injectable Instant and sleep callback so unit tests run deterministically with isolated state, keep a scheduling-safe FFI smoke test on the global pacer, and skip std::thread::sleep when the wait or timeout duration is zero.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head 86162196 cleanly merged onto origin/main (842b0cb7) on Windows 11 x64.
Code Review
- Encapsulating the pacer state into
struct Pacer(const fn new()) with injectablenowandsleeppreserves the production locking,WAITS/frame counters, token writeback, and timeout semantics onstatic PACER, while also skipping redundant zero-durationthread::sleepcalls. - Moving timing-sensitive assertions onto local
Pacer::new()instances with a virtual clock eliminates OS scheduler jitter whileffi_entry_points_pace_with_the_global_clockstill covers the FFI entry points.
Local Verification
cargo test --locked -p victory-gpu --lib frame::tests: 5 consecutive runs, 3/3 passed every run (0.00seach).cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): clean.cargo xtask policy:191 files ok.
Looks clean and ready to merge.
kotekompotek
left a comment
There was a problem hiding this comment.
Sound: the Pacer struct keeps the original semantics (interval restart anchored to the max handed-out tick) while making the clock injectable for deterministic tests — the per-kind last-tick array is what lets origin/vblank/flip waits not starve each other. LGTM.
|
Automated triage for the maintainers. Merge candidate. The frame clock in CI: passing. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified against origin/main (63bcca4):
cargo test -p victory-gpu --lib frame:: -- --test-threads=1: 3/3 passed in 0.00s (includingffi_entry_points_pace_with_the_global_clock).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Cleanly replaces real-time waits in frame pacing unit tests with a deterministic virtual clock.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head Tested
Not tested
AI use
|
Port the virtual-clock frame pacing fix from Marvisak#2877 (8616219). Keep the present conversion fixture typed and shader-readable, and verify its converted pixel. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Port the virtual-clock frame pacing fix from Marvisak#2877 (8616219). Keep the present conversion fixture typed and shader-readable, and verify its converted pixel. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
The four fixes for the Setup: Windows 11 26200, Ryzen with 16 logical CPUs, RX 5700 XT (the test is CPU-only), Rust 1.98.1, debug.
(In the interleaved rounds, each round ran all five builds once under the same load.)
What it's holding up: among the 44 open shader/GPU PRs whose latest CI run failed, these fail on that one test alone and touch no frame code: #148, #1362, #1811, #2348, #2751, #3235, #3454, #3518. Another seven fail only on AI use: Claude Code (Claude Opus 5.5). |
|
Two more Windows CI jobs reached the same frame test failure at line 231 this morning. #3047 passed all 18 game tests first. #3705 passed all nine rectangle tests. Both failed when the zero-timeout poll returned S_OK where the test expected S_FALSE. I combined those two exact heads with this PR at 8616219 in 11ba31d. Git merged all three cleanly. The three frame tests passed in 30 independent processes. The 18 game tests, nine rectangle tests, strict Clippy for both crates and the asset policy passed on that same tree. A maintainer can use this alongside the earlier comparison to decide which timing-test fix to merge. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com if folding the branch work into another commit. AI-assisted with OpenAI Codex. |
frame::tests::waits_end_on_ticks_and_count_framescan fail onwindows-latestCI runners after9c179ea:2_000us) and Windows' default 15.6 ms timer tick,sleep(wait)routinely oversleeps past the next 2 ms tick. Because9c179eaallows a wait to take an already-passed tick immediately (wait == 0), the followingtimeout_ms = 0poll returnsS_OKinstead ofTIMEOUT.< 10 mselapsed check afterstd::thread::sleep(Duration::ZERO).waits_end_on_ticks_and_count_framesandwaits_begun_together_take_different_ticksran in parallel against the same globalCLOCK/LASTstatics.Changes
Pacerstruct (static PACERat runtime) with injectablenow: Instantandsleepcallback so unit tests run deterministically on a virtual clock with isolated state (including explicit coverage of the9c179ealate zero-timeout poll).std::thread::sleepwhen the wait or timeout duration is zero, avoiding unnecessarySleep(0)timeslice yields on zero-timeout origin polls and late flip waits.ffi_entry_points_pace_with_the_global_clock) exercisingset_intervalandwaitonPACERwith scheduling-safe margins (10 s timeout / 1 us wait).Related to #2265; this approach isolates test state into per-test
Pacerinstances with a virtual clock and also avoidsSleep(0)calls on zero-duration waits.Verification
cargo test -p victory-gpu --locked frame::tests— 3 passed, 0 failed (0.00s)cargo test -p victory-gpu --features diagnostics --locked frame::tests— 3 passed, 0 failedcargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default and--all-features) — 0 warningscargo test -p xtask --bin xtask --locked— 6 passed, 0 failed (asset policy: 1 files ok)AI-assisted. Synthetic tests only.