From 73e1ef825ebe7ba0750f7a3b66e19e3a6ee0cc53 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 31 Mar 2020 21:15:51 +0000 Subject: [PATCH] [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 --- src/writer/spirv/builder.cc | 4 +++- src/writer/spirv/builder_constructor_expression_test.cc | 2 +- src/writer/spirv/builder_global_variable_test.cc | 4 ++-- src/writer/spirv/builder_return_test.cc | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index d0e10ebb14..35017b9bc0 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -371,7 +371,9 @@ uint32_t Builder::GenerateConstructorExpression( 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(); } diff --git a/src/writer/spirv/builder_constructor_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc index 51bb271f05..7a5fa2f668 100644 --- a/src/writer/spirv/builder_constructor_expression_test.cc +++ b/src/writer/spirv/builder_constructor_expression_test.cc @@ -69,7 +69,7 @@ TEST_F(BuilderTest, Constructor_Type) { %1 = OpTypeVector %2 3 %3 = OpConstant %2 1 %4 = OpConstant %2 3 -%5 = OpCompositeConstruct %1 %3 %3 %4 +%5 = OpConstantComposite %1 %3 %3 %4 )"); } diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 3f2deacfd9..09fed56b42 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -95,7 +95,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) { %1 = OpTypeVector %2 3 %3 = OpConstant %2 1 %4 = OpConstant %2 3 -%5 = OpCompositeConstruct %1 %3 %3 %4 +%5 = OpConstantComposite %1 %3 %3 %4 %7 = OpTypePointer Output %2 %6 = OpVariable %7 Output %5 )"); @@ -128,7 +128,7 @@ TEST_F(BuilderTest, GlobalVar_Const) { %1 = OpTypeVector %2 3 %3 = OpConstant %2 1 %4 = OpConstant %2 3 -%5 = OpCompositeConstruct %1 %3 %3 %4 +%5 = OpConstantComposite %1 %3 %3 %4 )"); } diff --git a/src/writer/spirv/builder_return_test.cc b/src/writer/spirv/builder_return_test.cc index 038bbb7a5d..f61805bf2d 100644 --- a/src/writer/spirv/builder_return_test.cc +++ b/src/writer/spirv/builder_return_test.cc @@ -67,7 +67,7 @@ TEST_F(BuilderTest, Return_WithValue) { %1 = OpTypeVector %2 3 %3 = OpConstant %2 1 %4 = OpConstant %2 3 -%5 = OpCompositeConstruct %1 %3 %3 %4 +%5 = OpConstantComposite %1 %3 %3 %4 )"); EXPECT_EQ(DumpInstructions(b.instructions()), R"(OpReturnValue %5 )");