d3d12: enable parallel shader compilation

Turns out the weird errors were because of mipmapping
This commit is contained in:
chyyran 2023-02-05 20:03:59 -05:00
parent a3589cc794
commit 34b334fd7f

View file

@ -49,8 +49,9 @@ use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleO
use windows::Win32::System::WindowsProgramming::INFINITE;
use crate::error::FilterChainError;
type DxilShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation>>;
type HlslShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation>>;
use rayon::prelude::*;
type DxilShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
type HlslShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
pub struct FilterMutable {
pub(crate) passes_enabled: usize,
@ -343,13 +344,6 @@ impl FilterChainD3D12 {
semantics: &ShaderSemantics,
force_hlsl: bool,
) -> error::Result<(ID3D12DescriptorHeap, ID3D12DescriptorHeap, Vec<FilterPass>)> {
let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? };
let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? };
let mut filters = Vec::new();
let shader_count = passes.len();
let work_heap = D3D12DescriptorHeap::<ResourceWorkHeap>::new(
device,
@ -364,16 +358,17 @@ impl FilterChainD3D12 {
let (sampler_work_heaps, sampler_heap_handle) =
unsafe { sampler_work_heap.suballocate(MAX_BINDINGS_COUNT as usize) };
for (
index,
((((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap), mut sampler_heap),
) in passes
.into_iter()
let filters: Vec<error::Result<_>> = passes.into_par_iter()
.zip(hlsl_passes)
.zip(work_heaps)
.zip(sampler_work_heaps)
.enumerate()
{
.map(|(
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 dxil_reflection = dxil.reflect(index, semantics)?;
let dxil = dxil.compile(Some(
librashader_reflect::back::dxil::ShaderModel::ShaderModel6_0,
@ -442,21 +437,50 @@ impl FilterChainD3D12 {
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
Ok((reflection,
uniform_bindings,
uniform_storage,
push_cbuffer,
ubo_cbuffer,
graphics_pipeline,
config.clone(),
source))
}).collect();
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
let filters = filters?;
let filters: Vec<error::Result<FilterPass>> = filters.into_iter()
.zip(work_heaps)
.zip(sampler_work_heaps)
.map(|(((reflection,
uniform_bindings,
uniform_storage,
push_cbuffer,
ubo_cbuffer,
pipeline,
config,
source), mut texture_heap), mut sampler_heap)| {
let texture_heap = texture_heap.alloc_range()?;
let sampler_heap = sampler_heap.alloc_range()?;
filters.push(FilterPass {
Ok(FilterPass {
reflection,
uniform_bindings,
uniform_storage,
push_cbuffer,
ubo_cbuffer,
pipeline: graphics_pipeline,
config: config.clone(),
pipeline,
config,
texture_heap,
sampler_heap,
source,
})
}
})
.collect();
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
let filters = filters?;
Ok((texture_heap_handle, sampler_heap_handle, filters))
}