Skip Integrated WARP (#4259)

This commit is contained in:
Connor Fitzgerald 2023-10-18 08:08:14 -04:00 committed by GitHub
parent da0b3fe685
commit 3e307a862f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 6 deletions

View File

@ -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<dxgiformat::DXGI_FORMAT> {
use wgt::TextureFormat as Tf;
use winapi::shared::dxgiformat::*;

View File

@ -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<d3d12::DxgiAdapter> {
let mut adapters = Vec::with_capacity(8);
@ -39,6 +58,10 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec<d3d12::DxgiAdapter
break;
}
if !should_keep_adapter(&adapter4) {
continue;
}
adapters.push(d3d12::DxgiAdapter::Adapter4(adapter4));
continue;
}
@ -55,6 +78,10 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec<d3d12::DxgiAdapter
break;
}
if !should_keep_adapter(&adapter1) {
continue;
}
// Do the most aggressive casts first, skipping Adpater4 as we definitely don't have dxgi1_6.
// Adapter1 -> Adapter3

View File

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