Skip to content

Commit

Permalink
Actually make sure the preprocessor compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlansneff committed Aug 17, 2020
1 parent 6b40c84 commit 9228dab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ features = ["glsl-new", "spirv"]
pretty_assertions = "0.6.1"

[features]
default = ["naga-reflect", "bevy-glsl-to-spirv"]
# default = ["bevy-glsl-to-spirv", "spirv-reflect"]
default = ["naga-glsl", "naga-reflect"]
png = ["image/png"]
hdr = ["image/hdr"]
naga-glsl = ["naga"] # Enable this when the glsl-new (or glsl) naga frontends are more mature
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_render/src/shader/preprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{borrow::Cow, collections::HashMap};

#[derive(Debug, Copy, Clone)]
pub enum IncludePath<'a> {
Absolute(&'a str),
Expand Down
13 changes: 9 additions & 4 deletions crates/bevy_render/src/shader/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ fn glsl_to_spirv(
|_include_path| Err(()), // bevy doesn't expose includes yet
|found_definition| {
shader_defs
.and_then(|defs| defs.find(|def| *def == found_definition))
.map(|def| if def.len() == 0 { None } else { Some(def) })
.and_then(|defs| defs.iter().find(|def| *def == found_definition))
.map(|def| {
if def.len() == 0 {
None
} else {
Some(def.to_string())
}
})
},
)
.expect("unable to preprocess shader");

// The `glsl_new` naga frontend is still a work-in-progress.
let module =
naga::front::glsl_new::parse_str(glsl_source, "main".to_string(), stage.into())
.unwrap();
naga::front::glsl_new::parse_str(&source, "main".to_string(), stage.into()).unwrap();
println!("{:#?}", module);
let mut writer =
naga::back::spv::Writer::new(&module.header, naga::back::spv::WriterFlags::NONE);
Expand Down

0 comments on commit 9228dab

Please sign in to comment.