gfx-rs/wgpu · error

No binary data provided to `ShaderModuleDescriptorGeneric`

Error message

No binary data provided to `ShaderModuleDescriptorGeneric`

What it means

`ShaderModuleDescriptorGeneric::trace_data` returns the binary shader source (HLSL, GLSL, or WGSL) for tracing purposes and panics if none of the source fields is populated. A shader module descriptor must carry exactly one binary/source representation; when all are `None` there is nothing to write. This is reachable when shader tracing is enabled and a descriptor is constructed empty or via a path that never sets a source.

Source

Thrown at wgpu-types/src/shader.rs:201

    #[cfg(feature = "trace")]
    /// Returns the source data for tracing purpose.
    pub fn trace_data(&self) -> &[u8] {
        if let Some(spirv) = &self.spirv {
            bytemuck::cast_slice(spirv)
        } else if let Some(metallib) = &self.metallib {
            metallib
        } else if let Some(msl) = &self.msl {
            msl.as_bytes()
        } else if let Some(dxil) = &self.dxil {
            dxil
        } else if let Some(hlsl) = &self.hlsl {
            hlsl.as_bytes()
        } else if let Some(glsl) = &self.glsl {
            glsl.as_bytes()
        } else if let Some(wgsl) = &self.wgsl {
            wgsl.as_bytes()
        } else {
            panic!("No binary data provided to `ShaderModuleDescriptorGeneric`")
        }
    }

    #[cfg(feature = "trace")]
    /// Returns the binary file extension for tracing purpose.
    pub fn trace_binary_ext(&self) -> &'static str {
        if self.spirv.is_some() {
            "spv"
        } else if self.metallib.is_some() {
            "metallib"
        } else if self.msl.is_some() {
            "metal"
        } else if self.dxil.is_some() {
            "dxil"
        } else if self.hlsl.is_some() {
            "hlsl"
        } else if self.glsl.is_some() {
            "glsl"

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Ensure the descriptor has a source set before use: assign `wgsl`, `glsl`, `hlsl`, or `dxil` in `ShaderModuleDescriptorGeneric`.
  2. If building descriptors from Naga, serialize the module to WGSL and store it in the `wgsl` field.
  3. Guard trace calls behind a check that at least one source field is Some.

Example fix

// before
let desc = ShaderModuleDescriptorGeneric::default();
create_shader_module(&device, &desc);
// after
let desc = ShaderModuleDescriptorGeneric {
    wgsl: Some(wgsl_source.into()),
    ..Default::default()
};
Defensive patterns

Strategy: validation

Validate before calling

// Before creating/tracing a shader module:
if desc.wgsl.is_none() && desc.glsl.is_none() && desc.hlsl.is_none() && desc.dxil.is_none() {
    return Err("ShaderModuleDescriptorGeneric needs a source: set wgsl, glsl, hlsl, or dxil");
}

Type guard

fn has_shader_source(desc: &ShaderModuleDescriptorGeneric) -> bool {
    desc.wgsl.is_some() || desc.glsl.is_some() || desc.hlsl.is_some() || desc.dxil.is_some()
}

Prevention

When it happens

Trigger: Calling `trace_data()` (with the `trace` feature enabled) on a `ShaderModuleDescriptorGeneric` where `dxil`, `hlsl`, `glsl`, and `wgsl` are all None.

Common situations: Constructing the descriptor programmatically and forgetting to set the WGSL source; Naga-related paths where the source field is filled later; tracing infrastructure writing a shader capture before source assignment.

Related errors


AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03). Data as JSON: /api/errors/7770b840571fc37d. Report an issue: GitHub.