reflect: get rid of meaningful indices for variable semantics
This commit is contained in:
parent
b987953181
commit
b1beb0e46f
|
@ -313,7 +313,7 @@ where
|
||||||
match ¶meter.semantics {
|
match ¶meter.semantics {
|
||||||
VariableSemantics::FloatParameter => {
|
VariableSemantics::FloatParameter => {
|
||||||
let offset = offset_type(range.offset);
|
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 {
|
if offset != meta.offset {
|
||||||
return Err(ShaderReflectError::MismatchedOffset {
|
return Err(ShaderReflectError::MismatchedOffset {
|
||||||
semantic: name,
|
semantic: name,
|
||||||
|
@ -330,7 +330,7 @@ where
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
meta.parameter_meta.insert(
|
meta.parameter_meta.insert(
|
||||||
parameter.index,
|
name.clone(),
|
||||||
VariableMeta {
|
VariableMeta {
|
||||||
id: name,
|
id: name,
|
||||||
offset,
|
offset,
|
||||||
|
@ -863,7 +863,7 @@ mod test {
|
||||||
param.id.clone(),
|
param.id.clone(),
|
||||||
UniformSemantic::Variable(SemanticMap {
|
UniformSemantic::Variable(SemanticMap {
|
||||||
semantics: VariableSemantics::FloatParameter,
|
semantics: VariableSemantics::FloatParameter,
|
||||||
index: index as u32,
|
index: (),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,33 +23,33 @@ pub trait TextureSemanticMap<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait VariableSemanticMap<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> {
|
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) {
|
match self.get(name) {
|
||||||
// existing uniforms in the semantic map have priority
|
// existing uniforms in the semantic map have priority
|
||||||
None => match name {
|
None => match name {
|
||||||
"MVP" => Some(SemanticMap {
|
"MVP" => Some(SemanticMap {
|
||||||
semantics: VariableSemantics::MVP,
|
semantics: VariableSemantics::MVP,
|
||||||
index: 0,
|
index: (),
|
||||||
}),
|
}),
|
||||||
"OutputSize" => Some(SemanticMap {
|
"OutputSize" => Some(SemanticMap {
|
||||||
semantics: VariableSemantics::Output,
|
semantics: VariableSemantics::Output,
|
||||||
index: 0,
|
index: (),
|
||||||
}),
|
}),
|
||||||
"FinalViewportSize" => Some(SemanticMap {
|
"FinalViewportSize" => Some(SemanticMap {
|
||||||
semantics: VariableSemantics::FinalViewport,
|
semantics: VariableSemantics::FinalViewport,
|
||||||
index: 0,
|
index: (),
|
||||||
}),
|
}),
|
||||||
"FrameCount" => Some(SemanticMap {
|
"FrameCount" => Some(SemanticMap {
|
||||||
semantics: VariableSemantics::FrameCount,
|
semantics: VariableSemantics::FrameCount,
|
||||||
index: 0,
|
index: (),
|
||||||
}),
|
}),
|
||||||
"FrameDirection" => Some(SemanticMap {
|
"FrameDirection" => Some(SemanticMap {
|
||||||
semantics: VariableSemantics::FrameDirection,
|
semantics: VariableSemantics::FrameDirection,
|
||||||
index: 0,
|
index: (),
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
@ -122,7 +122,7 @@ impl TextureSemanticMap<UniformSemantic> for FxHashMap<String, SemanticMap<Textu
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UniformSemantic {
|
pub enum UniformSemantic {
|
||||||
Variable(SemanticMap<VariableSemantics>),
|
Variable(SemanticMap<VariableSemantics, ()>),
|
||||||
Texture(SemanticMap<TextureSemantics>),
|
Texture(SemanticMap<TextureSemantics>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ pub struct ReflectSemantics {
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct ReflectMeta {
|
pub struct ReflectMeta {
|
||||||
pub parameter_meta: FxHashMap<u32, VariableMeta>,
|
pub parameter_meta: FxHashMap<String, VariableMeta>,
|
||||||
pub variable_meta: FxHashMap<VariableSemantics, VariableMeta>,
|
pub variable_meta: FxHashMap<VariableSemantics, VariableMeta>,
|
||||||
pub texture_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureImage>,
|
pub texture_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureImage>,
|
||||||
pub texture_size_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureSizeMeta>,
|
pub texture_size_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureSizeMeta>,
|
||||||
|
|
|
@ -79,9 +79,9 @@ pub trait ValidateTypeSemantics<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct SemanticMap<T> {
|
pub struct SemanticMap<T, I=u32> {
|
||||||
pub semantics: T,
|
pub semantics: T,
|
||||||
pub index: u32,
|
pub index: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
|
|
@ -161,6 +161,13 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut reflect = GLSL::from_compilation(spirv).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)
|
(shader, source, reflect)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
|
@ -194,12 +201,12 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
|
||||||
let mut semantics = semantics.clone();
|
let mut semantics = semantics.clone();
|
||||||
|
|
||||||
// insert parameters parsed from source
|
// insert parameters parsed from source
|
||||||
for (index, parameter) in source.parameters.iter().enumerate() {
|
// for (index, parameter) in source.parameters.iter().enumerate() {
|
||||||
semantics.uniform_semantics.insert(parameter.id.clone(), UniformSemantic::Variable(SemanticMap {
|
// semantics.uniform_semantics.insert(parameter.id.clone(), UniformSemantic::Variable(SemanticMap {
|
||||||
semantics: VariableSemantics::FloatParameter,
|
// semantics: VariableSemantics::FloatParameter,
|
||||||
index: index as u32
|
// index: 0
|
||||||
}));
|
// }));
|
||||||
}
|
// }
|
||||||
|
|
||||||
let reflection = reflect.reflect(index as u32, &semantics)?;
|
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));
|
locations.insert(param.id.clone(), reflect_parameter(program, param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// eprintln!("{:#?}", semantics);
|
// eprintln!("{:#?}", semantics);
|
||||||
eprintln!("{:#?}", reflection.meta);
|
eprintln!("{:#?}", reflection.meta);
|
||||||
eprintln!("{:#?}", locations);
|
eprintln!("{:#?}", locations);
|
||||||
|
|
Loading…
Reference in a new issue