Remove Variable::name().
This CL removes the name getter from the Variable class. All usages are updated to use the symbol. Change-Id: I3e4d86d2124d39023cad6113c62230c1757ece71 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36780 Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
197a1b943d
commit
396b02342f
|
@ -69,7 +69,7 @@ PipelineStage Function::pipeline_stage() const {
|
||||||
|
|
||||||
void Function::add_referenced_module_variable(Variable* var) {
|
void Function::add_referenced_module_variable(Variable* var) {
|
||||||
for (const auto* v : referenced_module_vars_) {
|
for (const auto* v : referenced_module_vars_) {
|
||||||
if (v->name() == var->name()) {
|
if (v->symbol() == var->symbol()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ void Function::add_referenced_module_variable(Variable* var) {
|
||||||
|
|
||||||
void Function::add_local_referenced_module_variable(Variable* var) {
|
void Function::add_local_referenced_module_variable(Variable* var) {
|
||||||
for (const auto* v : local_referenced_module_vars_) {
|
for (const auto* v : local_referenced_module_vars_) {
|
||||||
if (v->name() == var->name()) {
|
if (v->symbol() == var->symbol()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ uint32_t Variable::constant_id() const {
|
||||||
|
|
||||||
Variable* Variable::Clone(CloneContext* ctx) const {
|
Variable* Variable::Clone(CloneContext* ctx) const {
|
||||||
return ctx->mod->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_),
|
return ctx->mod->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_),
|
||||||
name(), storage_class(), ctx->Clone(type()),
|
name_, storage_class(), ctx->Clone(type()),
|
||||||
is_const_, ctx->Clone(constructor()),
|
is_const_, ctx->Clone(constructor()),
|
||||||
ctx->Clone(decorations_));
|
ctx->Clone(decorations_));
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,6 @@ class Variable : public Castable<Variable, Node> {
|
||||||
|
|
||||||
/// @returns the variable symbol
|
/// @returns the variable symbol
|
||||||
const Symbol& symbol() const { return symbol_; }
|
const Symbol& symbol() const { return symbol_; }
|
||||||
/// @returns the variable name
|
|
||||||
const std::string& name() const { return name_; }
|
|
||||||
|
|
||||||
/// @returns the variable's type.
|
/// @returns the variable's type.
|
||||||
type::Type* type() const { return type_; }
|
type::Type* type() const { return type_; }
|
||||||
|
|
|
@ -30,7 +30,6 @@ TEST_F(VariableTest, Creation) {
|
||||||
auto* v = Var("my_var", StorageClass::kFunction, ty.i32);
|
auto* v = Var("my_var", StorageClass::kFunction, ty.i32);
|
||||||
|
|
||||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||||
EXPECT_EQ(v->name(), "my_var");
|
|
||||||
EXPECT_EQ(v->storage_class(), StorageClass::kFunction);
|
EXPECT_EQ(v->storage_class(), StorageClass::kFunction);
|
||||||
EXPECT_EQ(v->type(), ty.i32);
|
EXPECT_EQ(v->type(), ty.i32);
|
||||||
EXPECT_EQ(v->source().range.begin.line, 0u);
|
EXPECT_EQ(v->source().range.begin.line, 0u);
|
||||||
|
@ -45,7 +44,6 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||||
"i", StorageClass::kPrivate, ty.f32, nullptr, VariableDecorationList{});
|
"i", StorageClass::kPrivate, ty.f32, nullptr, VariableDecorationList{});
|
||||||
|
|
||||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||||
EXPECT_EQ(v->name(), "i");
|
|
||||||
EXPECT_EQ(v->storage_class(), StorageClass::kPrivate);
|
EXPECT_EQ(v->storage_class(), StorageClass::kPrivate);
|
||||||
EXPECT_EQ(v->type(), ty.f32);
|
EXPECT_EQ(v->type(), ty.f32);
|
||||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||||
|
@ -61,7 +59,6 @@ TEST_F(VariableTest, CreationEmpty) {
|
||||||
VariableDecorationList{});
|
VariableDecorationList{});
|
||||||
|
|
||||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||||
EXPECT_EQ(v->name(), "a_var");
|
|
||||||
EXPECT_EQ(v->storage_class(), StorageClass::kWorkgroup);
|
EXPECT_EQ(v->storage_class(), StorageClass::kWorkgroup);
|
||||||
EXPECT_EQ(v->type(), ty.i32);
|
EXPECT_EQ(v->type(), ty.i32);
|
||||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||||
|
|
|
@ -64,10 +64,11 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
||||||
entry_point.workgroup_size_z) = func->workgroup_size();
|
entry_point.workgroup_size_z) = func->workgroup_size();
|
||||||
|
|
||||||
for (auto* var : func->referenced_module_variables()) {
|
for (auto* var : func->referenced_module_variables()) {
|
||||||
|
auto name = namer_->NameFor(var->symbol());
|
||||||
if (var->storage_class() == ast::StorageClass::kInput) {
|
if (var->storage_class() == ast::StorageClass::kInput) {
|
||||||
entry_point.input_variables.push_back(var->name());
|
entry_point.input_variables.push_back(name);
|
||||||
} else {
|
} else {
|
||||||
entry_point.output_variables.push_back(var->name());
|
entry_point.output_variables.push_back(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.push_back(std::move(entry_point));
|
result.push_back(std::move(entry_point));
|
||||||
|
|
|
@ -42,8 +42,8 @@ TEST_F(ParserImplTest, FunctionDecl) {
|
||||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||||
|
|
||||||
ASSERT_EQ(f->params().size(), 2u);
|
ASSERT_EQ(f->params().size(), 2u);
|
||||||
EXPECT_EQ(f->params()[0]->name(), "a");
|
EXPECT_EQ(f->params()[0]->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(f->params()[1]->name(), "b");
|
EXPECT_EQ(f->params()[1]->symbol(), p->get_module().RegisterSymbol("b"));
|
||||||
|
|
||||||
ASSERT_NE(f->return_type(), nullptr);
|
ASSERT_NE(f->return_type(), nullptr);
|
||||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||||
|
|
|
@ -33,8 +33,8 @@ TEST_F(ParserImplTest, FunctionHeader) {
|
||||||
|
|
||||||
EXPECT_EQ(f->name, "main");
|
EXPECT_EQ(f->name, "main");
|
||||||
ASSERT_EQ(f->params.size(), 2u);
|
ASSERT_EQ(f->params.size(), 2u);
|
||||||
EXPECT_EQ(f->params[0]->name(), "a");
|
EXPECT_EQ(f->params[0]->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(f->params[1]->name(), "b");
|
EXPECT_EQ(f->params[1]->symbol(), p->get_module().RegisterSymbol("b"));
|
||||||
EXPECT_TRUE(f->return_type->Is<ast::type::Void>());
|
EXPECT_TRUE(f->return_type->Is<ast::type::Void>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(e->is_const());
|
EXPECT_TRUE(e->is_const());
|
||||||
EXPECT_EQ(e->name(), "a");
|
EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
ASSERT_NE(e->type(), nullptr);
|
ASSERT_NE(e->type(), nullptr);
|
||||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) {
|
||||||
ASSERT_EQ(m.global_variables().size(), 1u);
|
ASSERT_EQ(m.global_variables().size(), 1u);
|
||||||
|
|
||||||
auto* v = m.global_variables()[0];
|
auto* v = m.global_variables()[0];
|
||||||
EXPECT_EQ(v->name(), "a");
|
EXPECT_EQ(v->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Invalid) {
|
TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Invalid) {
|
||||||
|
@ -64,7 +64,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalConstant) {
|
||||||
ASSERT_EQ(m.global_variables().size(), 1u);
|
ASSERT_EQ(m.global_variables().size(), 1u);
|
||||||
|
|
||||||
auto* v = m.global_variables()[0];
|
auto* v = m.global_variables()[0];
|
||||||
EXPECT_EQ(v->name(), "a");
|
EXPECT_EQ(v->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, GlobalDecl_GlobalConstant_Invalid) {
|
TEST_F(ParserImplTest, GlobalDecl_GlobalConstant_Invalid) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(e->name(), "a");
|
EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(e->name(), "a");
|
EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(e->name(), "a");
|
EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
ASSERT_NE(e->type(), nullptr);
|
ASSERT_NE(e->type(), nullptr);
|
||||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||||
|
@ -114,7 +114,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(e->name(), "a");
|
EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
ASSERT_NE(e->type(), nullptr);
|
ASSERT_NE(e->type(), nullptr);
|
||||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
EXPECT_EQ(e.value.size(), 1u);
|
EXPECT_EQ(e.value.size(), 1u);
|
||||||
|
|
||||||
EXPECT_EQ(e.value[0]->name(), "a");
|
EXPECT_EQ(e.value[0]->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(e.value[0]->type(), i32);
|
EXPECT_EQ(e.value[0]->type(), i32);
|
||||||
EXPECT_TRUE(e.value[0]->is_const());
|
EXPECT_TRUE(e.value[0]->is_const());
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
EXPECT_EQ(e.value.size(), 3u);
|
EXPECT_EQ(e.value.size(), 3u);
|
||||||
|
|
||||||
EXPECT_EQ(e.value[0]->name(), "a");
|
EXPECT_EQ(e.value[0]->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
EXPECT_EQ(e.value[0]->type(), i32);
|
EXPECT_EQ(e.value[0]->type(), i32);
|
||||||
EXPECT_TRUE(e.value[0]->is_const());
|
EXPECT_TRUE(e.value[0]->is_const());
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
|
||||||
ASSERT_EQ(e.value[0]->source().range.end.line, 1u);
|
ASSERT_EQ(e.value[0]->source().range.end.line, 1u);
|
||||||
ASSERT_EQ(e.value[0]->source().range.end.column, 2u);
|
ASSERT_EQ(e.value[0]->source().range.end.column, 2u);
|
||||||
|
|
||||||
EXPECT_EQ(e.value[1]->name(), "b");
|
EXPECT_EQ(e.value[1]->symbol(), p->get_module().RegisterSymbol("b"));
|
||||||
EXPECT_EQ(e.value[1]->type(), f32);
|
EXPECT_EQ(e.value[1]->type(), f32);
|
||||||
EXPECT_TRUE(e.value[1]->is_const());
|
EXPECT_TRUE(e.value[1]->is_const());
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
|
||||||
ASSERT_EQ(e.value[1]->source().range.end.line, 1u);
|
ASSERT_EQ(e.value[1]->source().range.end.line, 1u);
|
||||||
ASSERT_EQ(e.value[1]->source().range.end.column, 11u);
|
ASSERT_EQ(e.value[1]->source().range.end.column, 11u);
|
||||||
|
|
||||||
EXPECT_EQ(e.value[2]->name(), "c");
|
EXPECT_EQ(e.value[2]->symbol(), p->get_module().RegisterSymbol("c"));
|
||||||
EXPECT_EQ(e.value[2]->type(), vec2);
|
EXPECT_EQ(e.value[2]->type(), vec2);
|
||||||
EXPECT_TRUE(e.value[2]->is_const());
|
EXPECT_TRUE(e.value[2]->is_const());
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
|
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
|
||||||
ASSERT_NE(e->variable(), nullptr);
|
ASSERT_NE(e->variable(), nullptr);
|
||||||
EXPECT_EQ(e->variable()->name(), "a");
|
EXPECT_EQ(e->variable()->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
|
|
||||||
ASSERT_EQ(e->source().range.begin.line, 1u);
|
ASSERT_EQ(e->source().range.begin.line, 1u);
|
||||||
ASSERT_EQ(e->source().range.begin.column, 5u);
|
ASSERT_EQ(e->source().range.begin.column, 5u);
|
||||||
|
@ -51,7 +51,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
|
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
|
||||||
ASSERT_NE(e->variable(), nullptr);
|
ASSERT_NE(e->variable(), nullptr);
|
||||||
EXPECT_EQ(e->variable()->name(), "a");
|
EXPECT_EQ(e->variable()->symbol(), p->get_module().RegisterSymbol("a"));
|
||||||
|
|
||||||
ASSERT_EQ(e->source().range.begin.line, 1u);
|
ASSERT_EQ(e->source().range.begin.line, 1u);
|
||||||
ASSERT_EQ(e->source().range.begin.column, 5u);
|
ASSERT_EQ(e->source().range.begin.column, 5u);
|
||||||
|
|
|
@ -86,7 +86,7 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||||
// First do a quick check to see if the transform has already been applied.
|
// First do a quick check to see if the transform has already been applied.
|
||||||
for (ast::Variable* var : in->global_variables()) {
|
for (ast::Variable* var : in->global_variables()) {
|
||||||
if (auto* dec_var = var->As<ast::Variable>()) {
|
if (auto* dec_var = var->As<ast::Variable>()) {
|
||||||
if (dec_var->name() == kBufferName) {
|
if (dec_var->symbol() == in->RegisterSymbol(kBufferName)) {
|
||||||
diag::Diagnostic err;
|
diag::Diagnostic err;
|
||||||
err.message = "First index offset transform has already been applied.";
|
err.message = "First index offset transform has already been applied.";
|
||||||
err.severity = diag::Severity::Error;
|
err.severity = diag::Severity::Error;
|
||||||
|
@ -110,8 +110,8 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string vertex_index_name;
|
Symbol vertex_index_sym;
|
||||||
std::string instance_index_name;
|
Symbol instance_index_sym;
|
||||||
|
|
||||||
// Lazilly construct the UniformBuffer on first call to
|
// Lazilly construct the UniformBuffer on first call to
|
||||||
// maybe_create_buffer_var()
|
// maybe_create_buffer_var()
|
||||||
|
@ -134,15 +134,17 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||||
if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
|
if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
|
||||||
ast::Builtin blt_type = blt_dec->value();
|
ast::Builtin blt_type = blt_dec->value();
|
||||||
if (blt_type == ast::Builtin::kVertexIdx) {
|
if (blt_type == ast::Builtin::kVertexIdx) {
|
||||||
vertex_index_name = var->name();
|
vertex_index_sym = var->symbol();
|
||||||
has_vertex_index_ = true;
|
has_vertex_index_ = true;
|
||||||
return clone_variable_with_new_name(
|
return clone_variable_with_new_name(
|
||||||
ctx, var, kIndexOffsetPrefix + var->name());
|
ctx, var,
|
||||||
|
kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
|
||||||
} else if (blt_type == ast::Builtin::kInstanceIdx) {
|
} else if (blt_type == ast::Builtin::kInstanceIdx) {
|
||||||
instance_index_name = var->name();
|
instance_index_sym = var->symbol();
|
||||||
has_instance_index_ = true;
|
has_instance_index_ = true;
|
||||||
return clone_variable_with_new_name(
|
return clone_variable_with_new_name(
|
||||||
ctx, var, kIndexOffsetPrefix + var->name());
|
ctx, var,
|
||||||
|
kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,11 +163,12 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||||
func->local_referenced_builtin_variables()) {
|
func->local_referenced_builtin_variables()) {
|
||||||
if (data.second->value() == ast::Builtin::kVertexIdx) {
|
if (data.second->value() == ast::Builtin::kVertexIdx) {
|
||||||
statements.emplace_back(CreateFirstIndexOffset(
|
statements.emplace_back(CreateFirstIndexOffset(
|
||||||
vertex_index_name, kFirstVertexName, buffer_var, ctx->mod));
|
in->SymbolToName(vertex_index_sym), kFirstVertexName,
|
||||||
|
buffer_var, ctx->mod));
|
||||||
} else if (data.second->value() == ast::Builtin::kInstanceIdx) {
|
} else if (data.second->value() == ast::Builtin::kInstanceIdx) {
|
||||||
statements.emplace_back(CreateFirstIndexOffset(
|
statements.emplace_back(CreateFirstIndexOffset(
|
||||||
instance_index_name, kFirstInstanceName, buffer_var,
|
in->SymbolToName(instance_index_sym), kFirstInstanceName,
|
||||||
ctx->mod));
|
buffer_var, ctx->mod));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CloneWithStatementsAtStart(ctx, func, statements);
|
return CloneWithStatementsAtStart(ctx, func, statements);
|
||||||
|
@ -252,12 +255,13 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
|
||||||
ast::Variable* buffer_var,
|
ast::Variable* buffer_var,
|
||||||
ast::Module* mod) {
|
ast::Module* mod) {
|
||||||
auto* buffer = mod->create<ast::IdentifierExpression>(
|
auto* buffer = mod->create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol(buffer_var->name()), buffer_var->name());
|
Source{}, buffer_var->symbol(), mod->SymbolToName(buffer_var->symbol()));
|
||||||
|
|
||||||
|
auto lhs_name = kIndexOffsetPrefix + original_name;
|
||||||
auto* constructor = mod->create<ast::BinaryExpression>(
|
auto* constructor = mod->create<ast::BinaryExpression>(
|
||||||
Source{}, ast::BinaryOp::kAdd,
|
Source{}, ast::BinaryOp::kAdd,
|
||||||
mod->create<ast::IdentifierExpression>(
|
mod->create<ast::IdentifierExpression>(
|
||||||
Source{}, mod->RegisterSymbol(kIndexOffsetPrefix + original_name),
|
Source{}, mod->RegisterSymbol(lhs_name), lhs_name),
|
||||||
kIndexOffsetPrefix + original_name),
|
|
||||||
mod->create<ast::MemberAccessorExpression>(
|
mod->create<ast::MemberAccessorExpression>(
|
||||||
Source{}, buffer,
|
Source{}, buffer,
|
||||||
mod->create<ast::IdentifierExpression>(
|
mod->create<ast::IdentifierExpression>(
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
#include "src/symbol.h"
|
||||||
#include "src/transform/transform.h"
|
#include "src/transform/transform.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
|
|
@ -155,7 +155,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
||||||
for (auto* d : v->decorations()) {
|
for (auto* d : v->decorations()) {
|
||||||
if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
|
if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
|
||||||
if (builtin->value() == ast::Builtin::kVertexIdx) {
|
if (builtin->value() == ast::Builtin::kVertexIdx) {
|
||||||
vertex_index_name = v->name();
|
vertex_index_name = in->SymbolToName(v->symbol());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
||||||
for (auto* d : v->decorations()) {
|
for (auto* d : v->decorations()) {
|
||||||
if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
|
if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
|
||||||
if (builtin->value() == ast::Builtin::kInstanceIdx) {
|
if (builtin->value() == ast::Builtin::kInstanceIdx) {
|
||||||
instance_index_name = v->name();
|
instance_index_name = in->SymbolToName(v->symbol());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
|
||||||
v = out->create<ast::Variable>(
|
v = out->create<ast::Variable>(
|
||||||
Source{}, // source
|
Source{}, // source
|
||||||
v->symbol(), // symbol
|
v->symbol(), // symbol
|
||||||
v->name(), // name
|
out->SymbolToName(v->symbol()), // name
|
||||||
ast::StorageClass::kPrivate, // storage_class
|
ast::StorageClass::kPrivate, // storage_class
|
||||||
v->type(), // type
|
v->type(), // type
|
||||||
false, // is_const
|
false, // is_const
|
||||||
|
@ -358,10 +358,11 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
|
||||||
Source{}, CreatePullingPositionIdent(), pos_value);
|
Source{}, CreatePullingPositionIdent(), pos_value);
|
||||||
stmts.emplace_back(set_pos_expr);
|
stmts.emplace_back(set_pos_expr);
|
||||||
|
|
||||||
|
auto ident_name = in->SymbolToName(v->symbol());
|
||||||
stmts.emplace_back(out->create<ast::AssignmentStatement>(
|
stmts.emplace_back(out->create<ast::AssignmentStatement>(
|
||||||
Source{},
|
Source{},
|
||||||
out->create<ast::IdentifierExpression>(
|
out->create<ast::IdentifierExpression>(
|
||||||
Source{}, out->RegisterSymbol(v->name()), v->name()),
|
Source{}, out->RegisterSymbol(ident_name), ident_name),
|
||||||
AccessByFormat(i, attribute_desc.format)));
|
AccessByFormat(i, attribute_desc.format)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ bool GeneratorImpl::Generate(std::ostream& out) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_set<std::string> emitted_globals;
|
std::unordered_set<uint32_t> emitted_globals;
|
||||||
// Make sure all entry point data is emitted before the entry point functions
|
// Make sure all entry point data is emitted before the entry point functions
|
||||||
for (auto* func : module_->functions()) {
|
for (auto* func : module_->functions()) {
|
||||||
if (!func->IsEntryPoint()) {
|
if (!func->IsEntryPoint()) {
|
||||||
|
@ -1285,7 +1285,7 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out,
|
||||||
}
|
}
|
||||||
// Array name is output as part of the type
|
// Array name is output as part of the type
|
||||||
if (!v->type()->Is<ast::type::Array>()) {
|
if (!v->type()->Is<ast::type::Array>()) {
|
||||||
out << " " << v->name();
|
out << " " << namer_->NameFor(v->symbol());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1305,7 +1305,7 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out,
|
||||||
bool GeneratorImpl::EmitEntryPointData(
|
bool GeneratorImpl::EmitEntryPointData(
|
||||||
std::ostream& out,
|
std::ostream& out,
|
||||||
ast::Function* func,
|
ast::Function* func,
|
||||||
std::unordered_set<std::string>& emitted_globals) {
|
std::unordered_set<uint32_t>& emitted_globals) {
|
||||||
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> in_variables;
|
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> in_variables;
|
||||||
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> outvariables;
|
std::vector<std::pair<ast::Variable*, ast::VariableDecoration*>> outvariables;
|
||||||
for (auto data : func->referenced_location_variables()) {
|
for (auto data : func->referenced_location_variables()) {
|
||||||
|
@ -1338,22 +1338,24 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
// set. https://bugs.chromium.org/p/tint/issues/detail?id=104
|
// set. https://bugs.chromium.org/p/tint/issues/detail?id=104
|
||||||
auto* binding = data.second.binding;
|
auto* binding = data.second.binding;
|
||||||
if (binding == nullptr) {
|
if (binding == nullptr) {
|
||||||
error_ = "unable to find binding information for uniform: " + var->name();
|
error_ = "unable to find binding information for uniform: " +
|
||||||
|
module_->SymbolToName(var->symbol());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// auto* set = data.second.set;
|
// auto* set = data.second.set;
|
||||||
|
|
||||||
// If the global has already been emitted we skip it, it's been emitted by
|
// If the global has already been emitted we skip it, it's been emitted by
|
||||||
// a previous entry point.
|
// a previous entry point.
|
||||||
if (emitted_globals.count(var->name()) != 0) {
|
if (emitted_globals.count(var->symbol().value()) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
emitted_globals.insert(var->name());
|
emitted_globals.insert(var->symbol().value());
|
||||||
|
|
||||||
auto* type = var->type()->UnwrapIfNeeded();
|
auto* type = var->type()->UnwrapIfNeeded();
|
||||||
if (auto* strct = type->As<ast::type::Struct>()) {
|
if (auto* strct = type->As<ast::type::Struct>()) {
|
||||||
out << "ConstantBuffer<" << strct->name() << "> " << var->name()
|
out << "ConstantBuffer<" << strct->name() << "> "
|
||||||
<< " : register(b" << binding->value() << ");" << std::endl;
|
<< namer_->NameFor(var->symbol()) << " : register(b"
|
||||||
|
<< binding->value() << ");" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
// TODO(dsinclair): There is outstanding spec work to require all uniform
|
// TODO(dsinclair): There is outstanding spec work to require all uniform
|
||||||
// buffers to be [[block]] decorated, which means structs. This is
|
// buffers to be [[block]] decorated, which means structs. This is
|
||||||
|
@ -1361,7 +1363,7 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
// is not a block.
|
// is not a block.
|
||||||
// Relevant: https://github.com/gpuweb/gpuweb/issues/1004
|
// Relevant: https://github.com/gpuweb/gpuweb/issues/1004
|
||||||
// https://github.com/gpuweb/gpuweb/issues/1008
|
// https://github.com/gpuweb/gpuweb/issues/1008
|
||||||
auto name = "cbuffer_" + var->name();
|
auto name = "cbuffer_" + namer_->NameFor(var->symbol());
|
||||||
out << "cbuffer " << name << " : register(b" << binding->value() << ") {"
|
out << "cbuffer " << name << " : register(b" << binding->value() << ") {"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
@ -1370,7 +1372,7 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
if (!EmitType(out, type, Symbol())) {
|
if (!EmitType(out, type, Symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out << " " << var->name() << ";" << std::endl;
|
out << " " << namer_->NameFor(var->symbol()) << ";" << std::endl;
|
||||||
decrement_indent();
|
decrement_indent();
|
||||||
out << "};" << std::endl;
|
out << "};" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -1388,10 +1390,10 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
|
|
||||||
// If the global has already been emitted we skip it, it's been emitted by
|
// If the global has already been emitted we skip it, it's been emitted by
|
||||||
// a previous entry point.
|
// a previous entry point.
|
||||||
if (emitted_globals.count(var->name()) != 0) {
|
if (emitted_globals.count(var->symbol().value()) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
emitted_globals.insert(var->name());
|
emitted_globals.insert(var->symbol().value());
|
||||||
|
|
||||||
auto* ac = var->type()->As<ast::type::AccessControl>();
|
auto* ac = var->type()->As<ast::type::AccessControl>();
|
||||||
if (ac == nullptr) {
|
if (ac == nullptr) {
|
||||||
|
@ -1402,8 +1404,8 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
if (ac->IsReadWrite()) {
|
if (ac->IsReadWrite()) {
|
||||||
out << "RW";
|
out << "RW";
|
||||||
}
|
}
|
||||||
out << "ByteAddressBuffer " << var->name() << " : register(u"
|
out << "ByteAddressBuffer " << namer_->NameFor(var->symbol())
|
||||||
<< binding->value() << ");" << std::endl;
|
<< " : register(u" << binding->value() << ");" << std::endl;
|
||||||
emitted_storagebuffer = true;
|
emitted_storagebuffer = true;
|
||||||
}
|
}
|
||||||
if (emitted_storagebuffer) {
|
if (emitted_storagebuffer) {
|
||||||
|
@ -1430,7 +1432,7 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
out << " " << var->name() << " : ";
|
out << " " << namer_->NameFor(var->symbol()) << " : ";
|
||||||
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
if (func->pipeline_stage() == ast::PipelineStage::kCompute) {
|
if (func->pipeline_stage() == ast::PipelineStage::kCompute) {
|
||||||
error_ = "invalid location variable for pipeline stage";
|
error_ = "invalid location variable for pipeline stage";
|
||||||
|
@ -1475,7 +1477,7 @@ bool GeneratorImpl::EmitEntryPointData(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
out << " " << var->name() << " : ";
|
out << " " << namer_->NameFor(var->symbol()) << " : ";
|
||||||
|
|
||||||
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
auto loc = location->value();
|
auto loc = location->value();
|
||||||
|
@ -1697,7 +1699,7 @@ bool GeneratorImpl::EmitLoop(std::ostream& out, ast::LoopStatement* stmt) {
|
||||||
}
|
}
|
||||||
out << pre.str();
|
out << pre.str();
|
||||||
|
|
||||||
out << var->name() << " = ";
|
out << namer_->NameFor(var->symbol()) << " = ";
|
||||||
if (var->constructor() != nullptr) {
|
if (var->constructor() != nullptr) {
|
||||||
out << constructor_out.str();
|
out << constructor_out.str();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2289,7 +2291,7 @@ bool GeneratorImpl::EmitVariable(std::ostream& out,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!var->type()->Is<ast::type::Array>()) {
|
if (!var->type()->Is<ast::type::Array>()) {
|
||||||
out << " " << var->name();
|
out << " " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
out << constructor_out.str() << ";" << std::endl;
|
out << constructor_out.str() << ";" << std::endl;
|
||||||
|
|
||||||
|
@ -2337,8 +2339,8 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out,
|
||||||
if (!EmitType(out, var->type(), var->symbol())) {
|
if (!EmitType(out, var->type(), var->symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out << " " << var->name() << " = WGSL_SPEC_CONSTANT_" << const_id << ";"
|
out << " " << namer_->NameFor(var->symbol()) << " = WGSL_SPEC_CONSTANT_"
|
||||||
<< std::endl;
|
<< const_id << ";" << std::endl;
|
||||||
out << "#undef WGSL_SPEC_CONSTANT_" << const_id << std::endl;
|
out << "#undef WGSL_SPEC_CONSTANT_" << const_id << std::endl;
|
||||||
} else {
|
} else {
|
||||||
out << "static const ";
|
out << "static const ";
|
||||||
|
@ -2346,7 +2348,7 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!var->type()->Is<ast::type::Array>()) {
|
if (!var->type()->Is<ast::type::Array>()) {
|
||||||
out << " " << var->name();
|
out << " " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var->constructor() != nullptr) {
|
if (var->constructor() != nullptr) {
|
||||||
|
|
|
@ -224,7 +224,7 @@ class GeneratorImpl {
|
||||||
/// @returns true if the entry point data was emitted
|
/// @returns true if the entry point data was emitted
|
||||||
bool EmitEntryPointData(std::ostream& out,
|
bool EmitEntryPointData(std::ostream& out,
|
||||||
ast::Function* func,
|
ast::Function* func,
|
||||||
std::unordered_set<std::string>& emitted_globals);
|
std::unordered_set<uint32_t>& emitted_globals);
|
||||||
/// Handles emitting the entry point function
|
/// Handles emitting the entry point function
|
||||||
/// @param out the output stream
|
/// @param out the output stream
|
||||||
/// @param func the entry point
|
/// @param func the entry point
|
||||||
|
|
|
@ -72,7 +72,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
@ -122,7 +122,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
@ -172,7 +172,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
@ -222,7 +222,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
@ -269,7 +269,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
@ -311,7 +311,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
@ -361,7 +361,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
|
|
||||||
mod->AddFunction(func);
|
mod->AddFunction(func);
|
||||||
|
|
||||||
std::unordered_set<std::string> globals;
|
std::unordered_set<uint32_t> globals;
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
|
||||||
|
|
|
@ -607,7 +607,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
out_ << ", ";
|
out_ << ", ";
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
out_ << var->name();
|
out_ << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& data : func->referenced_uniform_variables()) {
|
for (const auto& data : func->referenced_uniform_variables()) {
|
||||||
|
@ -616,7 +616,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
out_ << ", ";
|
out_ << ", ";
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
out_ << var->name();
|
out_ << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& data : func->referenced_storagebuffer_variables()) {
|
for (const auto& data : func->referenced_storagebuffer_variables()) {
|
||||||
|
@ -625,7 +625,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
out_ << ", ";
|
out_ << ", ";
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
out_ << var->name();
|
out_ << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& params = expr->params();
|
const auto& params = expr->params();
|
||||||
|
@ -1035,7 +1035,7 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << " " << var->name() << " [[";
|
out_ << " " << namer_->NameFor(var->symbol()) << " [[";
|
||||||
if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
|
if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
|
||||||
out_ << "attribute(" << loc << ")";
|
out_ << "attribute(" << loc << ")";
|
||||||
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
|
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
|
||||||
|
@ -1072,7 +1072,7 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << " " << var->name() << " [[";
|
out_ << " " << namer_->NameFor(var->symbol()) << " [[";
|
||||||
|
|
||||||
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
auto loc = location->value();
|
auto loc = location->value();
|
||||||
|
@ -1275,7 +1275,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
|
||||||
if (!EmitType(var->type(), Symbol())) {
|
if (!EmitType(var->type(), Symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << "& " << var->name();
|
out_ << "& " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& data : func->referenced_uniform_variables()) {
|
for (const auto& data : func->referenced_uniform_variables()) {
|
||||||
|
@ -1290,7 +1290,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
|
||||||
if (!EmitType(var->type(), Symbol())) {
|
if (!EmitType(var->type(), Symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << "& " << var->name();
|
out_ << "& " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& data : func->referenced_storagebuffer_variables()) {
|
for (const auto& data : func->referenced_storagebuffer_variables()) {
|
||||||
|
@ -1313,7 +1313,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
|
||||||
if (!EmitType(ac->type(), Symbol())) {
|
if (!EmitType(ac->type(), Symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << "& " << var->name();
|
out_ << "& " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* v : func->params()) {
|
for (auto* v : func->params()) {
|
||||||
|
@ -1327,7 +1327,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
|
||||||
}
|
}
|
||||||
// Array name is output as part of the type
|
// Array name is output as part of the type
|
||||||
if (!v->type()->Is<ast::type::Array>()) {
|
if (!v->type()->Is<ast::type::Array>()) {
|
||||||
out_ << " " << v->name();
|
out_ << " " << namer_->NameFor(v->symbol());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1419,7 +1419,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
|
||||||
error_ = "unknown builtin";
|
error_ = "unknown builtin";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << " " << var->name() << " [[" << attr << "]]";
|
out_ << " " << namer_->NameFor(var->symbol()) << " [[" << attr << "]]";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto data : func->referenced_uniform_variables()) {
|
for (auto data : func->referenced_uniform_variables()) {
|
||||||
|
@ -1434,7 +1434,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
|
||||||
// set. https://bugs.chromium.org/p/tint/issues/detail?id=104
|
// set. https://bugs.chromium.org/p/tint/issues/detail?id=104
|
||||||
auto* binding = data.second.binding;
|
auto* binding = data.second.binding;
|
||||||
if (binding == nullptr) {
|
if (binding == nullptr) {
|
||||||
error_ = "unable to find binding information for uniform: " + var->name();
|
error_ = "unable to find binding information for uniform: " +
|
||||||
|
module_->SymbolToName(var->symbol());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// auto* set = data.second.set;
|
// auto* set = data.second.set;
|
||||||
|
@ -1445,7 +1446,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
|
||||||
if (!EmitType(var->type(), Symbol())) {
|
if (!EmitType(var->type(), Symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << "& " << var->name() << " [[buffer(" << binding->value() << ")]]";
|
out_ << "& " << namer_->NameFor(var->symbol()) << " [[buffer("
|
||||||
|
<< binding->value() << ")]]";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto data : func->referenced_storagebuffer_variables()) {
|
for (auto data : func->referenced_storagebuffer_variables()) {
|
||||||
|
@ -1474,7 +1476,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
|
||||||
if (!EmitType(ac->type(), Symbol())) {
|
if (!EmitType(ac->type(), Symbol())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << "& " << var->name() << " [[buffer(" << binding->value() << ")]]";
|
out_ << "& " << namer_->NameFor(var->symbol()) << " [[buffer("
|
||||||
|
<< binding->value() << ")]]";
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << ") {" << std::endl;
|
out_ << ") {" << std::endl;
|
||||||
|
@ -1589,7 +1592,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) {
|
||||||
make_indent();
|
make_indent();
|
||||||
|
|
||||||
auto* var = decl->variable();
|
auto* var = decl->variable();
|
||||||
out_ << var->name() << " = ";
|
out_ << namer_->NameFor(var->symbol()) << " = ";
|
||||||
if (var->constructor() != nullptr) {
|
if (var->constructor() != nullptr) {
|
||||||
if (!EmitExpression(var->constructor())) {
|
if (!EmitExpression(var->constructor())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2020,7 +2023,7 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var, bool skip_constructor) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!var->type()->Is<ast::type::Array>()) {
|
if (!var->type()->Is<ast::type::Array>()) {
|
||||||
out_ << " " << var->name();
|
out_ << " " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip_constructor) {
|
if (!skip_constructor) {
|
||||||
|
@ -2062,7 +2065,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!var->type()->Is<ast::type::Array>()) {
|
if (!var->type()->Is<ast::type::Array>()) {
|
||||||
out_ << " " << var->name();
|
out_ << " " << namer_->NameFor(var->symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var->HasConstantIdDecoration()) {
|
if (var->HasConstantIdDecoration()) {
|
||||||
|
|
|
@ -21,17 +21,18 @@ namespace writer {
|
||||||
namespace wgsl {
|
namespace wgsl {
|
||||||
|
|
||||||
Generator::Generator(ast::Module module)
|
Generator::Generator(ast::Module module)
|
||||||
: Text(std::move(module)), impl_(std::make_unique<GeneratorImpl>()) {}
|
: Text(std::move(module)),
|
||||||
|
impl_(std::make_unique<GeneratorImpl>(&module_)) {}
|
||||||
|
|
||||||
Generator::~Generator() = default;
|
Generator::~Generator() = default;
|
||||||
|
|
||||||
void Generator::Reset() {
|
void Generator::Reset() {
|
||||||
set_error("");
|
set_error("");
|
||||||
impl_ = std::make_unique<GeneratorImpl>();
|
impl_ = std::make_unique<GeneratorImpl>(&module_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Generator::Generate() {
|
bool Generator::Generate() {
|
||||||
auto ret = impl_->Generate(module_);
|
auto ret = impl_->Generate();
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
error_ = impl_->error();
|
error_ = impl_->error();
|
||||||
}
|
}
|
||||||
|
@ -40,7 +41,7 @@ bool Generator::Generate() {
|
||||||
|
|
||||||
bool Generator::GenerateEntryPoint(ast::PipelineStage stage,
|
bool Generator::GenerateEntryPoint(ast::PipelineStage stage,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
auto ret = impl_->GenerateEntryPoint(module_, stage, name);
|
auto ret = impl_->GenerateEntryPoint(stage, name);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
error_ = impl_->error();
|
error_ = impl_->error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,29 +78,30 @@ namespace tint {
|
||||||
namespace writer {
|
namespace writer {
|
||||||
namespace wgsl {
|
namespace wgsl {
|
||||||
|
|
||||||
GeneratorImpl::GeneratorImpl() : TextGenerator() {}
|
GeneratorImpl::GeneratorImpl(ast::Module* module)
|
||||||
|
: TextGenerator(), module_(*module) {}
|
||||||
|
|
||||||
GeneratorImpl::~GeneratorImpl() = default;
|
GeneratorImpl::~GeneratorImpl() = default;
|
||||||
|
|
||||||
bool GeneratorImpl::Generate(const ast::Module& module) {
|
bool GeneratorImpl::Generate() {
|
||||||
for (auto* const ty : module.constructed_types()) {
|
for (auto* const ty : module_.constructed_types()) {
|
||||||
if (!EmitConstructedType(ty)) {
|
if (!EmitConstructedType(ty)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!module.constructed_types().empty())
|
if (!module_.constructed_types().empty())
|
||||||
out_ << std::endl;
|
out_ << std::endl;
|
||||||
|
|
||||||
for (auto* var : module.global_variables()) {
|
for (auto* var : module_.global_variables()) {
|
||||||
if (!EmitVariable(var)) {
|
if (!EmitVariable(var)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!module.global_variables().empty()) {
|
if (!module_.global_variables().empty()) {
|
||||||
out_ << std::endl;
|
out_ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* func : module.functions()) {
|
for (auto* func : module_.functions()) {
|
||||||
if (!EmitFunction(func)) {
|
if (!EmitFunction(func)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -110,11 +111,10 @@ bool GeneratorImpl::Generate(const ast::Module& module) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::GenerateEntryPoint(const ast::Module& module,
|
bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
|
||||||
ast::PipelineStage stage,
|
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
auto* func =
|
auto* func =
|
||||||
module.FindFunctionBySymbolAndStage(module.GetSymbol(name), stage);
|
module_.FindFunctionBySymbolAndStage(module_.GetSymbol(name), stage);
|
||||||
if (func == nullptr) {
|
if (func == nullptr) {
|
||||||
error_ = "Unable to find requested entry point: " + name;
|
error_ = "Unable to find requested entry point: " + name;
|
||||||
return false;
|
return false;
|
||||||
|
@ -122,18 +122,18 @@ bool GeneratorImpl::GenerateEntryPoint(const ast::Module& module,
|
||||||
|
|
||||||
// TODO(dsinclair): We always emit constructed types even if they aren't
|
// TODO(dsinclair): We always emit constructed types even if they aren't
|
||||||
// strictly needed
|
// strictly needed
|
||||||
for (auto* const ty : module.constructed_types()) {
|
for (auto* const ty : module_.constructed_types()) {
|
||||||
if (!EmitConstructedType(ty)) {
|
if (!EmitConstructedType(ty)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!module.constructed_types().empty()) {
|
if (!module_.constructed_types().empty()) {
|
||||||
out_ << std::endl;
|
out_ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dsinclair): This should be smarter and only emit needed const
|
// TODO(dsinclair): This should be smarter and only emit needed const
|
||||||
// variables
|
// variables
|
||||||
for (auto* var : module.global_variables()) {
|
for (auto* var : module_.global_variables()) {
|
||||||
if (!var->is_const()) {
|
if (!var->is_const()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,8 @@ bool GeneratorImpl::GenerateEntryPoint(const ast::Module& module,
|
||||||
out_ << std::endl;
|
out_ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* f : module.functions()) {
|
for (auto* f : module_.functions()) {
|
||||||
if (!f->HasAncestorEntryPoint(module.GetSymbol(name))) {
|
if (!f->HasAncestorEntryPoint(module_.GetSymbol(name))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
out_ << v->name() << " : ";
|
out_ << module_.SymbolToName(v->symbol()) << " : ";
|
||||||
|
|
||||||
if (!EmitType(v->type())) {
|
if (!EmitType(v->type())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -597,7 +597,7 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << " " << var->name() << " : ";
|
out_ << " " << module_.SymbolToName(var->symbol()) << " : ";
|
||||||
if (!EmitType(var->type())) {
|
if (!EmitType(var->type())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,22 +53,19 @@ namespace wgsl {
|
||||||
class GeneratorImpl : public TextGenerator {
|
class GeneratorImpl : public TextGenerator {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
GeneratorImpl();
|
/// @param module the module to generate
|
||||||
|
explicit GeneratorImpl(ast::Module* mod);
|
||||||
~GeneratorImpl();
|
~GeneratorImpl();
|
||||||
|
|
||||||
/// Generates the result data
|
/// Generates the result data
|
||||||
/// @param module the module to generate
|
|
||||||
/// @returns true on successful generation; false otherwise
|
/// @returns true on successful generation; false otherwise
|
||||||
bool Generate(const ast::Module& module);
|
bool Generate();
|
||||||
|
|
||||||
/// Generates a single entry point
|
/// Generates a single entry point
|
||||||
/// @param module the module to generate from
|
|
||||||
/// @param stage the pipeline stage
|
/// @param stage the pipeline stage
|
||||||
/// @param name the entry point name
|
/// @param name the entry point name
|
||||||
/// @returns true on successful generation; false otherwise
|
/// @returns true on successful generation; false otherwise
|
||||||
bool GenerateEntryPoint(const ast::Module& module,
|
bool GenerateEntryPoint(ast::PipelineStage stage, const std::string& name);
|
||||||
ast::PipelineStage stage,
|
|
||||||
const std::string& name);
|
|
||||||
|
|
||||||
/// Handles generating a constructed type
|
/// Handles generating a constructed type
|
||||||
/// @param ty the constructed to generate
|
/// @param ty the constructed to generate
|
||||||
|
@ -206,6 +203,9 @@ class GeneratorImpl : public TextGenerator {
|
||||||
/// @param var the decorated variable
|
/// @param var the decorated variable
|
||||||
/// @returns true if the variable decoration was emitted
|
/// @returns true if the variable decoration was emitted
|
||||||
bool EmitVariableDecorations(ast::Variable* var);
|
bool EmitVariableDecorations(ast::Variable* var);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ast::Module& module_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
|
|
|
@ -226,7 +226,7 @@ TEST_F(WgslGeneratorImplTest,
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
ASSERT_TRUE(td.Determine()) << td.error();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.Generate(*mod)) << gen.error();
|
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"([[block]]
|
EXPECT_EQ(gen.result(), R"([[block]]
|
||||||
struct Data {
|
struct Data {
|
||||||
[[offset(0)]]
|
[[offset(0)]]
|
||||||
|
|
|
@ -33,7 +33,7 @@ TEST_F(WgslGeneratorImplTest, Generate) {
|
||||||
mod->AddFunction(Func("my_func", ast::VariableList{}, ty.void_,
|
mod->AddFunction(Func("my_func", ast::VariableList{}, ty.void_,
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{}));
|
ast::StatementList{}, ast::FunctionDecorationList{}));
|
||||||
|
|
||||||
ASSERT_TRUE(gen.Generate(*mod)) << gen.error();
|
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"(fn my_func() -> void {
|
EXPECT_EQ(gen.result(), R"(fn my_func() -> void {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace wgsl {
|
||||||
template <typename BASE>
|
template <typename BASE>
|
||||||
class TestHelperBase : public BASE, public ast::BuilderWithModule {
|
class TestHelperBase : public BASE, public ast::BuilderWithModule {
|
||||||
public:
|
public:
|
||||||
TestHelperBase() : td(mod), gen() {}
|
TestHelperBase() : td(mod), gen(mod) {}
|
||||||
|
|
||||||
~TestHelperBase() = default;
|
~TestHelperBase() = default;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue