wgsl-includes

Crates.iowgsl-includes
lib.rswgsl-includes
version0.0.2
created_at2025-03-27 12:20:16.691192+00
updated_at2025-04-01 08:02:11.248312+00
descriptionA tiny crate meant to solve two major pain points with naga & wgsl: no validation at compile time and no support for shader includes.
homepagehttps://github.com/TemporalInteractive/wgsl-includes
repositoryhttps://github.com/TemporalInteractive/wgsl-includes
max_upload_size
id1607881
size21,045
Jason de Wolff (JasondeWolff)

documentation

README

🏗️ wgsl-includes

wgsl-includes crate

This tiny crate is meant to solve two major pain points with naga & wgsl: no validation at compile time and no support for shader includes. Note that shaders are only included ONCE, meaning circular includes are not allowed. All shader paths must be relative to the crate root directory.

Features

  • Wgsl shader includes
  • Shader syntax validation

Example

my_crate/shaders/shared.wgsl contents:

// Define shared logic in a separate wgsl shader, this file is free to include more files
const VALUE: u32 = 0;

my_crate/shaders/some_compute_shader.wgsl contents:

// We can now include our shared logic
@include shaders/shared.wgsl

@compute
@workgroup_size(128)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
    // And use the contents from `shared.wgsl`
    let maths: u32 = global_id.x * VALUE;
}

On the rust side we can now include and validate our shader source code as follows:

let shader_src: &str = include_wgsl!("shaders/some_compute_shader.wgsl");
Commit count: 8

cargo fmt