1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2015 Google Inc.
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Device Initialization Tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktApiDeviceInitializationTests.hpp"
25 #include "vktTestCaseUtil.hpp"
26
27 #include "vkDefs.hpp"
28 #include "vkPlatform.hpp"
29 #include "vkStrUtil.hpp"
30 #include "vkRef.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkQueryUtil.hpp"
33 #include "vkMemUtil.hpp"
34 #include "vkDeviceUtil.hpp"
35 #include "vkApiVersion.hpp"
36
37 #include "tcuTestLog.hpp"
38 #include "tcuResultCollector.hpp"
39
40 #include "deUniquePtr.hpp"
41 #include "deStringUtil.hpp"
42
43 #include <vector>
44
45 namespace vkt
46 {
47 namespace api
48 {
49
50 namespace
51 {
52
53 using namespace vk;
54 using namespace std;
55 using std::vector;
56 using tcu::TestLog;
57
createInstanceTest(Context & context)58 tcu::TestStatus createInstanceTest (Context& context)
59 {
60 tcu::TestLog& log = context.getTestContext().getLog();
61 tcu::ResultCollector resultCollector (log);
62 const char* appNames[] = { "appName", DE_NULL, "", "app, name", "app(\"name\"", "app~!@#$%^&*()_+name", "app\nName", "app\r\nName" };
63 const char* engineNames[] = { "engineName", DE_NULL, "", "engine. name", "engine\"(name)", "eng~!@#$%^&*()_+name", "engine\nName", "engine\r\nName" };
64 const int patchNumbers[] = { 0, 1, 2, 3, 4, 5, 13, 4094, 4095 };
65 const deUint32 appVersions[] = { 0, 1, (deUint32)-1 };
66 const deUint32 engineVersions[] = { 0, 1, (deUint32)-1 };
67 const PlatformInterface& platformInterface = context.getPlatformInterface();
68 vector<VkApplicationInfo> appInfos;
69
70 // test over appName
71 for (int appNameNdx = 0; appNameNdx < DE_LENGTH_OF_ARRAY(appNames); appNameNdx++)
72 {
73 const VkApplicationInfo appInfo =
74 {
75 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
76 DE_NULL, // const void* pNext;
77 appNames[appNameNdx], // const char* pAppName;
78 0u, // deUint32 appVersion;
79 "engineName", // const char* pEngineName;
80 0u, // deUint32 engineVersion;
81 VK_API_VERSION, // deUint32 apiVersion;
82 };
83
84 appInfos.push_back(appInfo);
85 }
86
87 // test over engineName
88 for (int engineNameNdx = 0; engineNameNdx < DE_LENGTH_OF_ARRAY(engineNames); engineNameNdx++)
89 {
90 const VkApplicationInfo appInfo =
91 {
92 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
93 DE_NULL, // const void* pNext;
94 "appName", // const char* pAppName;
95 0u, // deUint32 appVersion;
96 engineNames[engineNameNdx], // const char* pEngineName;
97 0u, // deUint32 engineVersion;
98 VK_API_VERSION, // deUint32 apiVersion;
99 };
100
101 appInfos.push_back(appInfo);
102 }
103
104 // test over appVersion
105 for (int appVersionNdx = 0; appVersionNdx < DE_LENGTH_OF_ARRAY(appVersions); appVersionNdx++)
106 {
107 const VkApplicationInfo appInfo =
108 {
109 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
110 DE_NULL, // const void* pNext;
111 "appName", // const char* pAppName;
112 appVersions[appVersionNdx], // deUint32 appVersion;
113 "engineName", // const char* pEngineName;
114 0u, // deUint32 engineVersion;
115 VK_API_VERSION, // deUint32 apiVersion;
116 };
117
118 appInfos.push_back(appInfo);
119 }
120
121 // test over engineVersion
122 for (int engineVersionNdx = 0; engineVersionNdx < DE_LENGTH_OF_ARRAY(engineVersions); engineVersionNdx++)
123 {
124 const VkApplicationInfo appInfo =
125 {
126 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
127 DE_NULL, // const void* pNext;
128 "appName", // const char* pAppName;
129 0u, // deUint32 appVersion;
130 "engineName", // const char* pEngineName;
131 engineVersions[engineVersionNdx], // deUint32 engineVersion;
132 VK_API_VERSION, // deUint32 apiVersion;
133 };
134
135 appInfos.push_back(appInfo);
136 }
137 // patch component of api version checking (should be ignored by implementation)
138 for (int patchVersion = 0; patchVersion < DE_LENGTH_OF_ARRAY(patchNumbers); patchVersion++)
139 {
140 const VkApplicationInfo appInfo =
141 {
142 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
143 DE_NULL, // const void* pNext;
144 "appName", // const char* pAppName;
145 0u, // deUint32 appVersion;
146 "engineName", // const char* pEngineName;
147 0u, // deUint32 engineVersion;
148 VK_MAKE_VERSION(1, 0, patchNumbers[patchVersion]), // deUint32 apiVersion;
149 };
150
151 appInfos.push_back(appInfo);
152 }
153 // run the tests!
154 for (size_t appInfoNdx = 0; appInfoNdx < appInfos.size(); ++appInfoNdx)
155 {
156 const VkApplicationInfo& appInfo = appInfos[appInfoNdx];
157 const VkInstanceCreateInfo instanceCreateInfo =
158 {
159 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
160 DE_NULL, // const void* pNext;
161 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
162 &appInfo, // const VkApplicationInfo* pAppInfo;
163 0u, // deUint32 layerCount;
164 DE_NULL, // const char*const* ppEnabledLayernames;
165 0u, // deUint32 extensionCount;
166 DE_NULL, // const char*const* ppEnabledExtensionNames;
167 };
168
169 log << TestLog::Message << "Creating instance with appInfo: " << appInfo << TestLog::EndMessage;
170
171 try
172 {
173 const Unique<VkInstance> instance(createInstance(platformInterface, &instanceCreateInfo));
174 log << TestLog::Message << "Succeeded" << TestLog::EndMessage;
175 }
176 catch (const vk::Error& err)
177 {
178 resultCollector.fail("Failed, Error code: " + de::toString(err.getMessage()));
179 }
180 }
181
182 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
183 }
184
createInstanceWithInvalidApiVersionTest(Context & context)185 tcu::TestStatus createInstanceWithInvalidApiVersionTest (Context& context)
186 {
187 tcu::TestLog& log = context.getTestContext().getLog();
188 tcu::ResultCollector resultCollector (log);
189 const PlatformInterface& platformInterface = context.getPlatformInterface();
190 const ApiVersion apiVersion = unpackVersion(VK_API_VERSION);
191 const deUint32 invalidMajorVersion = (1 << 10) - 1;
192 const deUint32 invalidMinorVersion = (1 << 10) - 1;
193 vector<ApiVersion> invalidApiVersions;
194
195 invalidApiVersions.push_back(ApiVersion(invalidMajorVersion, apiVersion.minorNum, apiVersion.patchNum));
196 invalidApiVersions.push_back(ApiVersion(apiVersion.majorNum, invalidMinorVersion, apiVersion.patchNum));
197
198 for (size_t apiVersionNdx = 0; apiVersionNdx < invalidApiVersions.size(); apiVersionNdx++)
199 {
200 const VkApplicationInfo appInfo =
201 {
202 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
203 DE_NULL, // const void* pNext;
204 "appName", // const char* pAppName;
205 0u, // deUint32 appVersion;
206 "engineName", // const char* pEngineName;
207 0u, // deUint32 engineVersion;
208 pack(invalidApiVersions[apiVersionNdx]), // deUint32 apiVersion;
209 };
210 const VkInstanceCreateInfo instanceCreateInfo =
211 {
212 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
213 DE_NULL, // const void* pNext;
214 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
215 &appInfo, // const VkApplicationInfo* pAppInfo;
216 0u, // deUint32 layerCount;
217 DE_NULL, // const char*const* ppEnabledLayernames;
218 0u, // deUint32 extensionCount;
219 DE_NULL, // const char*const* ppEnabledExtensionNames;
220 };
221
222
223 log << TestLog::Message
224 <<"VK_API_VERSION defined in vulkan.h: " << apiVersion
225 << ", api version used to create instance: " << invalidApiVersions[apiVersionNdx]
226 << TestLog::EndMessage;
227
228 {
229 VkInstance instance = (VkInstance)0;
230 const VkResult result = platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
231 const bool gotInstance = !!instance;
232
233 if (instance)
234 {
235 const InstanceDriver instanceIface (platformInterface, instance);
236 instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
237 }
238
239 if (result == VK_ERROR_INCOMPATIBLE_DRIVER)
240 {
241 TCU_CHECK(!gotInstance);
242 log << TestLog::Message << "Pass, instance creation with invalid apiVersion is rejected" << TestLog::EndMessage;
243 }
244 else
245 resultCollector.fail("Fail, instance creation with invalid apiVersion is not rejected");
246 }
247 }
248
249 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
250 }
251
createInstanceWithNullApplicationInfoTest(Context & context)252 tcu::TestStatus createInstanceWithNullApplicationInfoTest (Context& context)
253 {
254 tcu::TestLog& log = context.getTestContext().getLog();
255 tcu::ResultCollector resultCollector (log);
256 const PlatformInterface& platformInterface = context.getPlatformInterface();
257
258 const VkInstanceCreateInfo instanceCreateInfo =
259 {
260 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
261 DE_NULL, // const void* pNext;
262 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
263 DE_NULL, // const VkApplicationInfo* pAppInfo;
264 0u, // deUint32 layerCount;
265 DE_NULL, // const char*const* ppEnabledLayernames;
266 0u, // deUint32 extensionCount;
267 DE_NULL, // const char*const* ppEnabledExtensionNames;
268 };
269
270 log << TestLog::Message << "Creating instance with NULL pApplicationInfo" << TestLog::EndMessage;
271
272 try
273 {
274 const Unique<VkInstance> instance(createInstance(platformInterface, &instanceCreateInfo));
275 log << TestLog::Message << "Succeeded" << TestLog::EndMessage;
276 }
277 catch (const vk::Error& err)
278 {
279 resultCollector.fail("Failed, Error code: " + de::toString(err.getMessage()));
280 }
281
282 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
283 }
284
createInstanceWithUnsupportedExtensionsTest(Context & context)285 tcu::TestStatus createInstanceWithUnsupportedExtensionsTest (Context& context)
286 {
287 tcu::TestLog& log = context.getTestContext().getLog();
288 const PlatformInterface& platformInterface = context.getPlatformInterface();
289 const char* enabledExtensions[] = {"VK_UNSUPPORTED_EXTENSION", "THIS_IS_NOT_AN_EXTENSION"};
290 const VkApplicationInfo appInfo =
291 {
292 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
293 DE_NULL, // const void* pNext;
294 "appName", // const char* pAppName;
295 0u, // deUint32 appVersion;
296 "engineName", // const char* pEngineName;
297 0u, // deUint32 engineVersion;
298 VK_API_VERSION, // deUint32 apiVersion;
299 };
300 const VkInstanceCreateInfo instanceCreateInfo =
301 {
302 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
303 DE_NULL, // const void* pNext;
304 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
305 &appInfo, // const VkApplicationInfo* pAppInfo;
306 0u, // deUint32 layerCount;
307 DE_NULL, // const char*const* ppEnabledLayernames;
308 DE_LENGTH_OF_ARRAY(enabledExtensions), // deUint32 extensionCount;
309 enabledExtensions, // const char*const* ppEnabledExtensionNames;
310 };
311
312 log << TestLog::Message << "Enabled extensions are: " << TestLog::EndMessage;
313
314 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(enabledExtensions); ndx++)
315 log << TestLog::Message << enabledExtensions[ndx] << TestLog::EndMessage;
316
317 {
318 VkInstance instance = (VkInstance)0;
319 const VkResult result = platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
320 const bool gotInstance = !!instance;
321
322 if (instance)
323 {
324 const InstanceDriver instanceIface (platformInterface, instance);
325 instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
326 }
327
328 if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
329 {
330 TCU_CHECK(!gotInstance);
331 return tcu::TestStatus::pass("Pass, creating instance with unsupported extension was rejected.");
332 }
333 else
334 return tcu::TestStatus::fail("Fail, creating instance with unsupported extensions succeeded.");
335 }
336 }
337
createDeviceTest(Context & context)338 tcu::TestStatus createDeviceTest (Context& context)
339 {
340 const PlatformInterface& platformInterface = context.getPlatformInterface();
341 const Unique<VkInstance> instance (createDefaultInstance(platformInterface));
342 const InstanceDriver instanceDriver (platformInterface, instance.get());
343 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
344 const deUint32 queueFamilyIndex = 0;
345 const deUint32 queueCount = 1;
346 const deUint32 queueIndex = 0;
347 const float queuePriority = 1.0f;
348 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
349 {
350 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
351 DE_NULL,
352 (VkDeviceQueueCreateFlags)0u,
353 queueFamilyIndex, //queueFamilyIndex;
354 queueCount, //queueCount;
355 &queuePriority, //pQueuePriorities;
356 };
357 const VkDeviceCreateInfo deviceCreateInfo =
358 {
359 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
360 DE_NULL, //pNext;
361 (VkDeviceCreateFlags)0u,
362 1, //queueRecordCount;
363 &deviceQueueCreateInfo, //pRequestedQueues;
364 0, //layerCount;
365 DE_NULL, //ppEnabledLayerNames;
366 0, //extensionCount;
367 DE_NULL, //ppEnabledExtensionNames;
368 DE_NULL, //pEnabledFeatures;
369 };
370
371 const Unique<VkDevice> device (createDevice(instanceDriver, physicalDevice, &deviceCreateInfo));
372 const DeviceDriver deviceDriver (instanceDriver, device.get());
373 VkQueue queue;
374
375 deviceDriver.getDeviceQueue(device.get(), queueFamilyIndex, queueIndex, &queue);
376 VK_CHECK(deviceDriver.queueWaitIdle(queue));
377
378 return tcu::TestStatus::pass("Pass");
379 }
380
createMultipleDevicesTest(Context & context)381 tcu::TestStatus createMultipleDevicesTest (Context& context)
382 {
383 tcu::TestLog& log = context.getTestContext().getLog();
384 tcu::ResultCollector resultCollector (log);
385 const int numDevices = 5;
386 const PlatformInterface& platformInterface = context.getPlatformInterface();
387 const Unique<VkInstance> instance (createDefaultInstance(platformInterface));
388 const InstanceDriver instanceDriver (platformInterface, instance.get());
389 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
390 const deUint32 queueFamilyIndex = 0;
391 const deUint32 queueCount = 1;
392 const deUint32 queueIndex = 0;
393 const float queuePriority = 1.0f;
394 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
395 {
396 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
397 DE_NULL,
398 (VkDeviceQueueCreateFlags)0u, //flags;
399 queueFamilyIndex, //queueFamilyIndex;
400 queueCount, //queueCount;
401 &queuePriority, //pQueuePriorities;
402 };
403 const VkDeviceCreateInfo deviceCreateInfo =
404 {
405 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
406 DE_NULL, //pNext;
407 (VkDeviceCreateFlags)0u,
408 1, //queueRecordCount;
409 &deviceQueueCreateInfo, //pRequestedQueues;
410 0, //layerCount;
411 DE_NULL, //ppEnabledLayerNames;
412 0, //extensionCount;
413 DE_NULL, //ppEnabledExtensionNames;
414 DE_NULL, //pEnabledFeatures;
415 };
416 vector<VkDevice> devices(numDevices, (VkDevice)DE_NULL);
417
418 try
419 {
420 for (int deviceNdx = 0; deviceNdx < numDevices; deviceNdx++)
421 {
422 const VkResult result = instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL/*pAllocator*/, &devices[deviceNdx]);
423
424 if (result != VK_SUCCESS)
425 {
426 resultCollector.fail("Failed to create Device No." + de::toString(deviceNdx) + ", Error Code: " + de::toString(result));
427 break;
428 }
429
430 {
431 const DeviceDriver deviceDriver(instanceDriver, devices[deviceNdx]);
432 VkQueue queue;
433
434 DE_ASSERT(queueIndex < queueCount);
435 deviceDriver.getDeviceQueue(devices[deviceNdx], queueFamilyIndex, queueIndex, &queue);
436 VK_CHECK(deviceDriver.queueWaitIdle(queue));
437 }
438 }
439 }
440 catch (const vk::Error& error)
441 {
442 resultCollector.fail(de::toString(error.getError()));
443 }
444 catch (...)
445 {
446 for (int deviceNdx = (int)devices.size()-1; deviceNdx >= 0; deviceNdx--)
447 {
448 if (devices[deviceNdx] != (VkDevice)DE_NULL)
449 {
450 DeviceDriver deviceDriver(instanceDriver, devices[deviceNdx]);
451 deviceDriver.destroyDevice(devices[deviceNdx], DE_NULL/*pAllocator*/);
452 }
453 }
454
455 throw;
456 }
457
458 for (int deviceNdx = (int)devices.size()-1; deviceNdx >= 0; deviceNdx--)
459 {
460 if (devices[deviceNdx] != (VkDevice)DE_NULL)
461 {
462 DeviceDriver deviceDriver(instanceDriver, devices[deviceNdx]);
463 deviceDriver.destroyDevice(devices[deviceNdx], DE_NULL/*pAllocator*/);
464 }
465 }
466
467 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
468 }
469
createDeviceWithUnsupportedExtensionsTest(Context & context)470 tcu::TestStatus createDeviceWithUnsupportedExtensionsTest (Context& context)
471 {
472 tcu::TestLog& log = context.getTestContext().getLog();
473 const PlatformInterface& platformInterface = context.getPlatformInterface();
474 const Unique<VkInstance> instance (createDefaultInstance(platformInterface));
475 const InstanceDriver instanceDriver (platformInterface, instance.get());
476 const char* enabledExtensions[] = {"VK_UNSUPPORTED_EXTENSION", "THIS_IS_NOT_AN_EXTENSION", "VK_DONT_SUPPORT_ME"};
477 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
478 const float queuePriority = 1.0f;
479 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
480 {
481 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
482 DE_NULL,
483 (VkDeviceQueueCreateFlags)0u,
484 0, //queueFamiliIndex;
485 1, //queueCount;
486 &queuePriority, //pQueuePriorities;
487 };
488 const VkDeviceCreateInfo deviceCreateInfo =
489 {
490 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
491 DE_NULL, //pNext;
492 (VkDeviceCreateFlags)0u,
493 1, //queueRecordCount;
494 &deviceQueueCreateInfo, //pRequestedQueues;
495 0, //layerCount;
496 DE_NULL, //ppEnabledLayerNames;
497 DE_LENGTH_OF_ARRAY(enabledExtensions), //extensionCount;
498 enabledExtensions, //ppEnabledExtensionNames;
499 DE_NULL, //pEnabledFeatures;
500 };
501
502 log << TestLog::Message << "Enabled extensions are: " << TestLog::EndMessage;
503
504 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(enabledExtensions); ndx++)
505 log << TestLog::Message << enabledExtensions[ndx] << TestLog::EndMessage;
506
507 {
508 VkDevice device = (VkDevice)0;
509 const VkResult result = instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL/*pAllocator*/, &device);
510 const bool gotDevice = !!device;
511
512 if (device)
513 {
514 const DeviceDriver deviceIface (instanceDriver, device);
515 deviceIface.destroyDevice(device, DE_NULL/*pAllocator*/);
516 }
517
518 if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
519 {
520 TCU_CHECK(!gotDevice);
521 return tcu::TestStatus::pass("Pass, create device with unsupported extension is rejected.");
522 }
523 else
524 return tcu::TestStatus::fail("Fail, create device with unsupported extension but succeed.");
525 }
526 }
527
getGlobalMaxQueueCount(const vector<VkQueueFamilyProperties> & queueFamilyProperties)528 deUint32 getGlobalMaxQueueCount(const vector<VkQueueFamilyProperties>& queueFamilyProperties)
529 {
530 deUint32 maxQueueCount = 0;
531
532 for (deUint32 queueFamilyNdx = 0; queueFamilyNdx < (deUint32)queueFamilyProperties.size(); queueFamilyNdx++)
533 {
534 maxQueueCount = de::max(maxQueueCount, queueFamilyProperties[queueFamilyNdx].queueCount);
535 }
536
537 return maxQueueCount;
538 }
539
createDeviceWithVariousQueueCountsTest(Context & context)540 tcu::TestStatus createDeviceWithVariousQueueCountsTest (Context& context)
541 {
542 tcu::TestLog& log = context.getTestContext().getLog();
543 const int queueCountDiff = 1;
544 const PlatformInterface& platformInterface = context.getPlatformInterface();
545 const Unique<VkInstance> instance (createDefaultInstance(platformInterface));
546 const InstanceDriver instanceDriver (platformInterface, instance.get());
547 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
548 const vector<VkQueueFamilyProperties> queueFamilyProperties = getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
549 const vector<float> queuePriorities (getGlobalMaxQueueCount(queueFamilyProperties), 1.0f);
550 vector<VkDeviceQueueCreateInfo> deviceQueueCreateInfos;
551
552 for (deUint32 queueFamilyNdx = 0; queueFamilyNdx < (deUint32)queueFamilyProperties.size(); queueFamilyNdx++)
553 {
554 const deUint32 maxQueueCount = queueFamilyProperties[queueFamilyNdx].queueCount;
555
556 for (deUint32 queueCount = 1; queueCount <= maxQueueCount; queueCount += queueCountDiff)
557 {
558 const VkDeviceQueueCreateInfo queueCreateInfo =
559 {
560 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
561 DE_NULL,
562 (VkDeviceQueueCreateFlags)0u,
563 queueFamilyNdx,
564 queueCount,
565 queuePriorities.data()
566 };
567
568 deviceQueueCreateInfos.push_back(queueCreateInfo);
569 }
570 }
571
572 for (size_t testNdx = 0; testNdx < deviceQueueCreateInfos.size(); testNdx++)
573 {
574 const VkDeviceQueueCreateInfo& queueCreateInfo = deviceQueueCreateInfos[testNdx];
575 const VkDeviceCreateInfo deviceCreateInfo =
576 {
577 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
578 DE_NULL, //pNext;
579 (VkDeviceCreateFlags)0u,
580 1, //queueRecordCount;
581 &queueCreateInfo, //pRequestedQueues;
582 0, //layerCount;
583 DE_NULL, //ppEnabledLayerNames;
584 0, //extensionCount;
585 DE_NULL, //ppEnabledExtensionNames;
586 DE_NULL, //pEnabledFeatures;
587 };
588 const Unique<VkDevice> device (createDevice(instanceDriver, physicalDevice, &deviceCreateInfo));
589 const DeviceDriver deviceDriver (instanceDriver, device.get());
590 const deUint32 queueFamilyIndex = deviceCreateInfo.pQueueCreateInfos->queueFamilyIndex;
591 const deUint32 queueCount = deviceCreateInfo.pQueueCreateInfos->queueCount;
592
593 for (deUint32 queueIndex = 0; queueIndex < queueCount; queueIndex++)
594 {
595 VkQueue queue;
596 VkResult result;
597
598 deviceDriver.getDeviceQueue(device.get(), queueFamilyIndex, queueIndex, &queue);
599 TCU_CHECK(!!queue);
600
601 result = deviceDriver.queueWaitIdle(queue);
602 if (result != VK_SUCCESS)
603 {
604 log << TestLog::Message
605 << "vkQueueWaitIdle failed"
606 << ", queueIndex = " << queueIndex
607 << ", queueCreateInfo " << queueCreateInfo
608 << ", Error Code: " << result
609 << TestLog::EndMessage;
610 return tcu::TestStatus::fail("Fail");
611 }
612 }
613 }
614 return tcu::TestStatus::pass("Pass");
615 }
616
617 } // anonymous
618
createDeviceInitializationTests(tcu::TestContext & testCtx)619 tcu::TestCaseGroup* createDeviceInitializationTests (tcu::TestContext& testCtx)
620 {
621 de::MovePtr<tcu::TestCaseGroup> deviceInitializationTests (new tcu::TestCaseGroup(testCtx, "device_init", "Device Initialization Tests"));
622
623 addFunctionCase(deviceInitializationTests.get(), "create_instance_name_version", "", createInstanceTest);
624 addFunctionCase(deviceInitializationTests.get(), "create_instance_invalid_api_version", "", createInstanceWithInvalidApiVersionTest);
625 addFunctionCase(deviceInitializationTests.get(), "create_instance_null_appinfo", "", createInstanceWithNullApplicationInfoTest);
626 addFunctionCase(deviceInitializationTests.get(), "create_instance_unsupported_extensions", "", createInstanceWithUnsupportedExtensionsTest);
627 addFunctionCase(deviceInitializationTests.get(), "create_device", "", createDeviceTest);
628 addFunctionCase(deviceInitializationTests.get(), "create_multiple_devices", "", createMultipleDevicesTest);
629 addFunctionCase(deviceInitializationTests.get(), "create_device_unsupported_extensions", "", createDeviceWithUnsupportedExtensionsTest);
630 addFunctionCase(deviceInitializationTests.get(), "create_device_various_queue_counts", "", createDeviceWithVariousQueueCountsTest);
631
632 return deviceInitializationTests.release();
633 }
634
635 } // api
636 } // vkt
637