gpu: a pipeline refused for want of memory is asked for again, not refused for the run #2616

Merged
superboynick merged 1 commit from upstream-pr/2616 into main 2026-11-30 14:12:02 +00:00
superboynick commented 2026-11-29 14:59:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by superboynick on 2026-11-29T14:59:11Z.


Follows sergiogbrox's diagnosis in #2520, which is the useful part of this: crates/victory-gpu/src/pipeline/make.rs settles a build once, so a refusal from the host is written to the OnceLock as None and kept for the run. That is right for a shader the device cannot make, and wrong for one it could not make just then.

His measurement: on an RTX 5060 Ti the process commit rose 19.6 -> 23.6 GB in about 4 s while the world streamed, the memory guard reported 150 MB free, 451 pipelines were refused 0x8007000e with retried=0 - and the memory came back, but those pipelines stayed refused, so the frame kept dropping 322 draws a frame (max 2,016) for the rest of the run at 0.3-0.4 fps in places. A second run with nothing else open had no refusals at all.

What this changes

When the host answers E_OUTOFMEMORY, the device is still there, and the memory guard did not itself defer the compile, make_with now treats it like the guard's own deferral: the pipeline is asked for again RETRY_AFTER_MS later instead of being recorded as refused - up to OUT_OF_MEMORY_RETRIES (3) times, after which the refusal is recorded for the run exactly as before. So a card that is really full stops retrying, and the per-run negative cache asked for in #2533 still applies wherever there is memory to spare.

Two small additions, both local: refused::failed sets a flag when the code is 0x8007000e and GetDeviceRemovedReason reports nothing; Pending counts its tries.

Verification, and what is missing

  • cargo build --release -p victory: clean.
  • cargo test -p victory-gpu --lib: 915 passed, 0 failed, 57 ignored.
  • In the game on this machine: not verified, and I would rather say so. This is a 12 GB card that also carries 3.8 GB of other applications' video memory; at Series X the title now dies in its own code with 0x80000003 during load, before any pipeline is made, so the run never reaches the state this change affects. At Series S, where it does run (10 fps, p10 9), there are no 0x8007000e refusals to retry.

@sergiogbrox - you offered to test a patch on the desktop where the burst reproduces by keeping a browser open while the world loads, and that is the only machine this can be checked on. If you run it, the line to look for is host pipeline refused for want of memory: it is tried again 1000 ms later and, at the end, retried= and retry_made= in the pipeline failures: line: they should stop being 0, and the draws dropped per frame should fall off once the memory comes back.

Claimed under #2520, per #1528. Checked for overlap: make.rs's settle/defer and refused.rs's failed are not touched by the memory work in #1463/#971/#718 (those are shadow.rs and the allocator).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5551933941 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616). Originally posted by [superboynick](https://github.com/superboynick) on 2026-11-29T14:59:11Z. --- Follows sergiogbrox's diagnosis in #2520, which is the useful part of this: `crates/victory-gpu/src/pipeline/make.rs` settles a build once, so a refusal from the host is written to the `OnceLock` as `None` and kept for the run. That is right for a shader the device cannot make, and wrong for one it could not make *just then*. His measurement: on an RTX 5060 Ti the process commit rose 19.6 -> 23.6 GB in about 4 s while the world streamed, the memory guard reported 150 MB free, **451 pipelines were refused `0x8007000e` with `retried=0`** - and the memory came back, but those pipelines stayed refused, so the frame kept dropping 322 draws a frame (max 2,016) for the rest of the run at 0.3-0.4 fps in places. A second run with nothing else open had no refusals at all. ## What this changes When the host answers `E_OUTOFMEMORY`, **the device is still there**, and the memory guard did not itself defer the compile, `make_with` now treats it like the guard's own deferral: the pipeline is asked for again `RETRY_AFTER_MS` later instead of being recorded as refused - up to `OUT_OF_MEMORY_RETRIES` (3) times, after which the refusal is recorded for the run exactly as before. So a card that is really full stops retrying, and the per-run negative cache asked for in #2533 still applies wherever there is memory to spare. Two small additions, both local: `refused::failed` sets a flag when the code is `0x8007000e` and `GetDeviceRemovedReason` reports nothing; `Pending` counts its tries. ## Verification, and what is missing - `cargo build --release -p victory`: clean. - `cargo test -p victory-gpu --lib`: **915 passed, 0 failed, 57 ignored**. - **In the game on this machine: not verified, and I would rather say so.** This is a 12 GB card that also carries 3.8 GB of other applications' video memory; at Series X the title now dies in its own code with `0x80000003` during load, before any pipeline is made, so the run never reaches the state this change affects. At Series S, where it does run (10 fps, p10 9), there are no `0x8007000e` refusals to retry. @sergiogbrox - you offered to test a patch on the desktop where the burst reproduces by keeping a browser open while the world loads, and that is the only machine this can be checked on. If you run it, the line to look for is `host pipeline refused for want of memory: it is tried again 1000 ms later` and, at the end, `retried=` and `retry_made=` in the `pipeline failures:` line: they should stop being 0, and the draws dropped per frame should fall off once the memory comes back. Claimed under #2520, per #1528. Checked for overlap: `make.rs`'s `settle`/`defer` and `refused.rs`'s `failed` are not touched by the memory work in #1463/#971/#718 (those are `shadow.rs` and the allocator).
superboynick commented 2026-11-29 15:14:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by superboynick on 2026-11-29T15:14:45Z.


