Skip to content

Commit 6264e29

Browse files
committed
add test for #1705
1 parent 4453e32 commit 6264e29

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

sugarloaf/tests/wgsl_validation.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2023-present, Raphael Amorim.
2+
//
3+
// This source code is licensed under the MIT license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
use naga::valid::{Capabilities, ValidationFlags, Validator};
7+
8+
const SHADERS: &[(&str, &str)] = &[
9+
(
10+
"renderer/renderer.wgsl",
11+
include_str!("../src/renderer/renderer.wgsl"),
12+
),
13+
(
14+
"renderer/image.wgsl",
15+
include_str!("../src/renderer/image.wgsl"),
16+
),
17+
("text_shader.wgsl", include_str!("../src/text_shader.wgsl")),
18+
(
19+
"grid/shaders/grid.wgsl",
20+
include_str!("../src/grid/shaders/grid.wgsl"),
21+
),
22+
(
23+
"components/filters/shader/triangle.wgsl",
24+
include_str!("../src/components/filters/shader/triangle.wgsl"),
25+
),
26+
(
27+
"components/filters/shader/blit.wgsl",
28+
include_str!("../src/components/filters/shader/blit.wgsl"),
29+
),
30+
];
31+
32+
#[test]
33+
fn bundled_wgsl_shaders_pass_naga_validation() {
34+
let mut failures = Vec::new();
35+
for (name, source) in SHADERS {
36+
match naga::front::wgsl::parse_str(source) {
37+
Err(err) => {
38+
failures.push(format!(
39+
"{name}: parse error\n{}",
40+
err.emit_to_string(source)
41+
));
42+
}
43+
Ok(module) => {
44+
let mut validator =
45+
Validator::new(ValidationFlags::all(), Capabilities::default());
46+
if let Err(err) = validator.validate(&module) {
47+
failures.push(format!(
48+
"{name}: validation error\n{}",
49+
err.emit_to_string(source)
50+
));
51+
}
52+
}
53+
}
54+
}
55+
assert!(
56+
failures.is_empty(),
57+
"WGSL shaders rejected by naga:\n\n{}",
58+
failures.join("\n\n")
59+
);
60+
}

0 commit comments

Comments
 (0)