From 91c5a496d252d60d98b510b45813dabc1d1bdd4e Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 20 May 2020 18:33:54 +0000 Subject: [PATCH] [wgsl-writer] Function var decls don't mention storage class From WGSL decision in https://github.com/gpuweb/gpuweb/issues/654 Change-Id: I570475cf0d069043d70794d7b92626798963bfdc Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21363 Reviewed-by: dan sinclair --- src/writer/wgsl/generator_impl.cc | 3 +- ...rator_impl_variable_decl_statement_test.cc | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 4805d953d6..d45a1a1353 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -466,7 +466,8 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { out_ << "const"; } else { out_ << "var"; - if (var->storage_class() != ast::StorageClass::kNone) { + if (var->storage_class() != ast::StorageClass::kNone && + var->storage_class() != ast::StorageClass::kFunction) { out_ << "<" << var->storage_class() << ">"; } } diff --git a/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc b/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc index f1797df912..03fbff3db7 100644 --- a/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc @@ -42,6 +42,37 @@ TEST_F(GeneratorImplTest, Emit_VariableDeclStatement) { EXPECT_EQ(g.result(), " var a : f32;\n"); } +TEST_F(GeneratorImplTest, Emit_VariableDeclStatement_Function) { + // Variable declarations with Function storage class don't mention their + // storage class. Rely on defaulting. + // https://github.com/gpuweb/gpuweb/issues/654 + ast::type::F32Type f32; + auto var = + std::make_unique("a", ast::StorageClass::kFunction, &f32); + + ast::VariableDeclStatement stmt(std::move(var)); + + GeneratorImpl g; + g.increment_indent(); + + ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error(); + EXPECT_EQ(g.result(), " var a : f32;\n"); +} + +TEST_F(GeneratorImplTest, Emit_VariableDeclStatement_Private) { + ast::type::F32Type f32; + auto var = + std::make_unique("a", ast::StorageClass::kPrivate, &f32); + + ast::VariableDeclStatement stmt(std::move(var)); + + GeneratorImpl g; + g.increment_indent(); + + ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error(); + EXPECT_EQ(g.result(), " var a : f32;\n"); +} + } // namespace } // namespace wgsl } // namespace writer