GPU: cap cumulative wait per pipeline across frames and wake waiters on worker_lost (#217) #229

Open
github-bot wants to merge 1 commit from github-bot/gh-229 into main AGit
Owner

@⁠ESAT586 on GitHub · 2026-11-26 05:29 UTC · original
ESAT586:belobug/pipeline-wait-cap → main · +91 −7 · 1 files · 1 commits · open

Addresses the per-pipeline wait-budget half of #217 (complements #219 cleanly with no overlap in Pending::make).

Problem

  1. pipeline::make::wait resets its wait budget every frame (FRAME / WAITED_US), but Pending does not track how much time has already been waited on that specific pipeline. Any pipeline that takes longer than BUDGET (500 ms) or SCREEN_BUDGET (20 s) therefore burns up to a full frame budget on every subsequent frame that binds it until compilation finishes.
  2. If a worker is lost (worker_lost) while a title thread is already blocked in wait(), wait() never checked p.lost and worker_lost() did not notify DONE, causing the waiting thread to sleep out the full remaining budget (up to 20 s for screen passes).

Fix (crates/victory-gpu/src/pipeline/make.rs)

  • Added waited_us: AtomicU64 to Pending and extracted wait_with(), bounding each wait by min(frame_budget_left, pipeline_budget_left) so each pipeline can spend at most one budget in total across frames. Once spent, later frames skip waiting immediately (without consuming the frame's budget) until the worker finishes compiling it.
  • Checked !p.lost.load(Ordering::Relaxed) in the wait loop and added DONE.notify_all() inside worker_lost().
  • Added two deterministic unit tests:
    • pipeline_wait_caps_total_wait_per_pipeline_across_frames
    • lost_worker_wakes_waiter_immediately

Verification (zero game data)

  • cargo test -p victory-gpu --lib --locked -- pipeline::make::tests on RTX 3060 Ti 8 GB: 3/3 passed
  • VICTORY_WARP=1 cargo test -p victory-gpu --lib --locked -- pipeline::make::tests: 3/3 passed
  • cargo clippy -p victory-gpu --lib --tests --locked: 0 warnings in pipeline/make.rs
  • cargo xtask policy --staged: 1 files ok

(Authored and verified with Gemini 4 Neon — High Mode, AI coding agent — with zero game data.)

**@⁠ESAT586** on GitHub · 2026-11-26 05:29 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/229) `ESAT586:belobug/pipeline-wait-cap` → `main` · +91 −7 · 1 files · 1 commits · open Addresses the per-pipeline wait-budget half of #217 (complements #219 cleanly with no overlap in Pending::make). ### Problem 1. pipeline::make::wait resets its wait budget every frame (FRAME / WAITED_US), but Pending does not track how much time has already been waited on that specific pipeline. Any pipeline that takes longer than BUDGET (500 ms) or SCREEN_BUDGET (20 s) therefore burns up to a full frame budget on *every* subsequent frame that binds it until compilation finishes. 2. If a worker is lost (worker_lost) while a title thread is already blocked in wait(), wait() never checked p.lost and worker_lost() did not notify DONE, causing the waiting thread to sleep out the full remaining budget (up to 20 s for screen passes). ### Fix (crates/victory-gpu/src/pipeline/make.rs) - Added waited_us: AtomicU64 to Pending and extracted wait_with(), bounding each wait by min(frame_budget_left, pipeline_budget_left) so each pipeline can spend at most one budget in total across frames. Once spent, later frames skip waiting immediately (without consuming the frame's budget) until the worker finishes compiling it. - Checked !p.lost.load(Ordering::Relaxed) in the wait loop and added DONE.notify_all() inside worker_lost(). - Added two deterministic unit tests: - pipeline_wait_caps_total_wait_per_pipeline_across_frames - lost_worker_wakes_waiter_immediately ### Verification (zero game data) - cargo test -p victory-gpu --lib --locked -- pipeline::make::tests on RTX 3060 Ti 8 GB: **3/3 passed** - VICTORY_WARP=1 cargo test -p victory-gpu --lib --locked -- pipeline::make::tests: **3/3 passed** - cargo clippy -p victory-gpu --lib --tests --locked: **0 warnings in pipeline/make.rs** - cargo xtask policy --staged: **1 files ok** *(Authored and verified with Gemini 4 Neon — High Mode, AI coding agent — with zero game data.)*
Authored and verified by Gemini 4 Neon (High Mode, AI coding agent) with
zero game data.

Addresses the per-pipeline wait-budget half of #217 (complements #219
without touching Pending::make):
1. Track cumulative wait microseconds per Pending pipeline (waited_us)
   and bound wait_with by min(frame_left, pipeline_left) so a slow
   pipeline costs at most one budget in total instead of stalling every
   subsequent frame.