Two things added to the branch since it was opened, both about making the change checkable without the machine that has the problem.

The decision is now a pure function with tests, rather than a condition inline in make_with:

fn retry_after_refusal(built_nothing: bool, deferred: bool, out_of_memory: bool, tries: u32) -> bool {
    built_nothing && !deferred && out_of_memory && tries < OUT_OF_MEMORY_RETRIES
}

with three tests over its cases: a refusal for want of memory is asked for again at 0, 1 and 2 tries and recorded at 3 and beyond; a refusal of any other kind, or one the memory guard itself deferred, is recorded at once; a pipeline that was built is never retried. cargo test -p victory-gpu --lib -- retry_after_refusal refusal_of_any_other pipeline_that_was_built: 2 passed, 1 passed, 1 passed.

And a flake worth knowing about, which is not this change. watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock fails on roughly one full-suite run in four, and it does so on main as well:

tree full cargo test -p victory-gpu --lib, 4 runs
origin/main (915 tests) ok, ok, 1 failed, ok
this branch (917 tests) ok, 1 failed, ok

Run alone, that test passes every time on both trees (3 of 3 here, 4 of 4 on main), so it is an order-of-tests or thread-timing matter in the full run rather than anything either tree changed. I have left it alone rather than fold an unrelated fix into this pull request, but CI on this branch will inherit its ~25 % failure rate, which is worth knowing before reading a red run as this change's fault.

Still unverified in the game on this machine, and for the same reason as before: 3.8 GB of this card is held by other applications, and at Series X the title dies in its own code with 0x80000003 during load, before any pipeline is made. @sergiogbrox's offer to test on the desktop where the streaming burst reproduces is the check that matters.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7257935513 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7257935513). Originally posted by [superboynick](https://github.com/superboynick) on 2026-11-29T15:14:45Z. --- Two things added to the branch since it was opened, both about making the change checkable without the machine that has the problem. **The decision is now a pure function with tests**, rather than a condition inline in `make_with`: ```rust fn retry_after_refusal(built_nothing: bool, deferred: bool, out_of_memory: bool, tries: u32) -> bool { built_nothing && !deferred && out_of_memory && tries < OUT_OF_MEMORY_RETRIES } ``` with three tests over its cases: a refusal for want of memory is asked for again at 0, 1 and 2 tries and recorded at 3 and beyond; a refusal of any other kind, or one the memory guard itself deferred, is recorded at once; a pipeline that was built is never retried. `cargo test -p victory-gpu --lib -- retry_after_refusal refusal_of_any_other pipeline_that_was_built`: 2 passed, 1 passed, 1 passed. **And a flake worth knowing about, which is not this change.** `watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock` fails on roughly one full-suite run in four, and it does so **on `main` as well**: | tree | full `cargo test -p victory-gpu --lib`, 4 runs | |---|---| | `origin/main` (915 tests) | ok, ok, **1 failed**, ok | | this branch (917 tests) | ok, **1 failed**, ok | Run alone, that test passes every time on both trees (3 of 3 here, 4 of 4 on main), so it is an order-of-tests or thread-timing matter in the full run rather than anything either tree changed. I have left it alone rather than fold an unrelated fix into this pull request, but CI on this branch will inherit its ~25 % failure rate, which is worth knowing before reading a red run as this change's fault. Still unverified in the game on this machine, and for the same reason as before: 3.8 GB of this card is held by other applications, and at Series X the title dies in its own code with `0x80000003` during load, before any pipeline is made. @sergiogbrox's offer to test on the desktop where the streaming burst reproduces is the check that matters.
superboynick commented 2026-11-29 15:20:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by superboynick on 2026-11-29T15:20:23Z.


A correction to my own number, before anyone acts on it: I said the watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock failure was about one full run in four. On origin/main it is rarer than that - five more full runs since (cargo test -p victory-gpu --lib, WARP, one thread) were all 915 passed, 0 failed, so what I have actually seen is one failure in nine full runs, not one in four. It has never failed when run alone (7 of 7 now on main).

The two panic sites from that one failure are still worth having, since they are two different things going wrong:

  • crates/victory-gpu/src/watch.rs:6215 - the test's own assert!(number > last[page], ...): a write through one view was not reported by writes(...) for another.
  • crates/victory-gpu/src/watch.rs:6113 - the .expect("a view") just above it: writes(...) answered None for a view the test had just mapped.

