2022-10-26 13:13:39 +11:00
|
|
|
use rustc_hash::FxHashMap;
|
2022-10-24 14:22:26 +11:00
|
|
|
use crate::error::ShaderReflectError;
|
2022-10-26 16:19:04 +11:00
|
|
|
use crate::reflect::semantics::{SemanticMap, ShaderReflection, VariableSemantics, TextureSemantics, VariableMeta, TextureMeta};
|
2022-10-24 14:22:26 +11:00
|
|
|
|
|
|
|
mod cross;
|
2022-10-23 17:36:41 +11:00
|
|
|
mod naga;
|
2022-10-24 14:22:26 +11:00
|
|
|
pub mod semantics;
|
2022-10-26 13:13:39 +11:00
|
|
|
mod rspirv;
|
2022-10-24 14:22:26 +11:00
|
|
|
|
|
|
|
pub trait ReflectShader {
|
2022-10-26 13:13:39 +11:00
|
|
|
fn reflect(&self, options: &ReflectOptions) -> Result<ShaderReflection, ShaderReflectError>;
|
2022-10-24 14:22:26 +11:00
|
|
|
}
|
2022-10-26 13:13:39 +11:00
|
|
|
|
2022-10-26 16:19:04 +11:00
|
|
|
#[derive(Debug)]
|
2022-10-26 13:13:39 +11:00
|
|
|
pub enum UniformSemantic {
|
|
|
|
Variable(SemanticMap<VariableSemantics>),
|
|
|
|
Texture(SemanticMap<TextureSemantics>)
|
|
|
|
}
|
|
|
|
|
2022-10-26 16:19:04 +11:00
|
|
|
#[derive(Debug)]
|
2022-10-26 13:13:39 +11:00
|
|
|
pub struct ReflectOptions {
|
|
|
|
pub pass_number: u32,
|
|
|
|
pub uniform_semantics: FxHashMap<String, UniformSemantic>,
|
2022-10-26 16:19:04 +11:00
|
|
|
pub non_uniform_semantics: FxHashMap<String, SemanticMap<TextureSemantics>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct ReflectMeta {
|
|
|
|
pub parameter_meta: FxHashMap<u32, VariableMeta>,
|
|
|
|
pub variable_meta: FxHashMap<VariableSemantics, VariableMeta>,
|
|
|
|
pub texture_meta: FxHashMap<SemanticMap<TextureSemantics>, TextureMeta>
|
2022-10-26 13:13:39 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn builtin_uniform_semantics() -> FxHashMap<String, UniformSemantic> {
|
|
|
|
let mut map = FxHashMap::default();
|
|
|
|
|
|
|
|
map.insert("MVP".into(), UniformSemantic::Variable(SemanticMap {
|
|
|
|
semantics: VariableSemantics::MVP,
|
|
|
|
index: 0
|
|
|
|
}));
|
|
|
|
|
|
|
|
map.insert("OutputSize".into(), UniformSemantic::Variable(SemanticMap {
|
|
|
|
semantics: VariableSemantics::Output,
|
|
|
|
index: 0
|
|
|
|
}));
|
|
|
|
|
|
|
|
map.insert("FinalViewportSize".into(), UniformSemantic::Variable(SemanticMap {
|
|
|
|
semantics: VariableSemantics::FinalViewport,
|
|
|
|
index: 0
|
|
|
|
}));
|
|
|
|
|
|
|
|
map.insert("FrameCount".into(), UniformSemantic::Variable(SemanticMap {
|
|
|
|
semantics: VariableSemantics::FrameCount,
|
|
|
|
index: 0
|
|
|
|
}));
|
|
|
|
|
|
|
|
map.insert("FrameDirection".into(), UniformSemantic::Variable(SemanticMap {
|
|
|
|
semantics: VariableSemantics::FrameDirection,
|
|
|
|
index: 0
|
|
|
|
}));
|
|
|
|
map
|
|
|
|
}
|