GPU: cap cumulative wait per pipeline across frames and guard worker panics (#73) #125

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

@⁠ESAT586 on GitHub · 2026-11-26 05:25 UTC · original
ESAT586:avatarmanz/pipeline-wait-cap-and-unwind → main · +111 −23 · 1 files · 1 commits · open

Fixes #73.

Problem

  1. wait() only tracked time spent per frame (SPENT), not per pipeline. A pipeline whose driver compile outlasts VICTORY_PIPELINE_WAIT_MS (500 ms) or VICTORY_SCREEN_WAIT_MS (10 s) consumed up to a full frame budget on every frame that bound it until compilation finished (as seen in #61 and #67).
  2. Pending::make() called HostPipeline::new without catch_unwind. Any panic during shader translation or driver compilation terminated the worker thread, leaked WAITING and slow_now, left made unset ("being made" forever), and left subsequent frames repeatedly waiting on it.

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

  • Added waited_us: AtomicU64 on Pending and extracted wait_with() so each wait is bounded by min(frame_budget_left, pipeline_budget_left) (with the same udget allowance per pipeline as its frame budget: wait_budget() for ordinary pipelines, screen_budget() for screen passes). Once a pipeline exhausts its allowance, later frames return immediately without touching the frame's wait budget until the worker finishes compiling it.
  • Wrapped pipeline construction in Pending::make_with() using std::panic::catch_unwind(AssertUnwindSafe(...)). On panic, it logs the pipeline key/shaders, marks self.made as Some(None) (refused), notifies DONE, and returns cleanly so the worker releases slow_now/WAITING and remains alive.
  • Added two deterministic unit tests:
    • pipeline_wait_caps_total_wait_per_pipeline_across_frames
    • worker_panic_refuses_pipeline_and_notifies_waiters

Verification (zero game data)

  • cargo test -p victory-gpu --lib --locked -- pipeline::make::tests on RTX 3060 Ti 8 GB: 8/8 passed
  • VICTORY_WARP=1 cargo test -p victory-gpu --lib --locked -- pipeline::make::tests: 8/8 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:25 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/125) `ESAT586:avatarmanz/pipeline-wait-cap-and-unwind` → `main` · +111 −23 · 1 files · 1 commits · open Fixes #73. ### Problem 1. **wait() only tracked time spent per frame (SPENT), not per pipeline.** A pipeline whose driver compile outlasts VICTORY_PIPELINE_WAIT_MS (500 ms) or VICTORY_SCREEN_WAIT_MS (10 s) consumed up to a full frame budget on *every* frame that bound it until compilation finished (as seen in #61 and #67). 2. **Pending::make() called HostPipeline::new without catch_unwind.** Any panic during shader translation or driver compilation terminated the worker thread, leaked WAITING and slow_now, left made unset ("being made" forever), and left subsequent frames repeatedly waiting on it. ### Fix (crates/victory-gpu/src/pipeline/make.rs) - Added waited_us: AtomicU64 on Pending and extracted wait_with() so each wait is bounded by min(frame_budget_left, pipeline_budget_left) (with the same udget allowance per pipeline as its frame budget: wait_budget() for ordinary pipelines, screen_budget() for screen passes). Once a pipeline exhausts its allowance, later frames return immediately without touching the frame's wait budget until the worker finishes compiling it. - Wrapped pipeline construction in Pending::make_with() using std::panic::catch_unwind(AssertUnwindSafe(...)). On panic, it logs the pipeline key/shaders, marks self.made as Some(None) (refused), notifies DONE, and returns cleanly so the worker releases slow_now/WAITING and remains alive. - Added two deterministic unit tests: - pipeline_wait_caps_total_wait_per_pipeline_across_frames - worker_panic_refuses_pipeline_and_notifies_waiters ### Verification (zero game data) - cargo test -p victory-gpu --lib --locked -- pipeline::make::tests on RTX 3060 Ti 8 GB: **8/8 passed** - VICTORY_WARP=1 cargo test -p victory-gpu --lib --locked -- pipeline::make::tests: **8/8 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.

Fixes #73:
1. Track cumulative waiting per Pending pipeline (waited_us) and cap
   wait_with by both the current frame's remaining wait budget and the
   pipeline's own remaining allowance (udget), so a slow or stuck
   compile costs at most one budget in total instead of stalling every
   subsequent frame.
2. Wrap HostPipeline::new inside Pending::make_with with
   std::panic::catch_unwind: if a worker panics while building a
   pipeline, log the failure, mark made as None (refused), notify
   waiters, and let the worker release slow_now/WAITING and continue
   serving the queue.
3. Add deterministic unit tests for both the multi-frame per-pipeline
   wait cap and worker panic recovery.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:42 +00:00
Author
Owner

@⁠gomeaw on GitHub · 2026-11-26 07:20 UTC · original

I reproduced a gap in the cumulative cap using the PR's wait_with unchanged in a small host-independent harness. With shared frame budgets enabled, hold DONE.0, start a waiter for frame 1, and wait until SPENT shows its reservation. Then start a waiter for frame 2 and wait for its reservation before releasing DONE.0. Both waiters read the same waited_us before either charges it. With a 250 ms pipeline budget, they each waited 250 ms and the final charge was 500 ms.

I would reserve the pipeline allowance before blocking, independently of frame accounting, and give back the unused allowance alongside the frame refund. A test with overlapping frames can cover this with shared frame budgets enabled. With VICTORY_PIPELINE_WAIT_SHARED=0, callers in the same frame can also overlap.

One other race to close while here: when catch_unwind surrounds get_or_init, another caller of make can start initializing the emptied OnceLock between the panic and set(None). Handle the unwind inside the initializer and return None there so the refusal is published by the same initialization. That covers the synchronous now caller overlapping a pipeline worker.

**@⁠gomeaw** on GitHub · 2026-11-26 07:20 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185348202) I reproduced a gap in the cumulative cap using the PR's `wait_with` unchanged in a small host-independent harness. With shared frame budgets enabled, hold `DONE.0`, start a waiter for frame 1, and wait until `SPENT` shows its reservation. Then start a waiter for frame 2 and wait for its reservation before releasing `DONE.0`. Both waiters read the same `waited_us` before either charges it. With a 250 ms pipeline budget, they each waited 250 ms and the final charge was 500 ms. I would reserve the pipeline allowance before blocking, independently of frame accounting, and give back the unused allowance alongside the frame refund. A test with overlapping frames can cover this with shared frame budgets enabled. With `VICTORY_PIPELINE_WAIT_SHARED=0`, callers in the same frame can also overlap. One other race to close while here: when `catch_unwind` surrounds `get_or_init`, another caller of `make` can start initializing the emptied `OnceLock` between the panic and `set(None)`. Handle the unwind inside the initializer and return `None` there so the refusal is published by the same initialization. That covers the synchronous `now` caller overlapping a pipeline worker.
Author
Owner

