wgsltowgpu

Latest Version docs.rs
An experimental library for generating typesafe Rust bindings from WGSL shaders to wgpu.

wgsltowgpu is designed to be incorporated into the compilation process using a build script. The WGSL shaders are parsed using naga to generate a corresponding Rust module. The generated Rust module contains the type definitions and boilerplate code needed to work with the WGSL shader module. Using the generated code can also reduce many instances of invalid API usage. wgsltowgpu facilitates a shader focused workflow where edits to WGSL code are automatically reflected in the corresponding Rust file. For example, changing the type of a uniform in WGSL will raise a compile error in Rust code using the generated struct to initialize the buffer.

Features

Usage

The generated code currently relies on memoffset for calculating field offsets for vertex input structs. Add the following lines to the Cargo.toml and fill in the appropriate versions for memoffset and wgsl_to_wgpu. When enabling derives for crates like bytemuck, serde, or encase, these dependencies should also be added to the Cargo.toml with the appropriate derive features.

```toml [dependencies] memoffset = "..."

[build-dependencies] wgsltowgpu = "..." ```

See the example crate for how to use the generated code. Run the example with cargo run.

Limitations