Skip to content

Commit 695c7a8

Browse files
WIP: feat(dx12): enable GPU-based validation for DX12 backend
Logic for doing this was sourced from <https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-d3d12-debug-layer-gpu-based-validation>.
1 parent bc65d84 commit 695c7a8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

d3d12/src/debug.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::com::ComPtr;
2-
use winapi::um::d3d12sdklayers;
2+
use winapi::{shared::{winerror::S_OK, minwindef::TRUE}, um::d3d12sdklayers};
33
#[cfg(any(feature = "libloading", feature = "implicit-link"))]
44
use winapi::Interface as _;
55

@@ -40,4 +40,14 @@ impl Debug {
4040
pub fn enable_layer(&self) {
4141
unsafe { self.EnableDebugLayer() }
4242
}
43+
44+
pub fn enable_gpu_based_validation(&self) -> bool {
45+
let (ptr, hr) = unsafe { self.cast::<d3d12sdklayers::ID3D12Debug1>() };
46+
if hr == S_OK {
47+
unsafe { ptr.SetEnableGPUBasedValidation(TRUE) };
48+
true
49+
} else {
50+
false
51+
}
52+
}
4353
}

wgpu-hal/src/dx12/instance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl crate::Instance<super::Api> for super::Instance {
2424
Ok(pair) => match pair.into_result() {
2525
Ok(debug_controller) => {
2626
debug_controller.enable_layer();
27+
debug_controller.enable_gpu_based_validation();
2728
}
2829
Err(err) => {
2930
log::warn!("Unable to enable D3D12 debug interface: {}", err);

0 commit comments

Comments
 (0)