{"record":{"id":"9e89b04f983d078d","repo":"stride3d/stride","slug":"unexpected-type-inputtype-for-f16tof32","errorCode":null,"errorMessage":"Unexpected type {inputType} for f16tof32","messagePattern":"Unexpected type (.+?) for f16tof32","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs","lineNumber":417,"sourceCode":"        else if (inputType is VectorType v)\n        {\n            var uintType = context.GetOrRegister(ScalarType.UInt);\n            var components = new int[v.Size];\n            for (int i = 0; i < v.Size; i++)\n            {\n                // Extract uint component\n                var comp = new SpirvValue(builder.InsertData(new OpCompositeExtract(uintType, context.Bound++, x.Id, [i])));\n                // UnpackHalf2x16 -> float2\n                var unpack = builder.Insert(new GLSLExp(float2Type, context.Bound++, context.GetGLSL(), comp.Id));\n                unpack.InstructionMemory.Span[4] = 62; // GLSLstd450 UnpackHalf2x16\n                // Extract .x -> float\n                var extract = new SpirvValue(builder.InsertData(new OpCompositeExtract(floatType, context.Bound++, unpack.ResultId, [0])));\n                components[i] = extract.Id;\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 f16tof32\");\n    }\n    public override SpirvValue CompileF32tof16(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default)\n    {\n        // f32tof16(float) -> uint: PackHalf2x16(float2(x, 0.0)) -> uint\n        // For vector variants: decompose, apply per-element, recompose\n        var returnType = functionType.ReturnType;\n        var inputType = context.ReverseTypes[x.TypeId];\n        var float2Type = context.GetOrRegister(new VectorType(ScalarType.Float, 2));\n        var floatType = context.GetOrRegister(ScalarType.Float);\n        var uintType = context.GetOrRegister(ScalarType.UInt);\n        var zero = context.AddConstant(0.0f);\n\n        if (inputType is ScalarType)\n        {\n            // Construct float2(x, 0.0)\n            var float2Val = new SpirvValue(builder.InsertData(new OpCompositeConstruct(float2Type, context.Bound++, [x.Id, zero])));\n            // PackHalf2x16(float2) -> uint\n            var pack = builder.Insert(new GLSLExp(uintType, context.Bound++, context.GetGLSL(), float2Val.Id));","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs#L399-L435","documentation":"CompileF32tof16's sibling f16tof32 expects its input to resolve to a uint or vector-of-uint (packed half values) so it can unpack via GLSL UnpackHalf2x16, extract components, and recompose. If the input type is anything else, it throws InvalidOperationException with the resolved input type, since the packed-half unpacking path cannot apply.","triggerScenarios":"Calling f16tof32(x) where x is float, int, half, or a vector whose element type is not uint — the intrinsic requires the packed 16-bit representation held in uint(s).","commonSituations":"Forgetting that HLSL f16tof32 takes a uint (or uint-vector) of packed halves and passing the original float/half value; assigning the result of an intermediate computation to a float variable and feeding it back.","solutions":["Ensure the argument is uint or a uint vector holding packed half values (asuint on the packed data).","Reinterpret with asuint(...) if the bits are currently typed as something else.","If you intended a plain float conversion, use a cast instead of f16tof32.","If a new input kind (e.g. scalar uint handled separately) should be supported, extend CompileF16tof32's type dispatch."],"exampleFix":"// before (SDSL)\nfloat x = 1.5;\nfloat y = f16tof32(x); // throws: Unexpected type float\n// after\nuint packed = asuint(...);\nfloat y = f16tof32(packed);","handlingStrategy":"validation","validationCode":"bool IsPackedUint(TypeBase t) =>\n    t is ScalarType { Type: Scalar.UInt } or VectorType { BaseType: ScalarType { Type: Scalar.UInt } };","typeGuard":"bool IsUintOrUintVec(TypeBase t) => t.GetElementType() is ScalarType { Type: Scalar.UInt };","tryCatchPattern":"try { result = intrinsics.CompileF16tof32(table, ctx, builder, fnType, x); }\ncatch (InvalidOperationException ex) { /* report that input must be uint of packed halves */ }","preventionTips":["Remember f16tof32 takes uint(s) of packed half bits","Use asuint() to reinterpret before unpacking","Use plain casts for ordinary float conversions"],"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"}