From ac4a2894fe1db284f3d79e1e615c83fd49aff82c Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 30 Jul 2020 16:48:36 +0000 Subject: [PATCH] [wgsl-writer] Emit array stride decoration. This CL adds array stride decorations to the WGSL writer. Bug: tint:179 Change-Id: I39d7625e1bdc876bbf9a83da7af76eb98bd09c28 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26002 Reviewed-by: David Neto --- src/writer/wgsl/generator_impl.cc | 5 +++++ src/writer/wgsl/generator_impl_type_test.cc | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 951c78d07c..dac8d3cda8 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -356,6 +356,11 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { out_ << alias->name(); } else if (type->IsArray()) { auto* ary = type->AsArray(); + + if (ary->has_array_stride()) { + out_ << "[[stride " << ary->array_stride() << "]] "; + } + out_ << "array<"; if (!EmitType(ary->type())) { return false; diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 1cbc2232dd..48c8fc312f 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -55,6 +55,16 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array) { EXPECT_EQ(g.result(), "array"); } +TEST_F(WgslGeneratorImplTest, EmitType_Array_WithStride) { + ast::type::BoolType b; + ast::type::ArrayType a(&b, 4); + a.set_array_stride(16); + + GeneratorImpl g; + ASSERT_TRUE(g.EmitType(&a)) << g.error(); + EXPECT_EQ(g.result(), "[[stride 16]] array"); +} + TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { ast::type::BoolType b; ast::type::ArrayType a(&b);