[spirv-writer] Generate loads for call parameters.

This CL updates the call code to emit an OpLoad if the parameter being
passed is a pointer.

Bug: tint:5
Change-Id: I19c2ffa1b55697173ded6d5509fecd37442e7966
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20501
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-28 17:31:00 +00:00 committed by dan sinclair
parent 228392558f
commit 40aa8d64aa
2 changed files with 50 additions and 1 deletions

View File

@ -904,7 +904,7 @@ uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
if (id == 0) {
return 0;
}
ops.push_back(Operand::Int(id));
ops.push_back(Operand::Int(GenerateLoadIfNeeded(param->result_type(), id)));
}
push_function_inst(spv::Op::OpExtInst, std::move(ops));

View File

@ -75,6 +75,55 @@ OpFunctionEnd
)");
}
TEST_F(BuilderTest, Call_GLSLMethod_WithLoad) {
ast::type::F32Type f32;
ast::type::VoidType void_type;
auto var = std::make_unique<ast::Variable>("ident",
ast::StorageClass::kPrivate, &f32);
ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("ident"));
ast::CallExpression expr(std::make_unique<ast::IdentifierExpression>(
std::vector<std::string>{"std", "round"}),
std::move(params));
Context ctx;
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
auto imp = std::make_unique<ast::Import>("GLSL.std.450", "std");
auto* glsl = imp.get();
mod.AddImport(std::move(imp));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Function func("a_func", {}, &void_type);
Builder b(&mod);
b.GenerateImport(glsl);
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(b.GenerateCallExpression(&expr), 9u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%1 = OpExtInstImport "GLSL.std.450"
OpName %2 "ident"
OpName %7 "a_func"
%4 = OpTypeFloat 32
%3 = OpTypePointer Private %4
%2 = OpVariable %3 Private
%6 = OpTypeVoid
%5 = OpTypeFunction %6
%7 = OpFunction %6 None %5
%8 = OpLabel
%10 = OpLoad %4 %2
%9 = OpExtInst %4 %1 Round %10
OpFunctionEnd
)");
}
} // namespace
} // namespace spirv
} // namespace writer