{"record":{"id":"cf0215bf810a31d9","repo":"stride3d/stride","slug":"unsupported-float-width-type-width","errorCode":null,"errorMessage":"Unsupported float width {type.Width}","messagePattern":"Unsupported float width (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Core/ConstantExpression.cs","lineNumber":122,"sourceCode":"                        long val = type switch\n                        {\n                            { Width: <= 32, Signedness: 0 } => (long)operand.ToLiteral<uint>(),\n                            { Width: <= 32, Signedness: 1 } => operand.ToLiteral<int>(),\n                            { Width: 64, Signedness: 0 } => (long)operand.ToLiteral<ulong>(),\n                            { Width: 64, Signedness: 1 } => operand.ToLiteral<long>(),\n                            _ => throw new NotImplementedException($\"Unsupported int width {type.Width}\"),\n                        };\n                        return new IntConstExpr(val);\n                    }\n                    else if (typeInst.Op == Op.OpTypeFloat)\n                    {\n                        var type = new OpTypeFloat(typeInst);\n                        double val = type switch\n                        {\n                            { Width: 16 } => (double)operand.ToLiteral<Half>(),\n                            { Width: 32 } => operand.ToLiteral<float>(),\n                            { Width: 64 } => operand.ToLiteral<double>(),\n                            _ => throw new NotImplementedException($\"Unsupported float width {type.Width}\"),\n                        };\n                        return new FloatConstExpr(val);\n                    }\n                    else\n                        throw new NotImplementedException($\"Unsupported constant type {typeInst.Op}\");\n                }\n                throw new InvalidOperationException($\"Cannot find type instruction for id {typeId}\");\n            }\n\n            case Op.OpConstantStringSDSL:\n            {\n                var operand = inst.Data.Get(\"literalString\");\n                return new StringConstExpr(operand.ToLiteral<string>());\n            }\n\n            case Op.OpGenericParameterSDSL:\n            case Op.OpGenericReferenceSDSL:\n            {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Core/ConstantExpression.cs#L104-L140","documentation":"ConstantExpression.ParseInstruction throws this NotImplementedException when parsing an OpConstant/OpSpecConstant whose result type is an OpTypeFloat with a Width other than 16, 32, or 64. The SPIR-V parser only knows how to materialize half, float, and double literals into a FloatConstExpr; any other declared float width (e.g. a malformed or exotic buffer) cannot be converted to a .NET double, so the library fails fast rather than silently corrupting the constant value.","triggerScenarios":"Parsing a SPIR-V buffer via ConstantExpression.ParseFromBuffer where the constant's OpTypeFloat instruction declares Width not in {16,32,64} — e.g. a corrupted hand-built SPIR-V blob, a buffer produced by a buggy custom emitter, or a non-standard float type injected by a tool.","commonSituations":"Feeding hand-crafted or third-party-generated SPIR-V into the SDSL parser; a producer tool writing OpTypeFloat with a wrong word-width value; fuzzing or loading truncated/misaligned SPIR-V where the width operand is read from the wrong offset.","solutions":["Inspect the SPIR-V buffer and fix the OpTypeFloat instruction so Width is 16, 32, or 64 (e.g. with spirv-val / spirv-dis).","Validate the buffer with the SPIR-V validator before calling ParseFromBuffer so malformed types are rejected upstream.","If you legitimately need another width, extend the switch in ConstantExpression.cs:117 to map the width to a literal type.","Check that the buffer was produced by the matching version of the Stride SPIR-V builder — older/newer toolchains may encode types differently."],"exampleFix":"// Buffer contains a bad float type\nvar type = new OpTypeFloat(typeInst); // Width: 48 -> throws\n// Fix the producer so it emits:\n// new OpTypeFloat(id, width: 32)","handlingStrategy":"validation","validationCode":"static bool HasSupportedFloatWidth(SpirvBuffer buffer, int typeId)\n    => buffer.TryGetInstructionById(typeId, out var t) && t.Op == Op.OpTypeFloat\n       && new OpTypeFloat(t).Width is 16 or 32 or 64;","typeGuard":"static bool IsSupportedFloatType(OpDataIndex typeInst)\n    => typeInst.Op == Op.OpTypeFloat && new OpTypeFloat(typeInst).Width is 16 or 32 or 64;","tryCatchPattern":"try\n{\n    var expr = ConstantExpression.ParseFromBuffer(id, buffer, context);\n}\ncatch (NotImplementedException ex)\n{\n    // log unsupported float width, skip or substitute a default constant\n    Console.Error.WriteLine($\"Unsupported constant encoding: {ex.Message}\");\n}","preventionTips":["Run spirv-val on all buffers before parsing.","Only parse buffers produced by the Stride SPIR-V builder you compiled against.","Never hand-edit SPIR-V type words; regenerate the buffer instead."],"tags":["spirv","shader-parsing","unsupported-value","not-implemented"],"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"}