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 Confidential Information as defined by the
19 * Khronos Membership Agreement until designated non-confidential by
20 * Khronos, at which point this condition clause shall be removed.
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 * \brief Vulkan test case base classes
33 *//*--------------------------------------------------------------------*/
35 #include "vktTestCase.hpp"
38 #include "vkRefUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkDeviceUtil.hpp"
41 #include "vkMemUtil.hpp"
42 #include "vkPlatform.hpp"
49 // Default device utilities
54 static deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
56 const vector<VkQueueFamilyProperties> queueProps = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
58 for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
60 if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
61 return (deUint32)queueNdx;
64 TCU_THROW(NotSupportedError, "No matching queue found");
67 Move<VkDevice> createDefaultDevice (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, deUint32 queueIndex, const VkPhysicalDeviceFeatures& enabledFeatures)
69 VkDeviceQueueCreateInfo queueInfo;
70 VkDeviceCreateInfo deviceInfo;
71 const float queuePriority = 1.0f;
73 deMemset(&queueInfo, 0, sizeof(queueInfo));
74 deMemset(&deviceInfo, 0, sizeof(deviceInfo));
76 queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
77 queueInfo.pNext = DE_NULL;
78 queueInfo.flags = (VkDeviceQueueCreateFlags)0u;
79 queueInfo.queueFamilyIndex = queueIndex;
80 queueInfo.queueCount = 1u;
81 queueInfo.pQueuePriorities = &queuePriority;
83 deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
84 deviceInfo.pNext = DE_NULL;
85 deviceInfo.queueCreateInfoCount = 1u;
86 deviceInfo.pQueueCreateInfos = &queueInfo;
87 deviceInfo.enabledExtensionCount = 0u;
88 deviceInfo.ppEnabledExtensionNames = DE_NULL;
89 deviceInfo.enabledLayerCount = 0u;
90 deviceInfo.ppEnabledLayerNames = DE_NULL;
91 deviceInfo.pEnabledFeatures = &enabledFeatures;
93 return createDevice(vki, physicalDevice, &deviceInfo);
99 DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine);
100 ~DefaultDevice (void);
102 VkInstance getInstance (void) const { return *m_instance; }
103 const InstanceInterface& getInstanceInterface (void) const { return m_instanceInterface; }
105 VkPhysicalDevice getPhysicalDevice (void) const { return m_physicalDevice; }
106 const VkPhysicalDeviceFeatures& getDeviceFeatures (void) const { return m_deviceFeatures; }
107 VkDevice getDevice (void) const { return *m_device; }
108 const DeviceInterface& getDeviceInterface (void) const { return m_deviceInterface; }
109 const VkPhysicalDeviceProperties& getDeviceProperties (void) const { return m_deviceProperties; }
111 deUint32 getUniversalQueueFamilyIndex (void) const { return m_universalQueueFamilyIndex; }
112 VkQueue getUniversalQueue (void) const;
115 const Unique<VkInstance> m_instance;
116 const InstanceDriver m_instanceInterface;
118 const VkPhysicalDevice m_physicalDevice;
120 const deUint32 m_universalQueueFamilyIndex;
121 const VkPhysicalDeviceFeatures m_deviceFeatures;
122 const VkPhysicalDeviceProperties m_deviceProperties;
124 const Unique<VkDevice> m_device;
125 const DeviceDriver m_deviceInterface;
128 DefaultDevice::DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine)
129 : m_instance (createDefaultInstance(vkPlatform))
130 , m_instanceInterface (vkPlatform, *m_instance)
131 , m_physicalDevice (chooseDevice(m_instanceInterface, *m_instance, cmdLine))
132 , m_universalQueueFamilyIndex (findQueueFamilyIndexWithCaps(m_instanceInterface, m_physicalDevice, VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT))
133 , m_deviceFeatures (getPhysicalDeviceFeatures(m_instanceInterface, m_physicalDevice)) // \note All supported features are enabled
134 , m_deviceProperties (getPhysicalDeviceProperties(m_instanceInterface, m_physicalDevice)) // \note All supported features are enabled
135 , m_device (createDefaultDevice(m_instanceInterface, m_physicalDevice, m_universalQueueFamilyIndex, m_deviceFeatures))
136 , m_deviceInterface (m_instanceInterface, *m_device)
140 DefaultDevice::~DefaultDevice (void)
144 VkQueue DefaultDevice::getUniversalQueue (void) const
147 m_deviceInterface.getDeviceQueue(*m_device, m_universalQueueFamilyIndex, 0, &queue);
151 // Allocator utilities
153 vk::Allocator* createAllocator (DefaultDevice* device)
155 const VkPhysicalDeviceMemoryProperties memoryProperties = vk::getPhysicalDeviceMemoryProperties(device->getInstanceInterface(), device->getPhysicalDevice());
157 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
158 return new SimpleAllocator(device->getDeviceInterface(), device->getDevice(), memoryProperties);
163 Context::Context (tcu::TestContext& testCtx,
164 const vk::PlatformInterface& platformInterface,
165 vk::ProgramCollection<vk::ProgramBinary>& progCollection)
166 : m_testCtx (testCtx)
167 , m_platformInterface (platformInterface)
168 , m_progCollection (progCollection)
169 , m_device (new DefaultDevice(m_platformInterface, testCtx.getCommandLine()))
170 , m_allocator (createAllocator(m_device.get()))
174 Context::~Context (void)
178 vk::VkInstance Context::getInstance (void) const { return m_device->getInstance(); }
179 const vk::InstanceInterface& Context::getInstanceInterface (void) const { return m_device->getInstanceInterface(); }
180 vk::VkPhysicalDevice Context::getPhysicalDevice (void) const { return m_device->getPhysicalDevice(); }
181 const vk::VkPhysicalDeviceFeatures& Context::getDeviceFeatures (void) const { return m_device->getDeviceFeatures(); }
182 const vk::VkPhysicalDeviceProperties& Context::getDeviceProperties (void) const { return m_device->getDeviceProperties(); }
183 vk::VkDevice Context::getDevice (void) const { return m_device->getDevice(); }
184 const vk::DeviceInterface& Context::getDeviceInterface (void) const { return m_device->getDeviceInterface(); }
185 deUint32 Context::getUniversalQueueFamilyIndex (void) const { return m_device->getUniversalQueueFamilyIndex(); }
186 vk::VkQueue Context::getUniversalQueue (void) const { return m_device->getUniversalQueue(); }
187 vk::Allocator& Context::getDefaultAllocator (void) const { return *m_allocator; }
191 void TestCase::initPrograms (SourceCollections&) const