GPU: prevent concurrent frame waits from consuming the same tick (#244) #281

Open
github-bot wants to merge 2 commits from github-bot/gh-281 into main AGit
Owner

@⁠adritoyalser on GitHub · 2026-11-24 23:11 UTC · original
adritoyalser:fix/flip-wait-race → main · +108 −19 · 1 files · 2 commits · open

Fixes #244.

Summary

  • In crates/victory-gpu/src/frame.rs (wait), check the previous value returned by last(kind).fetch_max(tick, Ordering::AcqRel) so only one waiter can claim a given tick.
  • If another waiter already claimed tick (or a later one), recompute next_tick(kind) and retry against the caller's original deadline (started.checked_add(limit)), so retries never extend the requested timeout.
  • Under diagnostics, PaceUs and the frame wait debug log now record actual started.elapsed() across any retry iterations rather than the single-attempt wait.min(limit).
  • Added two regression tests in frame::tests:
    • concurrent_flip_waits_consume_distinct_ticks: two barrier-synchronized FLIP waits both return S_OK and advance LAST[2] by at least 2.
    • concurrent_flip_retry_does_not_extend_timeout: two barrier-synchronized FLIP waits with a 200 ms interval (started after both threads align at the first barrier) and 285 ms timeout produce exactly one S_OK and one TIMEOUT with LAST[2] advancing by 1.

Verification

  • cargo test -q -p victory-gpu --lib --locked frame::tests (3 passed, 0 failed)
  • cargo clippy -q -p victory-gpu --all-targets --locked -- -D warnings (0 warnings)
  • cargo clippy -q -p victory-gpu --all-targets --all-features --locked -- -D warnings (0 warnings)
**@⁠adritoyalser** on GitHub · 2026-11-24 23:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/281) `adritoyalser:fix/flip-wait-race` → `main` · +108 −19 · 1 files · 2 commits · open Fixes #244. ### Summary - In `crates/victory-gpu/src/frame.rs` (`wait`), check the previous value returned by `last(kind).fetch_max(tick, Ordering::AcqRel)` so only one waiter can claim a given tick. - If another waiter already claimed `tick` (or a later one), recompute `next_tick(kind)` and retry against the caller's original `deadline` (`started.checked_add(limit)`), so retries never extend the requested timeout. - Under `diagnostics`, `PaceUs` and the `frame wait` debug log now record actual `started.elapsed()` across any retry iterations rather than the single-attempt `wait.min(limit)`. - Added two regression tests in `frame::tests`: - `concurrent_flip_waits_consume_distinct_ticks`: two barrier-synchronized `FLIP` waits both return `S_OK` and advance `LAST[2]` by at least 2. - `concurrent_flip_retry_does_not_extend_timeout`: two barrier-synchronized `FLIP` waits with a 200 ms interval (started after both threads align at the first barrier) and 285 ms timeout produce exactly one `S_OK` and one `TIMEOUT` with `LAST[2]` advancing by 1. ### Verification - `cargo test -q -p victory-gpu --lib --locked frame::tests` (3 passed, 0 failed) - `cargo clippy -q -p victory-gpu --all-targets --locked -- -D warnings` (0 warnings) - `cargo clippy -q -p victory-gpu --all-targets --all-features --locked -- -D warnings` (0 warnings)
Two concurrent waits for the same frame event kind could pick the same
tick before either advanced LAST, and both returned S_OK after
calling etch_max(tick) without checking its previous value.

Check the previous value returned by etch_max(tick, AcqRel) to ensure
only one waiter claims a given tick; if another waiter already claimed
it, recompute the next tick and retry against the caller's original
deadline so retries never extend the timeout.
Address review feedback on #281:
- Widen `concurrent_flip_retry_does_not_extend_timeout` to a 200 ms interval
  and 285 ms timeout, starting the interval after both threads align at the
  first barrier so thread-spawn scheduling cannot consume the first tick window.
- Use `_tick` directly instead of `let _ = tick;`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:39:50 +00:00
Author
Owner

@⁠adritoyalser on GitHub · 2026-11-24 23:21 UTC · original

Thanks for the thorough review @⁠ErRusso! Addressed all points:

  • Widened concurrent_flip_retry_does_not_extend_timeout to a 200 ms interval / 285 ms timeout and moved set_interval inside the first barrier phase so thread-spawn delay cannot eat into the first tick window.
  • Renamed tick to _tick and dropped let _ = tick;.
  • Confirmed and documented in the PR description that PaceUs intentionally records actual elapsed time (started.elapsed()) across retries.
  • Fixed the escaped backticks in the PR description.
**@⁠adritoyalser** on GitHub · 2026-11-24 23:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/281#issuecomment-7147312175) Thanks for the thorough review @⁠ErRusso! Addressed all points: - Widened `concurrent_flip_retry_does_not_extend_timeout` to a 200 ms interval / 285 ms timeout and moved `set_interval` inside the first barrier phase so thread-spawn delay cannot eat into the first tick window. - Renamed `tick` to `_tick` and dropped `let _ = tick;`. - Confirmed and documented in the PR description that `PaceUs` intentionally records actual elapsed time (`started.elapsed()`) across retries. - Fixed the escaped backticks in the PR description.
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/281/head:github-bot/gh-281'
git switch 'github-bot/gh-281'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-281'
git switch 'github-bot/gh-281'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-281'
git switch 'github-bot/gh-281'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-281'
git switch 'main'
git merge --squash 'github-bot/gh-281'
git switch 'main'
git merge --ff-only 'github-bot/gh-281'
git switch 'main'
git merge 'github-bot/gh-281'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.