SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
fix: start the window on Intel Macs without wgpu's indirect-call validation (#3024) (#4808)
Nathalie Schönwetterb702ce8c7df9
diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rsindex dcec873dce..9e1ca38acb 100644--- a/apps/solidcraft/src/main.rs+++ b/apps/solidcraft/src/main.rs@@ -871,6 +871,9 @@ fn wgpu_options(cpu: bool, preference: Option<&str>) -> eframe::egui_wgpu::WgpuCeprintln!("SolidCraft graphics: starting {backends:?}");setup.instance_descriptor.backends = backends;}+ let intel_mac = cfg!(all(target_os = "macos", target_arch = "x86_64"));+ let indirect = std::env::var(startup::INDIRECT_VALIDATION_ENV).ok();+ setup.instance_descriptor.flags = startup::window_instance_flags(setup.instance_descriptor.flags, intel_mac, indirect.as_deref());if cpu {setup.native_adapter_selector = Some(std::sync::Arc::new(startup::pick_cpu_adapter));}diff --git a/apps/solidcraft/src/startup.rs b/apps/solidcraft/src/startup.rsindex 5321fd2849..a88c4e9ca1 100644--- a/apps/solidcraft/src/startup.rs+++ b/apps/solidcraft/src/startup.rs@@ -208,6 +208,18 @@ pub fn has_hardware_adapter(backends: eframe::wgpu::Backends) -> bool {adapters.iter().any(|a| a.get_info().device_type != eframe::wgpu::DeviceType::Cpu)}+/// The environment variable that switches wgpu's indirect-call validation on or off.+pub const INDIRECT_VALIDATION_ENV: &str = "WGPU_VALIDATION_INDIRECT_CALL";++/// The instance flags for the window. wgpu's indirect-call validation compiles a compute shader+/// when the device is created, and on Intel Macs (macOS 12 with Intel Iris graphics, #3024,+/// #3080, #4605) the Metal compiler refuses it: the device is lost and the window never opens.+/// So on an Intel Mac the validation is left off, unless the user turned it on or off with+/// `WGPU_VALIDATION_INDIRECT_CALL` themselves.+pub fn window_instance_flags(flags: eframe::wgpu::InstanceFlags, intel_mac: bool, env: Option<&str>) -> eframe::wgpu::InstanceFlags {+ if intel_mac && env.map(str::trim).is_none_or(str::is_empty) { flags - eframe::wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL } else { flags }+}+/// The message shown when no window could be opened at all.pub fn no_window_message(error: &str, settings: Option<&Path>) -> String {let folder = settings.map(|d| d.display().to_string()).unwrap_or_else(|| "the SolidCraft settings folder".into());@@ -246,6 +258,19 @@ mod tests {assert!(settings_directory(Some(file.as_os_str()), Some(default)).is_err());}+ #[test]+ fn intel_macs_start_without_indirect_call_validation() {+ use eframe::wgpu::InstanceFlags as F;+ let on = F::VALIDATION | F::VALIDATION_INDIRECT_CALL;+ assert_eq!(window_instance_flags(on, true, None), F::VALIDATION);+ assert_eq!(window_instance_flags(on, true, Some(" ")), F::VALIDATION);+ // The user's own choice stands, on or off.+ assert_eq!(window_instance_flags(on, true, Some("1")), on);+ assert_eq!(window_instance_flags(F::VALIDATION, true, Some("0")), F::VALIDATION);+ // Every other machine keeps what it had.+ assert_eq!(window_instance_flags(on, false, None), on);+ }+#[test]fn switches_read_from_the_environment() {assert!(env_on(Some("1")) && env_on(Some("yes")) && !env_on(Some("0")) && !env_on(Some(" ")) && !env_on(None) && !env_on(Some("false")));diff --git a/docs/book/src/guide/troubleshooting.md b/docs/book/src/guide/troubleshooting.mdindex 6fe0f4ce79..100c0091fe 100644--- a/docs/book/src/guide/troubleshooting.md+++ b/docs/book/src/guide/troubleshooting.md@@ -61,6 +61,10 @@ saying what failed (earlier versions closed without a word). Things to try:- In a virtual machine, turn on 3D acceleration. Over Remote Desktop, try it on the machine itself.- Run `solidcraft --crash-log` to list recent crash reports, and attach the newest one to anissue.+- On an Intel Mac (Intel Iris graphics, macOS 12), "Parent device is lost" at start comes from+ the Metal compiler refusing wgpu's indirect-call validation shader. SolidCraft leaves that+ validation off on Intel Macs. To change it, set `WGPU_VALIDATION_INDIRECT_CALL=1` (on) or `0`+ (off) before starting; a value you set is always kept.## The desktop stutters or freezes while SolidCraft builds bodies