{"record":{"id":"f366457735f14e98","repo":"stride3d/stride","slug":"variable-initializer-is-not-supported-on-streams-variable","errorCode":null,"errorMessage":"Variable initializer is not supported on streams variable","messagePattern":"Variable initializer is not supported on streams variable","errorType":"validation","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Processing/Interfaces/Analysis/StreamAnalyzer.cs","lineNumber":105,"sourceCode":"\n            if (i.Op == Op.OpVariableSDSL && ((OpVariableSDSL)i) is\n                {\n                    StorageClass: StorageClass.Private or StorageClass.Workgroup or StorageClass.Uniform,\n                    ResultId: int\n                } variable\n                && context.ReverseTypes[variable.ResultType] is PointerType { BaseType: not ConstantBufferSymbol })\n            {\n                var name = nameTable.TryGetValue(variable.ResultId, out var nameId)\n                    ? nameId\n                    : $\"unnamed_{variable.ResultId}\";\n                var type = (PointerType)context.ReverseTypes[variable.ResultType];\n\n                if (variable.Flags.HasFlag(VariableFlagsMask.Stream))\n                {\n                    semanticTable.TryGetValue(variable.ResultId, out var semantic);\n\n                    if (variable.MethodOrConstantInitializer != null)\n                        throw new NotImplementedException(\"Variable initializer is not supported on streams variable\");\n\n                    streams.Add(variable.ResultId, new StreamVariableInfo(semantic, name, type, variable.ResultId) { Patch = patchVariables.Contains(variable.ResultId) });\n                }\n                else\n                {\n                    variables.Add(variable.ResultId, new VariableInfo(name, type, variable.ResultId)\n                    {\n                        VariableMethodInitializerId = variable.MethodOrConstantInitializer,\n                    });\n                }\n            }\n\n            if (i.Op == Op.OpVariableSDSL && ((OpVariableSDSL)i) is\n                {\n                    StorageClass: StorageClass.UniformConstant or StorageClass.StorageBuffer,\n                    ResultId: int\n                } resource)\n            {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Processing/Interfaces/Analysis/StreamAnalyzer.cs#L87-L123","documentation":"StreamAnalyzer.Analyze collects stream (interface) variables. A stream variable with an initializer would imply the interface variable has a default value, which SPIR-V interface variables don't support, so a VariableFlagsMask.Stream variable with MethodOrConstantInitializer set throws NotImplementedException.","triggerScenarios":"Declaring a `streams` input/output variable with an initializer (e.g. `float3 Normal = float3(0,1,0);` on a stream variable) so the SPIR-V OpVariable carries an Initializer operand while flagged Stream.","commonSituations":"SDSL shader giving a default value to an in/out interface variable; a transformation copying a constant initializer onto a stream variable.","solutions":["Remove the initializer from the stream/interface variable declaration","Initialize the value inside the stage function body instead (e.g. assign at the start of the shader)","Ensure no compiler transformation attaches initializers to stream-flagged variables"],"exampleFix":"// before (SDSL)\nstage float3 Normal = float3(0, 1, 0);\n// after\nstage float3 Normal; // assign inside the stage body instead","handlingStrategy":"validation","validationCode":"if (variable.Flags.HasFlag(VariableFlagsMask.Stream) && variable.MethodOrConstantInitializer != null)\n    throw new NotSupportedException($\"Stream variable {variable.ResultId} must not have an initializer\");","typeGuard":"bool IsPlainStreamVariable(VariableInfo v) => v.Flags.HasFlag(VariableFlagsMask.Stream) && v.MethodOrConstantInitializer is null;","tryCatchPattern":"try { analyzer.Analyze(module); } catch (NotImplementedException ex) { logger.LogError(ex, \"Stream variable with initializer\"); throw; }","preventionTips":["Declare stream/interface variables without initializers","Move default values into the shader body","Audit transformations for initializer propagation onto stream variables"],"tags":["shader","spirv","streams-analysis"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}