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;
79 bool is16BitStorageFeaturesSupported (const InstanceInterface& vki, VkPhysicalDevice device, const std::vector<std::string>& instanceExtensions, Extension16BitStorageFeatures toCheck)
81 VkPhysicalDevice16BitStorageFeaturesKHR extensionFeatures = querySupported16BitStorageFeatures(vki, device, instanceExtensions);
83 if ((toCheck & EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK) != 0 && extensionFeatures.storageBuffer16BitAccess == VK_FALSE)
86 if ((toCheck & EXT16BITSTORAGEFEATURES_UNIFORM) != 0 && extensionFeatures.uniformAndStorageBuffer16BitAccess == VK_FALSE)
89 if ((toCheck & EXT16BITSTORAGEFEATURES_PUSH_CONSTANT) != 0 && extensionFeatures.storagePushConstant16 == VK_FALSE)
92 if ((toCheck & EXT16BITSTORAGEFEATURES_INPUT_OUTPUT) != 0 && extensionFeatures.storageInputOutput16 == VK_FALSE)
98 Move<VkDevice> createDeviceWithExtensions (Context& context,
99 const deUint32 queueFamilyIndex,
100 const std::vector<std::string>& supportedExtensions,
101 const std::vector<std::string>& requiredExtensions)
103 const InstanceInterface& vki = context.getInstanceInterface();
104 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
105 std::vector<const char*> extensions (requiredExtensions.size());
106 bool requires16BitStorageExtension = false;
108 for (deUint32 extNdx = 0; extNdx < requiredExtensions.size(); ++extNdx)
110 const std::string& ext = requiredExtensions[extNdx];
112 // Check that all required extensions are supported first.
113 if (!de::contains(supportedExtensions.begin(), supportedExtensions.end(), ext))
115 TCU_THROW(NotSupportedError, (std::string("Device extension not supported: ") + ext).c_str());
118 if (ext == "VK_KHR_16bit_storage")
120 requires16BitStorageExtension = true;
123 extensions[extNdx] = ext.c_str();
126 // For the 16bit storage extension, we have four features to test. Requesting all features supported.
127 // Note that we don't throw NotImplemented errors here if a specific feature is not supported;
128 // that should be done when actually trying to use that specific feature.
129 VkPhysicalDevice16BitStorageFeaturesKHR ext16BitStorageFeatures = querySupported16BitStorageFeatures(vki, physicalDevice, context.getInstanceExtensions());
131 const float queuePriorities[] = { 1.0f };
132 const VkDeviceQueueCreateInfo queueInfos[] =
135 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
137 (VkDeviceQueueCreateFlags)0,
139 DE_LENGTH_OF_ARRAY(queuePriorities),
143 const VkPhysicalDeviceFeatures features = filterDefaultDeviceFeatures(getPhysicalDeviceFeatures(vki, physicalDevice));
144 const VkDeviceCreateInfo deviceParams =
146 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
147 (requires16BitStorageExtension ? &ext16BitStorageFeatures : DE_NULL),
148 (VkDeviceCreateFlags)0,
149 DE_LENGTH_OF_ARRAY(queueInfos),
153 (deUint32)extensions.size(),
154 extensions.empty() ? DE_NULL : &extensions[0],
158 return vk::createDevice(vki, physicalDevice, &deviceParams);
161 Allocator* createAllocator (const InstanceInterface& instanceInterface, const VkPhysicalDevice physicalDevice, const DeviceInterface& deviceInterface, const VkDevice device)
163 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(instanceInterface, physicalDevice);
165 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
166 return new SimpleAllocator(deviceInterface, device, memoryProperties);