• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2022 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Tests instructions from SPV_EXT_mesh_shader
16 
17 #include <sstream>
18 #include <string>
19 
20 #include "gmock/gmock.h"
21 #include "test/val/val_fixtures.h"
22 
23 namespace spvtools {
24 namespace val {
25 namespace {
26 
27 using ::testing::HasSubstr;
28 using ::testing::Values;
29 
30 using ValidateMeshShading = spvtest::ValidateBase<bool>;
31 
TEST_F(ValidateMeshShading,EmitMeshTasksEXTNotLastInstructionUniversal)32 TEST_F(ValidateMeshShading, EmitMeshTasksEXTNotLastInstructionUniversal) {
33   const std::string body = R"(
34                OpCapability MeshShadingEXT
35                OpExtension "SPV_EXT_mesh_shader"
36                OpMemoryModel Logical GLSL450
37                OpEntryPoint TaskEXT %main "main" %p
38                OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
39        %void = OpTypeVoid
40        %func = OpTypeFunction %void
41        %uint = OpTypeInt 32 0
42      %uint_1 = OpConstant %uint 1
43       %float = OpTypeFloat 32
44   %arr_float = OpTypeArray %float %uint_1
45     %Payload = OpTypeStruct %arr_float
46 %ptr_Payload = OpTypePointer TaskPayloadWorkgroupEXT %Payload
47           %p = OpVariable %ptr_Payload TaskPayloadWorkgroupEXT
48        %main = OpFunction %void None %func
49      %label1 = OpLabel
50                OpEmitMeshTasksEXT %uint_1 %uint_1 %uint_1 %p
51                OpBranch %label2
52      %label2 = OpLabel
53                OpReturn
54                OpFunctionEnd
55 )";
56 
57   CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_4);
58   EXPECT_EQ(SPV_ERROR_INVALID_LAYOUT,
59             ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
60   EXPECT_THAT(getDiagnosticString(),
61               HasSubstr("Branch must appear in a block"));
62 }
63 
TEST_F(ValidateMeshShading,EmitMeshTasksEXTNotLastInstructionVulkan)64 TEST_F(ValidateMeshShading, EmitMeshTasksEXTNotLastInstructionVulkan) {
65   const std::string body = R"(
66                OpCapability MeshShadingEXT
67                OpExtension "SPV_EXT_mesh_shader"
68                OpMemoryModel Logical GLSL450
69                OpEntryPoint TaskEXT %main "main" %p
70                OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
71        %void = OpTypeVoid
72        %func = OpTypeFunction %void
73        %uint = OpTypeInt 32 0
74      %uint_1 = OpConstant %uint 1
75       %float = OpTypeFloat 32
76   %arr_float = OpTypeArray %float %uint_1
77     %Payload = OpTypeStruct %arr_float
78 %ptr_Payload = OpTypePointer TaskPayloadWorkgroupEXT %Payload
79           %p = OpVariable %ptr_Payload TaskPayloadWorkgroupEXT
80        %main = OpFunction %void None %func
81      %label1 = OpLabel
82                OpEmitMeshTasksEXT %uint_1 %uint_1 %uint_1 %p
83                OpReturn
84                OpFunctionEnd
85 )";
86 
87   CompileSuccessfully(body, SPV_ENV_VULKAN_1_2);
88   EXPECT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions(SPV_ENV_VULKAN_1_2));
89   EXPECT_THAT(getDiagnosticString(),
90               HasSubstr("Return must appear in a block"));
91 }
92 
93 }  // namespace
94 }  // namespace val
95 }  // namespace spvtools
96