[spirv-writer] Fix global constant emitting

This CL fixes the emitting of global constants to use the correct
`OpConstantComposite` call when adding to the types section. A TODO is
added to generate `OpCompositeConstruct` when we need to generate
initializers inside functions.

Bug: tint:5
Change-Id: I1bbf6c68e21b546d6a643b4c99c7d2c9317bfcbd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18440
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-03-31 21:15:51 +00:00 committed by dan sinclair
parent a085c7bbe2
commit 73e1ef825e
4 changed files with 7 additions and 5 deletions

View File

@ -371,7 +371,9 @@ uint32_t Builder::GenerateConstructorExpression(
const_to_id_[str] = result.to_i(); const_to_id_[str] = result.to_i();
push_type(spv::Op::OpCompositeConstruct, ops); // TODO(dsinclair) For non-global constant's this should be
// in the instructions and ben an OpCompositeConstruct call.
push_type(spv::Op::OpConstantComposite, ops);
return result.to_i(); return result.to_i();
} }

View File

@ -69,7 +69,7 @@ TEST_F(BuilderTest, Constructor_Type) {
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
%3 = OpConstant %2 1 %3 = OpConstant %2 1
%4 = OpConstant %2 3 %4 = OpConstant %2 3
%5 = OpCompositeConstruct %1 %3 %3 %4 %5 = OpConstantComposite %1 %3 %3 %4
)"); )");
} }

View File

@ -95,7 +95,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
%3 = OpConstant %2 1 %3 = OpConstant %2 1
%4 = OpConstant %2 3 %4 = OpConstant %2 3
%5 = OpCompositeConstruct %1 %3 %3 %4 %5 = OpConstantComposite %1 %3 %3 %4
%7 = OpTypePointer Output %2 %7 = OpTypePointer Output %2
%6 = OpVariable %7 Output %5 %6 = OpVariable %7 Output %5
)"); )");
@ -128,7 +128,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
%3 = OpConstant %2 1 %3 = OpConstant %2 1
%4 = OpConstant %2 3 %4 = OpConstant %2 3
%5 = OpCompositeConstruct %1 %3 %3 %4 %5 = OpConstantComposite %1 %3 %3 %4
)"); )");
} }

View File

@ -67,7 +67,7 @@ TEST_F(BuilderTest, Return_WithValue) {
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
%3 = OpConstant %2 1 %3 = OpConstant %2 1
%4 = OpConstant %2 3 %4 = OpConstant %2 3
%5 = OpCompositeConstruct %1 %3 %3 %4 %5 = OpConstantComposite %1 %3 %3 %4
)"); )");
EXPECT_EQ(DumpInstructions(b.instructions()), R"(OpReturnValue %5 EXPECT_EQ(DumpInstructions(b.instructions()), R"(OpReturnValue %5
)"); )");