2
0

opcode_require_capabilities_test.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "test/unit_spirv.h"
  15. #include "source/enum_set.h"
  16. namespace spvtools {
  17. namespace {
  18. using spvtest::ElementsIn;
  19. // Capabilities required by an Opcode.
  20. struct ExpectedOpCodeCapabilities {
  21. spv::Op opcode;
  22. CapabilitySet capabilities;
  23. };
  24. using OpcodeTableCapabilitiesTest =
  25. ::testing::TestWithParam<ExpectedOpCodeCapabilities>;
  26. TEST_P(OpcodeTableCapabilitiesTest, TableEntryMatchesExpectedCapabilities) {
  27. auto env = SPV_ENV_UNIVERSAL_1_1;
  28. spv_opcode_table opcodeTable;
  29. ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableGet(&opcodeTable, env));
  30. spv_opcode_desc entry;
  31. ASSERT_EQ(SPV_SUCCESS, spvOpcodeTableValueLookup(env, opcodeTable,
  32. GetParam().opcode, &entry));
  33. EXPECT_EQ(
  34. ElementsIn(GetParam().capabilities),
  35. ElementsIn(CapabilitySet(entry->numCapabilities, entry->capabilities)));
  36. }
  37. INSTANTIATE_TEST_SUITE_P(
  38. TableRowTest, OpcodeTableCapabilitiesTest,
  39. // Spot-check a few opcodes.
  40. ::testing::Values(
  41. ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySize,
  42. CapabilitySet{spv::Capability::Kernel,
  43. spv::Capability::ImageQuery}},
  44. ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySizeLod,
  45. CapabilitySet{spv::Capability::Kernel,
  46. spv::Capability::ImageQuery}},
  47. ExpectedOpCodeCapabilities{spv::Op::OpImageQueryLevels,
  48. CapabilitySet{spv::Capability::Kernel,
  49. spv::Capability::ImageQuery}},
  50. ExpectedOpCodeCapabilities{spv::Op::OpImageQuerySamples,
  51. CapabilitySet{spv::Capability::Kernel,
  52. spv::Capability::ImageQuery}},
  53. ExpectedOpCodeCapabilities{
  54. spv::Op::OpImageSparseSampleImplicitLod,
  55. CapabilitySet{spv::Capability::SparseResidency}},
  56. ExpectedOpCodeCapabilities{spv::Op::OpCopyMemorySized,
  57. CapabilitySet{spv::Capability::Addresses}},
  58. ExpectedOpCodeCapabilities{spv::Op::OpArrayLength,
  59. CapabilitySet{spv::Capability::Shader}},
  60. ExpectedOpCodeCapabilities{spv::Op::OpFunction, CapabilitySet()},
  61. ExpectedOpCodeCapabilities{spv::Op::OpConvertFToS, CapabilitySet()},
  62. ExpectedOpCodeCapabilities{
  63. spv::Op::OpEmitStreamVertex,
  64. CapabilitySet{spv::Capability::GeometryStreams}},
  65. ExpectedOpCodeCapabilities{
  66. spv::Op::OpTypeNamedBarrier,
  67. CapabilitySet{spv::Capability::NamedBarrier}},
  68. ExpectedOpCodeCapabilities{
  69. spv::Op::OpGetKernelMaxNumSubgroups,
  70. CapabilitySet{spv::Capability::SubgroupDispatch}}));
  71. } // namespace
  72. } // namespace spvtools