|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +cd "$repo_root" |
| 6 | + |
| 7 | +tmpdir="$(mktemp -d)" |
| 8 | +negative_output="$tmpdir/negative.out" |
| 9 | +cleanup() { |
| 10 | + rm -rf "$tmpdir" |
| 11 | +} |
| 12 | +trap cleanup EXIT |
| 13 | + |
| 14 | +moon -C tools/wgpu_validation build --target native >/dev/null |
| 15 | +validator="$repo_root/tools/wgpu_validation/_build/native/debug/build/cmd/main/main.exe" |
| 16 | + |
| 17 | +wgpu_validate() { |
| 18 | + "$validator" "$@" |
| 19 | +} |
| 20 | + |
| 21 | +emit_case() { |
| 22 | + local case_name="$1" |
| 23 | + local output="$2" |
| 24 | + moon run tools/wgsl_validation_cases -- "$case_name" > "$output" |
| 25 | +} |
| 26 | + |
| 27 | +echo "== wgpu validation: shader module smoke ==" |
| 28 | +cat > "$tmpdir/shader_module_smoke.wgsl" <<'WGSL' |
| 29 | +@fragment |
| 30 | +fn fs_main() -> @location(0) vec4<f32> { |
| 31 | + return vec4<f32>(0.0, 0.0, 0.0, 1.0); |
| 32 | +} |
| 33 | +WGSL |
| 34 | +wgpu_validate --input "$tmpdir/shader_module_smoke.wgsl" --mode shader-module |
| 35 | + |
| 36 | +echo "== wgpu validation: storage access runtime layout ==" |
| 37 | +cat > "$tmpdir/storage_access_source.wgsl" <<'WGSL' |
| 38 | +@group(0) @binding(0) |
| 39 | +var<storage> values: array<u32>; |
| 40 | +
|
| 41 | +@group(0) @binding(1) |
| 42 | +var<storage, read_write> output: array<u32>; |
| 43 | +
|
| 44 | +@compute @workgroup_size(1) |
| 45 | +fn main(@builtin(global_invocation_id) id: vec3<u32>) { |
| 46 | + if (id.x >= arrayLength(&values)) { |
| 47 | + return; |
| 48 | + } |
| 49 | + output[id.x] = values[id.x]; |
| 50 | +} |
| 51 | +WGSL |
| 52 | +moon run tools/ir_roundtrip -- \ |
| 53 | + --input "$tmpdir/storage_access_source.wgsl" \ |
| 54 | + --output "$tmpdir/storage_access_ir.wgsl" >/dev/null |
| 55 | +wgpu_validate \ |
| 56 | + --input "$tmpdir/storage_access_ir.wgsl" \ |
| 57 | + --mode compute-storage-read \ |
| 58 | + --compute-entry main |
| 59 | + |
| 60 | +echo "== wgpu validation: storage access negative control ==" |
| 61 | +cat > "$tmpdir/storage_access_bad.wgsl" <<'WGSL' |
| 62 | +@group(0) @binding(0) |
| 63 | +var<storage, read_write> values: array<u32>; |
| 64 | +
|
| 65 | +@group(0) @binding(1) |
| 66 | +var<storage, read_write> output: array<u32>; |
| 67 | +
|
| 68 | +@compute @workgroup_size(1) |
| 69 | +fn main(@builtin(global_invocation_id) id: vec3<u32>) { |
| 70 | + if (id.x >= arrayLength(&values)) { |
| 71 | + return; |
| 72 | + } |
| 73 | + output[id.x] = values[id.x]; |
| 74 | +} |
| 75 | +WGSL |
| 76 | +if wgpu_validate \ |
| 77 | + --input "$tmpdir/storage_access_bad.wgsl" \ |
| 78 | + --mode compute-storage-read \ |
| 79 | + --compute-entry main >"$negative_output" 2>&1; then |
| 80 | + cat "$negative_output" >&2 |
| 81 | + echo "expected wgpu validation to reject read_write shader binding against read-only layout" >&2 |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +echo "== wgpu validation: Bevy PBR forward shader module ==" |
| 86 | +emit_case bevy-pbr-forward "$tmpdir/bevy_pbr_forward.wgsl" |
| 87 | +wgpu_validate --input "$tmpdir/bevy_pbr_forward.wgsl" --mode shader-module |
| 88 | + |
| 89 | +echo "== wgpu validation: MGStudio mesh3d forward shader module ==" |
| 90 | +emit_case mgstudio-mesh3d-forward "$tmpdir/mgstudio_mesh3d_forward.wgsl" |
| 91 | +wgpu_validate --input "$tmpdir/mgstudio_mesh3d_forward.wgsl" --mode shader-module |
| 92 | + |
| 93 | +echo "wgpu validation gate passed" |
0 commit comments