GPU: keep PresentX statistics monotonic across concurrent reports #2767

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/2769 into main
andrewpozdnakov7-jpg commented 2026-11-25 20:08:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T20:08:50Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6612779287 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T20:08:50Z. --- 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7173156509) 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.
fuzeofficlal commented 2026-11-25 21:03:14 +00:00 (Migrated from github.com)

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


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173701556 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7173701556). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:27:32Z. --- 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 commented 2026-11-25 21:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:36:19Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173916375 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7173916375). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:36:19Z. --- 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).
kotekompotek commented 2026-11-25 21:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:37:47Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173952852 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7173952852). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:37:47Z. --- 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 2026-11-26 00:03:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:21:55Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177460111 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769#issuecomment-7177460111). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:21:55Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 04:05:29 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6068288167 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769#pullrequestreview-6068288167). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:48:11Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 12:05:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:56:30Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6073721065 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2769#pullrequestreview-6073721065). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T11:56:30Z. **Review:** APPROVED --- 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 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/2769:upstream-pr/2769'
git switch 'upstream-pr/2769'

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