diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index dbe65f3c71..eefba24d02 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -307,6 +307,17 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { } first = false; + for (auto* deco : v->decorations()) { + out_ << "[["; + if (auto* builtin = deco->As()) { + out_ << "builtin(" << builtin->value() << ")"; + } + if (auto* location = deco->As()) { + out_ << "location(" << location->value() << ")"; + } + out_ << "]] "; + } + out_ << program_->Symbols().NameFor(v->symbol()) << " : "; if (!EmitType(v->type())) { diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index 7fd4574f31..dfc99cf62a 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -143,6 +143,30 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { )"); } +TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { + auto* vec4 = ty.vec4(); + auto* coord = Var("coord", vec4, ast::StorageClass::kInput, nullptr, + {create(ast::Builtin::kFragCoord)}); + auto* loc1 = Var("loc1", ty.f32(), ast::StorageClass::kInput, nullptr, + {create(1u)}); + auto* func = + Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(), + ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); + + GeneratorImpl& gen = Build(); + + gen.increment_indent(); + + ASSERT_TRUE(gen.EmitFunction(func)); + EXPECT_EQ(gen.result(), R"( [[stage(fragment)]] + fn frag_main([[builtin(frag_coord)]] coord : vec4, [[location(1)]] loc1 : f32) -> void { + } +)"); +} + // https://crbug.com/tint/297 TEST_F(WgslGeneratorImplTest, Emit_Function_Multiple_EntryPoint_With_Same_ModuleVar) {