Tests for pipeline laoyut early destroy

Added tests that use the created graphics pipeline after destroying
the pipeline layout used to create them.

New tests:
dEQP-VK.pipeline.early_destroy.no_cache_destroy_layout
dEQP-VK.pipeline.early_destroy.cache_destroy_layout

Affects:
dEQP-VK.pipeline.early_destroy.*

Components: Vulkan

VK-GL-CTS issue: 2362

Change-Id: Ib296b2834ea7c31891532e5c8e7102f30acc000f
diff --git a/android/cts/master/vk-master-2020-03-01.txt b/android/cts/master/vk-master-2020-03-01.txt
index 2453689..db99e7e 100644
--- a/android/cts/master/vk-master-2020-03-01.txt
+++ b/android/cts/master/vk-master-2020-03-01.txt
@@ -122591,6 +122591,8 @@
 dEQP-VK.pipeline.dynamic_offset.compute.arrays.storage_buffer.numcmdbuffers_2.sameorder.numdescriptorsetbindings_1.numdynamicbindings_1.numnondynamicbindings_1
 dEQP-VK.pipeline.dynamic_offset.compute.arrays.storage_buffer.numcmdbuffers_2.sameorder.numdescriptorsetbindings_1.numdynamicbindings_2.numnondynamicbindings_0
 dEQP-VK.pipeline.dynamic_offset.compute.arrays.storage_buffer.numcmdbuffers_2.sameorder.numdescriptorsetbindings_1.numdynamicbindings_2.numnondynamicbindings_1
+dEQP-VK.pipeline.early_destroy.cache_destroy_layout
+dEQP-VK.pipeline.early_destroy.no_cache_destroy_layout
 dEQP-VK.pipeline.image.suballocation.sampling_type.combined.view_type.1d.format.a2b10g10r10_unorm_pack32.count_1.size.1x1
 dEQP-VK.pipeline.image.suballocation.sampling_type.combined.view_type.1d.format.a2b10g10r10_unorm_pack32.count_1.size.2x1
 dEQP-VK.pipeline.image.suballocation.sampling_type.combined.view_type.1d.format.a2b10g10r10_unorm_pack32.count_1.size.32x1
diff --git a/android/cts/master/vk-master.txt b/android/cts/master/vk-master.txt
index 5604037..6a73f81 100644
--- a/android/cts/master/vk-master.txt
+++ b/android/cts/master/vk-master.txt
Binary files differ
diff --git a/external/vulkancts/modules/vulkan/pipeline/vktPipelineEarlyDestroyTests.cpp b/external/vulkancts/modules/vulkan/pipeline/vktPipelineEarlyDestroyTests.cpp
index 5a03e95..007613d 100644
--- a/external/vulkancts/modules/vulkan/pipeline/vktPipelineEarlyDestroyTests.cpp
+++ b/external/vulkancts/modules/vulkan/pipeline/vktPipelineEarlyDestroyTests.cpp
@@ -31,6 +31,11 @@
 #include "vkRefUtil.hpp"
 #include "vkObjUtil.hpp"
 #include "deUniquePtr.hpp"
+#include "tcuTexture.hpp"
+#include "vkImageUtil.hpp"
+#include "vkImageWithMemory.hpp"
+#include "vkBufferWithMemory.hpp"
+#include "vkCmdUtil.hpp"
 
 namespace vkt
 {
@@ -69,169 +74,270 @@
 		"}\n");
 }
 
