[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 <dneto@google.com>
This commit is contained in:
dan sinclair 2020-07-30 16:48:36 +00:00
parent a8e4e2ad5d
commit ac4a2894fe
2 changed files with 15 additions and 0 deletions

View File

@ -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;

View File

@ -55,6 +55,16 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array) {
EXPECT_EQ(g.result(), "array<bool, 4>");
}
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<bool, 4>");
}
TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) {
ast::type::BoolType b;
ast::type::ArrayType a(&b);