ast: Support non-literal workgroup_size parameters

Change the type of the values in an ast::WorkgroupDecoration to be
ast::Expression nodes, so that they can represent both
ast::ScalarExpression (literal) and ast::IdentifierExpression
(module-scope constant).

The Resolver processes these nodes to produce a uint32_t for the
default value on each dimension, and captures a reference to the
module-scope constant if it is overridable (which will soon be used by
the inspector and backends).

The WGSL parser now uses `primary_expression` to parse arguments to
workgroup_size.

Also added some WorkgroupSize() helpers to ProgramBuilder.

Bug: tint:713
Change-Id: I44b7b0021b925c84f25f65e26dc7da6b19ede508
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51262
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price
2021-05-19 13:40:08 +00:00
committed by Commit Bot service account
parent 40ac15f157
commit 70f80bb13d
22 changed files with 741 additions and 337 deletions

View File

@@ -59,6 +59,7 @@
#include "src/ast/variable_decl_statement.h"
#include "src/ast/vector.h"
#include "src/ast/void.h"
#include "src/ast/workgroup_decoration.h"
#include "src/program.h"
#include "src/program_id.h"
#include "src/sem/array.h"
@@ -1914,6 +1915,36 @@ class ProgramBuilder {
return create<ast::StageDecoration>(source_, stage);
}
/// Creates an ast::WorkgroupDecoration
/// @param x the x dimension expression
/// @returns the workgroup decoration pointer
template <typename EXPR_X>
ast::WorkgroupDecoration* WorkgroupSize(EXPR_X&& x) {
return WorkgroupSize(std::forward<EXPR_X>(x), nullptr, nullptr);
}
/// Creates an ast::WorkgroupDecoration
/// @param x the x dimension expression
/// @param y the y dimension expression
/// @returns the workgroup decoration pointer
template <typename EXPR_X, typename EXPR_Y>
ast::WorkgroupDecoration* WorkgroupSize(EXPR_X&& x, EXPR_Y&& y) {
return WorkgroupSize(std::forward<EXPR_X>(x), std::forward<EXPR_Y>(y),
nullptr);
}
/// Creates an ast::WorkgroupDecoration
/// @param x the x dimension expression
/// @param y the y dimension expression
/// @param z the z dimension expression
/// @returns the workgroup decoration pointer
template <typename EXPR_X, typename EXPR_Y, typename EXPR_Z>
ast::WorkgroupDecoration* WorkgroupSize(EXPR_X&& x, EXPR_Y&& y, EXPR_Z&& z) {
return create<ast::WorkgroupDecoration>(
source_, Expr(std::forward<EXPR_X>(x)), Expr(std::forward<EXPR_Y>(y)),
Expr(std::forward<EXPR_Z>(z)));
}
/// Sets the current builder source to `src`
/// @param src the Source used for future create() calls
void SetSource(const Source& src) {