GLSL: fix countOneBits().

This change essentially relands 10c554ecf4,
aka https://dawn-review.googlesource.com/c/tint/+/82140.

(Somehow, I managed to revert most of that in the subsequent CL for
reverseBits. I suspect a bad upstream and/or rebase.)

Bug: tint:1430
Change-Id: Iba2688294dcd7d3008ee9da78957a7a464ca1c0f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82220
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-03-01 14:25:42 +00:00
committed by Tint LUCI CQ
parent bee5fa6881
commit 4acf466ff9
24 changed files with 64 additions and 343 deletions

View File

@@ -646,6 +646,9 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out,
if (builtin->IsTexture()) {
return EmitTextureCall(out, call, builtin);
}
if (builtin->Type() == sem::BuiltinType::kCountOneBits) {
return EmitCountOneBitsCall(out, expr);
}
if (builtin->Type() == sem::BuiltinType::kSelect) {
return EmitSelectCall(out, expr);
}
@@ -940,6 +943,23 @@ bool GeneratorImpl::EmitEmulatedFMA(std::ostream& out,
return true;
}
bool GeneratorImpl::EmitCountOneBitsCall(std::ostream& out,
const ast::CallExpression* expr) {
// GLSL's bitCount returns an integer type, so cast it to the appropriate
// unsigned type.
if (!EmitType(out, TypeOf(expr)->UnwrapRef(), ast::StorageClass::kNone,
ast::Access::kReadWrite, "")) {
return false;
}
out << "(bitCount(";
if (!EmitExpression(out, expr->args[0])) {
return false;
}
out << "))";
return true;
}
bool GeneratorImpl::EmitSelectCall(std::ostream& out,
const ast::CallExpression* expr) {
auto* expr_false = expr->args[0];
@@ -1534,7 +1554,7 @@ std::string GeneratorImpl::generate_builtin_name(const sem::Builtin* builtin) {
case sem::BuiltinType::kAtan2:
return "atan";
case sem::BuiltinType::kCountOneBits:
return "countbits";
return "bitCount";
case sem::BuiltinType::kDpdx:
return "dFdx";
case sem::BuiltinType::kDpdxCoarse:

View File

@@ -204,6 +204,11 @@ class GeneratorImpl : public TextGenerator {
/// @param out the output of the expression stream
/// @param expr the call expression
/// @returns true if the call expression is emitted
bool EmitCountOneBitsCall(std::ostream& out, const ast::CallExpression* expr);
/// Handles generating a call to the `countOneBits()` builtin
/// @param out the output of the expression stream
/// @param expr the call expression
/// @returns true if the call expression is emitted
bool EmitSelectCall(std::ostream& out, const ast::CallExpression* expr);
/// Handles generating a call to the `dot()` builtin
/// @param out the output of the expression stream

View File

@@ -198,7 +198,7 @@ INSTANTIATE_TEST_SUITE_P(
BuiltinData{BuiltinType::kClamp, ParamType::kU32, "clamp"},
BuiltinData{BuiltinType::kCos, ParamType::kF32, "cos"},
BuiltinData{BuiltinType::kCosh, ParamType::kF32, "cosh"},
BuiltinData{BuiltinType::kCountOneBits, ParamType::kU32, "countbits"},
BuiltinData{BuiltinType::kCountOneBits, ParamType::kU32, "bitCount"},
BuiltinData{BuiltinType::kCross, ParamType::kF32, "cross"},
BuiltinData{BuiltinType::kDeterminant, ParamType::kF32, "determinant"},
BuiltinData{BuiltinType::kDistance, ParamType::kF32, "distance"},