GPU: throttle pipeline workers and pause early prewarming when commit headroom is low #777

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

@⁠im-a-cat on GitHub · 2026-11-25 07:21 UTC · original
im-a-cat:fix/pipeline-commit-headroom → main · +162 −11 · 2 files · 1 commits · open

Why

During scene transitions on 32 GB Windows systems (reported in #771), the title hits std::alloc::rust_oom (0xc0000409) without any GPU hang or TDR right during a burst of shader/pipeline compilation. Running up to 8 concurrent HostPipeline::new workers while also queueing speculative EARLY prewarm pipelines multiplies transient compiler/driver commit allocations just when virtual commit charge (GlobalMemoryStatusEx::ullAvailPageFile) is nearly exhausted.

What

  • crates/victory-gpu/src/host.rs:
    • Extracts a shared memory_status() helper around GlobalMemoryStatusEx and adds available_commit_ram() (ullAvailPageFile) alongside available_physical_ram() (ullAvailPhys).
  • crates/victory-gpu/src/pipeline/make.rs:
    • Adds a pure commit_budget(base_workers, avail_commit_bytes, avail_phys_bytes, floor_mb) helper controlled by VICTORY_PIPELINE_COMMIT_MB (default 2048 MiB; 0 disables commit throttling):
      • Healthy headroom (>= 4 GiB available commit and >= 2 GiB available physical RAM at the default 2048 MiB floor): full worker parallelism and speculative EARLY prewarming, unchanged from main.
      • Tight headroom (< 4 GiB commit or < 2 GiB physical RAM): pauses speculative EARLY prewarm queueing/popping and caps concurrent HostPipeline::new workers to at most 2 (REQUESTED draw pipelines still run immediately).
      • Critical commit squeeze (< 2 GiB commit): serializes pipeline compilation to 1 worker and skips EARLY prewarm.
    • Tracks active worker count inside Queue (protected by QUEUE + AVAILABLE, released via an RAII ActiveGuard on completion/drop so counts stay balanced and sleeping workers wake via AVAILABLE.notify_all()).
    • Adds two unit tests in pipeline::make::tests:
      • commit_budget_throttles_workers_and_early_under_pressure
      • early_pipelines_are_deferred_when_only_requested_allowed

Verification

  • cargo xtask policy: asset policy: 171 files ok
  • cargo clippy -p victory-gpu --lib --tests --features diagnostics: clean in host.rs and pipeline/make.rs (only pre-existing draw.rs / indirect.rs lints on main)
  • cargo test --workspace --locked: all non-ignored unit/integration tests pass (0 failures across every crate, including the 2 new pipeline::make::tests cases).

Mitigates #771

**@⁠im-a-cat** on GitHub · 2026-11-25 07:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/777) `im-a-cat:fix/pipeline-commit-headroom` → `main` · +162 −11 · 2 files · 1 commits · open ## Why During scene transitions on 32 GB Windows systems (reported in #771), the title hits `std::alloc::rust_oom` (`0xc0000409`) without any GPU hang or TDR right during a burst of shader/pipeline compilation. Running up to 8 concurrent `HostPipeline::new` workers while also queueing speculative `EARLY` prewarm pipelines multiplies transient compiler/driver commit allocations just when virtual commit charge (`GlobalMemoryStatusEx::ullAvailPageFile`) is nearly exhausted. ## What - **`crates/victory-gpu/src/host.rs`**: - Extracts a shared `memory_status()` helper around `GlobalMemoryStatusEx` and adds `available_commit_ram()` (`ullAvailPageFile`) alongside `available_physical_ram()` (`ullAvailPhys`). - **`crates/victory-gpu/src/pipeline/make.rs`**: - Adds a pure `commit_budget(base_workers, avail_commit_bytes, avail_phys_bytes, floor_mb)` helper controlled by `VICTORY_PIPELINE_COMMIT_MB` (default `2048` MiB; `0` disables commit throttling): - Healthy headroom (`>= 4 GiB` available commit and `>= 2 GiB` available physical RAM at the default `2048` MiB floor): full worker parallelism and speculative `EARLY` prewarming, unchanged from `main`. - Tight headroom (`< 4 GiB` commit or `< 2 GiB` physical RAM): pauses speculative `EARLY` prewarm queueing/popping and caps concurrent `HostPipeline::new` workers to at most 2 (`REQUESTED` draw pipelines still run immediately). - Critical commit squeeze (`< 2 GiB` commit): serializes pipeline compilation to 1 worker and skips `EARLY` prewarm. - Tracks active worker count inside `Queue` (protected by `QUEUE` + `AVAILABLE`, released via an RAII `ActiveGuard` on completion/drop so counts stay balanced and sleeping workers wake via `AVAILABLE.notify_all()`). - Adds two unit tests in `pipeline::make::tests`: - `commit_budget_throttles_workers_and_early_under_pressure` - `early_pipelines_are_deferred_when_only_requested_allowed` ## Verification - `cargo xtask policy`: `asset policy: 171 files ok` - `cargo clippy -p victory-gpu --lib --tests --features diagnostics`: clean in `host.rs` and `pipeline/make.rs` (only pre-existing `draw.rs` / `indirect.rs` lints on `main`) - `cargo test --workspace --locked`: all non-ignored unit/integration tests pass (`0` failures across every crate, including the 2 new `pipeline::make::tests` cases). Mitigates #771
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:53 +00:00
Author
Owner

