diff --git a/librashader-reflect/src/reflect/cross.rs b/librashader-reflect/src/reflect/cross.rs index 1c692db..eb6851a 100644 --- a/librashader-reflect/src/reflect/cross.rs +++ b/librashader-reflect/src/reflect/cross.rs @@ -313,7 +313,7 @@ where match ¶meter.semantics { VariableSemantics::FloatParameter => { let offset = offset_type(range.offset); - if let Some(meta) = meta.parameter_meta.get(¶meter.index) { + if let Some(meta) = meta.parameter_meta.get(&name) { if offset != meta.offset { return Err(ShaderReflectError::MismatchedOffset { semantic: name, @@ -330,7 +330,7 @@ where } } else { meta.parameter_meta.insert( - parameter.index, + name.clone(), VariableMeta { id: name, offset, @@ -863,7 +863,7 @@ mod test { param.id.clone(), UniformSemantic::Variable(SemanticMap { semantics: VariableSemantics::FloatParameter, - index: index as u32, + index: (), }), ); } diff --git a/librashader-reflect/src/reflect/mod.rs b/librashader-reflect/src/reflect/mod.rs index 75ba5e6..e4d35ba 100644 --- a/librashader-reflect/src/reflect/mod.rs +++ b/librashader-reflect/src/reflect/mod.rs @@ -23,33 +23,33 @@ pub trait TextureSemanticMap { } pub trait VariableSemanticMap { - fn get_variable_semantic(&self, name: &str) -> Option>; + fn get_variable_semantic(&self, name: &str) -> Option>; } impl VariableSemanticMap for FxHashMap { - fn get_variable_semantic(&self, name: &str) -> Option> { + fn get_variable_semantic(&self, name: &str) -> Option> { match self.get(name) { // existing uniforms in the semantic map have priority None => match name { "MVP" => Some(SemanticMap { semantics: VariableSemantics::MVP, - index: 0, + index: (), }), "OutputSize" => Some(SemanticMap { semantics: VariableSemantics::Output, - index: 0, + index: (), }), "FinalViewportSize" => Some(SemanticMap { semantics: VariableSemantics::FinalViewport, - index: 0, + index: (), }), "FrameCount" => Some(SemanticMap { semantics: VariableSemantics::FrameCount, - index: 0, + index: (), }), "FrameDirection" => Some(SemanticMap { semantics: VariableSemantics::FrameDirection, - index: 0, + index: (), }), _ => None, }, @@ -122,7 +122,7 @@ impl TextureSemanticMap for FxHashMap), + Variable(SemanticMap), Texture(SemanticMap), } @@ -134,7 +134,7 @@ pub struct ReflectSemantics { #[derive(Debug, Default)] pub struct ReflectMeta { - pub parameter_meta: FxHashMap, + pub parameter_meta: FxHashMap, pub variable_meta: FxHashMap, pub texture_meta: FxHashMap, TextureImage>, pub texture_size_meta: FxHashMap, TextureSizeMeta>, diff --git a/librashader-reflect/src/reflect/semantics.rs b/librashader-reflect/src/reflect/semantics.rs index 2f3403c..10e0655 100644 --- a/librashader-reflect/src/reflect/semantics.rs +++ b/librashader-reflect/src/reflect/semantics.rs @@ -79,9 +79,9 @@ pub trait ValidateTypeSemantics { } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct SemanticMap { +pub struct SemanticMap { pub semantics: T, - pub index: u32, + pub index: I, } bitflags! { diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index 4799996..5999015 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -161,6 +161,13 @@ pub fn load(path: impl AsRef) -> Result<(), Box>{ .unwrap(); let mut reflect = GLSL::from_compilation(spirv).unwrap(); + for parameter in source.parameters.iter() { + uniform_semantics.insert(parameter.id.clone(), UniformSemantic::Variable(SemanticMap { + semantics: VariableSemantics::FloatParameter, + index: () + })); + } + (shader, source, reflect) }).collect(); @@ -194,12 +201,12 @@ pub fn load(path: impl AsRef) -> Result<(), Box>{ let mut semantics = semantics.clone(); // insert parameters parsed from source - for (index, parameter) in source.parameters.iter().enumerate() { - semantics.uniform_semantics.insert(parameter.id.clone(), UniformSemantic::Variable(SemanticMap { - semantics: VariableSemantics::FloatParameter, - index: index as u32 - })); - } + // for (index, parameter) in source.parameters.iter().enumerate() { + // semantics.uniform_semantics.insert(parameter.id.clone(), UniformSemantic::Variable(SemanticMap { + // semantics: VariableSemantics::FloatParameter, + // index: 0 + // })); + // } let reflection = reflect.reflect(index as u32, &semantics)?; @@ -279,7 +286,6 @@ pub fn load(path: impl AsRef) -> Result<(), Box>{ locations.insert(param.id.clone(), reflect_parameter(program, param)); } - // eprintln!("{:#?}", semantics); eprintln!("{:#?}", reflection.meta); eprintln!("{:#?}", locations);