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

Open
im-a-cat wants to merge 1 commit from upstream-pr/777 into main
im-a-cat commented 2026-11-25 07:21:19 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by im-a-cat on 2026-11-25T07:21:19Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599376394 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/777). Originally posted by [im-a-cat](https://github.com/im-a-cat) on 2026-11-25T07:21:19Z. --- ## 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
hxghr6 commented 2026-11-25 13:05:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by hxghr6 on 2026-11-25T12:16:07Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7162144691 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/777#issuecomment-7162144691). Originally posted by [hxghr6](https://github.com/hxghr6) on 2026-11-25T12:16:07Z. --- 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.
Flyander commented 2026-11-25 21:05:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Flyander on 2026-11-25T20:19:34Z.

Review: COMMENTED


On RTX 5070 Ti / Windows 11 with 32 GiB RAM, a separate run of current main spent several minutes around 0.8–3 GiB of commit headroom during world entry, then recovered as work drained. I found one scheduler edge case worth covering before relying on prewarm to resume after that transition.

<!-- greyfinch-sync:fxceless/victory-fork:review:6064374014 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/777#pullrequestreview-6064374014). Originally posted by [Flyander](https://github.com/Flyander) on 2026-11-25T20:19:34Z. **Review:** COMMENTED --- On RTX 5070 Ti / Windows 11 with 32 GiB RAM, a separate run of current main spent several minutes around 0.8–3 GiB of commit headroom during world entry, then recovered as work drained. I found one scheduler edge case worth covering before relying on prewarm to resume after that transition.
Flyander commented 2026-11-25 21:05:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Flyander on 2026-11-25T20:19:34Z.

Code review location: crates/victory-gpu/src/pipeline/make.rs; line 384

@@ -282,11 +359,27 @@ fn start(p: &Arc<Pending>, priority: u8) {
     }
 }
 
-fn next() -> Arc<Pending> {
+struct ActiveGuard;
+
+impl Drop for ActiveGuard {
+    fn drop(&mut self) {
+        let mut queue = QUEUE.lock().unwrap_or_else(|e| e.into_inner());
+        queue.active = queue.active.saturating_sub(1);
+        if !queue.requested.is_empty() || !queue.early.is_empty() {
+            AVAILABLE.notify_all();
+        }
+    }
+}
+
+fn next(workers: usize) -> (Arc<Pending>, ActiveGuard) {
     let mut queue = QUEUE.lock().unwrap_or_else(|e| e.into_inner());
     loop {
-        if let Some(p) = queue.pop() {
-            return p;
+        let (allowed, allow_early) = current_commit_budget(workers);
+        if queue.active < allowed
+            && let Some(p) = queue.pop_with(allow_early)
+        {
+            queue.active += 1;
+            return (p, ActiveGuard);
         }
         queue = AVAILABLE.wait(queue).unwrap_or_else(|e| e.into_inner());

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.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4700381334 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/777#discussion_r4700381334). Originally posted by [Flyander](https://github.com/Flyander) on 2026-11-25T20:19:34Z. **Code review location:** `crates/victory-gpu/src/pipeline/make.rs`; line 384 ~~~~diff @@ -282,11 +359,27 @@ fn start(p: &Arc<Pending>, priority: u8) { } } -fn next() -> Arc<Pending> { +struct ActiveGuard; + +impl Drop for ActiveGuard { + fn drop(&mut self) { + let mut queue = QUEUE.lock().unwrap_or_else(|e| e.into_inner()); + queue.active = queue.active.saturating_sub(1); + if !queue.requested.is_empty() || !queue.early.is_empty() { + AVAILABLE.notify_all(); + } + } +} + +fn next(workers: usize) -> (Arc<Pending>, ActiveGuard) { let mut queue = QUEUE.lock().unwrap_or_else(|e| e.into_inner()); loop { - if let Some(p) = queue.pop() { - return p; + let (allowed, allow_early) = current_commit_budget(workers); + if queue.active < allowed + && let Some(p) = queue.pop_with(allow_early) + { + queue.active += 1; + return (p, ActiveGuard); } queue = AVAILABLE.wait(queue).unwrap_or_else(|e| e.into_inner()); ~~~~ --- 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 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/777:upstream-pr/777'
git switch 'upstream-pr/777'

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/777'
git switch 'upstream-pr/777'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/777'
git switch 'upstream-pr/777'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/777'
git switch 'main'
git merge --squash 'upstream-pr/777'
git switch 'main'
git merge --ff-only 'upstream-pr/777'
git switch 'main'
git merge 'upstream-pr/777'
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
fxceless/victory-fork!777
No description provided.