1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2017 Google Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Utilities for Vulkan SPIR-V assembly tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktSpvAsmUtils.hpp"
27 #include "deSTLUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkRefUtil.hpp"
33 namespace SpirVAssembly
41 VkPhysicalDeviceFeatures filterDefaultDeviceFeatures (const VkPhysicalDeviceFeatures& deviceFeatures)
43 VkPhysicalDeviceFeatures enabledDeviceFeatures = deviceFeatures;
45 // Disable robustness by default, as it has an impact on performance on some HW.
46 enabledDeviceFeatures.robustBufferAccess = false;
48 return enabledDeviceFeatures;
51 VkPhysicalDevice16BitStorageFeatures querySupported16BitStorageFeatures (const deUint32 apiVersion, const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions)
53 VkPhysicalDevice16BitStorageFeatures extensionFeatures =
55 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR, // sType
57 false, // storageUniformBufferBlock16
58 false, // storageUniform16
59 false, // storagePushConstant16
60 false, // storageInputOutput16
62 VkPhysicalDeviceFeatures2 features;
64 deMemset(&features, 0, sizeof(features));
65 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
66 features.pNext = &extensionFeatures;
68 // Call the getter only if supported. Otherwise above "zero" defaults are used
69 if(isInstanceExtensionSupported(apiVersion, instanceExtensions, "VK_KHR_get_physical_device_properties2"))
71 vki.getPhysicalDeviceFeatures2(device, &features);
74 return extensionFeatures;
77 VkPhysicalDeviceVariablePointerFeatures querySupportedVariablePointersFeatures (const deUint32 apiVersion, const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions)
79 VkPhysicalDeviceVariablePointerFeatures extensionFeatures =
81 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR, // sType
83 false, // variablePointersStorageBuffer
84 false, // variablePointers
87 VkPhysicalDeviceFeatures2 features;
88 deMemset(&features, 0, sizeof(features));
89 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
90 features.pNext = &extensionFeatures;
92 // Call the getter only if supported. Otherwise above "zero" defaults are used
93 if(isInstanceExtensionSupported(apiVersion, instanceExtensions, "VK_KHR_get_physical_device_properties2"))
95 vki.getPhysicalDeviceFeatures2(device, &features);
98 return extensionFeatures;
103 bool is16BitStorageFeaturesSupported (const deUint32 apiVersion, const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions, Extension16BitStorageFeatures toCheck)
105 VkPhysicalDevice16BitStorageFeatures extensionFeatures = querySupported16BitStorageFeatures(apiVersion, vki, device, instanceExtensions);
107 if ((toCheck & EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK) != 0 && extensionFeatures.storageBuffer16BitAccess == VK_FALSE)
110 if ((toCheck & EXT16BITSTORAGEFEATURES_UNIFORM) != 0 && extensionFeatures.uniformAndStorageBuffer16BitAccess == VK_FALSE)
113 if ((toCheck & EXT16BITSTORAGEFEATURES_PUSH_CONSTANT) != 0 && extensionFeatures.storagePushConstant16 == VK_FALSE)
116 if ((toCheck & EXT16BITSTORAGEFEATURES_INPUT_OUTPUT) != 0 && extensionFeatures.storageInputOutput16 == VK_FALSE)
122 bool isVariablePointersFeaturesSupported (const deUint32 apiVersion, const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions, ExtensionVariablePointersFeatures toCheck)
124 VkPhysicalDeviceVariablePointerFeatures extensionFeatures = querySupportedVariablePointersFeatures(apiVersion, vki, device, instanceExtensions);
126 if ((toCheck & EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS_STORAGEBUFFER) != 0 && extensionFeatures.variablePointersStorageBuffer == VK_FALSE)
129 if ((toCheck & EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS) != 0 && extensionFeatures.variablePointers == VK_FALSE)
135 Move<VkDevice> createDeviceWithExtensions (Context& context,
136 const deUint32 queueFamilyIndex,
137 const std::vector<std::string>& supportedExtensions,
138 const std::vector<std::string>& requiredExtensions)
140 const InstanceInterface& vki = context.getInstanceInterface();
141 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
142 std::vector<const char*> extensions;
143 void* pExtension = DE_NULL;
144 const VkPhysicalDeviceFeatures deviceFeatures = getPhysicalDeviceFeatures(vki, physicalDevice);
145 VkPhysicalDevice16BitStorageFeatures ext16BitStorageFeatures;
146 VkPhysicalDeviceVariablePointerFeatures extVariablePointerFeatures;
148 for (deUint32 extNdx = 0; extNdx < requiredExtensions.size(); ++extNdx)
150 const std::string& ext = requiredExtensions[extNdx];
152 // Check that all required extensions are supported first.
153 if (!isDeviceExtensionSupported(context.getUsedApiVersion(), supportedExtensions, ext))
155 TCU_THROW(NotSupportedError, (std::string("Device extension not supported: ") + ext).c_str());
158 // Currently don't support enabling multiple extensions at the same time.
159 if (ext == "VK_KHR_16bit_storage")
161 // For the 16bit storage extension, we have four features to test. Requesting all features supported.
162 // Note that we don't throw NotImplemented errors here if a specific feature is not supported;
163 // that should be done when actually trying to use that specific feature.
164 ext16BitStorageFeatures = querySupported16BitStorageFeatures(context.getUsedApiVersion(), vki, physicalDevice, context.getInstanceExtensions());
165 pExtension = &ext16BitStorageFeatures;
167 else if (ext == "VK_KHR_variable_pointers")
169 // For the VariablePointers extension, we have two features to test. Requesting all features supported.
170 extVariablePointerFeatures = querySupportedVariablePointersFeatures(context.getUsedApiVersion(), vki, physicalDevice, context.getInstanceExtensions());
171 pExtension = &extVariablePointerFeatures;
174 if (!isCoreDeviceExtension(context.getUsedApiVersion(), ext))
175 extensions.push_back(ext.c_str());
178 const float queuePriorities[] = { 1.0f };
179 const VkDeviceQueueCreateInfo queueInfos[] =
182 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
184 (VkDeviceQueueCreateFlags)0,
186 DE_LENGTH_OF_ARRAY(queuePriorities),
190 const VkPhysicalDeviceFeatures features = filterDefaultDeviceFeatures(deviceFeatures);
191 const VkDeviceCreateInfo deviceParams =
193 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
195 (VkDeviceCreateFlags)0,
196 DE_LENGTH_OF_ARRAY(queueInfos),
200 (deUint32)extensions.size(),
201 extensions.empty() ? DE_NULL : &extensions[0],
205 return vk::createDevice(vki, physicalDevice, &deviceParams);
208 Allocator* createAllocator (const InstanceInterface& instanceInterface, const VkPhysicalDevice physicalDevice, const DeviceInterface& deviceInterface, const VkDevice device)
210 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(instanceInterface, physicalDevice);
212 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
213 return new SimpleAllocator(deviceInterface, device, memoryProperties);
216 deUint32 getMinRequiredVulkanVersion (const SpirvVersion version)
220 case SPIRV_VERSION_1_0:
221 return VK_API_VERSION_1_0;
222 case SPIRV_VERSION_1_1:
223 case SPIRV_VERSION_1_2:
224 case SPIRV_VERSION_1_3:
225 return VK_API_VERSION_1_1;
232 std::string getVulkanName (const deUint32 version)
234 return std::string(version == VK_API_VERSION_1_1 ? "1.1" : "1.0");