Developer builds Facet-based unit tests to catch Rust/WGSL struct layout mismatches
A developer working on GPU compute shaders describes a recurring bug class: Rust structs annotated with zerocopy for byte-level serialization can silently diverge from WGSL struct layout rules, causing shader crashes severe enough to require rebooting the machine. Rather than adopt existing tools like wgsl_to_wgpu, wgsl_bindgen, or encase, they built a custom approach using naga to parse WGSL struct layouts and compare them against Rust struct layouts via unit tests, avoiding extra build-script dependencies.
GoKawiil's interpretation of the reporting above, not reported fact.
This highlights a subtle, hard-to-detect class of bugs at the Rust-to-GPU boundary where memory layout assumptions differ between host and shader code, with failure modes severe enough to hang a GPU. The approach suggests a lightweight alternative to heavier code-generation tools, which could appeal to developers wary of added build complexity, though it relies on developers remembering to write tests for every new config struct.
- Rust and WGSL have differing memory layout rules that can cause silent shader bugs
- The developer chose unit tests over existing crates like wgsl_to_wgpu or encase to avoid build-script overhead
- The naga crate, already used for shader compilation, was repurposed to introspect WGSL struct layouts for comparison
Source: mattkeeter.com, 2026-09-28
Published there as: “Testing WebGPU data layouts with Facet”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.