Merge branch 'jekstrand_renderpass_transfer_bit_fix' into 'master'
[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 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.
21  *
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.
29  *
30  *//*!
31  * \file
32  * \brief Vulkan test case base classes
33  *//*--------------------------------------------------------------------*/
34
35 #include "vktTestCase.hpp"
36
37 #include "vkRef.hpp"
38 #include "vkRefUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkDeviceUtil.hpp"
41 #include "vkMemUtil.hpp"
42 #include "vkPlatform.hpp"
43
44 #include "deMemory.h"
45
46 namespace vkt
47 {
48
49 // Default device utilities
50
51 using std::vector;
52 using namespace vk;
53
54 static deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
55 {
56         const vector<VkQueueFamilyProperties>   queueProps      = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
57
58         for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
59         {
60                 if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
61                         return (deUint32)queueNdx;
62         }
63
64         TCU_THROW(NotSupportedError, "No matching queue found");
65 }
66
67 Move<VkDevice> createDefaultDevice (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, deUint32 queueIndex, const VkPhysicalDeviceFeatures& enabledFeatures)
68 {
69         VkDeviceQueueCreateInfo         queueInfo;
70         VkDeviceCreateInfo                      deviceInfo;
71         const float                                     queuePriority   = 1.0f;
72
73         deMemset(&queueInfo,    0, sizeof(queueInfo));
74         deMemset(&deviceInfo,   0, sizeof(deviceInfo));
75
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;
82
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;
92
93         return createDevice(vki, physicalDevice, &deviceInfo);
94 };
95
96 class DefaultDevice
97 {
98 public:
99                                                                                 DefaultDevice                                   (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine);
100                                                                                 ~DefaultDevice                                  (void);
101
102         VkInstance                                                      getInstance                                             (void) const    { return *m_instance;                                   }
103         const InstanceInterface&                        getInstanceInterface                    (void) const    { return m_instanceInterface;                   }
104
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;                    }
110
111         deUint32                                                        getUniversalQueueFamilyIndex    (void) const    { return m_universalQueueFamilyIndex;   }
112         VkQueue                                                         getUniversalQueue                               (void) const;
113
114 private:
115         const Unique<VkInstance>                        m_instance;
116         const InstanceDriver                            m_instanceInterface;
117
118         const VkPhysicalDevice                          m_physicalDevice;
119
120         const deUint32                                          m_universalQueueFamilyIndex;
121         const VkPhysicalDeviceFeatures          m_deviceFeatures;
122         const VkPhysicalDeviceProperties        m_deviceProperties;
123
124         const Unique<VkDevice>                          m_device;
125         const DeviceDriver                                      m_deviceInterface;
126 };
127
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)
137 {
138 }
139
140 DefaultDevice::~DefaultDevice (void)
141 {
142 }
143
144 VkQueue DefaultDevice::getUniversalQueue (void) const
145 {
146         VkQueue queue   = 0;
147         m_deviceInterface.getDeviceQueue(*m_device, m_universalQueueFamilyIndex, 0, &queue);
148         return queue;
149 }
150
151 // Allocator utilities
152
153 vk::Allocator* createAllocator (DefaultDevice* device)
154 {
155         const VkPhysicalDeviceMemoryProperties memoryProperties = vk::getPhysicalDeviceMemoryProperties(device->getInstanceInterface(), device->getPhysicalDevice());
156
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);
159 }
160
161 // Context
162
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()))
171 {
172 }
173
174 Context::~Context (void)
175 {
176 }
177
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;                                                             }
188
189 // TestCase
190
191 void TestCase::initPrograms (SourceCollections&) const
192 {
193 }
194
195 } // vkt