From 5978f95f763827ec19fc972984dfb24fc7379a75 Mon Sep 17 00:00:00 2001 From: chyyran Date: Wed, 2 Oct 2024 18:04:36 -0400 Subject: [PATCH] reflect: make `ShaderPassArtifact` simpler as `PassResource` already includes the source data --- librashader-reflect/src/reflect/presets.rs | 30 +++++++++---------- librashader-runtime-d3d11/src/filter_chain.rs | 6 ++-- librashader-runtime-d3d12/src/filter_chain.rs | 15 ++++------ librashader-runtime-d3d9/src/filter_chain.rs | 6 ++-- .../src/filter_chain/chain.rs | 6 ++-- librashader-runtime-mtl/src/filter_chain.rs | 10 +++---- librashader-runtime-vk/src/filter_chain.rs | 12 ++++---- librashader-runtime-wgpu/src/filter_chain.rs | 10 +++---- 8 files changed, 46 insertions(+), 49 deletions(-) diff --git a/librashader-reflect/src/reflect/presets.rs b/librashader-reflect/src/reflect/presets.rs index dc0e581..f1f57df 100644 --- a/librashader-reflect/src/reflect/presets.rs +++ b/librashader-reflect/src/reflect/presets.rs @@ -8,7 +8,7 @@ use crate::reflect::semantics::{ use librashader_common::map::{FastHashMap, ShortString}; use librashader_pack::PassResource; use librashader_preprocess::{PreprocessError, ShaderSource}; -use librashader_presets::{PassMeta, ShaderPreset, TextureMeta}; +use librashader_presets::{ShaderPreset, TextureMeta}; /// Artifacts of a reflected and compiled shader pass. /// @@ -28,7 +28,7 @@ use librashader_presets::{PassMeta, ShaderPreset, TextureMeta}; /// ``` /// /// This allows a runtime to not name the backing type of the compiled artifact if not necessary. -pub type ShaderPassArtifact = (PassMeta, ShaderSource, CompilerBackend); +pub type ShaderPassArtifact = (PassResource, CompilerBackend); impl CompilePresetTarget for T {} @@ -38,7 +38,7 @@ pub trait CompilePresetTarget: OutputTarget { /// Compile passes of a shader preset given the applicable /// shader output target, compilation type, and resulting error. fn compile_preset_passes<'a, I, R, E>( - passes: Vec, + passes: impl IntoIterator, textures: impl Iterator, ) -> Result< ( @@ -63,7 +63,7 @@ pub trait CompilePresetTarget: OutputTarget { /// Compile passes of a shader preset given the applicable /// shader output target, compilation type, and resulting error. fn compile_preset_passes<'a, T, I, R, E>( - passes: Vec, + passes: impl IntoIterator, textures: impl Iterator, ) -> Result< ( @@ -85,11 +85,11 @@ where let mut texture_semantics: FastHashMap> = Default::default(); - let passes = passes + let artifacts = passes .into_iter() .map(|shader| { - let source = shader.data; - let compiled = I::Compiler::compile(&source)?; + let source = &shader.data; + let compiled = I::Compiler::compile(source)?; let reflect = T::from_compilation(compiled)?; for parameter in source.parameters.values() { @@ -101,22 +101,22 @@ where }), ); } - Ok::<_, E>((shader.meta, source, reflect)) + Ok::<_, E>((shader, reflect)) }) - .collect::)>, E>>()?; + .collect::)>, E>>()?; - for (meta, source, _) in &passes { + for (pass, _) in artifacts.iter() { insert_pass_semantics( &mut uniform_semantics, &mut texture_semantics, - meta.alias.as_ref(), - meta.id as usize, + pass.meta.alias.as_ref(), + pass.meta.id as usize, ); insert_pass_semantics( &mut uniform_semantics, &mut texture_semantics, - source.name.as_ref(), - meta.id as usize, + pass.data.name.as_ref(), + pass.meta.id as usize, ); } @@ -127,7 +127,7 @@ where texture_semantics, }; - Ok((passes, semantics)) + Ok((artifacts, semantics)) } /// Insert the available semantics for the input pass config into the provided semantic maps. diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 124ef46..2b7f177 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -282,7 +282,7 @@ impl FilterChainD3D11 { let device_is_singlethreaded = unsafe { (device.GetCreationFlags() & D3D11_CREATE_DEVICE_SINGLETHREADED.0) == 1 }; - let builder_fn = |(index, (config, source, mut reflect)): (usize, ShaderPassMeta)| { + let builder_fn = |(index, (config, mut reflect)): (usize, ShaderPassMeta)| { let reflection = reflect.reflect(index, semantics)?; let hlsl = reflect.compile(None)?; @@ -365,8 +365,8 @@ impl FilterChainD3D11 { uniform_storage, uniform_buffer: ubo_cbuffer, push_buffer: push_cbuffer, - source, - meta: config, + source: config.data, + meta: config.meta, }) }; diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index 28017e4..6614ef4 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -565,10 +565,7 @@ impl FilterChainD3D12 { |dxc, ( index, - ( - (((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap), - mut sampler_heap, - ), + ((((config, mut dxil), (_, mut hlsl)), mut texture_heap), mut sampler_heap), )| { let Ok((validator, library, compiler)) = dxc else { return Err(FilterChainError::Direct3DOperationError( @@ -581,10 +578,10 @@ impl FilterChainD3D12 { librashader_reflect::back::dxil::ShaderModel::ShaderModel6_0, ))?; - let render_format = if let Some(format) = config.get_format_override() { + let render_format = if let Some(format) = config.meta.get_format_override() { format - } else if source.format != ImageFormat::Unknown { - source.format + } else if config.data.format != ImageFormat::Unknown { + config.data.format } else { ImageFormat::R8G8B8A8Unorm } @@ -650,10 +647,10 @@ impl FilterChainD3D12 { uniform_bindings, uniform_storage, pipeline: graphics_pipeline, - meta: config, + meta: config.meta, texture_heap, sampler_heap, - source, + source: config.data, }) }, ) diff --git a/librashader-runtime-d3d9/src/filter_chain.rs b/librashader-runtime-d3d9/src/filter_chain.rs index 8c896eb..74ca87d 100644 --- a/librashader-runtime-d3d9/src/filter_chain.rs +++ b/librashader-runtime-d3d9/src/filter_chain.rs @@ -107,7 +107,7 @@ impl FilterChainD3D9 { semantics: &ShaderSemantics, disable_cache: bool, ) -> error::Result> { - let builder_fn = |(index, (config, source, mut reflect)): (usize, ShaderPassMeta)| { + let builder_fn = |(index, (config, mut reflect)): (usize, ShaderPassMeta)| { let mut reflection = reflect.reflect(index, semantics)?; let hlsl = reflect.compile(Some(HlslShaderModel::ShaderModel3_0))?; @@ -174,8 +174,8 @@ impl FilterChainD3D9 { uniform_bindings, uniform_storage, gl_halfpixel, - source, - meta: config, + source: config.data, + meta: config.meta, }) }; diff --git a/librashader-runtime-gl/src/filter_chain/chain.rs b/librashader-runtime-gl/src/filter_chain/chain.rs index f19c9d2..7b7d4ec 100644 --- a/librashader-runtime-gl/src/filter_chain/chain.rs +++ b/librashader-runtime-gl/src/filter_chain/chain.rs @@ -221,7 +221,7 @@ impl FilterChainImpl { let mut filters = Vec::new(); // initialize passes - for (index, (config, source, mut reflect)) in passes.into_iter().enumerate() { + for (index, (config, mut reflect)) in passes.into_iter().enumerate() { let reflection = reflect.reflect(index, semantics)?; let glsl = reflect.compile(version)?; @@ -257,8 +257,8 @@ impl FilterChainImpl { ubo_ring, uniform_storage, uniform_bindings, - source, - meta: config, + source: config.data, + meta: config.meta, }); } diff --git a/librashader-runtime-mtl/src/filter_chain.rs b/librashader-runtime-mtl/src/filter_chain.rs index fa2164e..e46ba7b 100644 --- a/librashader-runtime-mtl/src/filter_chain.rs +++ b/librashader-runtime-mtl/src/filter_chain.rs @@ -179,7 +179,7 @@ impl FilterChainMetal { let filters: Vec> = passes .into_iter() .enumerate() - .map(|(index, (config, source, mut reflect))| { + .map(|(index, (config, mut reflect))| { let reflection = reflect.reflect(index, semantics)?; let msl = reflect.compile(Some(MslVersion::new(2, 0, 0)))?; @@ -197,10 +197,10 @@ impl FilterChainMetal { let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset()); let render_pass_format: MTLPixelFormat = - if let Some(format) = config.get_format_override() { + if let Some(format) = config.meta.get_format_override() { format.into() } else { - source.format.into() + config.data.format.into() }; let graphics_pipeline = MetalGraphicsPipeline::new( @@ -217,8 +217,8 @@ impl FilterChainMetal { reflection, uniform_storage, uniform_bindings, - source, - meta: config, + source: config.data, + meta: config.meta, graphics_pipeline, }) }) diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 0d4badd..94c7671 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -498,7 +498,7 @@ impl FilterChainVulkan { let filters: Vec> = passes .into_par_iter() .enumerate() - .map(|(index, (config, source, mut reflect))| { + .map(|(index, (config, mut reflect))| { let reflection = reflect.reflect(index, semantics)?; let spirv_words = reflect.compile(None)?; @@ -520,10 +520,10 @@ impl FilterChainVulkan { let render_pass_format = if use_dynamic_rendering { vk::Format::UNDEFINED - } else if let Some(format) = config.get_format_override() { + } else if let Some(format) = config.meta.get_format_override() { format.into() - } else if source.format != ImageFormat::Unknown { - source.format.into() + } else if config.data.format != ImageFormat::Unknown { + config.data.format.into() } else { ImageFormat::R8G8B8A8Unorm.into() }; @@ -542,8 +542,8 @@ impl FilterChainVulkan { // compiled: spirv_words, uniform_storage, uniform_bindings, - source, - meta: config, + source: config.data, + meta: config.meta, graphics_pipeline, // ubo_ring, frames_in_flight, diff --git a/librashader-runtime-wgpu/src/filter_chain.rs b/librashader-runtime-wgpu/src/filter_chain.rs index f53d43a..c8c1901 100644 --- a/librashader-runtime-wgpu/src/filter_chain.rs +++ b/librashader-runtime-wgpu/src/filter_chain.rs @@ -314,7 +314,7 @@ impl FilterChainWgpu { let filters: Vec> = passes_iter .enumerate() - .map(|(index, (config, source, mut reflect))| { + .map(|(index, (config, mut reflect))| { let reflection = reflect.reflect(index, semantics)?; let wgsl = reflect.compile(NagaLoweringOptions { write_pcb_as_ubo: true, @@ -346,10 +346,10 @@ impl FilterChainWgpu { reflection.meta.create_binding_map(|param| param.offset()); let render_pass_format: Option = - if let Some(format) = config.get_format_override() { + if let Some(format) = config.meta.get_format_override() { format.into() } else { - source.format.into() + config.data.format.into() }; let graphics_pipeline = WgpuGraphicsPipeline::new( @@ -366,8 +366,8 @@ impl FilterChainWgpu { reflection, uniform_storage, uniform_bindings, - source, - meta: config, + source: config.data, + meta: config.meta, graphics_pipeline, }) })