diff --git a/wgpu-hal/src/auxil/dxgi/conv.rs b/wgpu-hal/src/auxil/dxgi/conv.rs index 3798f7ea0a..f3f4a18317 100644 --- a/wgpu-hal/src/auxil/dxgi/conv.rs +++ b/wgpu-hal/src/auxil/dxgi/conv.rs @@ -1,5 +1,13 @@ +use std::{ffi::OsString, os::windows::ffi::OsStringExt}; use winapi::shared::dxgiformat; +// Helper to convert DXGI adapter name to a normal string +pub fn map_adapter_name(name: [u16; 128]) -> String { + let len = name.iter().take_while(|&&c| c != 0).count(); + let name = OsString::from_wide(&name[..len]); + name.to_string_lossy().into_owned() +} + pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option { use wgt::TextureFormat as Tf; use winapi::shared::dxgiformat::*; diff --git a/wgpu-hal/src/auxil/dxgi/factory.rs b/wgpu-hal/src/auxil/dxgi/factory.rs index 1e0847d2c4..86d632678c 100644 --- a/wgpu-hal/src/auxil/dxgi/factory.rs +++ b/wgpu-hal/src/auxil/dxgi/factory.rs @@ -14,6 +14,25 @@ pub enum DxgiFactoryType { Factory6, } +fn should_keep_adapter(adapter: &dxgi::IDXGIAdapter1) -> bool { + let mut desc = unsafe { std::mem::zeroed() }; + unsafe { adapter.GetDesc1(&mut desc) }; + + // If run completely headless, windows will show two different WARP adapters, one + // which is lying about being an integrated card. This is so that programs + // that ignore software adapters will actually run on headless/gpu-less machines. + // + // We don't want that and discorage that kind of filtering anyway, so we skip the integrated WARP. + if desc.VendorId == 5140 && (desc.Flags & dxgi::DXGI_ADAPTER_FLAG_SOFTWARE) == 0 { + let adapter_name = super::conv::map_adapter_name(desc.Description); + if adapter_name.contains("Microsoft Basic Render Driver") { + return false; + } + } + + true +} + pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec { let mut adapters = Vec::with_capacity(8); @@ -39,6 +58,10 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec Vec Adapter3 diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index f291e0808d..23bd25e6aa 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -102,12 +102,7 @@ impl super::Adapter { adapter.unwrap_adapter2().GetDesc2(&mut desc); } - let device_name = { - use std::{ffi::OsString, os::windows::ffi::OsStringExt}; - let len = desc.Description.iter().take_while(|&&c| c != 0).count(); - let name = OsString::from_wide(&desc.Description[..len]); - name.to_string_lossy().into_owned() - }; + let device_name = auxil::dxgi::conv::map_adapter_name(desc.Description); let mut features_architecture: d3d12_ty::D3D12_FEATURE_DATA_ARCHITECTURE = unsafe { mem::zeroed() };