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

Closed
github-bot wants to merge 1 commit from gh-pr/2340/head into gh-pr/2340/base
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:04 UTC · original
andrewpozdnakov7-jpg:codex2/present-counter-order → main · +17 −3 · 1 files · 1 commits · closed without merging

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

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 11:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2340) `andrewpozdnakov7-jpg:codex2/present-counter-order` → `main` · +17 −3 · 1 files · 1 commits · closed without merging 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://git.gtahub.st/github/Marvisak--VIctory/issues/1633) 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]>`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:46 +00:00
github-bot closed this pull request 2026-11-26 05:02:46 +00:00
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 12:00 UTC · original

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.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 12:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2340#issuecomment-7161793254) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:27 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2340#issuecomment-7166867330) <!-- 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)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:08 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 22:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2340#issuecomment-7175989334) 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

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