1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Device Initialization Tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktApiDeviceInitializationTests.hpp"
25 #include "vktTestCaseUtil.hpp"
28 #include "vkPlatform.hpp"
29 #include "vkStrUtil.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkQueryUtil.hpp"
33 #include "vkMemUtil.hpp"
34 #include "vkDeviceUtil.hpp"
35 #include "vkApiVersion.hpp"
37 #include "tcuTestLog.hpp"
38 #include "tcuResultCollector.hpp"
39 #include "tcuCommandLine.hpp"
41 #include "deUniquePtr.hpp"
42 #include "deStringUtil.hpp"
59 tcu::TestStatus createInstanceTest (Context& context)
61 tcu::TestLog& log = context.getTestContext().getLog();
62 tcu::ResultCollector resultCollector (log);
63 const char* appNames[] = { "appName", DE_NULL, "", "app, name", "app(\"name\"", "app~!@#$%^&*()_+name", "app\nName", "app\r\nName" };
64 const char* engineNames[] = { "engineName", DE_NULL, "", "engine. name", "engine\"(name)", "eng~!@#$%^&*()_+name", "engine\nName", "engine\r\nName" };
65 const int patchNumbers[] = { 0, 1, 2, 3, 4, 5, 13, 4094, 4095 };
66 const deUint32 appVersions[] = { 0, 1, (deUint32)-1 };
67 const deUint32 engineVersions[] = { 0, 1, (deUint32)-1 };
68 const PlatformInterface& platformInterface = context.getPlatformInterface();
69 const deUint32 apiVersion = context.getUsedApiVersion();
70 vector<VkApplicationInfo> appInfos;
73 for (int appNameNdx = 0; appNameNdx < DE_LENGTH_OF_ARRAY(appNames); appNameNdx++)
75 const VkApplicationInfo appInfo =
77 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
78 DE_NULL, // const void* pNext;
79 appNames[appNameNdx], // const char* pAppName;
80 0u, // deUint32 appVersion;
81 "engineName", // const char* pEngineName;
82 0u, // deUint32 engineVersion;
83 apiVersion, // deUint32 apiVersion;
86 appInfos.push_back(appInfo);
89 // test over engineName
90 for (int engineNameNdx = 0; engineNameNdx < DE_LENGTH_OF_ARRAY(engineNames); engineNameNdx++)
92 const VkApplicationInfo appInfo =
94 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
95 DE_NULL, // const void* pNext;
96 "appName", // const char* pAppName;
97 0u, // deUint32 appVersion;
98 engineNames[engineNameNdx], // const char* pEngineName;
99 0u, // deUint32 engineVersion;
100 apiVersion, // deUint32 apiVersion;
103 appInfos.push_back(appInfo);
106 // test over appVersion
107 for (int appVersionNdx = 0; appVersionNdx < DE_LENGTH_OF_ARRAY(appVersions); appVersionNdx++)
109 const VkApplicationInfo appInfo =
111 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
112 DE_NULL, // const void* pNext;
113 "appName", // const char* pAppName;
114 appVersions[appVersionNdx], // deUint32 appVersion;
115 "engineName", // const char* pEngineName;
116 0u, // deUint32 engineVersion;
117 apiVersion, // deUint32 apiVersion;
120 appInfos.push_back(appInfo);
123 // test over engineVersion
124 for (int engineVersionNdx = 0; engineVersionNdx < DE_LENGTH_OF_ARRAY(engineVersions); engineVersionNdx++)
126 const VkApplicationInfo appInfo =
128 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
129 DE_NULL, // const void* pNext;
130 "appName", // const char* pAppName;
131 0u, // deUint32 appVersion;
132 "engineName", // const char* pEngineName;
133 engineVersions[engineVersionNdx], // deUint32 engineVersion;
134 apiVersion, // deUint32 apiVersion;
137 appInfos.push_back(appInfo);
139 const deUint32 manjorNum = unpackVersion(apiVersion).majorNum;
140 const deUint32 minorNum = unpackVersion(apiVersion).minorNum;
142 // patch component of api version checking (should be ignored by implementation)
143 for (int patchVersion = 0; patchVersion < DE_LENGTH_OF_ARRAY(patchNumbers); patchVersion++)
145 const VkApplicationInfo appInfo =
147 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
148 DE_NULL, // const void* pNext;
149 "appName", // const char* pAppName;
150 0u, // deUint32 appVersion;
151 "engineName", // const char* pEngineName;
152 0u, // deUint32 engineVersion;
153 VK_MAKE_VERSION(manjorNum, minorNum, patchNumbers[patchVersion]), // deUint32 apiVersion;
156 appInfos.push_back(appInfo);
159 // test when apiVersion is 0
161 const VkApplicationInfo appInfo =
163 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
164 DE_NULL, // const void* pNext;
165 "appName", // const char* pAppName;
166 0u, // deUint32 appVersion;
167 "engineName", // const char* pEngineName;
168 0u, // deUint32 engineVersion;
169 0u, // deUint32 apiVersion;
172 appInfos.push_back(appInfo);
176 for (size_t appInfoNdx = 0; appInfoNdx < appInfos.size(); ++appInfoNdx)
178 const VkApplicationInfo& appInfo = appInfos[appInfoNdx];
179 const VkInstanceCreateInfo instanceCreateInfo =
181 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
182 DE_NULL, // const void* pNext;
183 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
184 &appInfo, // const VkApplicationInfo* pAppInfo;
185 0u, // deUint32 layerCount;
186 DE_NULL, // const char*const* ppEnabledLayernames;
187 0u, // deUint32 extensionCount;
188 DE_NULL, // const char*const* ppEnabledExtensionNames;
191 log << TestLog::Message << "Creating instance with appInfo: " << appInfo << TestLog::EndMessage;
195 const Unique<VkInstance> instance(createInstance(platformInterface, &instanceCreateInfo));
196 log << TestLog::Message << "Succeeded" << TestLog::EndMessage;
198 catch (const vk::Error& err)
200 resultCollector.fail("Failed, Error code: " + de::toString(err.getMessage()));
204 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
207 tcu::TestStatus createInstanceWithInvalidApiVersionTest (Context& context)
209 tcu::TestLog& log = context.getTestContext().getLog();
210 tcu::ResultCollector resultCollector (log);
211 const PlatformInterface& platformInterface = context.getPlatformInterface();
213 deUint32 instanceApiVersion = 0u;
214 context.getPlatformInterface().enumerateInstanceVersion(&instanceApiVersion);
216 const ApiVersion apiVersion = unpackVersion(instanceApiVersion);
218 const deUint32 invalidMajorVersion = (1 << 10) - 1;
219 const deUint32 invalidMinorVersion = (1 << 10) - 1;
220 vector<ApiVersion> invalidApiVersions;
222 invalidApiVersions.push_back(ApiVersion(invalidMajorVersion, apiVersion.minorNum, apiVersion.patchNum));
223 invalidApiVersions.push_back(ApiVersion(apiVersion.majorNum, invalidMinorVersion, apiVersion.patchNum));
225 for (size_t apiVersionNdx = 0; apiVersionNdx < invalidApiVersions.size(); apiVersionNdx++)
227 const VkApplicationInfo appInfo =
229 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
230 DE_NULL, // const void* pNext;
231 "appName", // const char* pAppName;
232 0u, // deUint32 appVersion;
233 "engineName", // const char* pEngineName;
234 0u, // deUint32 engineVersion;
235 pack(invalidApiVersions[apiVersionNdx]), // deUint32 apiVersion;
237 const VkInstanceCreateInfo instanceCreateInfo =
239 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
240 DE_NULL, // const void* pNext;
241 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
242 &appInfo, // const VkApplicationInfo* pAppInfo;
243 0u, // deUint32 layerCount;
244 DE_NULL, // const char*const* ppEnabledLayernames;
245 0u, // deUint32 extensionCount;
246 DE_NULL, // const char*const* ppEnabledExtensionNames;
250 log << TestLog::Message
251 << "API version reported by enumerateInstanceVersion: " << apiVersion
252 << ", api version used to create instance: " << invalidApiVersions[apiVersionNdx]
253 << TestLog::EndMessage;
256 VkInstance instance = (VkInstance)0;
257 const VkResult result = platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
258 const bool gotInstance = !!instance;
262 const InstanceDriver instanceIface(platformInterface, instance);
263 instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
266 if (apiVersion.majorNum == 1 && apiVersion.minorNum == 0)
268 if (result == VK_ERROR_INCOMPATIBLE_DRIVER)
270 TCU_CHECK(!gotInstance);
271 log << TestLog::Message << "Pass, instance creation with invalid apiVersion is rejected" << TestLog::EndMessage;
274 resultCollector.fail("Fail, instance creation with invalid apiVersion is not rejected");
276 else if (apiVersion.majorNum == 1 && apiVersion.minorNum >= 1)
278 if (result == VK_SUCCESS)
280 TCU_CHECK(gotInstance);
281 log << TestLog::Message << "Pass, instance creation with nonstandard apiVersion succeeds for Vulkan 1.1" << TestLog::EndMessage;
283 else if (result == VK_ERROR_INCOMPATIBLE_DRIVER)
285 resultCollector.fail("Fail, In Vulkan 1.1 instance creation must not return VK_ERROR_INCOMPATIBLE_DRIVER.");
289 std::ostringstream message;
290 message << "Fail, createInstance failed with " << result;
291 resultCollector.fail(message.str().c_str());
297 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
300 tcu::TestStatus createInstanceWithNullApplicationInfoTest (Context& context)
302 tcu::TestLog& log = context.getTestContext().getLog();
303 tcu::ResultCollector resultCollector (log);
304 const PlatformInterface& platformInterface = context.getPlatformInterface();
306 const VkInstanceCreateInfo instanceCreateInfo =
308 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
309 DE_NULL, // const void* pNext;
310 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
311 DE_NULL, // const VkApplicationInfo* pAppInfo;
312 0u, // deUint32 layerCount;
313 DE_NULL, // const char*const* ppEnabledLayernames;
314 0u, // deUint32 extensionCount;
315 DE_NULL, // const char*const* ppEnabledExtensionNames;
318 log << TestLog::Message << "Creating instance with NULL pApplicationInfo" << TestLog::EndMessage;
322 const Unique<VkInstance> instance(createInstance(platformInterface, &instanceCreateInfo));
323 log << TestLog::Message << "Succeeded" << TestLog::EndMessage;
325 catch (const vk::Error& err)
327 resultCollector.fail("Failed, Error code: " + de::toString(err.getMessage()));
330 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
333 tcu::TestStatus createInstanceWithUnsupportedExtensionsTest (Context& context)
335 tcu::TestLog& log = context.getTestContext().getLog();
336 const PlatformInterface& platformInterface = context.getPlatformInterface();
337 const char* enabledExtensions[] = {"VK_UNSUPPORTED_EXTENSION", "THIS_IS_NOT_AN_EXTENSION"};
338 const deUint32 apiVersion = context.getUsedApiVersion();
339 const VkApplicationInfo appInfo =
341 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
342 DE_NULL, // const void* pNext;
343 "appName", // const char* pAppName;
344 0u, // deUint32 appVersion;
345 "engineName", // const char* pEngineName;
346 0u, // deUint32 engineVersion;
347 apiVersion, // deUint32 apiVersion;
349 const VkInstanceCreateInfo instanceCreateInfo =
351 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
352 DE_NULL, // const void* pNext;
353 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
354 &appInfo, // const VkApplicationInfo* pAppInfo;
355 0u, // deUint32 layerCount;
356 DE_NULL, // const char*const* ppEnabledLayernames;
357 DE_LENGTH_OF_ARRAY(enabledExtensions), // deUint32 extensionCount;
358 enabledExtensions, // const char*const* ppEnabledExtensionNames;
361 log << TestLog::Message << "Enabled extensions are: " << TestLog::EndMessage;
363 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(enabledExtensions); ndx++)
364 log << TestLog::Message << enabledExtensions[ndx] << TestLog::EndMessage;
367 VkInstance instance = (VkInstance)0;
368 const VkResult result = platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
369 const bool gotInstance = !!instance;
373 const InstanceDriver instanceIface (platformInterface, instance);
374 instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
377 if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
379 TCU_CHECK(!gotInstance);
380 return tcu::TestStatus::pass("Pass, creating instance with unsupported extension was rejected.");
383 return tcu::TestStatus::fail("Fail, creating instance with unsupported extensions succeeded.");
389 UTF8ABUSE_LONGNAME = 0,
391 UTF8ABUSE_OVERLONGNUL,
399 string getUTF8AbuseString (int index)
403 case UTF8ABUSE_LONGNAME:
404 // Generate a long name.
406 std::string longname;
407 longname.resize(65535, 'k');
411 case UTF8ABUSE_BADNAMES:
412 // Various illegal code points in utf-8
414 "Illegal bytes in UTF-8: "
415 "\xc0 \xc1 \xf5 \xf6 \xf7 \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe \xff"
416 "illegal surrogates: \xed\xad\xbf \xed\xbe\x80");
418 case UTF8ABUSE_OVERLONGNUL:
419 // Zero encoded as overlong, not exactly legal but often supported to differentiate from terminating zero
420 return string("UTF-8 encoded nul \xC0\x80 (should not end name)");
422 case UTF8ABUSE_OVERLONG:
423 // Some overlong encodings
425 "UTF-8 overlong \xF0\x82\x82\xAC \xfc\x83\xbf\xbf\xbf\xbf \xf8\x87\xbf\xbf\xbf "
428 case UTF8ABUSE_ZALGO:
429 // Internet "zalgo" meme "bleeding text"
431 "\x56\xcc\xb5\xcc\x85\xcc\x94\xcc\x88\xcd\x8a\xcc\x91\xcc\x88\xcd\x91\xcc\x83\xcd\x82"
432 "\xcc\x83\xcd\x90\xcc\x8a\xcc\x92\xcc\x92\xcd\x8b\xcc\x94\xcd\x9d\xcc\x98\xcc\xab\xcc"
433 "\xae\xcc\xa9\xcc\xad\xcc\x97\xcc\xb0\x75\xcc\xb6\xcc\xbe\xcc\x80\xcc\x82\xcc\x84\xcd"
434 "\x84\xcc\x90\xcd\x86\xcc\x9a\xcd\x84\xcc\x9b\xcd\x86\xcd\x92\xcc\x9a\xcd\x99\xcd\x99"
435 "\xcc\xbb\xcc\x98\xcd\x8e\xcd\x88\xcd\x9a\xcc\xa6\xcc\x9c\xcc\xab\xcc\x99\xcd\x94\xcd"
436 "\x99\xcd\x95\xcc\xa5\xcc\xab\xcd\x89\x6c\xcc\xb8\xcc\x8e\xcc\x8b\xcc\x8b\xcc\x9a\xcc"
437 "\x8e\xcd\x9d\xcc\x80\xcc\xa1\xcc\xad\xcd\x9c\xcc\xba\xcc\x96\xcc\xb3\xcc\xa2\xcd\x8e"
438 "\xcc\xa2\xcd\x96\x6b\xcc\xb8\xcc\x84\xcd\x81\xcc\xbf\xcc\x8d\xcc\x89\xcc\x85\xcc\x92"
439 "\xcc\x84\xcc\x90\xcd\x81\xcc\x93\xcd\x90\xcd\x92\xcd\x9d\xcc\x84\xcd\x98\xcd\x9d\xcd"
440 "\xa0\xcd\x91\xcc\x94\xcc\xb9\xcd\x93\xcc\xa5\xcd\x87\xcc\xad\xcc\xa7\xcd\x96\xcd\x99"
441 "\xcc\x9d\xcc\xbc\xcd\x96\xcd\x93\xcc\x9d\xcc\x99\xcc\xa8\xcc\xb1\xcd\x85\xcc\xba\xcc"
442 "\xa7\x61\xcc\xb8\xcc\x8e\xcc\x81\xcd\x90\xcd\x84\xcd\x8c\xcc\x8c\xcc\x85\xcd\x86\xcc"
443 "\x84\xcd\x84\xcc\x90\xcc\x84\xcc\x8d\xcd\x99\xcd\x8d\xcc\xb0\xcc\xa3\xcc\xa6\xcd\x89"
444 "\xcd\x8d\xcd\x87\xcc\x98\xcd\x8d\xcc\xa4\xcd\x9a\xcd\x8e\xcc\xab\xcc\xb9\xcc\xac\xcc"
445 "\xa2\xcd\x87\xcc\xa0\xcc\xb3\xcd\x89\xcc\xb9\xcc\xa7\xcc\xa6\xcd\x89\xcd\x95\x6e\xcc"
446 "\xb8\xcd\x8a\xcc\x8a\xcd\x82\xcc\x9b\xcd\x81\xcd\x90\xcc\x85\xcc\x9b\xcd\x80\xcd\x91"
447 "\xcd\x9b\xcc\x81\xcd\x81\xcc\x9a\xcc\xb3\xcd\x9c\xcc\x9e\xcc\x9d\xcd\x99\xcc\xa2\xcd"
448 "\x93\xcd\x96\xcc\x97\xff");
450 case UTF8ABUSE_CHINESE:
451 // Some Chinese glyphs.
452 // "English equivalent: The devil is in the details", https://en.wikiquote.org/wiki/Chinese_proverbs
454 "\xe8\xaf\xbb\xe4\xb9\xa6\xe9\xa1\xbb\xe7\x94\xa8\xe6\x84\x8f\xef\xbc\x8c\xe4\xb8\x80"
455 "\xe5\xad\x97\xe5\x80\xbc\xe5\x8d\x83\xe9\x87\x91\x20");
458 DE_ASSERT(index == UTF8ABUSE_EMPTY);
459 // Also try an empty string.
464 tcu::TestStatus createInstanceWithExtensionNameAbuseTest (Context& context)
466 const PlatformInterface& platformInterface = context.getPlatformInterface();
467 const char* extensionList[1] = { 0 };
468 const deUint32 apiVersion = context.getUsedApiVersion();
469 deUint32 failCount = 0;
471 for (int i = 0; i < UTF8ABUSE_MAX; i++)
473 string abuseString = getUTF8AbuseString(i);
474 extensionList[0] = abuseString.c_str();
476 const VkApplicationInfo appInfo =
478 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
479 DE_NULL, // const void* pNext;
480 "appName", // const char* pAppName;
481 0u, // deUint32 appVersion;
482 "engineName", // const char* pEngineName;
483 0u, // deUint32 engineVersion;
484 apiVersion, // deUint32 apiVersion;
487 const VkInstanceCreateInfo instanceCreateInfo =
489 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
490 DE_NULL, // const void* pNext;
491 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
492 &appInfo, // const VkApplicationInfo* pAppInfo;
493 0u, // deUint32 layerCount;
494 DE_NULL, // const char*const* ppEnabledLayernames;
495 1u, // deUint32 extensionCount;
496 extensionList, // const char*const* ppEnabledExtensionNames;
500 VkInstance instance = (VkInstance)0;
501 const VkResult result = platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
502 const bool gotInstance = !!instance;
506 const InstanceDriver instanceIface(platformInterface, instance);
507 instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
510 if (result != VK_ERROR_EXTENSION_NOT_PRESENT)
513 TCU_CHECK(!gotInstance);
518 return tcu::TestStatus::fail("Fail, creating instances with unsupported extensions succeeded.");
520 return tcu::TestStatus::pass("Pass, creating instances with unsupported extensions were rejected.");
523 tcu::TestStatus createInstanceWithLayerNameAbuseTest (Context& context)
525 const PlatformInterface& platformInterface = context.getPlatformInterface();
526 const char* layerList[1] = { 0 };
527 const deUint32 apiVersion = context.getUsedApiVersion();
528 deUint32 failCount = 0;
530 for (int i = 0; i < UTF8ABUSE_MAX; i++)
532 string abuseString = getUTF8AbuseString(i);
533 layerList[0] = abuseString.c_str();
535 const VkApplicationInfo appInfo =
537 VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType;
538 DE_NULL, // const void* pNext;
539 "appName", // const char* pAppName;
540 0u, // deUint32 appVersion;
541 "engineName", // const char* pEngineName;
542 0u, // deUint32 engineVersion;
543 apiVersion, // deUint32 apiVersion;
546 const VkInstanceCreateInfo instanceCreateInfo =
548 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType;
549 DE_NULL, // const void* pNext;
550 (VkInstanceCreateFlags)0u, // VkInstanceCreateFlags flags;
551 &appInfo, // const VkApplicationInfo* pAppInfo;
552 1u, // deUint32 layerCount;
553 layerList, // const char*const* ppEnabledLayernames;
554 0u, // deUint32 extensionCount;
555 DE_NULL, // const char*const* ppEnabledExtensionNames;
559 VkInstance instance = (VkInstance)0;
560 const VkResult result = platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
561 const bool gotInstance = !!instance;
565 const InstanceDriver instanceIface(platformInterface, instance);
566 instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
569 if (result != VK_ERROR_LAYER_NOT_PRESENT)
572 TCU_CHECK(!gotInstance);
577 return tcu::TestStatus::fail("Fail, creating instances with unsupported layers succeeded.");
579 return tcu::TestStatus::pass("Pass, creating instances with unsupported layers were rejected.");
582 tcu::TestStatus createDeviceTest (Context& context)
584 const PlatformInterface& platformInterface = context.getPlatformInterface();
585 const Unique<VkInstance> instance (createDefaultInstance(platformInterface, context.getUsedApiVersion()));
586 const InstanceDriver instanceDriver (platformInterface, instance.get());
587 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
588 const deUint32 queueFamilyIndex = 0;
589 const deUint32 queueCount = 1;
590 const deUint32 queueIndex = 0;
591 const float queuePriority = 1.0f;
593 const vector<VkQueueFamilyProperties> queueFamilyProperties = getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
595 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
597 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
599 (VkDeviceQueueCreateFlags)0u,
600 queueFamilyIndex, //queueFamilyIndex;
601 queueCount, //queueCount;
602 &queuePriority, //pQueuePriorities;
604 const VkDeviceCreateInfo deviceCreateInfo =
606 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
608 (VkDeviceCreateFlags)0u,
609 1, //queueRecordCount;
610 &deviceQueueCreateInfo, //pRequestedQueues;
612 DE_NULL, //ppEnabledLayerNames;
614 DE_NULL, //ppEnabledExtensionNames;
615 DE_NULL, //pEnabledFeatures;
618 const Unique<VkDevice> device (createDevice(platformInterface, *instance, instanceDriver, physicalDevice, &deviceCreateInfo));
619 const DeviceDriver deviceDriver (platformInterface, instance.get(), device.get());
620 const VkQueue queue = getDeviceQueue(deviceDriver, *device, queueFamilyIndex, queueIndex);
622 VK_CHECK(deviceDriver.queueWaitIdle(queue));
624 return tcu::TestStatus::pass("Pass");
627 tcu::TestStatus createMultipleDevicesTest (Context& context)
629 tcu::TestLog& log = context.getTestContext().getLog();
630 tcu::ResultCollector resultCollector (log);
631 const int numDevices = 5;
632 const PlatformInterface& platformInterface = context.getPlatformInterface();
633 const Unique<VkInstance> instance (createDefaultInstance(platformInterface, context.getUsedApiVersion()));
634 const InstanceDriver instanceDriver (platformInterface, instance.get());
635 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
636 const vector<VkQueueFamilyProperties> queueFamilyProperties = getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
637 const deUint32 queueFamilyIndex = 0;
638 const deUint32 queueCount = 1;
639 const deUint32 queueIndex = 0;
640 const float queuePriority = 1.0f;
641 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
643 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
645 (VkDeviceQueueCreateFlags)0u, //flags;
646 queueFamilyIndex, //queueFamilyIndex;
647 queueCount, //queueCount;
648 &queuePriority, //pQueuePriorities;
650 const VkDeviceCreateInfo deviceCreateInfo =
652 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
654 (VkDeviceCreateFlags)0u,
655 1, //queueRecordCount;
656 &deviceQueueCreateInfo, //pRequestedQueues;
658 DE_NULL, //ppEnabledLayerNames;
660 DE_NULL, //ppEnabledExtensionNames;
661 DE_NULL, //pEnabledFeatures;
663 vector<VkDevice> devices(numDevices, (VkDevice)DE_NULL);
667 for (int deviceNdx = 0; deviceNdx < numDevices; deviceNdx++)
669 const VkResult result = instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL/*pAllocator*/, &devices[deviceNdx]);
671 if (result != VK_SUCCESS)
673 resultCollector.fail("Failed to create Device No." + de::toString(deviceNdx) + ", Error Code: " + de::toString(result));
678 const DeviceDriver deviceDriver (platformInterface, instance.get(), devices[deviceNdx]);
679 const VkQueue queue = getDeviceQueue(deviceDriver, devices[deviceNdx], queueFamilyIndex, queueIndex);
681 VK_CHECK(deviceDriver.queueWaitIdle(queue));
685 catch (const vk::Error& error)
687 resultCollector.fail(de::toString(error.getError()));
691 for (int deviceNdx = (int)devices.size()-1; deviceNdx >= 0; deviceNdx--)
693 if (devices[deviceNdx] != (VkDevice)DE_NULL)
695 DeviceDriver deviceDriver(platformInterface, instance.get(), devices[deviceNdx]);
696 deviceDriver.destroyDevice(devices[deviceNdx], DE_NULL/*pAllocator*/);
703 for (int deviceNdx = (int)devices.size()-1; deviceNdx >= 0; deviceNdx--)
705 if (devices[deviceNdx] != (VkDevice)DE_NULL)
707 DeviceDriver deviceDriver(platformInterface, instance.get(), devices[deviceNdx]);
708 deviceDriver.destroyDevice(devices[deviceNdx], DE_NULL/*pAllocator*/);
712 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
715 tcu::TestStatus createDeviceWithUnsupportedExtensionsTest (Context& context)
717 tcu::TestLog& log = context.getTestContext().getLog();
718 const PlatformInterface& platformInterface = context.getPlatformInterface();
719 const Unique<VkInstance> instance (createDefaultInstance(platformInterface, context.getUsedApiVersion()));
720 const InstanceDriver instanceDriver (platformInterface, instance.get());
721 const char* enabledExtensions[] = {"VK_UNSUPPORTED_EXTENSION", "THIS_IS_NOT_AN_EXTENSION", "VK_DONT_SUPPORT_ME"};
722 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
723 const float queuePriority = 1.0f;
724 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
726 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
728 (VkDeviceQueueCreateFlags)0u,
729 0, //queueFamilyIndex;
731 &queuePriority, //pQueuePriorities;
733 const VkDeviceCreateInfo deviceCreateInfo =
735 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
737 (VkDeviceCreateFlags)0u,
738 1, //queueRecordCount;
739 &deviceQueueCreateInfo, //pRequestedQueues;
741 DE_NULL, //ppEnabledLayerNames;
742 DE_LENGTH_OF_ARRAY(enabledExtensions), //extensionCount;
743 enabledExtensions, //ppEnabledExtensionNames;
744 DE_NULL, //pEnabledFeatures;
747 log << TestLog::Message << "Enabled extensions are: " << TestLog::EndMessage;
749 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(enabledExtensions); ndx++)
750 log << TestLog::Message << enabledExtensions[ndx] << TestLog::EndMessage;
753 VkDevice device = (VkDevice)0;
754 const VkResult result = instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL/*pAllocator*/, &device);
755 const bool gotDevice = !!device;
759 const DeviceDriver deviceIface (platformInterface, instance.get(), device);
760 deviceIface.destroyDevice(device, DE_NULL/*pAllocator*/);
763 if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
765 TCU_CHECK(!gotDevice);
766 return tcu::TestStatus::pass("Pass, create device with unsupported extension is rejected.");
769 return tcu::TestStatus::fail("Fail, create device with unsupported extension but succeed.");
773 deUint32 getGlobalMaxQueueCount(const vector<VkQueueFamilyProperties>& queueFamilyProperties)
775 deUint32 maxQueueCount = 0;
777 for (deUint32 queueFamilyNdx = 0; queueFamilyNdx < (deUint32)queueFamilyProperties.size(); queueFamilyNdx++)
779 maxQueueCount = de::max(maxQueueCount, queueFamilyProperties[queueFamilyNdx].queueCount);
782 return maxQueueCount;
785 tcu::TestStatus createDeviceWithVariousQueueCountsTest (Context& context)
787 tcu::TestLog& log = context.getTestContext().getLog();
788 const int queueCountDiff = 1;
789 const PlatformInterface& platformInterface = context.getPlatformInterface();
790 const Unique<VkInstance> instance (createDefaultInstance(platformInterface, context.getUsedApiVersion()));
791 const InstanceDriver instanceDriver (platformInterface, instance.get());
792 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
793 const vector<VkQueueFamilyProperties> queueFamilyProperties = getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
794 const vector<float> queuePriorities (getGlobalMaxQueueCount(queueFamilyProperties), 1.0f);
795 vector<VkDeviceQueueCreateInfo> deviceQueueCreateInfos;
797 for (deUint32 queueFamilyNdx = 0; queueFamilyNdx < (deUint32)queueFamilyProperties.size(); queueFamilyNdx++)
799 const deUint32 maxQueueCount = queueFamilyProperties[queueFamilyNdx].queueCount;
801 for (deUint32 queueCount = 1; queueCount <= maxQueueCount; queueCount += queueCountDiff)
803 const VkDeviceQueueCreateInfo queueCreateInfo =
805 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
807 (VkDeviceQueueCreateFlags)0u,
810 queuePriorities.data()
813 deviceQueueCreateInfos.push_back(queueCreateInfo);
817 for (size_t testNdx = 0; testNdx < deviceQueueCreateInfos.size(); testNdx++)
819 const VkDeviceQueueCreateInfo& queueCreateInfo = deviceQueueCreateInfos[testNdx];
820 const VkDeviceCreateInfo deviceCreateInfo =
822 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, //sType;
824 (VkDeviceCreateFlags)0u,
825 1, //queueRecordCount;
826 &queueCreateInfo, //pRequestedQueues;
828 DE_NULL, //ppEnabledLayerNames;
830 DE_NULL, //ppEnabledExtensionNames;
831 DE_NULL, //pEnabledFeatures;
833 const Unique<VkDevice> device (createDevice(platformInterface, *instance, instanceDriver, physicalDevice, &deviceCreateInfo));
834 const DeviceDriver deviceDriver (platformInterface, instance.get(), device.get());
835 const deUint32 queueFamilyIndex = deviceCreateInfo.pQueueCreateInfos->queueFamilyIndex;
836 const deUint32 queueCount = deviceCreateInfo.pQueueCreateInfos->queueCount;
838 for (deUint32 queueIndex = 0; queueIndex < queueCount; queueIndex++)
840 const VkQueue queue = getDeviceQueue(deviceDriver, *device, queueFamilyIndex, queueIndex);
845 result = deviceDriver.queueWaitIdle(queue);
846 if (result != VK_SUCCESS)
848 log << TestLog::Message
849 << "vkQueueWaitIdle failed"
850 << ", queueIndex = " << queueIndex
851 << ", queueCreateInfo " << queueCreateInfo
852 << ", Error Code: " << result
853 << TestLog::EndMessage;
854 return tcu::TestStatus::fail("Fail");
858 return tcu::TestStatus::pass("Pass");
861 tcu::TestStatus createDeviceFeatures2Test (Context& context)
863 const PlatformInterface& vkp = context.getPlatformInterface();
864 const Unique<VkInstance> instance (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
865 const InstanceDriver vki (vkp, instance.get());
866 const VkPhysicalDevice physicalDevice = chooseDevice(vki, instance.get(), context.getTestContext().getCommandLine());
867 const deUint32 queueFamilyIndex = 0;
868 const deUint32 queueCount = 1;
869 const deUint32 queueIndex = 0;
870 const float queuePriority = 1.0f;
872 const InstanceDriver instanceDriver (vkp, instance.get());
873 const vector<VkQueueFamilyProperties> queueFamilyProperties = getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
875 VkPhysicalDeviceFeatures2 enabledFeatures;
876 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
878 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
880 (VkDeviceQueueCreateFlags)0u,
885 const VkDeviceCreateInfo deviceCreateInfo =
887 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
889 (VkDeviceCreateFlags)0u,
891 &deviceQueueCreateInfo,
899 // Populate enabledFeatures
900 enabledFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
901 enabledFeatures.pNext = DE_NULL;
903 vki.getPhysicalDeviceFeatures2(physicalDevice, &enabledFeatures);
906 const Unique<VkDevice> device (createDevice(vkp, *instance, vki, physicalDevice, &deviceCreateInfo));
907 const DeviceDriver vkd (vkp, instance.get(), device.get());
908 const VkQueue queue = getDeviceQueue(vkd, *device, queueFamilyIndex, queueIndex);
910 VK_CHECK(vkd.queueWaitIdle(queue));
913 return tcu::TestStatus::pass("Pass");
922 #define FEATURE_ITEM(MEMBER) {#MEMBER, DE_OFFSET_OF(VkPhysicalDeviceFeatures, MEMBER)}
924 tcu::TestStatus createDeviceWithUnsupportedFeaturesTest (Context& context)
926 tcu::TestLog& log = context.getTestContext().getLog();
927 tcu::ResultCollector resultCollector (log);
928 const PlatformInterface& platformInterface = context.getPlatformInterface();
929 const Move<VkInstance> instance (createDefaultInstance(platformInterface, context.getUsedApiVersion()));
930 const InstanceDriver instanceDriver (platformInterface, instance.get());
931 const VkPhysicalDevice physicalDevice = chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
932 const deUint32 queueFamilyIndex = 0;
933 const deUint32 queueCount = 1;
934 const float queuePriority = 1.0f;
935 VkPhysicalDeviceFeatures physicalDeviceFeatures;
937 const vector<VkQueueFamilyProperties> queueFamilyProperties = getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
939 instanceDriver.getPhysicalDeviceFeatures(physicalDevice, &physicalDeviceFeatures);
941 static const Feature features[] =
943 FEATURE_ITEM(robustBufferAccess),
944 FEATURE_ITEM(fullDrawIndexUint32),
945 FEATURE_ITEM(imageCubeArray),
946 FEATURE_ITEM(independentBlend),
947 FEATURE_ITEM(geometryShader),
948 FEATURE_ITEM(tessellationShader),
949 FEATURE_ITEM(sampleRateShading),
950 FEATURE_ITEM(dualSrcBlend),
951 FEATURE_ITEM(logicOp),
952 FEATURE_ITEM(multiDrawIndirect),
953 FEATURE_ITEM(drawIndirectFirstInstance),
954 FEATURE_ITEM(depthClamp),
955 FEATURE_ITEM(depthBiasClamp),
956 FEATURE_ITEM(fillModeNonSolid),
957 FEATURE_ITEM(depthBounds),
958 FEATURE_ITEM(wideLines),
959 FEATURE_ITEM(largePoints),
960 FEATURE_ITEM(alphaToOne),
961 FEATURE_ITEM(multiViewport),
962 FEATURE_ITEM(samplerAnisotropy),
963 FEATURE_ITEM(textureCompressionETC2),
964 FEATURE_ITEM(textureCompressionASTC_LDR),
965 FEATURE_ITEM(textureCompressionBC),
966 FEATURE_ITEM(occlusionQueryPrecise),
967 FEATURE_ITEM(pipelineStatisticsQuery),
968 FEATURE_ITEM(vertexPipelineStoresAndAtomics),
969 FEATURE_ITEM(fragmentStoresAndAtomics),
970 FEATURE_ITEM(shaderTessellationAndGeometryPointSize),
971 FEATURE_ITEM(shaderImageGatherExtended),
972 FEATURE_ITEM(shaderStorageImageExtendedFormats),
973 FEATURE_ITEM(shaderStorageImageMultisample),
974 FEATURE_ITEM(shaderStorageImageReadWithoutFormat),
975 FEATURE_ITEM(shaderStorageImageWriteWithoutFormat),
976 FEATURE_ITEM(shaderUniformBufferArrayDynamicIndexing),
977 FEATURE_ITEM(shaderSampledImageArrayDynamicIndexing),
978 FEATURE_ITEM(shaderStorageBufferArrayDynamicIndexing),
979 FEATURE_ITEM(shaderStorageImageArrayDynamicIndexing),
980 FEATURE_ITEM(shaderClipDistance),
981 FEATURE_ITEM(shaderCullDistance),
982 FEATURE_ITEM(shaderFloat64),
983 FEATURE_ITEM(shaderInt64),
984 FEATURE_ITEM(shaderInt16),
985 FEATURE_ITEM(shaderResourceResidency),
986 FEATURE_ITEM(shaderResourceMinLod),
987 FEATURE_ITEM(sparseBinding),
988 FEATURE_ITEM(sparseResidencyBuffer),
989 FEATURE_ITEM(sparseResidencyImage2D),
990 FEATURE_ITEM(sparseResidencyImage3D),
991 FEATURE_ITEM(sparseResidency2Samples),
992 FEATURE_ITEM(sparseResidency4Samples),
993 FEATURE_ITEM(sparseResidency8Samples),
994 FEATURE_ITEM(sparseResidency16Samples),
995 FEATURE_ITEM(sparseResidencyAliased),
996 FEATURE_ITEM(variableMultisampleRate),
997 FEATURE_ITEM(inheritedQueries)
1000 const int numFeatures = DE_LENGTH_OF_ARRAY(features);
1003 for (int featureNdx = 0; featureNdx < numFeatures; featureNdx++)
1005 // Test only features that are not supported.
1006 if (*(((VkBool32*)((deUint8*)(&physicalDeviceFeatures) + features[featureNdx].offset))))
1009 VkPhysicalDeviceFeatures enabledFeatures;
1011 for (int i = 0; i < numFeatures; i++)
1012 *((VkBool32*)((deUint8*)(&enabledFeatures) + features[i].offset)) = (i == featureNdx ? VK_TRUE : VK_FALSE);
1014 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
1016 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
1018 (VkDeviceQueueCreateFlags)0u,
1023 const VkDeviceCreateInfo deviceCreateInfo =
1025 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
1027 (VkDeviceCreateFlags)0u,
1029 &deviceQueueCreateInfo,
1038 const VkResult res = instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL, &device);
1040 if (res != VK_ERROR_FEATURE_NOT_PRESENT)
1043 resultCollector.fail("Not returning VK_ERROR_FEATURE_NOT_PRESENT when creating device with feature "
1044 + de::toString(features[featureNdx].name) + ", which was reported as unsupported.");
1049 return tcu::TestStatus(resultCollector.getResult(), "Enabling " + de::toString(numErrors) + " unsupported features didn't return VK_ERROR_FEATURE_NOT_PRESENT.");
1051 return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
1054 tcu::TestStatus createDeviceQueue2Test (Context& context)
1056 if (!context.contextSupports(vk::ApiVersion(1, 1, 0)))
1057 TCU_THROW(NotSupportedError, "Vulkan 1.1 is not supported");
1059 const PlatformInterface& platformInterface = context.getPlatformInterface();
1060 const VkInstance instance = context.getInstance();
1061 const InstanceDriver instanceDriver (platformInterface, instance);
1062 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
1063 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1064 const deUint32 queueCount = 1;
1065 const deUint32 queueIndex = 0;
1066 const float queuePriority = 1.0f;
1068 VkPhysicalDeviceProtectedMemoryFeatures protectedMemoryFeature =
1070 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES, // VkStructureType sType;
1071 DE_NULL, // void* pNext;
1072 VK_FALSE // VkBool32 protectedMemory;
1075 VkPhysicalDeviceFeatures2 features2;
1076 deMemset(&features2, 0, sizeof(features2));
1077 features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1078 features2.pNext = &protectedMemoryFeature;
1080 instanceDriver.getPhysicalDeviceFeatures2(physicalDevice, &features2);
1081 if (protectedMemoryFeature.protectedMemory == VK_FALSE)
1082 TCU_THROW(NotSupportedError, "Protected memory feature is not supported");
1084 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
1086 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType;
1087 DE_NULL, // const void* pNext;
1088 VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT, // VkDeviceQueueCreateFlags flags;
1089 queueFamilyIndex, // deUint32 queueFamilyIndex;
1090 queueCount, // deUint32 queueCount;
1091 &queuePriority, // const float* pQueuePriorities;
1093 const VkDeviceCreateInfo deviceCreateInfo =
1095 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType;
1096 &features2, // const void* pNext;
1097 (VkDeviceCreateFlags)0u, // VkDeviceCreateFlags flags;
1098 1, // deUint32 queueCreateInfoCount;
1099 &deviceQueueCreateInfo, // const VkDeviceQueueCreateInfo* pQueueCreateInfos;
1100 0, // deUint32 enabledLayerCount;
1101 DE_NULL, // const char* const* ppEnabledLayerNames;
1102 0, // deUint32 enabledExtensionCount;
1103 DE_NULL, // const char* const* ppEnabledExtensionNames;
1104 DE_NULL, // const VkPhysicalDeviceFeatures* pEnabledFeatures;
1106 const VkDeviceQueueInfo2 deviceQueueInfo2 =
1108 VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2, // VkStructureType sType;
1109 DE_NULL, // const void* pNext;
1110 VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT, // VkDeviceQueueCreateFlags flags;
1111 queueFamilyIndex, // deUint32 queueFamilyIndex;
1112 queueIndex, // deUint32 queueIndex;
1116 const Unique<VkDevice> device (createDevice(platformInterface, instance, instanceDriver, physicalDevice, &deviceCreateInfo));
1117 const DeviceDriver deviceDriver (platformInterface, instance, device.get());
1118 const VkQueue queue2 = getDeviceQueue2(deviceDriver, *device, &deviceQueueInfo2);
1120 VK_CHECK(deviceDriver.queueWaitIdle(queue2));
1123 return tcu::TestStatus::pass("Pass");
1126 tcu::TestStatus createDeviceQueue2UnmatchedFlagsTest (Context& context)
1128 if (!context.contextSupports(vk::ApiVersion(1, 1, 0)))
1129 TCU_THROW(NotSupportedError, "Vulkan 1.1 is not supported");
1131 const PlatformInterface& platformInterface = context.getPlatformInterface();
1132 const VkInstance instance = context.getInstance();
1133 const InstanceDriver instanceDriver (platformInterface, instance);
1134 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
1136 // Check if VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT flag can be used.
1138 VkPhysicalDeviceProtectedMemoryFeatures protectedFeatures;
1139 protectedFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES;
1140 protectedFeatures.pNext = DE_NULL;
1142 VkPhysicalDeviceFeatures2 deviceFeatures;
1143 deviceFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1144 deviceFeatures.pNext = &protectedFeatures;
1146 instanceDriver.getPhysicalDeviceFeatures2(physicalDevice, &deviceFeatures);
1147 if (!protectedFeatures.protectedMemory)
1149 TCU_THROW(NotSupportedError, "protectedMemory feature is not supported, no queue creation flags available");
1153 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1154 const deUint32 queueCount = 1;
1155 const deUint32 queueIndex = 0;
1156 const float queuePriority = 1.0f;
1157 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
1159 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType;
1160 DE_NULL, // const void* pNext;
1161 (VkDeviceQueueCreateFlags)0u, // VkDeviceQueueCreateFlags flags;
1162 queueFamilyIndex, // deUint32 queueFamilyIndex;
1163 queueCount, // deUint32 queueCount;
1164 &queuePriority, // const float* pQueuePriorities;
1166 VkPhysicalDeviceProtectedMemoryFeatures protectedFeatures =
1168 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES, // VkStructureType sType;
1169 DE_NULL, // void* pNext;
1170 VK_TRUE // VkBool32 protectedMemory;
1173 VkPhysicalDeviceFeatures emptyDeviceFeatures;
1174 deMemset(&emptyDeviceFeatures, 0, sizeof(emptyDeviceFeatures));
1176 const VkPhysicalDeviceFeatures2 deviceFeatures =
1178 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, // VkStructureType sType;
1179 &protectedFeatures, // void* pNext;
1180 emptyDeviceFeatures // VkPhysicalDeviceFeatures features;
1183 const VkDeviceCreateInfo deviceCreateInfo =
1185 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType;
1186 &deviceFeatures, // const void* pNext;
1187 (VkDeviceCreateFlags)0u, // VkDeviceCreateFlags flags;
1188 1, // deUint32 queueCreateInfoCount;
1189 &deviceQueueCreateInfo, // const VkDeviceQueueCreateInfo* pQueueCreateInfos;
1190 0, // deUint32 enabledLayerCount;
1191 DE_NULL, // const char* const* ppEnabledLayerNames;
1192 0, // deUint32 enabledExtensionCount;
1193 DE_NULL, // const char* const* ppEnabledExtensionNames;
1194 DE_NULL, // const VkPhysicalDeviceFeatures* pEnabledFeatures;
1196 const VkDeviceQueueInfo2 deviceQueueInfo2 =
1198 VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2, // VkStructureType sType;
1199 DE_NULL, // const void* pNext;
1200 VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT, // VkDeviceQueueCreateFlags flags;
1201 queueFamilyIndex, // deUint32 queueFamilyIndex;
1202 queueIndex, // deUint32 queueIndex;
1206 const Unique<VkDevice> device (createDevice(platformInterface, instance, instanceDriver, physicalDevice, &deviceCreateInfo));
1207 const DeviceDriver deviceDriver (platformInterface, instance, device.get());
1208 const VkQueue queue2 = getDeviceQueue2(deviceDriver, *device, &deviceQueueInfo2);
1210 if (queue2 != DE_NULL)
1211 return tcu::TestStatus::fail("Fail, getDeviceQueue2 should return VK_NULL_HANDLE when flags in VkDeviceQueueCreateInfo and VkDeviceQueueInfo2 are different.");
1213 const VkQueue queue = getDeviceQueue(deviceDriver, *device, queueFamilyIndex, queueIndex);
1215 VK_CHECK(deviceDriver.queueWaitIdle(queue));
1218 return tcu::TestStatus::pass("Pass");
1221 // Allocation tracking utilities
1226 void* alignedStartAddress;
1227 char* actualStartAddress;
1228 size_t requestedSizeBytes;
1229 size_t actualSizeBytes;
1230 VkSystemAllocationScope allocScope;
1235 , wasAllocated (false)
1236 , alignedStartAddress (DE_NULL)
1237 , actualStartAddress (DE_NULL)
1238 , requestedSizeBytes (0)
1239 , actualSizeBytes (0)
1240 , allocScope (VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)
1244 // Global vector to track allocations. This will be resized before each test and emptied after
1245 // However, we have to globally define it so the allocation callback functions work properly
1246 std::vector<AllocTrack> g_allocatedVector;
1247 bool g_intentionalFailEnabled = false;
1248 deUint32 g_intenionalFailIndex = 0;
1249 deUint32 g_intenionalFailCount = 0;
1250 size_t g_allocationsCount = 0;
1252 void freeAllocTracker (void)
1254 g_allocatedVector.clear();
1255 g_allocationsCount = 0;
1258 void initAllocTracker (size_t size, deUint32 intentionalFailIndex = (deUint32)~0)
1260 if (g_allocatedVector.size() > 0)
1263 g_allocatedVector.resize(size);
1265 if (intentionalFailIndex != (deUint32)~0)
1267 g_intentionalFailEnabled = true;
1268 g_intenionalFailIndex = intentionalFailIndex;
1269 g_intenionalFailCount = 0;
1273 g_intentionalFailEnabled = false;
1274 g_intenionalFailIndex = 0;
1275 g_intenionalFailCount = 0;
1278 g_allocationsCount = 0;
1281 bool isAllocTrackerEmpty ()
1283 bool success = true;
1284 bool wasAllocated = false;
1286 for (deUint32 vectorIdx = 0; vectorIdx < g_allocatedVector.size(); vectorIdx++)
1288 if (g_allocatedVector[vectorIdx].active)
1290 else if (!wasAllocated && g_allocatedVector[vectorIdx].wasAllocated)
1291 wasAllocated = true;
1294 if (!g_intentionalFailEnabled && !wasAllocated)
1300 VKAPI_ATTR void *VKAPI_CALL allocCallbackFunc (void *pUserData, size_t size, size_t alignment, VkSystemAllocationScope allocationScope)
1302 if (g_intentionalFailEnabled)
1303 if (++g_intenionalFailCount >= g_intenionalFailIndex)
1306 for (deUint32 vectorIdx = 0; vectorIdx < g_allocatedVector.size(); vectorIdx++)
1308 if (!g_allocatedVector[vectorIdx].active)
1310 g_allocatedVector[vectorIdx].requestedSizeBytes = size;
1311 g_allocatedVector[vectorIdx].actualSizeBytes = size + (alignment - 1);
1312 g_allocatedVector[vectorIdx].alignedStartAddress = DE_NULL;
1313 g_allocatedVector[vectorIdx].actualStartAddress = new char[g_allocatedVector[vectorIdx].actualSizeBytes];
1315 if (g_allocatedVector[vectorIdx].actualStartAddress != DE_NULL)
1317 deUint64 addr = (deUint64)g_allocatedVector[vectorIdx].actualStartAddress;
1318 addr += (alignment - 1);
1319 addr &= ~(alignment - 1);
1320 g_allocatedVector[vectorIdx].alignedStartAddress = (void *)addr;
1321 g_allocatedVector[vectorIdx].allocScope = allocationScope;
1322 g_allocatedVector[vectorIdx].userData = (deUint64)pUserData;
1323 g_allocatedVector[vectorIdx].active = true;
1324 g_allocatedVector[vectorIdx].wasAllocated = true;
1327 g_allocationsCount++;
1328 return g_allocatedVector[vectorIdx].alignedStartAddress;
1334 VKAPI_ATTR void VKAPI_CALL freeCallbackFunc (void *pUserData, void *pMemory)
1336 DE_UNREF(pUserData);
1338 for (deUint32 vectorIdx = 0; vectorIdx < g_allocatedVector.size(); vectorIdx++)
1340 if (g_allocatedVector[vectorIdx].active && g_allocatedVector[vectorIdx].alignedStartAddress == pMemory)
1342 delete[] g_allocatedVector[vectorIdx].actualStartAddress;
1343 g_allocatedVector[vectorIdx].active = false;
1349 VKAPI_ATTR void *VKAPI_CALL reallocCallbackFunc (void *pUserData, void *pOriginal, size_t size, size_t alignment, VkSystemAllocationScope allocationScope)
1351 if (pOriginal != DE_NULL)
1353 for (deUint32 vectorIdx = 0; vectorIdx < g_allocatedVector.size(); vectorIdx++)
1355 if (g_allocatedVector[vectorIdx].active && g_allocatedVector[vectorIdx].alignedStartAddress == pOriginal)
1359 freeCallbackFunc(pUserData, pOriginal);
1362 else if (size < g_allocatedVector[vectorIdx].requestedSizeBytes)
1366 void *pNew = allocCallbackFunc(pUserData, size, alignment, allocationScope);
1368 if (pNew != DE_NULL)
1370 size_t copySize = size;
1372 if (g_allocatedVector[vectorIdx].requestedSizeBytes < size)
1373 copySize = g_allocatedVector[vectorIdx].requestedSizeBytes;
1375 memcpy(pNew, pOriginal, copySize);
1376 freeCallbackFunc(pUserData, pOriginal);
1385 return allocCallbackFunc(pUserData, size, alignment, allocationScope);
1388 tcu::TestStatus createInstanceDeviceIntentionalAllocFail (Context& context)
1390 const PlatformInterface& vkp = context.getPlatformInterface();
1391 const deUint32 chosenDevice = context.getTestContext().getCommandLine().getVKDeviceId() - 1;
1392 VkInstance instance = DE_NULL;
1393 VkDevice device = DE_NULL;
1394 deUint32 physicalDeviceCount = 0;
1395 deUint32 queueFamilyCount = 0;
1396 deUint32 queueFamilyIndex = 0;
1397 const float queuePriority = 0.0f;
1398 const VkAllocationCallbacks allocationCallbacks =
1400 DE_NULL, // userData
1401 allocCallbackFunc, // pfnAllocation
1402 reallocCallbackFunc, // pfnReallocation
1403 freeCallbackFunc, // pfnFree
1404 DE_NULL, // pfnInternalAllocation
1405 DE_NULL // pfnInternalFree
1407 const VkApplicationInfo appInfo =
1409 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType
1411 "appName", // pApplicationName
1412 0u, // applicationVersion
1413 "engineName", // pEngineName
1414 0u, // engineVersion
1415 VK_API_VERSION_1_0 // apiVersion
1417 const VkInstanceCreateInfo instanceCreateInfo =
1419 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType
1421 (VkInstanceCreateFlags)0u, // flags
1422 &appInfo, // pApplicationInfo
1423 0u, // enabledLayerCount
1424 DE_NULL, // ppEnabledLayerNames
1425 0u, // enabledExtensionCount
1426 DE_NULL // ppEnabledExtensionNames
1428 deUint32 failIndex = 0;
1429 VkResult result = VK_SUCCESS;
1430 size_t max_allowed_alloc = 0;
1434 if (max_allowed_alloc == 0)
1436 if (result != VK_SUCCESS)
1437 return tcu::TestStatus::fail("Could not create instance and device");
1439 initAllocTracker(99999);
1443 initAllocTracker(max_allowed_alloc, failIndex++);
1445 if (failIndex >= static_cast<deUint32>(max_allowed_alloc))
1446 return tcu::TestStatus::fail("Out of retries, could not create instance and device");
1449 result = vkp.createInstance(&instanceCreateInfo, &allocationCallbacks, &instance);
1451 if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
1453 if (!isAllocTrackerEmpty())
1454 return tcu::TestStatus::fail("Allocations still remain, failed on index " + de::toString(failIndex));
1459 else if (result != VK_SUCCESS)
1460 return tcu::TestStatus::fail("createInstance returned " + de::toString(result));
1462 const InstanceDriver instanceDriver (vkp, instance);
1463 const InstanceInterface& vki (instanceDriver);
1465 result = vki.enumeratePhysicalDevices(instance, &physicalDeviceCount, DE_NULL);
1467 if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
1469 vki.destroyInstance(instance, &allocationCallbacks);
1471 if (!isAllocTrackerEmpty())
1472 return tcu::TestStatus::fail("Allocations still remain, failed on index " + de::toString(failIndex));
1477 else if (result != VK_SUCCESS)
1478 return tcu::TestStatus::fail("enumeratePhysicalDevices returned " + de::toString(result));
1480 vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
1482 result = vki.enumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices.data());
1484 if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
1486 vki.destroyInstance(instance, &allocationCallbacks);
1488 if (!isAllocTrackerEmpty())
1489 return tcu::TestStatus::fail("Allocations still remain, failed on index " + de::toString(failIndex));
1494 else if (result != VK_SUCCESS)
1495 return tcu::TestStatus::fail("enumeratePhysicalDevices returned " + de::toString(result));
1497 vki.getPhysicalDeviceQueueFamilyProperties(physicalDevices[chosenDevice], &queueFamilyCount, DE_NULL);
1499 if (queueFamilyCount == 0u)
1500 return tcu::TestStatus::fail("getPhysicalDeviceQueueFamilyProperties returned zero queue families");
1502 vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
1504 vki.getPhysicalDeviceQueueFamilyProperties(physicalDevices[chosenDevice], &queueFamilyCount, queueFamilies.data());
1506 if (queueFamilyCount == 0u)
1507 return tcu::TestStatus::fail("getPhysicalDeviceQueueFamilyProperties returned zero queue families");
1509 for (deUint32 i = 0; i < queueFamilyCount; i++)
1511 if (queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
1513 queueFamilyIndex = i;
1518 const VkDeviceQueueCreateInfo deviceQueueCreateInfo =
1520 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
1522 (VkDeviceQueueCreateFlags)0u, // flags
1523 queueFamilyIndex, // queueFamilyIndex
1525 &queuePriority // pQueuePriorities
1527 const VkDeviceCreateInfo deviceCreateInfo =
1529 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
1531 (VkDeviceCreateFlags)0u, // flags
1532 1u, // queueCreateInfoCount
1533 &deviceQueueCreateInfo, // pQueueCreateInfos
1534 0u, // enabledLayerCount
1535 DE_NULL, // ppEnabledLayerNames
1536 0u, // enabledExtensionCount
1537 DE_NULL, // ppEnabledExtensionNames
1538 DE_NULL // pEnabledFeatures
1541 result = vki.createDevice(physicalDevices[chosenDevice], &deviceCreateInfo, &allocationCallbacks, &device);
1543 if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
1545 vki.destroyInstance(instance, &allocationCallbacks);
1547 if (!isAllocTrackerEmpty())
1548 return tcu::TestStatus::fail("Allocations still remain, failed on index " + de::toString(failIndex));
1553 else if (result != VK_SUCCESS)
1554 return tcu::TestStatus::fail("VkCreateDevice returned " + de::toString(result));
1556 DeviceDriver(vkp, instance, device).destroyDevice(device, &allocationCallbacks);
1557 vki.destroyInstance(instance, &allocationCallbacks);
1558 if (max_allowed_alloc == 0)
1560 max_allowed_alloc = g_allocationsCount + 100;
1561 result = VK_ERROR_OUT_OF_HOST_MEMORY;
1565 while (result == VK_ERROR_OUT_OF_HOST_MEMORY);
1567 return tcu::TestStatus::pass("Pass");
1572 tcu::TestCaseGroup* createDeviceInitializationTests (tcu::TestContext& testCtx)
1574 de::MovePtr<tcu::TestCaseGroup> deviceInitializationTests (new tcu::TestCaseGroup(testCtx, "device_init", "Device Initialization Tests"));
1576 addFunctionCase(deviceInitializationTests.get(), "create_instance_name_version", "", createInstanceTest);
1577 addFunctionCase(deviceInitializationTests.get(), "create_instance_invalid_api_version", "", createInstanceWithInvalidApiVersionTest);
1578 addFunctionCase(deviceInitializationTests.get(), "create_instance_null_appinfo", "", createInstanceWithNullApplicationInfoTest);
1579 addFunctionCase(deviceInitializationTests.get(), "create_instance_unsupported_extensions", "", createInstanceWithUnsupportedExtensionsTest);
1580 addFunctionCase(deviceInitializationTests.get(), "create_instance_extension_name_abuse", "", createInstanceWithExtensionNameAbuseTest);
1581 addFunctionCase(deviceInitializationTests.get(), "create_instance_layer_name_abuse", "", createInstanceWithLayerNameAbuseTest);
1582 addFunctionCase(deviceInitializationTests.get(), "create_device", "", createDeviceTest);
1583 addFunctionCase(deviceInitializationTests.get(), "create_multiple_devices", "", createMultipleDevicesTest);
1584 addFunctionCase(deviceInitializationTests.get(), "create_device_unsupported_extensions", "", createDeviceWithUnsupportedExtensionsTest);
1585 addFunctionCase(deviceInitializationTests.get(), "create_device_various_queue_counts", "", createDeviceWithVariousQueueCountsTest);
1586 addFunctionCase(deviceInitializationTests.get(), "create_device_features2", "", createDeviceFeatures2Test);
1587 addFunctionCase(deviceInitializationTests.get(), "create_device_unsupported_features", "", createDeviceWithUnsupportedFeaturesTest);
1588 addFunctionCase(deviceInitializationTests.get(), "create_device_queue2", "", createDeviceQueue2Test);
1589 addFunctionCase(deviceInitializationTests.get(), "create_device_queue2_unmatched_flags", "", createDeviceQueue2UnmatchedFlagsTest);
1590 addFunctionCase(deviceInitializationTests.get(), "create_instance_device_intentional_alloc_fail", "", createInstanceDeviceIntentionalAllocFail);
1592 return deviceInitializationTests.release();