windows: Don't create directx device with debug flag when debug layer is missing (#35405)
Release Notes: - N/A
This commit is contained in:
parent
558bbfffae
commit
98c66eddb8
1 changed files with 32 additions and 14 deletions
|
@ -88,8 +88,11 @@ struct DirectComposition {
|
||||||
|
|
||||||
impl DirectXDevices {
|
impl DirectXDevices {
|
||||||
pub(crate) fn new(disable_direct_composition: bool) -> Result<ManuallyDrop<Self>> {
|
pub(crate) fn new(disable_direct_composition: bool) -> Result<ManuallyDrop<Self>> {
|
||||||
let dxgi_factory = get_dxgi_factory().context("Creating DXGI factory")?;
|
let debug_layer_available = check_debug_layer_available();
|
||||||
let adapter = get_adapter(&dxgi_factory).context("Getting DXGI adapter")?;
|
let dxgi_factory =
|
||||||
|
get_dxgi_factory(debug_layer_available).context("Creating DXGI factory")?;
|
||||||
|
let adapter =
|
||||||
|
get_adapter(&dxgi_factory, debug_layer_available).context("Getting DXGI adapter")?;
|
||||||
let (device, device_context) = {
|
let (device, device_context) = {
|
||||||
let mut device: Option<ID3D11Device> = None;
|
let mut device: Option<ID3D11Device> = None;
|
||||||
let mut context: Option<ID3D11DeviceContext> = None;
|
let mut context: Option<ID3D11DeviceContext> = None;
|
||||||
|
@ -99,6 +102,7 @@ impl DirectXDevices {
|
||||||
Some(&mut device),
|
Some(&mut device),
|
||||||
Some(&mut context),
|
Some(&mut context),
|
||||||
Some(&mut feature_level),
|
Some(&mut feature_level),
|
||||||
|
debug_layer_available,
|
||||||
)
|
)
|
||||||
.context("Creating Direct3D device")?;
|
.context("Creating Direct3D device")?;
|
||||||
match feature_level {
|
match feature_level {
|
||||||
|
@ -977,25 +981,34 @@ impl Drop for DirectXResources {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_dxgi_factory() -> Result<IDXGIFactory6> {
|
fn check_debug_layer_available() -> bool {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
let factory_flag = if unsafe { DXGIGetDebugInterface1::<IDXGIInfoQueue>(0) }
|
|
||||||
.log_err()
|
|
||||||
.is_some()
|
|
||||||
{
|
{
|
||||||
|
unsafe { DXGIGetDebugInterface1::<IDXGIInfoQueue>(0) }
|
||||||
|
.log_err()
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
{
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_dxgi_factory(debug_layer_available: bool) -> Result<IDXGIFactory6> {
|
||||||
|
let factory_flag = if debug_layer_available {
|
||||||
DXGI_CREATE_FACTORY_DEBUG
|
DXGI_CREATE_FACTORY_DEBUG
|
||||||
} else {
|
} else {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Failed to get DXGI debug interface. DirectX debugging features will be disabled."
|
"Failed to get DXGI debug interface. DirectX debugging features will be disabled."
|
||||||
);
|
);
|
||||||
DXGI_CREATE_FACTORY_FLAGS::default()
|
DXGI_CREATE_FACTORY_FLAGS::default()
|
||||||
};
|
};
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
let factory_flag = DXGI_CREATE_FACTORY_FLAGS::default();
|
|
||||||
unsafe { Ok(CreateDXGIFactory2(factory_flag)?) }
|
unsafe { Ok(CreateDXGIFactory2(factory_flag)?) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_adapter(dxgi_factory: &IDXGIFactory6) -> Result<IDXGIAdapter1> {
|
fn get_adapter(dxgi_factory: &IDXGIFactory6, debug_layer_available: bool) -> Result<IDXGIAdapter1> {
|
||||||
for adapter_index in 0.. {
|
for adapter_index in 0.. {
|
||||||
let adapter: IDXGIAdapter1 = unsafe {
|
let adapter: IDXGIAdapter1 = unsafe {
|
||||||
dxgi_factory
|
dxgi_factory
|
||||||
|
@ -1009,7 +1022,10 @@ fn get_adapter(dxgi_factory: &IDXGIFactory6) -> Result<IDXGIAdapter1> {
|
||||||
}
|
}
|
||||||
// Check to see whether the adapter supports Direct3D 11, but don't
|
// Check to see whether the adapter supports Direct3D 11, but don't
|
||||||
// create the actual device yet.
|
// create the actual device yet.
|
||||||
if get_device(&adapter, None, None, None).log_err().is_some() {
|
if get_device(&adapter, None, None, None, debug_layer_available)
|
||||||
|
.log_err()
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
return Ok(adapter);
|
return Ok(adapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1022,11 +1038,13 @@ fn get_device(
|
||||||
device: Option<*mut Option<ID3D11Device>>,
|
device: Option<*mut Option<ID3D11Device>>,
|
||||||
context: Option<*mut Option<ID3D11DeviceContext>>,
|
context: Option<*mut Option<ID3D11DeviceContext>>,
|
||||||
feature_level: Option<*mut D3D_FEATURE_LEVEL>,
|
feature_level: Option<*mut D3D_FEATURE_LEVEL>,
|
||||||
|
debug_layer_available: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
#[cfg(debug_assertions)]
|
let device_flags = if debug_layer_available {
|
||||||
let device_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_DEBUG;
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_DEBUG
|
||||||
#[cfg(not(debug_assertions))]
|
} else {
|
||||||
let device_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT
|
||||||
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
D3D11CreateDevice(
|
D3D11CreateDevice(
|
||||||
adapter,
|
adapter,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue