From 6917be2911518e572858ad15c6884a8e28279679 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Fri, 28 Jan 2022 17:46:14 +0100 Subject: [PATCH 1/2] Identify Apple M1 GPU as integrated --- wgpu-hal/src/gles/adapter.rs | 1 + wgpu-hal/src/metal/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index bcac8bf318..87307ac27f 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -118,6 +118,7 @@ impl super::Adapter { "mali", "intel", "v3d", + "apple m1", ]; let strings_that_imply_cpu = ["mesa offscreen", "swiftshader", "llvmpipe"]; diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index dd8fee1840..1fd0a7b522 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -108,13 +108,14 @@ impl crate::Instance for Instance { .into_iter() .map(|dev| { let name = dev.name().into(); + let has_unified_memory = dev.has_unified_memory(); let shared = AdapterShared::new(dev); crate::ExposedAdapter { info: wgt::AdapterInfo { name, vendor: 0, device: 0, - device_type: if shared.private_caps.low_power { + device_type: if has_unified_memory { wgt::DeviceType::IntegratedGpu } else { wgt::DeviceType::DiscreteGpu From ea4ca325b4bbab2e1a5b64f5a4e7e83eb33679d4 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Fri, 28 Jan 2022 23:16:22 +0100 Subject: [PATCH 2/2] metal: Call has_unified_memory conditional on OS version Fall back to current low_power implies integrated GPU for older OSes. --- wgpu-hal/src/metal/adapter.rs | 15 +++++++++++++++ wgpu-hal/src/metal/mod.rs | 8 ++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 1a05240ccd..9ce28eef19 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -988,6 +988,21 @@ impl super::PrivateCapabilities { } else { Self::version_at_least(major, minor, 13, 0) }, + has_unified_memory: if (os_is_mac && Self::version_at_least(major, minor, 10, 15)) + || (!os_is_mac && Self::version_at_least(major, minor, 13, 0)) + { + Some(device.has_unified_memory()) + } else { + None + }, + } + } + + pub fn device_type(&self) -> wgt::DeviceType { + if self.has_unified_memory.unwrap_or(self.low_power) { + wgt::DeviceType::IntegratedGpu + } else { + wgt::DeviceType::DiscreteGpu } } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 1fd0a7b522..1dd3e252c2 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -108,18 +108,13 @@ impl crate::Instance for Instance { .into_iter() .map(|dev| { let name = dev.name().into(); - let has_unified_memory = dev.has_unified_memory(); let shared = AdapterShared::new(dev); crate::ExposedAdapter { info: wgt::AdapterInfo { name, vendor: 0, device: 0, - device_type: if has_unified_memory { - wgt::DeviceType::IntegratedGpu - } else { - wgt::DeviceType::DiscreteGpu - }, + device_type: shared.private_caps.device_type(), backend: wgt::Backend::Metal, }, features: shared.private_caps.features(), @@ -231,6 +226,7 @@ struct PrivateCapabilities { supports_mutability: bool, supports_depth_clip_control: bool, supports_preserve_invariance: bool, + has_unified_memory: Option, } #[derive(Clone, Debug)]