From dee76fff44bb0710011098fb2767bb1ebb8a9f75 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 5 May 2021 16:12:32 +0000 Subject: [PATCH] spirv-reader: update tests to valid SPIR-V Bug: tint:765 Change-Id: I4312f9aa94fd813aeb9b388c10303f967057066f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49644 Kokoro: Kokoro Commit-Queue: David Neto Auto-Submit: David Neto Reviewed-by: Alan Baker --- src/reader/spirv/function_misc_test.cc | 27 ++++++++++++++------- src/reader/spirv/parser_impl_handle_test.cc | 11 ++++++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/reader/spirv/function_misc_test.cc b/src/reader/spirv/function_misc_test.cc index 053956395c..5a9354845b 100644 --- a/src/reader/spirv/function_misc_test.cc +++ b/src/reader/spirv/function_misc_test.cc @@ -25,6 +25,15 @@ namespace { using ::testing::Eq; using ::testing::HasSubstr; +std::string Preamble() { + return R"( + OpCapability Shader + OpMemoryModel Logical Simple + OpEntryPoint Fragment %100 "main" + OpExecutionMode %100 OriginUpperLeft +)"; +} + std::string CommonTypes() { return R"( %void = OpTypeVoid @@ -45,7 +54,7 @@ std::string CommonTypes() { using SpvParserTestMiscInstruction = SpvParserTest; TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Scalar) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %1 = OpUndef %bool %2 = OpUndef %uint %3 = OpUndef %int @@ -108,7 +117,7 @@ VariableDeclStatement{ } TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %4 = OpUndef %v2bool %1 = OpUndef %v2uint %2 = OpUndef %v2int @@ -188,7 +197,7 @@ VariableDeclStatement{ } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %100 = OpFunction %void None %voidfn %entry = OpLabel %1 = OpUndef %bool @@ -251,7 +260,7 @@ VariableDeclStatement{ } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %100 = OpFunction %void None %voidfn %entry = OpLabel %1 = OpUndef %v2uint @@ -314,7 +323,7 @@ VariableDeclStatement{ } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %mat = OpTypeMatrix %v2float 2 %100 = OpFunction %void None %voidfn @@ -355,7 +364,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %uint_2 = OpConstant %uint 2 %arr = OpTypeArray %uint %uint_2 @@ -389,7 +398,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %strct = OpTypeStruct %bool %uint %int %float %100 = OpFunction %void None %voidfn @@ -424,7 +433,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { } TEST_F(SpvParserTestMiscInstruction, OpNop) { - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %100 = OpFunction %void None %voidfn %entry = OpLabel OpNop @@ -452,7 +461,7 @@ using SpvParserSwizzleTest = TEST_P(SpvParserSwizzleTest, Sample) { // We need a function so we can get a FunctionEmitter. - const auto assembly = CommonTypes() + R"( + const auto assembly = Preamble() + CommonTypes() + R"( %100 = OpFunction %void None %voidfn %entry = OpLabel OpReturn diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 757d18bd5c..a633fca683 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -33,10 +33,18 @@ std::string Preamble() { OpCapability Sampled1D OpCapability Image1D OpCapability StorageImageExtendedFormats + OpCapability ImageQuery OpMemoryModel Logical Simple )"; } +std::string FragMain() { + return R"( + OpEntryPoint Fragment %main "main" ; assume no IO + OpExecutionMode %main OriginUpperLeft + )"; +} + std::string CommonBasicTypes() { return R"( %void = OpTypeVoid @@ -811,7 +819,7 @@ using SpvParserTest_RegisterHandleUsage_SampledImage = SpvParserTestBase<::testing::TestWithParam>; TEST_P(SpvParserTest_RegisterHandleUsage_SampledImage, Variable) { - const auto assembly = Preamble() + CommonTypes() + R"( + const auto assembly = Preamble() + FragMain() + CommonTypes() + R"( %si_ty = OpTypeSampledImage %f_texture_2d %coords = OpConstantNull %v2float @@ -1098,6 +1106,7 @@ using SpvParserTest_DeclUnderspecifiedHandle = TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) { const auto assembly = Preamble() + R"( + OpEntryPoint GLCompute %main "main" OpDecorate %10 DescriptorSet 0 OpDecorate %10 Binding 0 )" + GetParam().decorations +