mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-04-12 20:16:34 +00:00
[d3d12] don't fallback on FXC if DXC failed to load
This commit is contained in:
parent
74fe56fa83
commit
2aac44bb73
@ -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,
|
||||
};
|
||||
|
@ -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"))]
|
||||
|
Loading…
Reference in New Issue
Block a user