Skip to content

Commit 309919a

Browse files
Added precompile test
1 parent 930b35b commit 309919a

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ webgl = ["wgpu/webgl"]
3434
test-build-with-profiling = ["profiling/type-check"]
3535

3636
[dependencies]
37-
wgpu = { workspace = true, features = ["noop"] }
37+
wgpu = { workspace = true, features = ["noop", "precompile"] }
3838
wgpu-hal = { workspace = true, features = ["validation_canary"] }
3939
wgpu-macros.workspace = true
4040

tests/tests/wgpu-gpu/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod pipeline;
4343
mod pipeline_cache;
4444
mod planar_texture;
4545
mod poll;
46+
mod precompile;
4647
mod push_constants;
4748
mod query_set;
4849
mod queue_transfer;
@@ -104,6 +105,7 @@ fn all_tests() -> Vec<wgpu_test::GpuTestInitializer> {
104105
planar_texture::all_tests(&mut tests);
105106
poll::all_tests(&mut tests);
106107
push_constants::all_tests(&mut tests);
108+
precompile::all_tests(&mut tests);
107109
query_set::all_tests(&mut tests);
108110
queue_transfer::all_tests(&mut tests);
109111
ray_tracing::all_tests(&mut tests);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use wgpu_test::{gpu_test, GpuTestConfiguration, GpuTestInitializer, TestParameters};
2+
3+
pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) {
4+
vec.push(PRECOMPILE_ALL_STAGES_TEST);
5+
}
6+
7+
#[gpu_test]
8+
static PRECOMPILE_ALL_STAGES_TEST: GpuTestConfiguration = GpuTestConfiguration::new()
9+
.parameters(
10+
TestParameters::default().features(wgpu::Features::EXPERIMENTAL_PASSTHROUGH_SHADERS),
11+
)
12+
.run_async(async |ctx| unsafe {
13+
let _ = ctx
14+
.device
15+
.create_shader_module_passthrough(wgpu::precompile_wgsl!(
16+
"tests/wgpu-gpu/precompile/shader.wgsl",
17+
"vs_main"
18+
));
19+
let _ = ctx
20+
.device
21+
.create_shader_module_passthrough(wgpu::precompile_wgsl!(
22+
"tests/wgpu-gpu/precompile/shader.wgsl",
23+
"fs_main"
24+
));
25+
let _ = ctx
26+
.device
27+
.create_shader_module_passthrough(wgpu::precompile_wgsl!(
28+
"tests/wgpu-gpu/precompile/shader.wgsl",
29+
"cs_main"
30+
));
31+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@vertex
2+
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
3+
return vec4<f32>(0.0);
4+
}
5+
6+
@fragment
7+
fn fs_main() -> @location(0) vec4<f32> {
8+
return vec4<f32>(0.0);
9+
}
10+
11+
@compute
12+
@workgroup_size(1)
13+
fn cs_main() {}

wgpu-precompile-macro/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ impl Parse for MacroArgs {
100100
} else {
101101
relative_path
102102
};
103+
if !path_to_read.is_file() {
104+
panic!("Path does not exist or is not a file: {path_to_read:?}")
105+
}
103106
let bytes = std::fs::read(path_to_read).expect("Failed to read input file");
104107
(ShaderSource::File(bytes), Some(file_name))
105108
} else {

0 commit comments

Comments
 (0)