From 2aac44bb735e67768be15c35c2bed71032e26bb9 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:07:48 +0100 Subject: [PATCH] [d3d12] don't fallback on FXC if DXC failed to load --- wgpu-hal/src/dx12/instance.rs | 4 +- wgpu-hal/src/dx12/shader_compilation.rs | 49 ++++++++++--------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 389843a21..17fe1236e 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -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, }; diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 96865b908..53e44e6d3 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -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, } +#[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, dxil_path: Option, -) -> Result, 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 { + 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::()?; let utils = dxc.create_instance::()?; let validator = dxil.create_instance::()?; - 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, crate::DeviceError> { +pub(super) fn get_static_dxc_container() -> Result { #[cfg(feature = "static-dxc")] { unsafe { @@ -218,13 +209,13 @@ pub(super) fn get_static_dxc_container() -> Result, crate:: )) })?; - Ok(Some(DxcContainer { + Ok(DxcContainer { compiler, utils, validator: None, _dxc: None, _dxil: None, - })) + }) } } #[cfg(not(feature = "static-dxc"))]