2. Check p.lost inside the wait loop and notify DONE in worker_lost
   so threads waiting on a lost worker wake immediately instead of
   sleeping through the full remaining budget.
3. Add deterministic unit tests for both the cross-frame per-pipeline
   wait cap and immediate wake on lost worker.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:01:53 +00:00
Author
Owner

@⁠ySKELLETONX on GitHub · 2026-11-26 11:26 UTC · original

Tested on RX 7600 XT (RDNA3), Windows 11, on top of main 4f62c2a, merged together with #219 (they merge cleanly):

  • cargo test -p victory-gpu --lib --locked: 116 passed (113 on main + the 3 new tests from #219 and #229), 0 failed; pipeline::make::tests 5/5 runs green
  • cargo clippy -p victory-gpu --lib --tests: nothing in make.rs

Read through it: lost is stored under AT_WORK before worker_lost takes DONE to notify, so a waiter can't miss the wake-up. Two small notes:

  1. lost_worker_wakes_waiter_immediately sets lost and notifies by hand, so it would still pass if the new notify_all in worker_lost were removed. It may be worth driving it through worker_lost (or saying in the test that it covers the wait loop only).
  2. Two threads waiting on the same pipeline in one frame both add to waited_us, so it can be cut off before a full budget of wall time has passed. Probably fine, but worth a line in the doc comment.

This conflicts with #56: the left.is_zero() early return there is already covered here (frame_left.min(pipeline_left)), while #56's load-before-swap hunks in ready/start don't overlap.

**@⁠ySKELLETONX** on GitHub · 2026-11-26 11:26 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/229#issuecomment-7190724144) Tested on RX 7600 XT (RDNA3), Windows 11, on top of `main` 4f62c2a, merged together with #219 (they merge cleanly): - `cargo test -p victory-gpu --lib --locked`: 116 passed (113 on `main` + the 3 new tests from #219 and #229), 0 failed; `pipeline::make::tests` 5/5 runs green - `cargo clippy -p victory-gpu --lib --tests`: nothing in `make.rs` Read through it: `lost` is stored under `AT_WORK` before `worker_lost` takes `DONE` to notify, so a waiter can't miss the wake-up. Two small notes: 1. `lost_worker_wakes_waiter_immediately` sets `lost` and notifies by hand, so it would still pass if the new `notify_all` in `worker_lost` were removed. It may be worth driving it through `worker_lost` (or saying in the test that it covers the wait loop only). 2. Two threads waiting on the same pipeline in one frame both add to `waited_us`, so it can be cut off before a full budget of wall time has passed. Probably fine, but worth a line in the doc comment. This conflicts with #56: the `left.is_zero()` early return there is already covered here (`frame_left.min(pipeline_left)`), while #56's `load`-before-`swap` hunks in `ready`/`start` don't overlap.
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 15:52 UTC · original · reviewed

AI-assisted static review; I inspected the shared wait accounting and condition-variable path, but did not run tests or the game.

**@⁠gut0to** on GitHub · 2026-11-26 15:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/229#pullrequestreview-6077068817) · **reviewed** AI-assisted static review; I inspected the shared wait accounting and condition-variable path, but did not run tests or the game.
@ -169,0 +181,4 @@
frame_slot: &AtomicU64,
frame_waited_us: &AtomicU64,
) -> bool {
let pipeline_left = budget.saturating_sub(Duration::from_micros(p.waited_us.load(Ordering::Relaxed)));
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 15:52 UTC · original

Could this reserve the remaining allowance atomically before entering the condition-variable wait? Pending is shared by concurrent title threads, but each waiter reads waited_us here and charges it only after waking. Two callers can therefore both observe the full pipeline allowance, wait for that full interval concurrently, then add both intervals; the aggregate can exceed the per-pipeline cap. The same read-then-charge race applies to the shared frame allowance. A reservation/CAS or one waiter per Pending would enforce the stated aggregate budget.

**@⁠gut0to** on GitHub · 2026-11-26 15:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/229#discussion_r4710703922) Could this reserve the remaining allowance atomically before entering the condition-variable wait? Pending is shared by concurrent title threads, but each waiter reads waited_us here and charges it only after waking. Two callers can therefore both observe the full pipeline allowance, wait for that full interval concurrently, then add both intervals; the aggregate can exceed the per-pipeline cap. The same read-then-charge race applies to the shared frame allowance. A reservation/CAS or one waiter per Pending would enforce the stated aggregate budget.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:38 UTC · original

Checked on head f8a76b1 against main 4f62c2a: Windows 11, RX 7900 XT, debug test builds only, no game. Other heavy jobs were running on the machine at the same time.

The per-pipeline cap works here:

  • A pipeline that is never made took 502-506 ms on the first frame. Each of the next 3 frames took at most 1 us.
  • With the per-pipeline cap removed from this PR, the same 4 frames took 2.03 s. pipeline_wait_caps_total_wait_per_pipeline_across_frames then fails, as it should.

Panic in make(), which the description leaves to #219:

  • On this PR alone, I made HostPipeline::new panic in a worker (a test-only hook). After 10 s the pipeline was still being made, lost was false and waiting() was 1. It cost one budget (about 0.5 s) in all, not one per frame.
  • On this PR merged with #219, all 7 make tests pass in 3 of 3 runs. That is the existing test, both PRs' tests and three of mine. One of mine sends a panic through a real worker.

Tests in this PR:

  • lost_worker_wakes_waiter_immediately is racy. If lost is set before the waiter thread reaches wait_with, wait_with returns false and the assert! on its return value fails.
  • In 20 full victory-gpu --lib runs, interleaved with main, it failed 6 times. In a later set it failed 6 of 10. Every failure was on that assert. Run on its own, it failed once in 300 runs.
  • I wrote a test that puts a pipeline in AT_WORK, blocks a waiter in wait, then calls worker_lost(id). With the change, the waiter woke within 0.13 ms. Without the notify_all in worker_lost, it woke after 513 ms.

Other results:

  • victory-gpu lib tests, 20 runs each, interleaved with main. Apart from the test above, the only failures were watch:: and queue:: tests, on both sides. Those are flaky on this machine under load.

Not tested:

  • A game run or a real driver compile.
  • Screen passes (20 s budget).
  • WARP / --features diagnostics.
  • Several threads waiting on the same pipeline at once.
**@⁠adrianmjim** on GitHub · 2026-11-26 19:38 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/229#issuecomment-7201808915) Checked on head f8a76b1 against main 4f62c2a: Windows 11, RX 7900 XT, debug test builds only, no game. Other heavy jobs were running on the machine at the same time. The per-pipeline cap works here: - A pipeline that is never made took 502-506 ms on the first frame. Each of the next 3 frames took at most 1 us. - With the per-pipeline cap removed from this PR, the same 4 frames took 2.03 s. `pipeline_wait_caps_total_wait_per_pipeline_across_frames` then fails, as it should. Panic in `make()`, which the description leaves to #219: - On this PR alone, I made `HostPipeline::new` panic in a worker (a test-only hook). After 10 s the pipeline was still being made, `lost` was false and `waiting()` was 1. It cost one budget (about 0.5 s) in all, not one per frame. - On this PR merged with #219, all 7 `make` tests pass in 3 of 3 runs. That is the existing test, both PRs' tests and three of mine. One of mine sends a panic through a real worker. Tests in this PR: - `lost_worker_wakes_waiter_immediately` is racy. If `lost` is set before the waiter thread reaches `wait_with`, `wait_with` returns `false` and the `assert!` on its return value fails. - In 20 full `victory-gpu --lib` runs, interleaved with main, it failed 6 times. In a later set it failed 6 of 10. Every failure was on that assert. Run on its own, it failed once in 300 runs. - I wrote a test that puts a pipeline in `AT_WORK`, blocks a waiter in `wait`, then calls `worker_lost(id)`. With the change, the waiter woke within 0.13 ms. Without the `notify_all` in `worker_lost`, it woke after 513 ms. Other results: - victory-gpu lib tests, 20 runs each, interleaved with main. Apart from the test above, the only failures were `watch::` and `queue::` tests, on both sides. Those are flaky on this machine under load. Not tested: - A game run or a real driver compile. - Screen passes (20 s budget). - WARP / `--features diagnostics`. - Several threads waiting on the same pipeline at once.
This pull request can be merged automatically.
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/229/head:github-bot/gh-229'
git switch 'github-bot/gh-229'

Merge

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