From 310a0d2e8ed1dfc700d8e630f982303cc0be0293 Mon Sep 17 00:00:00 2001 From: RedMindZ Date: Tue, 22 Apr 2025 00:36:47 +0300 Subject: [PATCH 1/4] FXC is now loaded dynamically, removing the dependency on `d3dcompiler_47.dll` --- wgpu-hal/src/dx12/adapter.rs | 10 +- wgpu-hal/src/dx12/device.rs | 33 +-- wgpu-hal/src/dx12/instance.rs | 61 +++--- wgpu-hal/src/dx12/mod.rs | 6 +- wgpu-hal/src/dx12/shader_compilation.rs | 269 +++++++++++++++++------- 5 files changed, 248 insertions(+), 131 deletions(-) diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 4d214e7705..fd4cb12fa9 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -54,7 +54,7 @@ impl super::Adapter { adapter: DxgiAdapter, library: &Arc, instance_flags: wgt::InstanceFlags, - dxc_container: Option>, + compiler_container: Arc, ) -> Option> { // Create the device so that we can get the capabilities. let device = { @@ -221,8 +221,8 @@ impl super::Adapter { } }; - let shader_model = if let Some(ref dxc_container) = dxc_container { - let max_shader_model = match dxc_container.max_shader_model { + let shader_model = if let Some(max_shader_model) = compiler_container.max_shader_model() { + let max_shader_model = match max_shader_model { wgt::DxcShaderModel::V6_0 => Direct3D12::D3D_SHADER_MODEL_6_0, wgt::DxcShaderModel::V6_1 => Direct3D12::D3D_SHADER_MODEL_6_1, wgt::DxcShaderModel::V6_2 => Direct3D12::D3D_SHADER_MODEL_6_2, @@ -515,7 +515,7 @@ impl super::Adapter { private_caps, presentation_timer, workarounds, - dxc_container, + compiler_container, }, info, features, @@ -652,7 +652,7 @@ impl crate::Adapter for super::Adapter { memory_hints, self.private_caps, &self.library, - self.dxc_container.clone(), + self.compiler_container.clone(), )?; Ok(crate::OpenDevice { device, diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 7de69e368f..ac5ca72f2f 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -46,7 +46,7 @@ impl super::Device { memory_hints: &wgt::MemoryHints, private_caps: super::PrivateCapabilities, library: &Arc, - dxc_container: Option>, + compiler_container: Arc, ) -> Result { if private_caps .instance_flags @@ -200,7 +200,7 @@ impl super::Device { render_doc: Default::default(), null_rtv_handle, mem_allocator, - dxc_container, + compiler_container, counters: Default::default(), }) } @@ -325,27 +325,14 @@ impl super::Device { let source_name = stage.module.raw_name.as_deref(); - // Compile with DXC if available, otherwise fall back to FXC - let result = if let Some(ref dxc_container) = self.dxc_container { - shader_compilation::compile_dxc( - self, - &source, - source_name, - raw_ep, - stage_bit, - &full_stage, - dxc_container, - ) - } else { - shader_compilation::compile_fxc( - self, - &source, - source_name, - raw_ep, - stage_bit, - &full_stage, - ) - }; + let result = self.compiler_container.compile( + self, + &source, + source_name, + raw_ep, + stage_bit, + &full_stage, + ); let log_level = if result.is_ok() { log::Level::Info diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index f284500d0d..1034992784 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -10,7 +10,10 @@ use windows::{ }; use super::SurfaceTarget; -use crate::{auxil, dx12::D3D12Lib}; +use crate::{ + auxil, + dx12::{shader_compilation::CompilerContainer, D3D12Lib}, +}; impl crate::Instance for super::Instance { type A = super::Api; @@ -66,39 +69,34 @@ impl crate::Instance for super::Instance { } } - // Initialize DXC shader compiler - let dxc_container = match desc.backend_options.dx12.shader_compiler.clone() { + // Initialize the shader compiler + let compiler_container = match desc.backend_options.dx12.shader_compiler.clone() { wgt::Dx12Compiler::DynamicDxc { dxc_path, max_shader_model, - } => { - let container = super::shader_compilation::get_dynamic_dxc_container( - dxc_path.into(), - max_shader_model, - ) - .map_err(|e| { + } => CompilerContainer::new_dynamic_dxc(dxc_path.into(), max_shader_model).map_err( + |e| { crate::InstanceError::with_source(String::from("Failed to load dynamic DXC"), e) - })?; + }, + )?, + wgt::Dx12Compiler::StaticDxc => CompilerContainer::new_static_dxc().map_err(|e| { + crate::InstanceError::with_source(String::from("Failed to load static DXC"), e) + })?, + wgt::Dx12Compiler::Fxc => CompilerContainer::new_fxc().map_err(|e| { + crate::InstanceError::with_source(String::from("Failed to load FXC"), e) + })?, + }; - Some(Arc::new(container)) + match compiler_container { + CompilerContainer::DynamicDxc(..) => { + log::debug!("Using dynamic DXC for shader compilation") } - wgt::Dx12Compiler::StaticDxc => { - let container = - super::shader_compilation::get_static_dxc_container().map_err(|e| { - crate::InstanceError::with_source( - String::from("Failed to load static DXC"), - e, - ) - })?; - - Some(Arc::new(container)) + CompilerContainer::StaticDxc(..) => { + log::debug!("Using static DXC for shader compilation") + } + CompilerContainer::Fxc(..) => { + log::debug!("Using FXC for shader compilation") } - wgt::Dx12Compiler::Fxc => None, - }; - - match dxc_container { - Some(_) => log::debug!("Using DXC for shader compilation"), - None => log::debug!("Using FXC for shader compilation"), } Ok(Self { @@ -109,7 +107,7 @@ impl crate::Instance for super::Instance { _lib_dxgi: lib_dxgi, supports_allow_tearing, flags: desc.flags, - dxc_container, + compiler_container: Arc::new(compiler_container), }) } @@ -142,7 +140,12 @@ impl crate::Instance for super::Instance { adapters .into_iter() .filter_map(|raw| { - super::Adapter::expose(raw, &self.library, self.flags, self.dxc_container.clone()) + super::Adapter::expose( + raw, + &self.library, + self.flags, + self.compiler_container.clone(), + ) }) .collect() } diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 09c4f88420..ef5bfae304 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -460,7 +460,7 @@ pub struct Instance { supports_allow_tearing: bool, _lib_dxgi: DxgiLib, flags: wgt::InstanceFlags, - dxc_container: Option>, + compiler_container: Arc, } impl Instance { @@ -591,7 +591,7 @@ pub struct Adapter { // Note: this isn't used right now, but we'll need it later. #[allow(unused)] workarounds: Workarounds, - dxc_container: Option>, + compiler_container: Arc, } unsafe impl Send for Adapter {} @@ -653,7 +653,7 @@ pub struct Device { render_doc: auxil::renderdoc::RenderDoc, null_rtv_handle: descriptor::Handle, mem_allocator: Arc>, - dxc_container: Option>, + compiler_container: Arc, counters: Arc, } diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 8b3675617a..717c130b81 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -4,16 +4,204 @@ use crate::auxil::dxgi::result::HResult; use thiserror::Error; use windows::{ core::{Interface, PCSTR, PCWSTR}, - Win32::Graphics::Direct3D::{Dxc, Fxc}, + Win32::Graphics::Direct3D::{Dxc, Fxc, ID3DBlob, ID3DInclude, D3D_SHADER_MACRO}, }; -pub(super) fn compile_fxc( +pub(super) enum CompilerContainer { + Fxc(CompilerFxc), + DynamicDxc(CompilerDynamicDxc), + StaticDxc(CompilerStaticDxc), +} + +pub(super) struct CompilerFxc { + fxc: FxcLib, +} + +pub(super) struct CompilerDynamicDxc { + max_shader_model: wgt::DxcShaderModel, + compiler: Dxc::IDxcCompiler3, + // Has to be held onto for the lifetime of the device otherwise shaders will fail to compile. + // Only needed when using dynamic linking. + _dxc: DxcLib, +} + +pub(super) struct CompilerStaticDxc { + max_shader_model: wgt::DxcShaderModel, + compiler: Dxc::IDxcCompiler3, +} + +#[derive(Debug, Error)] +pub(super) enum GetContainerError { + #[error(transparent)] + Device(#[from] crate::DeviceError), + #[error("Failed to load {0}: {1}")] + FailedToLoad(&'static str, libloading::Error), +} + +impl CompilerContainer { + pub(super) fn new_fxc() -> Result { + let fxc = + FxcLib::new_dynamic().map_err(|e| GetContainerError::FailedToLoad(FxcLib::PATH, e))?; + + Ok(Self::Fxc(CompilerFxc { fxc })) + } + + pub(super) fn new_dynamic_dxc( + dxc_path: PathBuf, + max_shader_model: wgt::DxcShaderModel, + ) -> Result { + let dxc = DxcLib::new_dynamic(dxc_path) + .map_err(|e| GetContainerError::FailedToLoad("dxcompiler.dll", e))?; + + let compiler = dxc.create_instance::()?; + + Ok(Self::DynamicDxc(CompilerDynamicDxc { + max_shader_model, + compiler, + _dxc: dxc, + })) + } + + /// Creates a [`CompilerContainer`] that delegates to the statically-linked version of DXC. + pub(super) fn new_static_dxc() -> Result { + #[cfg(static_dxc)] + { + unsafe { + let compiler = dxc_create_instance::(|clsid, iid, ppv| { + windows_core::HRESULT(mach_dxcompiler_rs::DxcCreateInstance( + clsid.cast(), + iid.cast(), + ppv, + )) + })?; + + Ok(CompilerContainer::StaticDxc(CompilerStaticDxc { + max_shader_model: wgt::DxcShaderModel::V6_7, + compiler, + })) + } + } + #[cfg(not(static_dxc))] + { + panic!("Attempted to create a static DXC shader compiler, but the static-dxc feature was not enabled") + } + } + + pub(super) fn max_shader_model(&self) -> Option { + match self { + CompilerContainer::Fxc(..) => None, + CompilerContainer::DynamicDxc(CompilerDynamicDxc { + max_shader_model, .. + }) + | CompilerContainer::StaticDxc(CompilerStaticDxc { + max_shader_model, .. + }) => Some(max_shader_model.clone()), + } + } + + pub(super) fn compile( + &self, + device: &super::Device, + source: &str, + source_name: Option<&CStr>, + raw_ep: &str, + stage_bit: wgt::ShaderStages, + full_stage: &str, + ) -> Result { + match self { + CompilerContainer::Fxc(CompilerFxc { fxc }) => compile_fxc( + device, + source, + source_name, + raw_ep, + stage_bit, + full_stage, + fxc, + ), + CompilerContainer::DynamicDxc(CompilerDynamicDxc { compiler, .. }) + | CompilerContainer::StaticDxc(CompilerStaticDxc { compiler, .. }) => compile_dxc( + device, + source, + source_name, + raw_ep, + stage_bit, + full_stage, + compiler, + ), + } + } +} + +#[derive(Debug)] +struct FxcLib { + lib: crate::dx12::DynLib, +} + +impl FxcLib { + const PATH: &str = "d3dcompiler_47.dll"; + + fn new_dynamic() -> Result { + unsafe { crate::dx12::DynLib::new(Self::PATH).map(|lib| Self { lib }) } + } + + fn compile( + &self, + psrcdata: *const core::ffi::c_void, + srcdatasize: usize, + psourcename: PCSTR, + pdefines: Option<*const D3D_SHADER_MACRO>, + pinclude: Option<*mut ID3DInclude>, + pentrypoint: PCSTR, + ptarget: PCSTR, + flags1: u32, + flags2: u32, + ppcode: *mut Option, + pperrormsgs: Option<*mut Option>, + ) -> Result, crate::DeviceError> { + unsafe { + type D3DCompileFn = unsafe extern "system" fn( + psrcdata: *const core::ffi::c_void, + srcdatasize: usize, + psourcename: PCSTR, + pdefines: *const D3D_SHADER_MACRO, + pinclude: *mut core::ffi::c_void, + pentrypoint: PCSTR, + ptarget: PCSTR, + flags1: u32, + flags2: u32, + ppcode: *mut *mut core::ffi::c_void, + pperrormsgs: *mut *mut core::ffi::c_void, + ) -> windows_core::HRESULT; + + let d3dcompile_fn: libloading::Symbol = + self.lib.get(c"D3DCompile".to_bytes())?; + + Ok(d3dcompile_fn( + psrcdata, + srcdatasize, + psourcename, + pdefines.unwrap_or(core::ptr::null()), + core::mem::transmute(pinclude.unwrap_or(core::ptr::null_mut())), + pentrypoint, + ptarget, + flags1, + flags2, + core::mem::transmute(ppcode), + core::mem::transmute(pperrormsgs.unwrap_or(core::ptr::null_mut())), + ) + .ok()) + } + } +} + +fn compile_fxc( device: &super::Device, source: &str, source_name: Option<&CStr>, raw_ep: &str, stage_bit: wgt::ShaderStages, full_stage: &str, + fxc: &FxcLib, ) -> Result { profiling::scope!("compile_fxc"); let mut shader_data = None; @@ -36,9 +224,9 @@ pub(super) fn compile_fxc( .unwrap_or(core::ptr::null()); let mut error = None; - let hr = unsafe { + let hr = { profiling::scope!("Fxc::D3DCompile"); - Fxc::D3DCompile( + fxc.compile( // TODO: Update low-level bindings to accept a slice here source.as_ptr().cast(), source.len(), @@ -51,7 +239,7 @@ pub(super) fn compile_fxc( 0, &mut shader_data, Some(&mut error), - ) + )? }; match hr { @@ -130,64 +318,6 @@ unsafe fn dxc_create_instance( result__.ok_or(crate::DeviceError::Unexpected) } -pub(super) struct DxcContainer { - pub(super) max_shader_model: wgt::DxcShaderModel, - compiler: Dxc::IDxcCompiler3, - // Has to be held onto for the lifetime of the device otherwise shaders will fail to compile. - // Only needed when using dynamic linking. - _dxc: 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: PathBuf, - max_shader_model: wgt::DxcShaderModel, -) -> Result { - let dxc = DxcLib::new_dynamic(dxc_path) - .map_err(|e| GetDynamicDXCContainerError::FailedToLoad("dxcompiler.dll", e))?; - - let compiler = dxc.create_instance::()?; - - Ok(DxcContainer { - max_shader_model, - compiler, - _dxc: Some(dxc), - }) -} - -/// Creates a [`DxcContainer`] that delegates to the statically-linked version of DXC. -pub(super) fn get_static_dxc_container() -> Result { - #[cfg(static_dxc)] - { - unsafe { - let compiler = dxc_create_instance::(|clsid, iid, ppv| { - windows_core::HRESULT(mach_dxcompiler_rs::DxcCreateInstance( - clsid.cast(), - iid.cast(), - ppv, - )) - })?; - - Ok(DxcContainer { - max_shader_model: wgt::DxcShaderModel::V6_7, - compiler, - _dxc: None, - }) - } - } - #[cfg(not(static_dxc))] - { - panic!("Attempted to create a static DXC shader compiler, but the static-dxc feature was not enabled") - } -} - /// Owned PCWSTR #[allow(clippy::upper_case_acronyms)] struct OPCWSTR { @@ -223,14 +353,14 @@ fn as_err_str(blob: &Dxc::IDxcBlobUtf8) -> Result<&str, crate::DeviceError> { .map_err(|_| crate::DeviceError::Unexpected) } -pub(super) fn compile_dxc( +fn compile_dxc( device: &crate::dx12::Device, source: &str, source_name: Option<&CStr>, raw_ep: &str, stage_bit: wgt::ShaderStages, full_stage: &str, - dxc_container: &DxcContainer, + compiler: &Dxc::IDxcCompiler3, ) -> Result { profiling::scope!("compile_dxc"); @@ -277,12 +407,9 @@ pub(super) fn compile_dxc( Encoding: Dxc::DXC_CP_UTF8.0, }; - let compile_res: Dxc::IDxcResult = unsafe { - dxc_container - .compiler - .Compile(&buffer, Some(&compile_args), None) - } - .into_device_result("Compile")?; + let compile_res: Dxc::IDxcResult = + unsafe { compiler.Compile(&buffer, Some(&compile_args), None) } + .into_device_result("Compile")?; drop(compile_args); drop(source_name); From 4b0012f0141efef120958fddacf58e00a5d944f4 Mon Sep 17 00:00:00 2001 From: RedMindZ Date: Wed, 23 Apr 2025 02:00:39 +0300 Subject: [PATCH 2/4] A pointer to `D3DCompile` is now loaded once and stored for efficient repeated usage. Fixed clippy warnings. Fixed merge conflicts. --- wgpu-hal/src/dx12/shader_compilation.rs | 151 ++++++++++++------------ 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index a3932a69a9..79c949150f 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -6,7 +6,7 @@ use crate::auxil::dxgi::result::HResult; use thiserror::Error; use windows::{ core::{Interface, PCSTR, PCWSTR}, - Win32::Graphics::Direct3D::{Dxc, Fxc, ID3DBlob, ID3DInclude, D3D_SHADER_MACRO}, + Win32::Graphics::Direct3D::{Dxc, Fxc, ID3DBlob, D3D_SHADER_MACRO}, }; pub(super) enum CompilerContainer { @@ -42,10 +42,7 @@ pub(super) enum GetContainerError { impl CompilerContainer { pub(super) fn new_fxc() -> Result { - let fxc = - FxcLib::new_dynamic().map_err(|e| GetContainerError::FailedToLoad(FxcLib::PATH, e))?; - - Ok(Self::Fxc(CompilerFxc { fxc })) + FxcLib::new_dynamic().map(|fxc| Self::Fxc(CompilerFxc { fxc })) } pub(super) fn new_dynamic_dxc( @@ -134,64 +131,82 @@ impl CompilerContainer { } } +type D3DCompileFn = unsafe extern "system" fn( + psrcdata: *const core::ffi::c_void, + srcdatasize: usize, + psourcename: PCSTR, + pdefines: *const D3D_SHADER_MACRO, + pinclude: *mut core::ffi::c_void, + pentrypoint: PCSTR, + ptarget: PCSTR, + flags1: u32, + flags2: u32, + ppcode: *mut *mut core::ffi::c_void, + pperrormsgs: *mut *mut core::ffi::c_void, +) -> windows_core::HRESULT; + #[derive(Debug)] struct FxcLib { - lib: crate::dx12::DynLib, + // `d3dcompile_fn` points into `_lib`, so `_lib` must be held for as long + // as we want to keep compiling shaders with FXC. + _lib: crate::dx12::DynLib, + d3dcompile_fn: D3DCompileFn, } impl FxcLib { const PATH: &str = "d3dcompiler_47.dll"; - fn new_dynamic() -> Result { - unsafe { crate::dx12::DynLib::new(Self::PATH).map(|lib| Self { lib }) } + fn new_dynamic() -> Result { + unsafe { + let lib = crate::dx12::DynLib::new(Self::PATH) + .map_err(|e| GetContainerError::FailedToLoad(FxcLib::PATH, e))?; + let d3dcompile_fn: D3DCompileFn = *lib.get::(c"D3DCompile".to_bytes())?; + + Ok(Self { + _lib: lib, + d3dcompile_fn, + }) + } } fn compile( &self, - psrcdata: *const core::ffi::c_void, - srcdatasize: usize, - psourcename: PCSTR, - pdefines: Option<*const D3D_SHADER_MACRO>, - pinclude: Option<*mut ID3DInclude>, - pentrypoint: PCSTR, - ptarget: PCSTR, - flags1: u32, - flags2: u32, - ppcode: *mut Option, - pperrormsgs: Option<*mut Option>, + source: &str, + source_name: Option<&CStr>, + raw_ep: &str, + full_stage: &str, + compile_flags: u32, + shader_data: &mut Option, + error: &mut Option, ) -> Result, crate::DeviceError> { unsafe { - type D3DCompileFn = unsafe extern "system" fn( - psrcdata: *const core::ffi::c_void, - srcdatasize: usize, - psourcename: PCSTR, - pdefines: *const D3D_SHADER_MACRO, - pinclude: *mut core::ffi::c_void, - pentrypoint: PCSTR, - ptarget: PCSTR, - flags1: u32, - flags2: u32, - ppcode: *mut *mut core::ffi::c_void, - pperrormsgs: *mut *mut core::ffi::c_void, - ) -> windows_core::HRESULT; - - let d3dcompile_fn: libloading::Symbol = - self.lib.get(c"D3DCompile".to_bytes())?; - - Ok(d3dcompile_fn( - psrcdata, - srcdatasize, - psourcename, - pdefines.unwrap_or(core::ptr::null()), - core::mem::transmute(pinclude.unwrap_or(core::ptr::null_mut())), - pentrypoint, - ptarget, - flags1, - flags2, - core::mem::transmute(ppcode), - core::mem::transmute(pperrormsgs.unwrap_or(core::ptr::null_mut())), - ) - .ok()) + let raw_ep = alloc::ffi::CString::new(raw_ep).unwrap(); + let full_stage = alloc::ffi::CString::new(full_stage).unwrap(); + + // If no name has been set, D3DCompile wants the null pointer. + let source_name = source_name + .map(|cstr| cstr.as_ptr().cast()) + .unwrap_or(core::ptr::null()); + + { + profiling::scope!("Fxc::D3DCompile"); + Ok((self.d3dcompile_fn)( + source.as_ptr().cast(), + source.len(), + PCSTR(source_name), + core::ptr::null(), + core::ptr::null_mut(), + PCSTR(raw_ep.as_ptr().cast()), + PCSTR(full_stage.as_ptr().cast()), + compile_flags, + 0, + core::mem::transmute::<&mut Option<_>, *mut *mut core::ffi::c_void>( + shader_data, + ), + core::mem::transmute::<&mut Option<_>, *mut *mut core::ffi::c_void>(error), + ) + .ok()) + } } } } @@ -206,7 +221,6 @@ fn compile_fxc( fxc: &FxcLib, ) -> Result { profiling::scope!("compile_fxc"); - let mut shader_data = None; let mut compile_flags = Fxc::D3DCOMPILE_ENABLE_STRICTNESS; if device .shared @@ -217,32 +231,17 @@ fn compile_fxc( compile_flags |= Fxc::D3DCOMPILE_DEBUG | Fxc::D3DCOMPILE_SKIP_OPTIMIZATION; } - let raw_ep = alloc::ffi::CString::new(raw_ep).unwrap(); - let full_stage = alloc::ffi::CString::new(full_stage).unwrap(); - - // If no name has been set, D3DCompile wants the null pointer. - let source_name = source_name - .map(|cstr| cstr.as_ptr().cast()) - .unwrap_or(core::ptr::null()); - + let mut shader_data = None; let mut error = None; - let hr = { - profiling::scope!("Fxc::D3DCompile"); - fxc.compile( - // TODO: Update low-level bindings to accept a slice here - source.as_ptr().cast(), - source.len(), - PCSTR(source_name), - None, - None, - PCSTR(raw_ep.as_ptr().cast()), - PCSTR(full_stage.as_ptr().cast()), - compile_flags, - 0, - &mut shader_data, - Some(&mut error), - )? - }; + let hr = fxc.compile( + source, + source_name, + raw_ep, + full_stage, + compile_flags, + &mut shader_data, + &mut error, + )?; match hr { Ok(()) => { From 64d7e5510387a751f7371d903f09bea03250250e Mon Sep 17 00:00:00 2001 From: RedMindZ Date: Wed, 23 Apr 2025 02:09:59 +0300 Subject: [PATCH 3/4] More clippy fixes. --- wgpu-hal/src/dx12/shader_compilation.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 79c949150f..23e8e1fe1b 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -169,6 +169,7 @@ impl FxcLib { } } + #[allow(clippy::too_many_arguments)] fn compile( &self, source: &str, @@ -188,6 +189,9 @@ impl FxcLib { .map(|cstr| cstr.as_ptr().cast()) .unwrap_or(core::ptr::null()); + let shader_data: *mut Option = shader_data; + let error: *mut Option = error; + { profiling::scope!("Fxc::D3DCompile"); Ok((self.d3dcompile_fn)( @@ -200,10 +204,8 @@ impl FxcLib { PCSTR(full_stage.as_ptr().cast()), compile_flags, 0, - core::mem::transmute::<&mut Option<_>, *mut *mut core::ffi::c_void>( - shader_data, - ), - core::mem::transmute::<&mut Option<_>, *mut *mut core::ffi::c_void>(error), + shader_data as *mut *mut core::ffi::c_void, + error as *mut *mut core::ffi::c_void, ) .ok()) } From a87c4eebe5258f7e0b5b3ccfc1658f5eb48edd51 Mon Sep 17 00:00:00 2001 From: RedMindZ Date: Wed, 23 Apr 2025 02:19:21 +0300 Subject: [PATCH 4/4] Even more clippy fixes. --- wgpu-hal/src/dx12/shader_compilation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 23e8e1fe1b..c93bd772fd 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -204,8 +204,8 @@ impl FxcLib { PCSTR(full_stage.as_ptr().cast()), compile_flags, 0, - shader_data as *mut *mut core::ffi::c_void, - error as *mut *mut core::ffi::c_void, + shader_data.cast(), + error.cast(), ) .ok()) }