gpui: Prefer integrated GPUs on Intel Mac (#13685)
Emily
and
Denis Lukianenko
created
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 <denlyk1@gmail.com>
@@ -109,9 +109,12 @@ pub(crate) struct MetalRenderer {
impl MetalRenderer {
pub fn new(instance_buffer_pool: Arc<Mutex<InstanceBufferPool>>) -> 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);
};