| 1 |
// Copyright (c) 2015-2016 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 |
#include "source/enum_set.h" |
| 16 |
#include "source/table2.h" |
| 17 |
#include "test/unit_spirv.h" |
| 18 |
|
| 19 |
namespace spvtools { |
| 20 |
namespace { |
| 21 |
|
| 22 |
using spvtest::ElementsIn; |
| 23 |
|
| 24 |
// Capabilities required by an Opcode. |
| 25 |
struct ExpectedOpCodeCapabilities { |
| 26 |
spv::Op opcode; |
| 27 |
CapabilitySet capabilities; |
| 28 |
}; |
| 29 |
|
| 30 |
using OpcodeTableCapabilitiesTest = |
| 31 |
::testing::TestWithParam<ExpectedOpCodeCapabilities>; |
| 32 |
|
| 33 |
TEST_P(OpcodeTableCapabilitiesTest, TableEntryMatchesExpectedCapabilities) { |
| 34 |
const spvtools::InstructionDesc* desc = nullptr; |
| 35 |
ASSERT_EQ(SPV_SUCCESS, spvtools::LookupOpcode(GetParam().opcode, &desc)); |
| 36 |
auto caps = desc->capabilities(); |
| 37 |
EXPECT_EQ(ElementsIn(GetParam().capabilities), |
| 38 |
ElementsIn(CapabilitySet(static_cast<uint32_t>(caps.size()), |
| 39 |
caps.data()))); |
| 40 |
} |
| 41 |
|
| 42 |
INSTANTIATE_TEST_SUITE_P( |
| 43 |
TableRowTest, OpcodeTableCapabilitiesTest, |
| 44 |
// Spot-check a few opcodes. |
| 45 |
::testing::Values( |
| 46 |
ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySize, |
| 47 |
CapabilitySet{spv::Capability::Kernel, |
| 48 |
spv::Capability::ImageQuery}}, |
| 49 |
ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySizeLod, |
| 50 |
CapabilitySet{spv::Capability::Kernel, |
| 51 |
spv::Capability::ImageQuery}}, |
| 52 |
ExpectedOpCodeCapabilities{spv::Op::OpImageQueryLevels, |
| 53 |
CapabilitySet{spv::Capability::Kernel, |
| 54 |
spv::Capability::ImageQuery}}, |
| 55 |
ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySamples, |
| 56 |
CapabilitySet{spv::Capability::Kernel, |
| 57 |
spv::Capability::ImageQuery}}, |
| 58 |
ExpectedOpCodeCapabilities{ |
| 59 |
spv::Op::OpImageSparseSampleImplicitLod, |
| 60 |
CapabilitySet{spv::Capability::SparseResidency}}, |
| 61 |
ExpectedOpCodeCapabilities{ |
| 62 |
spv::Op::OpCopyMemorySized, |
| 63 |
CapabilitySet{spv::Capability::Addresses, |
| 64 |
spv::Capability::UntypedPointersKHR}}, |
| 65 |
ExpectedOpCodeCapabilities{spv::Op::OpArrayLength, |
| 66 |
CapabilitySet{spv::Capability::Shader}}, |
| 67 |
ExpectedOpCodeCapabilities{spv::Op::OpFunction, CapabilitySet()}, |
| 68 |
ExpectedOpCodeCapabilities{spv::Op::OpConvertFToS, CapabilitySet()}, |
| 69 |
ExpectedOpCodeCapabilities{ |
| 70 |
spv::Op::OpEmitStreamVertex, |
| 71 |
CapabilitySet{spv::Capability::GeometryStreams}}, |
| 72 |
ExpectedOpCodeCapabilities{ |
| 73 |
spv::Op::OpTypeNamedBarrier, |
| 74 |
CapabilitySet{spv::Capability::NamedBarrier}}, |
| 75 |
ExpectedOpCodeCapabilities{ |
| 76 |
spv::Op::OpGetKernelMaxNumSubgroups, |
| 77 |
CapabilitySet{spv::Capability::SubgroupDispatch}}, |
| 78 |
ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySamples, |
| 79 |
CapabilitySet{spv::Capability::Kernel, |
| 80 |
spv::Capability::ImageQuery}}, |
| 81 |
ExpectedOpCodeCapabilities{ |
| 82 |
spv::Op::OpImageSparseSampleImplicitLod, |
| 83 |
CapabilitySet{spv::Capability::SparseResidency}}, |
| 84 |
ExpectedOpCodeCapabilities{ |
| 85 |
spv::Op::OpCopyMemorySized, |
| 86 |
CapabilitySet{spv::Capability::Addresses, |
| 87 |
spv::Capability::UntypedPointersKHR}}, |
| 88 |
ExpectedOpCodeCapabilities{spv::Op::OpArrayLength, |
| 89 |
CapabilitySet{spv::Capability::Shader}}, |
| 90 |
ExpectedOpCodeCapabilities{spv::Op::OpFunction, CapabilitySet()}, |
| 91 |
ExpectedOpCodeCapabilities{spv::Op::OpConvertFToS, CapabilitySet()}, |
| 92 |
ExpectedOpCodeCapabilities{ |
| 93 |
spv::Op::OpEmitStreamVertex, |
| 94 |
CapabilitySet{spv::Capability::GeometryStreams}}, |
| 95 |
ExpectedOpCodeCapabilities{ |
| 96 |
spv::Op::OpTypeNamedBarrier, |
| 97 |
CapabilitySet{spv::Capability::NamedBarrier}}, |
| 98 |
ExpectedOpCodeCapabilities{ |
| 99 |
spv::Op::OpGetKernelMaxNumSubgroups, |
| 100 |
CapabilitySet{spv::Capability::SubgroupDispatch}})); |
| 101 |
|
| 102 |
} // namespace |
| 103 |
} // namespace spvtools |