spirv-reader: validity for user name tests

Bug: tint:765
Change-Id: Iad711d911137e2f66be28ac8238389f5b68c1d20
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50020
Commit-Queue: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
This commit is contained in:
David Neto 2021-05-07 21:35:54 +00:00 committed by Commit Bot service account
parent 2e1a284cbb
commit 9b26923b63
1 changed files with 45 additions and 11 deletions

View File

@ -23,25 +23,31 @@ namespace {
using ::testing::Eq; using ::testing::Eq;
TEST_F(SpvParserTest, UserName_RespectOpName) { using SpvParserUserNameTest = SpvParserTest;
TEST_F(SpvParserUserNameTest, UserName_RespectOpName) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
OpName %1 "the_void_type" OpName %1 "the_void_type"
%1 = OpTypeVoid %1 = OpTypeVoid
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->namer().GetName(1), Eq("the_void_type")); EXPECT_THAT(p->namer().GetName(1), Eq("the_void_type"));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, UserName_IgnoreEmptyName) { TEST_F(SpvParserUserNameTest, UserName_IgnoreEmptyName) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
OpName %1 "" OpName %1 ""
%1 = OpTypeVoid %1 = OpTypeVoid
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_FALSE(p->namer().HasName(1)); EXPECT_FALSE(p->namer().HasName(1));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, UserName_DistinguishDuplicateSuggestion) { TEST_F(SpvParserUserNameTest, UserName_DistinguishDuplicateSuggestion) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
OpName %1 "vanilla" OpName %1 "vanilla"
OpName %2 "vanilla" OpName %2 "vanilla"
@ -51,9 +57,11 @@ TEST_F(SpvParserTest, UserName_DistinguishDuplicateSuggestion) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->namer().GetName(1), Eq("vanilla")); EXPECT_THAT(p->namer().GetName(1), Eq("vanilla"));
EXPECT_THAT(p->namer().GetName(2), Eq("vanilla_1")); EXPECT_THAT(p->namer().GetName(2), Eq("vanilla_1"));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, UserName_RespectOpMemberName) { TEST_F(SpvParserUserNameTest, UserName_RespectOpMemberName) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
OpMemberName %3 0 "strawberry" OpMemberName %3 0 "strawberry"
OpMemberName %3 1 "vanilla" OpMemberName %3 1 "vanilla"
@ -65,9 +73,11 @@ TEST_F(SpvParserTest, UserName_RespectOpMemberName) {
EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("strawberry")); EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("strawberry"));
EXPECT_THAT(p->namer().GetMemberName(3, 1), Eq("vanilla")); EXPECT_THAT(p->namer().GetMemberName(3, 1), Eq("vanilla"));
EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("chocolate")); EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("chocolate"));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, UserName_IgnoreEmptyMemberName) { TEST_F(SpvParserUserNameTest, UserName_IgnoreEmptyMemberName) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
OpMemberName %3 0 "" OpMemberName %3 0 ""
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
@ -75,9 +85,11 @@ TEST_F(SpvParserTest, UserName_IgnoreEmptyMemberName) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0")); EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0"));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, UserName_SynthesizeMemberNames) { TEST_F(SpvParserUserNameTest, UserName_SynthesizeMemberNames) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeStruct %2 %2 %2 %3 = OpTypeStruct %2 %2 %2
@ -86,9 +98,11 @@ TEST_F(SpvParserTest, UserName_SynthesizeMemberNames) {
EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0")); EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0"));
EXPECT_THAT(p->namer().GetMemberName(3, 1), Eq("field1")); EXPECT_THAT(p->namer().GetMemberName(3, 1), Eq("field1"));
EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("field2")); EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("field2"));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, UserName_MemberNamesMixUserAndSynthesized) { TEST_F(SpvParserUserNameTest, UserName_MemberNamesMixUserAndSynthesized) {
auto p = parser(test::Assemble(R"( auto p = parser(test::Assemble(R"(
OpMemberName %3 1 "vanilla" OpMemberName %3 1 "vanilla"
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
@ -98,14 +112,17 @@ TEST_F(SpvParserTest, UserName_MemberNamesMixUserAndSynthesized) {
EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0")); EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0"));
EXPECT_THAT(p->namer().GetMemberName(3, 1), Eq("vanilla")); EXPECT_THAT(p->namer().GetMemberName(3, 1), Eq("vanilla"));
EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("field2")); EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("field2"));
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, EntryPointNames_AlwaysTakePrecedence) { TEST_F(SpvParserUserNameTest, EntryPointNames_AlwaysTakePrecedence) {
const std::string assembly = R"( const std::string assembly = R"(
OpCapability Shader OpCapability Shader
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
OpEntryPoint GLCompute %100 "main" OpEntryPoint Vertex %100 "main"
OpEntryPoint Fragment %100 "main_1" OpEntryPoint Fragment %100 "main_1"
OpExecutionMode %100 OriginUpperLeft
; attempt to grab the "main_1" that would be the derived name ; attempt to grab the "main_1" that would be the derived name
; for the second entry point. ; for the second entry point.
@ -134,14 +151,23 @@ TEST_F(SpvParserTest, EntryPointNames_AlwaysTakePrecedence) {
ASSERT_EQ(2u, ep_info.size()); ASSERT_EQ(2u, ep_info.size());
EXPECT_EQ(ep_info[0].name, "main"); EXPECT_EQ(ep_info[0].name, "main");
EXPECT_EQ(ep_info[1].name, "main_1"); EXPECT_EQ(ep_info[1].name, "main_1");
// This test checks two entry point with the same implementation function.
// But for the shader stages supported by WGSL, the SPIR-V rules require
// conflicting execution modes be applied to them.
// I still want to test the name disambiguation behaviour, but the cases
// are rejected by SPIR-V validation. This is true at least for the current
// WGSL feature set.
p->DeliberatelyInvalidSpirv();
} }
TEST_F(SpvParserTest, EntryPointNames_DistinctFromInnerNames) { TEST_F(SpvParserUserNameTest, EntryPointNames_DistinctFromInnerNames) {
const std::string assembly = R"( const std::string assembly = R"(
OpCapability Shader OpCapability Shader
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
OpEntryPoint GLCompute %100 "main" OpEntryPoint Vertex %100 "main"
OpEntryPoint Fragment %100 "main_1" OpEntryPoint Fragment %100 "main_1"
OpExecutionMode %100 OriginUpperLeft
; attempt to grab the "main_1" that would be the derived name ; attempt to grab the "main_1" that would be the derived name
; for the second entry point. ; for the second entry point.
@ -176,6 +202,14 @@ TEST_F(SpvParserTest, EntryPointNames_DistinctFromInnerNames) {
EXPECT_EQ(ep_info[1].name, "main_1"); EXPECT_EQ(ep_info[1].name, "main_1");
// ...but will use the same implementation function. // ...but will use the same implementation function.
EXPECT_EQ(ep_info[1].inner_name, "main_2"); EXPECT_EQ(ep_info[1].inner_name, "main_2");
// This test checks two entry point with the same implementation function.
// But for the shader stages supported by WGSL, the SPIR-V rules require
// conflicting execution modes be applied to them.
// I still want to test the name disambiguation behaviour, but the cases
// are rejected by SPIR-V validation. This is true at least for the current
// WGSL feature set.
p->DeliberatelyInvalidSpirv();
} }
} // namespace } // namespace