Home | History | Annotate | Download | only in api
      1 /*-------------------------------------------------------------------------
      2  * Vulkan Conformance Tests
      3  * ------------------------
      4  *
      5  * Copyright (c) 2015 The Khronos Group Inc.
      6  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
      7  * Copyright (c) 2015 Google Inc.
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*--------------------------------------------------------------------*/
     22 
     23 #include "vkDefs.hpp"
     24 #include "vktTestCaseUtil.hpp"
     25 #include "vkBuilderUtil.hpp"
     26 #include "vkPlatform.hpp"
     27 #include "vkRefUtil.hpp"
     28 #include "vkQueryUtil.hpp"
     29 #include "vkMemUtil.hpp"
     30 #include "vkDeviceUtil.hpp"
     31 #include "tcuTextureUtil.hpp"
     32 #include "vkImageUtil.hpp"
     33 #include "vkPrograms.hpp"
     34 #include "vkTypeUtil.hpp"
     35 #include "vkAllocationCallbackUtil.hpp"
     36 #include "vktApiCommandBuffersTests.hpp"
     37 #include "vktApiBufferComputeInstance.hpp"
     38 #include "vktApiComputeInstanceResultBuffer.hpp"
     39 #include "deSharedPtr.hpp"
     40 #include <sstream>
     41 
     42 namespace vkt
     43 {
     44 namespace api
     45 {
     46 namespace
     47 {
     48 
     49 using namespace vk;
     50 
     51 typedef de::SharedPtr<vk::Unique<vk::VkEvent> >	VkEventSp;
     52 
     53 // Global variables
     54 const deUint64								INFINITE_TIMEOUT		= ~(deUint64)0u;
     55 
     56 
     57 template <deUint32 NumBuffers>
     58 class CommandBufferBareTestEnvironment
     59 {
     60 public:
     61 											CommandBufferBareTestEnvironment	(Context&						context,
     62 																				 VkCommandPoolCreateFlags		commandPoolCreateFlags);
     63 
     64 	VkCommandPool							getCommandPool						(void) const					{ return *m_commandPool; }
     65 	VkCommandBuffer							getCommandBuffer					(deUint32 bufferIndex) const;
     66 
     67 protected:
     68 	Context&								m_context;
     69 	const VkDevice							m_device;
     70 	const DeviceInterface&					m_vkd;
     71 	const VkQueue							m_queue;
     72 	const deUint32							m_queueFamilyIndex;
     73 	Allocator&								m_allocator;
     74 
     75 	// \note All VkCommandBuffers are allocated from m_commandPool so there is no need
     76 	//       to free them separately as the auto-generated dtor will do that through
     77 	//       destroying the pool.
     78 	Move<VkCommandPool>						m_commandPool;
     79 	VkCommandBuffer							m_primaryCommandBuffers[NumBuffers];
     80 };
     81 
     82 template <deUint32 NumBuffers>
     83 CommandBufferBareTestEnvironment<NumBuffers>::CommandBufferBareTestEnvironment(Context& context, VkCommandPoolCreateFlags commandPoolCreateFlags)
     84 	: m_context								(context)
     85 	, m_device								(context.getDevice())
     86 	, m_vkd									(context.getDeviceInterface())
     87 	, m_queue								(context.getUniversalQueue())
     88 	, m_queueFamilyIndex					(context.getUniversalQueueFamilyIndex())
     89 	, m_allocator							(context.getDefaultAllocator())
     90 {
     91 	m_commandPool = createCommandPool(m_vkd, m_device, commandPoolCreateFlags, m_queueFamilyIndex);
     92 
     93 	const VkCommandBufferAllocateInfo		cmdBufferAllocateInfo	=
     94 	{
     95 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// VkStructureType             sType;
     96 		DE_NULL,													// const void*                 pNext;
     97 		*m_commandPool,												// VkCommandPool               commandPool;
     98 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// VkCommandBufferLevel        level;
     99 		NumBuffers												// deUint32                    commandBufferCount;
    100 	};
    101 
    102 	VK_CHECK(m_vkd.allocateCommandBuffers(m_device, &cmdBufferAllocateInfo, m_primaryCommandBuffers));
    103 }
    104 
    105 template <deUint32 NumBuffers>
    106 VkCommandBuffer CommandBufferBareTestEnvironment<NumBuffers>::getCommandBuffer(deUint32 bufferIndex) const
    107 {
    108 	DE_ASSERT(bufferIndex < NumBuffers);
    109 	return m_primaryCommandBuffers[bufferIndex];
    110 }
    111 
    112 class CommandBufferRenderPassTestEnvironment : public CommandBufferBareTestEnvironment<1>
    113 {
    114 public:
    115 											CommandBufferRenderPassTestEnvironment	(Context&						context,
    116 																					 VkCommandPoolCreateFlags		commandPoolCreateFlags);
    117 
    118 	VkRenderPass							getRenderPass							(void) const { return *m_renderPass; }
    119 	VkFramebuffer							getFrameBuffer							(void) const { return *m_frameBuffer; }
    120 	VkCommandBuffer							getPrimaryCommandBuffer					(void) const { return getCommandBuffer(0); }
    121 	VkCommandBuffer							getSecondaryCommandBuffer				(void) const { return *m_secondaryCommandBuffer; }
    122 
    123 	void									beginPrimaryCommandBuffer				(VkCommandBufferUsageFlags usageFlags);
    124 	void									beginSecondaryCommandBuffer				(VkCommandBufferUsageFlags usageFlags);
    125 	void									beginRenderPass							(VkSubpassContents content);
    126 	void									submitPrimaryCommandBuffer				(void);
    127 	de::MovePtr<tcu::TextureLevel>			readColorAttachment						(void);
    128 
    129 	static const VkImageType				DEFAULT_IMAGE_TYPE;
    130 	static const VkFormat					DEFAULT_IMAGE_FORMAT;
    131 	static const VkExtent3D					DEFAULT_IMAGE_SIZE;
    132 	static const VkRect2D					DEFAULT_IMAGE_AREA;
    133 
    134 protected:
    135 
    136 	Move<VkImage>							m_colorImage;
    137 	Move<VkImageView>						m_colorImageView;
    138 	Move<VkRenderPass>						m_renderPass;
    139 	Move<VkFramebuffer>						m_frameBuffer;
    140 	de::MovePtr<Allocation>					m_colorImageMemory;
    141 	Move<VkCommandBuffer>					m_secondaryCommandBuffer;
    142 
    143 };
    144 
    145 const VkImageType		CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_TYPE		= VK_IMAGE_TYPE_2D;
    146 const VkFormat			CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_FORMAT	= VK_FORMAT_R8G8B8A8_UINT;
    147 const VkExtent3D		CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_SIZE		= {255, 255, 1};
    148 const VkRect2D			CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_AREA		=
    149 {
    150 	{ 0u, 0u, },												//	VkOffset2D	offset;
    151 	{ DEFAULT_IMAGE_SIZE.width,	DEFAULT_IMAGE_SIZE.height },	//	VkExtent2D	extent;
    152 };
    153 
    154 CommandBufferRenderPassTestEnvironment::CommandBufferRenderPassTestEnvironment(Context& context, VkCommandPoolCreateFlags commandPoolCreateFlags)
    155 	: CommandBufferBareTestEnvironment<1>		(context, commandPoolCreateFlags)
    156 {
    157 	{
    158 		const VkAttachmentDescription			colorAttDesc			=
    159 		{
    160 			0u,													// VkAttachmentDescriptionFlags		flags;
    161 			DEFAULT_IMAGE_FORMAT,								// VkFormat							format;
    162 			VK_SAMPLE_COUNT_1_BIT,								// VkSampleCountFlagBits			samples;
    163 			VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				loadOp;
    164 			VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				storeOp;
    165 			VK_ATTACHMENT_LOAD_OP_DONT_CARE,					// VkAttachmentLoadOp				stencilLoadOp;
    166 			VK_ATTACHMENT_STORE_OP_DONT_CARE,					// VkAttachmentStoreOp				stencilStoreOp;
    167 			VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout					initialLayout;
    168 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,			// VkImageLayout					finalLayout;
    169 		};
    170 
    171 		const VkAttachmentDescription			attachments[1]			=
    172 		{
    173 			colorAttDesc
    174 		};
    175 
    176 		const VkAttachmentReference				colorAttRef				=
    177 		{
    178 			0u,													// deUint32							attachment;
    179 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,			// VkImageLayout					layout;
    180 		};
    181 
    182 		const VkSubpassDescription				subpassDesc[1]			=
    183 		{
    184 			{
    185 				0u,												// VkSubpassDescriptionFlags		flags;
    186 				VK_PIPELINE_BIND_POINT_GRAPHICS,				// VkPipelineBindPoint				pipelineBindPoint;
    187 				0u,												// deUint32							inputAttachmentCount;
    188 				DE_NULL,										// const VkAttachmentReference*		pInputAttachments;
    189 				1u,												// deUint32							colorAttachmentCount;
    190 				&colorAttRef,									// const VkAttachmentReference*		pColorAttachments;
    191 				DE_NULL,										// const VkAttachmentReference*		pResolveAttachments;
    192 				DE_NULL,										// const VkAttachmentReference*		depthStencilAttachment;
    193 				0u,												// deUint32							preserveAttachmentCount;
    194 				DE_NULL,										// const VkAttachmentReference*		pPreserveAttachments;
    195 			}
    196 		};
    197 
    198 		const VkRenderPassCreateInfo			renderPassCreateInfo	=
    199 		{
    200 			VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,			// VkStructureType					sType;
    201 			DE_NULL,											// const void*						pNext;
    202 			0u,													// VkRenderPassCreateFlags			flags;
    203 			1u,													// deUint32							attachmentCount;
    204 			attachments,										// const VkAttachmentDescription*	pAttachments;
    205 			1u,													// deUint32							subpassCount;
    206 			subpassDesc,										// const VkSubpassDescription*		pSubpasses;
    207 			0u,													// deUint32							dependencyCount;
    208 			DE_NULL,											// const VkSubpassDependency*		pDependencies;
    209 		};
    210 
    211 		m_renderPass = createRenderPass(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
    212 	}
    213 
    214 	{
    215 		const VkImageCreateInfo					imageCreateInfo			=
    216 		{
    217 			VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,		// VkStructureType			sType;
    218 			DE_NULL,									// const void*				pNext;
    219 			0u,											// VkImageCreateFlags		flags;
    220 			DEFAULT_IMAGE_TYPE,							// VkImageType				imageType;
    221 			DEFAULT_IMAGE_FORMAT,						// VkFormat					format;
    222 			DEFAULT_IMAGE_SIZE,							// VkExtent3D				extent;
    223 			1,											// deUint32					mipLevels;
    224 			1,											// deUint32					arrayLayers;
    225 			VK_SAMPLE_COUNT_1_BIT,						// VkSampleCountFlagBits	samples;
    226 			VK_IMAGE_TILING_OPTIMAL,					// VkImageTiling			tiling;
    227 			VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
    228 			VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
    229 			VK_IMAGE_USAGE_TRANSFER_DST_BIT,			// VkImageUsageFlags		usage;
    230 			VK_SHARING_MODE_EXCLUSIVE,					// VkSharingMode			sharingMode;
    231 			1,											// deUint32					queueFamilyIndexCount;
    232 			&m_queueFamilyIndex,						// const deUint32*			pQueueFamilyIndices;
    233 			VK_IMAGE_LAYOUT_UNDEFINED					// VkImageLayout			initialLayout;
    234 		};
    235 
    236 		m_colorImage = createImage(m_vkd, m_device, &imageCreateInfo, DE_NULL);
    237 	}
    238 
    239 	m_colorImageMemory = m_allocator.allocate(getImageMemoryRequirements(m_vkd, m_device, *m_colorImage), MemoryRequirement::Any);
    240 	VK_CHECK(m_vkd.bindImageMemory(m_device, *m_colorImage, m_colorImageMemory->getMemory(), m_colorImageMemory->getOffset()));
    241 
    242 	{
    243 		const VkImageViewCreateInfo				imageViewCreateInfo		=
    244 		{
    245 			VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,	// VkStructureType				sType;
    246 			DE_NULL,									// const void*					pNext;
    247 			0u,											// VkImageViewCreateFlags		flags;
    248 			*m_colorImage,								// VkImage						image;
    249 			VK_IMAGE_VIEW_TYPE_2D,						// VkImageViewType				viewType;
    250 			DEFAULT_IMAGE_FORMAT,						// VkFormat						format;
    251 			{
    252 				VK_COMPONENT_SWIZZLE_R,
    253 				VK_COMPONENT_SWIZZLE_G,
    254 				VK_COMPONENT_SWIZZLE_B,
    255 				VK_COMPONENT_SWIZZLE_A
    256 			},											// VkComponentMapping			components;
    257 			{
    258 				VK_IMAGE_ASPECT_COLOR_BIT,					// VkImageAspectFlags			aspectMask;
    259 				0u,											// deUint32						baseMipLevel;
    260 				1u,											// deUint32						mipLevels;
    261 				0u,											// deUint32						baseArrayLayer;
    262 				1u,											// deUint32						arraySize;
    263 			},											// VkImageSubresourceRange		subresourceRange;
    264 		};
    265 
    266 		m_colorImageView = createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL);
    267 	}
    268 
    269 	{
    270 		const VkImageView						attachmentViews[1]		=
    271 		{
    272 			*m_colorImageView
    273 		};
    274 
    275 		const VkFramebufferCreateInfo			framebufferCreateInfo	=
    276 		{
    277 			VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,	// VkStructureType			sType;
    278 			DE_NULL,									// const void*				pNext;
    279 			0u,											// VkFramebufferCreateFlags	flags;
    280 			*m_renderPass,								// VkRenderPass				renderPass;
    281 			1,											// deUint32					attachmentCount;
    282 			attachmentViews,							// const VkImageView*		pAttachments;
    283 			DEFAULT_IMAGE_SIZE.width,					// deUint32					width;
    284 			DEFAULT_IMAGE_SIZE.height,					// deUint32					height;
    285 			1u,											// deUint32					layers;
    286 		};
    287 
    288 		m_frameBuffer = createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL);
    289 	}
    290 
    291 	{
    292 		const VkCommandBufferAllocateInfo		cmdBufferAllocateInfo	=
    293 		{
    294 			VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// VkStructureType             sType;
    295 			DE_NULL,													// const void*                 pNext;
    296 			*m_commandPool,												// VkCommandPool               commandPool;
    297 			VK_COMMAND_BUFFER_LEVEL_SECONDARY,							// VkCommandBufferLevel        level;
    298 			1u															// deUint32                    commandBufferCount;
    299 		};
    300 
    301 		m_secondaryCommandBuffer = allocateCommandBuffer(m_vkd, m_device, &cmdBufferAllocateInfo);
    302 
    303 	}
    304 }
    305 
    306 void CommandBufferRenderPassTestEnvironment::beginRenderPass(VkSubpassContents content)
    307 {
    308 	const VkClearValue						clearValues[1]			=
    309 	{
    310 		makeClearValueColorU32(17, 59, 163, 251),
    311 	};
    312 
    313 	const VkRenderPassBeginInfo				renderPassBeginInfo		=
    314 	{
    315 		VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,				// VkStructureType		sType;
    316 		DE_NULL,												// const void*			pNext;
    317 		*m_renderPass,											// VkRenderPass			renderPass;
    318 		*m_frameBuffer,											// VkFramebuffer		framebuffer;
    319 		DEFAULT_IMAGE_AREA,										// VkRect2D				renderArea;
    320 		1u,														// deUint32				clearValueCount;
    321 		clearValues												// const VkClearValue*	pClearValues;
    322 	};
    323 
    324 	m_vkd.cmdBeginRenderPass(m_primaryCommandBuffers[0], &renderPassBeginInfo, content);
    325 }
    326 
    327 void CommandBufferRenderPassTestEnvironment::beginPrimaryCommandBuffer(VkCommandBufferUsageFlags usageFlags)
    328 {
    329 	const VkCommandBufferBeginInfo			commandBufferBeginInfo	=
    330 	{
    331 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,			// VkStructureType                          sType;
    332 		DE_NULL,												// const void*                              pNext;
    333 		usageFlags,												// VkCommandBufferUsageFlags                flags;
    334 		DE_NULL													// const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
    335 	};
    336 
    337 	VK_CHECK(m_vkd.beginCommandBuffer(m_primaryCommandBuffers[0], &commandBufferBeginInfo));
    338 
    339 }
    340 
    341 
    342 void CommandBufferRenderPassTestEnvironment::beginSecondaryCommandBuffer(VkCommandBufferUsageFlags usageFlags)
    343 {
    344 	const VkCommandBufferInheritanceInfo	commandBufferInheritanceInfo =
    345 	{
    346 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,		// VkStructureType                  sType;
    347 		DE_NULL,												// const void*                      pNext;
    348 		*m_renderPass,											// VkRenderPass                     renderPass;
    349 		0u,														// deUint32                         subpass;
    350 		*m_frameBuffer,											// VkFramebuffer                    framebuffer;
    351 		VK_FALSE,												// VkBool32                         occlusionQueryEnable;
    352 		0u,														// VkQueryControlFlags              queryFlags;
    353 		0u														// VkQueryPipelineStatisticFlags    pipelineStatistics;
    354 	};
    355 
    356 	const VkCommandBufferBeginInfo			commandBufferBeginInfo	=
    357 	{
    358 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,			// VkStructureType                          sType;
    359 		DE_NULL,												// const void*                              pNext;
    360 		usageFlags,												// VkCommandBufferUsageFlags                flags;
    361 		&commandBufferInheritanceInfo							// const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
    362 	};
    363 
    364 	VK_CHECK(m_vkd.beginCommandBuffer(*m_secondaryCommandBuffer, &commandBufferBeginInfo));
    365 
    366 }
    367 
    368 void CommandBufferRenderPassTestEnvironment::submitPrimaryCommandBuffer(void)
    369 {
    370 	const Unique<VkFence>					fence					(createFence(m_vkd, m_device));
    371 	const VkSubmitInfo						submitInfo				=
    372 	{
    373 		VK_STRUCTURE_TYPE_SUBMIT_INFO,							// VkStructureType                sType;
    374 		DE_NULL,												// const void*                    pNext;
    375 		0u,														// deUint32                       waitSemaphoreCount;
    376 		DE_NULL,												// const VkSemaphore*             pWaitSemaphores;
    377 		DE_NULL,												// const VkPipelineStageFlags*    pWaitDstStageMask;
    378 		1u,														// deUint32                       commandBufferCount;
    379 		m_primaryCommandBuffers,								// const VkCommandBuffer*         pCommandBuffers;
    380 		0u,														// deUint32                       signalSemaphoreCount;
    381 		DE_NULL													// const VkSemaphore*             pSignalSemaphores;
    382 	};
    383 
    384 	VK_CHECK(m_vkd.queueSubmit(m_queue, 1, &submitInfo, *fence));
    385 
    386 	VK_CHECK(m_vkd.waitForFences(m_device, 1, &fence.get(), VK_TRUE, ~0ull));
    387 
    388 }
    389 
    390 de::MovePtr<tcu::TextureLevel> CommandBufferRenderPassTestEnvironment::readColorAttachment ()
    391 {
    392 	Move<VkBuffer>					buffer;
    393 	de::MovePtr<Allocation>			bufferAlloc;
    394 	const tcu::TextureFormat		tcuFormat		= mapVkFormat(DEFAULT_IMAGE_FORMAT);
    395 	const VkDeviceSize				pixelDataSize	= DEFAULT_IMAGE_SIZE.height * DEFAULT_IMAGE_SIZE.height * tcuFormat.getPixelSize();
    396 	de::MovePtr<tcu::TextureLevel>	resultLevel		(new tcu::TextureLevel(tcuFormat, DEFAULT_IMAGE_SIZE.width, DEFAULT_IMAGE_SIZE.height));
    397 
    398 	// Create destination buffer
    399 	{
    400 		const VkBufferCreateInfo bufferParams =
    401 		{
    402 			VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,		// VkStructureType		sType;
    403 			DE_NULL,									// const void*			pNext;
    404 			0u,											// VkBufferCreateFlags	flags;
    405 			pixelDataSize,								// VkDeviceSize			size;
    406 			VK_BUFFER_USAGE_TRANSFER_DST_BIT,			// VkBufferUsageFlags	usage;
    407 			VK_SHARING_MODE_EXCLUSIVE,					// VkSharingMode		sharingMode;
    408 			0u,											// deUint32				queueFamilyIndexCount;
    409 			DE_NULL										// const deUint32*		pQueueFamilyIndices;
    410 		};
    411 
    412 		buffer		= createBuffer(m_vkd, m_device, &bufferParams);
    413 		bufferAlloc = m_allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, *buffer), MemoryRequirement::HostVisible);
    414 		VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
    415 	}
    416 
    417 	// Barriers for copying image to buffer
    418 
    419 	const VkImageMemoryBarrier imageBarrier =
    420 	{
    421 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,		// VkStructureType			sType;
    422 		DE_NULL,									// const void*				pNext;
    423 		VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,		// VkAccessFlags			srcAccessMask;
    424 		VK_ACCESS_TRANSFER_READ_BIT,				// VkAccessFlags			dstAccessMask;
    425 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,	// VkImageLayout			oldLayout;
    426 		VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,		// VkImageLayout			newLayout;
    427 		VK_QUEUE_FAMILY_IGNORED,					// deUint32					srcQueueFamilyIndex;
    428 		VK_QUEUE_FAMILY_IGNORED,					// deUint32					dstQueueFamilyIndex;
    429 		*m_colorImage,								// VkImage					image;
    430 		{											// VkImageSubresourceRange	subresourceRange;
    431 			VK_IMAGE_ASPECT_COLOR_BIT,	// VkImageAspectFlags	aspectMask;
    432 			0u,							// deUint32				baseMipLevel;
    433 			1u,							// deUint32				mipLevels;
    434 			0u,							// deUint32				baseArraySlice;
    435 			1u							// deUint32				arraySize;
    436 		}
    437 	};
    438 
    439 	const VkBufferMemoryBarrier bufferBarrier =
    440 	{
    441 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,	// VkStructureType	sType;
    442 		DE_NULL,									// const void*		pNext;
    443 		VK_ACCESS_TRANSFER_WRITE_BIT,				// VkAccessFlags	srcAccessMask;
    444 		VK_ACCESS_HOST_READ_BIT,					// VkAccessFlags	dstAccessMask;
    445 		VK_QUEUE_FAMILY_IGNORED,					// deUint32			srcQueueFamilyIndex;
    446 		VK_QUEUE_FAMILY_IGNORED,					// deUint32			dstQueueFamilyIndex;
    447 		*buffer,									// VkBuffer			buffer;
    448 		0u,											// VkDeviceSize		offset;
    449 		pixelDataSize								// VkDeviceSize		size;
    450 	};
    451 
    452 	// Copy image to buffer
    453 
    454 	const VkBufferImageCopy copyRegion =
    455 	{
    456 		0u,												// VkDeviceSize				bufferOffset;
    457 		DEFAULT_IMAGE_SIZE.width,						// deUint32					bufferRowLength;
    458 		DEFAULT_IMAGE_SIZE.height,						// deUint32					bufferImageHeight;
    459 		{ VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u },		// VkImageSubresourceLayers	imageSubresource;
    460 		{ 0, 0, 0 },									// VkOffset3D				imageOffset;
    461 		DEFAULT_IMAGE_SIZE								// VkExtent3D				imageExtent;
    462 	};
    463 
    464 	beginPrimaryCommandBuffer(0);
    465 	m_vkd.cmdPipelineBarrier(m_primaryCommandBuffers[0], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
    466 	m_vkd.cmdCopyImageToBuffer(m_primaryCommandBuffers[0], *m_colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, 1, &copyRegion);
    467 	m_vkd.cmdPipelineBarrier(m_primaryCommandBuffers[0], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
    468 	VK_CHECK(m_vkd.endCommandBuffer(m_primaryCommandBuffers[0]));
    469 
    470 	submitPrimaryCommandBuffer();
    471 
    472 	// Read buffer data
    473 	invalidateMappedMemoryRange(m_vkd, m_device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
    474 	tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), bufferAlloc->getHostPtr()));
    475 
    476 	return resultLevel;
    477 }
    478 
    479 
    480 // Testcases
    481 /********* 19.1. Command Pools (5.1 in VK 1.0 Spec) ***************************/
    482 tcu::TestStatus createPoolNullParamsTest(Context& context)
    483 {
    484 	const VkDevice							vkDevice				= context.getDevice();
    485 	const DeviceInterface&					vk						= context.getDeviceInterface();
    486 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    487 
    488 	createCommandPool(vk, vkDevice, 0u, queueFamilyIndex);
    489 
    490 	return tcu::TestStatus::pass("Command Pool allocated correctly.");
    491 }
    492 
    493 tcu::TestStatus createPoolNonNullAllocatorTest(Context& context)
    494 {
    495 	const VkDevice							vkDevice				= context.getDevice();
    496 	const DeviceInterface&					vk						= context.getDeviceInterface();
    497 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    498 	const VkAllocationCallbacks*			allocationCallbacks		= getSystemAllocator();
    499 
    500 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    501 	{
    502 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    503 		DE_NULL,													// pNext;
    504 		0u,															// flags;
    505 		queueFamilyIndex,											// queueFamilyIndex;
    506 	};
    507 
    508 	createCommandPool(vk, vkDevice, &cmdPoolParams, allocationCallbacks);
    509 
    510 	return tcu::TestStatus::pass("Command Pool allocated correctly.");
    511 }
    512 
    513 tcu::TestStatus createPoolTransientBitTest(Context& context)
    514 {
    515 	const VkDevice							vkDevice				= context.getDevice();
    516 	const DeviceInterface&					vk						= context.getDeviceInterface();
    517 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    518 
    519 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    520 	{
    521 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    522 		DE_NULL,													// pNext;
    523 		VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,						// flags;
    524 		queueFamilyIndex,											// queueFamilyIndex;
    525 	};
    526 
    527 	createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL);
    528 
    529 	return tcu::TestStatus::pass("Command Pool allocated correctly.");
    530 }
    531 
    532 tcu::TestStatus createPoolResetBitTest(Context& context)
    533 {
    534 	const VkDevice							vkDevice				= context.getDevice();
    535 	const DeviceInterface&					vk						= context.getDeviceInterface();
    536 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    537 
    538 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    539 	{
    540 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    541 		DE_NULL,													// pNext;
    542 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
    543 		queueFamilyIndex,											// queueFamilyIndex;
    544 	};
    545 
    546 	createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL);
    547 
    548 	return tcu::TestStatus::pass("Command Pool allocated correctly.");
    549 }
    550 
    551 tcu::TestStatus resetPoolReleaseResourcesBitTest(Context& context)
    552 {
    553 	const VkDevice							vkDevice				= context.getDevice();
    554 	const DeviceInterface&					vk						= context.getDeviceInterface();
    555 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    556 
    557 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    558 	{
    559 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    560 		DE_NULL,													// pNext;
    561 		0u,															// flags;
    562 		queueFamilyIndex,											// queueFamilyIndex;
    563 	};
    564 
    565 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL));
    566 
    567 	VK_CHECK(vk.resetCommandPool(vkDevice, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT));
    568 
    569 	return tcu::TestStatus::pass("Command Pool allocated correctly.");
    570 }
    571 
    572 tcu::TestStatus resetPoolNoFlagsTest(Context& context)
    573 {
    574 	const VkDevice							vkDevice				= context.getDevice();
    575 	const DeviceInterface&					vk						= context.getDeviceInterface();
    576 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    577 
    578 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    579 	{
    580 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    581 		DE_NULL,													// pNext;
    582 		0u,															// flags;
    583 		queueFamilyIndex,											// queueFamilyIndex;
    584 	};
    585 
    586 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL));
    587 
    588 	VK_CHECK(vk.resetCommandPool(vkDevice, *cmdPool, 0u));
    589 
    590 	return tcu::TestStatus::pass("Command Pool allocated correctly.");
    591 }
    592 
    593 bool executeCommandBuffer (const VkDevice			device,
    594 						   const DeviceInterface&	vk,
    595 						   const VkQueue			queue,
    596 						   const VkCommandBuffer	commandBuffer,
    597 						   const bool				exitBeforeEndCommandBuffer = false)
    598 {
    599 	const Unique<VkEvent>			event					(createEvent(vk, device));
    600 	const VkCommandBufferBeginInfo	commandBufferBeginInfo	=
    601 	{
    602 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,	//VkStructureType						sType;
    603 		DE_NULL,										//const void*							pNext;
    604 		0u,												//VkCommandBufferUsageFlags				flags;
    605 		(const VkCommandBufferInheritanceInfo*)DE_NULL	//const VkCommandBufferInheritanceInfo*	pInheritanceInfo;
    606 	};
    607 
    608 	VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufferBeginInfo));
    609 	{
    610 		const VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
    611 		vk.cmdSetEvent(commandBuffer, *event, stageMask);
    612 		if (exitBeforeEndCommandBuffer)
    613 			return exitBeforeEndCommandBuffer;
    614 	}
    615 	VK_CHECK(vk.endCommandBuffer(commandBuffer));
    616 
    617 	{
    618 		const Unique<VkFence>					fence			(createFence(vk, device));
    619 		const VkSubmitInfo						submitInfo		=
    620 		{
    621 			VK_STRUCTURE_TYPE_SUBMIT_INFO,			// sType
    622 			DE_NULL,								// pNext
    623 			0u,										// waitSemaphoreCount
    624 			DE_NULL,								// pWaitSemaphores
    625 			(const VkPipelineStageFlags*)DE_NULL,	// pWaitDstStageMask
    626 			1u,										// commandBufferCount
    627 			&commandBuffer,							// pCommandBuffers
    628 			0u,										// signalSemaphoreCount
    629 			DE_NULL									// pSignalSemaphores
    630 		};
    631 
    632 		// Submit the command buffer to the queue
    633 		VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
    634 		// wait for end of execution of queue
    635 		VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), 0u, INFINITE_TIMEOUT));
    636 	}
    637 	// check if buffer has been executed
    638 	const VkResult result = vk.getEventStatus(device, *event);
    639 	return result == VK_EVENT_SET;
    640 }
    641 
    642 tcu::TestStatus resetPoolReuseTest (Context& context)
    643 {
    644 	const VkDevice						vkDevice			= context.getDevice();
    645 	const DeviceInterface&				vk					= context.getDeviceInterface();
    646 	const deUint32						queueFamilyIndex	= context.getUniversalQueueFamilyIndex();
    647 	const VkQueue						queue				= context.getUniversalQueue();
    648 
    649 	const VkCommandPoolCreateInfo		cmdPoolParams		=
    650 	{
    651 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,	// sType;
    652 		DE_NULL,									// pNext;
    653 		0u,											// flags;
    654 		queueFamilyIndex							// queueFamilyIndex;
    655 	};
    656 	const Unique<VkCommandPool>			cmdPool				(createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL));
    657 	const VkCommandBufferAllocateInfo	cmdBufParams		=
    658 	{
    659 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,	// sType;
    660 		DE_NULL,										// pNext;
    661 		*cmdPool,										// commandPool;
    662 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,				// level;
    663 		1u												// bufferCount;
    664 	};
    665 	const Move<VkCommandBuffer>			commandBuffers[]	=
    666 	{
    667 		allocateCommandBuffer(vk, vkDevice, &cmdBufParams),
    668 		allocateCommandBuffer(vk, vkDevice, &cmdBufParams)
    669 	};
    670 
    671 	if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[0])))
    672 		return tcu::TestStatus::fail("Failed");
    673 	if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[1]), true))
    674 		return tcu::TestStatus::fail("Failed");
    675 
    676 	VK_CHECK(vk.resetCommandPool(vkDevice, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT));
    677 
    678 	if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[0])))
    679 		return tcu::TestStatus::fail("Failed");
    680 	if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[1])))
    681 		return tcu::TestStatus::fail("Failed");
    682 
    683 	{
    684 		const Unique<VkCommandBuffer> afterResetCommandBuffers(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
    685 		if (!executeCommandBuffer(vkDevice, vk, queue, *afterResetCommandBuffers))
    686 			return tcu::TestStatus::fail("Failed");
    687 	}
    688 
    689 	return tcu::TestStatus::pass("Passed");
    690 }
    691 
    692 /******** 19.2. Command Buffer Lifetime (5.2 in VK 1.0 Spec) ******************/
    693 tcu::TestStatus allocatePrimaryBufferTest(Context& context)
    694 {
    695 	const VkDevice							vkDevice				= context.getDevice();
    696 	const DeviceInterface&					vk						= context.getDeviceInterface();
    697 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    698 
    699 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    700 	{
    701 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    702 		DE_NULL,													// pNext;
    703 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
    704 		queueFamilyIndex,											// queueFamilyIndex;
    705 	};
    706 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
    707 
    708 	// Command buffer
    709 	const VkCommandBufferAllocateInfo		cmdBufParams			=
    710 	{
    711 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
    712 		DE_NULL,													// pNext;
    713 		*cmdPool,													// commandPool;
    714 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
    715 		1u,															// bufferCount;
    716 	};
    717 	const Unique<VkCommandBuffer>			cmdBuf					(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
    718 
    719 	return tcu::TestStatus::pass("Buffer was created correctly.");
    720 }
    721 
    722 tcu::TestStatus allocateManyPrimaryBuffersTest(Context& context)
    723 {
    724 
    725 	const VkDevice							vkDevice				= context.getDevice();
    726 	const DeviceInterface&					vk						= context.getDeviceInterface();
    727 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    728 
    729 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    730 	{
    731 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
    732 		DE_NULL,													//	const void*					pNext;
    733 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
    734 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
    735 	};
    736 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
    737 
    738 	// \todo Determining the minimum number of command buffers should be a function of available system memory and driver capabilities.
    739 #if (DE_PTR_SIZE == 4)
    740 	const unsigned minCommandBuffer = 1024;
    741 #else
    742 	const unsigned minCommandBuffer = 10000;
    743 #endif
    744 
    745 	// Command buffer
    746 	const VkCommandBufferAllocateInfo		cmdBufParams			=
    747 	{
    748 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
    749 		DE_NULL,													//	const void*					pNext;
    750 		*cmdPool,													//	VkCommandPool				pool;
    751 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
    752 		minCommandBuffer,											//	uint32_t					bufferCount;
    753 	};
    754 
    755 	// do not keep the handles to buffers, as they will be freed with command pool
    756 
    757 	// allocate the minimum required amount of buffers
    758 	VkCommandBuffer cmdBuffers[minCommandBuffer];
    759 	VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
    760 
    761 	std::ostringstream out;
    762 	out << "allocateManyPrimaryBuffersTest succeded: created " << minCommandBuffer << " command buffers";
    763 
    764 	return tcu::TestStatus::pass(out.str());
    765 }
    766 
    767 tcu::TestStatus allocateSecondaryBufferTest(Context& context)
    768 {
    769 	const VkDevice							vkDevice				= context.getDevice();
    770 	const DeviceInterface&					vk						= context.getDeviceInterface();
    771 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    772 
    773 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    774 	{
    775 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
    776 		DE_NULL,													// pNext;
    777 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
    778 		queueFamilyIndex,											// queueFamilyIndex;
    779 	};
    780 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
    781 
    782 	// Command buffer
    783 	const VkCommandBufferAllocateInfo		cmdBufParams			=
    784 	{
    785 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
    786 		DE_NULL,													// pNext;
    787 		*cmdPool,													// commandPool;
    788 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							// level;
    789 		1u,															// bufferCount;
    790 	};
    791 	const Unique<VkCommandBuffer>			cmdBuf					(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
    792 
    793 	return tcu::TestStatus::pass("Buffer was created correctly.");
    794 }
    795 
    796 tcu::TestStatus allocateManySecondaryBuffersTest(Context& context)
    797 {
    798 
    799 	const VkDevice							vkDevice				= context.getDevice();
    800 	const DeviceInterface&					vk						= context.getDeviceInterface();
    801 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    802 
    803 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    804 	{
    805 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
    806 		DE_NULL,													//	const void*					pNext;
    807 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
    808 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
    809 	};
    810 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
    811 
    812 	// \todo Determining the minimum number of command buffers should be a function of available system memory and driver capabilities.
    813 #if (DE_PTR_SIZE == 4)
    814 	const unsigned minCommandBuffer = 1024;
    815 #else
    816 	const unsigned minCommandBuffer = 10000;
    817 #endif
    818 
    819 	// Command buffer
    820 	const VkCommandBufferAllocateInfo		cmdBufParams			=
    821 	{
    822 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
    823 		DE_NULL,													//	const void*					pNext;
    824 		*cmdPool,													//	VkCommandPool				pool;
    825 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
    826 		minCommandBuffer,											//	uint32_t					bufferCount;
    827 	};
    828 
    829 	// do not keep the handles to buffers, as they will be freed with command pool
    830 
    831 	// allocate the minimum required amount of buffers
    832 	VkCommandBuffer cmdBuffers[minCommandBuffer];
    833 	VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
    834 
    835 	std::ostringstream out;
    836 	out << "allocateManySecondaryBuffersTest succeded: created " << minCommandBuffer << " command buffers";
    837 
    838 	return tcu::TestStatus::pass(out.str());
    839 }
    840 
    841 tcu::TestStatus executePrimaryBufferTest(Context& context)
    842 {
    843 	const VkDevice							vkDevice				= context.getDevice();
    844 	const DeviceInterface&					vk						= context.getDeviceInterface();
    845 	const VkQueue							queue					= context.getUniversalQueue();
    846 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    847 
    848 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    849 	{
    850 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
    851 		DE_NULL,													//	const void*					pNext;
    852 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
    853 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
    854 	};
    855 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
    856 
    857 	// Command buffer
    858 	const VkCommandBufferAllocateInfo		cmdBufParams			=
    859 	{
    860 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
    861 		DE_NULL,													//	const void*					pNext;
    862 		*cmdPool,													//	VkCommandPool				pool;
    863 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
    864 		1u,															//	uint32_t					bufferCount;
    865 	};
    866 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
    867 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
    868 	{
    869 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
    870 		DE_NULL,
    871 		0,															// flags
    872 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
    873 	};
    874 
    875 	// create event that will be used to check if secondary command buffer has been executed
    876 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
    877 
    878 	// reset event
    879 	VK_CHECK(vk.resetEvent(vkDevice, *event));
    880 
    881 	// record primary command buffer
    882 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
    883 	{
    884 		// allow execution of event during every stage of pipeline
    885 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
    886 
    887 		// record setting event
    888 		vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
    889 	}
    890 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
    891 
    892 	// create fence to wait for execution of queue
    893 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
    894 
    895 	const VkSubmitInfo						submitInfo				=
    896 	{
    897 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
    898 		DE_NULL,													// pNext
    899 		0u,															// waitSemaphoreCount
    900 		DE_NULL,													// pWaitSemaphores
    901 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
    902 		1,															// commandBufferCount
    903 		&primCmdBuf.get(),											// pCommandBuffers
    904 		0u,															// signalSemaphoreCount
    905 		DE_NULL,													// pSignalSemaphores
    906 	};
    907 
    908 	// Submit the command buffer to the queue
    909 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
    910 
    911 	// wait for end of execution of queue
    912 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
    913 
    914 	// check if buffer has been executed
    915 	VkResult result = vk.getEventStatus(vkDevice,*event);
    916 	if (result == VK_EVENT_SET)
    917 		return tcu::TestStatus::pass("Execute Primary Command Buffer succeeded");
    918 
    919 	return tcu::TestStatus::fail("Execute Primary Command Buffer FAILED");
    920 }
    921 
    922 tcu::TestStatus executeLargePrimaryBufferTest(Context& context)
    923 {
    924 	const VkDevice							vkDevice				= context.getDevice();
    925 	const DeviceInterface&					vk						= context.getDeviceInterface();
    926 	const VkQueue							queue					= context.getUniversalQueue();
    927 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
    928 	const deUint32							LARGE_BUFFER_SIZE		= 10000;
    929 
    930 	const VkCommandPoolCreateInfo			cmdPoolParams			=
    931 	{
    932 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
    933 		DE_NULL,													//	const void*					pNext;
    934 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
    935 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
    936 	};
    937 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
    938 
    939 	// Command buffer
    940 	const VkCommandBufferAllocateInfo		cmdBufParams			=
    941 	{
    942 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
    943 		DE_NULL,													//	const void*					pNext;
    944 		*cmdPool,													//	VkCommandPool				pool;
    945 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
    946 		1u,															//	uint32_t					bufferCount;
    947 	};
    948 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
    949 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
    950 	{
    951 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
    952 		DE_NULL,
    953 		0,															// flags
    954 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
    955 	};
    956 
    957 	std::vector<VkEventSp>					events;
    958 	for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
    959 		events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice))));
    960 
    961 	// record primary command buffer
    962 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
    963 	{
    964 		// set all the events
    965 		for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
    966 		{
    967 			vk.cmdSetEvent(*primCmdBuf, events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
    968 		}
    969 	}
    970 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
    971 
    972 	// create fence to wait for execution of queue
    973 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
    974 
    975 	const VkSubmitInfo						submitInfo				=
    976 	{
    977 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
    978 		DE_NULL,													// pNext
    979 		0u,															// waitSemaphoreCount
    980 		DE_NULL,													// pWaitSemaphores
    981 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
    982 		1,															// commandBufferCount
    983 		&primCmdBuf.get(),											// pCommandBuffers
    984 		0u,															// signalSemaphoreCount
    985 		DE_NULL,													// pSignalSemaphores
    986 	};
    987 
    988 	// Submit the command buffer to the queue
    989 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
    990 
    991 	// wait for end of execution of queue
    992 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
    993 
    994 	// check if the buffer was executed correctly - all events had their status
    995 	// changed
    996 	tcu::TestStatus testResult = tcu::TestStatus::incomplete();
    997 
    998 	for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
    999 	{
   1000 		if (vk.getEventStatus(vkDevice, events[ndx]->get()) != VK_EVENT_SET)
   1001 		{
   1002 			testResult = tcu::TestStatus::fail("An event was not set.");
   1003 			break;
   1004 		}
   1005 	}
   1006 
   1007 	if (!testResult.isComplete())
   1008 		testResult = tcu::TestStatus::pass("All events set correctly.");
   1009 
   1010 	return testResult;
   1011 }
   1012 
   1013 tcu::TestStatus resetBufferImplicitlyTest(Context& context)
   1014 {
   1015 	const VkDevice							vkDevice				= context.getDevice();
   1016 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1017 	const VkQueue							queue					= context.getUniversalQueue();
   1018 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1019 
   1020 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1021 	{
   1022 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   1023 		DE_NULL,													// pNext;
   1024 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
   1025 		queueFamilyIndex,											// queueFamilyIndex;
   1026 	};
   1027 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1028 
   1029 	// Command buffer
   1030 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1031 	{
   1032 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   1033 		DE_NULL,													// pNext;
   1034 		*cmdPool,													// pool;
   1035 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   1036 		1u,															// bufferCount;
   1037 	};
   1038 	const Unique<VkCommandBuffer>			cmdBuf						(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1039 
   1040 	const VkCommandBufferBeginInfo			cmdBufBeginInfo			=
   1041 	{
   1042 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   1043 		DE_NULL,													// pNext
   1044 		0u,															// flags
   1045 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1046 	};
   1047 
   1048 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1049 
   1050 	// Put the command buffer in recording state.
   1051 	VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginInfo));
   1052 	{
   1053 		// Set the event
   1054 		vk.cmdSetEvent(*cmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   1055 	}
   1056 	VK_CHECK(vk.endCommandBuffer(*cmdBuf));
   1057 
   1058 	// We'll use a fence to wait for the execution of the queue
   1059 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   1060 
   1061 	const VkSubmitInfo						submitInfo				=
   1062 	{
   1063 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1064 		DE_NULL,													// pNext
   1065 		0u,															// waitSemaphoreCount
   1066 		DE_NULL,													// pWaitSemaphores
   1067 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1068 		1u,															// commandBufferCount
   1069 		&cmdBuf.get(),												// pCommandBuffers
   1070 		0u,															// signalSemaphoreCount
   1071 		DE_NULL,													// pSignalSemaphores
   1072 	};
   1073 
   1074 	// Submitting the command buffer that sets the event to the queue
   1075 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
   1076 
   1077 	// Waiting for the queue to finish executing
   1078 	VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), 0u, INFINITE_TIMEOUT));
   1079 	// Reset the fence so that we can reuse it
   1080 	VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   1081 
   1082 	// Check if the buffer was executed
   1083 	if (vk.getEventStatus(vkDevice, *event) != VK_EVENT_SET)
   1084 		return tcu::TestStatus::fail("Failed to set the event.");
   1085 
   1086 	// Reset the event
   1087 	vk.resetEvent(vkDevice, *event);
   1088 	if(vk.getEventStatus(vkDevice, *event) != VK_EVENT_RESET)
   1089 		return tcu::TestStatus::fail("Failed to reset the event.");
   1090 
   1091 	// Reset the command buffer by putting it in recording state again. This
   1092 	// should empty the command buffer.
   1093 	VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginInfo));
   1094 	VK_CHECK(vk.endCommandBuffer(*cmdBuf));
   1095 
   1096 	// Submit the command buffer after resetting. It should have no commands
   1097 	// recorded, so the event should remain unsignaled.
   1098 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
   1099 	// Waiting for the queue to finish executing
   1100 	VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), 0u, INFINITE_TIMEOUT));
   1101 
   1102 	// Check if the event remained unset.
   1103 	if(vk.getEventStatus(vkDevice, *event) == VK_EVENT_RESET)
   1104 		return tcu::TestStatus::pass("Buffer was reset correctly.");
   1105 	else
   1106 		return tcu::TestStatus::fail("Buffer was not reset correctly.");
   1107 }
   1108 
   1109 using  de::SharedPtr;
   1110 typedef SharedPtr<Unique<VkEvent> >			VkEventShared;
   1111 
   1112 template<typename T>
   1113 inline SharedPtr<Unique<T> > makeSharedPtr (Move<T> move)
   1114 {
   1115 	return SharedPtr<Unique<T> >(new Unique<T>(move));
   1116 }
   1117 
   1118 bool submitAndCheck (Context& context, std::vector<VkCommandBuffer>& cmdBuffers, std::vector <VkEventShared>& events)
   1119 {
   1120 	const VkDevice						vkDevice	= context.getDevice();
   1121 	const DeviceInterface&				vk			= context.getDeviceInterface();
   1122 	const VkQueue						queue		= context.getUniversalQueue();
   1123 	const Unique<VkFence>				fence		(createFence(vk, vkDevice));
   1124 
   1125 	const VkSubmitInfo					submitInfo	=
   1126 	{
   1127 		VK_STRUCTURE_TYPE_SUBMIT_INFO,				// sType
   1128 		DE_NULL,									// pNext
   1129 		0u,											// waitSemaphoreCount
   1130 		DE_NULL,									// pWaitSemaphores
   1131 		(const VkPipelineStageFlags*)DE_NULL,		// pWaitDstStageMask
   1132 		static_cast<deUint32>(cmdBuffers.size()),	// commandBufferCount
   1133 		&cmdBuffers[0],								// pCommandBuffers
   1134 		0u,											// signalSemaphoreCount
   1135 		DE_NULL,									// pSignalSemaphores
   1136 	};
   1137 
   1138 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
   1139 	VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), 0u, INFINITE_TIMEOUT));
   1140 
   1141 	for(int eventNdx = 0; eventNdx < static_cast<int>(events.size()); ++eventNdx)
   1142 	{
   1143 		if (vk.getEventStatus(vkDevice, **events[eventNdx]) != VK_EVENT_SET)
   1144 			return false;
   1145 		vk.resetEvent(vkDevice, **events[eventNdx]);
   1146 	}
   1147 
   1148 	return true;
   1149 }
   1150 
   1151 void createCommadBuffers (const DeviceInterface&		vk,
   1152 						  const VkDevice				vkDevice,
   1153 						  deUint32						bufferCount,
   1154 						  VkCommandPool					pool,
   1155 						  const VkCommandBufferLevel	cmdBufferLevel,
   1156 						  VkCommandBuffer*				pCommandBuffers)
   1157 {
   1158 	const VkCommandBufferAllocateInfo		cmdBufParams	=
   1159 	{
   1160 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,	//	VkStructureType				sType;
   1161 		DE_NULL,										//	const void*					pNext;
   1162 		pool,											//	VkCommandPool				pool;
   1163 		cmdBufferLevel,									//	VkCommandBufferLevel		level;
   1164 		bufferCount,									//	uint32_t					bufferCount;
   1165 	};
   1166 	VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, pCommandBuffers));
   1167 }
   1168 
   1169 void addCommandsToBuffer (const DeviceInterface& vk, std::vector<VkCommandBuffer>& cmdBuffers, std::vector <VkEventShared>& events)
   1170 {
   1171 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   1172 	{
   1173 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   1174 		DE_NULL,
   1175 		(VkRenderPass)0u,								// renderPass
   1176 		0u,												// subpass
   1177 		(VkFramebuffer)0u,								// framebuffer
   1178 		VK_FALSE,										// occlusionQueryEnable
   1179 		(VkQueryControlFlags)0u,						// queryFlags
   1180 		(VkQueryPipelineStatisticFlags)0u,				// pipelineStatistics
   1181 	};
   1182 
   1183 	const VkCommandBufferBeginInfo		cmdBufBeginInfo	=
   1184 	{
   1185 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,	// sType
   1186 		DE_NULL,										// pNext
   1187 		0u,												// flags
   1188 		&secCmdBufInheritInfo,							// pInheritanceInfo;
   1189 	};
   1190 
   1191 	for(int bufferNdx = 0; bufferNdx < static_cast<int>(cmdBuffers.size()); ++bufferNdx)
   1192 	{
   1193 		VK_CHECK(vk.beginCommandBuffer(cmdBuffers[bufferNdx], &cmdBufBeginInfo));
   1194 		vk.cmdSetEvent(cmdBuffers[bufferNdx], **events[bufferNdx % events.size()], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   1195 		VK_CHECK(vk.endCommandBuffer(cmdBuffers[bufferNdx]));
   1196 	}
   1197 }
   1198 
   1199 bool executeSecondaryCmdBuffer (Context&						context,
   1200 								VkCommandPool					pool,
   1201 								std::vector<VkCommandBuffer>&	cmdBuffersSecondary,
   1202 								std::vector <VkEventShared>&	events)
   1203 {
   1204 	const VkDevice					vkDevice		= context.getDevice();
   1205 	const DeviceInterface&			vk				= context.getDeviceInterface();
   1206 	std::vector<VkCommandBuffer>	cmdBuffer		(1);
   1207 	const VkCommandBufferBeginInfo	cmdBufBeginInfo	=
   1208 	{
   1209 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,	// sType
   1210 		DE_NULL,										// pNext
   1211 		0u,												// flags
   1212 		(const VkCommandBufferInheritanceInfo*)DE_NULL,	// pInheritanceInfo;
   1213 	};
   1214 
   1215 	createCommadBuffers(vk, vkDevice, 1u, pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, &cmdBuffer[0]);
   1216 	VK_CHECK(vk.beginCommandBuffer(cmdBuffer[0], &cmdBufBeginInfo));
   1217 	vk.cmdExecuteCommands(cmdBuffer[0], static_cast<deUint32>(cmdBuffersSecondary.size()), &cmdBuffersSecondary[0]);
   1218 	VK_CHECK(vk.endCommandBuffer(cmdBuffer[0]));
   1219 
   1220 	bool returnValue = submitAndCheck(context, cmdBuffer, events);
   1221 	vk.freeCommandBuffers(vkDevice, pool, 1u, &cmdBuffer[0]);
   1222 	return returnValue;
   1223 }
   1224 
   1225 tcu::TestStatus trimCommandPoolTest (Context& context, const VkCommandBufferLevel cmdBufferLevel)
   1226 {
   1227 	if (!isDeviceExtensionSupported(context.getUsedApiVersion(), context.getDeviceExtensions(), "VK_KHR_maintenance1"))
   1228 		TCU_THROW(NotSupportedError, "Extension VK_KHR_maintenance1 not supported");
   1229 
   1230 	const VkDevice							vkDevice				= context.getDevice();
   1231 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1232 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1233 
   1234 	//test parameters
   1235 	const deUint32							cmdBufferIterationCount	= 300u;
   1236 	const deUint32							cmdBufferCount			= 10u;
   1237 
   1238 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1239 	{
   1240 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   1241 		DE_NULL,													// pNext;
   1242 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
   1243 		queueFamilyIndex,											// queueFamilyIndex;
   1244 	};
   1245 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1246 
   1247 	std::vector <VkEventShared>				events;
   1248 	for (deUint32 ndx = 0u; ndx < cmdBufferCount; ++ndx)
   1249 		events.push_back(makeSharedPtr(createEvent(vk, vkDevice)));
   1250 
   1251 	{
   1252 		std::vector<VkCommandBuffer> cmdBuffers(cmdBufferCount);
   1253 		createCommadBuffers(vk, vkDevice, cmdBufferCount, *cmdPool, cmdBufferLevel, &cmdBuffers[0]);
   1254 
   1255 		for (deUint32 cmdBufferIterationrNdx = 0; cmdBufferIterationrNdx < cmdBufferIterationCount; ++cmdBufferIterationrNdx)
   1256 		{
   1257 			addCommandsToBuffer(vk, cmdBuffers, events);
   1258 
   1259 			//Peak, situation when we use a lot more command buffers
   1260 			if (cmdBufferIterationrNdx % 10u == 0)
   1261 			{
   1262 				std::vector<VkCommandBuffer> cmdBuffersPeak(cmdBufferCount * 10u);
   1263 				createCommadBuffers(vk, vkDevice, static_cast<deUint32>(cmdBuffersPeak.size()), *cmdPool, cmdBufferLevel, &cmdBuffersPeak[0]);
   1264 				addCommandsToBuffer(vk, cmdBuffersPeak, events);
   1265 
   1266 				switch(cmdBufferLevel)
   1267 				{
   1268 					case VK_COMMAND_BUFFER_LEVEL_PRIMARY:
   1269 						if (!submitAndCheck(context, cmdBuffersPeak, events))
   1270 							return tcu::TestStatus::fail("Fail");
   1271 						break;
   1272 					case VK_COMMAND_BUFFER_LEVEL_SECONDARY:
   1273 						if (!executeSecondaryCmdBuffer(context, *cmdPool, cmdBuffersPeak, events))
   1274 							return tcu::TestStatus::fail("Fail");
   1275 						break;
   1276 					default:
   1277 						DE_ASSERT(0);
   1278 				}
   1279 				vk.freeCommandBuffers(vkDevice, *cmdPool, static_cast<deUint32>(cmdBuffersPeak.size()), &cmdBuffersPeak[0]);
   1280 			}
   1281 
   1282 			vk.trimCommandPool(vkDevice, *cmdPool, (VkCommandPoolTrimFlags)0);
   1283 
   1284 			switch(cmdBufferLevel)
   1285 			{
   1286 				case VK_COMMAND_BUFFER_LEVEL_PRIMARY:
   1287 					if (!submitAndCheck(context, cmdBuffers, events))
   1288 						return tcu::TestStatus::fail("Fail");
   1289 					break;
   1290 				case VK_COMMAND_BUFFER_LEVEL_SECONDARY:
   1291 					if (!executeSecondaryCmdBuffer(context, *cmdPool, cmdBuffers, events))
   1292 						return tcu::TestStatus::fail("Fail");
   1293 					break;
   1294 				default:
   1295 					DE_ASSERT(0);
   1296 			}
   1297 
   1298 			for (deUint32 bufferNdx = cmdBufferIterationrNdx % 3u; bufferNdx < cmdBufferCount; bufferNdx+=2u)
   1299 			{
   1300 				vk.freeCommandBuffers(vkDevice, *cmdPool, 1u, &cmdBuffers[bufferNdx]);
   1301 				createCommadBuffers(vk, vkDevice, 1u, *cmdPool, cmdBufferLevel, &cmdBuffers[bufferNdx]);
   1302 			}
   1303 		}
   1304 	}
   1305 
   1306 	return tcu::TestStatus::pass("Pass");
   1307 }
   1308 
   1309 /******** 19.3. Command Buffer Recording (5.3 in VK 1.0 Spec) *****************/
   1310 tcu::TestStatus recordSinglePrimaryBufferTest(Context& context)
   1311 {
   1312 	const VkDevice							vkDevice				= context.getDevice();
   1313 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1314 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1315 
   1316 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1317 	{
   1318 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1319 		DE_NULL,													//	const void*					pNext;
   1320 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1321 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1322 	};
   1323 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1324 
   1325 	// Command buffer
   1326 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1327 	{
   1328 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
   1329 		DE_NULL,													//	const void*					pNext;
   1330 		*cmdPool,													//	VkCommandPool				pool;
   1331 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1332 		1u,															//	uint32_t					bufferCount;
   1333 	};
   1334 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1335 
   1336 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   1337 	{
   1338 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1339 		DE_NULL,
   1340 		0,															// flags
   1341 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1342 	};
   1343 
   1344 	// create event that will be used to check if secondary command buffer has been executed
   1345 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1346 
   1347 	// record primary command buffer
   1348 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   1349 	{
   1350 		// record setting event
   1351 		vk.cmdSetEvent(*primCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   1352 	}
   1353 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   1354 
   1355 	return tcu::TestStatus::pass("Primary buffer recorded successfully.");
   1356 }
   1357 
   1358 tcu::TestStatus recordLargePrimaryBufferTest(Context &context)
   1359 {
   1360 
   1361 	const VkDevice							vkDevice				= context.getDevice();
   1362 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1363 	const VkQueue							queue					= context.getUniversalQueue();
   1364 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1365 
   1366 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1367 	{
   1368 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1369 		DE_NULL,													//	const void*					pNext;
   1370 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1371 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1372 	};
   1373 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1374 
   1375 	// Command buffer
   1376 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1377 	{
   1378 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
   1379 		DE_NULL,													//	const void*					pNext;
   1380 		*cmdPool,													//	VkCommandPool				pool;
   1381 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1382 		1u,															//	uint32_t					bufferCount;
   1383 	};
   1384 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1385 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   1386 	{
   1387 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1388 		DE_NULL,
   1389 		0,															// flags
   1390 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1391 	};
   1392 
   1393 	// create event that will be used to check if secondary command buffer has been executed
   1394 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1395 
   1396 	// reset event
   1397 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1398 
   1399 	// record primary command buffer
   1400 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   1401 	{
   1402 		// allow execution of event during every stage of pipeline
   1403 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   1404 
   1405 		// define minimal amount of commands to accept
   1406 		const long long unsigned minNumCommands = 10000llu;
   1407 
   1408 		for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands )
   1409 		{
   1410 			// record setting event
   1411 			vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
   1412 
   1413 			// record resetting event
   1414 			vk.cmdResetEvent(*primCmdBuf, *event,stageMask);
   1415 		};
   1416 
   1417 	}
   1418 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   1419 
   1420 	// create fence to wait for execution of queue
   1421 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   1422 
   1423 	const VkSubmitInfo						submitInfo				=
   1424 	{
   1425 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1426 		DE_NULL,													// pNext
   1427 		0u,															// waitSemaphoreCount
   1428 		DE_NULL,													// pWaitSemaphores
   1429 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1430 		1,															// commandBufferCount
   1431 		&primCmdBuf.get(),											// pCommandBuffers
   1432 		0u,															// signalSemaphoreCount
   1433 		DE_NULL,													// pSignalSemaphores
   1434 	};
   1435 
   1436 	// Submit the command buffer to the queue
   1437 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   1438 
   1439 	// wait for end of execution of queue
   1440 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1441 
   1442 	return tcu::TestStatus::pass("hugeTest succeeded");
   1443 }
   1444 
   1445 tcu::TestStatus recordSingleSecondaryBufferTest(Context& context)
   1446 {
   1447 	const VkDevice							vkDevice				= context.getDevice();
   1448 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1449 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1450 
   1451 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1452 	{
   1453 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1454 		DE_NULL,													//	const void*					pNext;
   1455 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1456 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1457 	};
   1458 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1459 
   1460 	// Command buffer
   1461 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1462 	{
   1463 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
   1464 		DE_NULL,													//	const void*					pNext;
   1465 		*cmdPool,													//	VkCommandPool				pool;
   1466 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   1467 		1u,															//	uint32_t					bufferCount;
   1468 	};
   1469 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1470 
   1471 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   1472 	{
   1473 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   1474 		DE_NULL,
   1475 		(VkRenderPass)0u,											// renderPass
   1476 		0u,															// subpass
   1477 		(VkFramebuffer)0u,											// framebuffer
   1478 		VK_FALSE,													// occlusionQueryEnable
   1479 		(VkQueryControlFlags)0u,									// queryFlags
   1480 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   1481 	};
   1482 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo		=
   1483 	{
   1484 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1485 		DE_NULL,
   1486 		0,															// flags
   1487 		&secCmdBufInheritInfo,
   1488 	};
   1489 
   1490 	// create event that will be used to check if secondary command buffer has been executed
   1491 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1492 
   1493 	// record primary command buffer
   1494 	VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   1495 	{
   1496 		// record setting event
   1497 		vk.cmdSetEvent(*secCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   1498 	}
   1499 	VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   1500 
   1501 	return tcu::TestStatus::pass("Secondary buffer recorded successfully.");
   1502 }
   1503 
   1504 tcu::TestStatus recordLargeSecondaryBufferTest(Context &context)
   1505 {
   1506 
   1507 	const VkDevice							vkDevice				= context.getDevice();
   1508 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1509 	const VkQueue							queue					= context.getUniversalQueue();
   1510 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1511 
   1512 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1513 	{
   1514 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1515 		DE_NULL,													//	const void*					pNext;
   1516 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1517 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1518 	};
   1519 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1520 
   1521 	// Command buffer
   1522 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1523 	{
   1524 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
   1525 		DE_NULL,													//	const void*					pNext;
   1526 		*cmdPool,													//	VkCommandPool				pool;
   1527 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1528 		1u,															//	uint32_t					bufferCount;
   1529 	};
   1530 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1531 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   1532 	{
   1533 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1534 		DE_NULL,
   1535 		0,															// flags
   1536 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1537 	};
   1538 
   1539 	// create event that will be used to check if secondary command buffer has been executed
   1540 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1541 
   1542 	// reset event
   1543 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1544 
   1545 	// record primary command buffer
   1546 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   1547 	{
   1548 		// allow execution of event during every stage of pipeline
   1549 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   1550 
   1551 		// define minimal amount of commands to accept
   1552 		const long long unsigned minNumCommands = 10000llu;
   1553 
   1554 		for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands )
   1555 		{
   1556 			// record setting event
   1557 			vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
   1558 
   1559 			// record resetting event
   1560 			vk.cmdResetEvent(*primCmdBuf, *event,stageMask);
   1561 		};
   1562 
   1563 
   1564 	}
   1565 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   1566 
   1567 	// create fence to wait for execution of queue
   1568 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   1569 
   1570 	const VkSubmitInfo						submitInfo				=
   1571 	{
   1572 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1573 		DE_NULL,													// pNext
   1574 		0u,															// waitSemaphoreCount
   1575 		DE_NULL,													// pWaitSemaphores
   1576 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1577 		1,															// commandBufferCount
   1578 		&primCmdBuf.get(),											// pCommandBuffers
   1579 		0u,															// signalSemaphoreCount
   1580 		DE_NULL,													// pSignalSemaphores
   1581 	};
   1582 
   1583 	// Submit the command buffer to the queue
   1584 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   1585 
   1586 	// wait for end of execution of queue
   1587 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1588 
   1589 	return tcu::TestStatus::pass("hugeTest succeeded");
   1590 }
   1591 
   1592 tcu::TestStatus submitPrimaryBufferTwiceTest(Context& context)
   1593 {
   1594 
   1595 	const VkDevice							vkDevice				= context.getDevice();
   1596 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1597 	const VkQueue							queue					= context.getUniversalQueue();
   1598 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1599 
   1600 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1601 	{
   1602 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1603 		DE_NULL,													//	const void*					pNext;
   1604 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1605 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1606 	};
   1607 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1608 
   1609 	// Command buffer
   1610 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1611 	{
   1612 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   1613 		DE_NULL,													//	const void*				pNext;
   1614 		*cmdPool,													//	VkCommandPool				pool;
   1615 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1616 		1u,															//	uint32_t					bufferCount;
   1617 	};
   1618 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1619 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   1620 	{
   1621 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1622 		DE_NULL,
   1623 		0,															// flags
   1624 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1625 	};
   1626 
   1627 	// create event that will be used to check if secondary command buffer has been executed
   1628 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1629 
   1630 	// reset event
   1631 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1632 
   1633 	// record primary command buffer
   1634 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   1635 	{
   1636 		// allow execution of event during every stage of pipeline
   1637 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   1638 
   1639 		// record setting event
   1640 		vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
   1641 	}
   1642 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   1643 
   1644 	// create fence to wait for execution of queue
   1645 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   1646 
   1647 	const VkSubmitInfo						submitInfo				=
   1648 	{
   1649 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1650 		DE_NULL,													// pNext
   1651 		0u,															// waitSemaphoreCount
   1652 		DE_NULL,													// pWaitSemaphores
   1653 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1654 		1,															// commandBufferCount
   1655 		&primCmdBuf.get(),											// pCommandBuffers
   1656 		0u,															// signalSemaphoreCount
   1657 		DE_NULL,													// pSignalSemaphores
   1658 	};
   1659 
   1660 	// submit primary buffer
   1661 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   1662 
   1663 	// wait for end of execution of queue
   1664 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1665 	VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   1666 	// check if buffer has been executed
   1667 	VkResult result = vk.getEventStatus(vkDevice,*event);
   1668 	if (result != VK_EVENT_SET)
   1669 		return tcu::TestStatus::fail("Submit Twice Test FAILED");
   1670 
   1671 	// reset event
   1672 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1673 
   1674 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   1675 
   1676 	// wait for end of execution of queue
   1677 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1678 
   1679 	// check if buffer has been executed
   1680 	result = vk.getEventStatus(vkDevice,*event);
   1681 	if (result != VK_EVENT_SET)
   1682 		return tcu::TestStatus::fail("Submit Twice Test FAILED");
   1683 	else
   1684 		return tcu::TestStatus::pass("Submit Twice Test succeeded");
   1685 }
   1686 
   1687 tcu::TestStatus submitSecondaryBufferTwiceTest(Context& context)
   1688 {
   1689 
   1690 	const VkDevice							vkDevice				= context.getDevice();
   1691 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1692 	const VkQueue							queue					= context.getUniversalQueue();
   1693 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1694 
   1695 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1696 	{
   1697 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1698 		DE_NULL,													//	const void*					pNext;
   1699 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1700 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1701 	};
   1702 
   1703 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1704 
   1705 	// Command buffer
   1706 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1707 	{
   1708 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   1709 		DE_NULL,													//	const void*				pNext;
   1710 		*cmdPool,													//	VkCommandPool				pool;
   1711 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1712 		1u,															//	uint32_t					bufferCount;
   1713 	};
   1714 
   1715 	const Unique<VkCommandBuffer>			primCmdBuf1				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1716 	const Unique<VkCommandBuffer>			primCmdBuf2				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1717 
   1718 	// Secondary Command buffer
   1719 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   1720 	{
   1721 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   1722 		DE_NULL,													//	const void*				pNext;
   1723 		*cmdPool,													//	VkCommandPool				pool;
   1724 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   1725 		1u,															//	uint32_t					bufferCount;
   1726 	};
   1727 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   1728 
   1729 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   1730 	{
   1731 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1732 		DE_NULL,
   1733 		0,															// flags
   1734 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1735 	};
   1736 
   1737 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   1738 	{
   1739 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   1740 		DE_NULL,
   1741 		(VkRenderPass)0u,											// renderPass
   1742 		0u,															// subpass
   1743 		(VkFramebuffer)0u,											// framebuffer
   1744 		VK_FALSE,													// occlusionQueryEnable
   1745 		(VkQueryControlFlags)0u,									// queryFlags
   1746 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   1747 	};
   1748 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo		=
   1749 	{
   1750 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1751 		DE_NULL,
   1752 		0u,															// flags
   1753 		&secCmdBufInheritInfo,
   1754 	};
   1755 
   1756 	// create event that will be used to check if secondary command buffer has been executed
   1757 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1758 
   1759 	// reset event
   1760 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1761 
   1762 	// record first primary command buffer
   1763 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
   1764 	{
   1765 		// record secondary command buffer
   1766 		VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   1767 		{
   1768 			// allow execution of event during every stage of pipeline
   1769 			VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   1770 
   1771 			// record setting event
   1772 			vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
   1773 		}
   1774 
   1775 		// end recording of secondary buffers
   1776 		VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   1777 
   1778 		// execute secondary buffer
   1779 		vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get());
   1780 	}
   1781 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
   1782 
   1783 	// create fence to wait for execution of queue
   1784 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   1785 
   1786 	const VkSubmitInfo						submitInfo1				=
   1787 	{
   1788 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1789 		DE_NULL,													// pNext
   1790 		0u,															// waitSemaphoreCount
   1791 		DE_NULL,													// pWaitSemaphores
   1792 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1793 		1,															// commandBufferCount
   1794 		&primCmdBuf1.get(),											// pCommandBuffers
   1795 		0u,															// signalSemaphoreCount
   1796 		DE_NULL,													// pSignalSemaphores
   1797 	};
   1798 
   1799 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
   1800 
   1801 	// wait for end of execution of queue
   1802 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1803 	VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   1804 
   1805 	// check if secondary buffer has been executed
   1806 	VkResult result = vk.getEventStatus(vkDevice,*event);
   1807 	if (result != VK_EVENT_SET)
   1808 		return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED");
   1809 
   1810 	// reset first primary buffer
   1811 	vk.resetCommandBuffer( *primCmdBuf1, 0u);
   1812 
   1813 	// reset event to allow receiving it again
   1814 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1815 
   1816 	// record second primary command buffer
   1817 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
   1818 	{
   1819 		// execute secondary buffer
   1820 		vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get());
   1821 	}
   1822 	// end recording
   1823 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
   1824 
   1825 	// submit second primary buffer, the secondary should be executed too
   1826 	const VkSubmitInfo						submitInfo2				=
   1827 	{
   1828 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1829 		DE_NULL,													// pNext
   1830 		0u,															// waitSemaphoreCount
   1831 		DE_NULL,													// pWaitSemaphores
   1832 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1833 		1,															// commandBufferCount
   1834 		&primCmdBuf2.get(),											// pCommandBuffers
   1835 		0u,															// signalSemaphoreCount
   1836 		DE_NULL,													// pSignalSemaphores
   1837 	};
   1838 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
   1839 
   1840 	// wait for end of execution of queue
   1841 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1842 
   1843 	// check if secondary buffer has been executed
   1844 	result = vk.getEventStatus(vkDevice,*event);
   1845 	if (result != VK_EVENT_SET)
   1846 		return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED");
   1847 	else
   1848 		return tcu::TestStatus::pass("Submit Twice Secondary Command Buffer succeeded");
   1849 }
   1850 
   1851 tcu::TestStatus oneTimeSubmitFlagPrimaryBufferTest(Context& context)
   1852 {
   1853 
   1854 	const VkDevice							vkDevice				= context.getDevice();
   1855 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1856 	const VkQueue							queue					= context.getUniversalQueue();
   1857 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1858 
   1859 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1860 	{
   1861 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1862 		DE_NULL,													//	const void*					pNext;
   1863 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1864 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1865 	};
   1866 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1867 
   1868 	// Command buffer
   1869 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1870 	{
   1871 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
   1872 		DE_NULL,													//	const void*					pNext;
   1873 		*cmdPool,													//	VkCommandPool				pool;
   1874 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1875 		1u,															//	uint32_t					bufferCount;
   1876 	};
   1877 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1878 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   1879 	{
   1880 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   1881 		DE_NULL,
   1882 		VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,				// flags
   1883 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   1884 	};
   1885 
   1886 	// create event that will be used to check if secondary command buffer has been executed
   1887 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   1888 
   1889 	// reset event
   1890 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1891 
   1892 	// record primary command buffer
   1893 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   1894 	{
   1895 		// allow execution of event during every stage of pipeline
   1896 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   1897 
   1898 		// record setting event
   1899 		vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
   1900 	}
   1901 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   1902 
   1903 	// create fence to wait for execution of queue
   1904 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   1905 
   1906 	const VkSubmitInfo						submitInfo				=
   1907 	{
   1908 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   1909 		DE_NULL,													// pNext
   1910 		0u,															// waitSemaphoreCount
   1911 		DE_NULL,													// pWaitSemaphores
   1912 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   1913 		1,															// commandBufferCount
   1914 		&primCmdBuf.get(),											// pCommandBuffers
   1915 		0u,															// signalSemaphoreCount
   1916 		DE_NULL,													// pSignalSemaphores
   1917 	};
   1918 
   1919 	// submit primary buffer
   1920 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   1921 
   1922 	// wait for end of execution of queue
   1923 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1924 	VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   1925 
   1926 	// check if buffer has been executed
   1927 	VkResult result = vk.getEventStatus(vkDevice,*event);
   1928 	if (result != VK_EVENT_SET)
   1929 		return tcu::TestStatus::fail("oneTimeSubmitFlagPrimaryBufferTest FAILED");
   1930 
   1931 	// record primary command buffer again - implicit reset because of VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
   1932 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   1933 	{
   1934 		// allow execution of event during every stage of pipeline
   1935 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   1936 
   1937 		// record setting event
   1938 		vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
   1939 	}
   1940 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   1941 
   1942 	// reset event
   1943 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   1944 
   1945 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   1946 
   1947 	// wait for end of execution of queue
   1948 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   1949 
   1950 	// check if buffer has been executed
   1951 	result = vk.getEventStatus(vkDevice,*event);
   1952 	if (result != VK_EVENT_SET)
   1953 		return tcu::TestStatus::fail("oneTimeSubmitFlagPrimaryBufferTest FAILED");
   1954 	else
   1955 		return tcu::TestStatus::pass("oneTimeSubmitFlagPrimaryBufferTest succeeded");
   1956 }
   1957 
   1958 tcu::TestStatus oneTimeSubmitFlagSecondaryBufferTest(Context& context)
   1959 {
   1960 
   1961 	const VkDevice							vkDevice				= context.getDevice();
   1962 	const DeviceInterface&					vk						= context.getDeviceInterface();
   1963 	const VkQueue							queue					= context.getUniversalQueue();
   1964 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   1965 
   1966 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   1967 	{
   1968 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   1969 		DE_NULL,													//	const void*					pNext;
   1970 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   1971 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   1972 	};
   1973 
   1974 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   1975 
   1976 	// Command buffer
   1977 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   1978 	{
   1979 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   1980 		DE_NULL,													//	const void*				pNext;
   1981 		*cmdPool,													//	VkCommandPool				pool;
   1982 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   1983 		1u,															//	uint32_t					bufferCount;
   1984 	};
   1985 
   1986 	const Unique<VkCommandBuffer>			primCmdBuf1				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1987 	const Unique<VkCommandBuffer>			primCmdBuf2				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   1988 
   1989 	// Secondary Command buffer
   1990 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   1991 	{
   1992 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   1993 		DE_NULL,													//	const void*				pNext;
   1994 		*cmdPool,													//	VkCommandPool				pool;
   1995 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   1996 		1u,															//	uint32_t					bufferCount;
   1997 	};
   1998 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   1999 
   2000 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   2001 	{
   2002 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2003 		DE_NULL,
   2004 		0,															// flags
   2005 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2006 	};
   2007 
   2008 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   2009 	{
   2010 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   2011 		DE_NULL,
   2012 		(VkRenderPass)0u,											// renderPass
   2013 		0u,															// subpass
   2014 		(VkFramebuffer)0u,											// framebuffer
   2015 		VK_FALSE,													// occlusionQueryEnable
   2016 		(VkQueryControlFlags)0u,									// queryFlags
   2017 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   2018 	};
   2019 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo		=
   2020 	{
   2021 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2022 		DE_NULL,
   2023 		VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,				// flags
   2024 		&secCmdBufInheritInfo,
   2025 	};
   2026 
   2027 	// create event that will be used to check if secondary command buffer has been executed
   2028 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   2029 
   2030 	// reset event
   2031 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   2032 
   2033 	// record first primary command buffer
   2034 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
   2035 	{
   2036 		// record secondary command buffer
   2037 		VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   2038 		{
   2039 			// allow execution of event during every stage of pipeline
   2040 			VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   2041 
   2042 			// record setting event
   2043 			vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
   2044 		}
   2045 
   2046 		// end recording of secondary buffers
   2047 		VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   2048 
   2049 		// execute secondary buffer
   2050 		vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get());
   2051 	}
   2052 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
   2053 
   2054 	// create fence to wait for execution of queue
   2055 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   2056 
   2057 	const VkSubmitInfo						submitInfo1				=
   2058 	{
   2059 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   2060 		DE_NULL,													// pNext
   2061 		0u,															// waitSemaphoreCount
   2062 		DE_NULL,													// pWaitSemaphores
   2063 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   2064 		1,															// commandBufferCount
   2065 		&primCmdBuf1.get(),											// pCommandBuffers
   2066 		0u,															// signalSemaphoreCount
   2067 		DE_NULL,													// pSignalSemaphores
   2068 	};
   2069 
   2070 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
   2071 
   2072 	// wait for end of execution of queue
   2073 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   2074 	VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   2075 
   2076 	// check if secondary buffer has been executed
   2077 	VkResult result = vk.getEventStatus(vkDevice,*event);
   2078 	if (result != VK_EVENT_SET)
   2079 		return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED");
   2080 
   2081 	// reset first primary buffer
   2082 	vk.resetCommandBuffer( *primCmdBuf1, 0u);
   2083 
   2084 	// reset event to allow receiving it again
   2085 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   2086 
   2087 	// record secondary command buffer again
   2088 	VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   2089 	{
   2090 		// allow execution of event during every stage of pipeline
   2091 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   2092 
   2093 		// record setting event
   2094 		vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
   2095 	}
   2096 	// end recording of secondary buffers
   2097 	VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   2098 
   2099 	// record second primary command buffer
   2100 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
   2101 	{
   2102 		// execute secondary buffer
   2103 		vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get());
   2104 	}
   2105 	// end recording
   2106 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
   2107 
   2108 	// submit second primary buffer, the secondary should be executed too
   2109 	const VkSubmitInfo						submitInfo2				=
   2110 	{
   2111 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   2112 		DE_NULL,													// pNext
   2113 		0u,															// waitSemaphoreCount
   2114 		DE_NULL,													// pWaitSemaphores
   2115 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   2116 		1,															// commandBufferCount
   2117 		&primCmdBuf2.get(),											// pCommandBuffers
   2118 		0u,															// signalSemaphoreCount
   2119 		DE_NULL,													// pSignalSemaphores
   2120 	};
   2121 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
   2122 
   2123 	// wait for end of execution of queue
   2124 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   2125 
   2126 	// check if secondary buffer has been executed
   2127 	result = vk.getEventStatus(vkDevice,*event);
   2128 	if (result != VK_EVENT_SET)
   2129 		return tcu::TestStatus::fail("oneTimeSubmitFlagSecondaryBufferTest FAILED");
   2130 	else
   2131 		return tcu::TestStatus::pass("oneTimeSubmitFlagSecondaryBufferTest succeeded");
   2132 }
   2133 
   2134 tcu::TestStatus renderPassContinueTest(Context& context)
   2135 {
   2136 	const DeviceInterface&					vkd						= context.getDeviceInterface();
   2137 	CommandBufferRenderPassTestEnvironment	env						(context, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
   2138 
   2139 	VkCommandBuffer							primaryCommandBuffer	= env.getPrimaryCommandBuffer();
   2140 	VkCommandBuffer							secondaryCommandBuffer	= env.getSecondaryCommandBuffer();
   2141 	const deUint32							clearColor[4]			= { 2, 47, 131, 211 };
   2142 
   2143 	const VkClearAttachment					clearAttachment			=
   2144 	{
   2145 		VK_IMAGE_ASPECT_COLOR_BIT,									// VkImageAspectFlags	aspectMask;
   2146 		0,															// deUint32				colorAttachment;
   2147 		makeClearValueColorU32(clearColor[0],
   2148 							   clearColor[1],
   2149 							   clearColor[2],
   2150 							   clearColor[3])						// VkClearValue			clearValue;
   2151 	};
   2152 
   2153 	const VkClearRect						clearRect				=
   2154 	{
   2155 		CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_AREA,	// VkRect2D	rect;
   2156 		0u,															// deUint32	baseArrayLayer;
   2157 		1u															// deUint32	layerCount;
   2158 	};
   2159 
   2160 	env.beginSecondaryCommandBuffer(VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
   2161 	vkd.cmdClearAttachments(secondaryCommandBuffer, 1, &clearAttachment, 1, &clearRect);
   2162 	VK_CHECK(vkd.endCommandBuffer(secondaryCommandBuffer));
   2163 
   2164 
   2165 	env.beginPrimaryCommandBuffer(0);
   2166 	env.beginRenderPass(VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
   2167 	vkd.cmdExecuteCommands(primaryCommandBuffer, 1, &secondaryCommandBuffer);
   2168 	vkd.cmdEndRenderPass(primaryCommandBuffer);
   2169 
   2170 	VK_CHECK(vkd.endCommandBuffer(primaryCommandBuffer));
   2171 
   2172 	env.submitPrimaryCommandBuffer();
   2173 
   2174 	de::MovePtr<tcu::TextureLevel>			result					= env.readColorAttachment();
   2175 	tcu::PixelBufferAccess					pixelBufferAccess		= result->getAccess();
   2176 
   2177 	for (deUint32 i = 0; i < (CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_SIZE.width * CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_SIZE.height); ++i)
   2178 	{
   2179 		deUint8* colorData = reinterpret_cast<deUint8*>(pixelBufferAccess.getDataPtr());
   2180 		for (int colorComponent = 0; colorComponent < 4; ++colorComponent)
   2181 			if (colorData[i * 4 + colorComponent] != clearColor[colorComponent])
   2182 				return tcu::TestStatus::fail("clear value mismatch");
   2183 	}
   2184 
   2185 	return tcu::TestStatus::pass("render pass continue test passed");
   2186 }
   2187 
   2188 tcu::TestStatus simultaneousUsePrimaryBufferTest(Context& context)
   2189 {
   2190 
   2191 	const VkDevice							vkDevice				= context.getDevice();
   2192 	const DeviceInterface&					vk						= context.getDeviceInterface();
   2193 	const VkQueue							queue					= context.getUniversalQueue();
   2194 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   2195 
   2196 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   2197 	{
   2198 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   2199 		DE_NULL,													//	const void*					pNext;
   2200 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   2201 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   2202 	};
   2203 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2204 
   2205 	// Command buffer
   2206 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   2207 	{
   2208 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType				sType;
   2209 		DE_NULL,													//	const void*					pNext;
   2210 		*cmdPool,													//	VkCommandPool				pool;
   2211 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   2212 		1u,															//	uint32_t					bufferCount;
   2213 	};
   2214 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   2215 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   2216 	{
   2217 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2218 		DE_NULL,
   2219 		VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,				// flags
   2220 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2221 	};
   2222 
   2223 	// create event that will be used to check if secondary command buffer has been executed
   2224 	const Unique<VkEvent>					eventOne				(createEvent(vk, vkDevice));
   2225 	const Unique<VkEvent>					eventTwo				(createEvent(vk, vkDevice));
   2226 
   2227 	// reset event
   2228 	VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
   2229 
   2230 	// record primary command buffer
   2231 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   2232 	{
   2233 		// wait for event
   2234 		vk.cmdWaitEvents(*primCmdBuf, 1u, &eventOne.get(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0u, DE_NULL, 0u, DE_NULL, 0u, DE_NULL);
   2235 
   2236 		// Set the second event
   2237 		vk.cmdSetEvent(*primCmdBuf, eventTwo.get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   2238 	}
   2239 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   2240 
   2241 	// create fence to wait for execution of queue
   2242 	const Unique<VkFence>					fence1					(createFence(vk, vkDevice));
   2243 	const Unique<VkFence>					fence2					(createFence(vk, vkDevice));
   2244 
   2245 
   2246 	const VkSubmitInfo						submitInfo				=
   2247 	{
   2248 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   2249 		DE_NULL,													// pNext
   2250 		0u,															// waitSemaphoreCount
   2251 		DE_NULL,													// pWaitSemaphores
   2252 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   2253 		1,															// commandBufferCount
   2254 		&primCmdBuf.get(),											// pCommandBuffers
   2255 		0u,															// signalSemaphoreCount
   2256 		DE_NULL,													// pSignalSemaphores
   2257 	};
   2258 
   2259 	// submit first buffer
   2260 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence1));
   2261 
   2262 	// submit second buffer
   2263 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence2));
   2264 
   2265 	// wait for both buffer to stop at event for 100 microseconds
   2266 	vk.waitForFences(vkDevice, 1, &fence1.get(), 0u, 100000);
   2267 	vk.waitForFences(vkDevice, 1, &fence2.get(), 0u, 100000);
   2268 
   2269 	// set event
   2270 	VK_CHECK(vk.setEvent(vkDevice, *eventOne));
   2271 
   2272 	// wait for end of execution of the first buffer
   2273 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence1.get(), 0u, INFINITE_TIMEOUT));
   2274 	// wait for end of execution of the second buffer
   2275 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence2.get(), 0u, INFINITE_TIMEOUT));
   2276 
   2277 	// TODO: this will be true if the command buffer was executed only once
   2278 	// TODO: add some test that will say if it was executed twice
   2279 
   2280 	// check if buffer has been executed
   2281 	VkResult result = vk.getEventStatus(vkDevice, *eventTwo);
   2282 	if (result == VK_EVENT_SET)
   2283 		return tcu::TestStatus::pass("simultaneous use - primary buffers test succeeded");
   2284 	else
   2285 		return tcu::TestStatus::fail("simultaneous use - primary buffers test FAILED");
   2286 }
   2287 
   2288 tcu::TestStatus simultaneousUseSecondaryBufferTest(Context& context)
   2289 {
   2290 	const VkDevice							vkDevice				= context.getDevice();
   2291 	const DeviceInterface&					vk						= context.getDeviceInterface();
   2292 	const VkQueue							queue					= context.getUniversalQueue();
   2293 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   2294 
   2295 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   2296 	{
   2297 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   2298 		DE_NULL,													//	const void*					pNext;
   2299 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   2300 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   2301 	};
   2302 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2303 
   2304 	// Command buffer
   2305 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   2306 	{
   2307 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   2308 		DE_NULL,													//	const void*				pNext;
   2309 		*cmdPool,													//	VkCommandPool				pool;
   2310 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   2311 		1u,															//	uint32_t					bufferCount;
   2312 	};
   2313 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   2314 
   2315 	// Secondary Command buffer params
   2316 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   2317 	{
   2318 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   2319 		DE_NULL,													//	const void*				pNext;
   2320 		*cmdPool,													//	VkCommandPool				pool;
   2321 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   2322 		1u,															//	uint32_t					bufferCount;
   2323 	};
   2324 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   2325 
   2326 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   2327 	{
   2328 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2329 		DE_NULL,
   2330 		0,															// flags
   2331 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2332 	};
   2333 
   2334 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   2335 	{
   2336 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   2337 		DE_NULL,
   2338 		(VkRenderPass)0u,											// renderPass
   2339 		0u,															// subpass
   2340 		(VkFramebuffer)0u,											// framebuffer
   2341 		VK_FALSE,													// occlusionQueryEnable
   2342 		(VkQueryControlFlags)0u,									// queryFlags
   2343 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   2344 	};
   2345 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo		=
   2346 	{
   2347 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2348 		DE_NULL,
   2349 		VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,				// flags
   2350 		&secCmdBufInheritInfo,
   2351 	};
   2352 
   2353 	// create event that will be used to check if secondary command buffer has been executed
   2354 	const Unique<VkEvent>					eventOne				(createEvent(vk, vkDevice));
   2355 	const Unique<VkEvent>					eventTwo				(createEvent(vk, vkDevice));
   2356 
   2357 	// reset event
   2358 	VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
   2359 	VK_CHECK(vk.resetEvent(vkDevice, *eventTwo));
   2360 
   2361 	// record secondary command buffer
   2362 	VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   2363 	{
   2364 		// allow execution of event during every stage of pipeline
   2365 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   2366 
   2367 		// wait for event
   2368 		vk.cmdWaitEvents(*secCmdBuf, 1, &eventOne.get(), stageMask, stageMask, 0, DE_NULL, 0u, DE_NULL, 0u, DE_NULL);
   2369 
   2370 		// reset event
   2371 		vk.cmdSetEvent(*secCmdBuf, *eventTwo, stageMask);
   2372 	}
   2373 	// end recording of secondary buffers
   2374 	VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   2375 
   2376 	// record primary command buffer
   2377 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   2378 	{
   2379 		// execute secondary buffer
   2380 		vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get());
   2381 	}
   2382 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   2383 
   2384 	// create fence to wait for execution of queue
   2385 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   2386 
   2387 	const VkSubmitInfo						submitInfo				=
   2388 	{
   2389 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   2390 		DE_NULL,													// pNext
   2391 		0u,															// waitSemaphoreCount
   2392 		DE_NULL,													// pWaitSemaphores
   2393 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   2394 		1,															// commandBufferCount
   2395 		&primCmdBuf.get(),											// pCommandBuffers
   2396 		0u,															// signalSemaphoreCount
   2397 		DE_NULL,													// pSignalSemaphores
   2398 	};
   2399 
   2400 	// submit primary buffer, the secondary should be executed too
   2401 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   2402 
   2403 	// wait for both buffers to stop at event for 100 microseconds
   2404 	vk.waitForFences(vkDevice, 1, &fence.get(), 0u, 100000);
   2405 
   2406 	// set event
   2407 	VK_CHECK(vk.setEvent(vkDevice, *eventOne));
   2408 
   2409 	// wait for end of execution of queue
   2410 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   2411 
   2412 	// TODO: this will be true if the command buffer was executed only once
   2413 	// TODO: add some test that will say if it was executed twice
   2414 
   2415 	// check if secondary buffer has been executed
   2416 	VkResult result = vk.getEventStatus(vkDevice,*eventTwo);
   2417 	if (result == VK_EVENT_SET)
   2418 		return tcu::TestStatus::pass("Simulatous Secondary Command Buffer Execution succeeded");
   2419 	else
   2420 		return tcu::TestStatus::fail("Simulatous Secondary Command Buffer Execution FAILED");
   2421 }
   2422 
   2423 tcu::TestStatus simultaneousUseSecondaryBufferOnePrimaryBufferTest(Context& context)
   2424 {
   2425 	const VkDevice							vkDevice = context.getDevice();
   2426 	const DeviceInterface&					vk = context.getDeviceInterface();
   2427 	const VkQueue							queue = context.getUniversalQueue();
   2428 	const deUint32							queueFamilyIndex = context.getUniversalQueueFamilyIndex();
   2429 	Allocator&								allocator = context.getDefaultAllocator();
   2430 	const ComputeInstanceResultBuffer		result(vk, vkDevice, allocator, 0.0f);
   2431 
   2432 	const VkCommandPoolCreateInfo			cmdPoolParams =
   2433 	{
   2434 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   2435 		DE_NULL,													//	const void*					pNext;
   2436 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   2437 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   2438 	};
   2439 	const Unique<VkCommandPool>				cmdPool(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2440 
   2441 	// Command buffer
   2442 	const VkCommandBufferAllocateInfo		cmdBufParams =
   2443 	{
   2444 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   2445 		DE_NULL,													//	const void*				pNext;
   2446 		*cmdPool,													//	VkCommandPool				pool;
   2447 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   2448 		1u,															//	uint32_t					bufferCount;
   2449 	};
   2450 	const Unique<VkCommandBuffer>			primCmdBuf(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   2451 
   2452 	// Secondary Command buffer params
   2453 	const VkCommandBufferAllocateInfo		secCmdBufParams =
   2454 	{
   2455 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   2456 		DE_NULL,													//	const void*				pNext;
   2457 		*cmdPool,													//	VkCommandPool				pool;
   2458 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   2459 		1u,															//	uint32_t					bufferCount;
   2460 	};
   2461 	const Unique<VkCommandBuffer>			secCmdBuf(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   2462 
   2463 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo =
   2464 	{
   2465 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2466 		DE_NULL,
   2467 		0,															// flags
   2468 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2469 	};
   2470 
   2471 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo =
   2472 	{
   2473 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   2474 		DE_NULL,
   2475 		(VkRenderPass)0u,
   2476 		0u,															// subpass
   2477 		(VkFramebuffer)0u,
   2478 		VK_FALSE,													// occlusionQueryEnable
   2479 		(VkQueryControlFlags)0u,
   2480 		(VkQueryPipelineStatisticFlags)0u,
   2481 	};
   2482 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo =
   2483 	{
   2484 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2485 		DE_NULL,
   2486 		VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,				// flags
   2487 		&secCmdBufInheritInfo,
   2488 	};
   2489 
   2490 	const deUint32							offset = (0u);
   2491 	const deUint32							addressableSize = 256;
   2492 	const deUint32							dataSize = 8;
   2493 	de::MovePtr<Allocation>					bufferMem;
   2494 	const Unique<VkBuffer>					buffer(createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem));
   2495 	// Secondary command buffer will have a compute shader that does an atomic increment to make sure that all instances of secondary buffers execute
   2496 	const Unique<VkDescriptorSetLayout>		descriptorSetLayout(createDescriptorSetLayout(context));
   2497 	const Unique<VkDescriptorPool>			descriptorPool(createDescriptorPool(context));
   2498 	const Unique<VkDescriptorSet>			descriptorSet(createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer()));
   2499 	const VkDescriptorSet					descriptorSets[] = { *descriptorSet };
   2500 	const int								numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets);
   2501 
   2502 	const VkPipelineLayoutCreateInfo layoutCreateInfo =
   2503 	{
   2504 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,				// sType
   2505 		DE_NULL,													// pNext
   2506 		(VkPipelineLayoutCreateFlags)0,
   2507 		numDescriptorSets,											// setLayoutCount
   2508 		&descriptorSetLayout.get(),									// pSetLayouts
   2509 		0u,															// pushConstantRangeCount
   2510 		DE_NULL,													// pPushConstantRanges
   2511 	};
   2512 	Unique<VkPipelineLayout>				pipelineLayout(createPipelineLayout(vk, vkDevice, &layoutCreateInfo));
   2513 
   2514 	const Unique<VkShaderModule>			computeModule(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("compute_increment"), (VkShaderModuleCreateFlags)0u));
   2515 
   2516 	const VkPipelineShaderStageCreateInfo	shaderCreateInfo =
   2517 	{
   2518 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
   2519 		DE_NULL,
   2520 		(VkPipelineShaderStageCreateFlags)0,
   2521 		VK_SHADER_STAGE_COMPUTE_BIT,								// stage
   2522 		*computeModule,												// shader
   2523 		"main",
   2524 		DE_NULL,													// pSpecializationInfo
   2525 	};
   2526 
   2527 	const VkComputePipelineCreateInfo		pipelineCreateInfo =
   2528 	{
   2529 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
   2530 		DE_NULL,
   2531 		0u,															// flags
   2532 		shaderCreateInfo,											// cs
   2533 		*pipelineLayout,											// layout
   2534 		(vk::VkPipeline)0,											// basePipelineHandle
   2535 		0u,															// basePipelineIndex
   2536 	};
   2537 
   2538 	const Unique<VkPipeline>				pipeline(createComputePipeline(vk, vkDevice, (VkPipelineCache)0u, &pipelineCreateInfo));
   2539 
   2540 	// record secondary command buffer
   2541 	VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   2542 	{
   2543 		vk.cmdBindPipeline(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
   2544 		vk.cmdBindDescriptorSets(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, 0, 0);
   2545 		vk.cmdDispatch(*secCmdBuf, 1u, 1u, 1u);
   2546 	}
   2547 	// end recording of secondary buffer
   2548 	VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   2549 
   2550 	// record primary command buffer
   2551 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   2552 	{
   2553 		// execute secondary buffer twice in same primary
   2554 		vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get());
   2555 		vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get());
   2556 	}
   2557 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   2558 
   2559 	// create fence to wait for execution of queue
   2560 	const Unique<VkFence>					fence(createFence(vk, vkDevice));
   2561 
   2562 	const VkSubmitInfo						submitInfo =
   2563 	{
   2564 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   2565 		DE_NULL,													// pNext
   2566 		0u,															// waitSemaphoreCount
   2567 		DE_NULL,													// pWaitSemaphores
   2568 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   2569 		1,															// commandBufferCount
   2570 		&primCmdBuf.get(),											// pCommandBuffers
   2571 		0u,															// signalSemaphoreCount
   2572 		DE_NULL,													// pSignalSemaphores
   2573 	};
   2574 
   2575 	// submit primary buffer, the secondary should be executed too
   2576 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   2577 
   2578 	// wait for end of execution of queue
   2579 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   2580 
   2581 	deUint32 resultCount;
   2582 	result.readResultContentsTo(&resultCount);
   2583 	// check if secondary buffer has been executed
   2584 	if (resultCount == 2)
   2585 		return tcu::TestStatus::pass("Simulatous Secondary Command Buffer Execution succeeded");
   2586 	else
   2587 		return tcu::TestStatus::fail("Simulatous Secondary Command Buffer Execution FAILED");
   2588 }
   2589 
   2590 tcu::TestStatus simultaneousUseSecondaryBufferTwoPrimaryBuffersTest(Context& context)
   2591 {
   2592 	const VkDevice							vkDevice = context.getDevice();
   2593 	const DeviceInterface&					vk = context.getDeviceInterface();
   2594 	const VkQueue							queue = context.getUniversalQueue();
   2595 	const deUint32							queueFamilyIndex = context.getUniversalQueueFamilyIndex();
   2596 	Allocator&								allocator = context.getDefaultAllocator();
   2597 	const ComputeInstanceResultBuffer		result(vk, vkDevice, allocator, 0.0f);
   2598 
   2599 	const VkCommandPoolCreateInfo			cmdPoolParams =
   2600 	{
   2601 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   2602 		DE_NULL,													//	const void*					pNext;
   2603 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   2604 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   2605 	};
   2606 	const Unique<VkCommandPool>				cmdPool(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2607 
   2608 	// Command buffer
   2609 	const VkCommandBufferAllocateInfo		cmdBufParams =
   2610 	{
   2611 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   2612 		DE_NULL,													//	const void*				pNext;
   2613 		*cmdPool,													//	VkCommandPool				pool;
   2614 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   2615 		1u,															//	uint32_t					bufferCount;
   2616 	};
   2617 	// Two separate primary cmd buffers that will be executed with the same secondary cmd buffer
   2618 	const deUint32 numPrimCmdBufs = 2;
   2619 	const Unique<VkCommandBuffer>			primCmdBufOne(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   2620 	const Unique<VkCommandBuffer>			primCmdBufTwo(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   2621 	VkCommandBuffer primCmdBufs[numPrimCmdBufs];
   2622 	primCmdBufs[0] = primCmdBufOne.get();
   2623 	primCmdBufs[1] = primCmdBufTwo.get();
   2624 
   2625 	// Secondary Command buffer params
   2626 	const VkCommandBufferAllocateInfo		secCmdBufParams =
   2627 	{
   2628 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   2629 		DE_NULL,													//	const void*				pNext;
   2630 		*cmdPool,													//	VkCommandPool				pool;
   2631 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   2632 		1u,															//	uint32_t					bufferCount;
   2633 	};
   2634 	const Unique<VkCommandBuffer>			secCmdBuf(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   2635 
   2636 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo =
   2637 	{
   2638 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2639 		DE_NULL,
   2640 		0,															// flags
   2641 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2642 	};
   2643 
   2644 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo =
   2645 	{
   2646 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   2647 		DE_NULL,
   2648 		(VkRenderPass)0u,											// renderPass
   2649 		0u,															// subpass
   2650 		(VkFramebuffer)0u,											// framebuffer
   2651 		VK_FALSE,													// occlusionQueryEnable
   2652 		(VkQueryControlFlags)0u,									// queryFlags
   2653 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   2654 	};
   2655 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo =
   2656 	{
   2657 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   2658 		DE_NULL,
   2659 		VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,				// flags
   2660 		&secCmdBufInheritInfo,
   2661 	};
   2662 
   2663 	const deUint32							offset = (0u);
   2664 	const deUint32							addressableSize = 256;
   2665 	const deUint32							dataSize = 8;
   2666 	de::MovePtr<Allocation>					bufferMem;
   2667 	const Unique<VkBuffer>					buffer(createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem));
   2668 	// Secondary command buffer will have a compute shader that does an atomic increment to make sure that all instances of secondary buffers execute
   2669 	const Unique<VkDescriptorSetLayout>		descriptorSetLayout(createDescriptorSetLayout(context));
   2670 	const Unique<VkDescriptorPool>			descriptorPool(createDescriptorPool(context));
   2671 	const Unique<VkDescriptorSet>			descriptorSet(createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer()));
   2672 	const VkDescriptorSet					descriptorSets[] = { *descriptorSet };
   2673 	const int								numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets);
   2674 
   2675 	const VkPipelineLayoutCreateInfo layoutCreateInfo =
   2676 	{
   2677 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,				// sType
   2678 		DE_NULL,													// pNext
   2679 		(VkPipelineLayoutCreateFlags)0,
   2680 		numDescriptorSets,											// setLayoutCount
   2681 		&descriptorSetLayout.get(),									// pSetLayouts
   2682 		0u,															// pushConstantRangeCount
   2683 		DE_NULL,													// pPushConstantRanges
   2684 	};
   2685 	Unique<VkPipelineLayout>				pipelineLayout(createPipelineLayout(vk, vkDevice, &layoutCreateInfo));
   2686 
   2687 	const Unique<VkShaderModule>			computeModule(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("compute_increment"), (VkShaderModuleCreateFlags)0u));
   2688 
   2689 	const VkPipelineShaderStageCreateInfo	shaderCreateInfo =
   2690 	{
   2691 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
   2692 		DE_NULL,
   2693 		(VkPipelineShaderStageCreateFlags)0,
   2694 		VK_SHADER_STAGE_COMPUTE_BIT,								// stage
   2695 		*computeModule,												// shader
   2696 		"main",
   2697 		DE_NULL,													// pSpecializationInfo
   2698 	};
   2699 
   2700 	const VkComputePipelineCreateInfo		pipelineCreateInfo =
   2701 	{
   2702 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
   2703 		DE_NULL,
   2704 		0u,															// flags
   2705 		shaderCreateInfo,											// cs
   2706 		*pipelineLayout,											// layout
   2707 		(vk::VkPipeline)0,											// basePipelineHandle
   2708 		0u,															// basePipelineIndex
   2709 	};
   2710 
   2711 	const Unique<VkPipeline>				pipeline(createComputePipeline(vk, vkDevice, (VkPipelineCache)0u, &pipelineCreateInfo));
   2712 
   2713 	// record secondary command buffer
   2714 	VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   2715 	{
   2716 		vk.cmdBindPipeline(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
   2717 		vk.cmdBindDescriptorSets(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, 0, 0);
   2718 		vk.cmdDispatch(*secCmdBuf, 1u, 1u, 1u);
   2719 	}
   2720 	// end recording of secondary buffer
   2721 	VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   2722 
   2723 	// record primary command buffers
   2724 	// Insert one instance of same secondary command buffer into two separate primary command buffers
   2725 	VK_CHECK(vk.beginCommandBuffer(*primCmdBufOne, &primCmdBufBeginInfo));
   2726 	{
   2727 		vk.cmdExecuteCommands(*primCmdBufOne, 1, &secCmdBuf.get());
   2728 	}
   2729 	VK_CHECK(vk.endCommandBuffer(*primCmdBufOne));
   2730 
   2731 	VK_CHECK(vk.beginCommandBuffer(*primCmdBufTwo, &primCmdBufBeginInfo));
   2732 	{
   2733 		vk.cmdExecuteCommands(*primCmdBufTwo, 1, &secCmdBuf.get());
   2734 	}
   2735 	VK_CHECK(vk.endCommandBuffer(*primCmdBufTwo));
   2736 
   2737 	// create fence to wait for execution of queue
   2738 	const Unique<VkFence>					fence(createFence(vk, vkDevice));
   2739 
   2740 	const VkSubmitInfo						submitInfo =
   2741 	{
   2742 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   2743 		DE_NULL,													// pNext
   2744 		0u,															// waitSemaphoreCount
   2745 		DE_NULL,													// pWaitSemaphores
   2746 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   2747 		numPrimCmdBufs,												// commandBufferCount
   2748 		primCmdBufs,												// pCommandBuffers
   2749 		0u,															// signalSemaphoreCount
   2750 		DE_NULL,													// pSignalSemaphores
   2751 	};
   2752 
   2753 	// submit primary buffers, the secondary should be executed too
   2754 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
   2755 
   2756 	// wait for end of execution of queue
   2757 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   2758 
   2759 	deUint32 resultCount;
   2760 	result.readResultContentsTo(&resultCount);
   2761 	// check if secondary buffer has been executed
   2762 	if (resultCount == 2)
   2763 		return tcu::TestStatus::pass("Simulatous Secondary Command Buffer Execution succeeded");
   2764 	else
   2765 		return tcu::TestStatus::fail("Simulatous Secondary Command Buffer Execution FAILED");
   2766 }
   2767 
   2768 tcu::TestStatus recordBufferQueryPreciseWithFlagTest(Context& context)
   2769 {
   2770 	const VkDevice							vkDevice				= context.getDevice();
   2771 	const DeviceInterface&					vk						= context.getDeviceInterface();
   2772 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   2773 
   2774 	if (!context.getDeviceFeatures().inheritedQueries)
   2775 		TCU_THROW(NotSupportedError, "Inherited queries feature is not supported");
   2776 
   2777 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   2778 	{
   2779 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   2780 		DE_NULL,													// pNext;
   2781 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
   2782 		queueFamilyIndex,											// queueFamilyIndex;
   2783 	};
   2784 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2785 
   2786 	// Command buffer
   2787 	const VkCommandBufferAllocateInfo		primCmdBufParams		=
   2788 	{
   2789 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   2790 		DE_NULL,													// pNext;
   2791 		*cmdPool,													// pool;
   2792 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   2793 		1u,															// flags;
   2794 	};
   2795 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
   2796 
   2797 	// Secondary Command buffer params
   2798 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   2799 	{
   2800 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   2801 		DE_NULL,													// pNext;
   2802 		*cmdPool,													// pool;
   2803 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							// level;
   2804 		1u,															// flags;
   2805 	};
   2806 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   2807 
   2808 	const VkCommandBufferBeginInfo			primBufferBeginInfo		=
   2809 	{
   2810 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   2811 		DE_NULL,													// pNext
   2812 		0u,															// flags
   2813 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2814 	};
   2815 
   2816 	const VkCommandBufferInheritanceInfo	secBufferInheritInfo	=
   2817 	{
   2818 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   2819 		DE_NULL,
   2820 		0u,															// renderPass
   2821 		0u,															// subpass
   2822 		0u,															// framebuffer
   2823 		VK_TRUE,													// occlusionQueryEnable
   2824 		VK_QUERY_CONTROL_PRECISE_BIT,								// queryFlags
   2825 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   2826 	};
   2827 	const VkCommandBufferBeginInfo			secBufferBeginInfo		=
   2828 	{
   2829 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   2830 		DE_NULL,													// pNext
   2831 		0u,															// flags
   2832 		&secBufferInheritInfo,
   2833 	};
   2834 
   2835 	const VkQueryPoolCreateInfo				queryPoolCreateInfo		=
   2836 	{
   2837 		VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,					// sType
   2838 		DE_NULL,													// pNext
   2839 		(VkQueryPoolCreateFlags)0,									// flags
   2840 		VK_QUERY_TYPE_OCCLUSION,									// queryType
   2841 		1u,															// entryCount
   2842 		0u,															// pipelineStatistics
   2843 	};
   2844 	Unique<VkQueryPool>						queryPool				(createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
   2845 
   2846 	VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
   2847 	VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
   2848 
   2849 	VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
   2850 	{
   2851 		vk.cmdResetQueryPool(primCmdBuf.get(), queryPool.get(), 0u, 1u);
   2852 		vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 0u, VK_QUERY_CONTROL_PRECISE_BIT);
   2853 		{
   2854 			vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
   2855 		}
   2856 		vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 0u);
   2857 	}
   2858 	VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
   2859 
   2860 	return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
   2861 }
   2862 
   2863 tcu::TestStatus recordBufferQueryImpreciseWithFlagTest(Context& context)
   2864 {
   2865 	const VkDevice							vkDevice				= context.getDevice();
   2866 	const DeviceInterface&					vk						= context.getDeviceInterface();
   2867 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   2868 
   2869 	if (!context.getDeviceFeatures().inheritedQueries)
   2870 		TCU_THROW(NotSupportedError, "Inherited queries feature is not supported");
   2871 
   2872 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   2873 	{
   2874 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   2875 		DE_NULL,													// pNext;
   2876 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
   2877 		queueFamilyIndex,											// queueFamilyIndex;
   2878 	};
   2879 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2880 
   2881 	// Command buffer
   2882 	const VkCommandBufferAllocateInfo		primCmdBufParams		=
   2883 	{
   2884 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   2885 		DE_NULL,													// pNext;
   2886 		*cmdPool,													// pool;
   2887 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   2888 		1u,															// flags;
   2889 	};
   2890 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
   2891 
   2892 	// Secondary Command buffer params
   2893 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   2894 	{
   2895 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   2896 		DE_NULL,													// pNext;
   2897 		*cmdPool,													// pool;
   2898 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							// level;
   2899 		1u,															// flags;
   2900 	};
   2901 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   2902 
   2903 	const VkCommandBufferBeginInfo			primBufferBeginInfo		=
   2904 	{
   2905 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   2906 		DE_NULL,													// pNext
   2907 		0u,															// flags
   2908 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   2909 	};
   2910 
   2911 	const VkCommandBufferInheritanceInfo	secBufferInheritInfo	=
   2912 	{
   2913 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   2914 		DE_NULL,
   2915 		0u,															// renderPass
   2916 		0u,															// subpass
   2917 		0u,															// framebuffer
   2918 		VK_TRUE,													// occlusionQueryEnable
   2919 		VK_QUERY_CONTROL_PRECISE_BIT,								// queryFlags
   2920 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   2921 	};
   2922 	const VkCommandBufferBeginInfo			secBufferBeginInfo		=
   2923 	{
   2924 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   2925 		DE_NULL,													// pNext
   2926 		0u,															// flags
   2927 		&secBufferInheritInfo,
   2928 	};
   2929 
   2930 	// Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
   2931 	const VkQueryPoolCreateInfo				queryPoolCreateInfo		=
   2932 	{
   2933 		VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,					// sType
   2934 		DE_NULL,													// pNext
   2935 		0u,															// flags
   2936 		VK_QUERY_TYPE_OCCLUSION,									// queryType
   2937 		1u,															// entryCount
   2938 		0u,															// pipelineStatistics
   2939 	};
   2940 	Unique<VkQueryPool>						queryPool				(createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
   2941 
   2942 	VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
   2943 	VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
   2944 
   2945 	VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
   2946 	{
   2947 		vk.cmdResetQueryPool(primCmdBuf.get(), queryPool.get(), 0u, 1u);
   2948 		vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 0u, VK_QUERY_CONTROL_PRECISE_BIT);
   2949 		{
   2950 			vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
   2951 		}
   2952 		vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 0u);
   2953 	}
   2954 	VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
   2955 
   2956 	return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
   2957 }
   2958 
   2959 tcu::TestStatus recordBufferQueryImpreciseWithoutFlagTest(Context& context)
   2960 {
   2961 	const VkDevice							vkDevice				= context.getDevice();
   2962 	const DeviceInterface&					vk						= context.getDeviceInterface();
   2963 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   2964 
   2965 	if (!context.getDeviceFeatures().inheritedQueries)
   2966 		TCU_THROW(NotSupportedError, "Inherited queries feature is not supported");
   2967 
   2968 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   2969 	{
   2970 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   2971 		DE_NULL,													// pNext;
   2972 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
   2973 		queueFamilyIndex,											// queueFamilyIndex;
   2974 	};
   2975 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   2976 
   2977 	// Command buffer
   2978 	const VkCommandBufferAllocateInfo		primCmdBufParams		=
   2979 	{
   2980 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   2981 		DE_NULL,													// pNext;
   2982 		*cmdPool,													// pool;
   2983 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   2984 		1u,															// flags;
   2985 	};
   2986 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
   2987 
   2988 	// Secondary Command buffer params
   2989 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   2990 	{
   2991 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   2992 		DE_NULL,													// pNext;
   2993 		*cmdPool,													// pool;
   2994 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							// level;
   2995 		1u,															// flags;
   2996 	};
   2997 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   2998 
   2999 	const VkCommandBufferBeginInfo			primBufferBeginInfo		=
   3000 	{
   3001 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3002 		DE_NULL,													// pNext
   3003 		0u,															// flags
   3004 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   3005 	};
   3006 
   3007 	const VkCommandBufferInheritanceInfo	secBufferInheritInfo	=
   3008 	{
   3009 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   3010 		DE_NULL,
   3011 		0u,															// renderPass
   3012 		0u,															// subpass
   3013 		0u,															// framebuffer
   3014 		VK_TRUE,													// occlusionQueryEnable
   3015 		0u,															// queryFlags
   3016 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   3017 	};
   3018 	const VkCommandBufferBeginInfo			secBufferBeginInfo		=
   3019 	{
   3020 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3021 		DE_NULL,													// pNext
   3022 		0u,															// flags
   3023 		&secBufferInheritInfo,
   3024 	};
   3025 
   3026 	// Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
   3027 	const VkQueryPoolCreateInfo				queryPoolCreateInfo		=
   3028 	{
   3029 		VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,					// sType
   3030 		DE_NULL,													// pNext
   3031 		(VkQueryPoolCreateFlags)0,
   3032 		VK_QUERY_TYPE_OCCLUSION,
   3033 		1u,
   3034 		0u,
   3035 	};
   3036 	Unique<VkQueryPool>						queryPool				(createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
   3037 
   3038 	VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
   3039 	VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
   3040 
   3041 	VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
   3042 	{
   3043 		vk.cmdResetQueryPool(primCmdBuf.get(), queryPool.get(), 0u, 1u);
   3044 		vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 0u, VK_QUERY_CONTROL_PRECISE_BIT);
   3045 		{
   3046 			vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
   3047 		}
   3048 		vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 0u);
   3049 	}
   3050 	VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
   3051 
   3052 	return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
   3053 }
   3054 
   3055 /******** 19.4. Command Buffer Submission (5.4 in VK 1.0 Spec) ****************/
   3056 tcu::TestStatus submitBufferCountNonZero(Context& context)
   3057 {
   3058 	const VkDevice							vkDevice				= context.getDevice();
   3059 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3060 	const VkQueue							queue					= context.getUniversalQueue();
   3061 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3062 
   3063 	const deUint32							BUFFER_COUNT			= 5u;
   3064 
   3065 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3066 	{
   3067 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   3068 		DE_NULL,													// pNext;
   3069 		0u,															// flags;
   3070 		queueFamilyIndex,											// queueFamilyIndex;
   3071 	};
   3072 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3073 
   3074 	// Command buffer
   3075 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3076 	{
   3077 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   3078 		DE_NULL,													// pNext;
   3079 		*cmdPool,													// pool;
   3080 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   3081 		BUFFER_COUNT,												// bufferCount;
   3082 	};
   3083 	VkCommandBuffer cmdBuffers[BUFFER_COUNT];
   3084 	VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
   3085 
   3086 	const VkCommandBufferBeginInfo			cmdBufBeginInfo			=
   3087 	{
   3088 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3089 		DE_NULL,													// pNext
   3090 		0u,															// flags
   3091 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   3092 	};
   3093 
   3094 	std::vector<VkEventSp>					events;
   3095 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3096 	{
   3097 		events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice))));
   3098 	}
   3099 
   3100 	// Record the command buffers
   3101 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3102 	{
   3103 		VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
   3104 		{
   3105 			vk.cmdSetEvent(cmdBuffers[ndx], events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   3106 		}
   3107 		VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
   3108 	}
   3109 
   3110 	// We'll use a fence to wait for the execution of the queue
   3111 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   3112 
   3113 	const VkSubmitInfo						submitInfo				=
   3114 	{
   3115 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3116 		DE_NULL,													// pNext
   3117 		0u,															// waitSemaphoreCount
   3118 		DE_NULL,													// pWaitSemaphores
   3119 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3120 		BUFFER_COUNT,												// commandBufferCount
   3121 		cmdBuffers,													// pCommandBuffers
   3122 		0u,															// signalSemaphoreCount
   3123 		DE_NULL,													// pSignalSemaphores
   3124 	};
   3125 
   3126 	// Submit the alpha command buffer to the queue
   3127 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
   3128 	// Wait for the queue
   3129 	VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT));
   3130 
   3131 	// Check if the buffers were executed
   3132 	tcu::TestStatus testResult = tcu::TestStatus::incomplete();
   3133 
   3134 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3135 	{
   3136 		if (vk.getEventStatus(vkDevice, events[ndx]->get()) != VK_EVENT_SET)
   3137 		{
   3138 			testResult = tcu::TestStatus::fail("Failed to set the event.");
   3139 			break;
   3140 		}
   3141 	}
   3142 
   3143 	if (!testResult.isComplete())
   3144 		testResult = tcu::TestStatus::pass("All buffers were submitted and executed correctly.");
   3145 
   3146 	return testResult;
   3147 }
   3148 
   3149 tcu::TestStatus submitBufferCountEqualZero(Context& context)
   3150 {
   3151 	const VkDevice							vkDevice				= context.getDevice();
   3152 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3153 	const VkQueue							queue					= context.getUniversalQueue();
   3154 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3155 
   3156 	const deUint32							BUFFER_COUNT			= 2u;
   3157 
   3158 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3159 	{
   3160 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   3161 		DE_NULL,													// pNext;
   3162 		0u,															// flags;
   3163 		queueFamilyIndex,											// queueFamilyIndex;
   3164 	};
   3165 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3166 
   3167 	// Command buffer
   3168 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3169 	{
   3170 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   3171 		DE_NULL,													// pNext;
   3172 		*cmdPool,													// pool;
   3173 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   3174 		BUFFER_COUNT,												// bufferCount;
   3175 	};
   3176 	VkCommandBuffer cmdBuffers[BUFFER_COUNT];
   3177 	VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
   3178 
   3179 	const VkCommandBufferBeginInfo			cmdBufBeginInfo			=
   3180 	{
   3181 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3182 		DE_NULL,													// pNext
   3183 		0u,															// flags
   3184 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   3185 	};
   3186 
   3187 	std::vector<VkEventSp>					events;
   3188 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3189 		events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice))));
   3190 
   3191 	// Record the command buffers
   3192 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3193 	{
   3194 		VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
   3195 		{
   3196 			vk.cmdSetEvent(cmdBuffers[ndx], events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   3197 		}
   3198 		VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
   3199 	}
   3200 
   3201 	// We'll use a fence to wait for the execution of the queue
   3202 	const Unique<VkFence>					fenceZero				(createFence(vk, vkDevice));
   3203 	const Unique<VkFence>					fenceOne				(createFence(vk, vkDevice));
   3204 
   3205 	const VkSubmitInfo						submitInfoCountZero		=
   3206 	{
   3207 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3208 		DE_NULL,													// pNext
   3209 		0u,															// waitSemaphoreCount
   3210 		DE_NULL,													// pWaitSemaphores
   3211 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3212 		1u,															// commandBufferCount
   3213 		&cmdBuffers[0],												// pCommandBuffers
   3214 		0u,															// signalSemaphoreCount
   3215 		DE_NULL,													// pSignalSemaphores
   3216 	};
   3217 
   3218 	const VkSubmitInfo						submitInfoCountOne		=
   3219 	{
   3220 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3221 		DE_NULL,													// pNext
   3222 		0u,															// waitSemaphoreCount
   3223 		DE_NULL,													// pWaitSemaphores
   3224 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3225 		1u,															// commandBufferCount
   3226 		&cmdBuffers[1],												// pCommandBuffers
   3227 		0u,															// signalSemaphoreCount
   3228 		DE_NULL,													// pSignalSemaphores
   3229 	};
   3230 
   3231 	// Submit the command buffers to the queue
   3232 	// We're performing two submits to make sure that the first one has
   3233 	// a chance to be processed before we check the event's status
   3234 	VK_CHECK(vk.queueSubmit(queue, 0, &submitInfoCountZero, fenceZero.get()));
   3235 	VK_CHECK(vk.queueSubmit(queue, 1, &submitInfoCountOne, fenceOne.get()));
   3236 
   3237 	const VkFence							fences[]				=
   3238 	{
   3239 		fenceZero.get(),
   3240 		fenceOne.get(),
   3241 	};
   3242 
   3243 	// Wait for the queue
   3244 	VK_CHECK(vk.waitForFences(vkDevice, (deUint32)DE_LENGTH_OF_ARRAY(fences), fences, VK_TRUE, INFINITE_TIMEOUT));
   3245 
   3246 	// Check if the first buffer was executed
   3247 	tcu::TestStatus testResult = tcu::TestStatus::incomplete();
   3248 
   3249 	if (vk.getEventStatus(vkDevice, events[0]->get()) == VK_EVENT_SET)
   3250 		testResult = tcu::TestStatus::fail("The first event was signaled.");
   3251 	else
   3252 		testResult = tcu::TestStatus::pass("The first submission was ignored.");
   3253 
   3254 	return testResult;
   3255 }
   3256 
   3257 tcu::TestStatus submitBufferWaitSingleSemaphore(Context& context)
   3258 {
   3259 	const VkDevice							vkDevice				= context.getDevice();
   3260 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3261 	const VkQueue							queue					= context.getUniversalQueue();
   3262 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3263 
   3264 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3265 	{
   3266 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// VkStructureType				sType;
   3267 		DE_NULL,													// const void*					pNext;
   3268 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// VkCommandPoolCreateFlags		flags;
   3269 		queueFamilyIndex,											// deUint32						queueFamilyIndex;
   3270 	};
   3271 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3272 
   3273 	// Command buffer
   3274 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3275 	{
   3276 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// VkStructureType				sType;
   3277 		DE_NULL,													// const void*					pNext;
   3278 		*cmdPool,													// VkCommandPool				pool;
   3279 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// VkCommandBufferLevel			level;
   3280 		1u,															// uint32_t						bufferCount;
   3281 	};
   3282 
   3283 	// Create two command buffers
   3284 	const Unique<VkCommandBuffer>			primCmdBuf1				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   3285 	const Unique<VkCommandBuffer>			primCmdBuf2				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   3286 
   3287 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   3288 	{
   3289 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3290 		DE_NULL,													// pNext
   3291 		0,															// flags
   3292 		DE_NULL														// const VkCommandBufferInheritanceInfo*	pInheritanceInfo;
   3293 	};
   3294 
   3295 	// create two events that will be used to check if command buffers has been executed
   3296 	const Unique<VkEvent>					event1					(createEvent(vk, vkDevice));
   3297 	const Unique<VkEvent>					event2					(createEvent(vk, vkDevice));
   3298 
   3299 	// reset events
   3300 	VK_CHECK(vk.resetEvent(vkDevice, *event1));
   3301 	VK_CHECK(vk.resetEvent(vkDevice, *event2));
   3302 
   3303 	// record first command buffer
   3304 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
   3305 	{
   3306 		// allow execution of event during every stage of pipeline
   3307 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   3308 
   3309 		// record setting event
   3310 		vk.cmdSetEvent(*primCmdBuf1, *event1,stageMask);
   3311 	}
   3312 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
   3313 
   3314 	// record second command buffer
   3315 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
   3316 	{
   3317 		// allow execution of event during every stage of pipeline
   3318 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   3319 
   3320 		// record setting event
   3321 		vk.cmdSetEvent(*primCmdBuf2, *event2,stageMask);
   3322 	}
   3323 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
   3324 
   3325 	// create fence to wait for execution of queue
   3326 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   3327 
   3328 	// create semaphore for use in this test
   3329 	const Unique <VkSemaphore>				semaphore				(createSemaphore(vk, vkDevice));
   3330 
   3331 	// create submit info for first buffer - signalling semaphore
   3332 	const VkSubmitInfo						submitInfo1				=
   3333 	{
   3334 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3335 		DE_NULL,													// pNext
   3336 		0u,															// waitSemaphoreCount
   3337 		DE_NULL,													// pWaitSemaphores
   3338 		DE_NULL,													// pWaitDstStageMask
   3339 		1,															// commandBufferCount
   3340 		&primCmdBuf1.get(),											// pCommandBuffers
   3341 		1u,															// signalSemaphoreCount
   3342 		&semaphore.get(),											// pSignalSemaphores
   3343 	};
   3344 
   3345 	// Submit the command buffer to the queue
   3346 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
   3347 
   3348 	// wait for end of execution of queue
   3349 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   3350 
   3351 	// check if buffer has been executed
   3352 	VkResult result = vk.getEventStatus(vkDevice,*event1);
   3353 	if (result != VK_EVENT_SET)
   3354 		return tcu::TestStatus::fail("Submit Buffer and Wait for Single Semaphore Test FAILED");
   3355 
   3356 	const VkPipelineStageFlags				waitDstStageFlags		= VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
   3357 
   3358 	// create submit info for second buffer - waiting for semaphore
   3359 	const VkSubmitInfo						submitInfo2				=
   3360 	{
   3361 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3362 		DE_NULL,													// pNext
   3363 		1u,															// waitSemaphoreCount
   3364 		&semaphore.get(),											// pWaitSemaphores
   3365 		&waitDstStageFlags,											// pWaitDstStageMask
   3366 		1,															// commandBufferCount
   3367 		&primCmdBuf2.get(),											// pCommandBuffers
   3368 		0u,															// signalSemaphoreCount
   3369 		DE_NULL,													// pSignalSemaphores
   3370 	};
   3371 
   3372 	// reset fence, so it can be used again
   3373 	VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   3374 
   3375 	// Submit the second command buffer to the queue
   3376 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
   3377 
   3378 	// wait for end of execution of queue
   3379 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   3380 
   3381 	// check if second buffer has been executed
   3382 	// if it has been executed, it means that the semaphore was signalled - so test if passed
   3383 	result = vk.getEventStatus(vkDevice,*event1);
   3384 	if (result != VK_EVENT_SET)
   3385 		return tcu::TestStatus::fail("Submit Buffer and Wait for Single Semaphore Test FAILED");
   3386 
   3387 	return tcu::TestStatus::pass("Submit Buffer and Wait for Single Semaphore Test succeeded");
   3388 }
   3389 
   3390 tcu::TestStatus submitBufferWaitManySemaphores(Context& context)
   3391 {
   3392 	// This test will create numSemaphores semaphores, and signal them in NUM_SEMAPHORES submits to queue
   3393 	// After that the numSubmissions queue submissions will wait for each semaphore
   3394 
   3395 	const deUint32							numSemaphores			= 10u;  // it must be multiply of numSubmission
   3396 	const deUint32							numSubmissions			= 2u;
   3397 	const VkDevice							vkDevice				= context.getDevice();
   3398 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3399 	const VkQueue							queue					= context.getUniversalQueue();
   3400 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3401 
   3402 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3403 	{
   3404 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// VkStructureType				sType;
   3405 		DE_NULL,													// const void*					pNext;
   3406 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// VkCommandPoolCreateFlags		flags;
   3407 		queueFamilyIndex,											// deUint32						queueFamilyIndex;
   3408 	};
   3409 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3410 
   3411 	// Command buffer
   3412 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3413 	{
   3414 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// VkStructureType				sType;
   3415 		DE_NULL,													// const void*					pNext;
   3416 		*cmdPool,													// VkCommandPool				pool;
   3417 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// VkCommandBufferLevel			level;
   3418 		1u,															// uint32_t						bufferCount;
   3419 	};
   3420 
   3421 	// Create command buffer
   3422 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   3423 
   3424 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   3425 	{
   3426 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3427 		DE_NULL,													// pNext
   3428 		0,															// flags
   3429 		DE_NULL														// const VkCommandBufferInheritanceInfo*	pInheritanceInfo;
   3430 	};
   3431 
   3432 	// create event that will be used to check if command buffers has been executed
   3433 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   3434 
   3435 	// reset event - at creation state is undefined
   3436 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   3437 
   3438 	// record command buffer
   3439 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   3440 	{
   3441 		// allow execution of event during every stage of pipeline
   3442 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   3443 
   3444 		// record setting event
   3445 		vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
   3446 	}
   3447 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   3448 
   3449 	// create fence to wait for execution of queue
   3450 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   3451 
   3452 	// numSemaphores is declared const, so this array can be static
   3453 	// the semaphores will be destroyed automatically at end of scope
   3454 	Move <VkSemaphore>						semaphoreArray[numSemaphores];
   3455 	VkSemaphore								semaphores[numSemaphores];
   3456 
   3457 	for (deUint32 idx = 0; idx < numSemaphores; ++idx) {
   3458 		// create semaphores for use in this test
   3459 		semaphoreArray[idx] = createSemaphore(vk, vkDevice);
   3460 		semaphores[idx] = semaphoreArray[idx].get();
   3461 	};
   3462 
   3463 	{
   3464 		// create submit info for buffer - signal semaphores
   3465 		const VkSubmitInfo submitInfo1 =
   3466 		{
   3467 			VK_STRUCTURE_TYPE_SUBMIT_INFO,							// sType
   3468 			DE_NULL,												// pNext
   3469 			0u,														// waitSemaphoreCount
   3470 			DE_NULL,												// pWaitSemaphores
   3471 			DE_NULL,												// pWaitDstStageMask
   3472 			1,														// commandBufferCount
   3473 			&primCmdBuf.get(),										// pCommandBuffers
   3474 			numSemaphores,											// signalSemaphoreCount
   3475 			semaphores												// pSignalSemaphores
   3476 		};
   3477 		// Submit the command buffer to the queue
   3478 		VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
   3479 
   3480 		// wait for end of execution of queue
   3481 		VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   3482 
   3483 		// check if buffer has been executed
   3484 		VkResult result = vk.getEventStatus(vkDevice,*event);
   3485 		if (result != VK_EVENT_SET)
   3486 			return tcu::TestStatus::fail("Submit Buffer and Wait for Many Semaphores Test FAILED");
   3487 
   3488 		// reset event, so next buffers can set it again
   3489 		VK_CHECK(vk.resetEvent(vkDevice, *event));
   3490 
   3491 		// reset fence, so it can be used again
   3492 		VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   3493 	}
   3494 
   3495 	const deUint32							numberOfSemaphoresToBeWaitedByOneSubmission	= numSemaphores / numSubmissions;
   3496 	const std::vector<VkPipelineStageFlags>	waitDstStageFlags							(numberOfSemaphoresToBeWaitedByOneSubmission, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
   3497 
   3498 	// the following code waits for the semaphores set above - numSubmissions queues will wait for each semaphore from above
   3499 	for (deUint32 idxSubmission = 0; idxSubmission < numSubmissions; ++idxSubmission) {
   3500 
   3501 		// create submit info for buffer - waiting for semaphore
   3502 		const VkSubmitInfo				submitInfo2				=
   3503 		{
   3504 			VK_STRUCTURE_TYPE_SUBMIT_INFO,												// sType
   3505 			DE_NULL,																	// pNext
   3506 			numberOfSemaphoresToBeWaitedByOneSubmission,								// waitSemaphoreCount
   3507 			semaphores + (numberOfSemaphoresToBeWaitedByOneSubmission * idxSubmission),	// pWaitSemaphores
   3508 			waitDstStageFlags.data(),													// pWaitDstStageMask
   3509 			1,																			// commandBufferCount
   3510 			&primCmdBuf.get(),															// pCommandBuffers
   3511 			0u,																			// signalSemaphoreCount
   3512 			DE_NULL,																	// pSignalSemaphores
   3513 		};
   3514 
   3515 		// Submit the second command buffer to the queue
   3516 		VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
   3517 
   3518 		// wait for 1 second.
   3519 		VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, 1000 * 1000 * 1000));
   3520 
   3521 		// check if second buffer has been executed
   3522 		// if it has been executed, it means that the semaphore was signalled - so test if passed
   3523 		VkResult result = vk.getEventStatus(vkDevice,*event);
   3524 		if (result != VK_EVENT_SET)
   3525 			return tcu::TestStatus::fail("Submit Buffer and Wait for Many Semaphores Test FAILED");
   3526 
   3527 		// reset fence, so it can be used again
   3528 		VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
   3529 
   3530 		// reset event, so next buffers can set it again
   3531 		VK_CHECK(vk.resetEvent(vkDevice, *event));
   3532 	}
   3533 
   3534 	return tcu::TestStatus::pass("Submit Buffer and Wait for Many Semaphores Test succeeded");
   3535 }
   3536 
   3537 tcu::TestStatus submitBufferNullFence(Context& context)
   3538 {
   3539 	const VkDevice							vkDevice				= context.getDevice();
   3540 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3541 	const VkQueue							queue					= context.getUniversalQueue();
   3542 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3543 
   3544 	const short								BUFFER_COUNT			= 2;
   3545 
   3546 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3547 	{
   3548 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   3549 		DE_NULL,													// pNext;
   3550 		0u,															// flags;
   3551 		queueFamilyIndex,											// queueFamilyIndex;
   3552 	};
   3553 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3554 
   3555 	// Command buffer
   3556 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3557 	{
   3558 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   3559 		DE_NULL,													// pNext;
   3560 		*cmdPool,													// pool;
   3561 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   3562 		1u,															// bufferCount;
   3563 	};
   3564 	VkCommandBuffer cmdBuffers[BUFFER_COUNT];
   3565 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3566 		VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffers[ndx]));
   3567 
   3568 	const VkCommandBufferBeginInfo			cmdBufBeginInfo			=
   3569 	{
   3570 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3571 		DE_NULL,													// pNext
   3572 		0u,															// flags
   3573 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   3574 	};
   3575 
   3576 	std::vector<VkEventSp>					events;
   3577 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3578 		events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice))));
   3579 
   3580 	// Record the command buffers
   3581 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3582 	{
   3583 		VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
   3584 		{
   3585 			vk.cmdSetEvent(cmdBuffers[ndx], events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
   3586 		}
   3587 		VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
   3588 	}
   3589 
   3590 	// We'll use a fence to wait for the execution of the queue
   3591 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   3592 
   3593 	const VkSubmitInfo						submitInfoNullFence		=
   3594 	{
   3595 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3596 		DE_NULL,													// pNext
   3597 		0u,															// waitSemaphoreCount
   3598 		DE_NULL,													// pWaitSemaphores
   3599 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3600 		1u,															// commandBufferCount
   3601 		&cmdBuffers[0],												// pCommandBuffers
   3602 		0u,															// signalSemaphoreCount
   3603 		DE_NULL,													// pSignalSemaphores
   3604 	};
   3605 
   3606 	const VkSubmitInfo						submitInfoNonNullFence	=
   3607 	{
   3608 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3609 		DE_NULL,													// pNext
   3610 		0u,															// waitSemaphoreCount
   3611 		DE_NULL,													// pWaitSemaphores
   3612 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3613 		1u,															// commandBufferCount
   3614 		&cmdBuffers[1],												// pCommandBuffers
   3615 		0u,															// signalSemaphoreCount
   3616 		DE_NULL,													// pSignalSemaphores
   3617 	};
   3618 
   3619 	// Perform two submissions - one with no fence, the other one with a valid
   3620 	// fence Hoping submitting the other buffer will give the first one time to
   3621 	// execute
   3622 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNullFence, DE_NULL));
   3623 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNonNullFence, fence.get()));
   3624 
   3625 	// Wait for the queue
   3626 	VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT));
   3627 
   3628 
   3629 	tcu::TestStatus testResult = tcu::TestStatus::incomplete();
   3630 
   3631 	//Fence guaranteed that all buffers submited before fence were executed
   3632 	if (vk.getEventStatus(vkDevice, events[0]->get()) != VK_EVENT_SET || vk.getEventStatus(vkDevice, events[1]->get()) != VK_EVENT_SET)
   3633 	{
   3634 		testResult = tcu::TestStatus::fail("One of the buffers was not executed.");
   3635 	}
   3636 	else
   3637 	{
   3638 		testResult = tcu::TestStatus::pass("Buffers have been submitted and executed correctly.");
   3639 	}
   3640 
   3641 	vk.queueWaitIdle(queue);
   3642 	return testResult;
   3643 }
   3644 
   3645 /******** 19.5. Secondary Command Buffer Execution (5.6 in VK 1.0 Spec) *******/
   3646 tcu::TestStatus executeSecondaryBufferTest(Context& context)
   3647 {
   3648 	const VkDevice							vkDevice				= context.getDevice();
   3649 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3650 	const VkQueue							queue					= context.getUniversalQueue();
   3651 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3652 
   3653 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3654 	{
   3655 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   3656 		DE_NULL,													// pNext;
   3657 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			// flags;
   3658 		queueFamilyIndex,											// queueFamilyIndex;
   3659 	};
   3660 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3661 
   3662 	// Command buffer
   3663 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3664 	{
   3665 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   3666 		DE_NULL,													// pNext;
   3667 		*cmdPool,													// commandPool;
   3668 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level;
   3669 		1u,															// bufferCount;
   3670 	};
   3671 	const Unique<VkCommandBuffer>			primCmdBuf				(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   3672 
   3673 	// Secondary Command buffer
   3674 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   3675 	{
   3676 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType;
   3677 		DE_NULL,													// pNext;
   3678 		*cmdPool,													// commandPool;
   3679 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							// level;
   3680 		1u,															// bufferCount;
   3681 	};
   3682 	const Unique<VkCommandBuffer>			secCmdBuf				(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
   3683 
   3684 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   3685 	{
   3686 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3687 		DE_NULL,													// pNext
   3688 		0u,															// flags
   3689 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   3690 	};
   3691 
   3692 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   3693 	{
   3694 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   3695 		DE_NULL,
   3696 		DE_NULL,													// renderPass
   3697 		0u,															// subpass
   3698 		DE_NULL,													// framebuffer
   3699 		VK_FALSE,													// occlusionQueryEnable
   3700 		(VkQueryControlFlags)0u,									// queryFlags
   3701 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   3702 	};
   3703 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo		=
   3704 	{
   3705 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   3706 		DE_NULL,													// pNext
   3707 		0u,															// flags
   3708 		&secCmdBufInheritInfo,
   3709 	};
   3710 
   3711 	// create event that will be used to check if secondary command buffer has been executed
   3712 	const Unique<VkEvent>					event					(createEvent(vk, vkDevice));
   3713 
   3714 	// reset event
   3715 	VK_CHECK(vk.resetEvent(vkDevice, *event));
   3716 
   3717 	// record secondary command buffer
   3718 	VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
   3719 	{
   3720 		// allow execution of event during every stage of pipeline
   3721 		VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   3722 		// record setting event
   3723 		vk.cmdSetEvent(*secCmdBuf, *event, stageMask);
   3724 	}
   3725 	// end recording of the secondary buffer
   3726 	VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
   3727 
   3728 	// record primary command buffer
   3729 	VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
   3730 	{
   3731 		// execute secondary buffer
   3732 		vk.cmdExecuteCommands(*primCmdBuf, 1u, &secCmdBuf.get());
   3733 	}
   3734 	VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
   3735 
   3736 	// create fence to wait for execution of queue
   3737 	const Unique<VkFence>					fence					(createFence(vk, vkDevice));
   3738 	const VkSubmitInfo						submitInfo				=
   3739 	{
   3740 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3741 		DE_NULL,													// pNext
   3742 		0u,															// waitSemaphoreCount
   3743 		DE_NULL,													// pWaitSemaphores
   3744 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3745 		1u,															// commandBufferCount
   3746 		&primCmdBuf.get(),											// pCommandBuffers
   3747 		0u,															// signalSemaphoreCount
   3748 		DE_NULL,													// pSignalSemaphores
   3749 	};
   3750 
   3751 	// submit primary buffer, the secondary should be executed too
   3752 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
   3753 
   3754 	// wait for end of execution of queue
   3755 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
   3756 
   3757 	// check if secondary buffer has been executed
   3758 	VkResult result = vk.getEventStatus(vkDevice, *event);
   3759 	if (result == VK_EVENT_SET)
   3760 		return tcu::TestStatus::pass("executeSecondaryBufferTest succeeded");
   3761 
   3762 	return tcu::TestStatus::fail("executeSecondaryBufferTest FAILED");
   3763 }
   3764 
   3765 tcu::TestStatus executeSecondaryBufferTwiceTest(Context& context)
   3766 {
   3767 	const deUint32							BUFFER_COUNT			= 10u;
   3768 	const VkDevice							vkDevice				= context.getDevice();
   3769 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3770 	const VkQueue							queue					= context.getUniversalQueue();
   3771 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3772 
   3773 	const VkCommandPoolCreateInfo			cmdPoolParams			=
   3774 	{
   3775 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					//	VkStructureType				sType;
   3776 		DE_NULL,													//	const void*					pNext;
   3777 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,			//	VkCommandPoolCreateFlags	flags;
   3778 		queueFamilyIndex,											//	deUint32					queueFamilyIndex;
   3779 	};
   3780 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, vkDevice, &cmdPoolParams));
   3781 
   3782 	// Command buffer
   3783 	const VkCommandBufferAllocateInfo		cmdBufParams			=
   3784 	{
   3785 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   3786 		DE_NULL,													//	const void*				pNext;
   3787 		*cmdPool,													//	VkCommandPool				pool;
   3788 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							//	VkCommandBufferLevel		level;
   3789 		1u,															//	uint32_t					bufferCount;
   3790 	};
   3791 	const Unique<VkCommandBuffer>			primCmdBufOne			(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   3792 	const Unique<VkCommandBuffer>			primCmdBufTwo			(allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
   3793 
   3794 	// Secondary Command buffers params
   3795 	const VkCommandBufferAllocateInfo		secCmdBufParams			=
   3796 	{
   3797 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				//	VkStructureType			sType;
   3798 		DE_NULL,													//	const void*				pNext;
   3799 		*cmdPool,													//	VkCommandPool				pool;
   3800 		VK_COMMAND_BUFFER_LEVEL_SECONDARY,							//	VkCommandBufferLevel		level;
   3801 		BUFFER_COUNT,												//	uint32_t					bufferCount;
   3802 	};
   3803 	VkCommandBuffer cmdBuffers[BUFFER_COUNT];
   3804 	VK_CHECK(vk.allocateCommandBuffers(vkDevice, &secCmdBufParams, cmdBuffers));
   3805 
   3806 	const VkCommandBufferBeginInfo			primCmdBufBeginInfo		=
   3807 	{
   3808 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   3809 		DE_NULL,
   3810 		0,															// flags
   3811 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   3812 	};
   3813 
   3814 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
   3815 	{
   3816 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
   3817 		DE_NULL,
   3818 		(VkRenderPass)0u,											// renderPass
   3819 		0u,															// subpass
   3820 		(VkFramebuffer)0u,											// framebuffer
   3821 		VK_FALSE,													// occlusionQueryEnable
   3822 		(VkQueryControlFlags)0u,									// queryFlags
   3823 		(VkQueryPipelineStatisticFlags)0u,							// pipelineStatistics
   3824 	};
   3825 	const VkCommandBufferBeginInfo			secCmdBufBeginInfo		=
   3826 	{
   3827 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
   3828 		DE_NULL,
   3829 		VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,				// flags
   3830 		&secCmdBufInheritInfo,
   3831 	};
   3832 
   3833 	// create event that will be used to check if secondary command buffer has been executed
   3834 	const Unique<VkEvent>					eventOne				(createEvent(vk, vkDevice));
   3835 
   3836 	// reset event
   3837 	VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
   3838 
   3839 	for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
   3840 	{
   3841 		// record secondary command buffer
   3842 		VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &secCmdBufBeginInfo));
   3843 		{
   3844 			// allow execution of event during every stage of pipeline
   3845 			VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
   3846 
   3847 			// wait for event
   3848 			vk.cmdWaitEvents(cmdBuffers[ndx], 1, &eventOne.get(), stageMask, stageMask, 0, DE_NULL, 0u, DE_NULL, 0u, DE_NULL);
   3849 		}
   3850 		// end recording of secondary buffers
   3851 		VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
   3852 	};
   3853 
   3854 	// record primary command buffer one
   3855 	VK_CHECK(vk.beginCommandBuffer(*primCmdBufOne, &primCmdBufBeginInfo));
   3856 	{
   3857 		// execute one secondary buffer
   3858 		vk.cmdExecuteCommands(*primCmdBufOne, 1, cmdBuffers );
   3859 	}
   3860 	VK_CHECK(vk.endCommandBuffer(*primCmdBufOne));
   3861 
   3862 	// record primary command buffer two
   3863 	VK_CHECK(vk.beginCommandBuffer(*primCmdBufTwo, &primCmdBufBeginInfo));
   3864 	{
   3865 		// execute one secondary buffer with all buffers
   3866 		vk.cmdExecuteCommands(*primCmdBufTwo, BUFFER_COUNT, cmdBuffers );
   3867 	}
   3868 	VK_CHECK(vk.endCommandBuffer(*primCmdBufTwo));
   3869 
   3870 	// create fence to wait for execution of queue
   3871 	const Unique<VkFence>					fenceOne				(createFence(vk, vkDevice));
   3872 	const Unique<VkFence>					fenceTwo				(createFence(vk, vkDevice));
   3873 
   3874 	const VkSubmitInfo						submitInfoOne			=
   3875 	{
   3876 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3877 		DE_NULL,													// pNext
   3878 		0u,															// waitSemaphoreCount
   3879 		DE_NULL,													// pWaitSemaphores
   3880 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3881 		1,															// commandBufferCount
   3882 		&primCmdBufOne.get(),										// pCommandBuffers
   3883 		0u,															// signalSemaphoreCount
   3884 		DE_NULL,													// pSignalSemaphores
   3885 	};
   3886 
   3887 	// submit primary buffer, the secondary should be executed too
   3888 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoOne, *fenceOne));
   3889 
   3890 	// wait for buffer to stop at event for 100 microseconds
   3891 	vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, 100000);
   3892 
   3893 	const VkSubmitInfo						submitInfoTwo			=
   3894 	{
   3895 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   3896 		DE_NULL,													// pNext
   3897 		0u,															// waitSemaphoreCount
   3898 		DE_NULL,													// pWaitSemaphores
   3899 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   3900 		1,															// commandBufferCount
   3901 		&primCmdBufTwo.get(),										// pCommandBuffers
   3902 		0u,															// signalSemaphoreCount
   3903 		DE_NULL,													// pSignalSemaphores
   3904 	};
   3905 
   3906 	// submit second primary buffer, the secondary should be executed too
   3907 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoTwo, *fenceTwo));
   3908 
   3909 	// wait for all buffers to stop at event for 100 microseconds
   3910 	vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, 100000);
   3911 
   3912 	// now all buffers are waiting at eventOne
   3913 	// set event eventOne
   3914 	VK_CHECK(vk.setEvent(vkDevice, *eventOne));
   3915 
   3916 	// wait for end of execution of fenceOne
   3917 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, INFINITE_TIMEOUT));
   3918 
   3919 	// wait for end of execution of second queue
   3920 	VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceTwo.get(), 0u, INFINITE_TIMEOUT));
   3921 
   3922 	return tcu::TestStatus::pass("executeSecondaryBufferTwiceTest succeeded");
   3923 }
   3924 
   3925 /******** 19.6. Commands Allowed Inside Command Buffers (? in VK 1.0 Spec) **/
   3926 tcu::TestStatus orderBindPipelineTest(Context& context)
   3927 {
   3928 	const DeviceInterface&					vk						= context.getDeviceInterface();
   3929 	const VkDevice							device					= context.getDevice();
   3930 	const VkQueue							queue					= context.getUniversalQueue();
   3931 	const deUint32							queueFamilyIndex		= context.getUniversalQueueFamilyIndex();
   3932 	Allocator&								allocator				= context.getDefaultAllocator();
   3933 	const ComputeInstanceResultBuffer		result					(vk, device, allocator);
   3934 
   3935 	enum
   3936 	{
   3937 		ADDRESSABLE_SIZE = 256, // allocate a lot more than required
   3938 	};
   3939 
   3940 	const tcu::Vec4							colorA1					= tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
   3941 	const tcu::Vec4							colorA2					= tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
   3942 	const tcu::Vec4							colorB1					= tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
   3943 	const tcu::Vec4							colorB2					= tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
   3944 
   3945 	const deUint32							dataOffsetA				= (0u);
   3946 	const deUint32							dataOffsetB				= (0u);
   3947 	const deUint32							viewOffsetA				= (0u);
   3948 	const deUint32							viewOffsetB				= (0u);
   3949 	const deUint32							bufferSizeA				= dataOffsetA + ADDRESSABLE_SIZE;
   3950 	const deUint32							bufferSizeB				= dataOffsetB + ADDRESSABLE_SIZE;
   3951 
   3952 	de::MovePtr<Allocation>					bufferMemA;
   3953 	const Unique<VkBuffer>					bufferA					(createColorDataBuffer(dataOffsetA, bufferSizeA, colorA1, colorA2, &bufferMemA, context));
   3954 
   3955 	de::MovePtr<Allocation>					bufferMemB;
   3956 	const Unique<VkBuffer>					bufferB					(createColorDataBuffer(dataOffsetB, bufferSizeB, colorB1, colorB2, &bufferMemB, context));
   3957 
   3958 	const Unique<VkDescriptorSetLayout>		descriptorSetLayout		(createDescriptorSetLayout(context));
   3959 	const Unique<VkDescriptorPool>			descriptorPool			(createDescriptorPool(context));
   3960 	const Unique<VkDescriptorSet>			descriptorSet			(createDescriptorSet(*descriptorPool, *descriptorSetLayout, *bufferA, viewOffsetA, *bufferB, viewOffsetB, result.getBuffer(), context));
   3961 	const VkDescriptorSet					descriptorSets[]		= { *descriptorSet };
   3962 	const int								numDescriptorSets		= DE_LENGTH_OF_ARRAY(descriptorSets);
   3963 
   3964 	const VkPipelineLayoutCreateInfo layoutCreateInfo =
   3965 	{
   3966 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,				// sType
   3967 		DE_NULL,													// pNext
   3968 		(VkPipelineLayoutCreateFlags)0,
   3969 		numDescriptorSets,											// setLayoutCount
   3970 		&descriptorSetLayout.get(),									// pSetLayouts
   3971 		0u,															// pushConstantRangeCount
   3972 		DE_NULL,													// pPushConstantRanges
   3973 	};
   3974 	Unique<VkPipelineLayout>				pipelineLayout			(createPipelineLayout(vk, device, &layoutCreateInfo));
   3975 
   3976 	const Unique<VkShaderModule>			computeModuleGood		(createShaderModule(vk, device, context.getBinaryCollection().get("compute_good"), (VkShaderModuleCreateFlags)0u));
   3977 	const Unique<VkShaderModule>			computeModuleBad		(createShaderModule(vk, device, context.getBinaryCollection().get("compute_bad"),  (VkShaderModuleCreateFlags)0u));
   3978 
   3979 	const VkPipelineShaderStageCreateInfo	shaderCreateInfoGood	=
   3980 	{
   3981 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
   3982 		DE_NULL,
   3983 		(VkPipelineShaderStageCreateFlags)0,
   3984 		VK_SHADER_STAGE_COMPUTE_BIT,								// stage
   3985 		*computeModuleGood,											// shader
   3986 		"main",
   3987 		DE_NULL,													// pSpecializationInfo
   3988 	};
   3989 
   3990 	const VkPipelineShaderStageCreateInfo	shaderCreateInfoBad	=
   3991 	{
   3992 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
   3993 		DE_NULL,
   3994 		(vk::VkPipelineShaderStageCreateFlags)0,
   3995 		vk::VK_SHADER_STAGE_COMPUTE_BIT,							// stage
   3996 		*computeModuleBad,											// shader
   3997 		"main",
   3998 		DE_NULL,													// pSpecializationInfo
   3999 	};
   4000 
   4001 	const VkComputePipelineCreateInfo		createInfoGood			=
   4002 	{
   4003 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
   4004 		DE_NULL,
   4005 		0u,															// flags
   4006 		shaderCreateInfoGood,										// cs
   4007 		*pipelineLayout,											// layout
   4008 		(vk::VkPipeline)0,											// basePipelineHandle
   4009 		0u,															// basePipelineIndex
   4010 	};
   4011 
   4012 	const VkComputePipelineCreateInfo		createInfoBad			=
   4013 	{
   4014 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
   4015 		DE_NULL,
   4016 		0u,															// flags
   4017 		shaderCreateInfoBad,										// cs
   4018 		*pipelineLayout,											// descriptorSetLayout.get()
   4019 		(VkPipeline)0,												// basePipelineHandle
   4020 		0u,															// basePipelineIndex
   4021 	};
   4022 
   4023 	const Unique<VkPipeline>				pipelineGood			(createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoGood));
   4024 	const Unique<VkPipeline>				pipelineBad				(createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoBad));
   4025 
   4026 	const VkAccessFlags						inputBit				= (VK_ACCESS_UNIFORM_READ_BIT);
   4027 	const VkBufferMemoryBarrier				bufferBarriers[]		=
   4028 	{
   4029 		{
   4030 			VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
   4031 			DE_NULL,
   4032 			VK_ACCESS_HOST_WRITE_BIT,									// outputMask
   4033 			inputBit,													// inputMask
   4034 			VK_QUEUE_FAMILY_IGNORED,									// srcQueueFamilyIndex
   4035 			VK_QUEUE_FAMILY_IGNORED,									// destQueueFamilyIndex
   4036 			*bufferA,													// buffer
   4037 			(VkDeviceSize)0u,											// offset
   4038 			(VkDeviceSize)bufferSizeA,									// size
   4039 		},
   4040 		{
   4041 			VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
   4042 			DE_NULL,
   4043 			VK_ACCESS_HOST_WRITE_BIT,									// outputMask
   4044 			inputBit,													// inputMask
   4045 			VK_QUEUE_FAMILY_IGNORED,									// srcQueueFamilyIndex
   4046 			VK_QUEUE_FAMILY_IGNORED,									// destQueueFamilyIndex
   4047 			*bufferB,													// buffer
   4048 			(VkDeviceSize)0u,											// offset
   4049 			(VkDeviceSize)bufferSizeB,									// size
   4050 		}
   4051 	};
   4052 
   4053 	const deUint32							numSrcBuffers			= 1u;
   4054 
   4055 	const deUint32* const					dynamicOffsets			= (DE_NULL);
   4056 	const deUint32							numDynamicOffsets		= (0);
   4057 	const int								numPreBarriers			= numSrcBuffers;
   4058 	const vk::VkBufferMemoryBarrier* const	postBarriers			= result.getResultReadBarrier();
   4059 	const int								numPostBarriers			= 1;
   4060 	const tcu::Vec4							refQuadrantValue14		= (colorA2);
   4061 	const tcu::Vec4							refQuadrantValue23		= (colorA1);
   4062 	const tcu::Vec4							references[4]			=
   4063 	{
   4064 		refQuadrantValue14,
   4065 		refQuadrantValue23,
   4066 		refQuadrantValue23,
   4067 		refQuadrantValue14,
   4068 	};
   4069 	tcu::Vec4								results[4];
   4070 
   4071 	// submit and wait begin
   4072 
   4073 	const tcu::UVec3 numWorkGroups = tcu::UVec3(4, 1u, 1);
   4074 
   4075 	const VkCommandPoolCreateInfo			cmdPoolCreateInfo		=
   4076 	{
   4077 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// sType;
   4078 		DE_NULL,													// pNext
   4079 		VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,						// flags
   4080 		queueFamilyIndex,											// queueFamilyIndex
   4081 	};
   4082 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, device, &cmdPoolCreateInfo));
   4083 	const VkCommandBufferAllocateInfo		cmdBufCreateInfo		=
   4084 	{
   4085 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// sType
   4086 		DE_NULL,													// pNext
   4087 		*cmdPool,													// commandPool
   4088 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// level
   4089 		1u,															// bufferCount;
   4090 	};
   4091 
   4092 	const VkCommandBufferBeginInfo			cmdBufBeginInfo			=
   4093 	{
   4094 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,				// sType
   4095 		DE_NULL,													// pNext
   4096 		0u,															// flags
   4097 		(const VkCommandBufferInheritanceInfo*)DE_NULL,
   4098 	};
   4099 
   4100 	const Unique<VkFence>					cmdCompleteFence		(createFence(vk, device));
   4101 	const Unique<VkCommandBuffer>			cmd						(allocateCommandBuffer(vk, device, &cmdBufCreateInfo));
   4102 
   4103 	VK_CHECK(vk.beginCommandBuffer(*cmd, &cmdBufBeginInfo));
   4104 
   4105 	vk.cmdBindPipeline(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineBad);
   4106 	vk.cmdBindPipeline(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineGood);
   4107 	vk.cmdBindDescriptorSets(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, numDynamicOffsets, dynamicOffsets);
   4108 
   4109 	if (numPreBarriers)
   4110 		vk.cmdPipelineBarrier(*cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0,
   4111 							  0, (const VkMemoryBarrier*)DE_NULL,
   4112 							  numPreBarriers, bufferBarriers,
   4113 							  0, (const VkImageMemoryBarrier*)DE_NULL);
   4114 
   4115 	vk.cmdDispatch(*cmd, numWorkGroups.x(), numWorkGroups.y(), numWorkGroups.z());
   4116 	vk.cmdPipelineBarrier(*cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0,
   4117 						  0, (const VkMemoryBarrier*)DE_NULL,
   4118 						  numPostBarriers, postBarriers,
   4119 						  0, (const VkImageMemoryBarrier*)DE_NULL);
   4120 	VK_CHECK(vk.endCommandBuffer(*cmd));
   4121 
   4122 	// run
   4123 	// submit second primary buffer, the secondary should be executed too
   4124 	const VkSubmitInfo						submitInfo				=
   4125 	{
   4126 		VK_STRUCTURE_TYPE_SUBMIT_INFO,								// sType
   4127 		DE_NULL,													// pNext
   4128 		0u,															// waitSemaphoreCount
   4129 		DE_NULL,													// pWaitSemaphores
   4130 		(const VkPipelineStageFlags*)DE_NULL,						// pWaitDstStageMask
   4131 		1,															// commandBufferCount
   4132 		&cmd.get(),													// pCommandBuffers
   4133 		0u,															// signalSemaphoreCount
   4134 		DE_NULL,													// pSignalSemaphores
   4135 	};
   4136 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *cmdCompleteFence));
   4137 
   4138 	VK_CHECK(vk.waitForFences(device, 1u, &cmdCompleteFence.get(), 0u, INFINITE_TIMEOUT)); // \note: timeout is failure
   4139 	VK_CHECK(vk.resetFences(device, 1u, &cmdCompleteFence.get()));
   4140 
   4141 	// submit and wait end
   4142 	result.readResultContentsTo(&results);
   4143 
   4144 	// verify
   4145 	if (results[0] == references[0] &&
   4146 		results[1] == references[1] &&
   4147 		results[2] == references[2] &&
   4148 		results[3] == references[3])
   4149 	{
   4150 		return tcu::TestStatus::pass("Pass");
   4151 	}
   4152 	else if (results[0] == tcu::Vec4(-1.0f) &&
   4153 			 results[1] == tcu::Vec4(-1.0f) &&
   4154 			 results[2] == tcu::Vec4(-1.0f) &&
   4155 			 results[3] == tcu::Vec4(-1.0f))
   4156 	{
   4157 		context.getTestContext().getLog()
   4158 		<< tcu::TestLog::Message
   4159 		<< "Result buffer was not written to."
   4160 		<< tcu::TestLog::EndMessage;
   4161 		return tcu::TestStatus::fail("Result buffer was not written to");
   4162 	}
   4163 	else
   4164 	{
   4165 		context.getTestContext().getLog()
   4166 		<< tcu::TestLog::Message
   4167 		<< "Error expected ["
   4168 		<< references[0] << ", "
   4169 		<< references[1] << ", "
   4170 		<< references[2] << ", "
   4171 		<< references[3] << "], got ["
   4172 		<< results[0] << ", "
   4173 		<< results[1] << ", "
   4174 		<< results[2] << ", "
   4175 		<< results[3] << "]"
   4176 		<< tcu::TestLog::EndMessage;
   4177 		return tcu::TestStatus::fail("Invalid result values");
   4178 	}
   4179 }
   4180 
   4181 // Shaders
   4182 void genComputeSource (SourceCollections& programCollection)
   4183 {
   4184 	const char* const						versionDecl				= glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
   4185 	std::ostringstream						bufGood;
   4186 
   4187 	bufGood << versionDecl << "\n"
   4188 	<< ""
   4189 	<< "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1u) in;\n"
   4190 	<< "layout(set = 0, binding = 1u, std140) uniform BufferName\n"
   4191 	<< "{\n"
   4192 	<< "	highp vec4 colorA;\n"
   4193 	<< "	highp vec4 colorB;\n"
   4194 	<< "} b_instance;\n"
   4195 	<< "layout(set = 0, binding = 0, std140) writeonly buffer OutBuf\n"
   4196 	<< "{\n"
   4197 	<< "	highp vec4 read_colors[4];\n"
   4198 	<< "} b_out;\n"
   4199 	<< "void main(void)\n"
   4200 	<< "{\n"
   4201 	<< "	highp int quadrant_id = int(gl_WorkGroupID.x);\n"
   4202 	<< "	highp vec4 result_color;\n"
   4203 	<< "	if (quadrant_id == 1 || quadrant_id == 2)\n"
   4204 	<< "		result_color = b_instance.colorA;\n"
   4205 	<< "	else\n"
   4206 	<< "		result_color = b_instance.colorB;\n"
   4207 	<< "	b_out.read_colors[gl_WorkGroupID.x] = result_color;\n"
   4208 	<< "}\n";
   4209 
   4210 	programCollection.glslSources.add("compute_good") << glu::ComputeSource(bufGood.str());
   4211 
   4212 	std::ostringstream	bufBad;
   4213 
   4214 	bufBad	<< versionDecl << "\n"
   4215 	<< ""
   4216 	<< "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1u) in;\n"
   4217 	<< "layout(set = 0, binding = 1u, std140) uniform BufferName\n"
   4218 	<< "{\n"
   4219 	<< "	highp vec4 colorA;\n"
   4220 	<< "	highp vec4 colorB;\n"
   4221 	<< "} b_instance;\n"
   4222 	<< "layout(set = 0, binding = 0, std140) writeonly buffer OutBuf\n"
   4223 	<< "{\n"
   4224 	<< "	highp vec4 read_colors[4];\n"
   4225 	<< "} b_out;\n"
   4226 	<< "void main(void)\n"
   4227 	<< "{\n"
   4228 	<< "	highp int quadrant_id = int(gl_WorkGroupID.x);\n"
   4229 	<< "	highp vec4 result_color;\n"
   4230 	<< "	if (quadrant_id == 1 || quadrant_id == 2)\n"
   4231 	<< "		result_color = b_instance.colorA;\n"
   4232 	<< "	else\n"
   4233 	<< "		result_color = b_instance.colorB;\n"
   4234 	<< "	b_out.read_colors[gl_WorkGroupID.x] = vec4(0.0, 0.0, 0.0, 0.0);\n"
   4235 	<< "}\n";
   4236 
   4237 	programCollection.glslSources.add("compute_bad") << glu::ComputeSource(bufBad.str());
   4238 }
   4239 
   4240 void genComputeIncrementSource (SourceCollections& programCollection)
   4241 {
   4242 	const char* const						versionDecl = glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
   4243 	std::ostringstream						bufIncrement;
   4244 
   4245 	bufIncrement << versionDecl << "\n"
   4246 		<< ""
   4247 		<< "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1u) in;\n"
   4248 		<< "layout(set = 0, binding = 0, std140) buffer InOutBuf\n"
   4249 		<< "{\n"
   4250 		<< "    coherent uint count;\n"
   4251 		<< "} b_in_out;\n"
   4252 		<< "void main(void)\n"
   4253 		<< "{\n"
   4254 		<< "	atomicAdd(b_in_out.count, 1u);\n"
   4255 		<< "}\n";
   4256 
   4257 	programCollection.glslSources.add("compute_increment") << glu::ComputeSource(bufIncrement.str());
   4258 }
   4259 
   4260 } // anonymous
   4261 
   4262 tcu::TestCaseGroup* createCommandBuffersTests (tcu::TestContext& testCtx)
   4263 {
   4264 	de::MovePtr<tcu::TestCaseGroup>	commandBuffersTests	(new tcu::TestCaseGroup(testCtx, "command_buffers", "Command Buffers Tests"));
   4265 
   4266 	/* 19.1. Command Pools (5.1 in VK 1.0 Spec) */
   4267 	addFunctionCase				(commandBuffersTests.get(), "pool_create_null_params",			"",	createPoolNullParamsTest);
   4268 	addFunctionCase				(commandBuffersTests.get(), "pool_create_non_null_allocator",	"",	createPoolNonNullAllocatorTest);
   4269 	addFunctionCase				(commandBuffersTests.get(), "pool_create_transient_bit",		"",	createPoolTransientBitTest);
   4270 	addFunctionCase				(commandBuffersTests.get(), "pool_create_reset_bit",			"",	createPoolResetBitTest);
   4271 	addFunctionCase				(commandBuffersTests.get(), "pool_reset_release_res",			"",	resetPoolReleaseResourcesBitTest);
   4272 	addFunctionCase				(commandBuffersTests.get(), "pool_reset_no_flags_res",			"",	resetPoolNoFlagsTest);
   4273 	addFunctionCase				(commandBuffersTests.get(), "pool_reset_reuse",					"",	resetPoolReuseTest);
   4274 	/* 19.2. Command Buffer Lifetime (5.2 in VK 1.0 Spec) */
   4275 	addFunctionCase				(commandBuffersTests.get(), "allocate_single_primary",			"", allocatePrimaryBufferTest);
   4276 	addFunctionCase				(commandBuffersTests.get(), "allocate_many_primary",			"",	allocateManyPrimaryBuffersTest);
   4277 	addFunctionCase				(commandBuffersTests.get(), "allocate_single_secondary",		"", allocateSecondaryBufferTest);
   4278 	addFunctionCase				(commandBuffersTests.get(), "allocate_many_secondary",			"", allocateManySecondaryBuffersTest);
   4279 	addFunctionCase				(commandBuffersTests.get(), "execute_small_primary",			"",	executePrimaryBufferTest);
   4280 	addFunctionCase				(commandBuffersTests.get(), "execute_large_primary",			"",	executeLargePrimaryBufferTest);
   4281 	addFunctionCase				(commandBuffersTests.get(), "reset_implicit",					"", resetBufferImplicitlyTest);
   4282 	addFunctionCase				(commandBuffersTests.get(), "trim_command_pool",				"", trimCommandPoolTest, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
   4283 	addFunctionCase				(commandBuffersTests.get(), "trim_command_pool_secondary",		"", trimCommandPoolTest, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
   4284 	/* 19.3. Command Buffer Recording (5.3 in VK 1.0 Spec) */
   4285 	addFunctionCase				(commandBuffersTests.get(), "record_single_primary",			"",	recordSinglePrimaryBufferTest);
   4286 	addFunctionCase				(commandBuffersTests.get(), "record_many_primary",				"", recordLargePrimaryBufferTest);
   4287 	addFunctionCase				(commandBuffersTests.get(), "record_single_secondary",			"",	recordSingleSecondaryBufferTest);
   4288 	addFunctionCase				(commandBuffersTests.get(), "record_many_secondary",			"", recordLargeSecondaryBufferTest);
   4289 	addFunctionCase				(commandBuffersTests.get(), "submit_twice_primary",				"",	submitPrimaryBufferTwiceTest);
   4290 	addFunctionCase				(commandBuffersTests.get(), "submit_twice_secondary",			"",	submitSecondaryBufferTwiceTest);
   4291 	addFunctionCase				(commandBuffersTests.get(), "record_one_time_submit_primary",	"",	oneTimeSubmitFlagPrimaryBufferTest);
   4292 	addFunctionCase				(commandBuffersTests.get(), "record_one_time_submit_secondary",	"",	oneTimeSubmitFlagSecondaryBufferTest);
   4293 	addFunctionCase				(commandBuffersTests.get(), "render_pass_continue",				"",	renderPassContinueTest);
   4294 	addFunctionCase				(commandBuffersTests.get(), "record_simul_use_primary",			"",	simultaneousUsePrimaryBufferTest);
   4295 	addFunctionCase				(commandBuffersTests.get(), "record_simul_use_secondary",		"",	simultaneousUseSecondaryBufferTest);
   4296 	addFunctionCaseWithPrograms (commandBuffersTests.get(), "record_simul_use_secondary_one_primary", "", genComputeIncrementSource, simultaneousUseSecondaryBufferOnePrimaryBufferTest);
   4297 	addFunctionCaseWithPrograms (commandBuffersTests.get(), "record_simul_use_secondary_two_primary", "", genComputeIncrementSource, simultaneousUseSecondaryBufferTwoPrimaryBuffersTest);
   4298 	addFunctionCase				(commandBuffersTests.get(), "record_query_precise_w_flag",		"",	recordBufferQueryPreciseWithFlagTest);
   4299 	addFunctionCase				(commandBuffersTests.get(), "record_query_imprecise_w_flag",	"",	recordBufferQueryImpreciseWithFlagTest);
   4300 	addFunctionCase				(commandBuffersTests.get(), "record_query_imprecise_wo_flag",	"",	recordBufferQueryImpreciseWithoutFlagTest);
   4301 	/* 19.4. Command Buffer Submission (5.4 in VK 1.0 Spec) */
   4302 	addFunctionCase				(commandBuffersTests.get(), "submit_count_non_zero",			"", submitBufferCountNonZero);
   4303 	addFunctionCase				(commandBuffersTests.get(), "submit_count_equal_zero",			"", submitBufferCountEqualZero);
   4304 	addFunctionCase				(commandBuffersTests.get(), "submit_wait_single_semaphore",		"", submitBufferWaitSingleSemaphore);
   4305 	addFunctionCase				(commandBuffersTests.get(), "submit_wait_many_semaphores",		"", submitBufferWaitManySemaphores);
   4306 	addFunctionCase				(commandBuffersTests.get(), "submit_null_fence",				"", submitBufferNullFence);
   4307 	/* 19.5. Secondary Command Buffer Execution (5.6 in VK 1.0 Spec) */
   4308 	addFunctionCase				(commandBuffersTests.get(), "secondary_execute",				"",	executeSecondaryBufferTest);
   4309 	addFunctionCase				(commandBuffersTests.get(), "secondary_execute_twice",			"",	executeSecondaryBufferTwiceTest);
   4310 	/* 19.6. Commands Allowed Inside Command Buffers (? in VK 1.0 Spec) */
   4311 	addFunctionCaseWithPrograms (commandBuffersTests.get(), "order_bind_pipeline",				"", genComputeSource, orderBindPipelineTest);
   4312 
   4313 	return commandBuffersTests.release();
   4314 }
   4315 
   4316 } // api
   4317 } // vkt
   4318 
   4319