• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "test/unit_spirv.h"
16 
17 #include "source/enum_set.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 
TEST_P(OpcodeTableCapabilitiesTest,TableEntryMatchesExpectedCapabilities)33 TEST_P(OpcodeTableCapabilitiesTest, TableEntryMatchesExpectedCapabilities) {
34   auto env = SPV_ENV_UNIVERSAL_1_1;
35   spv_opcode_table opcodeTable;
36   ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable, env));
37   spv_opcode_desc entry;
38   ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableValueLookup(env, opcodeTable,
39                                                    GetParam().opcode, &entry));
40   EXPECT_EQ(
41       ElementsIn(GetParam().capabilities),
42       ElementsIn(CapabilitySet(entry->numCapabilities, entry->capabilities)));
43 }
44 
45 INSTANTIATE_TEST_SUITE_P(
46     TableRowTest, OpcodeTableCapabilitiesTest,
47     // Spot-check a few opcodes.
48     ::testing::Values(
49         ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySize,
50                                    CapabilitySet{spv::Capability::Kernel,
51                                                  spv::Capability::ImageQuery}},
52         ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySizeLod,
53                                    CapabilitySet{spv::Capability::Kernel,
54                                                  spv::Capability::ImageQuery}},
55         ExpectedOpCodeCapabilities{spv::Op::OpImageQueryLevels,
56                                    CapabilitySet{spv::Capability::Kernel,
57                                                  spv::Capability::ImageQuery}},
58         ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySamples,
59                                    CapabilitySet{spv::Capability::Kernel,
60                                                  spv::Capability::ImageQuery}},
61         ExpectedOpCodeCapabilities{
62             spv::Op::OpImageSparseSampleImplicitLod,
63             CapabilitySet{spv::Capability::SparseResidency}},
64         ExpectedOpCodeCapabilities{spv::Op::OpCopyMemorySized,
65                                    CapabilitySet{spv::Capability::Addresses}},
66         ExpectedOpCodeCapabilities{spv::Op::OpArrayLength,
67                                    CapabilitySet{spv::Capability::Shader}},
68         ExpectedOpCodeCapabilities{spv::Op::OpFunction, CapabilitySet()},
69         ExpectedOpCodeCapabilities{spv::Op::OpConvertFToS, CapabilitySet()},
70         ExpectedOpCodeCapabilities{
71             spv::Op::OpEmitStreamVertex,
72             CapabilitySet{spv::Capability::GeometryStreams}},
73         ExpectedOpCodeCapabilities{
74             spv::Op::OpTypeNamedBarrier,
75             CapabilitySet{spv::Capability::NamedBarrier}},
76         ExpectedOpCodeCapabilities{
77             spv::Op::OpGetKernelMaxNumSubgroups,
78             CapabilitySet{spv::Capability::SubgroupDispatch}}));
79 
80 }  // namespace
81 }  // namespace spvtools
82