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 SpvOp 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{
50 SpvOpImageQuerySize,
51 CapabilitySet{SpvCapabilityKernel, SpvCapabilityImageQuery}},
52 ExpectedOpCodeCapabilities{
53 SpvOpImageQuerySizeLod,
54 CapabilitySet{SpvCapabilityKernel, SpvCapabilityImageQuery}},
55 ExpectedOpCodeCapabilities{
56 SpvOpImageQueryLevels,
57 CapabilitySet{SpvCapabilityKernel, SpvCapabilityImageQuery}},
58 ExpectedOpCodeCapabilities{
59 SpvOpImageQuerySamples,
60 CapabilitySet{SpvCapabilityKernel, SpvCapabilityImageQuery}},
61 ExpectedOpCodeCapabilities{SpvOpImageSparseSampleImplicitLod,
62 CapabilitySet{SpvCapabilitySparseResidency}},
63 ExpectedOpCodeCapabilities{SpvOpCopyMemorySized,
64 CapabilitySet{SpvCapabilityAddresses}},
65 ExpectedOpCodeCapabilities{SpvOpArrayLength,
66 CapabilitySet{SpvCapabilityShader}},
67 ExpectedOpCodeCapabilities{SpvOpFunction, CapabilitySet()},
68 ExpectedOpCodeCapabilities{SpvOpConvertFToS, CapabilitySet()},
69 ExpectedOpCodeCapabilities{SpvOpEmitStreamVertex,
70 CapabilitySet{SpvCapabilityGeometryStreams}},
71 ExpectedOpCodeCapabilities{SpvOpTypeNamedBarrier,
72 CapabilitySet{SpvCapabilityNamedBarrier}},
73 ExpectedOpCodeCapabilities{
74 SpvOpGetKernelMaxNumSubgroups,
75 CapabilitySet{SpvCapabilitySubgroupDispatch}}));
76
77 } // namespace
78 } // namespace spvtools
79