GPU: keep PresentX statistics monotonic across concurrent reports #2769

Open
github-bot wants to merge 1 commit from github-bot/gh-2769 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 20:08 UTC · original
andrewpozdnakov7-jpg:fix/present-counter-order → main · +19 −3 · 1 files · 1 commits · open

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 [email protected]

AI-assisted with Codex. Synthetic test.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769) `andrewpozdnakov7-jpg:fix/present-counter-order` → `main` · +19 −3 · 1 files · 1 commits · open 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](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) 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 <[email protected]> AI-assisted with Codex. Synthetic test.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:49 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:27 UTC · original

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7173701556) 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`.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:36 UTC · original

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 13f91cae. Nothing from the game was used.

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

**@⁠oni-swr** on GitHub · 2026-11-25 20:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7173916375) 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` 13f91cae. Nothing from the game was used. AI-assisted review (Claude Code / Claude Sonnet 5.5).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:37 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7173952852) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:21 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7177460111) <!-- victory-triage v1 head=63a2edbef1f6c92280ec6ce90a0a3960cb5bfeed verdict=merge-candidate at=2026-11-25T23:22:05Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 03:48 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 03:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769#pullrequestreview-6068288167) · **approved these changes** 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).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 11:56 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2769#pullrequestreview-6073721065) · **approved these changes** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2769/head:github-bot/gh-2769'
git switch 'github-bot/gh-2769'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2769'
git switch 'github-bot/gh-2769'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2769'
git switch 'github-bot/gh-2769'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2769'
git switch 'main'
git merge --squash 'github-bot/gh-2769'
git switch 'main'
git merge --ff-only 'github-bot/gh-2769'
git switch 'main'
git merge 'github-bot/gh-2769'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2769
No description provided.