Introduction
A .wesl file holds shader code in WESL,
the WebGPU Extended Shading Language. WESL is a strict superset of
WGSL, so every WGSL program is also a WESL program, and
it adds what WGSL lacks: imports between files, conditional compilation and packages
of shader code. A WESL tool resolves the imports and writes ordinary WGSL for the
graphics interface to use.
Tools exist as a Rust crate and an npm package, both named wesl. They
look for .wesl and .wgsl files, and when both exist for a
module, the .wesl file takes priority.
Structure
A WESL file is plain text in WGSL syntax with extra statements. An
import names an item from another module by a path that can start with
package (the root of the current package, package.wesl) or
super (the parent module). A path can end with a wildcard, or with a list
in braces in which an item can be renamed with as. The conditional
translation attribute @if keeps or drops a declaration, depending on
the features chosen when the code is compiled.
import package::utils::*;
import super::lighting::pbr;
import my::geom::sphere::{ draw, default_radius as foobar };
Not described
Known, not yet covered
- Reference: this overview is the only page. The language has no reference pages: the full import and module resolution rules, conditional translation with
@ifand its expressions, packages and how they are published, and the extensions to WGSL that are still being specified. The WESL specification describes them. - Reference: the WGSL language that WESL builds on has its own page.
- Viewer: there is no viewer for this format yet, and nothing is compiled or checked.
Links
Software
- wesl (JavaScript) – the npm package that links WESL into WGSL
Developers
Reference
- WESL specification: imports – the import syntax and resolution