diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 7d511ee368..f9c1584808 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -274,6 +274,11 @@ bool Builder::GenerateStructType(ast::type::StructType* struct_type, auto struct_id = result.to_i(); auto impl = struct_type->impl(); + if (!struct_type->name().empty()) { + push_debug(spv::Op::OpName, + {Operand::Int(struct_id), Operand::String(struct_type->name())}); + } + std::vector ops; ops.push_back(result); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index ccace3b695..10f960d894 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -186,6 +186,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) { EXPECT_EQ(id, 1); EXPECT_EQ(b.types().size(), 1); + EXPECT_EQ(DumpInstructions(b.debug()), ""); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct )"); } @@ -201,6 +202,7 @@ TEST_F(BuilderTest_Type, GenerateStruct) { auto s = std::make_unique(ast::StructDecoration::kNone, std::move(members)); ast::type::StructType s_type(std::move(s)); + s_type.set_name("my_struct"); Builder b; auto id = b.GenerateTypeIfNeeded(&s_type); @@ -210,7 +212,8 @@ TEST_F(BuilderTest_Type, GenerateStruct) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" +OpMemberName %1 0 "a" )"); } @@ -225,6 +228,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) { auto s = std::make_unique(ast::StructDecoration::kBlock, std::move(members)); ast::type::StructType s_type(std::move(s)); + s_type.set_name("my_struct"); Builder b; auto id = b.GenerateTypeIfNeeded(&s_type); @@ -234,7 +238,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" +OpMemberName %1 0 "a" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block )");