[wgsl-writer] Generate decorations on function return types

Bug: tint:576
Change-Id: I60d046fb4db558daf52178600b962eaeb6d3f843
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44602
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2021-03-15 17:15:23 +00:00 committed by Commit Bot service account
parent feecbe0d83
commit cc193de025
2 changed files with 32 additions and 0 deletions

View File

@ -329,6 +329,13 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
out_ << ") -> ";
if (!func->return_type_decorations().empty()) {
if (!EmitDecorations(func->return_type_decorations())) {
return false;
}
out_ << " ";
}
if (!EmitType(func->return_type())) {
return false;
}

View File

@ -167,6 +167,31 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
)");
}
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_ReturnValue) {
auto* func =
Func("frag_main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(Expr(1.f)),
},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
},
ast::DecorationList{
create<ast::LocationDecoration>(1u),
});
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitFunction(func));
EXPECT_EQ(gen.result(), R"( [[stage(fragment)]]
fn frag_main() -> [[location(1)]] f32 {
return 1.0;
}
)");
}
// https://crbug.com/tint/297
TEST_F(WgslGeneratorImplTest,
Emit_Function_Multiple_EntryPoint_With_Same_ModuleVar) {