diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 9f5afdbb5c..3c84ba9fa6 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -1438,6 +1438,12 @@ bool ParserImpl::EmitModuleScopeVariables() { if ((type_id == builtin_position_.pointer_type_id) && ((spirv_storage_class == spv::StorageClass::Input) || (spirv_storage_class == spv::StorageClass::Output))) { + // TODO(crbug.com/tint/103): Support modules that contain multiple Position built-ins. + if (builtin_position_.per_vertex_var_id != 0) { + return Fail() + << "unsupported: multiple Position built-in variables in the same module"; + } + // Skip emitting gl_PerVertex. builtin_position_.per_vertex_var_id = var.result_id(); builtin_position_.per_vertex_var_init_id = diff --git a/src/tint/reader/spirv/parser_impl_module_var_test.cc b/src/tint/reader/spirv/parser_impl_module_var_test.cc index c731fbfee4..2ae0435473 100644 --- a/src/tint/reader/spirv/parser_impl_module_var_test.cc +++ b/src/tint/reader/spirv/parser_impl_module_var_test.cc @@ -4132,6 +4132,35 @@ fn main() -> main_out { EXPECT_EQ(got, expected) << got; } +TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_MultiplePerVertexVariables) { + // This is not currently supported, so just make sure we produce a meaningful error instead of + // crashing. + const std::string assembly = R"( + OpCapability Shader + OpMemoryModel Logical Simple + OpEntryPoint Vertex %main "main" %1 + OpDecorate %struct Block + OpMemberDecorate %struct 0 BuiltIn Position + %void = OpTypeVoid + %voidfn = OpTypeFunction %void + %f32 = OpTypeFloat 32 + %vec4f = OpTypeVector %f32 4 + %struct = OpTypeStruct %vec4f + %struct_out_ptr = OpTypePointer Output %struct + %1 = OpVariable %struct_out_ptr Output + %2 = OpVariable %struct_out_ptr Output + %main = OpFunction %void None %voidfn + %entry = OpLabel + OpReturn + OpFunctionEnd +)"; + auto p = parser(test::Assemble(assembly)); + + EXPECT_FALSE(p->Parse()); + EXPECT_FALSE(p->success()); + EXPECT_EQ(p->error(), "unsupported: multiple Position built-in variables in the same module"); +} + TEST_F(SpvModuleScopeVarParserTest, Input_FlattenArray_OneLevel) { const std::string assembly = R"( OpCapability Shader