GLSL: fix Select op with a bool vector condition.

The fix is in the mix().

Bug: tint:1429
Change-Id: Id128ead6b124cd364f45a860ad991977be94be5b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80660
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White
2022-02-15 20:00:27 +00:00
committed by Tint LUCI CQ
parent 5f6a185d02
commit 4a15605be7
21 changed files with 55 additions and 774 deletions

View File

@@ -818,6 +818,24 @@ bool GeneratorImpl::EmitSelectCall(std::ostream& out,
auto* expr_false = expr->args[0];
auto* expr_true = expr->args[1];
auto* expr_cond = expr->args[2];
// GLSL does not support ternary expressions with a bool vector conditional,
// but it does support mix() with same.
if (TypeOf(expr_cond)->UnwrapRef()->is_bool_vector()) {
out << "mix(";
if (!EmitExpression(out, expr_false)) {
return false;
}
out << ", ";
if (!EmitExpression(out, expr_true)) {
return false;
}
out << ", ";
if (!EmitExpression(out, expr_cond)) {
return false;
}
out << ")";
return true;
}
ScopedParen paren(out);
if (!EmitExpression(out, expr_cond)) {
return false;

View File

@@ -287,7 +287,7 @@ TEST_F(GlslGeneratorImplTest_Builtin, Select_Vector) {
gen.increment_indent();
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "(bvec2(true, false) ? ivec2(3, 4) : ivec2(1, 2))");
EXPECT_EQ(out.str(), "mix(ivec2(1, 2), ivec2(3, 4), bvec2(true, false))");
}
TEST_F(GlslGeneratorImplTest_Builtin, Modf_Scalar) {