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