mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 20:25:56 +00:00
[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:
parent
989cee6d33
commit
bf46de42ad
@ -274,6 +274,11 @@ bool Builder::GenerateStructType(ast::type::StructType* struct_type,
|
|||||||
auto struct_id = result.to_i();
|
auto struct_id = result.to_i();
|
||||||
auto impl = struct_type->impl();
|
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;
|
std::vector<Operand> ops;
|
||||||
ops.push_back(result);
|
ops.push_back(result);
|
||||||
|
|
||||||
|
@ -186,6 +186,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
|
|||||||
EXPECT_EQ(id, 1);
|
EXPECT_EQ(id, 1);
|
||||||
|
|
||||||
EXPECT_EQ(b.types().size(), 1);
|
EXPECT_EQ(b.types().size(), 1);
|
||||||
|
EXPECT_EQ(DumpInstructions(b.debug()), "");
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct
|
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,
|
auto s = std::make_unique<ast::Struct>(ast::StructDecoration::kNone,
|
||||||
std::move(members));
|
std::move(members));
|
||||||
ast::type::StructType s_type(std::move(s));
|
ast::type::StructType s_type(std::move(s));
|
||||||
|
s_type.set_name("my_struct");
|
||||||
|
|
||||||
Builder b;
|
Builder b;
|
||||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||||
@ -210,7 +212,8 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
|
|||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeStruct %2
|
%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,
|
auto s = std::make_unique<ast::Struct>(ast::StructDecoration::kBlock,
|
||||||
std::move(members));
|
std::move(members));
|
||||||
ast::type::StructType s_type(std::move(s));
|
ast::type::StructType s_type(std::move(s));
|
||||||
|
s_type.set_name("my_struct");
|
||||||
|
|
||||||
Builder b;
|
Builder b;
|
||||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
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
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeStruct %2
|
%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
|
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block
|
||||||
)");
|
)");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user