stride3d/stride · error · Exception
Type not supported in SPIR-V
Error message
Type not supported in SPIR-V
What it means
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.
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
Example fix
// before
var arr = new LiteralArray<byte>(new byte[] { 1, 2, 3 }); // throws
// after
var arr = new LiteralArray<int>(new byte[] { 1, 2, 3 }.Select(b => (int)b).ToArray()); Defensive patterns
Strategy: type-guard
Validate before calling
static bool IsSpirvLiteralType<T>() =>
typeof(T) is var t && (
t == typeof(int) || t == typeof(uint) || t == typeof(long) || t == typeof(ulong) ||
t == typeof(Half) || t == typeof(float) || t == typeof(double) || t == typeof(bool) ||
t == typeof((int, int))); Type guard
static LiteralArray<T>? TryCreateLiteralArray<T>(T[] elements) =>
IsSpirvLiteralType<T>() ? new LiteralArray<T>(elements) : null; Try / catch
try
{
var arr = new LiteralArray<T>(elements);
}
catch (Exception ex) when (ex.Message == "Type not supported in SPIR-V")
{
log.Error($"Type {typeof(T)} cannot be encoded as a SPIR-V literal; convert to int/float/etc.");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Type not supported in SPIR-V
- Cannot create LiteralValue from the provided words
- Can't compute literal value for type
- Cannot simplify constant of type
- Unsupported constant type
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/08b96847c6ca59ef.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Spirv/Literals/LiteralArray.cs:39
static LiteralArray()
{
LiteralArray<T> v = default;
_ = v switch
{
LiteralArray<sbyte>
or LiteralArray<short>
or LiteralArray<int>
or LiteralArray<long>
or LiteralArray<byte>
or LiteralArray<ushort>
or LiteralArray<uint>
or LiteralArray<ulong>
or LiteralArray<Half>
or LiteralArray<float>
or LiteralArray<double>
or LiteralArray<bool>
or LiteralArray<(int, int)> => true,
_ => throw new Exception("Type not supported in SPIR-V")
};
}
public MemoryOwner<T> Elements { get; set { field?.Dispose(); field = value; } }
public readonly int WordCount => Elements?.Length ?? -1;
public readonly ReadOnlySpan<int> Words => Elements is not null ? MemoryMarshal.Cast<T, int>(Elements.Span) : [];
public LiteralArray()
{
Elements = MemoryOwner<T>.Empty;
}
public LiteralArray(MemoryOwner<T> elements)
{
Elements = elements;
}
public LiteralArray(ReadOnlySpan<T> elements)View on GitHub (pinned to 96fad776d2)