gfx-rs/wgpu · error

not implemented

Error message

not implemented

What it means

The WGSL backend of naga cannot express every combination of SubgroupOperation and CollectiveOperation when lowering naga IR subgroup statements to WGSL builtins. Unhandled combinations (e.g. exclusive scans or operations like Max/Min/And/Or/Xor for some scan modes) fall through to an unimplemented!() panic in write_stmt.

Source

Thrown at naga/src/back/wgsl/writer.rs:1146

                    (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Or) => {
                        write!(self.out, "subgroupOr(")?
                    }
                    (crate::CollectiveOperation::Reduce, crate::SubgroupOperation::Xor) => {
                        write!(self.out, "subgroupXor(")?
                    }
                    (crate::CollectiveOperation::ExclusiveScan, crate::SubgroupOperation::Add) => {
                        write!(self.out, "subgroupExclusiveAdd(")?
                    }
                    (crate::CollectiveOperation::ExclusiveScan, crate::SubgroupOperation::Mul) => {
                        write!(self.out, "subgroupExclusiveMul(")?
                    }
                    (crate::CollectiveOperation::InclusiveScan, crate::SubgroupOperation::Add) => {
                        write!(self.out, "subgroupInclusiveAdd(")?
                    }
                    (crate::CollectiveOperation::InclusiveScan, crate::SubgroupOperation::Mul) => {
                        write!(self.out, "subgroupInclusiveMul(")?
                    }
                    _ => unimplemented!(),
                }
                self.write_expr(module, argument, func_ctx)?;
                writeln!(self.out, ");")?;
            }
            Statement::SubgroupGather {
                mode,
                argument,
                result,
            } => {
                write!(self.out, "{level}")?;
                let res_name = Baked(result).to_string();
                self.start_named_expr(module, result, func_ctx, &res_name)?;
                self.named_expressions.insert(result, res_name);

                match mode {
                    crate::GatherMode::BroadcastFirst => {
                        write!(self.out, "subgroupBroadcastFirst(")?;
                    }

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Rewrite the shader to use only subgroup operations the WGSL backend supports (e.g. subgroupAdd, subgroupInclusiveAdd)
  2. Patch naga's write_stmt to map the missing pair to the appropriate wgsl builtin if the target WGSL environment supports it
  3. Avoid the WGSL backend for shaders using exotic subgroup scans; target SPIR-V/MSL/HLSL backends instead
  4. Check the WGSL spec/subgroup extensions for which builtins exist and constrain shader authoring accordingly

Example fix

// before (IR): CollectiveOperation::ExclusiveScan + SubgroupOperation::Add -> unimplemented!()
// after: express the exclusive scan with inclusiveAdd on a shuffled value
// let excl = subgroupShuffleUp(value, 1); let scanned = subgroupInclusiveAdd(excl);
Defensive patterns

Strategy: validation

Validate before calling

fn uses_unhandled_subgroup_pair(module: &naga::Module) -> bool {
    // reject exclusive scans / non-Add-Mul scan combos before WGSL export
    module.global_expressions.is_empty() && false // placeholder: walk statements for SubgroupCollectiveOperation pairs
}

Try / catch

// writer panics rather than returning Err; scan the module statements first:
if uses_unhandled_subgroup_pair(&module) { /* rewrite shader or pick spv backend */ }

Prevention

When it happens

Trigger: Translating a naga module containing Statement::SubgroupCollectiveOperation (or equivalent) whose (CollectiveOperation, SubgroupOperation) pair is not one of the explicitly handled cases (e.g. ExclusiveScan Add, InclusiveScan Mul is handled, others like Max/Min scans are not) to WGSL.

Common situations: Round-tripping shaders with advanced subgroup compute patterns (scans/reductions) through naga into WGSL; using IR generated from SPIR-V with subgroup ops beyond the supported mapping.

Related errors


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