gfx-rs/wgpu · error

not implemented

Error message

not implemented

What it means

A `unimplemented!()` panic in naga's SPIR-V backend (`cache_expression_value`, called from `write_block`) while selecting the SPIR-V opcode for a binary Add. Scalar and vector operands select FAdd/ISub-style ops per scalar kind, and `CooperativeMatrix` selects `OpFAdd`, but any other operand type (e.g. matrices or unexpected type inners) falls into `_ => unimplemented!()`. It indicates the SPIR-V writer lacks an opcode mapping for the addition's operand type.

Source

Thrown at naga/src/back/spv/block.rs:1167

                            } => {
                                //TODO: why not just rely on `Fadd` for matrices?
                                self.write_matrix_matrix_column_op(
                                    block,
                                    id,
                                    result_type_id,
                                    left_id,
                                    right_id,
                                    columns,
                                    rows,
                                    scalar.width,
                                    spirv::Op::FAdd,
                                );

                                self.cached[expr_handle] = id;
                                return Ok(());
                            }
                            crate::TypeInner::CooperativeMatrix { .. } => spirv::Op::FAdd,
                            _ => unimplemented!(),
                        },
                        crate::BinaryOperator::Subtract => match *left_ty_inner {
                            crate::TypeInner::Scalar(scalar)
                            | crate::TypeInner::Vector { scalar, .. } => match scalar.kind {
                                crate::ScalarKind::Float => spirv::Op::FSub,
                                _ => spirv::Op::ISub,
                            },
                            crate::TypeInner::Matrix {
                                columns,
                                rows,
                                scalar,
                            } => {
                                self.write_matrix_matrix_column_op(
                                    block,
                                    id,
                                    result_type_id,
                                    left_id,
                                    right_id,

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Rewrite the shader so additions operate on scalars/vectors (decompose matrix adds into component-wise vector ops).
  2. Lower the addition before SPIR-V emission (e.g. via naga's lowering passes) so the expression reaches the backend in a supported form.
  3. Upgrade naga or file an upstream issue with the failing WGSL module to get the opcode mapping added.

Example fix

// before: matrix + matrix add reaching SPIR-V writer unhandled
let m = a + b;
// after: component-wise via vectors/loops
for (var i = 0u; i < 4u; i++) { m[i] = a[i] + b[i]; }
Defensive patterns

Strategy: validation

Validate before calling

fn add_operands_supported(left_ty: &naga::TypeInner) -> bool {
    matches!(left_ty,
        naga::TypeInner::Scalar(_) | naga::TypeInner::Vector { .. } |
        naga::TypeInner::CooperativeMatrix { .. })
}

Type guard

fn is_scalar_or_vector(t: &naga::TypeInner) -> bool {
    matches!(t, naga::TypeInner::Scalar(_) | naga::TypeInner::Vector { .. })
}

Try / catch

let result = std::panic::catch_unwind(|| spv::write_pipeline(...)).map_err(|_| TranslateError::UnsupportedBinaryOp);

Prevention

When it happens

Trigger: Evaluating an addition expression whose left operand type is neither scalar, vector, nor CooperativeMatrix — e.g. a matrix add or an unexpected type inner reaching the SPIR-V block writer.

Common situations: Shaders using additions on types the SPIR-V writer doesn't map (such as matrix arithmetic on some paths); internal IR lowered in ways that produce non-scalar/vector adds; testing cooperative matrix or novel type support.

Related errors


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