Debian Codegraph @

test/val/val_extension_spv_khr_subgroup_uniform_control_flow.cpp

raw
1 // Copyright (c) 2021 Google 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 for OpExtension validator rules.
16
17 #include <string>
18 #include <vector>
19
20 #include "gmock/gmock.h"
21 #include "source/extensions.h"
22 #include "source/spirv_target_env.h"
23 #include "source/table2.h"
24 #include "test/test_fixture.h"
25 #include "test/unit_spirv.h"
26 #include "test/val/val_fixtures.h"
27
28 namespace spvtools {
29 namespace val {
30 namespace {
31
32 using ::testing::HasSubstr;
33 using ::testing::Values;
34 using ::testing::ValuesIn;
35
36 using ValidateSpvKHRSubgroupUniformControlFlow = spvtest::ValidateBase<bool>;
37
38 TEST_F(ValidateSpvKHRSubgroupUniformControlFlow, Valid) {
39 const std::string str = R"(
40 OpCapability Shader
41 OpExtension "SPV_KHR_subgroup_uniform_control_flow"
42 OpMemoryModel Logical Simple
43 OpEntryPoint GLCompute %main "main"
44 OpExecutionMode %main LocalSize 1 1 1
45 OpExecutionMode %main SubgroupUniformControlFlowKHR
46
47 %void = OpTypeVoid
48 %void_fn = OpTypeFunction %void
49
50 %main = OpFunction %void None %void_fn
51 %entry = OpLabel
52 OpReturn
53 OpFunctionEnd
54 )";
55 CompileSuccessfully(str.c_str());
56 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
57 }
58
59 TEST_F(ValidateSpvKHRSubgroupUniformControlFlow, RequiresExtension) {
60 const std::string str = R"(
61 OpCapability Shader
62 OpMemoryModel Logical Simple
63 OpEntryPoint GLCompute %main "main"
64 OpExecutionMode %main LocalSize 1 1 1
65 OpExecutionMode %main SubgroupUniformControlFlowKHR
66
67 %void = OpTypeVoid
68 %void_fn = OpTypeFunction %void
69
70 %main = OpFunction %void None %void_fn
71 %entry = OpLabel
72 OpReturn
73 OpFunctionEnd
74 )";
75 CompileSuccessfully(str.c_str());
76 EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
77 EXPECT_THAT(getDiagnosticString(),
78 HasSubstr("2nd operand of ExecutionMode: operand "
79 "SubgroupUniformControlFlowKHR(4421) "
80 "requires one of these extensions: "
81 "SPV_KHR_subgroup_uniform_control_flow"));
82 }
83
84 TEST_F(ValidateSpvKHRSubgroupUniformControlFlow, RequiresShaderCapability) {
85 const std::string str = R"(
86 OpCapability Kernel
87 OpCapability Addresses
88 OpExtension "SPV_KHR_subgroup_uniform_control_flow"
89 OpMemoryModel Physical32 OpenCL
90 OpEntryPoint Kernel %main "main"
91 OpExecutionMode %main SubgroupUniformControlFlowKHR
92
93 %void = OpTypeVoid
94 %void_fn = OpTypeFunction %void
95
96 %main = OpFunction %void None %void_fn
97 %entry = OpLabel
98 OpReturn
99 OpFunctionEnd
100 )";
101 CompileSuccessfully(str.c_str());
102 EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
103 EXPECT_THAT(getDiagnosticString(),
104 HasSubstr("Operand 2 of ExecutionMode requires one of these "
105 "capabilities: Shader"));
106 }
107
108 } // namespace
109 } // namespace val
110 } // namespace spvtools