[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 <dsinclair@google.com>
This commit is contained in:
parent
1bbc1cb2c1
commit
91c5a496d2
|
@ -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() << ">";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ast::Variable>("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<ast::Variable>("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<private> a : f32;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace writer
|
||||
|
|
Loading…
Reference in New Issue