PB: Make Var() and Global() params optional

and allow them in any order.

We're about to add Yet Another optional parameter - access control.
For style, we probably want this field before the decorations, however
that means adding more default values for all the cases where we don't
need to specify the access control.

Instead use some template magic to allow extra parameters to be
specified in any order, and entirely optional, with sensible defaults.
This keeps things readable and without huge code refactorings.

Bug: tint:846
Change-Id: I4f61eb765de63ad98ae786d187d2bd1b42942756
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53087
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-06-04 19:55:08 +00:00
committed by Tint LUCI CQ
parent 9fd3befa17
commit 620d77e480
21 changed files with 311 additions and 241 deletions

View File

@@ -152,7 +152,7 @@ void Msl::HandlePrivateAndWorkgroupVariables(CloneContext& ctx) const {
auto* constructor = ctx.Clone(var->Declaration()->constructor());
auto* local_var =
ctx.dst->Var(ctx.dst->Sym(), store_type, var->StorageClass(),
constructor, {disable_validation});
constructor, ast::DecorationList{disable_validation});
ctx.InsertBefore(func_ast->body()->statements(),
*func_ast->body()->begin(), ctx.dst->Decl(local_var));

View File

@@ -264,8 +264,9 @@ void Spirv::EmitVertexPointSize(CloneContext& ctx) const {
// Create a module-scope pointsize builtin output variable.
Symbol pointsize = ctx.dst->Symbols().New("tint_pointsize");
ctx.dst->Global(pointsize, ctx.dst->ty.f32(), ast::StorageClass::kOutput,
nullptr, {ctx.dst->Builtin(ast::Builtin::kPointSize)});
ctx.dst->Global(
pointsize, ctx.dst->ty.f32(), ast::StorageClass::kOutput,
ast::DecorationList{ctx.dst->Builtin(ast::Builtin::kPointSize)});
// Assign 1.0 to the global at the start of all vertex shader entry points.
ctx.ReplaceAll([&ctx, pointsize](ast::Function* func) -> ast::Function* {