I could not capture which variant (writes_to_views_are_not_lost with which rest/unlocked) because the run that failed printed only the test names. I am not folding a fix for it into this pull request: the two sites point at different failures, and one of them (None for a live view) is worth understanding before anything is changed. Reporting it here rather than silently working around it.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7258010583 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7258010583). Originally posted by [superboynick](https://github.com/superboynick) on 2026-11-29T15:20:23Z. --- A correction to my own number, before anyone acts on it: I said the `watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock` failure was about one full run in four. On `origin/main` it is rarer than that - five more full runs since (`cargo test -p victory-gpu --lib`, WARP, one thread) were all 915 passed, 0 failed, so what I have actually seen is **one failure in nine full runs**, not one in four. It has never failed when run alone (7 of 7 now on `main`). The two panic sites from that one failure are still worth having, since they are two different things going wrong: - `crates/victory-gpu/src/watch.rs:6215` - the test's own `assert!(number > last[page], ...)`: a write through one view was not reported by `writes(...)` for another. - `crates/victory-gpu/src/watch.rs:6113` - the `.expect("a view")` just above it: `writes(...)` answered `None` for a view the test had just mapped. I could not capture which variant (`writes_to_views_are_not_lost` with which `rest`/`unlocked`) because the run that failed printed only the test names. I am not folding a fix for it into this pull request: the two sites point at different failures, and one of them (`None` for a live view) is worth understanding before anything is changed. Reporting it here rather than silently working around it.
dyshay commented 2026-11-29 15:40:04 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T15:40:04Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7258270408 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7258270408). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T15:40:04Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.
CuteBooty commented 2026-11-29 20:57:25 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CuteBooty on 2026-11-29T20:57:25Z.


Another reproduction of the never-retried 0x8007000e pipelines, on an 8 GB card, in case the numbers help this PR. This run did not include #2616, so it shows the problem, not the fix; I have not run the patch.

  • Hardware: RTX 3070 8 GB (PCIe 3.0, no Resizable BAR), Ryzen 7 5800X3D, 32 GB RAM, Windows 11.
  • Build: main 829188e96 plus #2386 (build fix only), diagnostics build. Series S console profile, 1080p, DLSS performance + frame generation 2x.
  • First start after the update, cold shader cache: about 2,500 programs were still being built for the whole 8 minutes.
  • 114 compute pipeline creations failed with hr=0x8007000e within about three minutes of play, all with retried=0. Their dispatches were dropped ("a dispatch without a host pipeline dropped").
  • Separately, the memory guard put 8 compiles off and retried them after 1 s, as expected. The 114 were not among them.
  • Free physical memory was 0.7-2.8 GB during that stretch. Card memory peaked at about 6.4 of 7.1 GB, never over budget.
  • On screen: blocky particles. No crash or device removal.
  • Two later starts of the same build (standing still, frame generation off) had zero 0x8007000e failures, which fits a memory-pressure trigger rather than a shader problem.

So, as this PR says (read from the source, not from a run with it): a pipeline refused by the driver for memory in a pressured moment is settled as refused for the whole run (pipeline/make.rs settle()). A delayed retry like the memory guard's would have recovered these.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262489225 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7262489225). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-29T20:57:25Z. --- Another reproduction of the never-retried 0x8007000e pipelines, on an 8 GB card, in case the numbers help this PR. This run did not include #2616, so it shows the problem, not the fix; I have not run the patch. - Hardware: RTX 3070 8 GB (PCIe 3.0, no Resizable BAR), Ryzen 7 5800X3D, 32 GB RAM, Windows 11. - Build: main 829188e96 plus #2386 (build fix only), diagnostics build. Series S console profile, 1080p, DLSS performance + frame generation 2x. - First start after the update, cold shader cache: about 2,500 programs were still being built for the whole 8 minutes. - 114 compute pipeline creations failed with hr=0x8007000e within about three minutes of play, all with retried=0. Their dispatches were dropped ("a dispatch without a host pipeline dropped"). - Separately, the memory guard put 8 compiles off and retried them after 1 s, as expected. The 114 were not among them. - Free physical memory was 0.7-2.8 GB during that stretch. Card memory peaked at about 6.4 of 7.1 GB, never over budget. - On screen: blocky particles. No crash or device removal. - Two later starts of the same build (standing still, frame generation off) had zero 0x8007000e failures, which fits a memory-pressure trigger rather than a shader problem. So, as this PR says (read from the source, not from a run with it): a pipeline refused by the driver for memory in a pressured moment is settled as refused for the whole run (pipeline/make.rs settle()). A delayed retry like the memory guard's would have recovered these.
SergDi commented 2026-11-30 06:32:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by SergDi on 2026-11-30T06:32:39Z.


Found a cross-worker retry-ownership race in the current 0224c2776240400d996421af38e8ae0d20000c5b implementation. OUT_OF_MEMORY is process-global, while make_with consumes it with swap(false) even when another worker owns the OOM. The per-Pending lock does not protect this across different pipelines.

A deterministic test (channels, no sleeps) reproduces:

  1. Worker A records OOM and pauses before its maker consumes the flag.
  2. Worker B finishes a different, non-OOM failed build and consumes A's flag.
  3. A resumes and is recorded as permanently refused instead of being retried.

