Pipeline wait budget is per frame only: a pipeline that stays "being made" costs the whole budget in every frame that binds it #73

Open
opened 2026-11-26 01:40:48 +00:00 by j-fuxa · 2 comments
j-fuxa commented 2026-11-26 01:40:48 +00:00 (Migrated from github.com)
Contributor

Imported from avatarmanz/VIctory-7900XTX. Originally posted by j-fuxa on 2026-11-26T01:40:48Z.


What the code does. pipeline/make.rs bounds the wait for a pipeline that is not made yet per frame (wait_budget, 500 ms, VICTORY_PIPELINE_WAIT_MS, shared by all threads) but remembers nothing per pipeline. ready() enters wait() whenever p.made.get().is_none(), so a pipeline whose build outlasts the budget takes it again in every frame that binds it. For passes over the screen the budget is VICTORY_SCREEN_WAIT_MS, 10 s by default.

Evidence. #61 (median 398 ms a frame, GPU 0.0 ms, 459-539 ms "waiting for pipelines", 1,251 draws a frame dropped as "being made") and #67 (about 380 ms a frame, 80 ms of it work) have this shape, though their logs cannot tell "slow to build" from "stuck". fxceless/victory-fork#1181 measured the loop on four stuck pipelines: 500.1 ms waited in every world frame; with a 50 ms budget the median went from 761 to 252 ms. Our tree had the same code shape (found by code review, then fixed as below).

Second gap. Pending::make() runs HostPipeline::new with no catch_unwind (used elsewhere in the crate: list/thin.rs, host/aside.rs, land.rs, queue/behind.rs). If it panics, the worker ends, made stays unset and the state stays MAKING (start() returns early for good), WAITING and a slow slot (slow_now) are never given back, and every frame that binds the pipeline waits again. We have not seen such a panic; this is from reading the code.

Suggested fix.

  • Keep the time waited per pipeline (atomic microseconds on Pending). wait() takes the smaller of the frame's and the pipeline's budget left and returns at once at zero; the draw is dropped as now and finds the pipeline when it appears. A per-pipeline budget well under the frame budget keeps the first-frame wait for cheap pipelines.
  • Wrap the worker's make in catch_unwind; on a panic log the shaders and set made to None (refused).

Smaller. shader_cache::cached stores only successes (its test says "Failures are not stored"), so a program that does not translate is translated and refused again every run. In our tree about 114 programs did, roughly 100 s of worker time a run; victory shaders shows your count. A negative entry keyed like the positive one would stop it.

Caveat. Your library locking (same_name stripes, saving) already matches what mattered for us: one lock over every library call left 8 workers waiting 59 % of the time on a 404 MB library (about 150 ms a load).

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6617569937 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/issues/73). Originally posted by [j-fuxa](https://github.com/j-fuxa) on 2026-11-26T01:40:48Z. --- **What the code does.** `pipeline/make.rs` bounds the wait for a pipeline that is not made yet per frame (`wait_budget`, 500 ms, `VICTORY_PIPELINE_WAIT_MS`, shared by all threads) but remembers nothing per pipeline. `ready()` enters `wait()` whenever `p.made.get().is_none()`, so a pipeline whose build outlasts the budget takes it again in every frame that binds it. For passes over the screen the budget is `VICTORY_SCREEN_WAIT_MS`, 10 s by default. **Evidence.** #61 (median 398 ms a frame, GPU 0.0 ms, 459-539 ms "waiting for pipelines", 1,251 draws a frame dropped as "being made") and #67 (about 380 ms a frame, 80 ms of it work) have this shape, though their logs cannot tell "slow to build" from "stuck". fxceless/victory-fork#1181 measured the loop on four stuck pipelines: 500.1 ms waited in every world frame; with a 50 ms budget the median went from 761 to 252 ms. Our tree had the same code shape (found by code review, then fixed as below). **Second gap.** `Pending::make()` runs `HostPipeline::new` with no `catch_unwind` (used elsewhere in the crate: `list/thin.rs`, `host/aside.rs`, `land.rs`, `queue/behind.rs`). If it panics, the worker ends, `made` stays unset and the state stays MAKING (`start()` returns early for good), `WAITING` and a slow slot (`slow_now`) are never given back, and every frame that binds the pipeline waits again. We have not seen such a panic; this is from reading the code. **Suggested fix.** - Keep the time waited per pipeline (atomic microseconds on `Pending`). `wait()` takes the smaller of the frame's and the pipeline's budget left and returns at once at zero; the draw is dropped as now and finds the pipeline when it appears. A per-pipeline budget well under the frame budget keeps the first-frame wait for cheap pipelines. - Wrap the worker's make in `catch_unwind`; on a panic log the shaders and set `made` to `None` (refused). **Smaller.** `shader_cache::cached` stores only successes (its test says "Failures are not stored"), so a program that does not translate is translated and refused again every run. In our tree about 114 programs did, roughly 100 s of worker time a run; `victory shaders` shows your count. A negative entry keyed like the positive one would stop it. **Caveat.** Your library locking (`same_name` stripes, `saving`) already matches what mattered for us: one lock over every library call left 8 workers waiting 59 % of the time on a 404 MB library (about 150 ms a load).
BE29ZZ commented 2026-11-26 01:46:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from avatarmanz/VIctory-7900XTX. Originally posted by BE29ZZ on 2026-11-26T01:46:38Z.


Are you still struggling with this error? Would you like me to help?

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7180117798 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/issues/73#issuecomment-7180117798). Originally posted by [BE29ZZ](https://github.com/BE29ZZ) on 2026-11-26T01:46:38Z. --- Are you still struggling with this error? Would you like me to help?
jtrudeau1530 commented 2026-11-26 08:40:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from avatarmanz/VIctory-7900XTX. Originally posted by jtrudeau1530 on 2026-11-26T08:40:38Z.


On Linux/vkd3d-proton one root cause of a pipeline that stays "being made" forever is a host compile thread that dies: dxil-spirv overflows its stack on a few large shaders (see #111). Then the whole 500 ms budget is spent every frame (measured 500.1-500.2 ms/frame, 3.4 fps). #162 detects the dead thread and compiles the shader again in another control-flow shape: 0.0 ms waiting, 13.7-15.1 fps on the same build. It doesn't change the per-frame budget logic itself, so the cap discussed here is still worth having for pipelines that are genuinely slow.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7186884133 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/issues/73#issuecomment-7186884133). Originally posted by [jtrudeau1530](https://github.com/jtrudeau1530) on 2026-11-26T08:40:38Z. --- On Linux/vkd3d-proton one root cause of a pipeline that stays "being made" forever is a host compile thread that dies: dxil-spirv overflows its stack on a few large shaders (see #111). Then the whole 500 ms budget is spent every frame (measured 500.1-500.2 ms/frame, 3.4 fps). #162 detects the dead thread and compiles the shader again in another control-flow shape: 0.0 ms waiting, 13.7-15.1 fps on the same build. It doesn't change the per-frame budget logic itself, so the cap discussed here is still worth having for pipelines that are genuinely slow.
Sign in to join this conversation.
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#73
No description provided.