mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
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:
committed by
Dawn LUCI CQ
parent
fa289d3a83
commit
58794ae118
@@ -148,7 +148,7 @@ void ArrayLengthFromUniform::Run(CloneContext& ctx, const DataMap& inputs, DataM
|
||||
});
|
||||
buffer_size_ubo = ctx.dst->GlobalVar(
|
||||
ctx.dst->Sym(), ctx.dst->ty.Of(buffer_size_struct), ast::StorageClass::kUniform,
|
||||
ctx.dst->GroupAndBinding(cfg->ubo_binding.group, cfg->ubo_binding.binding));
|
||||
ctx.dst->Group(cfg->ubo_binding.group), ctx.dst->Binding(cfg->ubo_binding.binding));
|
||||
}
|
||||
return buffer_size_ubo;
|
||||
};
|
||||
|
||||
@@ -154,45 +154,44 @@ struct BuiltinPolyfill::State {
|
||||
auto V = [&](uint32_t value) -> const ast::Expression* {
|
||||
return ScalarOrVector(width, u32(value));
|
||||
};
|
||||
b.Func(
|
||||
name,
|
||||
utils::Vector{
|
||||
b.Param("v", T(ty)),
|
||||
},
|
||||
T(ty),
|
||||
utils::Vector{
|
||||
// var x = U(v);
|
||||
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(0, 16, x <= 0x0000ffff);
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(0), V(16), b.LessThanEqual("x", V(0x0000ffff))))),
|
||||
// x = x << b16;
|
||||
b.Assign("x", b.Shl("x", "b16")),
|
||||
// let b8 = select(0, 8, x <= 0x00ffffff);
|
||||
b.Decl(b.Let("b8", nullptr,
|
||||
b.Call("select", V(0), V(8), b.LessThanEqual("x", V(0x00ffffff))))),
|
||||
// x = x << b8;
|
||||
b.Assign("x", b.Shl("x", "b8")),
|
||||
// let b4 = select(0, 4, x <= 0x0fffffff);
|
||||
b.Decl(b.Let("b4", nullptr,
|
||||
b.Call("select", V(0), V(4), b.LessThanEqual("x", V(0x0fffffff))))),
|
||||
// x = x << b4;
|
||||
b.Assign("x", b.Shl("x", "b4")),
|
||||
// let b2 = select(0, 2, x <= 0x3fffffff);
|
||||
b.Decl(b.Let("b2", nullptr,
|
||||
b.Call("select", V(0), V(2), b.LessThanEqual("x", V(0x3fffffff))))),
|
||||
// x = x << b2;
|
||||
b.Assign("x", b.Shl("x", "b2")),
|
||||
// let b1 = select(0, 1, x <= 0x7fffffff);
|
||||
b.Decl(b.Let("b1", nullptr,
|
||||
b.Call("select", V(0), V(1), b.LessThanEqual("x", V(0x7fffffff))))),
|
||||
// let is_zero = select(0, 1, x == 0);
|
||||
b.Decl(b.Let("is_zero", nullptr, b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
|
||||
// return R((b16 | b8 | b4 | b2 | b1) + zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty),
|
||||
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"), "is_zero"))),
|
||||
});
|
||||
b.Func(name,
|
||||
utils::Vector{
|
||||
b.Param("v", T(ty)),
|
||||
},
|
||||
T(ty),
|
||||
utils::Vector{
|
||||
// var x = U(v);
|
||||
b.Decl(b.Var("x", b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(0, 16, x <= 0x0000ffff);
|
||||
b.Decl(b.Let(
|
||||
"b16", b.Call("select", V(0), V(16), b.LessThanEqual("x", V(0x0000ffff))))),
|
||||
// x = x << b16;
|
||||
b.Assign("x", b.Shl("x", "b16")),
|
||||
// let b8 = select(0, 8, x <= 0x00ffffff);
|
||||
b.Decl(b.Let("b8",
|
||||
b.Call("select", V(0), V(8), b.LessThanEqual("x", V(0x00ffffff))))),
|
||||
// x = x << b8;
|
||||
b.Assign("x", b.Shl("x", "b8")),
|
||||
// let b4 = select(0, 4, x <= 0x0fffffff);
|
||||
b.Decl(b.Let("b4",
|
||||
b.Call("select", V(0), V(4), b.LessThanEqual("x", V(0x0fffffff))))),
|
||||
// x = x << b4;
|
||||
b.Assign("x", b.Shl("x", "b4")),
|
||||
// let b2 = select(0, 2, x <= 0x3fffffff);
|
||||
b.Decl(b.Let("b2",
|
||||
b.Call("select", V(0), V(2), b.LessThanEqual("x", V(0x3fffffff))))),
|
||||
// x = x << b2;
|
||||
b.Assign("x", b.Shl("x", "b2")),
|
||||
// let b1 = select(0, 1, x <= 0x7fffffff);
|
||||
b.Decl(b.Let("b1",
|
||||
b.Call("select", V(0), V(1), b.LessThanEqual("x", V(0x7fffffff))))),
|
||||
// let is_zero = select(0, 1, x == 0);
|
||||
b.Decl(b.Let("is_zero", b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
|
||||
// return R((b16 | b8 | b4 | b2 | b1) + zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty),
|
||||
b.Add(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"), "is_zero"))),
|
||||
});
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -227,32 +226,27 @@ struct BuiltinPolyfill::State {
|
||||
T(ty),
|
||||
utils::Vector{
|
||||
// var x = U(v);
|
||||
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
|
||||
b.Decl(b.Var("x", b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(16, 0, bool(x & 0x0000ffff));
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))),
|
||||
b.Decl(b.Let("b16", b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))),
|
||||
// x = x >> b16;
|
||||
b.Assign("x", b.Shr("x", "b16")),
|
||||
// let b8 = select(8, 0, bool(x & 0x000000ff));
|
||||
b.Decl(b.Let("b8", nullptr,
|
||||
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
|
||||
b.Decl(b.Let("b8", b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
|
||||
// x = x >> b8;
|
||||
b.Assign("x", b.Shr("x", "b8")),
|
||||
// let b4 = select(4, 0, bool(x & 0x0000000f));
|
||||
b.Decl(b.Let("b4", nullptr,
|
||||
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
|
||||
b.Decl(b.Let("b4", b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
|
||||
// x = x >> b4;
|
||||
b.Assign("x", b.Shr("x", "b4")),
|
||||
// let b2 = select(2, 0, bool(x & 0x00000003));
|
||||
b.Decl(b.Let("b2", nullptr,
|
||||
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
|
||||
b.Decl(b.Let("b2", b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
|
||||
// x = x >> b2;
|
||||
b.Assign("x", b.Shr("x", "b2")),
|
||||
// let b1 = select(1, 0, bool(x & 0x00000001));
|
||||
b.Decl(b.Let("b1", nullptr,
|
||||
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
|
||||
b.Decl(b.Let("b1", b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
|
||||
// let is_zero = select(0, 1, x == 0);
|
||||
b.Decl(b.Let("is_zero", nullptr, b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
|
||||
b.Decl(b.Let("is_zero", b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
|
||||
// return R((b16 | b8 | b4 | b2 | b1) + zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty),
|
||||
@@ -278,14 +272,14 @@ struct BuiltinPolyfill::State {
|
||||
};
|
||||
|
||||
utils::Vector<const ast::Statement*, 8> body{
|
||||
b.Decl(b.Let("s", nullptr, b.Call("min", "offset", u32(W)))),
|
||||
b.Decl(b.Let("e", nullptr, b.Call("min", u32(W), b.Add("s", "count")))),
|
||||
b.Decl(b.Let("s", b.Call("min", "offset", u32(W)))),
|
||||
b.Decl(b.Let("e", b.Call("min", u32(W), b.Add("s", "count")))),
|
||||
};
|
||||
|
||||
switch (polyfill.extract_bits) {
|
||||
case Level::kFull:
|
||||
body.Push(b.Decl(b.Let("shl", nullptr, b.Sub(u32(W), "e"))));
|
||||
body.Push(b.Decl(b.Let("shr", nullptr, b.Add("shl", "s"))));
|
||||
body.Push(b.Decl(b.Let("shl", b.Sub(u32(W), "e"))));
|
||||
body.Push(b.Decl(b.Let("shr", b.Add("shl", "s"))));
|
||||
body.Push(
|
||||
b.Return(b.Shr(b.Shl("v", vecN_u32(b.Expr("shl"))), vecN_u32(b.Expr("shr")))));
|
||||
break;
|
||||
@@ -353,33 +347,27 @@ struct BuiltinPolyfill::State {
|
||||
utils::Vector{
|
||||
// var x = v; (unsigned)
|
||||
// var x = select(U(v), ~U(v), v < 0); (signed)
|
||||
b.Decl(b.Var("x", nullptr, x)),
|
||||
b.Decl(b.Var("x", x)),
|
||||
// let b16 = select(0, 16, bool(x & 0xffff0000));
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(0), V(16), B(b.And("x", V(0xffff0000)))))),
|
||||
b.Decl(b.Let("b16", b.Call("select", V(0), V(16), B(b.And("x", V(0xffff0000)))))),
|
||||
// x = x >> b16;
|
||||
b.Assign("x", b.Shr("x", "b16")),
|
||||
// let b8 = select(0, 8, bool(x & 0x0000ff00));
|
||||
b.Decl(b.Let("b8", nullptr,
|
||||
b.Call("select", V(0), V(8), B(b.And("x", V(0x0000ff00)))))),
|
||||
b.Decl(b.Let("b8", b.Call("select", V(0), V(8), B(b.And("x", V(0x0000ff00)))))),
|
||||
// x = x >> b8;
|
||||
b.Assign("x", b.Shr("x", "b8")),
|
||||
// let b4 = select(0, 4, bool(x & 0x000000f0));
|
||||
b.Decl(b.Let("b4", nullptr,
|
||||
b.Call("select", V(0), V(4), B(b.And("x", V(0x000000f0)))))),
|
||||
b.Decl(b.Let("b4", b.Call("select", V(0), V(4), B(b.And("x", V(0x000000f0)))))),
|
||||
// x = x >> b4;
|
||||
b.Assign("x", b.Shr("x", "b4")),
|
||||
// let b2 = select(0, 2, bool(x & 0x0000000c));
|
||||
b.Decl(b.Let("b2", nullptr,
|
||||
b.Call("select", V(0), V(2), B(b.And("x", V(0x0000000c)))))),
|
||||
b.Decl(b.Let("b2", b.Call("select", V(0), V(2), B(b.And("x", V(0x0000000c)))))),
|
||||
// x = x >> b2;
|
||||
b.Assign("x", b.Shr("x", "b2")),
|
||||
// let b1 = select(0, 1, bool(x & 0x00000002));
|
||||
b.Decl(b.Let("b1", nullptr,
|
||||
b.Call("select", V(0), V(1), B(b.And("x", V(0x00000002)))))),
|
||||
b.Decl(b.Let("b1", b.Call("select", V(0), V(1), B(b.And("x", V(0x00000002)))))),
|
||||
// let is_zero = select(0, 0xffffffff, x == 0);
|
||||
b.Decl(b.Let("is_zero", nullptr,
|
||||
b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
|
||||
b.Decl(b.Let("is_zero", b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
|
||||
// return R(b16 | b8 | b4 | b2 | b1 | zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty), b.Or(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"), "is_zero"))),
|
||||
@@ -418,33 +406,27 @@ struct BuiltinPolyfill::State {
|
||||
T(ty),
|
||||
utils::Vector{
|
||||
// var x = U(v);
|
||||
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
|
||||
b.Decl(b.Var("x", b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(16, 0, bool(x & 0x0000ffff));
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))),
|
||||
b.Decl(b.Let("b16", b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))),
|
||||
// x = x >> b16;
|
||||
b.Assign("x", b.Shr("x", "b16")),
|
||||
// let b8 = select(8, 0, bool(x & 0x000000ff));
|
||||
b.Decl(b.Let("b8", nullptr,
|
||||
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
|
||||
b.Decl(b.Let("b8", b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
|
||||
// x = x >> b8;
|
||||
b.Assign("x", b.Shr("x", "b8")),
|
||||
// let b4 = select(4, 0, bool(x & 0x0000000f));
|
||||
b.Decl(b.Let("b4", nullptr,
|
||||
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
|
||||
b.Decl(b.Let("b4", b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
|
||||
// x = x >> b4;
|
||||
b.Assign("x", b.Shr("x", "b4")),
|
||||
// let b2 = select(2, 0, bool(x & 0x00000003));
|
||||
b.Decl(b.Let("b2", nullptr,
|
||||
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
|
||||
b.Decl(b.Let("b2", b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
|
||||
// x = x >> b2;
|
||||
b.Assign("x", b.Shr("x", "b2")),
|
||||
// let b1 = select(1, 0, bool(x & 0x00000001));
|
||||
b.Decl(b.Let("b1", nullptr,
|
||||
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
|
||||
b.Decl(b.Let("b1", b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
|
||||
// let is_zero = select(0, 0xffffffff, x == 0);
|
||||
b.Decl(b.Let("is_zero", nullptr,
|
||||
b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
|
||||
b.Decl(b.Let("is_zero", b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
|
||||
// return R(b16 | b8 | b4 | b2 | b1 | is_zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty), b.Or(b.Or(b.Or(b.Or(b.Or("b16", "b8"), "b4"), "b2"), "b1"), "is_zero"))),
|
||||
@@ -479,16 +461,15 @@ struct BuiltinPolyfill::State {
|
||||
};
|
||||
|
||||
utils::Vector<const ast::Statement*, 8> body = {
|
||||
b.Decl(b.Let("s", nullptr, b.Call("min", "offset", u32(W)))),
|
||||
b.Decl(b.Let("e", nullptr, b.Call("min", u32(W), b.Add("s", "count")))),
|
||||
b.Decl(b.Let("s", b.Call("min", "offset", u32(W)))),
|
||||
b.Decl(b.Let("e", b.Call("min", u32(W), b.Add("s", "count")))),
|
||||
};
|
||||
|
||||
switch (polyfill.insert_bits) {
|
||||
case Level::kFull:
|
||||
// let mask = ((1 << s) - 1) ^ ((1 << e) - 1)
|
||||
body.Push(
|
||||
b.Decl(b.Let("mask", nullptr,
|
||||
b.Xor(b.Sub(b.Shl(1_u, "s"), 1_u), b.Sub(b.Shl(1_u, "e"), 1_u)))));
|
||||
body.Push(b.Decl(b.Let(
|
||||
"mask", b.Xor(b.Sub(b.Shl(1_u, "s"), 1_u), b.Sub(b.Shl(1_u, "e"), 1_u)))));
|
||||
// return ((n << s) & mask) | (v & ~mask)
|
||||
body.Push(b.Return(b.Or(b.And(b.Shl("n", U("s")), V("mask")),
|
||||
b.And("v", V(b.Complement("mask"))))));
|
||||
|
||||
@@ -169,9 +169,8 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) cons
|
||||
|
||||
// Construct the variable that'll hold the result of
|
||||
// RWByteAddressBuffer.GetDimensions()
|
||||
auto* buffer_size_result = ctx.dst->Decl(
|
||||
ctx.dst->Var(ctx.dst->Sym(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kNone, ctx.dst->Expr(0_u)));
|
||||
auto* buffer_size_result = ctx.dst->Decl(ctx.dst->Var(
|
||||
ctx.dst->Sym(), ctx.dst->ty.u32(), ctx.dst->Expr(0_u)));
|
||||
|
||||
// Call storage_buffer.GetDimensions(&buffer_size_result)
|
||||
auto* call_get_dims = ctx.dst->CallStmt(ctx.dst->Call(
|
||||
|
||||
@@ -544,8 +544,7 @@ struct CanonicalizeEntryPointIO::State {
|
||||
wrapper_body.Push(ctx.dst->CallStmt(call_inner));
|
||||
} else {
|
||||
// Capture the result of calling the original function.
|
||||
auto* inner_result =
|
||||
ctx.dst->Let(ctx.dst->Symbols().New("inner_result"), nullptr, call_inner);
|
||||
auto* inner_result = ctx.dst->Let(ctx.dst->Symbols().New("inner_result"), call_inner);
|
||||
wrapper_body.Push(ctx.dst->Decl(inner_result));
|
||||
|
||||
// Process the original return type to determine the outputs that the
|
||||
|
||||
@@ -79,7 +79,7 @@ struct CombineSamplers::State {
|
||||
/// Group 0 and binding 0 are used, with collisions disabled.
|
||||
/// @returns the newly-created attribute list
|
||||
auto Attributes() const {
|
||||
utils::Vector<const ast::Attribute*, 3> attributes = ctx.dst->GroupAndBinding(0, 0);
|
||||
utils::Vector<const ast::Attribute*, 3> attributes{ctx.dst->Group(0), ctx.dst->Binding(0)};
|
||||
attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kBindingPointCollision));
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ struct DecomposeMemoryAccess::State {
|
||||
// }
|
||||
auto load = LoadFunc(buf_ty, arr_ty->ElemType()->UnwrapRef(), var_user);
|
||||
auto* arr = b.Var(b.Symbols().New("arr"), CreateASTTypeFor(ctx, arr_ty));
|
||||
auto* i = b.Var(b.Symbols().New("i"), nullptr, b.Expr(0_u));
|
||||
auto* i = b.Var(b.Symbols().New("i"), b.Expr(0_u));
|
||||
auto* for_init = b.Decl(i);
|
||||
auto* for_cond = b.create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLessThan, b.Expr(i), b.Expr(u32(arr_ty->Count())));
|
||||
@@ -557,10 +557,10 @@ struct DecomposeMemoryAccess::State {
|
||||
// }
|
||||
// return arr;
|
||||
// }
|
||||
auto* array = b.Var(b.Symbols().New("array"), nullptr, b.Expr("value"));
|
||||
auto* array = b.Var(b.Symbols().New("array"), b.Expr("value"));
|
||||
auto store =
|
||||
StoreFunc(buf_ty, arr_ty->ElemType()->UnwrapRef(), var_user);
|
||||
auto* i = b.Var(b.Symbols().New("i"), nullptr, b.Expr(0_u));
|
||||
auto* i = b.Var(b.Symbols().New("i"), b.Expr(0_u));
|
||||
auto* for_init = b.Decl(i);
|
||||
auto* for_cond = b.create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLessThan, b.Expr(i), b.Expr(u32(arr_ty->Count())));
|
||||
|
||||
@@ -158,7 +158,7 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformStridedArray) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(32))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4u>(32), b.MemberAccessor("s", "a"))),
|
||||
@@ -206,7 +206,7 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformDefaultStridedArray) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(b.ty.vec4<f32>(), 4_u, 16))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0));
|
||||
b.Func(
|
||||
"f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
@@ -252,7 +252,7 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageStridedArray) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(32))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Group(0), b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4u>(32), b.MemberAccessor("s", "a"))),
|
||||
@@ -300,7 +300,7 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageDefaultStridedArray) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(4))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Group(0), b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4u>(4), b.MemberAccessor("s", "a"))),
|
||||
@@ -344,8 +344,8 @@ TEST_F(DecomposeStridedArrayTest, WriteStorageStridedArray) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(32))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty.array<f32, 4u>(32))),
|
||||
@@ -398,8 +398,8 @@ TEST_F(DecomposeStridedArrayTest, WriteStorageDefaultStridedArray) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(4))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty.array<f32, 4u>(4))),
|
||||
@@ -450,14 +450,14 @@ TEST_F(DecomposeStridedArrayTest, ReadWriteViaPointerLets) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array<f32, 4u>(32))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "a")))),
|
||||
b.Decl(b.Let("b", nullptr, b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
|
||||
b.Decl(b.Let("c", nullptr, b.Deref("b"))),
|
||||
b.Decl(b.Let("d", nullptr, b.IndexAccessor(b.Deref("b"), 1_i))),
|
||||
b.Decl(b.Let("a", b.AddressOf(b.MemberAccessor("s", "a")))),
|
||||
b.Decl(b.Let("b", b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
|
||||
b.Decl(b.Let("c", b.Deref("b"))),
|
||||
b.Decl(b.Let("d", b.IndexAccessor(b.Deref("b"), 1_i))),
|
||||
b.Assign(b.Deref("b"), b.Construct(b.ty.array<f32, 4u>(32), 1_f, 2_f, 3_f, 4_f)),
|
||||
b.Assign(b.IndexAccessor(b.Deref("b"), 1_i), 5_f),
|
||||
},
|
||||
@@ -511,8 +511,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) {
|
||||
ProgramBuilder b;
|
||||
b.Alias("ARR", b.ty.array<f32, 4u>(32));
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.type_name("ARR"))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
|
||||
@@ -581,8 +581,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
|
||||
b.ty.array(b.ty.type_name("ARR_A"), 3_u, 16), //
|
||||
4_u, 128));
|
||||
auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.type_name("ARR_B"))});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", b.ty.type_name("ARR_B"), b.MemberAccessor("s", "a"))),
|
||||
|
||||
@@ -76,7 +76,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
@@ -132,7 +132,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0));
|
||||
b.Func(
|
||||
"f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
@@ -185,7 +185,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
@@ -238,8 +238,8 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
@@ -295,8 +295,8 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func(
|
||||
"f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
@@ -349,8 +349,8 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageMatrix) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Assign(b.MemberAccessor("s", "m"),
|
||||
@@ -407,8 +407,8 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageColumn) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Assign(b.IndexAccessor(b.MemberAccessor("s", "m"), 1_i), b.vec2<f32>(1_f, 2_f)),
|
||||
@@ -466,15 +466,15 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
|
||||
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
|
||||
}),
|
||||
});
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0),
|
||||
b.Binding(0));
|
||||
b.Func("f", utils::Empty, b.ty.void_(),
|
||||
utils::Vector{
|
||||
b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))),
|
||||
b.Decl(b.Let("b", nullptr, b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
|
||||
b.Decl(b.Let("x", nullptr, b.Deref("b"))),
|
||||
b.Decl(b.Let("y", nullptr, b.IndexAccessor(b.Deref("b"), 1_i))),
|
||||
b.Decl(b.Let("z", nullptr, b.IndexAccessor("x", 1_i))),
|
||||
b.Decl(b.Let("a", b.AddressOf(b.MemberAccessor("s", "m")))),
|
||||
b.Decl(b.Let("b", b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
|
||||
b.Decl(b.Let("x", b.Deref("b"))),
|
||||
b.Decl(b.Let("y", b.IndexAccessor(b.Deref("b"), 1_i))),
|
||||
b.Decl(b.Let("z", b.IndexAccessor("x", 1_i))),
|
||||
b.Assign(b.Deref("b"), b.mat2x2<f32>(b.vec2<f32>(1_f, 2_f), b.vec2<f32>(3_f, 4_f))),
|
||||
b.Assign(b.IndexAccessor(b.Deref("b"), 1_i), b.vec2<f32>(5_f, 6_f)),
|
||||
},
|
||||
|
||||
@@ -84,7 +84,7 @@ class State {
|
||||
auto hoist_pointer_to = [&](const ast::Expression* expr) {
|
||||
auto name = b.Sym();
|
||||
auto* ptr = b.AddressOf(ctx.Clone(expr));
|
||||
auto* decl = b.Decl(b.Let(name, nullptr, ptr));
|
||||
auto* decl = b.Decl(b.Let(name, ptr));
|
||||
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
|
||||
return name;
|
||||
};
|
||||
@@ -92,7 +92,7 @@ class State {
|
||||
// Helper function to hoist `expr` to a let declaration.
|
||||
auto hoist_expr_to_let = [&](const ast::Expression* expr) {
|
||||
auto name = b.Sym();
|
||||
auto* decl = b.Decl(b.Let(name, nullptr, ctx.Clone(expr)));
|
||||
auto* decl = b.Decl(b.Let(name, ctx.Clone(expr)));
|
||||
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
|
||||
return name;
|
||||
};
|
||||
|
||||
@@ -122,7 +122,6 @@ void FirstIndexOffset::Run(CloneContext& ctx, const DataMap& inputs, DataMap& ou
|
||||
// Create a global to hold the uniform buffer
|
||||
Symbol buffer_name = ctx.dst->Sym();
|
||||
ctx.dst->GlobalVar(buffer_name, ctx.dst->ty.Of(struct_), ast::StorageClass::kUniform,
|
||||
nullptr,
|
||||
utils::Vector{
|
||||
ctx.dst->create<ast::BindingAttribute>(ub_binding),
|
||||
ctx.dst->create<ast::GroupAttribute>(ub_group),
|
||||
|
||||
@@ -158,8 +158,7 @@ class LocalizeStructArrayAssignment::State {
|
||||
// Store the address of the member access into a let as we need to read
|
||||
// the value twice e.g. let tint_symbol = &(s.a1);
|
||||
auto mem_access_ptr = b.Sym();
|
||||
s.insert_before_stmts.Push(
|
||||
b.Decl(b.Let(mem_access_ptr, nullptr, b.AddressOf(mem_access))));
|
||||
s.insert_before_stmts.Push(b.Decl(b.Let(mem_access_ptr, b.AddressOf(mem_access))));
|
||||
|
||||
// Disable further transforms when cloning
|
||||
TINT_SCOPED_ASSIGNMENT(s.process_nested_nodes, false);
|
||||
@@ -167,8 +166,7 @@ class LocalizeStructArrayAssignment::State {
|
||||
// Copy entire array out of struct into local temp var
|
||||
// e.g. var tint_symbol_1 = *(tint_symbol);
|
||||
auto tmp_var = b.Sym();
|
||||
s.insert_before_stmts.Push(
|
||||
b.Decl(b.Var(tmp_var, nullptr, b.Deref(mem_access_ptr))));
|
||||
s.insert_before_stmts.Push(b.Decl(b.Var(tmp_var, b.Deref(mem_access_ptr))));
|
||||
|
||||
// Replace input index_access with a clone of itself, but with its
|
||||
// .object replaced by the new temp var. This is returned from this
|
||||
|
||||
@@ -132,11 +132,11 @@ struct MultiplanarExternalTexture::State {
|
||||
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 @@ struct MultiplanarExternalTexture::State {
|
||||
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")),
|
||||
});
|
||||
|
||||
@@ -148,7 +148,7 @@ void NumWorkgroupsFromUniform::Run(CloneContext& ctx, const DataMap& inputs, Dat
|
||||
|
||||
num_workgroups_ubo = ctx.dst->GlobalVar(
|
||||
ctx.dst->Sym(), ctx.dst->ty.Of(num_workgroups_struct), ast::StorageClass::kUniform,
|
||||
ctx.dst->GroupAndBinding(group, binding));
|
||||
ctx.dst->Group(group), ctx.dst->Binding(binding));
|
||||
}
|
||||
return num_workgroups_ubo;
|
||||
};
|
||||
|
||||
@@ -427,7 +427,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
|
||||
auto clone_maybe_hoisted = [&](const ast::Expression* e) -> const ast::Expression* {
|
||||
if (to_hoist.count(e)) {
|
||||
auto name = b.Symbols().New();
|
||||
auto* v = b.Let(name, nullptr, ctx.Clone(e));
|
||||
auto* v = b.Let(name, ctx.Clone(e));
|
||||
auto* decl = b.Decl(v);
|
||||
curr_stmts->Push(decl);
|
||||
return b.Expr(name);
|
||||
@@ -476,7 +476,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
|
||||
// let r = temp;
|
||||
|
||||
auto name = b.Sym();
|
||||
curr_stmts->Push(b.Decl(b.Var(name, nullptr, decompose(bin_expr->lhs))));
|
||||
curr_stmts->Push(b.Decl(b.Var(name, decompose(bin_expr->lhs))));
|
||||
|
||||
const ast::Expression* if_cond = nullptr;
|
||||
if (bin_expr->IsLogicalOr()) {
|
||||
|
||||
@@ -181,8 +181,7 @@ struct SimplifyPointers::State {
|
||||
// Create a new variable
|
||||
auto saved_name = ctx.dst->Symbols().New(
|
||||
ctx.src->Symbols().NameFor(var->Declaration()->symbol) + "_save");
|
||||
auto* decl =
|
||||
ctx.dst->Decl(ctx.dst->Let(saved_name, nullptr, ctx.Clone(idx_expr)));
|
||||
auto* decl = ctx.dst->Decl(ctx.dst->Let(saved_name, ctx.Clone(idx_expr)));
|
||||
saved.emplace_back(decl);
|
||||
// Record the substitution of `idx_expr` to the saved variable
|
||||
// with the symbol `saved_name`. This will be used by the
|
||||
|
||||
@@ -79,7 +79,7 @@ struct SpirvAtomic::State {
|
||||
auto* block = call->Stmt()->Block()->Declaration();
|
||||
auto old_value = b.Symbols().New("old_value");
|
||||
auto old_value_decl = b.Decl(b.Let(
|
||||
old_value, nullptr,
|
||||
old_value,
|
||||
b.MemberAccessor(b.Call(sem::str(stub->builtin), std::move(out_args)),
|
||||
b.Expr("old_value"))));
|
||||
ctx.InsertBefore(block->statements, call->Stmt()->Declaration(),
|
||||
|
||||
@@ -141,7 +141,7 @@ class State {
|
||||
|
||||
auto ip = utils::GetInsertionPoint(ctx, stmt);
|
||||
auto var_name = b.Sym();
|
||||
auto* decl = b.Decl(b.Var(var_name, nullptr, ctx.Clone(expr)));
|
||||
auto* decl = b.Decl(b.Var(var_name, ctx.Clone(expr)));
|
||||
ctx.InsertBefore(ip.first->Declaration()->statements, ip.second, decl);
|
||||
|
||||
ctx.InsertBefore(ip.first->Declaration()->statements, ip.second, IfDiscardReturn(stmt));
|
||||
|
||||
@@ -33,7 +33,7 @@ TEST_F(GetInsertionPointTest, Block) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, expr));
|
||||
auto* var = b.Decl(b.Var("a", expr));
|
||||
auto* block = b.Block(var);
|
||||
b.Func("f", tint::utils::Empty, b.ty.void_(), tint::utils::Vector{block});
|
||||
|
||||
@@ -55,7 +55,7 @@ TEST_F(GetInsertionPointTest, ForLoopInit) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, expr));
|
||||
auto* var = b.Decl(b.Var("a", expr));
|
||||
auto* fl = b.For(var, b.Expr(true), nullptr, b.Block());
|
||||
auto* func_block = b.Block(fl);
|
||||
b.Func("f", tint::utils::Empty, b.ty.void_(), tint::utils::Vector{func_block});
|
||||
@@ -77,7 +77,7 @@ TEST_F(GetInsertionPointTest, ForLoopCont_Invalid) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, expr));
|
||||
auto* var = b.Decl(b.Var("a", expr));
|
||||
auto* s = b.For({}, b.Expr(true), var, b.Block());
|
||||
b.Func("f", tint::utils::Empty, b.ty.void_(), tint::utils::Vector{s});
|
||||
|
||||
|
||||
@@ -199,8 +199,8 @@ class HoistToDeclBefore::State {
|
||||
auto name = b.Symbols().New(decl_name);
|
||||
|
||||
// Construct the let/var that holds the hoisted expr
|
||||
auto* v = as_let ? static_cast<const ast::Variable*>(b.Let(name, nullptr, ctx.Clone(expr)))
|
||||
: static_cast<const ast::Variable*>(b.Var(name, nullptr, ctx.Clone(expr)));
|
||||
auto* v = as_let ? static_cast<const ast::Variable*>(b.Let(name, ctx.Clone(expr)))
|
||||
: static_cast<const ast::Variable*>(b.Var(name, ctx.Clone(expr)));
|
||||
auto* decl = b.Decl(v);
|
||||
|
||||
if (!InsertBefore(before_expr->Stmt(), decl)) {
|
||||
|
||||
@@ -35,7 +35,7 @@ TEST_F(HoistToDeclBeforeTest, VarInit) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, expr));
|
||||
auto* var = b.Decl(b.Var("a", expr));
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -67,7 +67,7 @@ TEST_F(HoistToDeclBeforeTest, ForLoopInit) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* s = b.For(b.Decl(b.Var("a", nullptr, expr)), b.Expr(true), nullptr, b.Block());
|
||||
auto* s = b.For(b.Decl(b.Var("a", expr)), b.Expr(true), nullptr, b.Block());
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{s});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -141,7 +141,7 @@ TEST_F(HoistToDeclBeforeTest, ForLoopCont) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* s = b.For(nullptr, b.Expr(true), b.Decl(b.Var("a", nullptr, expr)), b.Block());
|
||||
auto* s = b.For(nullptr, b.Expr(true), b.Decl(b.Var("a", expr)), b.Block());
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{s});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -269,7 +269,7 @@ TEST_F(HoistToDeclBeforeTest, Array1D) {
|
||||
ProgramBuilder b;
|
||||
auto* var1 = b.Decl(b.Var("a", b.ty.array<i32, 10>()));
|
||||
auto* expr = b.IndexAccessor("a", 0_i);
|
||||
auto* var2 = b.Decl(b.Var("b", nullptr, expr));
|
||||
auto* var2 = b.Decl(b.Var("b", expr));
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var1, var2});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -304,7 +304,7 @@ TEST_F(HoistToDeclBeforeTest, Array2D) {
|
||||
|
||||
auto* var1 = b.Decl(b.Var("a", b.ty.array(b.ty.array<i32, 10>(), 10_i)));
|
||||
auto* expr = b.IndexAccessor(b.IndexAccessor("a", 0_i), 0_i);
|
||||
auto* var2 = b.Decl(b.Var("b", nullptr, expr));
|
||||
auto* var2 = b.Decl(b.Var("b", expr));
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var1, var2});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -377,7 +377,7 @@ TEST_F(HoistToDeclBeforeTest, Prepare_ForLoopCont) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Expr(1_i);
|
||||
auto* s = b.For(nullptr, b.Expr(true), b.Decl(b.Var("a", nullptr, expr)), b.Block());
|
||||
auto* s = b.For(nullptr, b.Expr(true), b.Decl(b.Var("a", expr)), b.Block());
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{s});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -462,7 +462,7 @@ TEST_F(HoistToDeclBeforeTest, InsertBefore_Block) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
b.Func("foo", utils::Empty, b.ty.void_(), utils::Empty);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, b.Expr(1_i)));
|
||||
auto* var = b.Decl(b.Var("a", b.Expr(1_i)));
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var});
|
||||
|
||||
Program original(std::move(b));
|
||||
@@ -500,7 +500,7 @@ TEST_F(HoistToDeclBeforeTest, InsertBefore_ForLoopInit) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
b.Func("foo", utils::Empty, b.ty.void_(), utils::Empty);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, b.Expr(1_i)));
|
||||
auto* var = b.Decl(b.Var("a", b.Expr(1_i)));
|
||||
auto* s = b.For(var, b.Expr(true), nullptr, b.Block());
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{s});
|
||||
|
||||
@@ -541,7 +541,7 @@ TEST_F(HoistToDeclBeforeTest, InsertBefore_ForLoopCont) {
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
b.Func("foo", utils::Empty, b.ty.void_(), utils::Empty);
|
||||
auto* var = b.Decl(b.Var("a", nullptr, b.Expr(1_i)));
|
||||
auto* var = b.Decl(b.Var("a", b.Expr(1_i)));
|
||||
auto* cont = b.CompoundAssign("a", b.Expr(1_i), ast::BinaryOp::kAdd);
|
||||
auto* s = b.For(nullptr, b.Expr(true), cont, b.Block());
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var, s});
|
||||
|
||||
@@ -260,11 +260,8 @@ struct State {
|
||||
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
|
||||
// The decorated variable with struct type
|
||||
ctx.dst->GlobalVar(GetVertexBufferName(i), ctx.dst->ty.Of(struct_type),
|
||||
ast::StorageClass::kStorage, ast::Access::kRead,
|
||||
utils::Vector{
|
||||
ctx.dst->create<ast::BindingAttribute>(i),
|
||||
ctx.dst->create<ast::GroupAttribute>(cfg.pulling_group),
|
||||
});
|
||||
ast::StorageClass::kStorage, ast::Access::kRead, ctx.dst->Binding(i),
|
||||
ctx.dst->Group(cfg.pulling_group));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,7 +300,7 @@ struct State {
|
||||
}
|
||||
|
||||
// let pulling_offset_n = <attribute_offset>
|
||||
stmts.Push(ctx.dst->Decl(ctx.dst->Let(buffer_array_base, nullptr, attribute_offset)));
|
||||
stmts.Push(ctx.dst->Decl(ctx.dst->Let(buffer_array_base, attribute_offset)));
|
||||
|
||||
for (const VertexAttributeDescriptor& attribute_desc : buffer_layout.attributes) {
|
||||
auto it = location_info.find(attribute_desc.shader_location);
|
||||
|
||||
Reference in New Issue
Block a user