From 4f5ae578c848469f64a0fded6bf38c65dce65ae6 Mon Sep 17 00:00:00 2001 From: fxceless <36782933+fxceless@users.noreply.github.com> Date: Fri, 27 Nov 2026 23:08:32 +0300 Subject: [PATCH] GPU: a panicking pipeline build is refused and its worker carries on A panic inside `HostPipeline::new` (a translator gap, an unexpected shader form) unwound out of `make`, leaving `made` empty for ever: every draw or dispatch waiting on that pipeline waited to its budget in every frame, and the worker thread that hit it was gone. The build now runs under `catch_unwind`; a panic is logged and recorded as "no host pipeline" like a failed translation, so the queue entry completes and its waiters wake. Ported from fxceless/victory-fork 46da5eec (pull request #1353), GPL-3.0-or-later. (cherry picked from commit 52331a3b95ab28d21820cc187bfe8e8842062090) --- crates/victory-gpu/src/pipeline/make.rs | 38 ++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs index daa9028..226f478 100644 --- a/crates/victory-gpu/src/pipeline/make.rs +++ b/crates/victory-gpu/src/pipeline/make.rs @@ -22,6 +22,7 @@ //! 18e57db8 found the same). use std::collections::VecDeque; +use std::panic::{AssertUnwindSafe, catch_unwind}; use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering}; use std::sync::{Arc, Condvar, Mutex, OnceLock}; use std::time::{Duration, Instant}; @@ -183,12 +184,26 @@ impl Pending { } fn make(&self) { - self.made.get_or_init(|| { + self.make_with(|| { let began = Instant::now(); let made = HostPipeline::new(&self.shaders, self.graphics.as_deref()); super::library::note_time(&self.key, began.elapsed().as_millis() as u64); made }); + } + + fn make_with(&self, build: impl FnOnce() -> Option) { + self.made.get_or_init(|| { + // 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. + match catch_unwind(AssertUnwindSafe(build)) { + Ok(pipeline) => pipeline, + Err(_) => { + tracing::warn!(shaders = ?self.shaders, "host pipeline build panicked"); + None + } + } + }); let (lock, done) = &DONE; let _held = lock.lock().unwrap_or_else(|e| e.into_inner()); done.notify_all(); @@ -647,6 +662,27 @@ mod tests { assert!(matches!(p.made.get(), Some(None))); } + /// A panic inside a build must not take the worker thread with it, nor + /// leave the queue entry open for ever. + #[test] + fn a_panicking_pipeline_is_refused_and_the_worker_continues() { + let bad = Arc::new(Pending::new(Vec::new(), None)); + let good = Arc::new(Pending::new(Vec::new(), None)); + let failed = bad.clone(); + let next = good.clone(); + let worker = std::thread::spawn(move || { + failed.make_with(|| panic!("synthetic pipeline build panic")); + next.make_with(|| None); + }); + + worker.join().expect("the pipeline worker should survive"); + assert!(matches!(bad.made.get(), Some(None))); + assert!(matches!(good.made.get(), Some(None))); + + bad.make_with(|| panic!("the refused pipeline should stay complete")); + assert!(matches!(bad.made.get(), Some(None))); + } + /// A pipeline left out on purpose (a ray-tracing resolve without the structure builder) /// is never queued, so never made: it is counted as left out, and named so, not as /// "being made" (some 630 indirect dispatches a frame were, in every gameplay frame).