gl: split parameter semantics to per-pass

This commit is contained in:
chyyran 2022-11-13 01:57:47 -05:00
parent dcbdb382e1
commit b987953181

View file

@ -148,38 +148,39 @@ pub fn reflect_parameter(pipeline: GLuint, meta: &VariableMeta) -> ParameterLoca
pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
let preset = librashader_presets::ShaderPreset::try_parse(path)?; let preset = librashader_presets::ShaderPreset::try_parse(path)?;
let mut uniform_semantics: FxHashMap<String, UniformSemantic> = Default::default();
let mut texture_semantics: FxHashMap<String, SemanticMap<TextureSemantics>> = Default::default();
let mut passes: Vec<(&ShaderPassConfig, ShaderSource, _)> = preset.shaders.iter() let mut passes: Vec<(&ShaderPassConfig, ShaderSource, _)> = preset.shaders.iter()
.map(|shader| { .map(|shader| {
let source = librashader_preprocess::load_shader_source(&shader.name) eprintln!("[gl] loading {}", &shader.name.display());
let source: ShaderSource = librashader_preprocess::load_shader_source(&shader.name)
.unwrap(); .unwrap();
let spirv = librashader_reflect::front::shaderc::compile_spirv(&source) let spirv = librashader_reflect::front::shaderc::compile_spirv(&source)
.unwrap(); .unwrap();
let mut reflect = GLSL::from_compilation(spirv).unwrap(); let mut reflect = GLSL::from_compilation(spirv).unwrap();
(shader, source, reflect) (shader, source, reflect)
}).collect(); }).collect();
// todo: this can probably be extracted out. // todo: this can probably be extracted out.
let mut uniform_semantics: FxHashMap<String, UniformSemantic> = Default::default();
let mut texture_semantics: FxHashMap<String, SemanticMap<TextureSemantics>> = Default::default();
for details in &passes { for details in &passes {
load_pass_semantics(&mut uniform_semantics, &mut texture_semantics, details.0) load_pass_semantics(&mut uniform_semantics, &mut texture_semantics, details.0)
} }
// add float params
for (index, parameter) in preset.parameters.iter().enumerate() {
uniform_semantics.insert(parameter.name.clone(), UniformSemantic::Variable(SemanticMap {
semantics: VariableSemantics::FloatParameter,
index: index as u32
}));
}
// add lut params // add lut params
for (index, texture) in preset.textures.iter().enumerate() { for (index, texture) in preset.textures.iter().enumerate() {
texture_semantics.insert(texture.name.clone(), SemanticMap { texture_semantics.insert(texture.name.clone(), SemanticMap {
semantics: TextureSemantics::User, semantics: TextureSemantics::User,
index: index as u32 index: index as u32
}); });
uniform_semantics.insert(format!("{}Size", texture.name), UniformSemantic::Texture(SemanticMap {
semantics: TextureSemantics::User,
index: index as u32
}));
} }
let semantics = ReflectSemantics { let semantics = ReflectSemantics {
@ -190,7 +191,18 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
let mut filters = Vec::new(); let mut filters = Vec::new();
for (index, (config, source, mut reflect)) in passes.into_iter().enumerate() { for (index, (config, source, mut reflect)) in passes.into_iter().enumerate() {
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
}));
}
let reflection = reflect.reflect(index as u32, &semantics)?; let reflection = reflect.reflect(index as u32, &semantics)?;
let glsl = reflect.compile(GlVersion::V4_60)?; let glsl = reflect.compile(GlVersion::V4_60)?;
let vertex_resources = glsl.context.compiler.vertex.get_shader_resources()?; let vertex_resources = glsl.context.compiler.vertex.get_shader_resources()?;
@ -268,14 +280,14 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
} }
eprintln!("{:#?}", semantics); // eprintln!("{:#?}", semantics);
eprintln!("{:#?}", reflection.meta); eprintln!("{:#?}", reflection.meta);
eprintln!("{:#?}", locations); eprintln!("{:#?}", locations);
eprintln!("{:#?}", reflection.push_constant); eprintln!("{:#?}", reflection.push_constant);
eprintln!("====fragment===="); // eprintln!("====fragment====");
eprintln!("{:#}", glsl.fragment); // eprintln!("{:#}", glsl.fragment);
eprintln!("====vertex===="); // eprintln!("====vertex====");
eprintln!("{:#}", glsl.vertex); // eprintln!("{:#}", glsl.vertex);
filters.push(FilterPass { filters.push(FilterPass {
reflection, reflection,
@ -328,7 +340,8 @@ mod tests {
#[test] #[test]
fn triangle() { fn triangle() {
let (glfw, window, events, shader, vao) = hello_triangle::setup(); let (glfw, window, events, shader, vao) = hello_triangle::setup();
load("../test/basic.slangp") // load("../test/basic.slangp")
load("../test/slang-shaders/crt/crt-royale.slangp")
.unwrap(); .unwrap();
hello_triangle::do_loop(glfw, window, events, shader, vao); hello_triangle::do_loop(glfw, window, events, shader, vao);
} }