Skip to content

Commit dd01b6d

Browse files
committed
[d3d12] make DxgiLib and D3D12Lib methods consistent
1 parent 29e288f commit dd01b6d

File tree

5 files changed

+119
-134
lines changed

5 files changed

+119
-134
lines changed

wgpu-hal/src/auxil/dxgi/factory.rs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -225,46 +225,27 @@ pub fn create_factory(
225225
// The `DXGI_CREATE_FACTORY_DEBUG` flag is only allowed to be passed to
226226
// `CreateDXGIFactory2` if the debug interface is actually available. So
227227
// we check for whether it exists first.
228-
match lib_dxgi.debug_interface1() {
229-
Ok(pair) => match pair {
230-
Ok(_debug_controller) => {
231-
factory_flags |= Dxgi::DXGI_CREATE_FACTORY_DEBUG;
232-
}
233-
Err(err) => {
234-
log::warn!("Unable to enable DXGI debug interface: {}", err);
235-
}
236-
},
237-
Err(err) => {
238-
log::warn!("Debug interface function for DXGI not found: {:?}", err);
239-
}
228+
if lib_dxgi.debug_interface1().is_ok() {
229+
factory_flags |= Dxgi::DXGI_CREATE_FACTORY_DEBUG;
240230
}
241231

242232
// Intercept `OutputDebugString` calls
243233
super::exception::register_exception_handler();
244234
}
245235

246236
// Try to create IDXGIFactory4
247-
let factory4 = match lib_dxgi.create_factory2(factory_flags) {
248-
Ok(pair) => match pair {
249-
Ok(factory) => Some(factory),
250-
// We hard error here as we _should have_ been able to make a factory4 but couldn't.
251-
Err(err) => {
252-
// err is a Cow<str>, not an Error implementor
253-
return Err(crate::InstanceError::new(format!(
254-
"failed to create IDXGIFactory4: {err:?}"
255-
)));
256-
}
257-
},
237+
let factory4 = match lib_dxgi.create_factory4(factory_flags) {
238+
Ok(factory) => Some(factory),
258239
// If we require factory4, hard error.
259240
Err(err) if required_factory_type == DxgiFactoryType::Factory4 => {
260241
return Err(crate::InstanceError::with_source(
261-
String::from("IDXGIFactory1 creation function not found"),
242+
String::from("IDXGIFactory4 creation failed"),
262243
err,
263244
));
264245
}
265246
// If we don't print it to warn as all win7 will hit this case.
266247
Err(err) => {
267-
log::warn!("IDXGIFactory1 creation function not found: {err:?}");
248+
log::warn!("IDXGIFactory4 creation function not found: {err:?}");
268249
None
269250
}
270251
};
@@ -293,19 +274,10 @@ pub fn create_factory(
293274

294275
// Try to create IDXGIFactory1
295276
let factory1 = match lib_dxgi.create_factory1() {
296-
Ok(pair) => match pair {
297-
Ok(factory) => factory,
298-
Err(err) => {
299-
// err is a Cow<str>, not an Error implementor
300-
return Err(crate::InstanceError::new(format!(
301-
"failed to create IDXGIFactory1: {err:?}"
302-
)));
303-
}
304-
},
305-
// We always require at least factory1, so hard error
277+
Ok(factory) => factory,
306278
Err(err) => {
307279
return Err(crate::InstanceError::with_source(
308-
String::from("IDXGIFactory1 creation function not found"),
280+
String::from("IDXGIFactory1 creation failed"),
309281
err,
310282
));
311283
}

wgpu-hal/src/dx12/adapter.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,9 @@ impl super::Adapter {
6464
// Create the device so that we can get the capabilities.
6565
let device = {
6666
profiling::scope!("ID3D12Device::create_device");
67-
match library.create_device(&adapter, Direct3D::D3D_FEATURE_LEVEL_11_0) {
68-
Ok(pair) => match pair {
69-
Ok(device) => device,
70-
Err(err) => {
71-
log::warn!("Device creation failed: {}", err);
72-
return None;
73-
}
74-
},
75-
Err(err) => {
76-
log::warn!("Device creation function is not found: {:?}", err);
77-
return None;
78-
}
79-
}
67+
library
68+
.create_device(&adapter, Direct3D::D3D_FEATURE_LEVEL_11_0)
69+
.ok()?
8070
};
8171

8272
profiling::scope!("feature queries");

wgpu-hal/src/dx12/instance.rs

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,20 @@ impl crate::Instance for super::Instance {
3434
.intersects(wgt::InstanceFlags::VALIDATION | wgt::InstanceFlags::GPU_BASED_VALIDATION)
3535
{
3636
// Enable debug layer
37-
match lib_main.debug_interface() {
38-
Ok(pair) => match pair {
39-
Ok(debug_controller) => {
40-
if desc.flags.intersects(wgt::InstanceFlags::VALIDATION) {
41-
unsafe { debug_controller.EnableDebugLayer() }
42-
}
43-
if desc
44-
.flags
45-
.intersects(wgt::InstanceFlags::GPU_BASED_VALIDATION)
46-
{
47-
#[allow(clippy::collapsible_if)]
48-
if let Ok(debug1) = debug_controller.cast::<Direct3D12::ID3D12Debug1>()
49-
{
50-
unsafe { debug1.SetEnableGPUBasedValidation(true) }
51-
} else {
52-
log::warn!("Failed to enable GPU-based validation");
53-
}
54-
}
55-
}
56-
Err(err) => {
57-
log::warn!("Unable to enable D3D12 debug interface: {}", err);
37+
if let Ok(debug_controller) = lib_main.debug_interface() {
38+
if desc.flags.intersects(wgt::InstanceFlags::VALIDATION) {
39+
unsafe { debug_controller.EnableDebugLayer() }
40+
}
41+
if desc
42+
.flags
43+
.intersects(wgt::InstanceFlags::GPU_BASED_VALIDATION)
44+
{
45+
#[allow(clippy::collapsible_if)]
46+
if let Ok(debug1) = debug_controller.cast::<Direct3D12::ID3D12Debug1>() {
47+
unsafe { debug1.SetEnableGPUBasedValidation(true) }
48+
} else {
49+
log::warn!("Failed to enable GPU-based validation");
5850
}
59-
},
60-
Err(err) => {
61-
log::warn!("Debug interface function for D3D12 not found: {:?}", err);
6251
}
6352
}
6453
}
@@ -70,19 +59,7 @@ impl crate::Instance for super::Instance {
7059
)?;
7160

7261
// Create IDXGIFactoryMedia
73-
let factory_media = match lib_dxgi.create_factory_media() {
74-
Ok(pair) => match pair {
75-
Ok(factory_media) => Some(factory_media),
76-
Err(err) => {
77-
log::error!("Failed to create IDXGIFactoryMedia: {}", err);
78-
None
79-
}
80-
},
81-
Err(err) => {
82-
log::warn!("IDXGIFactory1 creation function not found: {:?}", err);
83-
None
84-
}
85-
};
62+
let factory_media = lib_dxgi.create_factory_media().ok();
8663

8764
let mut supports_allow_tearing = false;
8865
if let Some(factory5) = factory.as_factory5() {

0 commit comments

Comments
 (0)