diff --git a/crates/gpu/src/path/mod.rs b/crates/gpu/src/path/mod.rs index c649449b2..3f52e317e 100644 --- a/crates/gpu/src/path/mod.rs +++ b/crates/gpu/src/path/mod.rs @@ -92,11 +92,16 @@ pub fn host() -> Result { /// Open an independent job device on the viewport's selected adapter. In particular, /// software fallback and safe mode must not rediscover a failing hardware driver. /// An explicit incompatible SOLIDCRAFT_GPU policy leaves this executor unavailable. -/// The path tracer runs on Vulkan only: a viewport on another backend is reopened on the same -/// GPU through Vulkan, and without one the executor is unavailable and images render on the CPU. +/// The path tracer runs on Vulkan only. On Windows it must keep the viewport's backend: +/// opening Vulkan drivers that startup avoided can crash inside native driver code. +/// Elsewhere a viewport on another backend is reopened on the same GPU through Vulkan. +/// Without a usable Vulkan adapter the executor is unavailable; CPU image methods remain usable. pub fn host_on_adapter(adapter: &wgpu::Adapter) -> Result { let policy = crate::select::Policy::from_env().map_err(gpu)?; let info = adapter.get_info(); + if !viewport_path_backends(info.backend, cfg!(target_os = "windows")).contains(wgpu::Backends::VULKAN) { + return Err(gpu(format!("{VULKAN_ONLY}; the viewport uses {:?}", info.backend))); + } if !policy.admits(crate::select::tier_of(info.device_type)) { return Err(gpu(format!("viewport adapter does not satisfy SOLIDCRAFT_GPU={}", policy.name()))); } @@ -115,6 +120,11 @@ pub fn host_on_adapter(adapter: &wgpu::Adapter) -> Result { // D3D12 shader compilation is avoided; the user can select a CPU image method instead. const VULKAN_ONLY: &str = "the GPU path tracer requires a Vulkan driver; select a CPU image method when Vulkan is unavailable"; +/// Backends a viewport's path device may open, before any driver is loaded. +fn viewport_path_backends(backend: wgpu::Backend, windows: bool) -> wgpu::Backends { + if windows { wgpu::Backends::from(backend) } else { wgpu::Backends::VULKAN } +} + // Path resources need six storage buffers (geometry, BVH, accumulation, HDRI, // textures, medium-failure counts). Request that limit only on this independent path device: raster and // tessellation keep their existing four-buffer downlevel requirement. diff --git a/crates/gpu/src/path/tests.rs b/crates/gpu/src/path/tests.rs index bb2ef4c3f..055c5565e 100644 --- a/crates/gpu/src/path/tests.rs +++ b/crates/gpu/src/path/tests.rs @@ -543,6 +543,22 @@ fn path_devices_are_vulkan_only() { } } +#[test] +fn viewport_path_backends_keep_windows_on_its_selected_backend() { + for backend in [wgpu::Backend::Dx12, wgpu::Backend::Gl, wgpu::Backend::Vulkan] { + let allowed = viewport_path_backends(backend, true); + assert_eq!(allowed, wgpu::Backends::from(backend)); + assert_eq!(allowed.contains(wgpu::Backends::VULKAN), backend == wgpu::Backend::Vulkan); + } +} + +#[test] +fn viewport_path_backends_preserve_other_platforms() { + for backend in [wgpu::Backend::Vulkan, wgpu::Backend::Gl, wgpu::Backend::Metal] { + assert_eq!(viewport_path_backends(backend, false), wgpu::Backends::VULKAN); + } +} + #[test] fn admission_rejects_hostile_parameters_and_transparency() { let mut scene = sphere(white());