{"record":{"id":"9c7ff0cf828224ff","repo":"stride3d/stride","slug":"unsupported-type-for-getelementcount-symbol","errorCode":null,"errorMessage":"Unsupported type for GetElementCount: {symbol}","messagePattern":"Unsupported type for GetElementCount: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs","lineNumber":728,"sourceCode":"\n    public static SymbolType GetValueType(this SymbolType type)\n    {\n        return type switch\n        {\n            PointerType pointerType => pointerType.BaseType,\n            _ => type\n        };\n    }\n\n    public static SymbolType GetVectorOrScalar(this ScalarType scalar, int size)\n        => size == 1 ? scalar : new VectorType(scalar, size);\n\n    public static int GetElementCount(this SymbolType symbol) => symbol switch\n    {\n        ScalarType s => 1,\n        VectorType v => v.Size,\n        MatrixType m => m.Rows * m.Columns,\n        _ => throw new NotSupportedException($\"Unsupported type for GetElementCount: {symbol}\"),\n    };\n    public static ScalarType GetElementType(this SymbolType symbol) => symbol switch\n    {\n        ScalarType s => s,\n        VectorType v => v.BaseType,\n        MatrixType m => m.BaseType,\n        _ => throw new NotSupportedException($\"Unsupported type for GetElementType: {symbol}\"),\n    };\n    public static SymbolType WithElementType(this SymbolType symbol, ScalarType elementType) => symbol switch\n    {\n        ScalarType s => elementType,\n        VectorType v => v.BaseType == elementType ? v : v with { BaseType = elementType },\n        MatrixType m => m.BaseType == elementType ? m : m with { BaseType = elementType },\n        _ => throw new NotSupportedException($\"Unsupported type for WithElementType: {symbol}\"),\n    };\n    public static bool IsSignedInteger(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.Int or Scalar.Int64 };\n    public static bool IsUnsignedInteger(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.UInt or Scalar.UInt64 };\n    public static bool IsFloating(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.Half or Scalar.Float or Scalar.Double };","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs#L710-L746","documentation":"GetElementCount is a SPIR-V builder extension method that computes the number of scalar elements a SymbolType holds (scalar=1, vector=its size, matrix=rows*columns). It throws NotSupportedException for any other SymbolType (e.g. array, struct, image, pointer types) because an element count is not defined for them.","triggerScenarios":"Calling GetElementCount() on a SymbolType that is not ScalarType, VectorType, or MatrixType — e.g. an ArrayType, StructType, PointerType, or ImageType passed to an instruction-size helper during SPIR-V emission.","commonSituations":"Compiling a shader that passes arrays or structs (or handles to buffers/images) into code paths that assume numeric types, e.g. composite construction, constant folding, or implicit conversion logic in the Stride shader compiler.","solutions":["Inspect the SymbolType before calling; only numeric types (scalar/vector/matrix) have an element count.","For arrays, use the array element count (Size * GetElementCount(elementType)) instead; for structs, sum member counts.","Add a match arm or a type guard in the calling code to route non-numeric types to the correct handling.","Log/dump the offending symbol type to confirm which shader construct produced it."],"exampleFix":"// before\nint count = symbolType.GetElementCount();\n// after\nint count = symbolType switch\n{\n    ScalarType or VectorType or MatrixType => symbolType.GetElementCount(),\n    ArrayType a => a.Size * a.BaseType.GetElementCount(),\n    _ => throw new NotSupportedException($\"Cannot compute element count for {symbolType}\")\n};","handlingStrategy":"type-guard","validationCode":"bool hasElementCount = t is ScalarType or VectorType or MatrixType;","typeGuard":"static bool IsNumericType(SymbolType t) => t is ScalarType or VectorType or MatrixType;","tryCatchPattern":"try { count = symbol.GetElementCount(); } catch (NotSupportedException ex) { /* fallback: handle composite types separately */ }","preventionTips":["Only call element-count helpers on scalar/vector/matrix types","Handle arrays/structs in dedicated code paths","Add unit tests covering all SymbolType variants","Dump the symbol kind when adding new type variants"],"tags":["spirv","shader-compiler","unsupported-type"],"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"}