compilemem: isolate transient compile spikes & guard deferred compiles from refused/retry #2578

Manually merged
github merged 1 commit from github-bot/gh-2578 into main 2026-11-30 14:16:27 +00:00 AGit
Owner

@⁠steven-seagull27 on GitHub · 2026-11-29 14:34 UTC · original
steven-seagull27:fix/compilemem-estimator-and-deferred-refusal → main · +311 −37 · 3 files · 1 commits · merged 2026-11-30 14:12 UTC

Summary

Fixes two tightly-coupled bugs in the shader-compile memory guard and pipeline failure reporting paths:

1. Prevent concurrent persistent allocations from poisoning compilemem::Estimator (crates/victory-gpu/src/compilemem.rs)

  • Problem: State::finish computed peak.saturating_sub(r.private_at_start) / r.overlap.max(1) from whole-process PrivateUsage. When a shader compile overlapped a persistent allocation burst (such as buffers or textures committed while loading a scene), the compile was billed for gigabytes of unrelated persistent memory, inflating Estimator::expected() for the rest of the session, throttling concurrent compilation, and tripping COMMIT_FLOOR_MB prematurely.
  • Fix: Because driver compiler scratch memory is transient and released before Create*PipelineState returns whereas persistent allocations stay committed at private_now, State::finish now measures the transient compile spike above baseline = r.private_at_start.max(private_now):
    • Persistent growth committed during a compile is excluded (peak - max(start, now)).
    • Unrelated frees below private_at_start are not overcounted as compile scratch.
    • Genuine transient compile spikes above max(start, now) continue to be measured and shared across overlapping compiles.
  • Also avoids unnecessary K32GetProcessMemoryInfo / figures_now polling in sampler() and line() when no compiles are running.

2. Do not falsely record memory-guard deferrals as permanent 0x8007000E failures or bypass compilemem on retry (crates/victory-gpu/src/pipeline/host.rs, crates/victory-gpu/src/pipeline/refused.rs)

  • Problem: When compilemem::begin defers a compile, library::pipeline returns Err(memguard::refusal()) (E_OUTOFMEMORY) with thread-local memguard::deferred() == true so pipeline::make retries it after RETRY_AFTER_MS. However, HostPipeline::new called refused::failed(...) and refused::retry(...) unconditionally on error (compute, mesh, graphics, root signature):
    1. Every deferred compile was falsely logged and counted as a permanent host pipeline failed (0x8007000e) in pipeline::refused.
    2. When VICTORY_SHADER_CAPS=1 was enabled, refused::retry called CreateComputePipelineState / CreateGraphicsPipelineState directly on the driver, bypassing compilemem and memguard.
  • Fix:
    • Routed HostPipeline::new pipeline error handling through on_pipeline_error, which returns None immediately when crate::memguard::deferred() is true without recording a refusal or calling refused::retry, while leaving the thread-local flag intact for pipeline::make's memguard::take_deferred().
    • Added defense-in-depth crate::memguard::deferred() guards to pipeline::refused::failed and pipeline::refused::retry as well.

Testing

All tests are synthetic unit tests run in isolation (--test-threads=1):

  • cargo test --locked -j 2 -p victory-gpu --lib -- compilemem --nocapture --test-threads=1 — 13 passed, 0 failed (including new tests for concurrent persistent growth, transient spike on top of persistent growth, fast unsampled compiles, unrelated frees below start, and overlapping compiles with persistent growth).
  • cargo test --locked -j 2 -p victory-gpu --lib -- memguard --nocapture --test-threads=1 — 6 passed, 0 failed.
  • cargo test --locked -j 2 -p victory-gpu --lib -- pipeline:: --test-threads=1 — 73 passed, 0 failed, 2 ignored (including new tests in pipeline::host and pipeline::refused verifying that deferred errors are not recorded in refused, never invoke the retry closure, and preserve memguard::deferred() for take_deferred()).
  • cargo clippy --locked -j 2 -p victory-gpu --lib --tests — passed with 0 warnings in touched files.
  • git diff --check — clean.
