check debug layer before creating

This commit is contained in:
Junkui Zhang 2025-07-31 00:05:56 +08:00
parent 6a91ac26d7
commit 34e433ad90

View file

@ -974,7 +974,17 @@ impl Drop for DirectXResources {
#[inline]
fn get_dxgi_factory() -> Result<IDXGIFactory6> {
#[cfg(debug_assertions)]
let factory_flag = DXGI_CREATE_FACTORY_DEBUG;
let factory_flag = if unsafe { DXGIGetDebugInterface1::<IDXGIInfoQueue>(0) }
.log_err()
.is_some()
{
DXGI_CREATE_FACTORY_DEBUG
} else {
log::error!(
"Failed to get DXGI debug interface. DirectX debugging features will be disabled."
);
DXGI_CREATE_FACTORY_FLAGS::default()
};
#[cfg(not(debug_assertions))]
let factory_flag = DXGI_CREATE_FACTORY_FLAGS::default();
unsafe { Ok(CreateDXGIFactory2(factory_flag)?) }