-tcu::TestStatus testEarlyDestroy (Context& context, bool usePipelineCache)
+tcu::TestStatus testEarlyDestroy (Context& context, bool usePipelineCache, bool destroyLayout)
 {
-	const DeviceInterface&							vk								= context.getDeviceInterface();
-	const VkDevice									vkDevice						= context.getDevice();
-	const Unique<VkShaderModule>					vertexShaderModule				(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_vert"), 0));
-	const Unique<VkShaderModule>					fragmentShaderModule			(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_frag"), 0));
+	const DeviceInterface&								vk							    = context.getDeviceInterface();
+	const VkDevice										vkDevice						= context.getDevice();
+	const Unique<VkShaderModule>						vertexShaderModule				(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_vert"), 0));
+	const Unique<VkShaderModule>						fragmentShaderModule			(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_frag"), 0));
 
-	const Unique<VkCommandPool>						cmdPool							(createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, context.getUniversalQueueFamilyIndex()));
-	const Unique<VkCommandBuffer>					cmdBuffer						(allocateCommandBuffer(vk, vkDevice, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
+	const Unique<VkCommandPool>							cmdPool							(createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, context.getUniversalQueueFamilyIndex()));
+	const Unique<VkCommandBuffer>						cmdBuffer						(allocateCommandBuffer(vk, vkDevice, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
 
-	const VkPipelineLayoutCreateInfo				pipelineLayoutCreateInfo		=
+	const VkPipelineLayoutCreateInfo					pipelineLayoutCreateInfo		=
 	{
-		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,	// VkStructureType                 sType;
-		DE_NULL,										// const void*                     pNext;
-		0u,												// VkPipelineLayoutCreateFlags     flags;
-		0u,												// deUint32                        setLayoutCount;
-		DE_NULL,										// const VkDescriptorSetLayout*    pSetLayouts;
-		0u,												// deUint32                        pushConstantRangeCount;
-		DE_NULL											// const VkPushConstantRange*      pPushConstantRanges;
+		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,									// VkStructureType					sType;
+		DE_NULL,																		// const void*						pNext;
+		0u,																				// VkPipelineLayoutCreateFlags		flags;
+		0u,																				// deUint32							setLayoutCount;
+		DE_NULL,																		// const VkDescriptorSetLayout*		pSetLayouts;
+		0u,																				// deUint32							pushConstantRangeCount;
+		DE_NULL																			// const VkPushConstantRange*		pPushConstantRanges;
 	};
 
-	const Unique<VkPipelineLayout>					pipelineLayout					(createPipelineLayout(vk, vkDevice, &pipelineLayoutCreateInfo, DE_NULL));
-
-	const Unique<VkRenderPass>						renderPass						(makeRenderPass(vk, vkDevice, VK_FORMAT_R8G8B8A8_UNORM));
-
-	const VkPipelineShaderStageCreateInfo			stages[]						=
+	// Multiple passes for destroy layout in order to increase the chance of crashing if some resource/state gets carried over from previous iterations.
+	int numTests = destroyLayout ? 3 : 1;
+	for(int i = 0; i < numTests; ++i)
 	{
+		Move<VkPipelineLayout>							pipelineLayout					(createPipelineLayout(vk, vkDevice, &pipelineLayoutCreateInfo, DE_NULL));
+		const Unique<VkRenderPass>						renderPass						(makeRenderPass(vk, vkDevice, VK_FORMAT_R8G8B8A8_UNORM));
+		const VkPipelineShaderStageCreateInfo			stages[]						=
 		{
-			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType                     sType;
-			DE_NULL,												// const void*                         pNext;
-			0u,														// VkPipelineShaderStageCreateFlags    flags;
-			VK_SHADER_STAGE_VERTEX_BIT,								// VkShaderStageFlagBits               stage;
-			*vertexShaderModule,									// VkShaderModule                      module;
-			"main",													// const char*                         pName;
-			DE_NULL													// const VkSpecializationInfo*         pSpecializationInfo;
-		},
+			{
+				VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,					// VkStructureType					sType;
+				DE_NULL,																// const void*						pNext;
+				0u,																		// VkPipelineShaderStageCreateFlags	flags;
+				VK_SHADER_STAGE_VERTEX_BIT,												// VkShaderStageFlagBits			stage;
+				*vertexShaderModule,													// VkShaderModule					module;
+				"main",																	// const char*						pName;
+				DE_NULL																	// const VkSpecializationInfo*		pSpecializationInfo;
+			},
+			{
+				VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,					// VkStructureType					sType;
+				DE_NULL,																// const void*						pNext;
+				0u,																		// VkPipelineShaderStageCreateFlags	flags;
+				VK_SHADER_STAGE_FRAGMENT_BIT,											// VkShaderStageFlagBits			stage;
+				*fragmentShaderModule,													// VkShaderModule					module;
+				"main",																	// const char*						pName;
+				DE_NULL																	// const VkSpecializationInfo*		pSpecializationInfo;
+			}
+		};
+		const VkPipelineVertexInputStateCreateInfo		vertexInputStateCreateInfo		=
 		{
-			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType                     sType;
-			DE_NULL,												// const void*                         pNext;
-			0u,														// VkPipelineShaderStageCreateFlags    flags;
-			VK_SHADER_STAGE_FRAGMENT_BIT,							// VkShaderStageFlagBits               stage;
-			*fragmentShaderModule,									// VkShaderModule                      module;
-			"main",													// const char*                         pName;
-			DE_NULL													// const VkSpecializationInfo*         pSpecializationInfo;
+			VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,					// VkStructureType							sType;
+			DE_NULL,																	// const void*								pNext;
+			0u,																			// VkPipelineVertexInputStateCreateFlags	flags;
+			0u,																			// deUint32									vertexBindingDescriptionCount;
+			DE_NULL,																	// const VkVertexInputBindingDescription*	pVertexBindingDescriptions;
+			0u,																			// deUint32									vertexAttributeDescriptionCount;
+			DE_NULL																		// const VkVertexInputAttributeDescription*	pVertexAttributeDescriptions;
+		};
+		const VkPipelineInputAssemblyStateCreateInfo	inputAssemblyStateCreateInfo	=
+		{
+			VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,				// VkStructureType							sType;
+			DE_NULL,																	// const void*								pNext;
+			0u,																			// VkPipelineInputAssemblyStateCreateFlags	flags;
+			VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,										// VkPrimitiveTopology						topology;
+			VK_FALSE																	// VkBool32									primitiveRestartEnable;
+		};
+		const VkPipelineRasterizationStateCreateInfo	rasterizationStateCreateInfo	=
+		{
+			VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,					// VkStructureType							sType;
+			DE_NULL,																	// const void*								pNext;
+			0u,																			// VkPipelineRasterizationStateCreateFlags	flags;
+			VK_FALSE,																	// VkBool32									depthClampEnable;
+			VK_TRUE,																	// VkBool32									rasterizerDiscardEnable;
+			VK_POLYGON_MODE_FILL,														// VkPolygonMode							polygonMode;
+			VK_CULL_MODE_BACK_BIT,														// VkCullModeFlags							cullMode;
+			VK_FRONT_FACE_CLOCKWISE,													// VkFrontFace								frontFace;
+			VK_FALSE,																	// VkBool32									depthBiasEnable;
+			0.0f,																		// float									depthBiasConstantFactor;
+			0.0f,																		// float									depthBiasClamp;
+			0.0f,																		// float									depthBiasSlopeFactor;
+			1.0f																		// float									lineWidth;
+		};
+		const VkPipelineColorBlendAttachmentState		colorBlendAttachmentState		=
+		{
+			VK_FALSE,																	// VkBool32					blendEnable;
+			VK_BLEND_FACTOR_ZERO,														// VkBlendFactor			srcColorBlendFactor;
+			VK_BLEND_FACTOR_ZERO,														// VkBlendFactor			dstColorBlendFactor;
+			VK_BLEND_OP_ADD,															// VkBlendOp				colorBlendOp;
+			VK_BLEND_FACTOR_ZERO,														// VkBlendFactor			srcAlphaBlendFactor;
+			VK_BLEND_FACTOR_ZERO,														// VkBlendFactor			dstAlphaBlendFactor;
+			VK_BLEND_OP_ADD,															// VkBlendOp				alphaBlendOp;
+			0xf																			// VkColorComponentFlags	colorWriteMask;
+		};
+		const VkPipelineColorBlendStateCreateInfo		colorBlendStateCreateInfo		=
+		{
+			VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,					// VkStructureType								sType;
+			DE_NULL,																	// const void*									pNext;
+			0u,																			// VkPipelineColorBlendStateCreateFlags			flags;
+			VK_FALSE,																	// VkBool32										logicOpEnable;
+			VK_LOGIC_OP_CLEAR,															// VkLogicOp									logicOp;
+			1u,																			// deUint32										attachmentCount;
+			&colorBlendAttachmentState,													// const VkPipelineColorBlendAttachmentState*	pAttachments;
+			{ 0.0f, 0.0f, 0.0f, 0.0f }													// float										blendConstants[4];
+		};
+		const VkPipelineCacheCreateInfo					pipelineCacheCreateInfo			=
+		{
+			VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,								// VkStructureType				sType;
+			DE_NULL,																	// const void*					pNext;
+			0u,																			// VkPipelineCacheCreateFlags	flags;
+			0u,																			// size_t						initialDataSize;
+			DE_NULL																		// const void*					pInitialData;
+		};
+		const Unique<VkPipelineCache>					pipelineCache					(createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo));
+		const VkGraphicsPipelineCreateInfo				graphicsPipelineCreateInfo		=
+		{
+			VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,							// VkStructureType									sType;
+			DE_NULL,																	// const void*										pNext;
+			VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,								// VkPipelineCreateFlags							flags;
+			2u,																			// deUint32											stageCount;
+			stages,																		// const VkPipelineShaderStageCreateInfo*			pStages;
+			&vertexInputStateCreateInfo,												// const VkPipelineVertexInputStateCreateInfo*		pVertexInputState;
+			&inputAssemblyStateCreateInfo,												// const VkPipelineInputAssemblyStateCreateInfo*	pInputAssemblyState;
+			DE_NULL,																	// const VkPipelineTessellationStateCreateInfo*		pTessellationState;
+			DE_NULL,																	// const VkPipelineViewportStateCreateInfo*			pViewportState;
+			&rasterizationStateCreateInfo,												// const VkPipelineRasterizationStateCreateInfo*	pRasterizationState;
+			DE_NULL,																	// const VkPipelineMultisampleStateCreateInfo*		pMultisampleState;
+			DE_NULL,																	// const VkPipelineDepthStencilStateCreateInfo*		pDepthStencilState;
+			&colorBlendStateCreateInfo,													// const VkPipelineColorBlendStateCreateInfo*		pColorBlendState;
+			DE_NULL,																	// const VkPipelineDynamicStateCreateInfo*			pDynamicState;
+			*pipelineLayout,															// VkPipelineLayout									layout;
+			*renderPass,																// VkRenderPass										renderPass;
+			0u,																			// deUint32											subpass;
+			DE_NULL,																	// VkPipeline										basePipelineHandle;
+			0																			// int												basePipelineIndex;
+		};
+		createGraphicsPipeline(vk, vkDevice, usePipelineCache ? *pipelineCache : DE_NULL, &graphicsPipelineCreateInfo);
+
+		const deUint32 framebufferWidth													= 32;
+		const deUint32 framebufferHeight												= 32;
+		if (destroyLayout)
+		{
+			// This will destroy the pipelineLayout when going out of enclosing scope
+			Move<VkPipelineLayout> layout(pipelineLayout);
 		}
-	};
+		const VkCommandBufferBeginInfo					cmdBufferBeginInfo				=
+		{
+			VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,								// VkStructureType							sType;
+			DE_NULL,																	// const void*								pNext;
+			0u,																			// VkCommandBufferUsageFlags				flags;
+			(const VkCommandBufferInheritanceInfo*)DE_NULL								// const VkCommandBufferInheritanceInfo*	pInheritanceInfo;
+		};
+		if (!destroyLayout) {
+			VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
+			VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
+		} else {
+			auto&										allocator						= context.getDefaultAllocator();
+			const auto									queue							= context.getUniversalQueue();
+			const VkFormat								attachmentFormat				= VK_FORMAT_R8G8B8A8_UNORM;
+			const tcu::TextureFormat					textureFormat					= mapVkFormat(attachmentFormat);
+			const VkDeviceSize							imageSize						= framebufferWidth * framebufferHeight * textureFormat.getPixelSize();
+			const VkImageCreateInfo						imageCreateInfo					=
+			{
+				VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,									// VkStructureType			sType;
+				DE_NULL,																// const void*				pNext;
+				(VkImageCreateFlags)0,													// VkImageCreateFlags		flags;
+				VK_IMAGE_TYPE_2D,														// VkImageType				imageType;
+				attachmentFormat,														// VkFormat					format;
+				{ framebufferWidth, framebufferHeight, 1u },							// VkExtent3D				extent;
+				1u,																		// deUint32					mipLevels;
+				1u,																		// deUint32					arrayLayers;
+				VK_SAMPLE_COUNT_1_BIT,													// VkSampleCountFlagBits	samples;
+				VK_IMAGE_TILING_OPTIMAL,												// VkImageTiling			tiling;
+				VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
+				VK_IMAGE_USAGE_TRANSFER_DST_BIT |
+				VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,									// VkImageUsageFlags		usage;
+				VK_SHARING_MODE_EXCLUSIVE,												// VkSharingMode			sharingMode;
+				0u,																		// deUint32					queueFamilyIndexCount;
+				DE_NULL,																// const deUint32*			pQueueFamilyIndices;
+				VK_IMAGE_LAYOUT_UNDEFINED												// VkImageLayout			initialLayout;
+			};
+			const ImageWithMemory						attachmentImage					(vk, vkDevice, context.getDefaultAllocator(), imageCreateInfo, MemoryRequirement::Any);
+			const VkImageSubresourceRange				colorSubresourceRange			= { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u };
+			const Unique<VkImageView>					attachmentImageView				(vk::makeImageView(vk, vkDevice, *attachmentImage, VK_IMAGE_VIEW_TYPE_2D, attachmentFormat, colorSubresourceRange));
+			const VkBufferCreateInfo					imageBufferCreateInfo			= vk::makeBufferCreateInfo(imageSize, vk::VK_BUFFER_USAGE_TRANSFER_DST_BIT);
+			const BufferWithMemory						imageBuffer						(vk, vkDevice, allocator, imageBufferCreateInfo, vk::MemoryRequirement::HostVisible);
+			const Unique<VkFramebuffer>					framebuffer						(vk::makeFramebuffer(vk, vkDevice, *renderPass, *attachmentImageView, framebufferWidth, framebufferHeight, 1u));
 
-	const VkPipelineVertexInputStateCreateInfo		vertexInputStateCreateInfo		=
-	{
-		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,	// VkStructureType                             sType;
-		DE_NULL,													// const void*                                 pNext;
-		0u,															// VkPipelineVertexInputStateCreateFlags       flags;
-		0u,															// deUint32                                    vertexBindingDescriptionCount;
-		DE_NULL,													// const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
-		0u,															// deUint32                                    vertexAttributeDescriptionCount;
-		DE_NULL														// const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
-	};
+			VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
+			const tcu::Vec4								clearColor						= { 0.2f, 0.6f, 0.8f, 1.0f };
+			VkClearValue								clearValue						=
+			{
+				{ { clearColor.x(), clearColor.y(),
+					clearColor.z(), clearColor.w() } }									// float						float32[4];
+			};
+			VkClearAttachment								attachment						=
+			{
+				VK_IMAGE_ASPECT_COLOR_BIT,												// VkImageAspectFlags			aspectMask;
+				0u,																		// deUint32						colorAttachment;
+				clearValue																// VkClearValue					clearValue;
+			};
+			const VkRect2D								renderArea						= { { 0, 0 }, { framebufferWidth, framebufferHeight } };
+			const VkClearRect								rect							=
+			{
+				renderArea,																// VkRect2D						rect
+				0u,																		// uint32_t						baseArrayLayer
+				1u																		// uint32_t						layerCount
+			};
+			const VkRenderPassBeginInfo				    renderPassBeginInfo				=
+			{
+				VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,								// VkStructureType				sType;
+				DE_NULL,																// const void*					pNext;
+				*renderPass,															// VkRenderPass					renderPass;
+				*framebuffer,															// VkFramebuffer				framebuffer;
+				renderArea,																// VkRect2D						renderArea;
+				1u,																		// deUint32						clearValueCount;
+				&clearValue																// const VkClearValue*			pClearValues;
+			};
+			vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
+			vk.cmdClearAttachments(*cmdBuffer, 1, &attachment, 1, &rect);
+			vk.cmdEndRenderPass(*cmdBuffer);
+			vk::copyImageToBuffer(vk, *cmdBuffer, *attachmentImage, *imageBuffer, tcu::IVec2(framebufferWidth, framebufferHeight));
+			VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
 
-	const VkPipelineInputAssemblyStateCreateInfo	inputAssemblyStateCreateInfo	=
-	{
-		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,	// VkStructureType                            sType;
-		DE_NULL,														// const void*                                pNext;
-		0u,																// VkPipelineInputAssemblyStateCreateFlags    flags;
-		VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,							// VkPrimitiveTopology                        topology;
-		VK_FALSE														// VkBool32                                   primitiveRestartEnable;
-	};
+			vk::submitCommandsAndWait(vk, vkDevice, queue, *cmdBuffer);
+			vk.resetCommandBuffer(*cmdBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
+			const auto&									imageBufferAlloc				= imageBuffer.getAllocation();
+			vk::invalidateAlloc(vk, vkDevice, imageBufferAlloc);
 
-	const VkPipelineRasterizationStateCreateInfo	rasterizationStateCreateInfo	=
-	{
-		VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,	// VkStructureType                            sType;
-		DE_NULL,													// const void*                                pNext;
-		0u,															// VkPipelineRasterizationStateCreateFlags    flags;
-		VK_FALSE,													// VkBool32                                   depthClampEnable;
-		VK_TRUE,													// VkBool32                                   rasterizerDiscardEnable;
-		VK_POLYGON_MODE_FILL,										// VkPolygonMode                              polygonMode;
-		VK_CULL_MODE_BACK_BIT,										// VkCullModeFlags                            cullMode;
-		VK_FRONT_FACE_CLOCKWISE,									// VkFrontFace                                frontFace;
-		VK_FALSE,													// VkBool32                                   depthBiasEnable;
-		0.0f,														// float                                      depthBiasConstantFactor;
-		0.0f,														// float                                      depthBiasClamp;
-		0.0f,														// float                                      depthBiasSlopeFactor;
-		1.0f														// float                                      lineWidth;
-	};
+			const auto									imageBufferPtr					= reinterpret_cast<const char*>(imageBufferAlloc.getHostPtr()) + imageBufferAlloc.getOffset();
+			const tcu::ConstPixelBufferAccess			imagePixels						(textureFormat, framebufferWidth, framebufferHeight, 1u, imageBufferPtr);
 
-	const VkPipelineColorBlendAttachmentState		colorBlendAttachmentState		=
-	{
-		VK_FALSE,				// VkBool32                 blendEnable;
-		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            srcColorBlendFactor;
-		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            dstColorBlendFactor;
-		VK_BLEND_OP_ADD,		// VkBlendOp                colorBlendOp;
-		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            srcAlphaBlendFactor;
-		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            dstAlphaBlendFactor;
-		VK_BLEND_OP_ADD,		// VkBlendOp                alphaBlendOp;
-		0xf						// VkColorComponentFlags    colorWriteMask;
-	};
+			for (int z = 0; z < imagePixels.getDepth(); ++z)
+			for (int y = 0; y < imagePixels.getHeight(); ++y)
+			for (int x = 0; x < imagePixels.getWidth(); ++x)
+			{
+				const auto pixel = imagePixels.getPixel(x, y, z);
+				if (pixel != clearColor) {
+									std::ostringstream msg; msg << "Pixel value mismatch after framebuffer clear." << " diff: " << pixel << " vs " << clearColor;
 
-	const VkPipelineColorBlendStateCreateInfo		colorBlendStateCreateInfo		=
-	{
-		VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,	// VkStructureType                               sType;
-		DE_NULL,													// const void*                                   pNext;
-		0u,															// VkPipelineColorBlendStateCreateFlags          flags;
-		VK_FALSE,													// VkBool32                                      logicOpEnable;
-		VK_LOGIC_OP_CLEAR,											// VkLogicOp                                     logicOp;
-		1u,															// deUint32                                      attachmentCount;
-		&colorBlendAttachmentState,									// const VkPipelineColorBlendAttachmentState*    pAttachments;
-		{ 0.0f, 0.0f, 0.0f, 0.0f }									// float                                         blendConstants[4];
-	};
-
-	const VkPipelineCacheCreateInfo					pipelineCacheCreateInfo			=
-	{
-		VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,	// VkStructureType               sType;
-		DE_NULL,										// const void*                   pNext;
-		0u,												// VkPipelineCacheCreateFlags    flags;
-		0u,												// size_t                        initialDataSize;
-		DE_NULL											// const void*                   pInitialData;
-	};
-
-	const Unique<VkPipelineCache>					pipelineCache					(createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo));
-
-	const VkGraphicsPipelineCreateInfo				graphicsPipelineCreateInfo		=
-	{
-		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,	// VkStructureType                                  sType;
-		DE_NULL,											// const void*                                      pNext;
-		VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT,		// VkPipelineCreateFlags                            flags;
-		2u,													// deUint32                                         stageCount;
-		stages,												// const VkPipelineShaderStageCreateInfo*           pStages;
-		&vertexInputStateCreateInfo,						// const VkPipelineVertexInputStateCreateInfo*      pVertexInputState;
-		&inputAssemblyStateCreateInfo,						// const VkPipelineInputAssemblyStateCreateInfo*    pInputAssemblyState;
-		DE_NULL,											// const VkPipelineTessellationStateCreateInfo*     pTessellationState;
-		DE_NULL,											// const VkPipelineViewportStateCreateInfo*         pViewportState;
-		&rasterizationStateCreateInfo,						// const VkPipelineRasterizationStateCreateInfo*    pRasterizationState;
-		DE_NULL,											// const VkPipelineMultisampleStateCreateInfo*      pMultisampleState;
-		DE_NULL,											// const VkPipelineDepthStencilStateCreateInfo*     pDepthStencilState;
-		&colorBlendStateCreateInfo,							// const VkPipelineColorBlendStateCreateInfo*       pColorBlendState;
-		DE_NULL,											// const VkPipelineDynamicStateCreateInfo*          pDynamicState;
-		*pipelineLayout,									// VkPipelineLayout                                 layout;
-		*renderPass,										// VkRenderPass                                     renderPass;
-		0u,													// deUint32                                         subpass;
-		DE_NULL,											// VkPipeline                                       basePipelineHandle;
-		0													// int                                              basePipelineIndex;
-	};
-
-	createGraphicsPipeline(vk, vkDevice, usePipelineCache ? *pipelineCache : DE_NULL, &graphicsPipelineCreateInfo);
-
-	const VkCommandBufferBeginInfo					cmdBufferBeginInfo				=
-	{
-		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,	// VkStructureType                          sType;
-		DE_NULL,										// const void*                              pNext;
-		0u,												// VkCommandBufferUsageFlags                flags;
-		(const VkCommandBufferInheritanceInfo*)DE_NULL	// const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
-	};
-
-	VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
-	VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
-
+					return tcu::TestStatus::fail(msg.str()/*"Pixel value mismatch after framebuffer clear."*/);
+				}
+			}
+		}
+	}
 	// Passes as long as no crash occurred.
 	return tcu::TestStatus::pass("Pass");
 }
 
+tcu::TestStatus testEarlyDestroyKeepLayout (Context& context, bool useCache)
+{
+	return testEarlyDestroy (context, useCache, false);
+}
+
+tcu::TestStatus testEarlyDestroyDestroyLayout (Context& context, bool useCache)
+{
+	return testEarlyDestroy (context, useCache, true);
+}
+
 void addEarlyDestroyTestCasesWithFunctions (tcu::TestCaseGroup* group)
 {
-	addFunctionCaseWithPrograms(group, "cache", "", initPrograms, testEarlyDestroy, true);
-	addFunctionCaseWithPrograms(group, "no_cache", "", initPrograms, testEarlyDestroy, false);
+	addFunctionCaseWithPrograms(group, "cache", "", initPrograms, testEarlyDestroyKeepLayout, true);
+	addFunctionCaseWithPrograms(group, "no_cache", "", initPrograms, testEarlyDestroyKeepLayout, false);
+	addFunctionCaseWithPrograms(group, "cache_destroy_layout", "", initPrograms, testEarlyDestroyDestroyLayout, true);
+	addFunctionCaseWithPrograms(group, "no_cache_destroy_layout", "", initPrograms, testEarlyDestroyDestroyLayout, false);
 }
 
 } // anonymous
diff --git a/external/vulkancts/mustpass/master/vk-default.txt b/external/vulkancts/mustpass/master/vk-default.txt
index fde5379..2300563 100644
--- a/external/vulkancts/mustpass/master/vk-default.txt
+++ b/external/vulkancts/mustpass/master/vk-default.txt
Binary files differ