The two patches below apply in order to this PR: the first adds the test and extracts a behavior-preserving note_out_of_memory() helper; the second uses a thread-local Cell and clears it before building, following the existing memguard pattern.

Actual Windows test tree: f72cec7714aa6d6e274b761fb6fa40bfcf44243b + #3125 (39de4d1) + this PR's diff + our test. Not the exact PR head. RED fails at the pipeline refused for memory is asked for again. Adding the fix gives 75 passed, 0 failed, 2 ignored for pipeline::.

cargo test --locked --release -p victory-gpu --lib a_refusal_for_want_of_memory -- --test-threads=1 --nocapture
# Apply pr2616-fix.patch, then:
cargo test --locked --release -p victory-gpu --lib pipeline:: -- --test-threads=1 --nocapture

The targeted regression covers cross-thread ownership; it does not independently cover the extra reset-before-build line. Final Windows Clippy diagnostic sets match the clean base (using --no-deps to reach this crate); strict Clippy is still failing baseline findings.

Two reporting caveats: existing retried/retry_made count VICTORY_SHADER_CAPS retries, not this OOM path. Our game runs reproduced memory-guard deferrals, not an intercepted driver OOM, so we cannot claim in-game efficacy or an FPS gain from this fix.

AI assistance: Codex and Claude prepared/reviewed these patches and collected the Windows test evidence.

pr2616-test.patch
diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs
index 57689019..58533fd9 100644
--- a/crates/victory-gpu/src/pipeline/make.rs
+++ b/crates/victory-gpu/src/pipeline/make.rs
@@ -2539,6 +2539,35 @@ mod tests {
         assert!(!retry_after_refusal(true, false, true, 99));
     }
 
