From 0bcb50b04aabb253a9d542b65e42f55dec98a2fa Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 4 Jun 2020 17:05:43 +0000 Subject: [PATCH] [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 --- src/writer/spirv/builder.cc | 2 ++ src/writer/spirv/builder_intrinsic_test.cc | 35 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 7d34b2f460..1ad79b90eb 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -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; diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index 054f9f42d4..d819ad554f 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -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("v", ast::StorageClass::kPrivate, &vec3); + + ast::ExpressionList params; + params.push_back(std::make_unique("v")); + ast::CallExpression expr(std::make_unique("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