macOS: Enumerate GPUs first; prefer low-power non-removable; fall back to system default#38164
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: steve.
|
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: steve.
|
|
recheck |
| std::process::exit(1); | ||
| } | ||
| // When multiple devices exist (e.g., Intel iGPU + dGPU or eGPU), prefer low-power, non-removable. | ||
| devices.sort_by_key(|d| (d.is_removable(), !d.is_low_power())); |
There was a problem hiding this comment.
The original code sorted by (is_removable(), is_low_power()), while this new one sorts by (is_removable(), !is_low_power()): was there a bug before? 🤔
There was a problem hiding this comment.
I have a MacBook with M1 Max and it works for me before and after the change. Hopefully I'm on the right track here so we can get some momentum for a fix. Definitely open to suggestions.
Use metal::Device::system_default() first to select the GPU. Fall back to Device::all() only if default device is unavailable. When enumerating, prefer non-removable, low-power devices for stability. Improves startup on ASi where enumeration returns empty; keeps sensible default on Intel multi‑GPU. Clarify error when no Metal devices are found. Fixes zed-industries#37689
|
From my perspective, this PR has two issues:
|
|
@JunkuiZhang thank you, I have fixed the issues. is there a way for people who have the issue to try a build? |
|
I think your changes make things a bit more complicated than they need to be. If I understand correctly, the issue on your machine is that |
…back to system_default
|
thank you. updated. |
Have feedback on this plugin? Let's hear it! |
|
recheck |
|
I pushed a few changes to your PR, could you check if everything still runs fine on your machine? |
|
thank you! yes it still works for me on MacBook Pro M1 Max. I've never been able to reproduce the original issue. your change is good, but sorting with (is_removable(), is_low_power()) then pop() still risks picking a removable eGPU when present. proposed change: Why: |
|
The change you suggested seems logically the same as mine, the only difference is that you’re using |
|
I cleaned it up a bit more, I hope that's okay. My testing on MacBook Pro M1 Max always works, I was not able to reproduce the original issue. Prefer non-removable, low-power GPU (iGPU) by ordering with min_by_key(|d| (d.is_removable(), !d.is_low_power())), yielding iGPU → dGPU → eGPU. |
…k to system default (zed-industries#38164) Problem: Some macOS environments report no devices via MTLCopyAllDevices, causing startup failure with “unable to access a compatible graphics device,” especially on Apple Silicon. Change: Prefer MTLCreateSystemDefaultDevice (metal::Device::system_default()) first. If None, enumerate devices and select a non‑removable, low‑power device by preference. Why this works: On Apple Silicon the system default is the unified GPU; on Intel, the fallback keeps a stable policy and avoids accidentally picking removable/high‑power devices. Impact: Fixes startup on affected ASi systems; improves selection consistency on Intel multi‑GPU. Behavior unchanged where system_default() succeeds. Risk: Low. Aligns with Apple’s recommended selection path. Still fails early with a clearer message if no Metal devices exist. Closes zed-industries#37689. Release Notes: - Fixed: Startup failure on some Apple Silicon machines when Metal device enumeration returned no devices by falling back to the system default device. --------- Co-authored-by: 张小白 <364772080@qq.com> Co-authored-by: Kate <work@localcc.cc>
Problem: Some macOS environments report no devices via MTLCopyAllDevices, causing startup failure with “unable to access a compatible graphics device,” especially on Apple Silicon.
Change: Prefer MTLCreateSystemDefaultDevice (metal::Device::system_default()) first. If None, enumerate devices and select a non‑removable, low‑power device by preference.
Why this works: On Apple Silicon the system default is the unified GPU; on Intel, the fallback keeps a stable policy and avoids accidentally picking removable/high‑power devices.
Impact: Fixes startup on affected ASi systems; improves selection consistency on Intel multi‑GPU. Behavior unchanged where system_default() succeeds.
Risk: Low. Aligns with Apple’s recommended selection path. Still fails early with a clearer message if no Metal devices exist.
Closes #37689.
Release Notes: