{"record":{"id":"c84f7894269ac00d","repo":"gfx-rs/wgpu","slug":"unexpected-max","errorCode":null,"errorMessage":"Unexpected max({:?})","messagePattern":"Unexpected max\\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"naga/src/back/spv/block.rs","lineNumber":1412,"sourceCode":"                                    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) => {\n                                    (spirv::GlslStd450Op::UMin, spirv::GlslStd450Op::UMax)\n                                }\n                                _ => unreachable!(),\n                            };\n\n                            let max_id = self.gen_id();","sourceCodeStart":1394,"sourceCodeEnd":1430,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/naga/src/back/spv/block.rs#L1394-L1430","documentation":"Same family as 108 but for MathFunction::Max: the backend maps arg_scalar_kind Float/Sint/Uint to GlslStd450 FMax/SMax/UMax; any other kind (including Bool — note the WGSL spec only defines max for numeric types) triggers `unimplemented!(\"Unexpected max({:?})\", other)` in cache_expression_value under write_block, aborting SPIR-V generation.","triggerScenarios":"A `max(a, b)` call whose argument scalar kind is None or otherwise unmapped (bool, composite, pointer) when the SPIR-V backend lowers math functions.","commonSituations":"Fuzzed/unvalidated IR with max over booleans; calling naga's spv backend directly on hand-built modules; type-inference changes after naga upgrades altering arg_scalar_kind.","solutions":["Restrict max() calls to numeric (f32/i32/u32, or matching vectors) arguments","Validate the IR module before SPIR-V emission","Dump IR to identify the bad max call site","File a naga issue with the shader if it is valid WGSL"],"exampleFix":"// before\nlet m = max(flag_a, flag_b); // bools\n// after\nlet m = select(flag_b, flag_a, flag_a); // or compute on numeric values","handlingStrategy":"validation","validationCode":"assert!(matches!(arg_scalar_kind, Some(crate::ScalarKind::Float | crate::ScalarKind::Sint | crate::ScalarKind::Uint)), \"max() 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 max only on numeric scalars/vectors","Validate IR before invoking the SPIR-V writer","Wrap untrusted-shader translation in catch_unwind and report panics upstream"],"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"}