{"record":{"id":"c76b1f5ac2a1e945","repo":"stride3d/stride","slug":"unsupported-element-type-for-max-context-reversetypes-a","errorCode":null,"errorMessage":"Unsupported element type for max: {context.ReverseTypes[a.TypeId].GetElementType()}","messagePattern":"Unsupported element type for max: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs","lineNumber":125,"sourceCode":"    {\n        var instruction = context.ReverseTypes[a.TypeId].GetElementType() switch\n        {\n            ScalarType { Type: Scalar.Float or Scalar.Double } => builder.InsertData(new GLSLFMin(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), a.Id, b.Id)),\n            ScalarType { Type: Scalar.UInt } => builder.InsertData(new GLSLUMin(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), a.Id, b.Id)),\n            ScalarType { Type: Scalar.Int } => builder.InsertData(new GLSLSMin(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), a.Id, b.Id)),\n            _ => throw new NotSupportedException($\"Unsupported element type for min: {context.ReverseTypes[a.TypeId].GetElementType()}\"),\n        };\n        return new(instruction);\n    }\n\n    public override SpirvValue CompileMax(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue a, SpirvValue b, TextLocation location = default)\n    {\n        var instruction = context.ReverseTypes[a.TypeId].GetElementType() switch\n        {\n            ScalarType { Type: Scalar.Float or Scalar.Double } => builder.InsertData(new GLSLFMax(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), a.Id, b.Id)),\n            ScalarType { Type: Scalar.UInt } => builder.InsertData(new GLSLUMax(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), a.Id, b.Id)),\n            ScalarType { Type: Scalar.Int } => builder.InsertData(new GLSLSMax(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), a.Id, b.Id)),\n            _ => throw new NotSupportedException($\"Unsupported element type for max: {context.ReverseTypes[a.TypeId].GetElementType()}\"),\n        };\n        return new(instruction);\n    }\n\n    public override SpirvValue CompileClamp(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, SpirvValue min, SpirvValue max, TextLocation location = default)\n    {\n        var instruction = context.ReverseTypes[x.TypeId].GetElementType() switch\n        {\n            ScalarType { Type: Scalar.Float } => builder.InsertData(new GLSLFClamp(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), x.Id, min.Id, max.Id)),\n            ScalarType { Type: Scalar.UInt } => builder.InsertData(new GLSLUClamp(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), x.Id, min.Id, max.Id)),\n            ScalarType { Type: Scalar.Int } => builder.InsertData(new GLSLSClamp(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), x.Id, min.Id, max.Id)),\n            _ => throw new NotSupportedException($\"Unsupported element type for clamp: {context.ReverseTypes[x.TypeId].GetElementType()}\"),\n        };\n        return new(instruction);\n    }\n\n    public override SpirvValue CompileRadians(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLRadians, x);\n    public override SpirvValue CompileDegrees(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLDegrees, x);","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs#L107-L143","documentation":"CompileMax maps max() to GLSL.FMax (float/double), GLSL.UMax (uint), or GLSL.SMax (int). Any other element type (bool, half, custom scalars) falls to the default arm and throws NotSupportedException at IntrinsicImplementations.cs:125.","triggerScenarios":"Calling max(a, b) where a's element scalar type is not Float, Double, UInt, or Int in the SPIR-V type table.","commonSituations":"Taking max of boolean or half-precision values not yet mapped in the SPIR-V backend, or after adding new scalar types without updating the intrinsic dispatch.","solutions":["Use int/uint/float/double operands (scalars or vectors) with max().","Cast unsupported types to a supported numeric type before calling max().","Add a corresponding GLSL extended-op arm in CompileMax if the element type should be supported."],"exampleFix":"// before\nhalf2 h = max(h1, h2);      // if half is unsupported\n// after\nfloat2 h = max((float2)h1, (float2)h2);","handlingStrategy":"type-guard","validationCode":"// max supports float/double/uint/int element types only\nif (aType.GetElementType() is not ScalarType { Type: Scalar.Float or Scalar.Double or Scalar.Int or Scalar.UInt })\n    throw new ShaderCompileHint(\"max requires numeric scalar element type\");","typeGuard":"static bool IsMaxSupported(BaseType t) => t.GetElementType() is ScalarType s && s.Type is Scalar.Float or Scalar.Double or Scalar.Int or Scalar.UInt;","tryCatchPattern":"try { result = intrinsic.CompileMax(table, context, builder, functionType, a, b); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"element type for max\"))\n{ diagnostics.Report(location, ex.Message); }","preventionTips":["Use max() with int/uint/float/double operands only.","Cast half/custom scalar types to supported types before calling max().","Cover each scalar type with an intrinsic-compilation unit test."],"tags":["shader","intrinsics","spirv","glm"],"backgroundTag":"unsupported-dtype","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}