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

Open
ESAT586 wants to merge 1 commit from upstream-pr/125 into main
ESAT586 commented 2026-11-26 05:25:15 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by ESAT586 on 2026-11-26T05:25:15Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6620151333 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/125). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-26T05:25:15Z. --- 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.)*
gomeaw commented 2026-11-26 07:20:18 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by gomeaw on 2026-11-26T07:20:18Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7185348202 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185348202). Originally posted by [gomeaw](https://github.com/gomeaw) on 2026-11-26T07:20:18Z. --- 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 commented 2026-11-26 07:32:40 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by gomeaw on 2026-11-26T07:32:40Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7185571403 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185571403). Originally posted by [gomeaw](https://github.com/gomeaw) on 2026-11-26T07:32:40Z. --- 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.
avatarmanz commented 2026-11-26 07:36:16 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by avatarmanz on 2026-11-26T07:36:16Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7185635196 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185635196). Originally posted by [avatarmanz](https://github.com/avatarmanz) on 2026-11-26T07:36:16Z. --- 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.
gomeaw commented 2026-11-26 07:46:52 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by gomeaw on 2026-11-26T07:46:52Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7185827129 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/125#issuecomment-7185827129). Originally posted by [gomeaw](https://github.com/gomeaw) on 2026-11-26T07:46:52Z. --- [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 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/125:upstream-pr/125'
git switch 'upstream-pr/125'

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/125'
git switch 'upstream-pr/125'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/125'
git switch 'upstream-pr/125'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/125'
git switch 'main'
git merge --squash 'upstream-pr/125'
git switch 'main'
git merge --ff-only 'upstream-pr/125'
git switch 'main'
git merge 'upstream-pr/125'
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
avatarmanz/VIctory-7900XTX!125
No description provided.