From c1e18059f891d34ade1db2de10e3a41fa64ce9c4 Mon Sep 17 00:00:00 2001 From: Emily Date: Wed, 3 Jul 2024 14:12:24 +0100 Subject: [PATCH] gpui: Prefer integrated GPUs on Intel Mac (#13685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Intel, Metal will pick a discrete GPU by default when available, resulting in higher power consumption and heat output. Prefer non‐removable low‐power devices to correct this. On Apple Silicon, there is only ever one GPU, so there is no functional change. I didn’t do intensive benchmarking of this or anything, but Zed still seems responsive and it stops my MacBook Pro acting as a combination space heater–jet engine. Thanks to @denlukia for showing that this is easy to fix; I’ve marked you as a co‐author, I hope that’s okay. Closes: #5124 Release Notes: - Improved power consumption on Intel Macs by preferring integrated GPUs over the discrete GPUs. ([#5124](https://github.com/zed-industries/zed/issues/5124)). Co-authored-by: Denis Lukianenko --- crates/gpui/src/platform/mac/metal_renderer.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/mac/metal_renderer.rs b/crates/gpui/src/platform/mac/metal_renderer.rs index f6818fe3de0b0cf62cbd93948fee4a9b13698aa0..97d788412febcc5787fe7abb00005e655745be30 100644 --- a/crates/gpui/src/platform/mac/metal_renderer.rs +++ b/crates/gpui/src/platform/mac/metal_renderer.rs @@ -109,9 +109,12 @@ pub(crate) struct MetalRenderer { impl MetalRenderer { pub fn new(instance_buffer_pool: Arc>) -> Self { - let device: metal::Device = if let Some(device) = metal::Device::system_default() { - device - } else { + // Prefer low‐power integrated GPUs on Intel Mac. On Apple + // Silicon, there is only ever one GPU, so this is equivalent to + // `metal::Device::system_default()`. + let mut devices = metal::Device::all(); + devices.sort_by_key(|device| (!device.is_removable(), device.is_low_power())); + let Some(device) = devices.pop() else { log::error!("unable to access a compatible graphics device"); std::process::exit(1); };