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>
diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc
index f68a165..d3ac05f 100644
--- a/src/tint/transform/multiplanar_external_texture.cc
+++ b/src/tint/transform/multiplanar_external_texture.cc
@@ -132,11 +132,11 @@
syms.plane_0 = ctx.Clone(global->symbol);
syms.plane_1 = b.Symbols().New("ext_tex_plane_1");
b.GlobalVar(syms.plane_1, b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()),
- b.GroupAndBinding(bps.plane_1.group, bps.plane_1.binding));
+ b.Group(bps.plane_1.group), b.Binding(bps.plane_1.binding));
syms.params = b.Symbols().New("ext_tex_params");
b.GlobalVar(syms.params, b.ty.type_name("ExternalTextureParams"),
- ast::StorageClass::kUniform,
- b.GroupAndBinding(bps.params.group, bps.params.binding));
+ ast::StorageClass::kUniform, b.Group(bps.params.group),
+ b.Binding(bps.params.binding));
// Replace the original texture_external binding with a texture_2d<f32>
// binding.
@@ -276,24 +276,22 @@
b.ty.vec3<f32>(),
utils::Vector{
// let cond = abs(v) < vec3(params.D);
- b.Decl(b.Let(
- "cond", nullptr,
- b.LessThan(b.Call("abs", "v"), b.vec3<f32>(b.MemberAccessor("params", "D"))))),
+ b.Decl(b.Let("cond", b.LessThan(b.Call("abs", "v"),
+ b.vec3<f32>(b.MemberAccessor("params", "D"))))),
// let t = sign(v) * ((params.C * abs(v)) + params.F);
- b.Decl(b.Let("t", nullptr,
+ b.Decl(b.Let("t",
b.Mul(b.Call("sign", "v"),
b.Add(b.Mul(b.MemberAccessor("params", "C"), b.Call("abs", "v")),
b.MemberAccessor("params", "F"))))),
// let f = (sign(v) * pow(((params.A * abs(v)) + params.B),
// vec3(params.G))) + params.E;
- b.Decl(b.Let("f", nullptr,
- b.Mul(b.Call("sign", "v"),
- b.Add(b.Call("pow",
- b.Add(b.Mul(b.MemberAccessor("params", "A"),
- b.Call("abs", "v")),
- b.MemberAccessor("params", "B")),
- b.vec3<f32>(b.MemberAccessor("params", "G"))),
- b.MemberAccessor("params", "E"))))),
+ b.Decl(b.Let("f", b.Mul(b.Call("sign", "v"),
+ b.Add(b.Call("pow",
+ b.Add(b.Mul(b.MemberAccessor("params", "A"),
+ b.Call("abs", "v")),
+ b.MemberAccessor("params", "B")),
+ b.vec3<f32>(b.MemberAccessor("params", "G"))),
+ b.MemberAccessor("params", "E"))))),
// return select(f, t, cond);
b.Return(b.Call("select", "f", "t", "cond")),
});