Merge "Add clear() to de::AppendList" into nyc-dev
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / vktTestCase.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
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:
14  *
15  * The above copyright notice(s) and this permission notice shall be
16  * included in all copies or substantial portions of the Materials.
17  *
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.
25  *
26  *//*!
27  * \file
28  * \brief Vulkan test case base classes
29  *//*--------------------------------------------------------------------*/
30
31 #include "vktTestCase.hpp"
32
33 #include "vkRef.hpp"
34 #include "vkRefUtil.hpp"
35 #include "vkQueryUtil.hpp"
36 #include "vkDeviceUtil.hpp"
37 #include "vkMemUtil.hpp"
38 #include "vkPlatform.hpp"
39
40 #include "deMemory.h"
41
42 namespace vkt
43 {
44
45 // Default device utilities
46
47 using std::vector;
48 using namespace vk;
49
50 static deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
51 {
52         const vector<VkQueueFamilyProperties>   queueProps      = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
53
54         for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
55         {
56                 if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
57                         return (deUint32)queueNdx;
58         }
59
60         TCU_THROW(NotSupportedError, "No matching queue found");
61 }
62
63 Move<VkDevice> createDefaultDevice (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, deUint32 queueIndex, const VkPhysicalDeviceFeatures& enabledFeatures)
64 {
65         VkDeviceQueueCreateInfo         queueInfo;
66         VkDeviceCreateInfo                      deviceInfo;
67         const float                                     queuePriority   = 1.0f;
68
69         deMemset(&queueInfo,    0, sizeof(queueInfo));
70         deMemset(&deviceInfo,   0, sizeof(deviceInfo));
71
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;
78
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;
88
89         return createDevice(vki, physicalDevice, &deviceInfo);
90 };
91
92 class DefaultDevice
93 {
94 public:
95                                                                                 DefaultDevice                                   (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine);
96                                                                                 ~DefaultDevice                                  (void);
97
98         VkInstance                                                      getInstance                                             (void) const    { return *m_instance;                                   }
99         const InstanceInterface&                        getInstanceInterface                    (void) const    { return m_instanceInterface;                   }
100
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;                    }
106
107         deUint32                                                        getUniversalQueueFamilyIndex    (void) const    { return m_universalQueueFamilyIndex;   }
108         VkQueue                                                         getUniversalQueue                               (void) const;
109
110 private:
111         static VkPhysicalDeviceFeatures         filterDefaultDeviceFeatures             (const VkPhysicalDeviceFeatures& deviceFeatures);
112
113         const Unique<VkInstance>                        m_instance;
114         const InstanceDriver                            m_instanceInterface;
115
116         const VkPhysicalDevice                          m_physicalDevice;
117
118         const deUint32                                          m_universalQueueFamilyIndex;
119         const VkPhysicalDeviceFeatures          m_deviceFeatures;
120         const VkPhysicalDeviceProperties        m_deviceProperties;
121
122         const Unique<VkDevice>                          m_device;
123         const DeviceDriver                                      m_deviceInterface;
124 };
125
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)
135 {
136 }
137
138 DefaultDevice::~DefaultDevice (void)
139 {
140 }
141
142 VkQueue DefaultDevice::getUniversalQueue (void) const
143 {
144         VkQueue queue   = 0;
145         m_deviceInterface.getDeviceQueue(*m_device, m_universalQueueFamilyIndex, 0, &queue);
146         return queue;
147 }
148
149 VkPhysicalDeviceFeatures DefaultDevice::filterDefaultDeviceFeatures (const VkPhysicalDeviceFeatures& deviceFeatures)
150 {
151         VkPhysicalDeviceFeatures enabledDeviceFeatures = deviceFeatures;
152
153         // Disable robustness by default, as it has an impact on performance on some HW.
154         enabledDeviceFeatures.robustBufferAccess = false;
155
156         return enabledDeviceFeatures;
157 }
158
159 // Allocator utilities
160
161 vk::Allocator* createAllocator (DefaultDevice* device)
162 {
163         const VkPhysicalDeviceMemoryProperties memoryProperties = vk::getPhysicalDeviceMemoryProperties(device->getInstanceInterface(), device->getPhysicalDevice());
164
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);
167 }
168
169 // Context
170
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()))
179 {
180 }
181
182 Context::~Context (void)
183 {
184 }
185
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;                                                             }
196
197 // TestCase
198
199 void TestCase::initPrograms (SourceCollections&) const
200 {
201 }
202
203 } // vkt