{"record":{"id":"4fbbececa162dfd1","repo":"stride3d/stride","slug":"semantic-semantic-requested-with-type-type-but-last-time","errorCode":null,"errorMessage":"Semantic {semantic} requested with type {type} but last time with {result.Type}","messagePattern":"Semantic (.+?) requested with type (.+?) but last time with (.+?)","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Processing/Interfaces/Generation/EntryPointWrapperGenerator.cs","lineNumber":67,"sourceCode":"                var variableValueType = variable.Value.Type.BaseType;\n                var methodInitializerCall = buffer.Add(new OpFunctionCall(context.GetOrRegister(variableValueType), context.Bound++, methodInitializerId, []));\n                buffer.Add(new OpStore(variable.Value.VariableId, methodInitializerCall.ResultId, null, []));\n            }\n        }\n\n        // Update entry point type (since Streams type might have been replaced)\n        entryPointFunctionType = (FunctionType)entryPoint.Type;\n\n        var builtinVariables = new Dictionary<string, (SymbolType Type, int Id)>();\n        var entryPointExtraVariables = new List<int>();\n\n        int GetOrDeclareBuiltInValue(SymbolType type, string semantic)\n        {\n            semantic = semantic.ToUpperInvariant();\n            if (builtinVariables.TryGetValue(semantic, out var result))\n            {\n                if (result.Type != type)\n                    throw new InvalidOperationException($\"Semantic {semantic} requested with type {type} but last time with {result.Type}\");\n                return result.Id;\n            }\n\n            // Declare the global builtin\n            var variableId = context.Bound++;\n            if (!BuiltinProcessor.ProcessBuiltinsDecoration(context, executionModel, variableId, StreamVariableType.Input, semantic, ref type))\n                throw new InvalidOperationException();\n            var variable = context.Add(new OpVariable(context.GetOrRegister(new PointerType(type, Specification.StorageClass.Input)), variableId, Specification.StorageClass.Input, null)).ResultId;\n            entryPointExtraVariables.Add(variable);\n            var value = buffer.Add(new OpLoad(context.GetOrRegister(type), context.Bound++, variable, null, [])).ResultId;\n            builtinVariables.Add(semantic, (type, value));\n            return value;\n        }\n\n        void FillSemanticArguments(FunctionType functionType, Span<int> arguments)\n        {\n            foreach (var i in context)\n            {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Processing/Interfaces/Generation/EntryPointWrapperGenerator.cs#L49-L85","documentation":"EntryPointWrapperGenerator caches declared builtin variables by semantic name. If the same semantic is requested a second time with a different SymbolType than the first declaration, it throws InvalidOperationException because SPIR-V requires one consistent type per builtin variable; silently reusing it with a different type would produce invalid SPIR-V.","triggerScenarios":"GenerateWrapper processes two parameters (or two stream members) carrying the same semantic string, but their resolved SymbolTypes differ, e.g. the same SV_ semantic declared as float4 in one place and float3 (or uint) in another within a single entry-point wrapper.","commonSituations":"HLSL/SDSL signatures where the same system value appears on both an entry-point parameter and a struct member with mismatched vector/component types; recent refactors that changed one declaration's type but not the other; copy-paste of parameters where one lost a swizzle-compatible type.","solutions":["Make all uses of the same semantic use one identical SymbolType (match component count and base type) in the entry-point signature.","If different types are truly needed, use distinct semantic names so each gets its own builtin variable.","Inspect GetOrDeclareBuiltInValue calls in EntryPointWrapperGenerator.cs:67 to see the conflicting types reported in the message and align the offending declaration.","Recheck upstream SDSL/HLSL struct definitions for the stream layout so types agree before wrapper generation."],"exampleFix":"// before\nvoid CSMain(uint3 id : SV_GroupID, uint3 threadId : SV_GroupThreadID, float3 extra : SV_GroupID) // SV_GroupID as float3 conflicts with uint3\n\n// after\nvoid CSMain(uint3 id : SV_GroupID, uint3 threadId : SV_GroupThreadID) // single consistent uint3 declaration per semantic","handlingStrategy":"validation","validationCode":"// Ensure every semantic is declared with exactly one type across the entry-point signature\nvar bySemantic = parameters.GroupBy(p => p.Semantic, StringComparer.OrdinalIgnoreCase);\nbool typesConsistent = bySemantic.All(g => g.Select(p => p.Type).Distinct().Count() == 1);","typeGuard":"static bool HasConsistentSemanticTypes(IEnumerable<(string Semantic, SymbolType Type)> decls) =>\n    decls.GroupBy(d => d.Semantic, StringComparer.OrdinalIgnoreCase)\n         .All(g => g.Select(d => d.Type).Distinct().Count() <= 1);","tryCatchPattern":"try\n{\n    var id = GetOrDeclareBuiltInValue(type, semantic);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"requested with type\"))\n{\n    log.Error($\"Conflicting types for semantic '{semantic}': {ex.Message}\");\n    throw new ShaderCompilationException($\"Semantic '{semantic}' declared with conflicting types in entry point\", ex);\n}","preventionTips":["Declare each system-value semantic once and reuse the variable instead of redeclaring it with different types.","Enforce in the SDSL/HLSL front-end that a semantic maps to exactly one SymbolType per entry point.","Match vector component counts exactly (e.g. float4 vs float3 mismatches are the usual culprit).","Add a signature-validation test that groups parameters by semantic and asserts type uniqueness."],"tags":["spirv","shader-compilation","type-mismatch","semantic"],"backgroundTag":"type-mismatch","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"}