stride3d/stride · error · NotSupportedException

Unsupported composite type

Error message

Unsupported composite type {Type}

What it means

VectorLiteral.CompileImpl flattens a composite literal into scalars for SPIR-V emission. Only VectorType, MatrixType, and ArrayType have defined composite layouts; any other literal Type cannot be decomposed and throws this NotSupportedException.

Solutions

  1. Check the literal's declared type — it must be a vector, matrix, or array to use aggregate initializer syntax
  2. Fix the expression so scalars are assigned directly rather than via composite literals
  3. Report a parser bug if a valid composite literal reaches this path

Example fix

// before
float x = { 1.0, 2.0 }; // scalar with composite literal
// after
float2 x = { 1.0, 2.0 };
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure literal Type is a supported composite before compiling
if (literal.Type is not (VectorType or MatrixType or ArrayType))
    throw new NotSupportedException($"Literal type {literal.Type} is not a composite");

Type guard

bool IsCompositeLiteral(TypeBase t) => t is VectorType or MatrixType or ArrayType;

Try / catch

try { literal.Compile(context, builder); }
catch (NotSupportedException ex) when (ex.Message.Contains("Unsupported composite type")) { /* report invalid literal type */ }

Prevention

When it happens

Trigger: A literal expression whose Type is a scalar or custom composite (not vector/matrix/array) enters the composite compilation path — typically a malformed or wrongly-typed literal in parsed SDSL code.

Common situations: Parser/AST bugs where a literal's Type was not narrowed to a composite; user code attempting an aggregate initializer on a non-aggregate type that survived type checking.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/3c857eec1795a2c8. Report an issue: GitHub.

Appendix: source

Thrown at sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs:185

    public bool IsConstant()
    {
        foreach (var v in Values)
            if (v is not (NumberLiteral or BoolLiteral))
                return false;
        return true;
    }

    public override SpirvValue CompileImpl(SymbolTable table, CompilerUnit compiler)
    {
        var (builder, context) = compiler;

        (var compositeCount, var totalCount, var expectedElementType) = Type switch
        {
            VectorType v => (v.Size, v.Size, v.BaseType),
            MatrixType m => (m.Columns, m.Columns * m.Rows, m.BaseType),
            ArrayType t => (t.Size, t.Size, t.BaseType),
            _ => throw new NotSupportedException($"Unsupported composite type {Type}"),
        };

        Span<int> values = stackalloc int[totalCount];
        Span<int> compositeValues = stackalloc int[compositeCount];

        // Note: There are a lot of opportunity to optimize by working with vector-to-vector copy (if they align correctly) and/or OpVectorShuffle, but it can get quite complex to handle all cases
        //       However, it is probably optimized by SPIRV-Cross or the compiler/driver, so maybe not worth optimzing (due to increased code cases/complexity)
        var elementIndex = 0;
        for (int i = 0; i < Values.Count; i++)
        {
            // Note: we can compute expected element type only if there are as many source values as expected elements
            // i.e. float3(float, float, float) is OK but float3(float, float2) is not as we don't know which element will be which before compiling them (we would need 2-pass compilation for that)
            var value = Values[i].CompileAsValue(table, compiler, expectedElementType);
            var valueType = Values[i].ValueType;

            // We expand elements, because float4 can be created from (float, float2, float), or (float2x2)
            if (Type is ScalarType or VectorType or MatrixType)
            {

View on GitHub (pinned to 96fad776d2)