From b702ce8c7df9ceeb2fb7db9883301399c511c9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathalie=20Sch=C3=B6nwetter?= <1506194+Make-o-Rama@users.noreply.github.com> Date: Sat, 24 Oct 2026 21:52:55 +0000 Subject: [PATCH] fix: start the window on Intel Macs without wgpu's indirect-call validation (#3024) (#4808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nathalie Schönwetter Co-authored-by: Claude Sonnet 5.5 --- apps/solidcraft/src/main.rs | 3 +++ apps/solidcraft/src/startup.rs | 25 +++++++++++++++++++++++++ docs/book/src/guide/troubleshooting.md | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rs index dcec873dc..9e1ca38ac 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::WgpuC eprintln!("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.rs index 5321fd284..a88c4e9ca 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.md index 6fe0f4ce7..100c0091f 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 an issue. +- 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