Home | History | Annotate | Download | only in api
      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 
     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 
    154 	// test when apiVersion is 0
    155 	{
    156 		const VkApplicationInfo appInfo =
    157 		{
    158 			VK_STRUCTURE_TYPE_APPLICATION_INFO,		// VkStructureType				sType;
    159 			DE_NULL,								// const void*					pNext;
    160 			"appName",								// const char*					pAppName;
    161 			0u,										// deUint32						appVersion;
    162 			"engineName",							// const char*					pEngineName;
    163 			0u,										// deUint32						engineVersion;
    164 			0u,										// deUint32						apiVersion;
    165 		};
    166 
    167 		appInfos.push_back(appInfo);
    168 	}
    169 
    170 	// run the tests!
    171 	for (size_t appInfoNdx = 0; appInfoNdx < appInfos.size(); ++appInfoNdx)
    172 	{
    173 		const VkApplicationInfo&		appInfo					= appInfos[appInfoNdx];
    174 		const VkInstanceCreateInfo		instanceCreateInfo		=
    175 		{
    176 			VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,	// VkStructureType				sType;
    177 			DE_NULL,								// const void*					pNext;
    178 			(VkInstanceCreateFlags)0u,				// VkInstanceCreateFlags		flags;
    179 			&appInfo,								// const VkApplicationInfo*		pAppInfo;
    180 			0u,										// deUint32						layerCount;
    181 			DE_NULL,								// const char*const*			ppEnabledLayernames;
    182 			0u,										// deUint32						extensionCount;
    183 			DE_NULL,								// const char*const*			ppEnabledExtensionNames;
    184 		};
    185 
    186 		log << TestLog::Message << "Creating instance with appInfo: " << appInfo << TestLog::EndMessage;
    187 
    188 		try
    189 		{
    190 			const Unique<VkInstance> instance(createInstance(platformInterface, &instanceCreateInfo));
    191 			log << TestLog::Message << "Succeeded" << TestLog::EndMessage;
    192 		}
    193 		catch (const vk::Error& err)
    194 		{
    195 			resultCollector.fail("Failed, Error code: " + de::toString(err.getMessage()));
    196 		}
    197 	}
    198 
    199 	return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
    200 }
    201 
    202 tcu::TestStatus createInstanceWithInvalidApiVersionTest (Context& context)
    203 {
    204 	tcu::TestLog&				log					= context.getTestContext().getLog();
    205 	tcu::ResultCollector		resultCollector		(log);
    206 	const PlatformInterface&	platformInterface	= context.getPlatformInterface();
    207 	const ApiVersion			apiVersion			= unpackVersion(VK_API_VERSION);
    208 	const deUint32				invalidMajorVersion	= (1 << 10) - 1;
    209 	const deUint32				invalidMinorVersion	= (1 << 10) - 1;
    210 	vector<ApiVersion>			invalidApiVersions;
    211 
    212 	invalidApiVersions.push_back(ApiVersion(invalidMajorVersion, apiVersion.minorNum, apiVersion.patchNum));
    213 	invalidApiVersions.push_back(ApiVersion(apiVersion.majorNum, invalidMinorVersion, apiVersion.patchNum));
    214 
    215 	for (size_t apiVersionNdx = 0; apiVersionNdx < invalidApiVersions.size(); apiVersionNdx++)
    216 	{
    217 		const VkApplicationInfo appInfo					=
    218 		{
    219 			VK_STRUCTURE_TYPE_APPLICATION_INFO,			// VkStructureType				sType;
    220 			DE_NULL,									// const void*					pNext;
    221 			"appName",									// const char*					pAppName;
    222 			0u,											// deUint32						appVersion;
    223 			"engineName",								// const char*					pEngineName;
    224 			0u,											// deUint32						engineVersion;
    225 			pack(invalidApiVersions[apiVersionNdx]),	// deUint32						apiVersion;
    226 		};
    227 		const VkInstanceCreateInfo instanceCreateInfo	=
    228 		{
    229 			VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,		// VkStructureType				sType;
    230 			DE_NULL,									// const void*					pNext;
    231 			(VkInstanceCreateFlags)0u,					// VkInstanceCreateFlags		flags;
    232 			&appInfo,									// const VkApplicationInfo*		pAppInfo;
    233 			0u,											// deUint32						layerCount;
    234 			DE_NULL,									// const char*const*			ppEnabledLayernames;
    235 			0u,											// deUint32						extensionCount;
    236 			DE_NULL,									// const char*const*			ppEnabledExtensionNames;
    237 		};
    238 
    239 
    240 		log << TestLog::Message
    241 			<<"VK_API_VERSION defined in vulkan.h: " << apiVersion
    242 			<< ", api version used to create instance: " << invalidApiVersions[apiVersionNdx]
    243 			<< TestLog::EndMessage;
    244 
    245 		{
    246 			VkInstance		instance	= (VkInstance)0;
    247 			const VkResult	result		= platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
    248 			const bool		gotInstance	= !!instance;
    249 
    250 			if (instance)
    251 			{
    252 				const InstanceDriver	instanceIface	(platformInterface, instance);
    253 				instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
    254 			}
    255 
    256 			if (result == VK_ERROR_INCOMPATIBLE_DRIVER)
    257 			{
    258 				TCU_CHECK(!gotInstance);
    259 				log << TestLog::Message << "Pass, instance creation with invalid apiVersion is rejected" << TestLog::EndMessage;
    260 			}
    261 			else
    262 				resultCollector.fail("Fail, instance creation with invalid apiVersion is not rejected");
    263 		}
    264 	}
    265 
    266 	return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
    267 }
    268 
    269 tcu::TestStatus createInstanceWithNullApplicationInfoTest (Context& context)
    270 {
    271 	tcu::TestLog&				log						= context.getTestContext().getLog();
    272 	tcu::ResultCollector		resultCollector			(log);
    273 	const PlatformInterface&	platformInterface		= context.getPlatformInterface();
    274 
    275 	const VkInstanceCreateInfo		instanceCreateInfo		=
    276 	{
    277 		VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,	// VkStructureType				sType;
    278 		DE_NULL,								// const void*					pNext;
    279 		(VkInstanceCreateFlags)0u,				// VkInstanceCreateFlags		flags;
    280 		DE_NULL,								// const VkApplicationInfo*		pAppInfo;
    281 		0u,										// deUint32						layerCount;
    282 		DE_NULL,								// const char*const*			ppEnabledLayernames;
    283 		0u,										// deUint32						extensionCount;
    284 		DE_NULL,								// const char*const*			ppEnabledExtensionNames;
    285 	};
    286 
    287 	log << TestLog::Message << "Creating instance with NULL pApplicationInfo" << TestLog::EndMessage;
    288 
    289 	try
    290 	{
    291 		const Unique<VkInstance> instance(createInstance(platformInterface, &instanceCreateInfo));
    292 		log << TestLog::Message << "Succeeded" << TestLog::EndMessage;
    293 	}
    294 	catch (const vk::Error& err)
    295 	{
    296 		resultCollector.fail("Failed, Error code: " + de::toString(err.getMessage()));
    297 	}
    298 
    299 	return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
    300 }
    301 
    302 tcu::TestStatus createInstanceWithUnsupportedExtensionsTest (Context& context)
    303 {
    304 	tcu::TestLog&						log						= context.getTestContext().getLog();
    305 	const PlatformInterface&			platformInterface		= context.getPlatformInterface();
    306 	const char*							enabledExtensions[]		= {"VK_UNSUPPORTED_EXTENSION", "THIS_IS_NOT_AN_EXTENSION"};
    307 	const VkApplicationInfo				appInfo					=
    308 	{
    309 		VK_STRUCTURE_TYPE_APPLICATION_INFO,						// VkStructureType				sType;
    310 		DE_NULL,												// const void*					pNext;
    311 		"appName",												// const char*					pAppName;
    312 		0u,														// deUint32						appVersion;
    313 		"engineName",											// const char*					pEngineName;
    314 		0u,														// deUint32						engineVersion;
    315 		VK_API_VERSION,											// deUint32						apiVersion;
    316 	};
    317 	const VkInstanceCreateInfo			instanceCreateInfo		=
    318 	{
    319 		VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,					// VkStructureType				sType;
    320 		DE_NULL,												// const void*					pNext;
    321 		(VkInstanceCreateFlags)0u,								// VkInstanceCreateFlags		flags;
    322 		&appInfo,												// const VkApplicationInfo*		pAppInfo;
    323 		0u,														// deUint32						layerCount;
    324 		DE_NULL,												// const char*const*			ppEnabledLayernames;
    325 		DE_LENGTH_OF_ARRAY(enabledExtensions),					// deUint32						extensionCount;
    326 		enabledExtensions,										// const char*const*			ppEnabledExtensionNames;
    327 	};
    328 
    329 	log << TestLog::Message << "Enabled extensions are: " << TestLog::EndMessage;
    330 
    331 	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(enabledExtensions); ndx++)
    332 		log << TestLog::Message << enabledExtensions[ndx] <<  TestLog::EndMessage;
    333 
    334 	{
    335 		VkInstance		instance	= (VkInstance)0;
    336 		const VkResult	result		= platformInterface.createInstance(&instanceCreateInfo, DE_NULL/*pAllocator*/, &instance);
    337 		const bool		gotInstance	= !!instance;
    338 
    339 		if (instance)
    340 		{
    341 			const InstanceDriver	instanceIface	(platformInterface, instance);
    342 			instanceIface.destroyInstance(instance, DE_NULL/*pAllocator*/);
    343 		}
    344 
    345 		if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
    346 		{
    347 			TCU_CHECK(!gotInstance);
    348 			return tcu::TestStatus::pass("Pass, creating instance with unsupported extension was rejected.");
    349 		}
    350 		else
    351 			return tcu::TestStatus::fail("Fail, creating instance with unsupported extensions succeeded.");
    352 	}
    353 }
    354 
    355 tcu::TestStatus createDeviceTest (Context& context)
    356 {
    357 	const PlatformInterface&		platformInterface		= context.getPlatformInterface();
    358 	const Unique<VkInstance>		instance				(createDefaultInstance(platformInterface));
    359 	const InstanceDriver			instanceDriver			(platformInterface, instance.get());
    360 	const VkPhysicalDevice			physicalDevice			= chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
    361 	const deUint32					queueFamilyIndex		= 0;
    362 	const deUint32					queueCount				= 1;
    363 	const deUint32					queueIndex				= 0;
    364 	const float						queuePriority			= 1.0f;
    365 	const VkDeviceQueueCreateInfo	deviceQueueCreateInfo	=
    366 	{
    367 		VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
    368 		DE_NULL,
    369 		(VkDeviceQueueCreateFlags)0u,
    370 		queueFamilyIndex,						//queueFamilyIndex;
    371 		queueCount,								//queueCount;
    372 		&queuePriority,							//pQueuePriorities;
    373 	};
    374 	const VkDeviceCreateInfo		deviceCreateInfo	=
    375 	{
    376 		VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,	//sType;
    377 		DE_NULL,								//pNext;
    378 		(VkDeviceCreateFlags)0u,
    379 		1,										//queueRecordCount;
    380 		&deviceQueueCreateInfo,					//pRequestedQueues;
    381 		0,										//layerCount;
    382 		DE_NULL,								//ppEnabledLayerNames;
    383 		0,										//extensionCount;
    384 		DE_NULL,								//ppEnabledExtensionNames;
    385 		DE_NULL,								//pEnabledFeatures;
    386 	};
    387 
    388 	const Unique<VkDevice>			device					(createDevice(instanceDriver, physicalDevice, &deviceCreateInfo));
    389 	const DeviceDriver				deviceDriver			(instanceDriver, device.get());
    390 	VkQueue							queue;
    391 
    392 	deviceDriver.getDeviceQueue(device.get(), queueFamilyIndex, queueIndex, &queue);
    393 	VK_CHECK(deviceDriver.queueWaitIdle(queue));
    394 
    395 	return tcu::TestStatus::pass("Pass");
    396 }
    397 
    398 tcu::TestStatus createMultipleDevicesTest (Context& context)
    399 {
    400 	tcu::TestLog&										log						= context.getTestContext().getLog();
    401 	tcu::ResultCollector								resultCollector			(log);
    402 	const int											numDevices				= 5;
    403 	const PlatformInterface&							platformInterface		= context.getPlatformInterface();
    404 	const Unique<VkInstance>							instance				(createDefaultInstance(platformInterface));
    405 	const InstanceDriver								instanceDriver			(platformInterface, instance.get());
    406 	const VkPhysicalDevice								physicalDevice			= chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
    407 	const deUint32										queueFamilyIndex		= 0;
    408 	const deUint32										queueCount				= 1;
    409 	const deUint32										queueIndex				= 0;
    410 	const float											queuePriority			= 1.0f;
    411 	const VkDeviceQueueCreateInfo						deviceQueueCreateInfo	=
    412 	{
    413 		VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
    414 		DE_NULL,
    415 		(VkDeviceQueueCreateFlags)0u,					//flags;
    416 		queueFamilyIndex,								//queueFamilyIndex;
    417 		queueCount,										//queueCount;
    418 		&queuePriority,									//pQueuePriorities;
    419 	};
    420 	const VkDeviceCreateInfo							deviceCreateInfo		=
    421 	{
    422 		VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,			//sType;
    423 		DE_NULL,										//pNext;
    424 		(VkDeviceCreateFlags)0u,
    425 		1,												//queueRecordCount;
    426 		&deviceQueueCreateInfo,							//pRequestedQueues;
    427 		0,												//layerCount;
    428 		DE_NULL,										//ppEnabledLayerNames;
    429 		0,												//extensionCount;
    430 		DE_NULL,										//ppEnabledExtensionNames;
    431 		DE_NULL,										//pEnabledFeatures;
    432 	};
    433 	vector<VkDevice>									devices(numDevices, (VkDevice)DE_NULL);
    434 
    435 	try
    436 	{
    437 		for (int deviceNdx = 0; deviceNdx < numDevices; deviceNdx++)
    438 		{
    439 			const VkResult result = instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL/*pAllocator*/, &devices[deviceNdx]);
    440 
    441 			if (result != VK_SUCCESS)
    442 			{
    443 				resultCollector.fail("Failed to create Device No." + de::toString(deviceNdx) + ", Error Code: " + de::toString(result));
    444 				break;
    445 			}
    446 
    447 			{
    448 				const DeviceDriver	deviceDriver(instanceDriver, devices[deviceNdx]);
    449 				VkQueue				queue;
    450 
    451 				DE_ASSERT(queueIndex < queueCount);
    452 				deviceDriver.getDeviceQueue(devices[deviceNdx], queueFamilyIndex, queueIndex, &queue);
    453 				VK_CHECK(deviceDriver.queueWaitIdle(queue));
    454 			}
    455 		}
    456 	}
    457 	catch (const vk::Error& error)
    458 	{
    459 		resultCollector.fail(de::toString(error.getError()));
    460 	}
    461 	catch (...)
    462 	{
    463 		for (int deviceNdx = (int)devices.size()-1; deviceNdx >= 0; deviceNdx--)
    464 		{
    465 			if (devices[deviceNdx] != (VkDevice)DE_NULL)
    466 			{
    467 				DeviceDriver deviceDriver(instanceDriver, devices[deviceNdx]);
    468 				deviceDriver.destroyDevice(devices[deviceNdx], DE_NULL/*pAllocator*/);
    469 			}
    470 		}
    471 
    472 		throw;
    473 	}
    474 
    475 	for (int deviceNdx = (int)devices.size()-1; deviceNdx >= 0; deviceNdx--)
    476 	{
    477 		if (devices[deviceNdx] != (VkDevice)DE_NULL)
    478 		{
    479 			DeviceDriver deviceDriver(instanceDriver, devices[deviceNdx]);
    480 			deviceDriver.destroyDevice(devices[deviceNdx], DE_NULL/*pAllocator*/);
    481 		}
    482 	}
    483 
    484 	return tcu::TestStatus(resultCollector.getResult(), resultCollector.getMessage());
    485 }
    486 
    487 tcu::TestStatus createDeviceWithUnsupportedExtensionsTest (Context& context)
    488 {
    489 	tcu::TestLog&					log						= context.getTestContext().getLog();
    490 	const PlatformInterface&		platformInterface		= context.getPlatformInterface();
    491 	const Unique<VkInstance>		instance				(createDefaultInstance(platformInterface));
    492 	const InstanceDriver			instanceDriver			(platformInterface, instance.get());
    493 	const char*						enabledExtensions[]		= {"VK_UNSUPPORTED_EXTENSION", "THIS_IS_NOT_AN_EXTENSION", "VK_DONT_SUPPORT_ME"};
    494 	const VkPhysicalDevice			physicalDevice			= chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
    495 	const float						queuePriority			= 1.0f;
    496 	const VkDeviceQueueCreateInfo	deviceQueueCreateInfo	=
    497 	{
    498 		VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
    499 		DE_NULL,
    500 		(VkDeviceQueueCreateFlags)0u,
    501 		0,										//queueFamiliIndex;
    502 		1,										//queueCount;
    503 		&queuePriority,							//pQueuePriorities;
    504 	};
    505 	const VkDeviceCreateInfo		deviceCreateInfo		=
    506 	{
    507 		VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,	//sType;
    508 		DE_NULL,								//pNext;
    509 		(VkDeviceCreateFlags)0u,
    510 		1,										//queueRecordCount;
    511 		&deviceQueueCreateInfo,					//pRequestedQueues;
    512 		0,										//layerCount;
    513 		DE_NULL,								//ppEnabledLayerNames;
    514 		DE_LENGTH_OF_ARRAY(enabledExtensions),	//extensionCount;
    515 		enabledExtensions,						//ppEnabledExtensionNames;
    516 		DE_NULL,								//pEnabledFeatures;
    517 	};
    518 
    519 	log << TestLog::Message << "Enabled extensions are: " << TestLog::EndMessage;
    520 
    521 	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(enabledExtensions); ndx++)
    522 		log << TestLog::Message << enabledExtensions[ndx] <<  TestLog::EndMessage;
    523 
    524 	{
    525 		VkDevice		device		= (VkDevice)0;
    526 		const VkResult	result		= instanceDriver.createDevice(physicalDevice, &deviceCreateInfo, DE_NULL/*pAllocator*/, &device);
    527 		const bool		gotDevice	= !!device;
    528 
    529 		if (device)
    530 		{
    531 			const DeviceDriver	deviceIface	(instanceDriver, device);
    532 			deviceIface.destroyDevice(device, DE_NULL/*pAllocator*/);
    533 		}
    534 
    535 		if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
    536 		{
    537 			TCU_CHECK(!gotDevice);
    538 			return tcu::TestStatus::pass("Pass, create device with unsupported extension is rejected.");
    539 		}
    540 		else
    541 			return tcu::TestStatus::fail("Fail, create device with unsupported extension but succeed.");
    542 	}
    543 }
    544 
    545 deUint32 getGlobalMaxQueueCount(const vector<VkQueueFamilyProperties>& queueFamilyProperties)
    546 {
    547 	deUint32 maxQueueCount = 0;
    548 
    549 	for (deUint32 queueFamilyNdx = 0; queueFamilyNdx < (deUint32)queueFamilyProperties.size(); queueFamilyNdx++)
    550 	{
    551 		maxQueueCount = de::max(maxQueueCount, queueFamilyProperties[queueFamilyNdx].queueCount);
    552 	}
    553 
    554 	return maxQueueCount;
    555 }
    556 
    557 tcu::TestStatus createDeviceWithVariousQueueCountsTest (Context& context)
    558 {
    559 	tcu::TestLog&							log						= context.getTestContext().getLog();
    560 	const int								queueCountDiff			= 1;
    561 	const PlatformInterface&				platformInterface		= context.getPlatformInterface();
    562 	const Unique<VkInstance>				instance				(createDefaultInstance(platformInterface));
    563 	const InstanceDriver					instanceDriver			(platformInterface, instance.get());
    564 	const VkPhysicalDevice					physicalDevice			= chooseDevice(instanceDriver, instance.get(), context.getTestContext().getCommandLine());
    565 	const vector<VkQueueFamilyProperties>	queueFamilyProperties	= getPhysicalDeviceQueueFamilyProperties(instanceDriver, physicalDevice);
    566 	const vector<float>						queuePriorities			(getGlobalMaxQueueCount(queueFamilyProperties), 1.0f);
    567 	vector<VkDeviceQueueCreateInfo>			deviceQueueCreateInfos;
    568 
    569 	for (deUint32 queueFamilyNdx = 0; queueFamilyNdx < (deUint32)queueFamilyProperties.size(); queueFamilyNdx++)
    570 	{
    571 		const deUint32 maxQueueCount = queueFamilyProperties[queueFamilyNdx].queueCount;
    572 
    573 		for (deUint32 queueCount = 1; queueCount <= maxQueueCount; queueCount += queueCountDiff)
    574 		{
    575 			const VkDeviceQueueCreateInfo queueCreateInfo =
    576 			{
    577 				VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
    578 				DE_NULL,
    579 				(VkDeviceQueueCreateFlags)0u,
    580 				queueFamilyNdx,
    581 				queueCount,
    582 				queuePriorities.data()
    583 			};
    584 
    585 			deviceQueueCreateInfos.push_back(queueCreateInfo);
    586 		}
    587 	}
    588 
    589 	for (size_t testNdx = 0; testNdx < deviceQueueCreateInfos.size(); testNdx++)
    590 	{
    591 		const VkDeviceQueueCreateInfo&	queueCreateInfo		= deviceQueueCreateInfos[testNdx];
    592 		const VkDeviceCreateInfo		deviceCreateInfo	=
    593 		{
    594 			VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,	//sType;
    595 			DE_NULL,								//pNext;
    596 			(VkDeviceCreateFlags)0u,
    597 			1,										//queueRecordCount;
    598 			&queueCreateInfo,						//pRequestedQueues;
    599 			0,										//layerCount;
    600 			DE_NULL,								//ppEnabledLayerNames;
    601 			0,										//extensionCount;
    602 			DE_NULL,								//ppEnabledExtensionNames;
    603 			DE_NULL,								//pEnabledFeatures;
    604 		};
    605 		const Unique<VkDevice>			device				(createDevice(instanceDriver, physicalDevice, &deviceCreateInfo));
    606 		const DeviceDriver				deviceDriver		(instanceDriver, device.get());
    607 		const deUint32					queueFamilyIndex	= deviceCreateInfo.pQueueCreateInfos->queueFamilyIndex;
    608 		const deUint32					queueCount			= deviceCreateInfo.pQueueCreateInfos->queueCount;
    609 
    610 		for (deUint32 queueIndex = 0; queueIndex < queueCount; queueIndex++)
    611 		{
    612 			VkQueue		queue;
    613 			VkResult	result;
    614 
    615 			deviceDriver.getDeviceQueue(device.get(), queueFamilyIndex, queueIndex, &queue);
    616 			TCU_CHECK(!!queue);
    617 
    618 			result = deviceDriver.queueWaitIdle(queue);
    619 			if (result != VK_SUCCESS)
    620 			{
    621 				log << TestLog::Message
    622 					<< "vkQueueWaitIdle failed"
    623 					<< ",  queueIndex = " << queueIndex
    624 					<< ", queueCreateInfo " << queueCreateInfo
    625 					<< ", Error Code: " << result
    626 					<< TestLog::EndMessage;
    627 				return tcu::TestStatus::fail("Fail");
    628 			}
    629 		}
    630 	}
    631 	return tcu::TestStatus::pass("Pass");
    632 }
    633 
    634 Move<VkInstance> createInstanceWithExtension (const PlatformInterface& vkp, const char* extensionName)
    635 {
    636 	const vector<VkExtensionProperties>	instanceExts	= enumerateInstanceExtensionProperties(vkp, DE_NULL);
    637 	vector<string>						enabledExts;
    638 
    639 	if (!isExtensionSupported(instanceExts, RequiredExtension(extensionName)))
    640 		TCU_THROW(NotSupportedError, (string(extensionName) + " is not supported").c_str());
    641 
    642 	enabledExts.push_back(extensionName);
    643 
    644 	return createDefaultInstance(vkp, vector<string>() /* layers */, enabledExts);
    645 }
    646 
    647 tcu::TestStatus createDeviceFeatures2Test (Context& context)
    648 {
    649 	const PlatformInterface&		vkp						= context.getPlatformInterface();
    650 	const Unique<VkInstance>		instance				(createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
    651 	const InstanceDriver			vki						(vkp, instance.get());
    652 	const VkPhysicalDevice			physicalDevice			= chooseDevice(vki, instance.get(), context.getTestContext().getCommandLine());
    653 	const deUint32					queueFamilyIndex		= 0;
    654 	const deUint32					queueCount				= 1;
    655 	const deUint32					queueIndex				= 0;
    656 	const float						queuePriority			= 1.0f;
    657 
    658 	VkPhysicalDeviceFeatures2KHR	enabledFeatures;
    659 	const VkDeviceQueueCreateInfo	deviceQueueCreateInfo	=
    660 	{
    661 		VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
    662 		DE_NULL,
    663 		(VkDeviceQueueCreateFlags)0u,
    664 		queueFamilyIndex,
    665 		queueCount,
    666 		&queuePriority,
    667 	};
    668 	const VkDeviceCreateInfo		deviceCreateInfo	=
    669 	{
    670 		VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
    671 		&enabledFeatures,
    672 		(VkDeviceCreateFlags)0u,
    673 		1,
    674 		&deviceQueueCreateInfo,
    675 		0,
    676 		DE_NULL,
    677 		0,
    678 		DE_NULL,
    679 		DE_NULL,
    680 	};
    681 
    682 	// Populate enabledFeatures
    683 	enabledFeatures.sType		= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
    684 	enabledFeatures.pNext		= DE_NULL;
    685 
    686 	vki.getPhysicalDeviceFeatures2KHR(physicalDevice, &enabledFeatures);
    687 
    688 	{
    689 		const Unique<VkDevice>	device		(createDevice(vki, physicalDevice, &deviceCreateInfo));
    690 		const DeviceDriver		vkd			(vki, device.get());
    691 		VkQueue					queue;
    692 
    693 		vkd.getDeviceQueue(device.get(), queueFamilyIndex, queueIndex, &queue);
    694 		VK_CHECK(vkd.queueWaitIdle(queue));
    695 	}
    696 
    697 	return tcu::TestStatus::pass("Pass");
    698 }
    699 
    700 } // anonymous
    701 
    702 tcu::TestCaseGroup* createDeviceInitializationTests (tcu::TestContext& testCtx)
    703 {
    704 	de::MovePtr<tcu::TestCaseGroup>	deviceInitializationTests (new tcu::TestCaseGroup(testCtx, "device_init", "Device Initialization Tests"));
    705 
    706 	addFunctionCase(deviceInitializationTests.get(), "create_instance_name_version",			"", createInstanceTest);
    707 	addFunctionCase(deviceInitializationTests.get(), "create_instance_invalid_api_version",		"", createInstanceWithInvalidApiVersionTest);
    708 	addFunctionCase(deviceInitializationTests.get(), "create_instance_null_appinfo",		    "", createInstanceWithNullApplicationInfoTest);
    709 	addFunctionCase(deviceInitializationTests.get(), "create_instance_unsupported_extensions",	"", createInstanceWithUnsupportedExtensionsTest);
    710 	addFunctionCase(deviceInitializationTests.get(), "create_device",							"", createDeviceTest);
    711 	addFunctionCase(deviceInitializationTests.get(), "create_multiple_devices",					"", createMultipleDevicesTest);
    712 	addFunctionCase(deviceInitializationTests.get(), "create_device_unsupported_extensions",	"", createDeviceWithUnsupportedExtensionsTest);
    713 	addFunctionCase(deviceInitializationTests.get(), "create_device_various_queue_counts",		"", createDeviceWithVariousQueueCountsTest);
    714 	addFunctionCase(deviceInitializationTests.get(), "create_device_features2",					"", createDeviceFeatures2Test);
    715 
    716 	return deviceInitializationTests.release();
    717 }
    718 
    719 } // api
    720 } // vkt
    721