gpui: Prefer integrated GPUs on Intel Mac (#13685)

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>
This commit is contained in:
Emily 2024-07-03 14:12:24 +01:00 committed by GitHub
parent 351a3c0815
commit c1e18059f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 lowpower 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);
};