{"record":{"id":"d77ac8498810c509","repo":"stride3d/stride","slug":"unsupported-type-for-swizzle-valuetype","errorCode":null,"errorMessage":"Unsupported type for swizzle: {valueType}","messagePattern":"Unsupported type for swizzle: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs","lineNumber":34,"sourceCode":"        var type = context.ReverseTypes[result.TypeId];\n        if (type is PointerType pointerType)\n        {\n            type = pointerType.BaseType;\n            var inst = Insert(new OpLoad(context.Types[type], context.Bound++, result.Id, null, []));\n            result = new(inst.ResultId, inst.ResultType);\n        }\n\n        return result;\n    }\n\n    public (SpirvValue, SymbolType) ApplySwizzles(SpirvContext context, SpirvValue value, Span<int> swizzleIndices)\n    {\n        var valueType = context.ReverseTypes[value.TypeId];\n        return valueType switch\n        {\n            ScalarType s => ApplyScalarSwizzles(context, value, s, swizzleIndices),\n            VectorType v => ApplyVectorSwizzles(context, value, v, swizzleIndices),\n            _ => throw new NotSupportedException($\"Unsupported type for swizzle: {valueType}\"),\n        };\n    }\n\n    public (SpirvValue, SymbolType) ApplyScalarSwizzles(SpirvContext context, SpirvValue value, ScalarType s, Span<int> swizzleIndices)\n    {\n        var resultType = new VectorType(s, swizzleIndices.Length);\n\n        Span<int> constructIndices = stackalloc int[swizzleIndices.Length];\n        for (int j = 0; j < constructIndices.Length; ++j)\n        {\n            if (swizzleIndices[j] != 0)\n                throw new InvalidOperationException(\"Invalid swizzle for scalar type\");\n\n            constructIndices[j] = value.Id;\n        }\n\n        SpirvValue result;\n        var construct = InsertData(new OpCompositeConstruct(context.GetOrRegister(resultType), context.Bound++, new(constructIndices)));","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs#L16-L52","documentation":"ApplySwizzles resolves the SPIR-V type of the value being swizzled and dispatches to scalar/vector swizzle handlers. If the value's type is neither a ScalarType nor a VectorType (e.g. matrix, struct, array), the switch falls through to a NotSupportedException, because only scalar and vector components support swizzle semantics here.","triggerScenarios":"Applying a swizzle (e.g. .xyz) to a value whose resolved type is a MatrixType, StructType, ArrayType, or StreamsType in the SPIR-V context.","commonSituations":"Writing HLSL with a swizzle on a matrix (mat.xy) or a sampled stream/struct value; parser/frontend passing a composite type where a vector was expected.","solutions":["Rewrite the shader to apply the swizzle only to vectors or scalars","For matrices, extract a column/row vector first, then swizzle the vector","Check upstream type inference to see why the value resolved to a non-scalar/vector type","Extend the builder with a matrix swizzle handler if this is a supported language feature"],"exampleFix":"// before (HLSL)\nfloat4x4 m;\nfloat3 v = m.xyz;\n// after\nfloat4x4 m;\nfloat3 v = m[0].xyz;","handlingStrategy":"type-guard","validationCode":"// Ensure the swizzled expression's symbol type is scalar or vector\nvar t = symbolTable.ResolveType(expr.Target);\nif (t is not (ScalarType or VectorType))\n    throw new ShaderSemanticException($\"Swizzle requires scalar/vector, got {t}\");","typeGuard":"bool IsSwizzleable(SymbolType t) => t is ScalarType or VectorType;","tryCatchPattern":"try { var (val, sym) = ApplySwizzles(context, value, swizzle); }\ncatch (NotSupportedException ex) { Log.Error(ex, \"Cannot swizzle value of type {Type}\", context.ReverseTypes[value.TypeId]); throw; }","preventionTips":["Only apply member-access swizzles to vector/scalar expressions","Extract matrix rows/columns into vectors before swizzling","Add unit tests for swizzles on every composite type"],"tags":["shader","swizzle","spirv","unsupported-operation"],"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"}