tint::ProgramBuilder: Simplify variable constructors

Expand the Option argument paradigm to:
* Remove the requirement to always pass a 'type' parameter. Type inferencing is the easier, and increasingly common way to declare a variable, so this prevents a whole lot of `nullptr` smell which negatively impacts readability.
* Accept attributes directly as arguments, removing the `utils::Vector{ ... }` smell.

Rename `ProgramBuilder::VarOptionals` to `VarOptions`, and add equivalent `LetOptions`, `ConstOptions` and `OverrideOptions`.

Clean up all the calls to `Var()`, `Let()`, `Const()` and `Override()`:
* Use the `Group()` and `Binding()` helpers where possible
* Removing `nullptr` type arguments
* Replace attribute vectors with the list of attributes.
* Remove already-defaulted `ast::StorageClass::kNone` arguments.
* Remove already-defaulted `ast::Access::kUndefined` arguments.

Finally, remove the `GroupAndBinding()` helper, which only existed because you needed to pass attributes as a vector.

Change-Id: I8890e4eb0ffac9f9df2207b28a6f02a163e34d96
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99580
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton
2022-08-19 17:28:53 +00:00
committed by Dawn LUCI CQ
parent fa289d3a83
commit 58794ae118
113 changed files with 1659 additions and 2455 deletions

View File

