Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
WESL: A Community Standard for Enhanced WGSL
This is the crate for all your WESL needs.
See also the standalone CLI.
Basic Usage
See [Wesl] for an overview of the high-level API.
# use ;
let compiler = new;
# // just adding a virtual file here so the doctest runs without a filesystem
# let mut resolver = new;
# resolver.add_module;
# let compiler = compiler.set_custom_resolver;
// compile a WESL file to a WGSL string
let wgsl_str = compiler
.compile
.inspect_err // pretty errors with `display()`
.unwrap
.to_string;
Usage in build.rs
In your Rust project you probably want to have your WESL code converted automatically to a WGSL string at build-time, unless your WGSL code must be assembled at runtime.
Add this crate to your build dependencies in Cargo.toml:
[]
= "0.1"
Create the build.rs file with the following content:
# use ;
Include the compiled WGSL string in your code:
let module = device.create_shader_module;
Write shaders inline with the [quote_module] macro
See the wesl-quote crate.
Evaluating const-expressions
This is an advanced and experimental feature. wesl-rs supports evaluation and execution
of WESL code with the eval feature flag. Early evaluation (in particular of
const-expressions) helps developers to catch bugs early by improving the validation and
error reporting capabilities of WESL. Full evaluation of const-expressions can be enabled
with the lower compiler option.
Additionally, the eval feature adds support for user-defined @const attributes on
functions, which allows one to precompute data ahead of time, and ensure that code has no
runtime dependencies.
The eval/exec implementation is tested with the WebGPU Conformance Test Suite.
# use ;
// ...standalone expression
let wgsl_expr = eval_str.unwrap.to_string;
assert_eq!;
// ...expression using declarations in a WESL file
let source = "const my_const = 4; @const fn my_fn(v: u32) -> u32 { return v * 10; }";
# let mut resolver = new;
# resolver.add_module;
# let compiler = new_barebones.set_custom_resolver;
let wgsl_expr = compiler
.compile.unwrap
.eval.unwrap
.to_string;
assert_eq!;
Features
| name | description | Status/Specification |
|---|---|---|
generics |
user-defined type-generators and generic functions | experimental |
package |
create shader libraries published to crates.io |
experimental |
eval |
execute shader code on the CPU and @const attribute |
experimental |
naga-ext |
enable all Naga/WGPU extensions | experimental |
serde |
derive Serialize and Deserialize for syntax nodes |