Skip to content

GPU: keep PresentX statistics monotonic across concurrent reports - #2769

Open
andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/present-counter-order
Open

andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/present-counter-order

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Two concurrent PresentX calls can report draw and dispatch totals out of order. If a call samples 6 and pauses while another reports 8, subtracting the previous total from 6 panics in a debug build and also moves the saved total backwards. Retain the highest reported total atomically and return a zero delta for a stale snapshot.

The same synthetic test supplies totals [5, 8, 6, 8, 11]. On 13f91ca it panics on the third sample with subtraction overflow. On 63a2edb the deltas are [5, 3, 0, 0, 3], and the saved total is 11. Six paired runs reproduced the result. The serial GPU suite on WARP passed 199 tests with one ignored in both debug settings. Strict GPU Clippy in both feature configurations and asset policy passed.

The exact heads of #1997 and #2666 merge cleanly with this commit. The local composition with #1997 at fdc5ff5 passes the primary-plane fallback, shared texture state restore, compositor build and counter tests. Its full serial GPU suite passed 202 tests with one ignored in both WARP debug settings. Coordination claim

Please retain the Git author on cherry-pick or rebase. If you fold the fix or test into another commit, please add the following trailer.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex. Synthetic test.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and verified 63a2edbe on Windows 11 (RTX 5090 + WARP) against main (13f91ca).

  • Replacing now - last.swap(now, Relaxed) with now.saturating_sub(last.fetch_max(now, Relaxed)) in count_since cleanly prevents concurrent PresentX reports from either rewinding last or panicking on unsigned subtraction underflow in debug builds.
  • RTX 5090 (--features diagnostics, queue::tests, 3 consecutive runs): 3/3 passed (5/5 each run, including stale_present_totals_do_not_move_the_reported_count_back).
  • WARP: queue::tests 3/3 passed (5/5); full victory-gpu --features diagnostics --test-threads=1: 199 passed, 0 failed, 1 ignored.
  • cargo clippy (default & diagnostics): 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent verification of head 63a2edbe (WARP/CPU): looks good.

  • Diff: the present counters now use fetch_max with a saturating subtraction, so a stale snapshot from a descheduled presenter reports 0 and the counter cannot move back (the old now - swap(now) could underflow and panic in debug). The change is small and in scope.
  • Tests: victory-gpu --lib 196 pass, 0 fail (5 reruns, plus 195/195 on origin/main). Clippy -D warnings is clean. One earlier run failed frame::tests::waits_end_on_ticks_and_count_frames, a shared-state test unrelated to this diff (it is already tracked as TEST-FRAME-WAITS). It did not reproduce in 5 full runs and 3 filtered runs.
  • Negative control: with the old now - last.swap(now) semantics put back into count_since, stale_present_totals_do_not_move_the_reported_count_back fails ([5, 3, 18446744073709551614, 2, 3] instead of [5, 3, 0, 0, 3]). The test is sequential, so it models the interleaving rather than running two threads, which is fine for a deterministic check.

Method: WARP/CPU only (no physical GPU; VICTORY_WARP=1, VICTORY_D3D12_WARP=1, Windows SDK dxil.dll on PATH, so DXIL validation ran), cargo test -p <crate> --lib --locked and cargo clippy -p <crate> --all-targets --locked -- -D warnings, compared with origin/main 13f91ca. Nothing from the game was used.

AI-assisted review (Claude Code / Claude Sonnet 5.5).

@kotekompotek

Copy link
Copy Markdown

Correct and minimal: fetch_max + saturating_sub makes the reported deltas monotonic when two presenters race on the same counter (stale snapshot contributes 0 instead of wrapping). The test covers exactly the interleaving that broke it.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In crates/victory-gpu/src/queue.rs (present), the drawn/dispatched deltas for the periodic frame log line now go through count_since, which uses fetch_max and a saturating subtraction. A stale snapshot from a concurrent presenter then reports 0 instead of underflowing (which panics in a debug build) and cannot move the saved total backwards. The change is correct and minimal, and the test covers the out-of-order sequence. Note the value is small: the block only runs when the frame number is a power of two, so the race needs two presenters at frames 1 and 2 at the same moment, and it only affects a log line. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

@Dukestar69 Dukestar69 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 merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • cargo test -p victory-gpu --lib queue::tests: 6 passed, 0 failed (including new stale_present_totals_do_not_move_the_reported_count_back).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed and verified at head 63a2edbe against origin/main (63bcca43) on Windows 11 (RTX 5090 + WARP, D3D12 Debug Layer):

  • Design & correctness: replacing now - last.swap(now, Ordering::Relaxed) with count_since (now.saturating_sub(last.fetch_max(now, Ordering::Relaxed)) in crates/victory-gpu/src/queue.rs:473-476, 511-512) keeps DRAWN and DISPATCHED monotonic across concurrent PresentX reporters, returns 0 for stale snapshots instead of panicking on unsigned underflow in debug builds or wrapping in release builds, and preserves accurate delta sums. The unit test at queue.rs:818-825 directly verifies the out-of-order [5, 8, 6, 8, 11] sequence.
  • Verification:
    • Clean git merge-tree against origin/main (63bcca43); cargo xtask policy (184 files ok); cargo clippy -p victory-gpu --all-targets -- -D warnings clean with default features and --all-features.
    • queue::tests 5/5 passed on all three configurations: RTX 5090 (default), RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics), and WARP (VICTORY_D3D12_WARP=1) + VICTORY_D3D12_DEBUG=1.

LGTM.

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