[spirv-writer] Add support for all intrinsic.

This CL adds support for generating an OpAll .

Bug: tint:5
Change-Id: I70a92bc68064625324d6c7b59220a901ced76f96
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22621
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-06-04 17:05:43 +00:00 committed by dan sinclair
parent 3e7dc82b35
commit 0bcb50b04a
2 changed files with 37 additions and 0 deletions

View File

@ -1248,6 +1248,8 @@ uint32_t Builder::GenerateIntrinsic(const std::string& name,
spv::Op op = spv::Op::OpNop;
if (name == "any") {
op = spv::Op::OpAny;
} else if (name == "all") {
op = spv::Op::OpAll;
}
if (op == spv::Op::OpNop) {
error_ = "unable to determine operator for: " + name;

View File

@ -68,6 +68,41 @@ TEST_F(BuilderTest, Call_Any) {
)");
}
TEST_F(BuilderTest, Call_All) {
ast::type::BoolType bool_type;
ast::type::VectorType vec3(&bool_type, 3);
auto var =
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &vec3);
ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("v"));
ast::CallExpression expr(std::make_unique<ast::IdentifierExpression>("all"),
std::move(params));
Context ctx;
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
EXPECT_EQ(b.GenerateCallExpression(&expr), 6u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeBool
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
%1 = OpVariable %2 Private %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(%7 = OpLoad %3 %1
%6 = OpAll %4 %7
)");
}
} // namespace
} // namespace spirv
} // namespace writer