SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
GPU path tracer: compile the path pipeline one at a time per process (#6706) (#6813)
Frank2aa45ef3ee2c
diff --git a/crates/gpu/src/path/mod.rs b/crates/gpu/src/path/mod.rsindex 6215400cc7..41d19e3cfe 100644--- a/crates/gpu/src/path/mod.rs+++ b/crates/gpu/src/path/mod.rs@@ -217,6 +217,7 @@ impl Executor {lost.store(false, Ordering::Release);log::warn!("gpu-path device lost ({reason:?}); executor unavailable: {message}");});+ let compiling = one_compile_at_a_time();let scopes = scopes(&device);let shader =device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("gpu-path"), source: wgpu::ShaderSource::Wgsl(SHADER.into()) });@@ -251,11 +252,21 @@ impl Executor {cache: None,});checked(scopes)?;+ drop(compiling);warm_up(&device, &queue, &pipeline, &placeholder_bind(&device, &layout, 7)?, &healthy)?;Ok(Self { context: Arc::new(Context { healthy, device, queue, pipeline, layout, denoise: std::sync::OnceLock::new() }) })}}+/// Native drivers compile the path pipeline for minutes and gigabytes on a cold shader cache.+/// Executors opened side by side (parallel tests, each on its own device) compiled it together+/// until memory ran out (#6706). One compile at a time per process: the first fills the driver's+/// cache, and the waiting ones then get it from there.+fn one_compile_at_a_time() -> std::sync::MutexGuard<'static, ()> {+ static COMPILE: std::sync::Mutex<()> = std::sync::Mutex::new(());+ COMPILE.lock().unwrap_or_else(std::sync::PoisonError::into_inner)+}+// Small zeroed bindings: binding 0 is a uniform whose zero work count makes every// invocation return at once; the others are storage buffers.fn placeholder_bind(device: &wgpu::Device, layout: &wgpu::BindGroupLayout, count: u32) -> Result<wgpu::BindGroup> {diff --git a/crates/gpu/src/path/tests.rs b/crates/gpu/src/path/tests.rsindex 77d6fe18e6..ea150c0733 100644--- a/crates/gpu/src/path/tests.rs+++ b/crates/gpu/src/path/tests.rs@@ -593,6 +593,25 @@ fn path_devices_are_vulkan_or_metal_only() {}}+/// #6706: executors opened side by side never compile the path pipeline at the same time.+#[test]+fn path_pipelines_compile_one_at_a_time() {+ use std::sync::atomic::AtomicUsize;+ let inside = AtomicUsize::new(0);+ let most = AtomicUsize::new(0);+ std::thread::scope(|scope| {+ for _ in 0..8 {+ scope.spawn(|| {+ let _compiling = one_compile_at_a_time();+ most.fetch_max(inside.fetch_add(1, Ordering::SeqCst) + 1, Ordering::SeqCst);+ std::thread::sleep(Duration::from_millis(5));+ inside.fetch_sub(1, Ordering::SeqCst);+ });+ }+ });+ assert_eq!(most.load(Ordering::SeqCst), 1);+}+#[test]fn viewport_path_backends_keep_windows_on_its_selected_backend() {for backend in [wgpu::Backend::Dx12, wgpu::Backend::Gl, wgpu::Backend::Vulkan] {