mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 07:06:11 +00:00
Add Symbol to Variable.
This CL adds a Symbol to the Variable AST node along side the name. The name will be removed in a future CL. Change-Id: I1c05e5595392b1c4a0afa82387d97b2b4472bade Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35881 Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: dan sinclair <dsinclair@chromium.org> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
b5839939e1
commit
a57f842be9
@@ -51,12 +51,13 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
|
||||
|
||||
// Declare the pointsize builtin output variable.
|
||||
auto* pointsize_var = out.module.create<ast::Variable>(
|
||||
Source{}, // source
|
||||
kPointSizeVar, // name
|
||||
ast::StorageClass::kOutput, // storage_class
|
||||
f32, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
Source{}, // source
|
||||
out.module.RegisterSymbol(kPointSizeVar), // symbol
|
||||
kPointSizeVar, // name
|
||||
ast::StorageClass::kOutput, // storage_class
|
||||
f32, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out.module.create<ast::BuiltinDecoration>(Source{},
|
||||
|
||||
@@ -65,13 +65,14 @@ ast::Variable* clone_variable_with_new_name(ast::CloneContext* ctx,
|
||||
ast::Variable* in,
|
||||
std::string new_name) {
|
||||
return ctx->mod->create<ast::Variable>(
|
||||
ctx->Clone(in->source()), // source
|
||||
new_name, // name
|
||||
in->storage_class(), // storage_class
|
||||
ctx->Clone(in->type()), // type
|
||||
in->is_const(), // is_const
|
||||
ctx->Clone(in->constructor()), // constructor
|
||||
ctx->Clone(in->decorations())); // decorations
|
||||
ctx->Clone(in->source()), // source
|
||||
ctx->mod->RegisterSymbol(new_name), // symbol
|
||||
new_name, // name
|
||||
in->storage_class(), // storage_class
|
||||
ctx->Clone(in->type()), // type
|
||||
in->is_const(), // is_const
|
||||
ctx->Clone(in->constructor()), // constructor
|
||||
ctx->Clone(in->decorations())); // decorations
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -226,12 +227,13 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
|
||||
mod->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
|
||||
|
||||
auto* idx_var = mod->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
kBufferName, // name
|
||||
ast::StorageClass::kUniform, // storage_class
|
||||
struct_type, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
Source{}, // source
|
||||
mod->RegisterSymbol(kBufferName), // symbol
|
||||
kBufferName, // name
|
||||
ast::StorageClass::kUniform, // storage_class
|
||||
struct_type, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
mod->create<ast::BindingDecoration>(Source{}, binding_),
|
||||
mod->create<ast::SetDecoration>(Source{}, set_),
|
||||
@@ -261,8 +263,9 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
|
||||
mod->create<ast::IdentifierExpression>(
|
||||
Source{}, mod->RegisterSymbol(field_name), field_name)));
|
||||
auto* var =
|
||||
mod->create<ast::Variable>(Source{}, // source
|
||||
original_name, // name
|
||||
mod->create<ast::Variable>(Source{}, // source
|
||||
mod->RegisterSymbol(original_name), // symbol
|
||||
original_name, // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
mod->create<ast::type::U32>(), // type
|
||||
true, // is_const
|
||||
|
||||
@@ -165,18 +165,19 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
||||
// We didn't find a vertex index builtin, so create one
|
||||
vertex_index_name = kDefaultVertexIndexName;
|
||||
|
||||
auto* var =
|
||||
out->create<ast::Variable>(Source{}, // source
|
||||
vertex_index_name, // name
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(
|
||||
Source{}, ast::Builtin::kVertexIdx),
|
||||
});
|
||||
auto* var = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
out->RegisterSymbol(vertex_index_name), // symbol
|
||||
vertex_index_name, // name
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kVertexIdx),
|
||||
});
|
||||
|
||||
out->AddGlobalVariable(var);
|
||||
}
|
||||
@@ -212,18 +213,19 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
||||
// We didn't find an instance index builtin, so create one
|
||||
instance_index_name = kDefaultInstanceIndexName;
|
||||
|
||||
auto* var =
|
||||
out->create<ast::Variable>(Source{}, // source
|
||||
instance_index_name, // name
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(
|
||||
Source{}, ast::Builtin::kInstanceIdx),
|
||||
});
|
||||
auto* var = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
out->RegisterSymbol(instance_index_name), // symbol
|
||||
instance_index_name, // name
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kInstanceIdx),
|
||||
});
|
||||
out->AddGlobalVariable(var);
|
||||
}
|
||||
|
||||
@@ -241,6 +243,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
|
||||
// place in the AST.
|
||||
v = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
v->symbol(), // symbol
|
||||
v->name(), // name
|
||||
ast::StorageClass::kPrivate, // storage_class
|
||||
v->type(), // type
|
||||
@@ -282,9 +285,11 @@ void VertexPulling::State::AddVertexStorageBuffers() {
|
||||
|
||||
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
|
||||
// The decorated variable with struct type
|
||||
std::string name = GetVertexBufferName(i);
|
||||
auto* var = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
GetVertexBufferName(i), // name
|
||||
out->RegisterSymbol(name), // symbol
|
||||
name, // name
|
||||
ast::StorageClass::kStorageBuffer, // storage_class
|
||||
struct_type, // type
|
||||
false, // is_const
|
||||
@@ -308,13 +313,14 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
|
||||
// Declare the |kPullingPosVarName| variable in the shader
|
||||
auto* pos_declaration = out->create<ast::VariableDeclStatement>(
|
||||
Source{}, out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
kPullingPosVarName, // name
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{})); // decorations
|
||||
Source{}, // source
|
||||
out->RegisterSymbol(kPullingPosVarName), // symbol
|
||||
kPullingPosVarName, // name
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{})); // decorations
|
||||
|
||||
// |kPullingPosVarName| refers to the byte location of the current read. We
|
||||
// declare a variable in the shader to avoid having to reuse Expression
|
||||
|
||||
@@ -50,6 +50,7 @@ class VertexPullingHelper : public ast::BuilderWithModule {
|
||||
Func("main", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
|
||||
mod->AddFunction(func);
|
||||
}
|
||||
|
||||
@@ -399,20 +400,17 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
|
||||
TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
AddVertexInputVariable(0, "var_a", &f32);
|
||||
AddVertexInputVariable(1, "var_b", &f32);
|
||||
|
||||
ast::type::I32 i32;
|
||||
AddVertexInputVariable(0, "var_a", ty.f32);
|
||||
AddVertexInputVariable(1, "var_b", ty.f32);
|
||||
|
||||
mod->AddGlobalVariable(
|
||||
Var("custom_vertex_index", ast::StorageClass::kInput, &i32, nullptr,
|
||||
Var("custom_vertex_index", ast::StorageClass::kInput, ty.i32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx),
|
||||
}));
|
||||
|
||||
mod->AddGlobalVariable(
|
||||
Var("custom_instance_index", ast::StorageClass::kInput, &i32, nullptr,
|
||||
Var("custom_instance_index", ast::StorageClass::kInput, ty.i32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user