{"record":{"id":"83e06051bacda542","repo":"gfx-rs/wgpu","slug":"unexpected-min","errorCode":null,"errorMessage":"Unexpected min({:?})","messagePattern":"Unexpected min\\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"naga/src/back/spv/block.rs","lineNumber":1406,"sourceCode":"                                MathOp::Ext(spirv::GlslStd450Op::FAbs)\n                            }\n                            Some(crate::ScalarKind::Sint) => MathOp::Ext(spirv::GlslStd450Op::SAbs),\n                            Some(crate::ScalarKind::Uint) => {\n                                MathOp::Custom(Instruction::unary(\n                                    spirv::Op::CopyObject, // do nothing\n                                    result_type_id,\n                                    id,\n                                    arg0_id,\n                                ))\n                            }\n                            other => unimplemented!(\"Unexpected abs({:?})\", other),\n                        }\n                    }\n                    Mf::Min => MathOp::Ext(match arg_scalar_kind {\n                        Some(crate::ScalarKind::Float) => spirv::GlslStd450Op::FMin,\n                        Some(crate::ScalarKind::Sint) => spirv::GlslStd450Op::SMin,\n                        Some(crate::ScalarKind::Uint) => spirv::GlslStd450Op::UMin,\n                        other => unimplemented!(\"Unexpected min({:?})\", other),\n                    }),\n                    Mf::Max => MathOp::Ext(match arg_scalar_kind {\n                        Some(crate::ScalarKind::Float) => spirv::GlslStd450Op::FMax,\n                        Some(crate::ScalarKind::Sint) => spirv::GlslStd450Op::SMax,\n                        Some(crate::ScalarKind::Uint) => spirv::GlslStd450Op::UMax,\n                        other => unimplemented!(\"Unexpected max({:?})\", other),\n                    }),\n                    Mf::Clamp => match arg_scalar_kind {\n                        // Clamp is undefined if min > max. In practice this means it can use a median-of-three\n                        // instruction to determine the value. This is fine according to the WGSL spec for float\n                        // clamp, but integer clamp _must_ use min-max. As such we write out min/max.\n                        Some(crate::ScalarKind::Float) => MathOp::Ext(spirv::GlslStd450Op::FClamp),\n                        Some(_) => {\n                            let (min_op, max_op) = match arg_scalar_kind {\n                                Some(crate::ScalarKind::Sint) => {\n                                    (spirv::GlslStd450Op::SMin, spirv::GlslStd450Op::SMax)\n                                }\n                                Some(crate::ScalarKind::Uint) => {","sourceCodeStart":1388,"sourceCodeEnd":1424,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/naga/src/back/spv/block.rs#L1388-L1424","documentation":"The SPIR-V backend lowers MathFunction::Min through GlslStd450 FMin/SMin/UMin based on arg_scalar_kind; a Float/Sint/Uint argument is fine, but any other kind (None, Bool, etc.) reaches `unimplemented!(\"Unexpected min({:?})\", other)`. The panic occurs in cache_expression_value invoked by write_block, halting shader translation.","triggerScenarios":"A `min(a, b)` built-in whose argument scalar kind is not Float, Sint, or Uint — e.g. min over bools or a kindless/composite type — while generating SPIR-V.","commonSituations":"Direct backend use on unvalidated/fuzzed IR; front-end regression letting invalid min() through; WGSL sources with min on booleans that should have failed validation.","solutions":["Use min only on numeric scalar/vector arguments in the shader","Run naga validation before the spv backend to catch the bad call early","Inspect the IR dump to locate the offending min expression","Report a reproducer upstream if valid input panics"],"exampleFix":"// before\nlet m = min(a, b); // a,b: bool\n// after\nlet m = min(a.x, b.x); // f32 components","handlingStrategy":"validation","validationCode":"assert!(matches!(arg_scalar_kind, Some(crate::ScalarKind::Float | crate::ScalarKind::Sint | crate::ScalarKind::Uint)), \"min() requires numeric argument\");","typeGuard":"fn min_max_supported(kind: Option<crate::ScalarKind>) -> bool {\n    matches!(kind, Some(crate::ScalarKind::Float | crate::ScalarKind::Sint | crate::ScalarKind::Uint))\n}","tryCatchPattern":null,"preventionTips":["Use min only on numeric scalars/vectors","Run naga validation before spv-out","Test math built-ins against the WGSL spec's supported parameterizations"],"tags":["spv","naga","unimplemented","math-function","codegen-panic"],"backgroundTag":"spv-backend-unimplemented-opcode","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}