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