| 1 |
// Copyright (c) 2017 Google Inc. |
| 2 |
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights |
| 3 |
// reserved. |
| 4 |
// |
| 5 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
// you may not use this file except in compliance with the License. |
| 7 |
// You may obtain a copy of the License at |
| 8 |
// |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
// |
| 11 |
// Unless required by applicable law or agreed to in writing, software |
| 12 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
// See the License for the specific language governing permissions and |
| 15 |
// limitations under the License. |
| 16 |
|
| 17 |
// Tests for OpExtension validator rules. |
| 18 |
|
| 19 |
#include <string> |
| 20 |
#include <utility> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
#include "gtest/gtest.h" |
| 24 |
#include "source/enum_string_mapping.h" |
| 25 |
#include "source/extensions.h" |
| 26 |
|
| 27 |
namespace spvtools { |
| 28 |
namespace { |
| 29 |
|
| 30 |
using ::testing::Values; |
| 31 |
using ::testing::ValuesIn; |
| 32 |
|
| 33 |
using ExtensionTest = |
| 34 |
::testing::TestWithParam<std::pair<Extension, std::string>>; |
| 35 |
using UnknownExtensionTest = ::testing::TestWithParam<std::string>; |
| 36 |
using CapabilityTest = |
| 37 |
::testing::TestWithParam<std::pair<SpvCapability, std::string>>; |
| 38 |
|
| 39 |
TEST_P(ExtensionTest, TestExtensionFromString) { |
| 40 |
const std::pair<Extension, std::string>& param = GetParam(); |
| 41 |
const Extension extension = param.first; |
| 42 |
const std::string extension_str = param.second; |
| 43 |
Extension result_extension; |
| 44 |
ASSERT_TRUE(GetExtensionFromString(extension_str.c_str(), &result_extension)); |
| 45 |
EXPECT_EQ(extension, result_extension); |
| 46 |
} |
| 47 |
|
| 48 |
TEST_P(ExtensionTest, TestExtensionToString) { |
| 49 |
const std::pair<Extension, std::string>& param = GetParam(); |
| 50 |
const Extension extension = param.first; |
| 51 |
const std::string extension_str = param.second; |
| 52 |
const std::string result_str = ExtensionToString(extension); |
| 53 |
EXPECT_EQ(extension_str, result_str); |
| 54 |
} |
| 55 |
|
| 56 |
TEST_P(UnknownExtensionTest, TestExtensionFromStringFails) { |
| 57 |
Extension result_extension; |
| 58 |
ASSERT_FALSE(GetExtensionFromString(GetParam().c_str(), &result_extension)); |
| 59 |
} |
| 60 |
|
| 61 |
TEST_P(CapabilityTest, TestCapabilityToString) { |
| 62 |
const std::pair<SpvCapability, std::string>& param = GetParam(); |
| 63 |
const SpvCapability capability = param.first; |
| 64 |
const std::string capability_str = param.second; |
| 65 |
const std::string result_str = CapabilityToString(capability); |
| 66 |
EXPECT_EQ(capability_str, result_str); |
| 67 |
} |
| 68 |
|
| 69 |
INSTANTIATE_TEST_SUITE_P( |
| 70 |
AllExtensions, ExtensionTest, |
| 71 |
ValuesIn(std::vector<std::pair<Extension, std::string>>({ |
| 72 |
{Extension::kSPV_KHR_16bit_storage, "SPV_KHR_16bit_storage"}, |
| 73 |
{Extension::kSPV_KHR_device_group, "SPV_KHR_device_group"}, |
| 74 |
{Extension::kSPV_KHR_multiview, "SPV_KHR_multiview"}, |
| 75 |
{Extension::kSPV_KHR_shader_ballot, "SPV_KHR_shader_ballot"}, |
| 76 |
{Extension::kSPV_KHR_shader_draw_parameters, |
| 77 |
"SPV_KHR_shader_draw_parameters"}, |
| 78 |
{Extension::kSPV_KHR_subgroup_vote, "SPV_KHR_subgroup_vote"}, |
| 79 |
{Extension::kSPV_NVX_multiview_per_view_attributes, |
| 80 |
"SPV_NVX_multiview_per_view_attributes"}, |
| 81 |
{Extension::kSPV_NV_geometry_shader_passthrough, |
| 82 |
"SPV_NV_geometry_shader_passthrough"}, |
| 83 |
{Extension::kSPV_NV_sample_mask_override_coverage, |
| 84 |
"SPV_NV_sample_mask_override_coverage"}, |
| 85 |
{Extension::kSPV_NV_stereo_view_rendering, |
| 86 |
"SPV_NV_stereo_view_rendering"}, |
| 87 |
{Extension::kSPV_NV_viewport_array2, "SPV_NV_viewport_array2"}, |
| 88 |
{Extension::kSPV_GOOGLE_decorate_string, "SPV_GOOGLE_decorate_string"}, |
| 89 |
{Extension::kSPV_GOOGLE_hlsl_functionality1, |
| 90 |
"SPV_GOOGLE_hlsl_functionality1"}, |
| 91 |
{Extension::kSPV_KHR_8bit_storage, "SPV_KHR_8bit_storage"}, |
| 92 |
}))); |
| 93 |
|
| 94 |
INSTANTIATE_TEST_SUITE_P(UnknownExtensions, UnknownExtensionTest, |
| 95 |
Values("", "SPV_KHR_", "SPV_KHR_device_group_ERROR", |
| 96 |
/*alphabetically before all extensions*/ "A", |
| 97 |
/*alphabetically after all extensions*/ "Z", |
| 98 |
"SPV_ERROR_random_string_hfsdklhlktherh")); |
| 99 |
|
| 100 |
INSTANTIATE_TEST_SUITE_P( |
| 101 |
AllCapabilities, CapabilityTest, |
| 102 |
ValuesIn(std::vector<std::pair<SpvCapability, std::string>>( |
| 103 |
{{SpvCapabilityMatrix, "Matrix"}, |
| 104 |
{SpvCapabilityShader, "Shader"}, |
| 105 |
{SpvCapabilityGeometry, "Geometry"}, |
| 106 |
{SpvCapabilityTessellation, "Tessellation"}, |
| 107 |
{SpvCapabilityAddresses, "Addresses"}, |
| 108 |
{SpvCapabilityLinkage, "Linkage"}, |
| 109 |
{SpvCapabilityKernel, "Kernel"}, |
| 110 |
{SpvCapabilityVector16, "Vector16"}, |
| 111 |
{SpvCapabilityFloat16Buffer, "Float16Buffer"}, |
| 112 |
{SpvCapabilityFloat16, "Float16"}, |
| 113 |
{SpvCapabilityFloat64, "Float64"}, |
| 114 |
{SpvCapabilityInt64, "Int64"}, |
| 115 |
{SpvCapabilityInt64Atomics, "Int64Atomics"}, |
| 116 |
{SpvCapabilityImageBasic, "ImageBasic"}, |
| 117 |
{SpvCapabilityImageReadWrite, "ImageReadWrite"}, |
| 118 |
{SpvCapabilityImageMipmap, "ImageMipmap"}, |
| 119 |
{SpvCapabilityPipes, "Pipes"}, |
| 120 |
{SpvCapabilityGroups, "Groups"}, |
| 121 |
{SpvCapabilityDeviceEnqueue, "DeviceEnqueue"}, |
| 122 |
{SpvCapabilityLiteralSampler, "LiteralSampler"}, |
| 123 |
{SpvCapabilityAtomicStorage, "AtomicStorage"}, |
| 124 |
{SpvCapabilityInt16, "Int16"}, |
| 125 |
{SpvCapabilityTessellationPointSize, "TessellationPointSize"}, |
| 126 |
{SpvCapabilityGeometryPointSize, "GeometryPointSize"}, |
| 127 |
{SpvCapabilityImageGatherExtended, "ImageGatherExtended"}, |
| 128 |
{SpvCapabilityStorageImageMultisample, "StorageImageMultisample"}, |
| 129 |
{SpvCapabilityUniformBufferArrayDynamicIndexing, |
| 130 |
"UniformBufferArrayDynamicIndexing"}, |
| 131 |
{SpvCapabilitySampledImageArrayDynamicIndexing, |
| 132 |
"SampledImageArrayDynamicIndexing"}, |
| 133 |
{SpvCapabilityStorageBufferArrayDynamicIndexing, |
| 134 |
"StorageBufferArrayDynamicIndexing"}, |
| 135 |
{SpvCapabilityStorageImageArrayDynamicIndexing, |
| 136 |
"StorageImageArrayDynamicIndexing"}, |
| 137 |
{SpvCapabilityClipDistance, "ClipDistance"}, |
| 138 |
{SpvCapabilityCullDistance, "CullDistance"}, |
| 139 |
{SpvCapabilityImageCubeArray, "ImageCubeArray"}, |
| 140 |
{SpvCapabilitySampleRateShading, "SampleRateShading"}, |
| 141 |
{SpvCapabilityImageRect, "ImageRect"}, |
| 142 |
{SpvCapabilitySampledRect, "SampledRect"}, |
| 143 |
{SpvCapabilityGenericPointer, "GenericPointer"}, |
| 144 |
{SpvCapabilityInt8, "Int8"}, |
| 145 |
{SpvCapabilityInputAttachment, "InputAttachment"}, |
| 146 |
{SpvCapabilitySparseResidency, "SparseResidency"}, |
| 147 |
{SpvCapabilityMinLod, "MinLod"}, |
| 148 |
{SpvCapabilitySampled1D, "Sampled1D"}, |
| 149 |
{SpvCapabilityImage1D, "Image1D"}, |
| 150 |
{SpvCapabilitySampledCubeArray, "SampledCubeArray"}, |
| 151 |
{SpvCapabilitySampledBuffer, "SampledBuffer"}, |
| 152 |
{SpvCapabilityImageBuffer, "ImageBuffer"}, |
| 153 |
{SpvCapabilityImageMSArray, "ImageMSArray"}, |
| 154 |
{SpvCapabilityStorageImageExtendedFormats, |
| 155 |
"StorageImageExtendedFormats"}, |
| 156 |
{SpvCapabilityImageQuery, "ImageQuery"}, |
| 157 |
{SpvCapabilityDerivativeControl, "DerivativeControl"}, |
| 158 |
{SpvCapabilityInterpolationFunction, "InterpolationFunction"}, |
| 159 |
{SpvCapabilityTransformFeedback, "TransformFeedback"}, |
| 160 |
{SpvCapabilityGeometryStreams, "GeometryStreams"}, |
| 161 |
{SpvCapabilityStorageImageReadWithoutFormat, |
| 162 |
"StorageImageReadWithoutFormat"}, |
| 163 |
{SpvCapabilityStorageImageWriteWithoutFormat, |
| 164 |
"StorageImageWriteWithoutFormat"}, |
| 165 |
{SpvCapabilityMultiViewport, "MultiViewport"}, |
| 166 |
{SpvCapabilitySubgroupDispatch, "SubgroupDispatch"}, |
| 167 |
{SpvCapabilityNamedBarrier, "NamedBarrier"}, |
| 168 |
{SpvCapabilityPipeStorage, "PipeStorage"}, |
| 169 |
{SpvCapabilitySubgroupBallotKHR, "SubgroupBallotKHR"}, |
| 170 |
{SpvCapabilityDrawParameters, "DrawParameters"}, |
| 171 |
{SpvCapabilitySubgroupVoteKHR, "SubgroupVoteKHR"}, |
| 172 |
{SpvCapabilityStorageBuffer16BitAccess, "StorageBuffer16BitAccess"}, |
| 173 |
{SpvCapabilityStorageUniformBufferBlock16, |
| 174 |
"StorageBuffer16BitAccess"}, // Preferred name |
| 175 |
{SpvCapabilityUniformAndStorageBuffer16BitAccess, |
| 176 |
"UniformAndStorageBuffer16BitAccess"}, |
| 177 |
{SpvCapabilityStorageUniform16, |
| 178 |
"UniformAndStorageBuffer16BitAccess"}, // Preferred name |
| 179 |
{SpvCapabilityStoragePushConstant16, "StoragePushConstant16"}, |
| 180 |
{SpvCapabilityStorageInputOutput16, "StorageInputOutput16"}, |
| 181 |
{SpvCapabilityDeviceGroup, "DeviceGroup"}, |
| 182 |
{SpvCapabilityAtomicFloat32AddEXT, "AtomicFloat32AddEXT"}, |
| 183 |
{SpvCapabilityAtomicFloat64AddEXT, "AtomicFloat64AddEXT"}, |
| 184 |
{SpvCapabilityMultiView, "MultiView"}, |
| 185 |
{SpvCapabilityInt64ImageEXT, "Int64ImageEXT"}, |
| 186 |
{SpvCapabilitySampleMaskOverrideCoverageNV, |
| 187 |
"SampleMaskOverrideCoverageNV"}, |
| 188 |
{SpvCapabilityGeometryShaderPassthroughNV, |
| 189 |
"GeometryShaderPassthroughNV"}, |
| 190 |
// The next two are different names for the same token. |
| 191 |
{SpvCapabilityShaderViewportIndexLayerNV, |
| 192 |
"ShaderViewportIndexLayerEXT"}, |
| 193 |
{SpvCapabilityShaderViewportIndexLayerEXT, |
| 194 |
"ShaderViewportIndexLayerEXT"}, |
| 195 |
{SpvCapabilityShaderViewportMaskNV, "ShaderViewportMaskNV"}, |
| 196 |
{SpvCapabilityShaderStereoViewNV, "ShaderStereoViewNV"}, |
| 197 |
{SpvCapabilityPerViewAttributesNV, "PerViewAttributesNV"}}))); |
| 198 |
|
| 199 |
} // namespace |
| 200 |
} // namespace spvtools |