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>.
This commit is contained in:
Erich Gubler 2024-01-11 14:09:12 -05:00
parent ecd5836aed
commit 4aab8a8399
2 changed files with 17 additions and 1 deletions

View File

@ -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<d3d12sdklayers::ID3D12Debug>;
@ -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::<d3d12sdklayers::ID3D12Debug1>() };
if hr == S_OK {
unsafe { ptr.SetEnableGPUBasedValidation(TRUE) };
true
} else {
false
}
}
}

View File

@ -26,6 +26,9 @@ impl crate::Instance<super::Api> for super::Instance {
Ok(pair) => match pair.into_result() {
Ok(debug_controller) => {
debug_controller.enable_layer();
if !debug_controller.enable_gpu_based_validation() {
log::warn!("Failed to enable GPU-based validation");
}
}
Err(err) => {
log::warn!("Unable to enable D3D12 debug interface: {}", err);