From a78b560b8b569b76aa02d13179846e00f26ce452 Mon Sep 17 00:00:00 2001 From: Cave Bats Of Ware <556437+cavebatsofware@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:47:57 -0400 Subject: [PATCH] Improve GPU selection on Windows (#39264) Closes #39263 Release Notes: - N/A from https://github.com/zed-industries/zed/issues/39263#issuecomment-3358220988 > > > If you replace that code with > > > > let adapter: IDXGIAdapter1 = unsafe { > > dxgi_factory.EnumAdapters(adapter_index) > > }?.cast()?; > > > > does it not select the right GPU? > > @reflectronic That does seem to select the active gpu for me, meaning whichever GPU is currently connected. This is a much simpler solution than the one I have here (https://github.com/zed-industries/zed/pull/39264 - updated) and while I'm sure I could imagine someone wanting to choose their GPU to render Zed on, that may not be something that the application really needs to support. > > I have a branch with just this as the only change that I can push to that PR if the simpler solution is preferred. > > ```rust > let adapter: IDXGIAdapter1 = unsafe { > dxgi_factory.EnumAdapters(adapter_index)?.cast()? > }; > ``` --- crates/gpui/src/platform/windows/directx_devices.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/platform/windows/directx_devices.rs b/crates/gpui/src/platform/windows/directx_devices.rs index 4fa4db827492faffaa0d8912b1f37b52f8cfc88f..a6a2381777b11fd1863735f3c7f4b71aafbf6a39 100644 --- a/crates/gpui/src/platform/windows/directx_devices.rs +++ b/crates/gpui/src/platform/windows/directx_devices.rs @@ -14,10 +14,11 @@ use windows::Win32::{ }, Dxgi::{ CreateDXGIFactory2, DXGI_CREATE_FACTORY_DEBUG, DXGI_CREATE_FACTORY_FLAGS, - DXGI_GPU_PREFERENCE_MINIMUM_POWER, IDXGIAdapter1, IDXGIFactory6, + IDXGIAdapter1, IDXGIFactory6, }, }, }; +use windows::core::Interface; pub(crate) fn try_to_recover_from_device_lost( mut f: impl FnMut() -> Result, @@ -121,10 +122,7 @@ fn get_dxgi_factory(debug_layer_available: bool) -> Result { #[inline] fn get_adapter(dxgi_factory: &IDXGIFactory6, debug_layer_available: bool) -> Result { for adapter_index in 0.. { - let adapter: IDXGIAdapter1 = unsafe { - dxgi_factory - .EnumAdapterByGpuPreference(adapter_index, DXGI_GPU_PREFERENCE_MINIMUM_POWER) - }?; + let adapter: IDXGIAdapter1 = unsafe { dxgi_factory.EnumAdapters(adapter_index)?.cast()? }; if let Ok(desc) = unsafe { adapter.GetDesc1() } { let gpu_name = String::from_utf16_lossy(&desc.Description) .trim_matches(char::from(0))