GPU: keep PresentX statistics monotonic across concurrent reports #2769
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2769
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2769"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 20:08 UTC · original
andrewpozdnakov7-jpg:fix/present-counter-order→main· +19 −3 · 1 files · 1 commits · openTwo 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
13f91cait panics on the third sample with subtraction overflow. On63a2edbthe 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
fdc5ff5passes 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 claimPlease 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 on GitHub · 2026-11-25 20:27 UTC · original
Reviewed and verified
63a2edbeon Windows 11 (RTX 5090 + WARP) againstmain(13f91ca).now - last.swap(now, Relaxed)withnow.saturating_sub(last.fetch_max(now, Relaxed))incount_sincecleanly prevents concurrentPresentXreports from either rewindinglastor panicking on unsigned subtraction underflow in debug builds.--features diagnostics,queue::tests, 3 consecutive runs): 3/3 passed (5/5each run, includingstale_present_totals_do_not_move_the_reported_count_back).queue::tests3/3 passed (5/5); fullvictory-gpu --features diagnostics --test-threads=1: 199 passed, 0 failed, 1 ignored.cargo clippy(default &diagnostics): 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treevs13f91ca.@oni-swr on GitHub · 2026-11-25 20:36 UTC · original
Independent verification of head
63a2edbe(WARP/CPU): looks good.fetch_maxwith a saturating subtraction, so a stale snapshot from a descheduled presenter reports 0 and the counter cannot move back (the oldnow - swap(now)could underflow and panic in debug). The change is small and in scope.victory-gpu --lib196 pass, 0 fail (5 reruns, plus 195/195 onorigin/main). Clippy-D warningsis clean. One earlier run failedframe::tests::waits_end_on_ticks_and_count_frames, a shared-state test unrelated to this diff (it is already tracked asTEST-FRAME-WAITS). It did not reproduce in 5 full runs and 3 filtered runs.now - last.swap(now)semantics put back intocount_since,stale_present_totals_do_not_move_the_reported_count_backfails ([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 SDKdxil.dllon PATH, so DXIL validation ran),cargo test -p <crate> --lib --lockedandcargo clippy -p <crate> --all-targets --locked -- -D warnings, compared withorigin/main13f91cae. Nothing from the game was used.AI-assisted review (Claude Code / Claude Sonnet 5.5).
@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.
@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 throughcount_since, which usesfetch_maxand 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 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 newstale_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 on GitHub · 2026-11-26 11:56 UTC · original · approved these changes
Reviewed and verified at head
63a2edbeagainstorigin/main(63bcca43) on Windows 11 (RTX 5090 + WARP, D3D12 Debug Layer):now - last.swap(now, Ordering::Relaxed)withcount_since(now.saturating_sub(last.fetch_max(now, Ordering::Relaxed))incrates/victory-gpu/src/queue.rs:473-476, 511-512) keepsDRAWNandDISPATCHEDmonotonic across concurrentPresentXreporters, returns0for stale snapshots instead of panicking on unsigned underflow in debug builds or wrapping in release builds, and preserves accurate delta sums. The unit test atqueue.rs:818-825directly verifies the out-of-order[5, 8, 6, 8, 11]sequence.git merge-treeagainstorigin/main(63bcca43);cargo xtask policy(184 files ok);cargo clippy -p victory-gpu --all-targets -- -D warningsclean with default features and--all-features.queue::tests5/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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.