From 9b26923b63caa20b0d16c0dab2be6bc31fc0030d Mon Sep 17 00:00:00 2001 From: David Neto Date: Fri, 7 May 2021 21:35:54 +0000 Subject: [PATCH] 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 Kokoro: Kokoro Reviewed-by: Alan Baker --- .../spirv/parser_impl_user_name_test.cc | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/reader/spirv/parser_impl_user_name_test.cc b/src/reader/spirv/parser_impl_user_name_test.cc index f69be619f7..258fd63850 100644 --- a/src/reader/spirv/parser_impl_user_name_test.cc +++ b/src/reader/spirv/parser_impl_user_name_test.cc @@ -23,25 +23,31 @@ namespace { using ::testing::Eq; -TEST_F(SpvParserTest, UserName_RespectOpName) { +using SpvParserUserNameTest = SpvParserTest; + +TEST_F(SpvParserUserNameTest, UserName_RespectOpName) { auto p = parser(test::Assemble(R"( OpName %1 "the_void_type" %1 = OpTypeVoid )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); 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"( OpName %1 "" %1 = OpTypeVoid )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_FALSE(p->namer().HasName(1)); + + p->DeliberatelyInvalidSpirv(); } -TEST_F(SpvParserTest, UserName_DistinguishDuplicateSuggestion) { +TEST_F(SpvParserUserNameTest, UserName_DistinguishDuplicateSuggestion) { auto p = parser(test::Assemble(R"( OpName %1 "vanilla" OpName %2 "vanilla" @@ -51,9 +57,11 @@ TEST_F(SpvParserTest, UserName_DistinguishDuplicateSuggestion) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_THAT(p->namer().GetName(1), Eq("vanilla")); 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"( OpMemberName %3 0 "strawberry" 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, 1), Eq("vanilla")); 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"( OpMemberName %3 0 "" %2 = OpTypeInt 32 0 @@ -75,9 +85,11 @@ TEST_F(SpvParserTest, UserName_IgnoreEmptyMemberName) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); 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"( %2 = OpTypeInt 32 0 %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, 1), Eq("field1")); 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"( OpMemberName %3 1 "vanilla" %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, 1), Eq("vanilla")); 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"( OpCapability Shader OpMemoryModel Logical Simple - OpEntryPoint GLCompute %100 "main" + OpEntryPoint Vertex %100 "main" OpEntryPoint Fragment %100 "main_1" + OpExecutionMode %100 OriginUpperLeft ; attempt to grab the "main_1" that would be the derived name ; for the second entry point. @@ -134,14 +151,23 @@ TEST_F(SpvParserTest, EntryPointNames_AlwaysTakePrecedence) { ASSERT_EQ(2u, ep_info.size()); EXPECT_EQ(ep_info[0].name, "main"); 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"( OpCapability Shader OpMemoryModel Logical Simple - OpEntryPoint GLCompute %100 "main" + OpEntryPoint Vertex %100 "main" OpEntryPoint Fragment %100 "main_1" + OpExecutionMode %100 OriginUpperLeft ; attempt to grab the "main_1" that would be the derived name ; for the second entry point. @@ -176,6 +202,14 @@ TEST_F(SpvParserTest, EntryPointNames_DistinctFromInnerNames) { EXPECT_EQ(ep_info[1].name, "main_1"); // ...but will use the same implementation function. 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