{"record":{"id":"d78c741c8b10d8d9","repo":"stride3d/stride","slug":"type-not-supported-in-spir-v-literalvalue","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/LiteralValue.cs","lineNumber":43,"sourceCode":"        LiteralValue<T> v = default;\n        _ = v switch\n        {\n            LiteralValue<sbyte>\n            or LiteralValue<short>\n            or LiteralValue<int>\n            or LiteralValue<int?>\n            or LiteralValue<long>\n            or LiteralValue<byte>\n            or LiteralValue<ushort>\n            or LiteralValue<uint>\n            or LiteralValue<ulong>\n            or LiteralValue<Half>\n            or LiteralValue<float>\n            or LiteralValue<double>\n            or LiteralValue<string>\n            or LiteralValue<bool>\n            or LiteralValue<(int, int)> => true,\n            _ => throw new Exception(\"Type not supported in SPIR-V\")\n        };\n    }\n    public bool dispose;\n    public MemoryOwner<int> MemoryOwner { get; private set; }\n    public readonly ReadOnlySpan<int> Words => MemoryOwner.Span;\n    public T Value { get; set { field = value; if (MemoryOwner is not null) UpdateMemory(); } }\n    public readonly int WordCount => Words.Length;\n\n    public LiteralValue(Span<int> words, bool dispose = false)\n    {\n        this.dispose = dispose;\n        T value = default!;\n        if (value is bool)\n            Unsafe.As<T, bool>(ref value) = words[0] != 0;\n        else if (value is byte)\n            Unsafe.As<T, byte>(ref value) = (byte)words[0];\n        else if (value is sbyte)\n            Unsafe.As<T, sbyte>(ref value) = (sbyte)words[0];","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Spirv/Literals/LiteralValue.cs#L25-L61","documentation":"LiteralValue.IsSupported (the type-support switch over LiteralValue<T> instantiations) only recognizes a fixed set of T types: Half, float, double, string, bool, (int,int) plus numeric/enum types handled earlier in the switch. Any other T falls through to the throw. SPIR-V literals are limited to these scalar representations, so the library rejects everything else at construction time.","triggerScenarios":"Creating a LiteralValue<T> with a T that is not one of: bool, byte, sbyte, short, ushort, int, uint, Half, float, long, ulong, double, string, (int,int), or an Enum — e.g. new LiteralValue<char>(...) or LiteralValue<decimal>.","commonSituations":"Hand-writing SPIR-V literal operands with a convenient .NET type (char, decimal, IntPtr, custom struct); generic code that passes arbitrary T into literal construction; porting code after a type was removed from the supported list in a Stride version change.","solutions":["Use a supported type: convert to int/uint/float/double/bool/string/(int,int) before constructing the literal.","For char, convert to ushort or int (SPIR-V literals are integer words).","For decimal, convert to double or float.","If the type genuinely must be supported, add a LiteralValue<T> implementation (where T : ...) plus a matching case in the support switch in LiteralValue.cs."],"exampleFix":"// before\nvar lit = new LiteralValue<char>('A');\n// after\nvar lit = new LiteralValue<ushort>((ushort)'A');","handlingStrategy":"validation","validationCode":"static bool IsSupportedLiteralType(Type t) =>\n    t == typeof(bool) || t == typeof(byte) || t == typeof(sbyte) ||\n    t == typeof(short) || t == typeof(ushort) || t == typeof(Half) ||\n    t == typeof(int) || t == typeof(uint) || t == typeof(float) ||\n    t == typeof(long) || t == typeof(ulong) || t == typeof(double) ||\n    t == typeof(string) || t == typeof((int, int)) || typeof(Enum).IsAssignableFrom(t);","typeGuard":"static bool CanMakeLiteral<T>() => IsSupportedLiteralType(typeof(T));","tryCatchPattern":"try { var lit = new LiteralValue<T>(value); }\ncatch (Exception ex) when (ex.Message == \"Type not supported in SPIR-V\") { /* fall back to a supported encoding, e.g. convert to int/float */ }","preventionTips":["Restrict literal construction to the closed set of SPIR-V-supported types via a helper factory.","Convert char/decimal/other .NET types to int/float words before creating literals.","Add a unit test enumerating every T your pipeline feeds into LiteralValue."],"tags":["spirv","literals","unsupported-type","shader-compilation"],"backgroundTag":"unsupported-operation","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"}