From 06d8c1bfa854c06879827da9a61960122f7c9cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20B=C5=82asik?= Date: Mon, 26 Oct 2026 17:08:21 +0100 Subject: [PATCH 1/2] claim: #7183 From 6fb1d9a0e6b42e8e4dd505f3fadfb98ba139fef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20B=C5=82asik?= Date: Mon, 26 Oct 2026 17:02:46 +0100 Subject: [PATCH 2/2] GPU path tracer runs on Metal on macOS, not only Vulkan (#3217) --- .../examples/studio_evidence.rs | 2 +- crates/gpu/src/path/denoise_tests.rs | 8 ++--- crates/gpu/src/path/mod.rs | 18 +++++------ crates/gpu/src/path/tests.rs | 30 +++++++++---------- crates/gpu/src/select.rs | 22 +++++++++----- crates/ui-egui/src/render_workspace_tests.rs | 3 +- docs/render-path.md | 4 +-- 7 files changed, 45 insertions(+), 42 deletions(-) diff --git a/apps/solidcraft-cli/examples/studio_evidence.rs b/apps/solidcraft-cli/examples/studio_evidence.rs index e6076443ec7..92572c3ac2d 100644 --- a/apps/solidcraft-cli/examples/studio_evidence.rs +++ b/apps/solidcraft-cli/examples/studio_evidence.rs @@ -87,7 +87,7 @@ fn run() -> Result<(), String> { let gpu_host_start = Instant::now(); let policy = solidcraft_gpu::select::Policy::from_env().map_err(|e| e.to_string())?; let (adapter, report) = - solidcraft_gpu::select::pick_vulkan(policy, |_| true).ok_or("no Vulkan adapter satisfies the requested GPU policy")?; + solidcraft_gpu::select::pick_path(policy, |_| true).ok_or("no Vulkan or Metal adapter satisfies the requested GPU policy")?; session.register_render_job_host(solidcraft_gpu::path::host_on_adapter(&adapter).map_err(|e| e.to_string())?).map_err(|e| e.to_string())?; (Some(report), Some(gpu_host_start.elapsed().as_secs_f64())) } else { diff --git a/crates/gpu/src/path/denoise_tests.rs b/crates/gpu/src/path/denoise_tests.rs index 9d7225b6ce2..8c219ea98a2 100644 --- a/crates/gpu/src/path/denoise_tests.rs +++ b/crates/gpu/src/path/denoise_tests.rs @@ -144,10 +144,10 @@ fn context() -> Option> { let (_, device, queue) = match open_headless() { Ok(v) => v, Err(e) => { - // The path tracer runs on Vulkan only: where the backends in use leave Vulkan out - // (macOS, or `WGPU_BACKEND=dx12`), it is unavailable by design, not missing. - let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN); - assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}"); + // The path tracer runs on Vulkan or Metal only: where the backends in use leave both out + // (`WGPU_BACKEND=dx12`), it is unavailable by design, not missing. + let available = !crate::select::path_backends().is_empty(); + assert!(!available || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}"); return None; } }; diff --git a/crates/gpu/src/path/mod.rs b/crates/gpu/src/path/mod.rs index c649449b263..bddc888b052 100644 --- a/crates/gpu/src/path/mod.rs +++ b/crates/gpu/src/path/mod.rs @@ -92,19 +92,19 @@ 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, or Metal on macOS: a viewport on another backend is reopened on the same +/// GPU through one of them, and without one the executor is unavailable and images render on the CPU. 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 !policy.admits(crate::select::tier_of(info.device_type)) { return Err(gpu(format!("viewport adapter does not satisfy SOLIDCRAFT_GPU={}", policy.name()))); } - if info.backend != wgpu::Backend::Vulkan { - let (vulkan, _) = crate::select::pick_vulkan(policy, |i| i.vendor == info.vendor && i.device == info.device) + if !matches!(info.backend, wgpu::Backend::Vulkan | wgpu::Backend::Metal) { + let (picked, _) = crate::select::pick_path(policy, |i| i.vendor == info.vendor && i.device == info.device) .ok_or_else(|| gpu(format!("{VULKAN_ONLY}; the viewport uses {:?}", info.backend)))?; - let (device, queue) = open_device(&vulkan)?; - log::info!("gpu-path viewport GPU: {} through Vulkan", info.name); + let (device, queue) = open_device(&picked)?; + log::info!("gpu-path viewport GPU: {} through Vulkan or Metal", info.name); return ImageHost::with_executor(Arc::new(Executor::new(device, queue)?)); } let (device, queue) = open_device(adapter)?; @@ -113,7 +113,7 @@ 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"; +const VULKAN_ONLY: &str = "the GPU path tracer requires a Vulkan driver (Metal on macOS); select a CPU image method when none is available"; // 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 @@ -145,8 +145,8 @@ fn open_device(adapter: &wgpu::Adapter) -> Result<(wgpu::Device, wgpu::Queue)> { } fn open_headless() -> Result<(wgpu::Adapter, wgpu::Device, wgpu::Queue)> { let policy = crate::select::Policy::from_env().map_err(gpu)?; - let (adapter, _) = crate::select::pick_vulkan(policy, |_| true) - .ok_or_else(|| gpu(format!("{VULKAN_ONLY}; no Vulkan adapter satisfies SOLIDCRAFT_GPU={}", policy.name())))?; + let (adapter, _) = crate::select::pick_path(policy, |_| true) + .ok_or_else(|| gpu(format!("{VULKAN_ONLY}; no Vulkan or Metal adapter satisfies SOLIDCRAFT_GPU={}", policy.name())))?; let (device, queue) = open_device(&adapter)?; Ok((adapter, device, queue)) } diff --git a/crates/gpu/src/path/tests.rs b/crates/gpu/src/path/tests.rs index bb2ef4c3f2d..6948e0e4889 100644 --- a/crates/gpu/src/path/tests.rs +++ b/crates/gpu/src/path/tests.rs @@ -6,10 +6,10 @@ fn executor() -> Option { let (adapter, device, queue) = match open_headless() { Ok(device) => device, Err(e) => { - // The path tracer runs on Vulkan only: where the backends in use leave Vulkan out - // (macOS, or `WGPU_BACKEND=dx12`), it is unavailable by design, not missing. - let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN); - assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}"); + // The path tracer runs on Vulkan or Metal only: where the backends in use leave both out + // (`WGPU_BACKEND=dx12`), it is unavailable by design, not missing. + let available = !crate::select::path_backends().is_empty(); + assert!(!available || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}"); eprintln!("gpu-path device test skipped: {e}"); return None; } @@ -529,16 +529,14 @@ fn shader_validates_without_a_device() { naga::valid::Validator::new(naga::valid::ValidationFlags::all(), naga::valid::Capabilities::empty()).validate(&module).unwrap(); } -/// #3217: the path tracer opens Vulkan adapters only, and none where the platform has no -/// Vulkan backend (macOS). +/// #3217: the path tracer opens Vulkan adapters, or Metal on macOS, never D3D12 or GL. #[test] -fn path_devices_are_vulkan_only() { - let picked = crate::select::pick_vulkan(crate::select::Policy::Auto, |_| true); - if let Some((adapter, report)) = &picked { - assert_eq!(adapter.get_info().backend, wgpu::Backend::Vulkan); - assert_eq!(report.backend, "Vulkan"); +fn path_devices_are_vulkan_or_metal_only() { + let picked = crate::select::pick_path(crate::select::Policy::Auto, |_| true); + if let Some((adapter, _)) = &picked { + assert!(matches!(adapter.get_info().backend, wgpu::Backend::Vulkan | wgpu::Backend::Metal)); } - if cfg!(target_os = "macos") || !crate::select::native_backends().contains(wgpu::Backends::VULKAN) { + if crate::select::path_backends().is_empty() { assert!(picked.is_none()); } } @@ -3213,8 +3211,8 @@ fn display_bloom_slices_refuse_invalid_ranges_without_panicking() { fn cancelled_environment_preparation_unwinds_gpu_error_scopes() { use solidcraft_render::lighting::environment::EnvironmentSource; let Ok((_, device, _queue)) = open_headless() else { - let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN); - assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required Vulkan device unavailable"); + let available = !crate::select::path_backends().is_empty(); + assert!(!available || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required Vulkan device unavailable"); return; }; let mut image = request(1); @@ -3239,8 +3237,8 @@ fn cancelled_environment_preparation_unwinds_gpu_error_scopes() { #[test] fn failed_resource_creation_unwinds_gpu_error_scopes() { let Ok((_, device, _queue)) = open_headless() else { - let vulkan = crate::select::native_backends().contains(wgpu::Backends::VULKAN); - assert!(!vulkan || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required Vulkan device unavailable"); + let available = !crate::select::path_backends().is_empty(); + assert!(!available || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required Vulkan device unavailable"); return; }; let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { diff --git a/crates/gpu/src/select.rs b/crates/gpu/src/select.rs index 24c92cd4b2a..e5507034de3 100644 --- a/crates/gpu/src/select.rs +++ b/crates/gpu/src/select.rs @@ -201,18 +201,24 @@ pub fn survey(policy: Policy) -> Survey { Survey { backends: format!("{:?}", native_backends()), adapters: found, chosen, lands_on } } -/// The Vulkan adapter `policy` picks among those `keep` accepts, with its report; `None` where -/// the native backends (or `WGPU_BACKEND`) leave out Vulkan, as on macOS. The GPU path tracer -/// runs on Vulkan only (#3217): D3D12 was never faster in our measurements and needs minutes to -/// compile its shader at every start, where Vulkan keeps compiled pipelines between runs. +/// The backends the GPU path tracer may use among the native ones: Vulkan, and Metal on macOS +/// (D3D12 is out, #3217: it was never faster in our measurements and needs minutes to compile +/// its shader at every start, where Vulkan keeps compiled pipelines between runs). +pub fn path_backends() -> wgpu::Backends { + native_backends() & (wgpu::Backends::VULKAN | wgpu::Backends::METAL) +} + +/// The path-tracer adapter `policy` picks among those `keep` accepts, with its report; `None` +/// where `path_backends` is empty (`WGPU_BACKEND=dx12`) or no adapter qualifies. #[cfg(not(target_arch = "wasm32"))] -pub fn pick_vulkan(policy: Policy, keep: impl Fn(&wgpu::AdapterInfo) -> bool) -> Option<(wgpu::Adapter, AdapterReport)> { - if !native_backends().contains(wgpu::Backends::VULKAN) { +pub fn pick_path(policy: Policy, keep: impl Fn(&wgpu::AdapterInfo) -> bool) -> Option<(wgpu::Adapter, AdapterReport)> { + let backends = path_backends(); + if backends.is_empty() { return None; } let mut desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env(); - desc.backends = wgpu::Backends::VULKAN; - let mut all = pollster::block_on(wgpu::Instance::new(desc).enumerate_adapters(wgpu::Backends::VULKAN)); + desc.backends = backends; + let mut all = pollster::block_on(wgpu::Instance::new(desc).enumerate_adapters(backends)); all.sort_by_key(|a| std::cmp::Reverse(rank(a.get_info().device_type))); all.into_iter() .filter(|a| keep(&a.get_info())) diff --git a/crates/ui-egui/src/render_workspace_tests.rs b/crates/ui-egui/src/render_workspace_tests.rs index 9890c62fa93..0e9e5dcbc1e 100644 --- a/crates/ui-egui/src/render_workspace_tests.rs +++ b/crates/ui-egui/src/render_workspace_tests.rs @@ -481,8 +481,7 @@ fn progressive_image_controls_route_to_the_registered_host() { let host = match host { Ok(host) => host, Err(e) => { - let vulkan = egui_wgpu::wgpu::Backends::VULKAN; - let expected = solidcraft_gpu::select::native_backends().contains(vulkan); + let expected = !solidcraft_gpu::select::path_backends().is_empty(); assert!(!expected || std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none(), "required GPU unavailable: {e}"); eprintln!("skipping progressive UI device test: {e}"); return; diff --git a/docs/render-path.md b/docs/render-path.md index dee75016474..d121dae265a 100644 --- a/docs/render-path.md +++ b/docs/render-path.md @@ -17,8 +17,8 @@ the pending/ready/failed host, and failures are not retried on each viewport ins It opens its independent job device on the viewport's selected adapter, so software fallback and safe mode do not rediscover a failing hardware driver. An incompatible explicit GPU policy leaves progressive rendering unavailable there. -The path tracer runs on Vulkan only (#3217). A viewport on D3D12 is reopened on the -same GPU through Vulkan. Where there is no Vulkan driver (macOS for now, Windows over +The path tracer runs on Vulkan, or on Metal on macOS (#3217). A viewport on D3D12 is reopened on the +same GPU through Vulkan. Where there is no Vulkan or Metal driver (Windows over Remote Desktop or on the WARP software adapter, older drivers), the path executor reports itself unavailable and images render on the CPU. On an RTX 4090, D3D12 was never faster: equal per sample with DXC and about 55% slower with FXC, and it compiles the path shader