Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Errors

SourceError

Raised by wgsl_rs::Source methods.

VariantWhen
TemplateWgslwgsl_source() is called on a Source that is still a template (has unresolved TypeParam nodes). Call instantiate(...) first to produce concrete WGSL.

Recovery

#![allow(unused)]
fn main() {
match source.wgsl_source() {
    Ok(wgsl) => { /* write or compile */ }
    Err(SourceError::TemplateWgsl) => {
        let concrete = source.instantiate(&[concrete_type])?;
        let wgsl = concrete.wgsl_source()?;
    }
}
}

wgsl_rs_linkage_wgpu::Error

Raised by the wgsl-rs-linkage-wgpu crates when analyzing a source or creating a bind group by name.

VariantWhen
TemplateResolution { .. }Analysis was requested for a template source that has not been instantiated with concrete types, or the source graph references an imported template that is missing or ambiguous (converted from SourceError::TemplateNotFound / SourceError::AmbiguousTemplate).
NoSuchBindGroup { .. }create_bind_group_named was called for a @group(N) the module does not declare.
MissingBinding { .. }A named-resource bind group creation is missing a resource for one of the group’s declared binding names.
UnknownBindingName { .. }A named-resource creation provided a resource for a name the group does not declare.
DuplicateBindingName { .. }A named-resource creation provided the same binding name twice.

All variants are struct variants; match them with { .. } patterns.

Recovery

Bind group lookups return Option, not Result (linkage.bind_group(0)), so recovery there is ordinary Option handling. Only analysis and named-resource bind group creation return Error:

#![allow(unused)]
fn main() {
use wgsl_rs_linkage_wgpu::{analyze_ir_module, analyze_wgsl_module, Error};

// Analysis is the only source of `TemplateResolution`: instantiate the
// template with concrete types first, then analyze the concrete IR.
let linkage = match analyze_wgsl_module(&my_shader::WGSL_SOURCE) {
    Ok(linkage) => linkage,
    Err(Error::TemplateResolution { .. }) => {
        // The source is a template: instantiate it with concrete types,
        // then analyze the concrete IR instead.
        analyze_ir_module(my_shader::instantiate::<f32, u32>())
    }
    Err(other) => return Err(other),
};
}

When the error came from a missing or ambiguous imported template, instantiating the root is not the fix: provide (or disambiguate) the imported module so the source graph can be assembled in the first place.

#![allow(unused)]
fn main() {
use wgsl_rs_linkage_wgpu::Error;

// Named-resource bind group creation surfaces the binding-name variants:
match linkage.create_bind_group_named(0, &device, &[("FRAME", binding)]) {
    Ok(bind_group) => { /* bind it */ }
    Err(Error::MissingBinding { .. }) => {
        // a declared binding had no resource provided
    }
    Err(_) => { /* NoSuchBindGroup, UnknownBindingName, DuplicateBindingName */ }
}
}

General Pattern

Template errors are recoverable by instantiating with concrete types (see Template Modules & Instantiation and Template Linkage). Bind group / binding errors indicate a mismatch between the host-side layout code and the shader declaration — inspect ir::Module items (Uniform, Storage, Sampler, Texture) to reconcile.