tint: Add ProgramBuilder::Else() helper

This aids readability when building chains of if-else statements.

Change-Id: I77ed5a16421bd52302db61f2776d55971838e122
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88366
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price
2022-05-02 14:53:36 +00:00
parent 41e4d9a34c
commit 8aff0ed684
19 changed files with 107 additions and 90 deletions

View File

@@ -329,13 +329,13 @@ struct MultiplanarExternalTexture::State {
b.Block(
// color = textureLoad(plane0, coord, 0).rgb;
b.Assign("color", b.MemberAccessor(single_plane_call, "rgb"))),
b.Block(
b.Else(b.Block(
// color = vec4<f32>(plane_0_call.r, plane_1_call.rg, 1.0) *
// params.yuvToRgbConversionMatrix;
b.Assign("color",
b.Mul(b.vec4<f32>(b.MemberAccessor(plane_0_call, "r"),
b.MemberAccessor(plane_1_call, "rg"), 1.0f),
b.MemberAccessor("params", "yuvToRgbConversionMatrix"))))),
b.MemberAccessor("params", "yuvToRgbConversionMatrix")))))),
// color = gammaConversion(color, gammaDecodeParams);
b.Assign("color", b.Call("gammaCorrection", "color",
b.MemberAccessor("params", "gammaDecodeParams"))),

View File

@@ -123,7 +123,7 @@ class HoistToDeclBefore::State {
// Move the 'else-if' into the new `else` block as a plain 'if'.
auto* cond = ctx.Clone(else_if->condition);
auto* body = ctx.Clone(else_if->body);
auto* new_if = b.If(cond, body, ctx.Clone(else_if->else_statement));
auto* new_if = b.If(cond, body, b.Else(ctx.Clone(else_if->else_statement)));
body_stmts.emplace_back(new_if);
// Replace the 'else-if' with the new 'else' block.

View File

@@ -184,9 +184,9 @@ TEST_F(HoistToDeclBeforeTest, ElseIf) {
ProgramBuilder b;
auto* var = b.Decl(b.Var("a", b.ty.bool_()));
auto* expr = b.Expr("a");
auto* s = b.If(b.Expr(true), b.Block(), //
b.If(expr, b.Block(), //
b.Block()));
auto* s = b.If(b.Expr(true), b.Block(), //
b.Else(b.If(expr, b.Block(), //
b.Else(b.Block()))));
b.Func("f", {}, b.ty.void_(), {var, s});
Program original(std::move(b));
@@ -378,9 +378,9 @@ TEST_F(HoistToDeclBeforeTest, Prepare_ElseIf) {
ProgramBuilder b;
auto* var = b.Decl(b.Var("a", b.ty.bool_()));
auto* expr = b.Expr("a");
auto* s = b.If(b.Expr(true), b.Block(), //
b.If(expr, b.Block(), //
b.Block()));
auto* s = b.If(b.Expr(true), b.Block(), //
b.Else(b.If(expr, b.Block(), //
b.Else(b.Block()))));
b.Func("f", {}, b.ty.void_(), {var, s});
Program original(std::move(b));
@@ -552,9 +552,9 @@ TEST_F(HoistToDeclBeforeTest, InsertBefore_ElseIf) {
ProgramBuilder b;
b.Func("foo", {}, b.ty.void_(), {});
auto* var = b.Decl(b.Var("a", b.ty.bool_()));
auto* elseif = b.If(b.Expr("a"), b.Block(), b.Block());
auto* elseif = b.If(b.Expr("a"), b.Block(), b.Else(b.Block()));
auto* s = b.If(b.Expr(true), b.Block(), //
elseif);
b.Else(elseif));
b.Func("f", {}, b.ty.void_(), {var, s});
Program original(std::move(b));