Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip Integrated WARP #4259

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions wgpu-hal/src/auxil/dxgi/conv.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
27 changes: 27 additions & 0 deletions wgpu-hal/src/auxil/dxgi/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down