From 4772cd8c63ec0ef485bf4d84be17960834259b5b Mon Sep 17 00:00:00 2001 From: Benjamin Frye Date: Fri, 27 Dec 2024 03:06:50 +1100 Subject: [PATCH] fix(dxgi): DX12 exception handler lifetime based on device not adapter (#6828) --- wgpu-hal/src/auxil/dxgi/factory.rs | 3 --- wgpu-hal/src/dx12/device.rs | 7 +++++++ wgpu-hal/src/dx12/instance.rs | 8 -------- wgpu-hal/src/dx12/mod.rs | 7 +++++++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/wgpu-hal/src/auxil/dxgi/factory.rs b/wgpu-hal/src/auxil/dxgi/factory.rs index 4b71abda37..cb2205cfcb 100644 --- a/wgpu-hal/src/auxil/dxgi/factory.rs +++ b/wgpu-hal/src/auxil/dxgi/factory.rs @@ -141,9 +141,6 @@ pub fn create_factory( if let Ok(Some(_)) = lib_dxgi.debug_interface1() { factory_flags |= Dxgi::DXGI_CREATE_FACTORY_DEBUG; } - - // Intercept `OutputDebugString` calls - super::exception::register_exception_handler(); } let factory4 = match lib_dxgi.create_factory4(factory_flags) { diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index a983a92011..20dc20164f 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -37,6 +37,13 @@ impl super::Device { library: &Arc, dxc_container: Option>, ) -> Result { + if private_caps + .instance_flags + .contains(wgt::InstanceFlags::VALIDATION) + { + auxil::dxgi::exception::register_exception_handler(); + } + let mem_allocator = super::suballocation::create_allocator_wrapper(&raw, memory_hints)?; let idle_fence: Direct3D12::ID3D12Fence = unsafe { diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 17fe1236e5..c257afe804 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -12,14 +12,6 @@ use windows::{ use super::SurfaceTarget; use crate::{auxil, dx12::D3D12Lib}; -impl Drop for super::Instance { - fn drop(&mut self) { - if self.flags.contains(wgt::InstanceFlags::VALIDATION) { - auxil::dxgi::exception::unregister_exception_handler(); - } - } -} - impl crate::Instance for super::Instance { type A = super::Api; diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index e0f27119df..d58d79300a 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -605,6 +605,13 @@ pub struct Device { impl Drop for Device { fn drop(&mut self) { self.rtv_pool.lock().free_handle(self.null_rtv_handle); + if self + .private_caps + .instance_flags + .contains(wgt::InstanceFlags::VALIDATION) + { + auxil::dxgi::exception::unregister_exception_handler(); + } } }