{"record":{"id":"08b96847c6ca59ef","repo":"stride3d/stride","slug":"type-not-supported-in-spir-v","errorCode":null,"errorMessage":"Type not supported in SPIR-V","messagePattern":"Type not supported in SPIR-V","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Spirv/Literals/LiteralArray.cs","lineNumber":39,"sourceCode":"    static LiteralArray()\n    {\n        LiteralArray<T> v = default;\n        _ = v switch\n        {\n            LiteralArray<sbyte>\n            or LiteralArray<short>\n            or LiteralArray<int>\n            or LiteralArray<long>\n            or LiteralArray<byte>\n            or LiteralArray<ushort>\n            or LiteralArray<uint>\n            or LiteralArray<ulong>\n            or LiteralArray<Half>\n            or LiteralArray<float>\n            or LiteralArray<double>\n            or LiteralArray<bool>\n            or LiteralArray<(int, int)> => true,\n            _ => throw new Exception(\"Type not supported in SPIR-V\")\n        };\n    }\n\n    public MemoryOwner<T> Elements { get; set { field?.Dispose(); field = value; } }\n    public readonly int WordCount => Elements?.Length ?? -1;\n\n    public readonly ReadOnlySpan<int> Words => Elements is not null ? MemoryMarshal.Cast<T, int>(Elements.Span) : [];\n\n    public LiteralArray()\n    {\n        Elements = MemoryOwner<T>.Empty;\n    }\n\n    public LiteralArray(MemoryOwner<T> elements)\n    {\n        Elements = elements;\n    }\n    public LiteralArray(ReadOnlySpan<T> elements)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Spirv/Literals/LiteralArray.cs#L21-L57","documentation":"LiteralArray's type-support check returns true only for the literal array element types SPIR-V can encode (integers, unsigned, long variants, ulong, Half, float, double, bool, and (int,int) pairs). Any other T passed to the helper throws a generic Exception stating the type is not supported in SPIR-V, since SPIR-V literals have a fixed set of encodable types.","triggerScenarios":"Calling the LiteralArray.IsSupported/Check helper (directly or via LiteralArray construction) with a generic T that is not one of the supported literal element types — e.g. byte, sbyte, short, decimal, char, or a custom struct.","commonSituations":"Writing a generic SPIR-V constant emitter with T=byte or T=short and assuming all numeric types encode; a serialization helper passing decimal or user struct arrays as constant data; API changes where a previously used type is no longer in the supported list.","solutions":["Convert the data to a supported element type before building the LiteralArray (e.g. cast byte[] to int[] or float[])","Split compound/custom-typed constants into individual supported-typed constants (e.g. pack two ints instead of a struct)","If short/byte coverage is genuinely needed, extend the supported type list in LiteralArray and its word-encoding logic"],"exampleFix":"// before\nvar arr = new LiteralArray<byte>(new byte[] { 1, 2, 3 }); // throws\n// after\nvar arr = new LiteralArray<int>(new byte[] { 1, 2, 3 }.Select(b => (int)b).ToArray());","handlingStrategy":"type-guard","validationCode":"static bool IsSpirvLiteralType<T>() =>\n    typeof(T) is var t && (\n    t == typeof(int) || t == typeof(uint) || t == typeof(long) || t == typeof(ulong) ||\n    t == typeof(Half) || t == typeof(float) || t == typeof(double) || t == typeof(bool) ||\n    t == typeof((int, int)));","typeGuard":"static LiteralArray<T>? TryCreateLiteralArray<T>(T[] elements) =>\n    IsSpirvLiteralType<T>() ? new LiteralArray<T>(elements) : null;","tryCatchPattern":"try\n{\n    var arr = new LiteralArray<T>(elements);\n}\ncatch (Exception ex) when (ex.Message == \"Type not supported in SPIR-V\")\n{\n    log.Error($\"Type {typeof(T)} cannot be encoded as a SPIR-V literal; convert to int/float/etc.\");\n}","preventionTips":["Restrict generic constant-emission helpers to the supported literal type set","Convert byte/short/decimal data to int/float before building literal arrays","Encode structs as multiple per-field constants instead of one array"],"tags":["spirv","literals","unsupported-type"],"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"}