@⁠hxghr6 on GitHub · 2026-11-25 12:16 UTC · original

A data point from an RX 9070 XT (Windows 11, 31 GB RAM, page file managed by Windows, AMD driver 32.0.31044.16) on what limiting the pipeline workers by commit headroom does at the world load. I tried two forms of the same idea on main 310c6eb (not this PR's code), each run into the world with scripted keys and a cold driver shader cache (a fresh VICTORY_SHADER_LOOP_LIMIT), sampling the process and the system's commit every 10 s:

run rule process private system commit at the end outcome
no limit 8 workers 8.6 GB to 29.9 GB in 114 s 56.8 of 57.9 GB device removed (0x887A0006) at about 2 min
2 GiB of headroom kept per running compile 4 at 8 GiB, 1 at 2 GiB 8.3 GB to 28.0 GB in 134 s 54.8 of 55.9 GB stopped from outside at 134 s with the system nearly out of memory, outcome unknown
1 at a time under 8 GiB of headroom 1 at a time from the start up to 32.4 GB, then about 26.5 GB not sampled ran the full 14.7 min, but the queue drained at about 1.5 pipelines a second (1,419 to 645 in 8 minutes)

With and without the limit the system's commit stayed within 1 to 2 GB of its limit while the page file grew it from 38 GB to 56-58 GB, and the process grew by the same 20 GB in about two minutes. So on this machine the commit is taken by the world load itself, not by how many compiles run at once; serializing compiles alone did not keep the headroom, and serializing them fully made the world wait minutes for its pipelines. Four device removals at the same point, all without a limit, made the 1-at-a-time run's survival suggestive but not proof. Offline, the biggest compute pipeline (39f0e9aeb156a61c) peaks at 2 GB for a single compile on this driver.

That is one run of each limited form against four without a limit (the table's first row is the one of those four whose system commit was sampled), so take it as indicative.

**@⁠hxghr6** on GitHub · 2026-11-25 12:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/777#issuecomment-7162144691) A data point from an RX 9070 XT (Windows 11, 31 GB RAM, page file managed by Windows, AMD driver 32.0.31044.16) on what limiting the pipeline workers by commit headroom does at the world load. I tried two forms of the same idea on `main` 310c6eb (not this PR's code), each run into the world with scripted keys and a cold driver shader cache (a fresh `VICTORY_SHADER_LOOP_LIMIT`), sampling the process and the system's commit every 10 s: | run | rule | process private | system commit at the end | outcome | |---|---|---|---|---| | no limit | 8 workers | 8.6 GB to 29.9 GB in 114 s | 56.8 of 57.9 GB | device removed (0x887A0006) at about 2 min | | 2 GiB of headroom kept per running compile | 4 at 8 GiB, 1 at 2 GiB | 8.3 GB to 28.0 GB in 134 s | 54.8 of 55.9 GB | stopped from outside at 134 s with the system nearly out of memory, outcome unknown | | 1 at a time under 8 GiB of headroom | 1 at a time from the start | up to 32.4 GB, then about 26.5 GB | not sampled | ran the full 14.7 min, but the queue drained at about 1.5 pipelines a second (1,419 to 645 in 8 minutes) | With and without the limit the system's commit stayed within 1 to 2 GB of its limit while the page file grew it from 38 GB to 56-58 GB, and the process grew by the same 20 GB in about two minutes. So on this machine the commit is taken by the world load itself, not by how many compiles run at once; serializing compiles alone did not keep the headroom, and serializing them fully made the world wait minutes for its pipelines. Four device removals at the same point, all without a limit, made the 1-at-a-time run's survival suggestive but not proof. Offline, the biggest compute pipeline (`39f0e9aeb156a61c`) peaks at 2 GB for a single compile on this driver. That is one run of each limited form against four without a limit (the table's first row is the one of those four whose system commit was sampled), so take it as indicative.
@ -290,2 +381,4 @@
queue.active += 1;
return (p, ActiveGuard);
}
queue = AVAILABLE.wait(queue).unwrap_or_else(|e| e.into_inner());
Author
Owner

@⁠Flyander on GitHub · 2026-11-25 20:19 UTC · original

If pressure pauses EARLY work while there are queued EARLY jobs and no active workers, all workers go into this unconditional wait. An increase in host memory headroom does not notify AVAILABLE, so those jobs stay queued until another pipeline happens to be requested. This leaves a quiet part of loading unable to prewarm. A bounded wait_timeout only when real EARLY work is deferred and no worker is active would recheck headroom while leaving the empty queue on the existing blocking wait. The existing queue test calls pop_with(true) directly, so it does not cover the sleeping workers.

**@⁠Flyander** on GitHub · 2026-11-25 20:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/777#discussion_r4700381334) If pressure pauses EARLY work while there are queued EARLY jobs and no active workers, all workers go into this unconditional wait. An increase in host memory headroom does not notify `AVAILABLE`, so those jobs stay queued until another pipeline happens to be requested. This leaves a quiet part of loading unable to prewarm. A bounded `wait_timeout` only when real EARLY work is deferred and no worker is active would recheck headroom while leaving the empty queue on the existing blocking wait. The existing queue test calls `pop_with(true)` directly, so it does not cover the sleeping workers.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/777/head:github-bot/gh-777'
git switch 'github-bot/gh-777'

Merge

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