From db5d2ea4f287e8cdc22e719f2182245de1c8c375 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 1 Aug 2022 18:11:25 +0000 Subject: [PATCH] tint/writer/wgsl: Emit inferred-type arrays Bug: tint:1628 Change-Id: If0907ee7c4dc3d0216aba0282dc2c5203a3ea727 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97590 Reviewed-by: Dan Sinclair Commit-Queue: Ben Clayton --- src/tint/writer/wgsl/generator_impl.cc | 21 +++++++++++-------- .../wgsl/generator_impl_constructor_test.cc | 12 +++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 6ca708349a..f3129c0e61 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -382,19 +382,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } } - out << "array<"; - if (!EmitType(out, ary->type)) { - return false; - } + out << "array"; + if (ary->type) { + out << "<"; + TINT_DEFER(out << ">"); - if (!ary->IsRuntimeArray()) { - out << ", "; - if (!EmitExpression(out, ary->count)) { + if (!EmitType(out, ary->type)) { return false; } - } - out << ">"; + if (!ary->IsRuntimeArray()) { + out << ", "; + if (!EmitExpression(out, ary->count)) { + return false; + } + } + } return true; }, [&](const ast::Bool*) { diff --git a/src/tint/writer/wgsl/generator_impl_constructor_test.cc b/src/tint/writer/wgsl/generator_impl_constructor_test.cc index 07b10ad2ac..40bf393b28 100644 --- a/src/tint/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/tint/writer/wgsl/generator_impl_constructor_test.cc @@ -174,5 +174,17 @@ TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Array) { "vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f))")); } +TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_ImplicitArray) { + WrapInFunction(Construct(ty.array(nullptr, nullptr), vec3(1_f, 2_f, 3_f), + vec3(4_f, 5_f, 6_f), vec3(7_f, 8_f, 9_f))); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.Generate()) << gen.error(); + EXPECT_THAT(gen.result(), + HasSubstr("array(vec3(1.0f, 2.0f, 3.0f), " + "vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f))")); +} + } // namespace } // namespace tint::writer::wgsl