GLSL: fix vector relational ops.

In GLSL, relational operators are only valid for scalar operands. For
vector operands, lessThan, greaterThan, etc must be used.

Bug: tint:1303

Change-Id: Ia800f89111630c756dc1b30ef0c6858fb520fb16
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69561
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Stephen White
2021-11-16 16:16:56 +00:00
committed by Tint LUCI CQ
parent 90eb5aa292
commit b9170c65fc
6 changed files with 65 additions and 16 deletions

View File

@@ -52,6 +52,19 @@
#include "src/writer/append_vector.h"
#include "src/writer/float_to_string.h"
namespace {
bool IsRelational(tint::ast::BinaryOp op) {
return op == tint::ast::BinaryOp::kEqual ||
op == tint::ast::BinaryOp::kNotEqual ||
op == tint::ast::BinaryOp::kLessThan ||
op == tint::ast::BinaryOp::kGreaterThan ||
op == tint::ast::BinaryOp::kLessThanEqual ||
op == tint::ast::BinaryOp::kGreaterThanEqual;
}
} // namespace
namespace tint {
namespace writer {
namespace glsl {
@@ -212,8 +225,47 @@ bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) {
return true;
}
bool GeneratorImpl::EmitVectorRelational(std::ostream& out,
const ast::BinaryExpression* expr) {
switch (expr->op) {
case ast::BinaryOp::kEqual:
out << "equal";
break;
case ast::BinaryOp::kNotEqual:
out << "notEqual";
break;
case ast::BinaryOp::kLessThan:
out << "lessThan";
break;
case ast::BinaryOp::kGreaterThan:
out << "greaterThan";
break;
case ast::BinaryOp::kLessThanEqual:
out << "lessThanEqual";
break;
case ast::BinaryOp::kGreaterThanEqual:
out << "greaterThanEqual";
break;
default:
break;
}
out << "(";
if (!EmitExpression(out, expr->lhs)) {
return false;
}
out << ", ";
if (!EmitExpression(out, expr->rhs)) {
return false;
}
out << ")";
return true;
}
bool GeneratorImpl::EmitBinary(std::ostream& out,
const ast::BinaryExpression* expr) {
if (IsRelational(expr->op) && !TypeOf(expr->lhs)->UnwrapRef()->is_scalar()) {
return EmitVectorRelational(out, expr);
}
if (expr->op == ast::BinaryOp::kLogicalAnd ||
expr->op == ast::BinaryOp::kLogicalOr) {
auto name = UniqueIdentifier(kTempNamePrefix);

View File

@@ -78,8 +78,14 @@ class GeneratorImpl : public TextGenerator {
bool EmitBinary(std::ostream& out, const ast::BinaryExpression* expr);
/// Handles generating a bitcast expression
/// @param out the output of the expression stream
/// @param expr the as expression
/// @returns true if the bitcast was emitted
/// @param expr the expression
/// @returns true if the binary expression was emitted
bool EmitVectorRelational(std::ostream& out,
const ast::BinaryExpression* expr);
/// Handles generating a vector relational expression
/// @param out the output of the expression stream
/// @param expr the expression
/// @returns true if the vector relational expression was emitted
bool EmitBitcast(std::ostream& out, const ast::BitcastExpression* expr);
/// Emits a list of statements
/// @param stmts the statement list