From 621d1da3c29ea794084fb2db9da4a7510307b45c Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 5 Feb 2023 21:17:16 -0500 Subject: [PATCH] dx12: reduce initializations of dxc --- librashader-runtime-d3d12/src/filter_chain.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index a2c9d3c..fdaf75f 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -362,11 +362,18 @@ impl FilterChainD3D12 { let filters: Vec> = passes.into_par_iter() .zip(hlsl_passes) .enumerate() - .map(|(index, ((config, source, mut dxil), + .map_init( + || { + let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? }; + let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? }; + let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? }; + Ok::<_, FilterChainError>((validator, library, compiler)) + }, + |dxc, (index, ((config, source, mut dxil), (_, _, mut hlsl)))| { - let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? }; - let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? }; - let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? }; + let Ok((validator, library, compiler)) = dxc else { + return Err(FilterChainError::Direct3DOperationError("Could not initialize DXC for thread")); + }; let dxil_reflection = dxil.reflect(index, semantics)?; let dxil = dxil.compile(Some( @@ -446,6 +453,7 @@ impl FilterChainD3D12 { let filters: error::Result> = filters.into_iter().collect(); let filters = filters?; + /// Need to take care of the heaps in a single thread because [;16] is not sized..? let filters: Vec> = filters .into_iter() .zip(work_heaps)