reflect: get rid of meaningful indices for variable semantics

This commit is contained in:
chyyran 2022-11-13 02:05:49 -05:00
parent b987953181
commit b1beb0e46f
4 changed files with 27 additions and 21 deletions

View file

@ -313,7 +313,7 @@ where
match &parameter.semantics {
VariableSemantics::FloatParameter => {
let offset = offset_type(range.offset);
if let Some(meta) = meta.parameter_meta.get(&parameter.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: (),
}),
);
}

View file

@ -23,33 +23,33 @@ pub trait TextureSemanticMap<T> {
}
pub trait VariableSemanticMap<T> {
fn get_variable_semantic(&self, name: &str) -> Option<SemanticMap<VariableSemantics>>;
fn get_variable_semantic(&self, name: &str) -> Option<SemanticMap<VariableSemantics, ()>>;
}
impl VariableSemanticMap<UniformSemantic> for FxHashMap<String, UniformSemantic> {
fn get_variable_semantic(&self, name: &str) -> Option<SemanticMap<VariableSemantics>> {
fn get_variable_semantic(&self, name: &str) -> Option<SemanticMap<VariableSemantics, ()>> {
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<UniformSemantic> for FxHashMap<String, SemanticMap<Textu
#[derive(Debug, Clone)]
pub enum UniformSemantic {
Variable(SemanticMap<VariableSemantics>),
Variable(SemanticMap<VariableSemantics, ()>),
Texture(SemanticMap<TextureSemantics>),
}
@ -134,7 +134,7 @@ pub struct ReflectSemantics {
#[derive(Debug, Default)]
pub struct ReflectMeta {
pub parameter_meta: FxHashMap<u32, VariableMeta>,
pub parameter_meta: FxHashMap<String, VariableMeta>,
pub variable_meta: FxHashMap<VariableSemantics, VariableMeta>,
pub texture_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureImage>,
pub texture_size_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureSizeMeta>,

View file

@ -79,9 +79,9 @@ pub trait ValidateTypeSemantics<T> {
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct SemanticMap<T> {
pub struct SemanticMap<T, I=u32> {
pub semantics: T,
pub index: u32,
pub index: I,
}
bitflags! {

View file

@ -161,6 +161,13 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
.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<Path>) -> Result<(), Box<dyn Error>>{
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<Path>) -> Result<(), Box<dyn Error>>{
locations.insert(param.id.clone(), reflect_parameter(program, param));
}
// eprintln!("{:#?}", semantics);
eprintln!("{:#?}", reflection.meta);
eprintln!("{:#?}", locations);