Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wgsl-in] Transition to a pass-based architecture #2065

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serialize = ["serde", "indexmap/serde-1"]
deserialize = ["serde", "indexmap/serde-1"]
spv-in = ["petgraph", "spirv"]
spv-out = ["spirv"]
wgsl-in = ["codespan-reporting", "hexf-parse", "termcolor", "unicode-xid"]
wgsl-in = ["clone", "codespan-reporting", "termcolor", "aho-corasick", "chumsky", "half", "hexf-parse", "lasso", "logos", "strum"]
wgsl-out = []
hlsl-out = []
span = ["codespan-reporting", "termcolor"]
Expand All @@ -58,10 +58,17 @@ num-traits = "0.2"
spirv = { version = "0.2", optional = true }
thiserror = "1.0.21"
serde = { version = "1.0.103", features = ["derive"], optional = true }
petgraph = { version ="0.6", optional = true }
petgraph = { version = "0.6", optional = true }
pp-rs = { version = "0.2.1", optional = true }

# wgsl frontend dependencies
aho-corasick = { version = "0.7.19", optional = true }
chumsky = { version = "0.8.0", default-features = false, optional = true }
half = { version = "1.8.2", optional = true }
hexf-parse = { version = "0.2.1", optional = true }
unicode-xid = { version = "0.2.3", optional = true }
lasso = { version = "0.6.0", optional = true }
logos = { version = "0.12.1", optional = true }
strum = { version = "0.24.1", features = ["derive"], optional = true }

[dev-dependencies]
bincode = "1"
Expand Down
12 changes: 6 additions & 6 deletions benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ fn frontends(c: &mut Criterion) {
#[cfg(all(feature = "wgsl-in", feature = "serialize", feature = "deserialize"))]
group.bench_function("bin", |b| {
let inputs_wgsl = gather_inputs("tests/in", "wgsl");
let mut parser = naga::front::wgsl::Parser::new();
let mut context = naga::front::wgsl::WgslContext::new();
let inputs_bin = inputs_wgsl
.iter()
.map(|input| {
let string = std::str::from_utf8(input).unwrap();
let module = parser.parse(string).unwrap();
let module = context.parse(string).unwrap();
bincode::serialize(&module).unwrap()
})
.collect::<Vec<_>>();
Expand All @@ -60,14 +60,14 @@ fn frontends(c: &mut Criterion) {
#[cfg(feature = "wgsl-in")]
group.bench_function("wgsl", |b| {
let inputs_wgsl = gather_inputs("tests/in", "wgsl");
let mut context = naga::front::wgsl::WgslContext::new();
let inputs = inputs_wgsl
.iter()
.map(|input| std::str::from_utf8(input).unwrap())
.collect::<Vec<_>>();
let mut parser = naga::front::wgsl::Parser::new();
b.iter(move || {
for &input in inputs.iter() {
parser.parse(input).unwrap();
context.parse(input).unwrap();
}
});
});
Expand Down Expand Up @@ -99,12 +99,12 @@ fn frontends(c: &mut Criterion) {
#[cfg(feature = "wgsl-in")]
fn gather_modules() -> Vec<naga::Module> {
let inputs = gather_inputs("tests/in", "wgsl");
let mut parser = naga::front::wgsl::Parser::new();
let mut context = naga::front::wgsl::WgslContext::new();
inputs
.iter()
.map(|input| {
let string = std::str::from_utf8(input).unwrap();
parser.parse(string).unwrap()
context.parse(string).unwrap()
})
.collect()
}
Expand Down
8 changes: 6 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
Ok(v) => (v, Some(input)),
Err(ref e) => {
let path = input_path.to_string_lossy();
e.emit_to_stderr_with_path(&input, &path);
return Err(CliError("Could not parse WGSL").into());

for e in e {
e.emit_to_stderr_with_path(&input, &path);
}

return Err(CliError("WGSL Error").into());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ impl<W: Write> Writer<W> {
} => {
let name = &self.names[&NameKey::Constant(handle)];
// First write only constant name
write!(self.out, "let {}: ", name)?;
write!(self.out, "const {}: ", name)?;
// Next write constant type and value
match *value {
crate::ScalarValue::Sint(value) => {
Expand All @@ -1852,7 +1852,7 @@ impl<W: Write> Writer<W> {
crate::ConstantInner::Composite { ty, ref components } => {
let name = &self.names[&NameKey::Constant(handle)];
// First write only constant name
write!(self.out, "let {}: ", name)?;
write!(self.out, "const {}: ", name)?;
// Next write constant type
self.write_type(module, ty)?;

Expand Down
Loading