Skip to content

TemporalInteractive/wgsl-includes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏗️ 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.

This crate is nightly only.

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");

About

Allow wgsl shaders to include other shaders

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published