Skip to content

DX12 fails to populate MaxSupportedFeatureLevel on specific (older?) environments #8803

@ErichDonGubler

Description

@ErichDonGubler

Description

Currently, this causes crashes in environments that serve affected hardware (see bug 2007754).

Introduced by #8576, which was motivated by bug 2007754.

Repro steps

use pollster::FutureExt;

fn main() {
    let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::from_env_or_default());
    let adapter = instance
        .request_adapter(&Default::default())
        .block_on()
        .unwrap();
    drop(adapter);
}

☝🏻 Unfortunately, this is not guaranteed to crash; it depends on the environment you use.

Expected vs observed behavior

Expected: either no adapter provided, or a successful adapter initialization.

Observed: Crash at wgpu-hal/src/dx12/adapter.rs:127, i.e.:

// Detect the highest supported feature level.
let d3d_feature_level = [
Direct3D::D3D_FEATURE_LEVEL_12_2,
Direct3D::D3D_FEATURE_LEVEL_12_1,
Direct3D::D3D_FEATURE_LEVEL_12_0,
Direct3D::D3D_FEATURE_LEVEL_11_1,
Direct3D::D3D_FEATURE_LEVEL_11_0,
];
let mut device_levels = Direct3D12::D3D12_FEATURE_DATA_FEATURE_LEVELS {
NumFeatureLevels: d3d_feature_level.len() as u32,
pFeatureLevelsRequested: d3d_feature_level.as_ptr().cast(),
MaxSupportedFeatureLevel: Default::default(),
};
unsafe {
device.CheckFeatureSupport(
Direct3D12::D3D12_FEATURE_FEATURE_LEVELS,
<*mut _>::cast(&mut device_levels),
size_of_val(&device_levels) as u32,
)
}
.unwrap();
let max_feature_level = match device_levels.MaxSupportedFeatureLevel {
Direct3D::D3D_FEATURE_LEVEL_11_0 => FeatureLevel::_11_0,
Direct3D::D3D_FEATURE_LEVEL_11_1 => FeatureLevel::_11_1,
Direct3D::D3D_FEATURE_LEVEL_12_0 => FeatureLevel::_12_0,
Direct3D::D3D_FEATURE_LEVEL_12_1 => FeatureLevel::_12_1,
Direct3D::D3D_FEATURE_LEVEL_12_2 => FeatureLevel::_12_2,
_ => unreachable!(),
};

Platform

DX12, so Windows.

Metadata

Metadata

Assignees

Labels

backend: dx12Issues with DX12 or DXGItype: bugSomething isn't working

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions