1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and/or associated documentation files (the
9 * "Materials"), to deal in the Materials without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Materials, and to
12 * permit persons to whom the Materials are furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice(s) and this permission notice shall be
16 * included in all copies or substantial portions of the Materials.
18 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
28 * \brief Vulkan test case base classes
29 *//*--------------------------------------------------------------------*/
31 #include "vktTestCase.hpp"
34 #include "vkRefUtil.hpp"
35 #include "vkQueryUtil.hpp"
36 #include "vkDeviceUtil.hpp"
37 #include "vkMemUtil.hpp"
38 #include "vkPlatform.hpp"
45 // Default device utilities
50 static deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
52 const vector<VkQueueFamilyProperties> queueProps = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
54 for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
56 if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
57 return (deUint32)queueNdx;
60 TCU_THROW(NotSupportedError, "No matching queue found");
63 Move<VkDevice> createDefaultDevice (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, deUint32 queueIndex, const VkPhysicalDeviceFeatures& enabledFeatures)
65 VkDeviceQueueCreateInfo queueInfo;
66 VkDeviceCreateInfo deviceInfo;
67 const float queuePriority = 1.0f;
69 deMemset(&queueInfo, 0, sizeof(queueInfo));
70 deMemset(&deviceInfo, 0, sizeof(deviceInfo));
72 queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
73 queueInfo.pNext = DE_NULL;
74 queueInfo.flags = (VkDeviceQueueCreateFlags)0u;
75 queueInfo.queueFamilyIndex = queueIndex;
76 queueInfo.queueCount = 1u;
77 queueInfo.pQueuePriorities = &queuePriority;
79 deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
80 deviceInfo.pNext = DE_NULL;
81 deviceInfo.queueCreateInfoCount = 1u;
82 deviceInfo.pQueueCreateInfos = &queueInfo;
83 deviceInfo.enabledExtensionCount = 0u;
84 deviceInfo.ppEnabledExtensionNames = DE_NULL;
85 deviceInfo.enabledLayerCount = 0u;
86 deviceInfo.ppEnabledLayerNames = DE_NULL;
87 deviceInfo.pEnabledFeatures = &enabledFeatures;
89 return createDevice(vki, physicalDevice, &deviceInfo);
95 DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine);
96 ~DefaultDevice (void);
98 VkInstance getInstance (void) const { return *m_instance; }
99 const InstanceInterface& getInstanceInterface (void) const { return m_instanceInterface; }
101 VkPhysicalDevice getPhysicalDevice (void) const { return m_physicalDevice; }
102 const VkPhysicalDeviceFeatures& getDeviceFeatures (void) const { return m_deviceFeatures; }
103 VkDevice getDevice (void) const { return *m_device; }
104 const DeviceInterface& getDeviceInterface (void) const { return m_deviceInterface; }
105 const VkPhysicalDeviceProperties& getDeviceProperties (void) const { return m_deviceProperties; }
107 deUint32 getUniversalQueueFamilyIndex (void) const { return m_universalQueueFamilyIndex; }
108 VkQueue getUniversalQueue (void) const;
111 static VkPhysicalDeviceFeatures filterDefaultDeviceFeatures (const VkPhysicalDeviceFeatures& deviceFeatures);
113 const Unique<VkInstance> m_instance;
114 const InstanceDriver m_instanceInterface;
116 const VkPhysicalDevice m_physicalDevice;
118 const deUint32 m_universalQueueFamilyIndex;
119 const VkPhysicalDeviceFeatures m_deviceFeatures;
120 const VkPhysicalDeviceProperties m_deviceProperties;
122 const Unique<VkDevice> m_device;
123 const DeviceDriver m_deviceInterface;
126 DefaultDevice::DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine)
127 : m_instance (createDefaultInstance(vkPlatform))
128 , m_instanceInterface (vkPlatform, *m_instance)
129 , m_physicalDevice (chooseDevice(m_instanceInterface, *m_instance, cmdLine))
130 , m_universalQueueFamilyIndex (findQueueFamilyIndexWithCaps(m_instanceInterface, m_physicalDevice, VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT))
131 , m_deviceFeatures (filterDefaultDeviceFeatures(getPhysicalDeviceFeatures(m_instanceInterface, m_physicalDevice)))
132 , m_deviceProperties (getPhysicalDeviceProperties(m_instanceInterface, m_physicalDevice)) // \note All supported features are enabled
133 , m_device (createDefaultDevice(m_instanceInterface, m_physicalDevice, m_universalQueueFamilyIndex, m_deviceFeatures))
134 , m_deviceInterface (m_instanceInterface, *m_device)
138 DefaultDevice::~DefaultDevice (void)
142 VkQueue DefaultDevice::getUniversalQueue (void) const
145 m_deviceInterface.getDeviceQueue(*m_device, m_universalQueueFamilyIndex, 0, &queue);
149 VkPhysicalDeviceFeatures DefaultDevice::filterDefaultDeviceFeatures (const VkPhysicalDeviceFeatures& deviceFeatures)
151 VkPhysicalDeviceFeatures enabledDeviceFeatures = deviceFeatures;
153 // Disable robustness by default, as it has an impact on performance on some HW.
154 enabledDeviceFeatures.robustBufferAccess = false;
156 return enabledDeviceFeatures;
159 // Allocator utilities
161 vk::Allocator* createAllocator (DefaultDevice* device)
163 const VkPhysicalDeviceMemoryProperties memoryProperties = vk::getPhysicalDeviceMemoryProperties(device->getInstanceInterface(), device->getPhysicalDevice());
165 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
166 return new SimpleAllocator(device->getDeviceInterface(), device->getDevice(), memoryProperties);
171 Context::Context (tcu::TestContext& testCtx,
172 const vk::PlatformInterface& platformInterface,
173 vk::ProgramCollection<vk::ProgramBinary>& progCollection)
174 : m_testCtx (testCtx)
175 , m_platformInterface (platformInterface)
176 , m_progCollection (progCollection)
177 , m_device (new DefaultDevice(m_platformInterface, testCtx.getCommandLine()))
178 , m_allocator (createAllocator(m_device.get()))
182 Context::~Context (void)
186 vk::VkInstance Context::getInstance (void) const { return m_device->getInstance(); }
187 const vk::InstanceInterface& Context::getInstanceInterface (void) const { return m_device->getInstanceInterface(); }
188 vk::VkPhysicalDevice Context::getPhysicalDevice (void) const { return m_device->getPhysicalDevice(); }
189 const vk::VkPhysicalDeviceFeatures& Context::getDeviceFeatures (void) const { return m_device->getDeviceFeatures(); }
190 const vk::VkPhysicalDeviceProperties& Context::getDeviceProperties (void) const { return m_device->getDeviceProperties(); }
191 vk::VkDevice Context::getDevice (void) const { return m_device->getDevice(); }
192 const vk::DeviceInterface& Context::getDeviceInterface (void) const { return m_device->getDeviceInterface(); }
193 deUint32 Context::getUniversalQueueFamilyIndex (void) const { return m_device->getUniversalQueueFamilyIndex(); }
194 vk::VkQueue Context::getUniversalQueue (void) const { return m_device->getUniversalQueue(); }
195 vk::Allocator& Context::getDefaultAllocator (void) const { return *m_allocator; }
199 void TestCase::initPrograms (SourceCollections&) const