From 7f663228212a86e3982ed7c214a1e70af0ad29bd Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 11 Jan 2024 14:09:12 -0500 Subject: [PATCH] WIP: feat(dx12): enable GPU-based validation for DX12 backend Logic for doing this was sourced from . --- d3d12/src/debug.rs | 15 ++++++++++++++- wgpu-hal/src/dx12/instance.rs | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/d3d12/src/debug.rs b/d3d12/src/debug.rs index 3a6abc46b7e..f321d878d8a 100644 --- a/d3d12/src/debug.rs +++ b/d3d12/src/debug.rs @@ -1,7 +1,10 @@ use crate::com::ComPtr; -use winapi::um::d3d12sdklayers; #[cfg(any(feature = "libloading", feature = "implicit-link"))] use winapi::Interface as _; +use winapi::{ + shared::{minwindef::TRUE, winerror::S_OK}, + um::d3d12sdklayers, +}; pub type Debug = ComPtr; @@ -40,4 +43,14 @@ impl Debug { pub fn enable_layer(&self) { unsafe { self.EnableDebugLayer() } } + + pub fn enable_gpu_based_validation(&self) -> bool { + let (ptr, hr) = unsafe { self.cast::() }; + if hr == S_OK { + unsafe { ptr.SetEnableGPUBasedValidation(TRUE) }; + true + } else { + false + } + } } diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 7bf5f3ef755..1ec7730b26f 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -24,6 +24,7 @@ impl crate::Instance for super::Instance { Ok(pair) => match pair.into_result() { Ok(debug_controller) => { debug_controller.enable_layer(); + debug_controller.enable_gpu_based_validation(); } Err(err) => { log::warn!("Unable to enable D3D12 debug interface: {}", err);