+    /// Two workers: one's compile is refused for want of memory, and before its
+    /// maker looks, another worker's pipeline is refused for another reason
+    /// start to end. The retry goes to the first, the second stands refused.
+    #[test]
+    fn a_refusal_for_want_of_memory_is_retried_for_the_pipeline_refused_and_no_other() {
+        let short = Arc::new(Pending::new(Vec::new(), None));
+        let other = Arc::new(Pending::new(Vec::new(), None));
+        let (refused_tx, refused_rx) = std::sync::mpsc::channel();
+        let (go_tx, go_rx) = std::sync::mpsc::channel::<()>();
+        let first = short.clone();
+        let worker = std::thread::spawn(move || {
+            first.make_with(|| {
+                crate::pipeline::refused::note_out_of_memory();
+                refused_tx.send(()).unwrap();
+                go_rx.recv().unwrap();
+                None
+            });
+        });
+        refused_rx.recv().unwrap();
+        let second = other.clone();
+        std::thread::spawn(move || second.make_with(|| None)).join().unwrap();
+        go_tx.send(()).unwrap();
+        worker.join().unwrap();
+        assert!(short.made.get().is_none(), "the pipeline refused for memory is asked for again");
+        assert_eq!(short.oom_retries.load(Ordering::Relaxed), 1);
+        assert!(matches!(other.made.get(), Some(None)), "the other refusal stands for the run");
+        assert_eq!(other.oom_retries.load(Ordering::Relaxed), 0);
+    }
+
     #[test]
     fn a_refusal_of_any_other_kind_is_recorded_at_once() {
         // A shader the device cannot make, or a refusal whose memory came from the
diff --git a/crates/victory-gpu/src/pipeline/refused.rs b/crates/victory-gpu/src/pipeline/refused.rs
index 1e4c61ef..6326c7ea 100644
--- a/crates/victory-gpu/src/pipeline/refused.rs
+++ b/crates/victory-gpu/src/pipeline/refused.rs
@@ -210,6 +210,10 @@ pub(crate) fn take_out_of_memory() -> bool {
     OUT_OF_MEMORY.swap(false, std::sync::atomic::Ordering::Relaxed)
 }
 
+pub(crate) fn note_out_of_memory() {
+    OUT_OF_MEMORY.store(true, std::sync::atomic::Ordering::Relaxed);
+}
+
 /// The one code that means "no memory right now" rather than "this cannot be
 /// made": `E_OUTOFMEMORY`, as `0x8007000E`.
 const E_OUTOFMEMORY: u32 = 0x8007_000E;
@@ -255,7 +259,7 @@ pub(crate) fn failed(
     // Out of memory, with the device still there: the pipeline is not refused
     // for the run, only not made yet, and `make` asks again after its wait.
     if hr == E_OUTOFMEMORY && removed.is_none() {
-        OUT_OF_MEMORY.store(true, std::sync::atomic::Ordering::Relaxed);
+        note_out_of_memory();
     }
     let messages = host.and_then(|h| h.log_messages());
     let lacks = lacks(code);
pr2616-fix.patch
diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs
index 58533fd9..710bd4a1 100644
--- a/crates/victory-gpu/src/pipeline/make.rs
+++ b/crates/victory-gpu/src/pipeline/make.rs
@@ -407,6 +407,7 @@ impl Pending {
             let _one = self.building.lock().unwrap_or_else(|e| e.into_inner());
             if self.made.get().is_none() {
                 crate::memguard::take_deferred();
+                crate::pipeline::refused::take_out_of_memory();
                 // A failed translation must complete this queue entry and wake its waiters:
                 // a panic left `made` empty for ever and the worker thread gone with it.
                 let (built, deferred) = match catch_unwind(AssertUnwindSafe(build)) {
diff --git a/crates/victory-gpu/src/pipeline/refused.rs b/crates/victory-gpu/src/pipeline/refused.rs
index 6326c7ea..9102b210 100644
--- a/crates/victory-gpu/src/pipeline/refused.rs
+++ b/crates/victory-gpu/src/pipeline/refused.rs
@@ -194,24 +194,26 @@ struct Seen {
 
 static SEEN: Mutex<Option<Seen>> = Mutex::new(None);
 
-/// Set when the host refused a pipeline only because it ran out of memory, and
-/// the device is still there. Such a refusal says nothing about the shader: on a
-/// card whose budget is nearly spent the title's streaming runs the process past
-/// it for a second or two, and a compile that happens to land in that second is
-/// refused, while the same compile a second later succeeds (#2520, where 157
-/// pipelines stayed refused for a whole run and dropped 30-60 % of the draws
-/// after the memory had recovered).
-static OUT_OF_MEMORY: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+thread_local! {
+    /// Set when the host refused a pipeline only because it ran out of memory, and
+    /// the device is still there. Such a refusal says nothing about the shader: on a
+    /// card whose budget is nearly spent the title's streaming runs the process past
+    /// it for a second or two, and a compile that happens to land in that second is
+    /// refused, while the same compile a second later succeeds (#2520, where 157
+    /// pipelines stayed refused for a whole run and dropped 30-60 % of the draws
+    /// after the memory had recovered).
+    static OUT_OF_MEMORY: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
+}
 
-/// Whether a refusal since the last call was the host running out of memory:
+/// Whether a refusal on this thread since the last call was the host running out of memory:
 /// the caller asks this after a build came back empty, and makes the pipeline
 /// again later rather than recording it as refused for the run.
 pub(crate) fn take_out_of_memory() -> bool {
-    OUT_OF_MEMORY.swap(false, std::sync::atomic::Ordering::Relaxed)
+    OUT_OF_MEMORY.replace(false)
 }
 
 pub(crate) fn note_out_of_memory() {
-    OUT_OF_MEMORY.store(true, std::sync::atomic::Ordering::Relaxed);
+    OUT_OF_MEMORY.set(true);
 }
 
 /// The one code that means "no memory right now" rather than "this cannot be
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7270757215 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7270757215). Originally posted by [SergDi](https://github.com/SergDi) on 2026-11-30T06:32:39Z. --- Found a cross-worker retry-ownership race in the current `0224c2776240400d996421af38e8ae0d20000c5b` implementation. `OUT_OF_MEMORY` is process-global, while `make_with` consumes it with `swap(false)` even when another worker owns the OOM. The per-Pending lock does not protect this across different pipelines. A deterministic test (channels, no sleeps) reproduces: 1. Worker A records OOM and pauses before its maker consumes the flag. 2. Worker B finishes a different, non-OOM failed build and consumes A's flag. 3. A resumes and is recorded as permanently refused instead of being retried. The two patches below apply in order to this PR: the first adds the test and extracts a behavior-preserving `note_out_of_memory()` helper; the second uses a thread-local `Cell` and clears it before building, following the existing memguard pattern. **Actual Windows test tree:** `f72cec7714aa6d6e274b761fb6fa40bfcf44243b` + #3125 (`39de4d1`) + this PR's diff + our test. Not the exact PR head. RED fails at `the pipeline refused for memory is asked for again`. Adding the fix gives **75 passed, 0 failed, 2 ignored** for `pipeline::`. ```powershell cargo test --locked --release -p victory-gpu --lib a_refusal_for_want_of_memory -- --test-threads=1 --nocapture # Apply pr2616-fix.patch, then: cargo test --locked --release -p victory-gpu --lib pipeline:: -- --test-threads=1 --nocapture ``` The targeted regression covers cross-thread ownership; it does not independently cover the extra reset-before-build line. Final Windows Clippy diagnostic sets match the clean base (using `--no-deps` to reach this crate); strict Clippy is still failing baseline findings. Two reporting caveats: existing `retried`/`retry_made` count `VICTORY_SHADER_CAPS` retries, not this OOM path. Our game runs reproduced memory-guard deferrals, not an intercepted driver OOM, so we cannot claim in-game efficacy or an FPS gain from this fix. AI assistance: Codex and Claude prepared/reviewed these patches and collected the Windows test evidence. <details> <summary>pr2616-test.patch</summary> ```diff diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs index 57689019..58533fd9 100644 --- a/crates/victory-gpu/src/pipeline/make.rs +++ b/crates/victory-gpu/src/pipeline/make.rs @@ -2539,6 +2539,35 @@ mod tests { assert!(!retry_after_refusal(true, false, true, 99)); } + /// Two workers: one's compile is refused for want of memory, and before its + /// maker looks, another worker's pipeline is refused for another reason + /// start to end. The retry goes to the first, the second stands refused. + #[test] + fn a_refusal_for_want_of_memory_is_retried_for_the_pipeline_refused_and_no_other() { + let short = Arc::new(Pending::new(Vec::new(), None)); + let other = Arc::new(Pending::new(Vec::new(), None)); + let (refused_tx, refused_rx) = std::sync::mpsc::channel(); + let (go_tx, go_rx) = std::sync::mpsc::channel::<()>(); + let first = short.clone(); + let worker = std::thread::spawn(move || { + first.make_with(|| { + crate::pipeline::refused::note_out_of_memory(); + refused_tx.send(()).unwrap(); + go_rx.recv().unwrap(); + None + }); + }); + refused_rx.recv().unwrap(); + let second = other.clone(); + std::thread::spawn(move || second.make_with(|| None)).join().unwrap(); + go_tx.send(()).unwrap(); + worker.join().unwrap(); + assert!(short.made.get().is_none(), "the pipeline refused for memory is asked for again"); + assert_eq!(short.oom_retries.load(Ordering::Relaxed), 1); + assert!(matches!(other.made.get(), Some(None)), "the other refusal stands for the run"); + assert_eq!(other.oom_retries.load(Ordering::Relaxed), 0); + } + #[test] fn a_refusal_of_any_other_kind_is_recorded_at_once() { // A shader the device cannot make, or a refusal whose memory came from the diff --git a/crates/victory-gpu/src/pipeline/refused.rs b/crates/victory-gpu/src/pipeline/refused.rs index 1e4c61ef..6326c7ea 100644 --- a/crates/victory-gpu/src/pipeline/refused.rs +++ b/crates/victory-gpu/src/pipeline/refused.rs @@ -210,6 +210,10 @@ pub(crate) fn take_out_of_memory() -> bool { OUT_OF_MEMORY.swap(false, std::sync::atomic::Ordering::Relaxed) } +pub(crate) fn note_out_of_memory() { + OUT_OF_MEMORY.store(true, std::sync::atomic::Ordering::Relaxed); +} + /// The one code that means "no memory right now" rather than "this cannot be /// made": `E_OUTOFMEMORY`, as `0x8007000E`. const E_OUTOFMEMORY: u32 = 0x8007_000E; @@ -255,7 +259,7 @@ pub(crate) fn failed( // Out of memory, with the device still there: the pipeline is not refused // for the run, only not made yet, and `make` asks again after its wait. if hr == E_OUTOFMEMORY && removed.is_none() { - OUT_OF_MEMORY.store(true, std::sync::atomic::Ordering::Relaxed); + note_out_of_memory(); } let messages = host.and_then(|h| h.log_messages()); let lacks = lacks(code); ``` </details> <details> <summary>pr2616-fix.patch</summary> ```diff diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs index 58533fd9..710bd4a1 100644 --- a/crates/victory-gpu/src/pipeline/make.rs +++ b/crates/victory-gpu/src/pipeline/make.rs @@ -407,6 +407,7 @@ impl Pending { let _one = self.building.lock().unwrap_or_else(|e| e.into_inner()); if self.made.get().is_none() { crate::memguard::take_deferred(); + crate::pipeline::refused::take_out_of_memory(); // A failed translation must complete this queue entry and wake its waiters: // a panic left `made` empty for ever and the worker thread gone with it. let (built, deferred) = match catch_unwind(AssertUnwindSafe(build)) { diff --git a/crates/victory-gpu/src/pipeline/refused.rs b/crates/victory-gpu/src/pipeline/refused.rs index 6326c7ea..9102b210 100644 --- a/crates/victory-gpu/src/pipeline/refused.rs +++ b/crates/victory-gpu/src/pipeline/refused.rs @@ -194,24 +194,26 @@ struct Seen { static SEEN: Mutex<Option<Seen>> = Mutex::new(None); -/// Set when the host refused a pipeline only because it ran out of memory, and -/// the device is still there. Such a refusal says nothing about the shader: on a -/// card whose budget is nearly spent the title's streaming runs the process past -/// it for a second or two, and a compile that happens to land in that second is -/// refused, while the same compile a second later succeeds (#2520, where 157 -/// pipelines stayed refused for a whole run and dropped 30-60 % of the draws -/// after the memory had recovered). -static OUT_OF_MEMORY: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); +thread_local! { + /// Set when the host refused a pipeline only because it ran out of memory, and + /// the device is still there. Such a refusal says nothing about the shader: on a + /// card whose budget is nearly spent the title's streaming runs the process past + /// it for a second or two, and a compile that happens to land in that second is + /// refused, while the same compile a second later succeeds (#2520, where 157 + /// pipelines stayed refused for a whole run and dropped 30-60 % of the draws + /// after the memory had recovered). + static OUT_OF_MEMORY: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; +} -/// Whether a refusal since the last call was the host running out of memory: +/// Whether a refusal on this thread since the last call was the host running out of memory: /// the caller asks this after a build came back empty, and makes the pipeline /// again later rather than recording it as refused for the run. pub(crate) fn take_out_of_memory() -> bool { - OUT_OF_MEMORY.swap(false, std::sync::atomic::Ordering::Relaxed) + OUT_OF_MEMORY.replace(false) } pub(crate) fn note_out_of_memory() { - OUT_OF_MEMORY.store(true, std::sync::atomic::Ordering::Relaxed); + OUT_OF_MEMORY.set(true); } /// The one code that means "no memory right now" rather than "this cannot be ``` </details>
SergDi commented 2026-11-30 10:38:49 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by SergDi on 2026-11-30T10:38:49Z.


Follow-up to my TLS/reset proposal: I added a separate test for the pre-build reset, which the earlier cross-thread test does not cover.

This is an entry-boundary invariant, not a newly reproduced gameplay bug. I did not find a current production path that leaves a stale flag for a later make_with on the same thread: that function consumes the flag after a build; the direct warm callers do not subsequently enter it. The test makes that boundary assumption explicit.

On one dedicated thread, it seeds a stale flag before a non-OOM refusal and before a panicking build. Both must be recorded without spending an OOM retry. A control sets OOM inside the build and must still retry.

Windows / Rust 1.98.1, base file contents 41adb551 + this PR's 0224c277 diff + the two patches in my earlier comment + this new test:

Check Result
New test, TLS and reset present PASS
Remove only the pre-build reset; retain TLS Expected FAIL: a refusal of another kind is recorded at once, not retried for a stale flag
Earlier concurrency test under the same mutation PASS — it does not cover the reset
Restore reset, run pipeline:: 75 passed, 0 failed, 2 ignored
cargo test --locked --release -p victory-gpu --lib a_stale_refusal_for_memory_is_not_charged_to_the_next_build_on_the_thread -- --test-threads=1 --nocapture

The patch below applies on top of the earlier test + supplemental fix. It changes tests only. The caught synthetic panic is intentional. Clippy was run without -D warnings; no diagnostics point to the new test, but this is not a strict Clippy pass or a matched baseline comparison. No in-game benefit is claimed.

AI assistance: Claude prepared and ran the test; Codex reviewed the evidence. No game data is included.

oom-reset-test.patch — test only, atop the earlier supplemental fix
diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs
index 710bd4a..8e00537 100644
--- a/crates/victory-gpu/src/pipeline/make.rs
+++ b/crates/victory-gpu/src/pipeline/make.rs
@@ -2569,6 +2569,48 @@ mod tests {
         assert_eq!(other.oom_retries.load(Ordering::Relaxed), 0);
     }
 
+    /// One thread: a refusal for want of memory was noted outside any
+    /// [`Pending::make_with`] (as `HostPipeline::new` does when `known::make`
+    /// calls it directly) and nobody took it. The thread's next builds, one
+    /// refused for another reason and one that panics, are recorded at once;
+    /// only a refusal for memory noted during the build itself is retried.
+    /// No run path leaves the flag set today: this pins the reset before the
+    /// build, not a bug seen in a run.
+    #[test]
+    fn a_stale_refusal_for_memory_is_not_charged_to_the_next_build_on_the_thread() {
+        let refused = Arc::new(Pending::new(Vec::new(), None));
+        let panicked = Arc::new(Pending::new(Vec::new(), None));
+        let short = Arc::new(Pending::new(Vec::new(), None));
+        for p in [&refused, &panicked, &short] {
+            p.queue_state.store(MAKING, Ordering::Relaxed);
+        }
+        let (a, b, c) = (refused.clone(), panicked.clone(), short.clone());
+        let left = std::thread::spawn(move || {
+            crate::pipeline::refused::note_out_of_memory();
+            a.make_with(|| None);
+            crate::pipeline::refused::note_out_of_memory();
+            b.make_with(|| panic!("synthetic build panic after a stale refusal for memory"));
+            c.make_with(|| {
+                crate::pipeline::refused::note_out_of_memory();
+                None
+            });
+            crate::pipeline::refused::take_out_of_memory()
+        })
+        .join()
+        .unwrap();
+        for (p, what) in [(&refused, "a refusal of another kind"), (&panicked, "a panicking build")] {
+            assert!(matches!(p.made.get(), Some(None)), "{what} is recorded at once, not retried for a stale flag");
+            assert_eq!(p.oom_retries.load(Ordering::Relaxed), 0, "{what} spends no retry");
+            assert_eq!(p.queue_state.load(Ordering::Relaxed), MAKING, "{what} is not put back in the queue");
+            assert!(!p.retry_waits(), "{what} has no pause");
+        }
+        assert!(short.made.get().is_none(), "a refusal for memory during the build is still asked for again");
+        assert_eq!(short.oom_retries.load(Ordering::Relaxed), 1);
+        assert_eq!(short.queue_state.load(Ordering::Relaxed), NOT_QUEUED);
+        assert!(short.retry_waits());
+        assert!(!left, "every build takes the thread's flag");
+    }
+
     #[test]
     fn a_refusal_of_any_other_kind_is_recorded_at_once() {
         // A shader the device cannot make, or a refusal whose memory came from the
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7275885131 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7275885131). Originally posted by [SergDi](https://github.com/SergDi) on 2026-11-30T10:38:49Z. --- Follow-up to my [TLS/reset proposal](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2616#issuecomment-7270757215): I added a separate test for the **pre-build reset**, which the earlier cross-thread test does not cover. This is an entry-boundary invariant, **not a newly reproduced gameplay bug**. I did not find a current production path that leaves a stale flag for a later `make_with` on the same thread: that function consumes the flag after a build; the direct warm callers do not subsequently enter it. The test makes that boundary assumption explicit. On one dedicated thread, it seeds a stale flag before a non-OOM refusal and before a panicking build. Both must be recorded without spending an OOM retry. A control sets OOM inside the build and must still retry. Windows / Rust 1.98.1, base file contents `41adb551` + this PR's `0224c277` diff + the two patches in my earlier comment + this new test: | Check | Result | |---|---| | New test, TLS and reset present | PASS | | Remove **only** the pre-build reset; retain TLS | Expected FAIL: `a refusal of another kind is recorded at once, not retried for a stale flag` | | Earlier concurrency test under the same mutation | PASS — it does not cover the reset | | Restore reset, run `pipeline::` | 75 passed, 0 failed, 2 ignored | ```powershell cargo test --locked --release -p victory-gpu --lib a_stale_refusal_for_memory_is_not_charged_to_the_next_build_on_the_thread -- --test-threads=1 --nocapture ``` The patch below applies on top of the earlier test + supplemental fix. It changes tests only. The caught synthetic panic is intentional. Clippy was run without `-D warnings`; no diagnostics point to the new test, but this is not a strict Clippy pass or a matched baseline comparison. No in-game benefit is claimed. AI assistance: Claude prepared and ran the test; Codex reviewed the evidence. No game data is included. <details> <summary>oom-reset-test.patch — test only, atop the earlier supplemental fix</summary> ```diff diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs index 710bd4a..8e00537 100644 --- a/crates/victory-gpu/src/pipeline/make.rs +++ b/crates/victory-gpu/src/pipeline/make.rs @@ -2569,6 +2569,48 @@ mod tests { assert_eq!(other.oom_retries.load(Ordering::Relaxed), 0); } + /// One thread: a refusal for want of memory was noted outside any + /// [`Pending::make_with`] (as `HostPipeline::new` does when `known::make` + /// calls it directly) and nobody took it. The thread's next builds, one + /// refused for another reason and one that panics, are recorded at once; + /// only a refusal for memory noted during the build itself is retried. + /// No run path leaves the flag set today: this pins the reset before the + /// build, not a bug seen in a run. + #[test] + fn a_stale_refusal_for_memory_is_not_charged_to_the_next_build_on_the_thread() { + let refused = Arc::new(Pending::new(Vec::new(), None)); + let panicked = Arc::new(Pending::new(Vec::new(), None)); + let short = Arc::new(Pending::new(Vec::new(), None)); + for p in [&refused, &panicked, &short] { + p.queue_state.store(MAKING, Ordering::Relaxed); + } + let (a, b, c) = (refused.clone(), panicked.clone(), short.clone()); + let left = std::thread::spawn(move || { + crate::pipeline::refused::note_out_of_memory(); + a.make_with(|| None); + crate::pipeline::refused::note_out_of_memory(); + b.make_with(|| panic!("synthetic build panic after a stale refusal for memory")); + c.make_with(|| { + crate::pipeline::refused::note_out_of_memory(); + None + }); + crate::pipeline::refused::take_out_of_memory() + }) + .join() + .unwrap(); + for (p, what) in [(&refused, "a refusal of another kind"), (&panicked, "a panicking build")] { + assert!(matches!(p.made.get(), Some(None)), "{what} is recorded at once, not retried for a stale flag"); + assert_eq!(p.oom_retries.load(Ordering::Relaxed), 0, "{what} spends no retry"); + assert_eq!(p.queue_state.load(Ordering::Relaxed), MAKING, "{what} is not put back in the queue"); + assert!(!p.retry_waits(), "{what} has no pause"); + } + assert!(short.made.get().is_none(), "a refusal for memory during the build is still asked for again"); + assert_eq!(short.oom_retries.load(Ordering::Relaxed), 1); + assert_eq!(short.queue_state.load(Ordering::Relaxed), NOT_QUEUED); + assert!(short.retry_waits()); + assert!(!left, "every build takes the thread's flag"); + } + #[test] fn a_refusal_of_any_other_kind_is_recorded_at_once() { // A shader the device cannot make, or a refusal whose memory came from the ``` </details>
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
trustno1-coder/VIctory-NVIDIA!2616
No description provided.