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

Open
adritoyalser wants to merge 2 commits from upstream-pr/281 into main
adritoyalser commented 2026-11-24 23:11:54 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adritoyalser on 2026-11-24T23:11:54Z.


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)
<!-- greyfinch-sync:fxceless/victory-fork:issue:6593292295 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/281). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-24T23:11:54Z. --- 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)
ErRusso commented 2026-11-25 00:09:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ErRusso on 2026-11-24T23:19:09Z.

Review: CHANGES_REQUESTED


Reviewed at 3e9cbe1 against 2119b0e.

The tick-claim fix is correct: fetch_max's previous value is the right claim test, and the retry loop is bounded by started + limit, so it cannot extend the caller's timeout. I built the head for x86_64-pc-windows-gnu and ran frame::tests under Wine: 3/3 passed, and each new concurrency test passed 50/50 stress runs.

Requesting changes for one test-robustness issue:

  • concurrent_flip_retry_does_not_extend_timeout uses a 60 ms interval and an 85 ms timeout. If both threads are first scheduled more than 60 ms after set_interval (a loaded Windows CI runner), both compute the second tick at 120 ms, which is outside the 85 ms deadline, and both return TIMEOUT. The test then fails its "exactly one S_OK" assertion. Widen the margin (for example 200 ms interval / 285 ms timeout) or make the clock injectable.

Non-blocking:

  • PaceUs now records actual elapsed time rather than wait.min(limit). That is arguably more accurate, but it changes diagnostics semantics; please confirm it is intentional or note it in the description.
  • let _ = tick; is only needed because tick is used solely by the diagnostics log; _tick or a cfg-scoped use would be clearer.
  • The PR description has mangled identifiers (\tick, \next_tick, rame::tests), likely escaped tabs/newlines.
<!-- greyfinch-sync:fxceless/victory-fork:review:6048955801 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/281#pullrequestreview-6048955801). Originally posted by [ErRusso](https://github.com/ErRusso) on 2026-11-24T23:19:09Z. **Review:** CHANGES_REQUESTED --- Reviewed at `3e9cbe1` against `2119b0e`. The tick-claim fix is correct: `fetch_max`'s previous value is the right claim test, and the retry loop is bounded by `started + limit`, so it cannot extend the caller's timeout. I built the head for `x86_64-pc-windows-gnu` and ran `frame::tests` under Wine: 3/3 passed, and each new concurrency test passed 50/50 stress runs. Requesting changes for one test-robustness issue: - `concurrent_flip_retry_does_not_extend_timeout` uses a 60 ms interval and an 85 ms timeout. If both threads are first scheduled more than 60 ms after `set_interval` (a loaded Windows CI runner), both compute the second tick at 120 ms, which is outside the 85 ms deadline, and both return `TIMEOUT`. The test then fails its "exactly one `S_OK`" assertion. Widen the margin (for example 200 ms interval / 285 ms timeout) or make the clock injectable. Non-blocking: - `PaceUs` now records actual elapsed time rather than `wait.min(limit)`. That is arguably more accurate, but it changes diagnostics semantics; please confirm it is intentional or note it in the description. - `let _ = tick;` is only needed because `tick` is used solely by the diagnostics log; `_tick` or a cfg-scoped use would be clearer. - The PR description has mangled identifiers (`\tick`, `\next_tick`, `rame::tests`), likely escaped tabs/newlines.
adritoyalser commented 2026-11-25 00:10:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adritoyalser on 2026-11-24T23:21:41Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7147312175 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/281#issuecomment-7147312175). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-24T23:21:41Z. --- 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 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/281:upstream-pr/281'
git switch 'upstream-pr/281'

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