GPU: preserve the latest draw counter sample across presents #2338

Closed
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/2340 into main
andrewpozdnakov7-jpg commented 2026-11-25 11:04:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T11:04:54Z.


Two presents can sample the host draw or dispatch counter, then report in the opposite order. present used swap and subtracted the previous value, so a late older sample could underflow and move the saved count backwards.

fetch_max keeps the highest reported count. An older sample contributes zero, and the next newer sample reports only the additional work.

A synthetic Windows regression delivers samples 12, 10, then 15 to the same accounting used by present. The calculation from 940d32f panics on the second sample. After the change, the reported deltas are 12, 0, and 3. All five queue tests, strict GPU Clippy with diagnostics, and the staged asset policy pass.

Coordination claim

Please retain the Git author when reapplying this change. If you fold it into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6603038807 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2340). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T11:04:54Z. --- Two presents can sample the host draw or dispatch counter, then report in the opposite order. `present` used `swap` and subtracted the previous value, so a late older sample could underflow and move the saved count backwards. `fetch_max` keeps the highest reported count. An older sample contributes zero, and the next newer sample reports only the additional work. A synthetic Windows regression delivers samples `12`, `10`, then `15` to the same accounting used by `present`. The calculation from `940d32f` panics on the second sample. After the change, the reported deltas are `12`, `0`, and `3`. All five queue tests, strict GPU Clippy with diagnostics, and the staged asset policy pass. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7160507107) Please retain the Git author when reapplying this change. If you fold it into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
DenRakEiw commented 2026-11-25 12:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:25:24Z.

Review: APPROVED


Verified against origin/main (940d32f):

  • Using now.saturating_sub(last.fetch_max(now, Ordering::Relaxed)) in since_last_count cleanly prevents overlapping Present calls from rolling back or underflowing the reported draw/dispatch counters.
  • cargo test -p victory-gpu queue::tests: 5/5 passed (including an_older_present_sample_cannot_roll_back_the_reported_count).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6056747348 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2340#pullrequestreview-6056747348). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:25:24Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`): - Using `now.saturating_sub(last.fetch_max(now, Ordering::Relaxed))` in `since_last_count` cleanly prevents overlapping `Present` calls from rolling back or underflowing the reported draw/dispatch counters. - `cargo test -p victory-gpu queue::tests`: 5/5 passed (including `an_older_present_sample_cannot_roll_back_the_reported_count`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 12:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:51:57Z.

Review: COMMENTED


Draw counter samples preserved across presents via fetch_max instead of swap (saturating). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057089383 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2340#pullrequestreview-6057089383). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T11:51:57Z. **Review:** COMMENTED --- Draw counter samples preserved across presents via fetch_max instead of swap (saturating). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
welisonzika14-jpg commented 2026-11-25 12:03:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T12:00:23Z.


First run on NVIDIA hardware here, as far as I can see (the reviews above are static or WARP). RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head 4efd8c7 merged onto main 940d32f, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.

The PR's test queue::tests::an_older_present_sample_cannot_roll_back_the_reported_count passes on this card. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161793254 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2340#issuecomment-7161793254). Originally posted by [welisonzika14-jpg](https://github.com/welisonzika14-jpg) on 2026-11-25T12:00:23Z. --- First run on NVIDIA hardware here, as far as I can see (the reviews above are static or WARP). RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `4efd8c7` merged onto `main` `940d32f`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast`. The PR's test `queue::tests::an_older_present_sample_cannot_roll_back_the_reported_count` passes on this card. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Marvisak commented 2026-11-25 16:09:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:27:16Z.


Automated triage for the maintainers.

Merge candidate (small). In queue.rs present, the per-line draw and dispatch deltas were now - last.swap(now). If two presents race, the older sample can arrive second and the subtraction underflows: a panic inside an extern "system" function in debug builds, a huge logged count in release. The new since_last_count uses fetch_max with saturating_sub, so a late older sample reports 0 and the saved count never goes backwards; the unit test covers exactly that ordering. It only affects logging. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166867330 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2340#issuecomment-7166867330). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:27:16Z. --- <!-- victory-triage v1 head=4efd8c7782f35bed964c6c8dba7224f80bb48d11 verdict=merge-candidate at=2026-11-25T15:27:00Z --> Automated triage for the maintainers. **Merge candidate (small).** In `queue.rs` `present`, the per-line draw and dispatch deltas were `now - last.swap(now)`. If two presents race, the older sample can arrive second and the subtraction underflows: a panic inside an `extern "system"` function in debug builds, a huge logged count in release. The new `since_last_count` uses `fetch_max` with `saturating_sub`, so a late older sample reports 0 and the saved count never goes backwards; the unit test covers exactly that ordering. It only affects logging. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 23:04:19 +00:00
Marvisak commented 2026-11-25 23:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:08:34Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because the case cannot occur. The deltas are computed only when the presented frame number is a power of two, and the title presents from one thread, so samples arrive in order. The values feed one info log line.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175989334 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2340#issuecomment-7175989334). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:08:34Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because the case cannot occur. The deltas are computed only when the presented frame number is a power of two, and the title presents from one thread, so samples arrive in order. The values feed one info log line. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

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!2338
No description provided.