[spirv-writer] Generate load of conditionals.

This CL adds the missing load of conditional values.

Bug: tint:327
Change-Id: I836ecfacb3a237a54886ebc7625c9449ba33fdc7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32700
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-11-13 22:01:29 +00:00 committed by Commit Bot service account
parent 10d5c6a6b6
commit c7c8f58f17
2 changed files with 34 additions and 0 deletions

View File

@ -1998,6 +1998,7 @@ bool Builder::GenerateConditionalBlock(
if (cond_id == 0) {
return false;
}
cond_id = GenerateLoadIfNeeded(cond->result_type(), cond_id);
auto merge_block = result_op();
auto merge_block_id = merge_block.to_i();

View File

@ -627,6 +627,39 @@ OpReturnValue %5
)");
}
TEST_F(BuilderTest, If_WithLoad_Bug327) {
// var a : bool;
// if (a) {
// }
ast::type::BoolType bool_type;
auto var = std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction,
&bool_type);
td.RegisterVariableForTesting(var.get());
ast::IfStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeBool
%2 = OpTypePointer Function %3
%1 = OpVariable %2 Function
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(%4 = OpLoad %3 %1
OpSelectionMerge %5 None
OpBranchConditional %4 %6 %5
%6 = OpLabel
OpBranch %5
%5 = OpLabel
)");
}
} // namespace
} // namespace spirv
} // namespace writer