**@⁠steven-seagull27** on GitHub · 2026-11-29 14:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2578) `steven-seagull27:fix/compilemem-estimator-and-deferred-refusal` → `main` · +311 −37 · 3 files · 1 commits · merged 2026-11-30 14:12 UTC ## Summary Fixes two tightly-coupled bugs in the shader-compile memory guard and pipeline failure reporting paths: ### 1. Prevent concurrent persistent allocations from poisoning `compilemem::Estimator` (`crates/victory-gpu/src/compilemem.rs`) - **Problem:** `State::finish` computed `peak.saturating_sub(r.private_at_start) / r.overlap.max(1)` from whole-process `PrivateUsage`. When a shader compile overlapped a persistent allocation burst (such as buffers or textures committed while loading a scene), the compile was billed for gigabytes of unrelated persistent memory, inflating `Estimator::expected()` for the rest of the session, throttling concurrent compilation, and tripping `COMMIT_FLOOR_MB` prematurely. - **Fix:** Because driver compiler scratch memory is transient and released before `Create*PipelineState` returns whereas persistent allocations stay committed at `private_now`, `State::finish` now measures the transient compile spike above `baseline = r.private_at_start.max(private_now)`: - Persistent growth committed during a compile is excluded (`peak - max(start, now)`). - Unrelated frees below `private_at_start` are not overcounted as compile scratch. - Genuine transient compile spikes above `max(start, now)` continue to be measured and shared across overlapping compiles. - Also avoids unnecessary `K32GetProcessMemoryInfo` / `figures_now` polling in `sampler()` and `line()` when no compiles are running. ### 2. Do not falsely record memory-guard deferrals as permanent `0x8007000E` failures or bypass `compilemem` on retry (`crates/victory-gpu/src/pipeline/host.rs`, `crates/victory-gpu/src/pipeline/refused.rs`) - **Problem:** When `compilemem::begin` defers a compile, `library::pipeline` returns `Err(memguard::refusal())` (`E_OUTOFMEMORY`) with thread-local `memguard::deferred() == true` so `pipeline::make` retries it after `RETRY_AFTER_MS`. However, `HostPipeline::new` called `refused::failed(...)` and `refused::retry(...)` unconditionally on error (compute, mesh, graphics, root signature): 1. Every deferred compile was falsely logged and counted as a permanent `host pipeline failed (0x8007000e)` in `pipeline::refused`. 2. When `VICTORY_SHADER_CAPS=1` was enabled, `refused::retry` called `CreateComputePipelineState` / `CreateGraphicsPipelineState` directly on the driver, bypassing `compilemem` and `memguard`. - **Fix:** - Routed `HostPipeline::new` pipeline error handling through `on_pipeline_error`, which returns `None` immediately when `crate::memguard::deferred()` is true without recording a refusal or calling `refused::retry`, while leaving the thread-local flag intact for `pipeline::make`'s `memguard::take_deferred()`. - Added defense-in-depth `crate::memguard::deferred()` guards to `pipeline::refused::failed` and `pipeline::refused::retry` as well. ## Testing All tests are synthetic unit tests run in isolation (`--test-threads=1`): - `cargo test --locked -j 2 -p victory-gpu --lib -- compilemem --nocapture --test-threads=1` — **13 passed, 0 failed** (including new tests for concurrent persistent growth, transient spike on top of persistent growth, fast unsampled compiles, unrelated frees below start, and overlapping compiles with persistent growth). - `cargo test --locked -j 2 -p victory-gpu --lib -- memguard --nocapture --test-threads=1` — **6 passed, 0 failed**. - `cargo test --locked -j 2 -p victory-gpu --lib -- pipeline:: --test-threads=1` — **73 passed, 0 failed, 2 ignored** (including new tests in `pipeline::host` and `pipeline::refused` verifying that deferred errors are not recorded in `refused`, never invoke the retry closure, and preserve `memguard::deferred()` for `take_deferred()`). - `cargo clippy --locked -j 2 -p victory-gpu --lib --tests` — passed with 0 warnings in touched files. - `git diff --check` — clean.
1. Measure compile memory usage as the transient spike above max(private_at_start, private_now) in compilemem::State::finish so concurrent persistent allocations (e.g. world-load buffers/textures) do not poison the estimator, and skip idle process_memory() polling in sampler()/line() when no compiles are running.

2. Guard pipeline::host error handling and pipeline::refused::{failed,retry} on memguard::deferred() so memory-guard deferrals return None cleanly without falsely recording permanent 0x8007000e failures or invoking the VICTORY_SHADER_CAPS direct-create retry (bypassing compilemem), while preserving the thread-local deferred flag for pipeline::make::take_deferred().
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 14:39:19 +00:00
github manually merged commit 114ea1b2ec into main 2026-11-30 14:16:27 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2578
No description provided.