[spirv-writer] Emit struct names

This CL changes the struct generation to emit the `OpName` for the
struct instead of doing it in a separate type alias pass. The struct
name was the only thing that needed to be output in the type alias pass
and this makes sure it's only emitted if used.

Bug: tint:5
Change-Id: I7389a3cd61812171fceeaae99253610152aa523d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17860
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-03-26 15:49:06 +00:00 committed by dan sinclair
parent 989cee6d33
commit bf46de42ad
2 changed files with 12 additions and 2 deletions

View File

@ -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<Operand> ops;
ops.push_back(result);

View File

@ -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::Struct>(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::Struct>(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
)");