@⁠gomeaw on GitHub · 2026-11-26 07:32 UTC · original

The reservation and initializer fixes are ready as a PR against your branch. The overlap test holds the first waiter before completion and checks that the second frame gets no reservation. The Windows job repeats that test eight times. The change is a single commit, c326c7a, if you prefer to cherry-pick it.

**@⁠gomeaw** on GitHub · 2026-11-26 07:32 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185571403) The reservation and initializer fixes are ready as [a PR against your branch](https://github.com/ESAT586/VIctory-7900XTX/pull/1). The overlap test holds the first waiter before completion and checks that the second frame gets no reservation. The Windows job repeats that test eight times. The change is a single commit, `c326c7a`, if you prefer to cherry-pick it.
Author
Owner

@⁠avatarmanz on GitHub · 2026-11-26 07:36 UTC · original

Left open: a pipeline past its total wait is dropped instead of waited for, on every card; needs an in-game check on the 7900 XTX first.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:36 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185635196) Left open: a pipeline past its total wait is dropped instead of waited for, on every card; needs an in-game check on the 7900 XTX first.
Author
Owner

@⁠gomeaw on GitHub · 2026-11-26 07:46 UTC · original

The hardware A/B branch applies #125 and the reservation fix to 39031cb, with only pipeline scheduling and its tests changed. A paired 7900 XTX run with the same initial cache can compare the first world frame, screen passes that run once, and the p95 Present interval. The overlap regression passed eight consecutive times on Windows.

**@⁠gomeaw** on GitHub · 2026-11-26 07:46 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185827129) [The hardware A/B branch](https://github.com/gomeaw/VIctory-7900XTX/tree/test/pipeline-wait-cap) applies #125 and the reservation fix to `39031cb`, with only pipeline scheduling and its tests changed. A paired 7900 XTX run with the same initial cache can compare the first world frame, screen passes that run once, and the p95 Present interval. The overlap regression passed eight consecutive times on Windows.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pipeline/make.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/125/head:github-bot/gh-125'
git switch 'github-bot/gh-125'

Merge

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