Introduction
WGSL, the WebGPU Shading Language, is the shader language of WebGPU, the W3C’s graphics and compute API for web browsers. Browsers take WGSL source as text and translate it into whatever the system’s graphics API needs, such as HLSL, Metal or SPIR-V. It is also used outside the browser by native WebGPU libraries such as wgpu and Dawn.
Structure
A WGSL file is plain text with a syntax closer to Rust than to C. Functions are
declared with fn, variables with var, let or
const, and types come after names, as in x: f32. Attributes
start with @: @vertex, @fragment and
@compute mark entry points, @location and
@builtin mark inputs and outputs, and @group and
@binding place resources. One file can hold several entry points.
@fragment
fn fs_main(@location(0) colour: vec3f) -> @location(0) vec4f {
return vec4f(colour, 1.0);
}
Links
Software
Developers
Reference
- WebGPU Shading Language, W3C specification