From 40e4ce908f2461e324446a349e1e28f82e61fbdd Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 15 Jan 2023 14:06:38 -0500 Subject: [PATCH] preprocess: store parameters in FxHashMap --- Cargo.lock | 1 + librashader-capi/src/error.rs | 4 ---- librashader-capi/src/presets.rs | 2 +- librashader-preprocess/Cargo.toml | 1 + librashader-preprocess/src/lib.rs | 7 +++++-- librashader-reflect/src/reflect/cross.rs | 16 ++++++++-------- librashader-runtime-d3d11/src/filter_chain.rs | 2 +- .../src/filter_chain/filter_impl.rs | 2 +- librashader-runtime-vk/src/filter_chain.rs | 2 +- librashader-runtime/src/binding.rs | 9 ++++----- librashader-runtime/src/uniforms.rs | 1 - librashader/src/lib.rs | 4 +++- 12 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa75ecf..9e3847c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,6 +814,7 @@ version = "0.1.0-beta.6" dependencies = [ "librashader-common", "nom", + "rustc-hash", "thiserror", ] diff --git a/librashader-capi/src/error.rs b/librashader-capi/src/error.rs index 25f5ccb..ab91139 100644 --- a/librashader-capi/src/error.rs +++ b/librashader-capi/src/error.rs @@ -194,10 +194,6 @@ impl LibrashaderError { None } - pub(crate) fn panic(panic: Box) -> libra_error_t { - LibrashaderError::UnknownError(panic).export() - } - pub(crate) fn export(self) -> libra_error_t { NonNull::new(Box::into_raw(Box::new(self))) } diff --git a/librashader-capi/src/presets.rs b/librashader-capi/src/presets.rs index 5c1b948..77e2426 100644 --- a/librashader-capi/src/presets.rs +++ b/librashader-capi/src/presets.rs @@ -141,7 +141,7 @@ extern_fn! { } extern_fn! { - /// Get a list of runtime parameter names. + /// Get a list of runtime parameters. /// /// ## Safety /// - `preset` must be null or a valid and aligned pointer to a shader preset. diff --git a/librashader-preprocess/Cargo.toml b/librashader-preprocess/Cargo.toml index 6d443fc..a5a3c5e 100644 --- a/librashader-preprocess/Cargo.toml +++ b/librashader-preprocess/Cargo.toml @@ -15,6 +15,7 @@ description = "RetroArch shaders for all." thiserror = "1.0.37" nom = "7.1.1" librashader-common = { path = "../librashader-common", version = "0.1.0-beta.6" } +rustc-hash = "1.1.0" [features] default = [ "line_directives" ] diff --git a/librashader-preprocess/src/lib.rs b/librashader-preprocess/src/lib.rs index b1ffa5d..45326ff 100644 --- a/librashader-preprocess/src/lib.rs +++ b/librashader-preprocess/src/lib.rs @@ -7,6 +7,7 @@ use crate::include::read_source; pub use error::*; use librashader_common::ImageFormat; use std::path::Path; +use rustc_hash::FxHashMap; /// The source file for a single shader pass. #[derive(Debug, Clone, PartialEq)] @@ -21,7 +22,7 @@ pub struct ShaderSource { pub name: Option, /// The list of shader parameters found in the shader source. - pub parameters: Vec, + pub parameters: FxHashMap, /// The image format the shader expects. pub format: ImageFormat, @@ -71,12 +72,14 @@ pub(crate) fn load_shader_source(path: impl AsRef) -> Result { - id: u32, + // id: u32, + // descriptor_set: u32, name: &'a str, - descriptor_set: u32, binding: u32, } @@ -276,9 +276,9 @@ where let size = ast.get_declared_struct_size(ubo.base_type_id)?; Ok(UboData { - descriptor_set, + // descriptor_set, + // id: ubo.id, binding, - id: ubo.id, size, }) } @@ -538,9 +538,9 @@ where } Ok(TextureData { - id: texture.id, + // id: texture.id, + // descriptor_set, name: &texture.name, - descriptor_set, binding, }) } diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index ac2eb4a..133a7d7 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -426,7 +426,7 @@ impl FilterChainD3D11 { let spirv = GlslangCompilation::compile(&source)?; let reflect = HLSL::from_compilation(spirv)?; - for parameter in source.parameters.iter() { + for parameter in source.parameters.values() { uniform_semantics.insert( parameter.id.clone(), UniformSemantic::Unique(Semantic { diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index 1356af9..dad8fbd 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -173,7 +173,7 @@ impl FilterChainImpl { let spirv = GlslangCompilation::compile(&source)?; let reflect = GLSL::from_compilation(spirv)?; - for parameter in source.parameters.iter() { + for parameter in source.parameters.values() { uniform_semantics.insert( parameter.id.clone(), UniformSemantic::Unique(Semantic { diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index a97419a..d87a5ae 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -297,7 +297,7 @@ impl FilterChainVulkan { let spirv = GlslangCompilation::compile(&source)?; let reflect = SPIRV::from_compilation(spirv)?; - for parameter in source.parameters.iter() { + for parameter in source.parameters.values() { uniform_semantics.insert( parameter.id.clone(), UniformSemantic::Unique(Semantic { diff --git a/librashader-runtime/src/binding.rs b/librashader-runtime/src/binding.rs index f8522d0..507b721 100644 --- a/librashader-runtime/src/binding.rs +++ b/librashader-runtime/src/binding.rs @@ -99,7 +99,7 @@ where pass_feedback: impl Iterator>>, original_history: impl Iterator>>, lookup_textures: impl Iterator)>, - parameter_defaults: &[ShaderParameter], + parameter_defaults: &HashMap, runtime_parameters: &HashMap, ) { // Bind MVP @@ -238,13 +238,12 @@ where { let id = id.as_str(); - let default = parameter_defaults - .iter() - .find(|&p| p.id == id) + let default = parameter_defaults.get(id) .map(|f| f.initial) .unwrap_or(0f32); - let value = *runtime_parameters.get(id).unwrap_or(&default); + let value = *runtime_parameters.get(id) + .unwrap_or(&default); uniform_storage.bind_scalar(offset.offset(), value, offset.context()); } diff --git a/librashader-runtime/src/uniforms.rs b/librashader-runtime/src/uniforms.rs index 6c2802d..9ff37b2 100644 --- a/librashader-runtime/src/uniforms.rs +++ b/librashader-runtime/src/uniforms.rs @@ -1,4 +1,3 @@ -use librashader_common::Size; use librashader_reflect::reflect::semantics::MemberOffset; use std::marker::PhantomData; diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index 291032a..7fe5943 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -47,7 +47,9 @@ pub mod presets { let iters: Result>, PreprocessError> = preset .shaders .iter() - .map(|s| ShaderSource::load(&s.name).map(|s| s.parameters)) + .map(|s| ShaderSource::load(&s.name).map(|s| + s.parameters.into_values() + .collect())) .into_iter() .collect(); let iters = iters?;