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 VkPhysicalDevice16BitStorageFeaturesKHR querySupported16BitStorageFeatures (const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions)
53 VkPhysicalDevice16BitStorageFeaturesKHR 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 VkPhysicalDeviceFeatures2KHR features;
64 deMemset(&features, 0, sizeof(features));
65 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
66 features.pNext = &extensionFeatures;
68 // Call the getter only if supported. Otherwise above "zero" defaults are used
69 if (de::contains(instanceExtensions.begin(), instanceExtensions.end(), "VK_KHR_get_physical_device_properties2"))
71 vki.getPhysicalDeviceFeatures2KHR(device, &features);
74 return extensionFeatures;
77 VkPhysicalDeviceVariablePointerFeaturesKHR querySupportedVariablePointersFeatures (const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions)
79 VkPhysicalDeviceVariablePointerFeaturesKHR extensionFeatures =
81 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR, // sType
83 false, // variablePointersStorageBuffer
84 false, // variablePointers
87 VkPhysicalDeviceFeatures2KHR features;
88 deMemset(&features, 0, sizeof(features));
89 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
90 features.pNext = &extensionFeatures;
92 // Call the getter only if supported. Otherwise above "zero" defaults are used
93 if (de::contains(instanceExtensions.begin(), instanceExtensions.end(), "VK_KHR_get_physical_device_properties2"))
95 vki.getPhysicalDeviceFeatures2KHR(device, &features);
98 return extensionFeatures;
103 bool is16BitStorageFeaturesSupported (const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions, Extension16BitStorageFeatures toCheck)
105 VkPhysicalDevice16BitStorageFeaturesKHR extensionFeatures = querySupported16BitStorageFeatures(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 InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions, ExtensionVariablePointersFeatures toCheck)
124 VkPhysicalDeviceVariablePointerFeaturesKHR extensionFeatures = querySupportedVariablePointersFeatures(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 (requiredExtensions.size());
143 void* pExtension = DE_NULL;
144 const VkPhysicalDeviceFeatures deviceFeatures = getPhysicalDeviceFeatures(vki, physicalDevice);
145 VkPhysicalDevice16BitStorageFeaturesKHR ext16BitStorageFeatures;
146 VkPhysicalDeviceVariablePointerFeaturesKHR 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 (!de::contains(supportedExtensions.begin(), supportedExtensions.end(), 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(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(vki, physicalDevice, context.getInstanceExtensions());
171 pExtension = &extVariablePointerFeatures;
174 extensions[extNdx] = ext.c_str();
177 const float queuePriorities[] = { 1.0f };
178 const VkDeviceQueueCreateInfo queueInfos[] =
181 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
183 (VkDeviceQueueCreateFlags)0,
185 DE_LENGTH_OF_ARRAY(queuePriorities),
189 const VkPhysicalDeviceFeatures features = filterDefaultDeviceFeatures(deviceFeatures);
190 const VkDeviceCreateInfo deviceParams =
192 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
194 (VkDeviceCreateFlags)0,
195 DE_LENGTH_OF_ARRAY(queueInfos),
199 (deUint32)extensions.size(),
200 extensions.empty() ? DE_NULL : &extensions[0],
204 return vk::createDevice(vki, physicalDevice, &deviceParams);
207 Allocator* createAllocator (const InstanceInterface& instanceInterface, const VkPhysicalDevice physicalDevice, const DeviceInterface& deviceInterface, const VkDevice device)
209 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(instanceInterface, physicalDevice);
211 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
212 return new SimpleAllocator(deviceInterface, device, memoryProperties);