[d3d12] don't fallback on FXC if DXC failed to load

This commit is contained in:
teoxoy 2024-12-02 16:07:48 +01:00 committed by Teodor Tanasoaia
parent 74fe56fa83
commit 2aac44bb73
2 changed files with 22 additions and 31 deletions

View File

@ -89,7 +89,7 @@ impl crate::Instance for super::Instance {
)
})?;
container.map(Arc::new)
Some(Arc::new(container))
}
wgt::Dx12Compiler::StaticDxc => {
let container =
@ -100,7 +100,7 @@ impl crate::Instance for super::Instance {
)
})?;
container.map(Arc::new)
Some(Arc::new(container))
}
wgt::Dx12Compiler::Fxc => None,
};

View File

@ -1,6 +1,7 @@
use crate::auxil::dxgi::result::HResult;
use std::ffi::CStr;
use std::path::PathBuf;
use std::{error::Error, ffi::CStr};
use thiserror::Error;
use windows::{
core::{Interface, PCSTR, PCWSTR},
Win32::Graphics::Direct3D::{Dxc, Fxc},
@ -157,49 +158,39 @@ pub(super) struct DxcContainer {
_dxil: Option<DxcLib>,
}
#[derive(Debug, Error)]
pub(super) enum GetDynamicDXCContainerError {
#[error(transparent)]
Device(#[from] crate::DeviceError),
#[error("Failed to load {0}: {1}")]
FailedToLoad(&'static str, libloading::Error),
}
pub(super) fn get_dynamic_dxc_container(
dxc_path: Option<PathBuf>,
dxil_path: Option<PathBuf>,
) -> Result<Option<DxcContainer>, crate::DeviceError> {
let dxc = match DxcLib::new_dynamic(dxc_path, "dxcompiler.dll") {
Ok(dxc) => dxc,
Err(e) => {
log::warn!(
"Failed to load dxcompiler.dll. Defaulting to FXC instead: {}: {:?}",
e,
e.source()
);
return Ok(None);
}
};
) -> Result<DxcContainer, GetDynamicDXCContainerError> {
let dxc = DxcLib::new_dynamic(dxc_path, "dxcompiler.dll")
.map_err(|e| GetDynamicDXCContainerError::FailedToLoad("dxcompiler.dll", e))?;
let dxil = match DxcLib::new_dynamic(dxil_path, "dxil.dll") {
Ok(dxil) => dxil,
Err(e) => {
log::warn!(
"Failed to load dxil.dll. Defaulting to FXC instead: {}: {:?}",
e,
e.source()
);
return Ok(None);
}
};
let dxil = DxcLib::new_dynamic(dxil_path, "dxil.dll")
.map_err(|e| GetDynamicDXCContainerError::FailedToLoad("dxil.dll", e))?;
let compiler = dxc.create_instance::<Dxc::IDxcCompiler3>()?;
let utils = dxc.create_instance::<Dxc::IDxcUtils>()?;
let validator = dxil.create_instance::<Dxc::IDxcValidator>()?;
Ok(Some(DxcContainer {
Ok(DxcContainer {
compiler,
utils,
validator: Some(validator),
_dxc: Some(dxc),
_dxil: Some(dxil),
}))
})
}
/// Creates a [`DxcContainer`] that delegates to the statically-linked version of DXC.
pub(super) fn get_static_dxc_container() -> Result<Option<DxcContainer>, crate::DeviceError> {
pub(super) fn get_static_dxc_container() -> Result<DxcContainer, crate::DeviceError> {
#[cfg(feature = "static-dxc")]
{
unsafe {
@ -218,13 +209,13 @@ pub(super) fn get_static_dxc_container() -> Result<Option<DxcContainer>, crate::
))
})?;
Ok(Some(DxcContainer {
Ok(DxcContainer {
compiler,
utils,
validator: None,
_dxc: None,
_dxil: None,
}))
})
}
}
#[cfg(not(feature = "static-dxc"))]