GPU: make frame pacing tests deterministic with a virtual clock #2875

Open
alexandruiulian201-bot wants to merge 1 commit from upstream-pr/2877 into main
alexandruiulian201-bot commented 2026-11-25 22:56:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexandruiulian201-bot on 2026-11-25T22:56:01Z.


frame::tests::waits_end_on_ticks_and_count_frames can fail on windows-latest CI runners after 9c179ea:

  1. With a 2 ms interval (2_000 us) and Windows' default 15.6 ms timer tick, sleep(wait) routinely oversleeps past the next 2 ms tick. Because 9c179ea allows a wait to take an already-passed tick immediately (wait == 0), the following timeout_ms = 0 poll returns S_OK instead of TIMEOUT.
  2. Scheduling spikes on loaded CI runners can also advance past a 50 ms tick or exceed the < 10 ms elapsed check after std::thread::sleep(Duration::ZERO).
  3. waits_end_on_ticks_and_count_frames and waits_begun_together_take_different_ticks ran in parallel against the same global CLOCK / LAST statics.

Changes

  • Move pacing state into a Pacer struct (static PACER at runtime) with injectable now: Instant and sleep callback so unit tests run deterministically on a virtual clock with isolated state (including explicit coverage of the 9c179ea late zero-timeout poll).
  • Skip std::thread::sleep when the wait or timeout duration is zero, avoiding unnecessary Sleep(0) timeslice yields on zero-timeout origin polls and late flip waits.
  • Keep an FFI smoke test (ffi_entry_points_pace_with_the_global_clock) exercising set_interval and wait on PACER with scheduling-safe margins (10 s timeout / 1 us wait).

Related to #2265; this approach isolates test state into per-test Pacer instances with a virtual clock and also avoids Sleep(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 failed
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features) — 0 warnings
  • cargo test -p xtask --bin xtask --locked — 6 passed, 0 failed (asset policy: 1 files ok)

AI-assisted. Synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5500596177 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877). Originally posted by [alexandruiulian201-bot](https://github.com/alexandruiulian201-bot) on 2026-11-25T22:56:01Z. --- `frame::tests::waits_end_on_ticks_and_count_frames` can fail on `windows-latest` CI runners after `9c179ea`: 1. With a 2 ms interval (`2_000` us) and Windows' default 15.6 ms timer tick, `sleep(wait)` routinely oversleeps past the next 2 ms tick. Because `9c179ea` allows a wait to take an already-passed tick immediately (`wait == 0`), the following `timeout_ms = 0` poll returns `S_OK` instead of `TIMEOUT`. 2. Scheduling spikes on loaded CI runners can also advance past a 50 ms tick or exceed the `< 10 ms` elapsed check after `std::thread::sleep(Duration::ZERO)`. 3. `waits_end_on_ticks_and_count_frames` and `waits_begun_together_take_different_ticks` ran in parallel against the same global `CLOCK` / `LAST` statics. ### Changes - Move pacing state into a `Pacer` struct (`static PACER` at runtime) with injectable `now: Instant` and `sleep` callback so unit tests run deterministically on a virtual clock with isolated state (including explicit coverage of the `9c179ea` late zero-timeout poll). - Skip `std::thread::sleep` when the wait or timeout duration is zero, avoiding unnecessary `Sleep(0)` timeslice yields on zero-timeout origin polls and late flip waits. - Keep an FFI smoke test (`ffi_entry_points_pace_with_the_global_clock`) exercising `set_interval` and `wait` on `PACER` with scheduling-safe margins (10 s timeout / 1 us wait). Related to #2265; this approach isolates test state into per-test `Pacer` instances with a virtual clock and also avoids `Sleep(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 failed - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default and `--all-features`) — 0 warnings - `cargo test -p xtask --bin xtask --locked` — 6 passed, 0 failed (`asset policy: 1 files ok`) AI-assisted. Synthetic tests only.
fuzeofficlal commented 2026-11-25 23:31:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:31:32Z.

Review: COMMENTED


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 injectable now and sleep preserves the production locking, WAITS/frame counters, token writeback, and timeout semantics on static PACER, while also skipping redundant zero-duration thread::sleep calls.
  • Moving timing-sensitive assertions onto local Pacer::new() instances with a virtual clock eliminates OS scheduler jitter while ffi_entry_points_pace_with_the_global_clock still 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.00s each).
  • 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066445734 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#pullrequestreview-6066445734). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:31:32Z. **Review:** COMMENTED --- 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 injectable `now` and `sleep` preserves the production locking, `WAITS`/frame counters, token writeback, and timeout semantics on `static PACER`, while also skipping redundant zero-duration `thread::sleep` calls. - Moving timing-sensitive assertions onto local `Pacer::new()` instances with a virtual clock eliminates OS scheduler jitter while `ffi_entry_points_pace_with_the_global_clock` still 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.00s` each). - `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 commented 2026-11-25 23:36:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:36:34Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066492669 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#pullrequestreview-6066492669). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:36:34Z. **Review:** COMMENTED --- 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.
Marvisak commented 2026-11-26 05:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:26:11Z.


Automated triage for the maintainers.

Merge candidate. The frame clock in frame.rs moves into a Pacer with injectable now and sleep, so unit tests use a virtual clock instead of real sleeps and shared statics; set_interval, next_tick and wait compute the same ticks, and the only behaviour change (no sleep for zero durations) is harmless. #2265 fixes the same flaky test differently and the two conflict; this one removes the timing dependence entirely, so only one should land.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182593245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#issuecomment-7182593245). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:26:11Z. --- <!-- victory-triage v1 head=86162196737a332a4535811cfbf45be4184944a2 verdict=merge-candidate at=2026-11-26T04:26:05Z --> Automated triage for the maintainers. **Merge candidate.** The frame clock in `frame.rs` moves into a `Pacer` with injectable `now` and `sleep`, so unit tests use a virtual clock instead of real sleeps and shared statics; `set_interval`, `next_tick` and `wait` compute the same ticks, and the only behaviour change (no sleep for zero durations) is harmless. #2265 fixes the same flaky test differently and the two conflict; this one removes the timing dependence entirely, so only one should land. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 10:09:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:09:43Z.

Review: APPROVED


Verified against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib frame:: -- --test-threads=1: 3/3 passed in 0.00s (including ffi_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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6072141767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#pullrequestreview-6072141767). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:09:43Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib frame:: -- --test-threads=1`: 3/3 passed in 0.00s (including `ffi_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).
futurepro62 commented 2026-11-26 11:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T10:12:27Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head 8616219 (on its base 842b0cb).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: ffi_entry_points_pace_with_the_global_clock.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7189051786 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#issuecomment-7189051786). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T10:12:27Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head `8616219` (on its base `842b0cb`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `ffi_entry_points_pace_with_the_global_clock`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
ColorMeBoom commented 2026-11-27 16:27:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T16:27:53Z.


The four fixes for the frame::tests flake, measured side by side (#2877, #2265, #2861, #3080), and the open PRs it's holding up.

Setup: Windows 11 26200, Ryzen with 16 logical CPUs, RX 5700 XT (the test is CPU-only), Rust 1.98.1, debug. main 63bcca4, and each PR merged alone onto it at its current head: #2877 8616219, #2265 303be14, #2861 b670296, #3080 5a4f469. Each build's victory-gpu lib test binary was run as <exe> frame::tests:: --test-threads=1, one process per run.

build idle, 200 runs 16 busy threads, 200 runs 16 busy threads, 1,000 interleaved rounds total
main 1 2 3 6 / 1,400, all at frame.rs:231
#2877 0 0 0 0 / 1,400
#2265 0 0 0 0 / 1,400
#2861 0 0 0 0 / 1,400
#3080 0 0 0 0 / 1,400

(In the interleaved rounds, each round ran all five builds once under the same load.)

  • main fails here the way CI does: the zero-time-out poll at frame.rs:231 gets S_OK instead of TIMEOUT. That's about 0.4% of runs on this machine.
  • Each fix: 0 failures in 1,400. At main's rate, 0 in 1,400 by chance is about 0.25%, so each is a real improvement. These numbers can't rank the four against each other. They only show that any one of them stops what CI keeps hitting.

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 descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait (the shared WHILE_PREPARING hook, fixed by #2585, CI green, and by #2861's thread_local!): #1955, #2856, #3031, #3051, #3069, #3149, #3380. Landing one fix for each lets those 15 go green on a re-run, with no change to the PRs themselves.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7223291370 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#issuecomment-7223291370). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T16:27:53Z. --- **The four fixes for the `frame::tests` flake, measured side by side** (#2877, #2265, #2861, #3080), and the open PRs it's holding up. **Setup:** Windows 11 26200, Ryzen with 16 logical CPUs, RX 5700 XT (the test is CPU-only), Rust 1.98.1, debug. `main` `63bcca4`, and each PR merged alone onto it at its current head: #2877 `8616219`, #2265 `303be14`, #2861 `b670296`, #3080 `5a4f469`. Each build's `victory-gpu` lib test binary was run as `<exe> frame::tests:: --test-threads=1`, one process per run. | build | idle, 200 runs | 16 busy threads, 200 runs | 16 busy threads, 1,000 interleaved rounds | total | | --- | --- | --- | --- | --- | | `main` | 1 | 2 | 3 | **6 / 1,400**, all at `frame.rs:231` | | #2877 | 0 | 0 | 0 | 0 / 1,400 | | #2265 | 0 | 0 | 0 | 0 / 1,400 | | #2861 | 0 | 0 | 0 | 0 / 1,400 | | #3080 | 0 | 0 | 0 | 0 / 1,400 | (In the interleaved rounds, each round ran all five builds once under the same load.) - `main` fails here the way CI does: the zero-time-out poll at `frame.rs:231` gets `S_OK` instead of `TIMEOUT`. That's about 0.4% of runs on this machine. - Each fix: 0 failures in 1,400. At `main`'s rate, 0 in 1,400 by chance is about 0.25%, so each is a real improvement. These numbers can't rank the four against each other. They only show that any one of them stops what CI keeps hitting. **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 `descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait` (the shared `WHILE_PREPARING` hook, fixed by #2585, CI green, and by #2861's `thread_local!`): #1955, #2856, #3031, #3051, #3069, #3149, #3380. Landing one fix for each lets those 15 go green on a re-run, with no change to the PRs themselves. AI use: Claude Code (Claude Opus 5.5).
andrewpozdnakov7-jpg commented 2026-11-28 09:45:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T09:45:06Z.


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 [email protected] if folding the branch work into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237441603 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2877#issuecomment-7237441603). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T09:45:06Z. --- Two more Windows CI jobs reached the same frame test failure at line 231 this morning. [#3047](https://github.com/Marvisak/VIctory/actions/runs/46129520686/job/140931409627) passed all 18 game tests first. [#3705](https://github.com/Marvisak/VIctory/actions/runs/46131418745/job/140937184922) 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](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/11ba31dfff0e853e692b3ce504eb9ac878a33b21). 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 <[email protected]> if folding the branch work into another commit. AI-assisted with OpenAI Codex.
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/2877:upstream-pr/2877'
git switch 'upstream-pr/2877'

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/2877'
git switch 'upstream-pr/2877'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2877'
git switch 'upstream-pr/2877'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2877'
git switch 'main'
git merge --squash 'upstream-pr/2877'
git switch 'main'
git merge --ff-only 'upstream-pr/2877'
git switch 'main'
git merge 'upstream-pr/2877'
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!2875
No description provided.