@@ -647,7 +647,7 @@ TEST_F(InspectorGetEntryPointTest, MixInOutVariablesAndStruct) {
}
TEST_F(InspectorGetEntryPointTest, OverrideUnreferenced) {
Override("foo", ty.f32(), nullptr);
Override("foo", ty.f32());
MakeEmptyBodyFunction("ep_func", utils::Vector{
Stage(ast::PipelineStage::kCompute),
WorkgroupSize(1_i),
@@ -662,7 +662,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideUnreferenced) {
}
TEST_F(InspectorGetEntryPointTest, OverrideReferencedByEntryPoint) {
Override("foo", ty.f32(), nullptr);
Override("foo", ty.f32());
MakePlainGlobalReferenceBodyFunction("ep_func", "foo", ty.f32(),
utils::Vector{
Stage(ast::PipelineStage::kCompute),
@@ -679,7 +679,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideReferencedByEntryPoint) {
}
TEST_F(InspectorGetEntryPointTest, OverrideReferencedByCallee) {
Override("foo", ty.f32(), nullptr);
Override("foo", ty.f32());
MakePlainGlobalReferenceBodyFunction("callee_func", "foo", ty.f32(), utils::Empty);
MakeCallerBodyFunction("ep_func", utils::Vector{std::string("callee_func")},
utils::Vector{
@@ -697,14 +697,8 @@ TEST_F(InspectorGetEntryPointTest, OverrideReferencedByCallee) {
}
TEST_F(InspectorGetEntryPointTest, OverrideSomeReferenced) {
Override("foo", ty.f32(), nullptr,
utils::Vector{
Id(1),
});
Override("bar", ty.f32(), nullptr,
utils::Vector{
Id(2),
});
Override("foo", ty.f32(), Id(1));
Override("bar", ty.f32(), Id(2));
MakePlainGlobalReferenceBodyFunction("callee_func", "foo", ty.f32(), utils::Empty);
MakeCallerBodyFunction("ep_func", utils::Vector{std::string("callee_func")},
utils::Vector{
@@ -723,10 +717,10 @@ TEST_F(InspectorGetEntryPointTest, OverrideSomeReferenced) {
}
TEST_F(InspectorGetEntryPointTest, OverrideTypes) {
Override("bool_var", ty.bool_(), nullptr);
Override("float_var", ty.f32(), nullptr);
Override("u32_var", ty.u32(), nullptr);
Override("i32_var", ty.i32(), nullptr);
Override("bool_var", ty.bool_());
Override("float_var", ty.f32());
Override("u32_var", ty.u32());
Override("i32_var", ty.i32());
MakePlainGlobalReferenceBodyFunction("bool_func", "bool_var", ty.bool_(), utils::Empty);
MakePlainGlobalReferenceBodyFunction("float_func", "float_var", ty.f32(), utils::Empty);
@@ -775,7 +769,7 @@ TEST_F(InspectorGetEntryPointTest, OverrideInitialized) {
}
TEST_F(InspectorGetEntryPointTest, OverrideUninitialized) {
Override("foo", ty.f32(), nullptr);
Override("foo", ty.f32());
MakePlainGlobalReferenceBodyFunction("ep_func", "foo", ty.f32(),
utils::Vector{
Stage(ast::PipelineStage::kCompute),
@@ -794,11 +788,8 @@ TEST_F(InspectorGetEntryPointTest, OverrideUninitialized) {
}
TEST_F(InspectorGetEntryPointTest, OverrideNumericIDSpecified) {
Override("foo_no_id", ty.f32(), nullptr);
Override("foo_id", ty.f32(), nullptr,
utils::Vector{
Id(1234),
});
Override("foo_no_id", ty.f32());
Override("foo_id", ty.f32(), Id(1234));
MakePlainGlobalReferenceBodyFunction("no_id_func", "foo_no_id", ty.f32(), utils::Empty);
MakePlainGlobalReferenceBodyFunction("id_func", "foo_id", ty.f32(), utils::Empty);
@@ -1234,18 +1225,9 @@ INSTANTIATE_TEST_SUITE_P(
InterpolationType::kFlat, InterpolationSampling::kNone}));
TEST_F(InspectorGetOverrideDefaultValuesTest, Bool) {
Override("foo", ty.bool_(), nullptr,
utils::Vector{
Id(1),
});
Override("bar", ty.bool_(), Expr(true),
utils::Vector{
Id(20),
});
Override("baz", ty.bool_(), Expr(false),
utils::Vector{
Id(300),
});
Override("foo", ty.bool_(), Id(1));
Override("bar", ty.bool_(), Expr(true), Id(20));
Override("baz", ty.bool_(), Expr(false), Id(300));
Inspector& inspector = Build();
@@ -1265,14 +1247,8 @@ TEST_F(InspectorGetOverrideDefaultValuesTest, Bool) {
}
TEST_F(InspectorGetOverrideDefaultValuesTest, U32) {
Override("foo", ty.u32(), nullptr,
utils::Vector{
Id(1),
});
Override("bar", ty.u32(), Expr(42_u),
utils::Vector{
Id(20),
});
Override("foo", ty.u32(), Id(1));
Override("bar", ty.u32(), Expr(42_u), Id(20));
Inspector& inspector = Build();
@@ -1288,18 +1264,9 @@ TEST_F(InspectorGetOverrideDefaultValuesTest, U32) {
}
TEST_F(InspectorGetOverrideDefaultValuesTest, I32) {
Override("foo", ty.i32(), nullptr,
utils::Vector{
Id(1),
});
Override("bar", ty.i32(), Expr(-42_i),
utils::Vector{
Id(20),
});
Override("baz", ty.i32(), Expr(42_i),
utils::Vector{
Id(300),
});
Override("foo", ty.i32(), Id(1));
Override("bar", ty.i32(), Expr(-42_i), Id(20));
Override("baz", ty.i32(), Expr(42_i), Id(300));
Inspector& inspector = Build();
@@ -1319,22 +1286,10 @@ TEST_F(InspectorGetOverrideDefaultValuesTest, I32) {
}
TEST_F(InspectorGetOverrideDefaultValuesTest, Float) {
Override("foo", ty.f32(), nullptr,
utils::Vector{
Id(1),
});
Override("bar", ty.f32(), Expr(0_f),
utils::Vector{
Id(20),
});
Override("baz", ty.f32(), Expr(-10_f),
utils::Vector{
Id(300),
});
Override("x", ty.f32(), Expr(15_f),
utils::Vector{
Id(4000),
});
Override("foo", ty.f32(), Id(1));
Override("bar", ty.f32(), Expr(0_f), Id(20));
Override("baz", ty.f32(), Expr(-10_f), Id(300));
Override("x", ty.f32(), Expr(15_f), Id(4000));
Inspector& inspector = Build();
@@ -1358,21 +1313,12 @@ TEST_F(InspectorGetOverrideDefaultValuesTest, Float) {
}
TEST_F(InspectorGetConstantNameToIdMapTest, WithAndWithoutIds) {
Override("v1", ty.f32(), nullptr,
utils::Vector{
Id(1),
});
Override("v20", ty.f32(), nullptr,
utils::Vector{
Id(20),
});
Override("v300", ty.f32(), nullptr,
utils::Vector{
Id(300),
});
auto* a = Override("a", ty.f32(), nullptr);
auto* b = Override("b", ty.f32(), nullptr);
auto* c = Override("c", ty.f32(), nullptr);
Override("v1", ty.f32(), Id(1));
Override("v20", ty.f32(), Id(20));
Override("v300", ty.f32(), Id(300));
auto* a = Override("a", ty.f32());
auto* b = Override("b", ty.f32());
auto* c = Override("c", ty.f32());
Inspector& inspector = Build();
@@ -1416,9 +1362,9 @@ TEST_F(InspectorGetStorageSizeTest, Simple_NonStruct) {
AddStorageBuffer("rosb_var", ty.i32(), ast::Access::kRead, 1, 1);
Func("ep_func", utils::Empty, ty.void_(),
utils::Vector{
Decl(Let("ub", nullptr, Expr("ub_var"))),
Decl(Let("sb", nullptr, Expr("sb_var"))),
Decl(Let("rosb", nullptr, Expr("rosb_var"))),
Decl(Let("ub", Expr("ub_var"))),
Decl(Let("sb", Expr("sb_var"))),
Decl(Let("rosb", Expr("rosb_var"))),
},
utils::Vector{
Stage(ast::PipelineStage::kCompute),
@@ -1474,7 +1420,7 @@ TEST_F(InspectorGetStorageSizeTest, NonStructVec3) {
AddUniformBuffer("ub_var", ty.vec3<f32>(), 0, 0);
Func("ep_func", utils::Empty, ty.void_(),
utils::Vector{
Decl(Let("ub", nullptr, Expr("ub_var"))),
Decl(Let("ub", Expr("ub_var"))),
},
utils::Vector{
Stage(ast::PipelineStage::kCompute),
@@ -1493,7 +1439,7 @@ TEST_F(InspectorGetStorageSizeTest, StructVec3) {
AddUniformBuffer("ub_var", ty.Of(ub_struct_type), 0, 0);
Func("ep_func", utils::Empty, ty.void_(),
utils::Vector{
Decl(Let("ub", nullptr, Expr("ub_var"))),
Decl(Let("ub", Expr("ub_var"))),
},
utils::Vector{
Stage(ast::PipelineStage::kCompute),

View File

@@ -126,11 +126,7 @@ void InspectorBuilder::AddUniformBuffer(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type, ast::StorageClass::kUniform,
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
GlobalVar(name, type, ast::StorageClass::kUniform, Binding(binding), Group(group));
}
void InspectorBuilder::AddWorkgroupStorage(const std::string& name, const ast::Type* type) {
@@ -142,11 +138,7 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name,
ast::Access access,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type, ast::StorageClass::kStorage, access,
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
GlobalVar(name, type, ast::StorageClass::kStorage, access, Binding(binding), Group(group));
}
void InspectorBuilder::MakeStructVariableReferenceBodyFunction(
@@ -178,32 +170,20 @@ void InspectorBuilder::MakeStructVariableReferenceBodyFunction(
}
void InspectorBuilder::AddSampler(const std::string& name, uint32_t group, uint32_t binding) {
GlobalVar(name, sampler_type(),
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
GlobalVar(name, sampler_type(), Binding(binding), Group(group));
}
void InspectorBuilder::AddComparisonSampler(const std::string& name,
uint32_t group,
uint32_t binding) {
GlobalVar(name, comparison_sampler_type(),
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
GlobalVar(name, comparison_sampler_type(), Binding(binding), Group(group));
}
void InspectorBuilder::AddResource(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type,
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
GlobalVar(name, type, Binding(binding), Group(group));
}
void InspectorBuilder::AddGlobalVariable(const std::string& name, const ast::Type* type) {
@@ -305,11 +285,7 @@ void InspectorBuilder::AddStorageTexture(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type,
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
GlobalVar(name, type, Binding(binding), Group(group));
}
const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction(