{"record":{"id":"7a66405350d7d24e","repo":"stride3d/stride","slug":"unexpected-type-inputtype-for-f32tof16","errorCode":null,"errorMessage":"Unexpected type {inputType} for f32tof16","messagePattern":"Unexpected type (.+?) for f32tof16","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs","lineNumber":456,"sourceCode":"        }\n        else if (inputType is VectorType v)\n        {\n            var components = new int[v.Size];\n            for (int i = 0; i < v.Size; i++)\n            {\n                // Extract float component\n                var comp = new SpirvValue(builder.InsertData(new OpCompositeExtract(floatType, context.Bound++, x.Id, [i])));\n                // Construct float2(comp, 0.0)\n                var float2Val = new SpirvValue(builder.InsertData(new OpCompositeConstruct(float2Type, context.Bound++, [comp.Id, zero])));\n                // PackHalf2x16 -> uint\n                var pack = builder.Insert(new GLSLExp(uintType, context.Bound++, context.GetGLSL(), float2Val.Id));\n                pack.InstructionMemory.Span[4] = 58; // GLSLstd450 PackHalf2x16\n                components[i] = pack.ResultId;\n            }\n            var result = new SpirvValue(builder.InsertData(new OpCompositeConstruct(context.GetOrRegister(returnType), context.Bound++, [.. components])));\n            return result;\n        }\n        throw new InvalidOperationException($\"Unexpected type {inputType} for f32tof16\");\n    }\n    public override SpirvValue CompileFirstbitlow(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLFindILsb, x);\n    public override SpirvValue CompileFma(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue a, SpirvValue b, SpirvValue c, TextLocation location = default)\n    {\n        var instruction = builder.Insert(new GLSLFma(a.TypeId, context.Bound++, context.GetGLSL(), a.Id, b.Id, c.Id));\n        return new(instruction.ResultId, instruction.ResultType);\n    }\n    public override SpirvValue CompileFrexp(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, SpirvValue exp, TextLocation location = default)\n    {\n        var instruction = builder.Insert(new GLSLFrexp(context.GetOrRegister(functionType.ReturnType), context.Bound++, context.GetGLSL(), x.Id, exp.Id));\n        return new(instruction.ResultId, instruction.ResultType);\n    }\n    public override SpirvValue CompileIsfinite(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default)\n    {\n        // isfinite(x) = !(isinf(x) || isnan(x))\n        var boolType = context.GetOrRegister(functionType.ReturnType);\n        var isInf = builder.Insert(new OpIsInf(boolType, context.Bound++, x.Id));\n        var isNan = builder.Insert(new OpIsNan(boolType, context.Bound++, x.Id));","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs#L438-L474","documentation":"CompileF32tof16 packs float values into 16-bit halves using GLSLstd450 PackHalf2x16 and expects the input to resolve to a float scalar or float vector; the per-element results are recomposed into the uint return type. If the input type is not a supported float type/vector, it throws InvalidOperationException naming the resolved input type.","triggerScenarios":"Calling f32tof16(x) where x resolves to int, uint, double, or a non-float vector — only float scalars/vectors can be packed with PackHalf2x16 in the generated code.","commonSituations":"Passing an int assuming bit-level reinterpretation; passing a double from double-precision math; generic T functions instantiating to non-float types.","solutions":["Cast the argument to float (or floatN) before f32tof16, e.g. f32tof16((float)x).","Use asuint/asint for pure bit reinterpretation instead of f32tof16.","Ensure generic shader code constrains T to float types for this call path.","If another input kind should be supported, extend the type dispatch in CompileF32tof16."],"exampleFix":"// before (SDSL)\nint i = 3;\nuint p = f32tof16(i); // throws: Unexpected type int\n// after\nuint p = f32tof16((float)i);","handlingStrategy":"validation","validationCode":"bool IsFloatInput(TypeBase t) =>\n    t is ScalarType { Type: Scalar.Float } or VectorType { BaseType: ScalarType { Type: Scalar.Float } };","typeGuard":"bool IsFloatOrFloatVec(TypeBase t) => t.GetElementType() is ScalarType { Type: Scalar.Float };","tryCatchPattern":"try { result = intrinsics.CompileF32tof16(table, ctx, builder, fnType, x); }\ncatch (InvalidOperationException ex) { /* report that input must be float/floatN */ }","preventionTips":["Cast ints/doubles to float before f32tof16","Use asuint/asint for bit reinterpretation instead","Keep generic T constrained to float for packing intrinsics"],"tags":["shader","spirv","sdsl","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}