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 <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-08-01 18:11:25 +00:00 committed by Dawn LUCI CQ
parent 19e9673e0a
commit db5d2ea4f2
2 changed files with 24 additions and 9 deletions

View File

@ -382,19 +382,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) {
} }
} }
out << "array<"; out << "array";
if (!EmitType(out, ary->type)) { if (ary->type) {
return false; out << "<";
} TINT_DEFER(out << ">");
if (!ary->IsRuntimeArray()) { if (!EmitType(out, ary->type)) {
out << ", ";
if (!EmitExpression(out, ary->count)) {
return false; return false;
} }
}
out << ">"; if (!ary->IsRuntimeArray()) {
out << ", ";
if (!EmitExpression(out, ary->count)) {
return false;
}
}
}
return true; return true;
}, },
[&](const ast::Bool*) { [&](const ast::Bool*) {

View File

@ -174,5 +174,17 @@ TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Array) {
"vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))")); "vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))"));
} }
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_ImplicitArray) {
WrapInFunction(Construct(ty.array(nullptr, nullptr), vec3<f32>(1_f, 2_f, 3_f),
vec3<f32>(4_f, 5_f, 6_f), vec3<f32>(7_f, 8_f, 9_f)));
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(),
HasSubstr("array(vec3<f32>(1.0f, 2.0f, 3.0f), "
"vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))"));
}
} // namespace } // namespace
} // namespace tint::writer::wgsl } // namespace tint::writer::wgsl