Home | History | Annotate | Download | only in api
      1 /*------------------------------------------------------------------------
      2  * Vulkan Conformance Tests
      3  * ------------------------
      4  *
      5  * Copyright (c) 2016 The Khronos Group Inc.
      6  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
      7  *
      8  * Licensed under the Apache License, Version 2.0 (the "License");
      9  * you may not use this file except in compliance with the License.
     10  * You may obtain a copy of the License at
     11  *
     12  *      http://www.apache.org/licenses/LICENSE-2.0
     13  *
     14  * Unless required by applicable law or agreed to in writing, software
     15  * distributed under the License is distributed on an "AS IS" BASIS,
     16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17  * See the License for the specific language governing permissions and
     18  * limitations under the License.
     19  *
     20  *//*!
     21  * \file
     22  * \brief Vulkan Image Clearing Tests
     23  *//*--------------------------------------------------------------------*/
     24 
     25 #include "vktApiImageClearingTests.hpp"
     26 
     27 #include "deRandom.hpp"
     28 #include "deMath.h"
     29 #include "deStringUtil.hpp"
     30 #include "deUniquePtr.hpp"
     31 #include "deArrayUtil.hpp"
     32 #include "deInt32.h"
     33 #include "vkImageUtil.hpp"
     34 #include "vkMemUtil.hpp"
     35 #include "vktTestCase.hpp"
     36 #include "vktTestCaseUtil.hpp"
     37 #include "vkQueryUtil.hpp"
     38 #include "vkRefUtil.hpp"
     39 #include "vkTypeUtil.hpp"
     40 #include "tcuImageCompare.hpp"
     41 #include "tcuTexture.hpp"
     42 #include "tcuTextureUtil.hpp"
     43 #include "tcuVectorType.hpp"
     44 #include "tcuTexture.hpp"
     45 #include "tcuFloat.hpp"
     46 #include "tcuTestLog.hpp"
     47 #include "tcuVectorUtil.hpp"
     48 #include <sstream>
     49 #include <numeric>
     50 
     51 namespace vkt
     52 {
     53 
     54 namespace api
     55 {
     56 
     57 using namespace vk;
     58 using namespace tcu;
     59 
     60 namespace
     61 {
     62 
     63 VkExtent3D getMipLevelExtent (VkExtent3D baseExtent, const deUint32 mipLevel)
     64 {
     65 	baseExtent.width	= std::max(baseExtent.width  >> mipLevel, 1u);
     66 	baseExtent.height	= std::max(baseExtent.height >> mipLevel, 1u);
     67 	baseExtent.depth	= std::max(baseExtent.depth  >> mipLevel, 1u);
     68 	return baseExtent;
     69 }
     70 
     71 deUint32 getNumMipLevels (const VkExtent3D& baseExtent, const deUint32 maxMipLevels)
     72 {
     73 	const deUint32 widestEdge = std::max(std::max(baseExtent.width, baseExtent.height), baseExtent.depth);
     74 	return std::min(static_cast<deUint32>(deFloatLog2(static_cast<float>(widestEdge))) + 1u, maxMipLevels);
     75 }
     76 
     77 std::vector<deUint32> getImageMipLevelSizes (const deUint32 pixelSize, const VkExtent3D& baseExtent, const deUint32 numMipLevels, const deUint32 perLevelAlignment = 1u)
     78 {
     79 	std::vector<deUint32> results(numMipLevels);
     80 
     81 	for (deUint32 mipLevel = 0; mipLevel < numMipLevels; ++mipLevel)
     82 	{
     83 		const VkExtent3D extent = getMipLevelExtent(baseExtent, mipLevel);
     84 		results[mipLevel] = static_cast<deUint32>(deAlignSize(extent.width * extent.height * extent.depth * pixelSize, perLevelAlignment));
     85 	}
     86 
     87 	return results;
     88 }
     89 
     90 //! Check if a point lies in a cross-like area.
     91 inline bool isInClearRange (const UVec4& clearCoords, const deUint32 x, const deUint32 y)
     92 {
     93 	return !((x <  clearCoords[0] && y <  clearCoords[1]) ||
     94 			 (x <  clearCoords[0] && y >= clearCoords[3]) ||
     95 			 (x >= clearCoords[2] && y <  clearCoords[1]) ||
     96 			 (x >= clearCoords[2] && y >= clearCoords[3]));
     97 }
     98 
     99 // This method is copied from the vktRenderPassTests.cpp. It should be moved to a common place.
    100 int calcFloatDiff (float a, float b)
    101 {
    102 	const int			asign	= Float32(a).sign();
    103 	const int			bsign	= Float32(a).sign();
    104 
    105 	const deUint32		avalue	= (Float32(a).bits() & ((0x1u << 31u) - 1u));
    106 	const deUint32		bvalue	= (Float32(b).bits() & ((0x1u << 31u) - 1u));
    107 
    108 	if (asign != bsign)
    109 		return avalue + bvalue + 1u;
    110 	else if (avalue < bvalue)
    111 		return bvalue - avalue;
    112 	else
    113 		return avalue - bvalue;
    114 }
    115 
    116 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
    117 bool comparePixelToDepthClearValue (const ConstPixelBufferAccess&	access,
    118 									int								x,
    119 									int								y,
    120 									float							ref,
    121 									std::string&					stringResult)
    122 {
    123 	const TextureFormat			format			= getEffectiveDepthStencilTextureFormat(access.getFormat(), Sampler::MODE_DEPTH);
    124 	const TextureChannelClass	channelClass	= getTextureChannelClass(format.type);
    125 
    126 	switch (channelClass)
    127 	{
    128 		case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    129 		case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    130 		{
    131 			const int	bitDepth	= getTextureFormatBitDepth(format).x();
    132 			const float	depth		= access.getPixDepth(x, y);
    133 			const float	threshold	= 2.0f / (float)((1 << bitDepth) - 1);
    134 			const bool	result		= deFloatAbs(depth - ref) <= threshold;
    135 
    136 			if (!result)
    137 			{
    138 				std::stringstream s;
    139 				s << "Ref:" << ref << " Threshold:" << threshold << " Depth:" << depth;
    140 				stringResult	= s.str();
    141 			}
    142 
    143 			return result;
    144 		}
    145 
    146 		case TEXTURECHANNELCLASS_FLOATING_POINT:
    147 		{
    148 			const float	depth			= access.getPixDepth(x, y);
    149 			const int	mantissaBits	= getTextureFormatMantissaBitDepth(format).x();
    150 			const int	threshold		= 10 * 1 << (23 - mantissaBits);
    151 
    152 			DE_ASSERT(mantissaBits <= 23);
    153 
    154 			const bool	result			= calcFloatDiff(depth, ref) <= threshold;
    155 
    156 			if (!result)
    157 			{
    158 				float				floatThreshold	= Float32((deUint32)threshold).asFloat();
    159 				std::stringstream	s;
    160 
    161 				s << "Ref:" << ref << " Threshold:" << floatThreshold << " Depth:" << depth;
    162 				stringResult	= s.str();
    163 			}
    164 
    165 			return result;
    166 		}
    167 
    168 		default:
    169 			DE_FATAL("Invalid channel class");
    170 			return false;
    171 	}
    172 }
    173 
    174 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
    175 bool comparePixelToStencilClearValue (const ConstPixelBufferAccess&	access,
    176 									  int							x,
    177 									  int							y,
    178 									  deUint32						ref,
    179 									  std::string&					stringResult)
    180 {
    181 	const deUint32	stencil	= access.getPixStencil(x, y);
    182 	const bool		result	= stencil == ref;
    183 
    184 	if (!result)
    185 	{
    186 		std::stringstream s;
    187 		s << "Ref:" << ref << " Threshold:0" << " Stencil:" << stencil;
    188 		stringResult	= s.str();
    189 	}
    190 
    191 	return result;
    192 }
    193 
    194 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
    195 bool comparePixelToColorClearValue (const ConstPixelBufferAccess&	access,
    196 									int								x,
    197 									int								y,
    198 									int								z,
    199 									const VkClearColorValue&		ref,
    200 									std::string&					stringResult)
    201 {
    202 	const TextureFormat				format			= access.getFormat();
    203 	const TextureChannelClass		channelClass	= getTextureChannelClass(format.type);
    204 	const BVec4						channelMask		= getTextureFormatChannelMask(format);
    205 
    206 	switch (channelClass)
    207 	{
    208 		case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    209 		case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    210 		{
    211 			const IVec4	bitDepth	(getTextureFormatBitDepth(format));
    212 			const Vec4	resColor	(access.getPixel(x, y, z));
    213 			Vec4		refColor	(ref.float32[0],
    214 									 ref.float32[1],
    215 									 ref.float32[2],
    216 									 ref.float32[3]);
    217 			const int	modifier	= (channelClass == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT) ? 0 : 1;
    218 			const Vec4	threshold	(bitDepth[0] > 0 ? 1.0f / ((float)(1 << (bitDepth[0] - modifier)) - 1.0f) : 1.0f,
    219 									 bitDepth[1] > 0 ? 1.0f / ((float)(1 << (bitDepth[1] - modifier)) - 1.0f) : 1.0f,
    220 									 bitDepth[2] > 0 ? 1.0f / ((float)(1 << (bitDepth[2] - modifier)) - 1.0f) : 1.0f,
    221 									 bitDepth[3] > 0 ? 1.0f / ((float)(1 << (bitDepth[3] - modifier)) - 1.0f) : 1.0f);
    222 
    223 			if (isSRGB(access.getFormat()))
    224 				refColor	= linearToSRGB(refColor);
    225 
    226 			const bool	result		= !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
    227 
    228 			if (!result)
    229 			{
    230 				std::stringstream s;
    231 				s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
    232 				stringResult	= s.str();
    233 			}
    234 
    235 			return result;
    236 		}
    237 
    238 		case TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    239 		{
    240 			const UVec4	resColor	(access.getPixelUint(x, y, z));
    241 			const UVec4	refColor	(ref.uint32[0],
    242 									 ref.uint32[1],
    243 									 ref.uint32[2],
    244 									 ref.uint32[3]);
    245 			const UVec4	threshold	(1);
    246 
    247 			const bool	result		= !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
    248 
    249 			if (!result)
    250 			{
    251 				std::stringstream s;
    252 				s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
    253 				stringResult	= s.str();
    254 			}
    255 
    256 			return result;
    257 		}
    258 
    259 		case TEXTURECHANNELCLASS_SIGNED_INTEGER:
    260 		{
    261 			const IVec4	resColor	(access.getPixelInt(x, y, z));
    262 			const IVec4	refColor	(ref.int32[0],
    263 									 ref.int32[1],
    264 									 ref.int32[2],
    265 									 ref.int32[3]);
    266 			const IVec4	threshold	(1);
    267 
    268 			const bool	result		= !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
    269 
    270 			if (!result)
    271 			{
    272 				std::stringstream s;
    273 				s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
    274 				stringResult	= s.str();
    275 			}
    276 
    277 			return result;
    278 		}
    279 
    280 		case TEXTURECHANNELCLASS_FLOATING_POINT:
    281 		{
    282 			const Vec4	resColor		(access.getPixel(x, y, z));
    283 			const Vec4	refColor		(ref.float32[0],
    284 										 ref.float32[1],
    285 										 ref.float32[2],
    286 										 ref.float32[3]);
    287 			const IVec4	mantissaBits	(getTextureFormatMantissaBitDepth(format));
    288 			const IVec4	threshold		(10 * IVec4(1) << (23 - mantissaBits));
    289 
    290 			DE_ASSERT(allEqual(greaterThanEqual(threshold, IVec4(0)), BVec4(true)));
    291 
    292 			for (int ndx = 0; ndx < 4; ndx++)
    293 			{
    294 				const bool result	= !(calcFloatDiff(resColor[ndx], refColor[ndx]) > threshold[ndx] && channelMask[ndx]);
    295 
    296 				if (!result)
    297 				{
    298 					float				floatThreshold	= Float32((deUint32)(threshold)[0]).asFloat();
    299 					Vec4				thresholdVec4	(floatThreshold,
    300 														 floatThreshold,
    301 														 floatThreshold,
    302 														 floatThreshold);
    303 					std::stringstream	s;
    304 					s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << thresholdVec4 << " Color:" << resColor;
    305 					stringResult	= s.str();
    306 
    307 					return false;
    308 				}
    309 			}
    310 
    311 			return true;
    312 		}
    313 
    314 		default:
    315 			DE_FATAL("Invalid channel class");
    316 			return false;
    317 	}
    318 }
    319 
    320 struct TestParams
    321 {
    322 	bool			useSingleMipLevel;	//!< only mip level 0, otherwise up to maxMipLevels
    323 	VkImageType		imageType;
    324 	VkFormat		imageFormat;
    325 	VkExtent3D		imageExtent;
    326 	VkClearValue	initValue;
    327 	VkClearValue	clearValue[2];		//!< the second value is used with more than one mip map
    328 };
    329 
    330 class ImageClearingTestInstance : public vkt::TestInstance
    331 {
    332 public:
    333 										ImageClearingTestInstance		(Context&			context,
    334 																		 const TestParams&	testParams);
    335 
    336 	Move<VkCommandPool>					createCommandPool				(VkCommandPoolCreateFlags commandPoolCreateFlags) const;
    337 	Move<VkCommandBuffer>				allocatePrimaryCommandBuffer	(VkCommandPool commandPool) const;
    338 	Move<VkImage>						createImage						(VkImageType imageType, VkFormat format, VkExtent3D extent, VkImageUsageFlags usage) const;
    339 	Move<VkImageView>					createImageView					(VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask) const;
    340 	Move<VkRenderPass>					createRenderPass				(VkFormat format) const;
    341 	Move<VkFramebuffer>					createFrameBuffer				(VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight) const;
    342 
    343 	void								beginCommandBuffer				(VkCommandBufferUsageFlags usageFlags) const;
    344 	void								endCommandBuffer				(void) const;
    345 	void								submitCommandBuffer				(void) const;
    346 	void								beginRenderPass					(VkSubpassContents content, VkClearValue clearValue) const;
    347 
    348 	void								pipelineImageBarrier			(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout) const;
    349 	de::MovePtr<TextureLevelPyramid>	readImage						(VkImageAspectFlags aspectMask) const;
    350 	tcu::TestStatus						verifyResultImage				(const std::string& successMessage, const UVec4& clearCoords = UVec4()) const;
    351 
    352 protected:
    353 	VkImageViewType						getCorrespondingImageViewType	(VkImageType imageType) const;
    354 	VkImageUsageFlags					getImageUsageFlags				(VkFormat format) const;
    355 	VkImageAspectFlags					getImageAspectFlags				(VkFormat format) const;
    356 	bool								getIsAttachmentFormat			(VkFormat format) const;
    357 	bool								getIsStencilFormat				(VkFormat format) const;
    358 	bool								getIsDepthFormat				(VkFormat format) const;
    359 	VkImageFormatProperties				getImageFormatProperties		(void) const;
    360 	de::MovePtr<Allocation>				allocateAndBindImageMemory		(VkImage image) const;
    361 
    362 	const TestParams&					m_params;
    363 	const VkDevice						m_device;
    364 	const InstanceInterface&			m_vki;
    365 	const DeviceInterface&				m_vkd;
    366 	const VkQueue						m_queue;
    367 	const deUint32						m_queueFamilyIndex;
    368 	Allocator&							m_allocator;
    369 
    370 	const bool							m_isAttachmentFormat;
    371 	const VkImageUsageFlags				m_imageUsageFlags;
    372 	const VkImageAspectFlags			m_imageAspectFlags;
    373 	const VkImageFormatProperties		m_imageFormatProperties;
    374 	const deUint32						m_imageMipLevels;
    375 	const deUint32						m_thresholdMipLevel;
    376 
    377 	Unique<VkCommandPool>				m_commandPool;
    378 	Unique<VkCommandBuffer>				m_commandBuffer;
    379 
    380 	Unique<VkImage>						m_image;
    381 	de::MovePtr<Allocation>				m_imageMemory;
    382 	Unique<VkImageView>					m_imageView;
    383 	Unique<VkRenderPass>				m_renderPass;
    384 	Unique<VkFramebuffer>				m_frameBuffer;
    385 };
    386 
    387 ImageClearingTestInstance::ImageClearingTestInstance (Context& context, const TestParams& params)
    388 	: TestInstance				(context)
    389 	, m_params					(params)
    390 	, m_device					(context.getDevice())
    391 	, m_vki						(context.getInstanceInterface())
    392 	, m_vkd						(context.getDeviceInterface())
    393 	, m_queue					(context.getUniversalQueue())
    394 	, m_queueFamilyIndex		(context.getUniversalQueueFamilyIndex())
    395 	, m_allocator				(context.getDefaultAllocator())
    396 	, m_isAttachmentFormat		(getIsAttachmentFormat(params.imageFormat))
    397 	, m_imageUsageFlags			(getImageUsageFlags(params.imageFormat))
    398 	, m_imageAspectFlags		(getImageAspectFlags(params.imageFormat))
    399 	, m_imageFormatProperties	(getImageFormatProperties())
    400 	, m_imageMipLevels			(params.useSingleMipLevel ? 1u : getNumMipLevels(params.imageExtent, m_imageFormatProperties.maxMipLevels))
    401 	, m_thresholdMipLevel		(std::max(m_imageMipLevels / 2u, 1u))
    402 	, m_commandPool				(createCommandPool(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
    403 	, m_commandBuffer			(allocatePrimaryCommandBuffer(*m_commandPool))
    404 
    405 	, m_image					(createImage(params.imageType,
    406 											 params.imageFormat,
    407 											 params.imageExtent,
    408 											 m_imageUsageFlags))
    409 
    410 	, m_imageMemory				(allocateAndBindImageMemory(*m_image))
    411 	, m_imageView				(m_isAttachmentFormat ? createImageView(*m_image,
    412 												 getCorrespondingImageViewType(params.imageType),
    413 												 params.imageFormat,
    414 												 m_imageAspectFlags) : vk::Move<VkImageView>())
    415 
    416 	, m_renderPass				(m_isAttachmentFormat ? createRenderPass(params.imageFormat) : vk::Move<vk::VkRenderPass>())
    417 	, m_frameBuffer				(m_isAttachmentFormat ? createFrameBuffer(*m_imageView, *m_renderPass, params.imageExtent.width, params.imageExtent.height) : vk::Move<vk::VkFramebuffer>())
    418 {
    419 }
    420 
    421 VkImageViewType ImageClearingTestInstance::getCorrespondingImageViewType (VkImageType imageType) const
    422 {
    423 	switch (imageType)
    424 	{
    425 		case VK_IMAGE_TYPE_1D:
    426 			return VK_IMAGE_VIEW_TYPE_1D;
    427 		case VK_IMAGE_TYPE_2D:
    428 			return VK_IMAGE_VIEW_TYPE_2D;
    429 		case VK_IMAGE_TYPE_3D:
    430 			return VK_IMAGE_VIEW_TYPE_3D;
    431 		default:
    432 			DE_FATAL("Unknown image type!");
    433 	}
    434 
    435 	return VK_IMAGE_VIEW_TYPE_2D;
    436 }
    437 
    438 VkImageUsageFlags ImageClearingTestInstance::getImageUsageFlags (VkFormat format) const
    439 {
    440 	VkImageUsageFlags	commonFlags	= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
    441 
    442 	if (m_isAttachmentFormat)
    443 	{
    444 		if (isDepthStencilFormat(format))
    445 			return commonFlags | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
    446 
    447 		return commonFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
    448 	}
    449 	return commonFlags;
    450 }
    451 
    452 VkImageAspectFlags ImageClearingTestInstance::getImageAspectFlags (VkFormat format) const
    453 {
    454 	VkImageAspectFlags	imageAspectFlags	= 0;
    455 
    456 	if (getIsDepthFormat(format))
    457 		imageAspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
    458 
    459 	if (getIsStencilFormat(format))
    460 		imageAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
    461 
    462 	if (imageAspectFlags == 0)
    463 		imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
    464 
    465 	return imageAspectFlags;
    466 }
    467 
    468 bool ImageClearingTestInstance::getIsAttachmentFormat (VkFormat format) const
    469 {
    470 	const VkFormatProperties props	= vk::getPhysicalDeviceFormatProperties(m_vki, m_context.getPhysicalDevice(), format);
    471 
    472 	return (props.optimalTilingFeatures & (vk::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) != 0;
    473 }
    474 
    475 bool ImageClearingTestInstance::getIsStencilFormat (VkFormat format) const
    476 {
    477 	const TextureFormat tcuFormat	= mapVkFormat(format);
    478 
    479 	if (tcuFormat.order == TextureFormat::S || tcuFormat.order == TextureFormat::DS)
    480 		return true;
    481 
    482 	return false;
    483 }
    484 
    485 bool ImageClearingTestInstance::getIsDepthFormat (VkFormat format) const
    486 {
    487 	const TextureFormat	tcuFormat	= mapVkFormat(format);
    488 
    489 	if (tcuFormat.order == TextureFormat::D || tcuFormat.order == TextureFormat::DS)
    490 		return true;
    491 
    492 	return false;
    493 }
    494 
    495 VkImageFormatProperties ImageClearingTestInstance::getImageFormatProperties (void) const
    496 {
    497 	VkImageFormatProperties properties;
    498 	const VkResult result = m_vki.getPhysicalDeviceImageFormatProperties(m_context.getPhysicalDevice(), m_params.imageFormat, m_params.imageType,
    499 																		 VK_IMAGE_TILING_OPTIMAL, m_imageUsageFlags, (VkImageCreateFlags)0, &properties);
    500 
    501 	if (result == VK_ERROR_FORMAT_NOT_SUPPORTED)
    502 		TCU_THROW(NotSupportedError, "Format not supported");
    503 	else
    504 		return properties;
    505 }
    506 
    507 de::MovePtr<Allocation> ImageClearingTestInstance::allocateAndBindImageMemory (VkImage image) const
    508 {
    509 	de::MovePtr<Allocation>	imageMemory	(m_allocator.allocate(getImageMemoryRequirements(m_vkd, m_device, image), MemoryRequirement::Any));
    510 	VK_CHECK(m_vkd.bindImageMemory(m_device, image, imageMemory->getMemory(), imageMemory->getOffset()));
    511 	return imageMemory;
    512 }
    513 
    514 Move<VkCommandPool> ImageClearingTestInstance::createCommandPool (VkCommandPoolCreateFlags commandPoolCreateFlags) const
    515 {
    516 	const VkCommandPoolCreateInfo			cmdPoolCreateInfo		=
    517 	{
    518 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,					// VkStructureType             sType;
    519 		DE_NULL,													// const void*                 pNext;
    520 		commandPoolCreateFlags,										// VkCommandPoolCreateFlags    flags;
    521 		m_queueFamilyIndex											// deUint32                    queueFamilyIndex;
    522 	};
    523 
    524 	return vk::createCommandPool(m_vkd, m_device, &cmdPoolCreateInfo, DE_NULL);
    525 }
    526 
    527 Move<VkCommandBuffer> ImageClearingTestInstance::allocatePrimaryCommandBuffer (VkCommandPool commandPool) const
    528 {
    529 	const VkCommandBufferAllocateInfo		cmdBufferAllocateInfo	=
    530 	{
    531 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,				// VkStructureType             sType;
    532 		DE_NULL,													// const void*                 pNext;
    533 		commandPool,												// VkCommandPool               commandPool;
    534 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,							// VkCommandBufferLevel        level;
    535 		1															// deUint32                    commandBufferCount;
    536 	};
    537 
    538 	return vk::allocateCommandBuffer(m_vkd, m_device, &cmdBufferAllocateInfo);
    539 }
    540 
    541 Move<VkImage> ImageClearingTestInstance::createImage (VkImageType imageType, VkFormat format, VkExtent3D extent, VkImageUsageFlags usage) const
    542 {
    543 	const VkImageCreateInfo					imageCreateInfo			=
    544 	{
    545 		VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,		// VkStructureType			sType;
    546 		DE_NULL,									// const void*				pNext;
    547 		0u,											// VkImageCreateFlags		flags;
    548 		imageType,									// VkImageType				imageType;
    549 		format,										// VkFormat					format;
    550 		extent,										// VkExtent3D				extent;
    551 		m_imageMipLevels,							// deUint32					mipLevels;
    552 		1u,											// deUint32					arrayLayers;
    553 		VK_SAMPLE_COUNT_1_BIT,						// VkSampleCountFlagBits	samples;
    554 		VK_IMAGE_TILING_OPTIMAL,					// VkImageTiling			tiling;
    555 		usage,										// VkImageUsageFlags		usage;
    556 		VK_SHARING_MODE_EXCLUSIVE,					// VkSharingMode			sharingMode;
    557 		1u,											// deUint32					queueFamilyIndexCount;
    558 		&m_queueFamilyIndex,						// const deUint32*			pQueueFamilyIndices;
    559 		VK_IMAGE_LAYOUT_UNDEFINED					// VkImageLayout			initialLayout;
    560 	};
    561 
    562 	return vk::createImage(m_vkd, m_device, &imageCreateInfo, DE_NULL);
    563 }
    564 
    565 Move<VkImageView> ImageClearingTestInstance::createImageView (VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask) const
    566 {
    567 	const VkImageViewCreateInfo				imageViewCreateInfo		=
    568 	{
    569 		VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,	// VkStructureType				sType;
    570 		DE_NULL,									// const void*					pNext;
    571 		0u,											// VkImageViewCreateFlags		flags;
    572 		image,										// VkImage						image;
    573 		viewType,									// VkImageViewType				viewType;
    574 		format,										// VkFormat						format;
    575 		{
    576 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			r;
    577 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			g;
    578 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			b;
    579 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			a;
    580 		},											// VkComponentMapping			components;
    581 		{
    582 			aspectMask,									// VkImageAspectFlags			aspectMask;
    583 			0u,											// deUint32						baseMipLevel;
    584 			1u,											// deUint32						mipLevels;
    585 			0u,											// deUint32						baseArrayLayer;
    586 			1u,											// deUint32						arraySize;
    587 		},											// VkImageSubresourceRange		subresourceRange;
    588 	};
    589 
    590 	return vk::createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL);
    591 }
    592 
    593 Move<VkRenderPass> ImageClearingTestInstance::createRenderPass (VkFormat format) const
    594 {
    595 	VkImageLayout							imageLayout;
    596 
    597 	if (isDepthStencilFormat(format))
    598 		imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
    599 	else
    600 		imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
    601 
    602 	const VkAttachmentDescription			attachmentDesc			=
    603 	{
    604 		0u,													// VkAttachmentDescriptionFlags		flags;
    605 		format,												// VkFormat							format;
    606 		VK_SAMPLE_COUNT_1_BIT,								// VkSampleCountFlagBits			samples;
    607 		VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				loadOp;
    608 		VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				storeOp;
    609 		VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				stencilLoadOp;
    610 		VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				stencilStoreOp;
    611 		imageLayout,										// VkImageLayout					initialLayout;
    612 		imageLayout,										// VkImageLayout					finalLayout;
    613 	};
    614 
    615 	const VkAttachmentDescription			attachments[1]			=
    616 	{
    617 		attachmentDesc
    618 	};
    619 
    620 	const VkAttachmentReference				attachmentRef			=
    621 	{
    622 		0u,													// deUint32							attachment;
    623 		imageLayout,										// VkImageLayout					layout;
    624 	};
    625 
    626 	const VkAttachmentReference*			pColorAttachments		= DE_NULL;
    627 	const VkAttachmentReference*			pDepthStencilAttachment	= DE_NULL;
    628 	deUint32								colorAttachmentCount	= 1;
    629 
    630 	if (isDepthStencilFormat(format))
    631 	{
    632 		colorAttachmentCount	= 0;
    633 		pDepthStencilAttachment	= &attachmentRef;
    634 	}
    635 	else
    636 	{
    637 		colorAttachmentCount	= 1;
    638 		pColorAttachments		= &attachmentRef;
    639 	}
    640 
    641 	const VkSubpassDescription				subpassDesc[1]			=
    642 	{
    643 		{
    644 			0u,												// VkSubpassDescriptionFlags		flags;
    645 			VK_PIPELINE_BIND_POINT_GRAPHICS,				// VkPipelineBindPoint				pipelineBindPoint;
    646 			0u,												// deUint32							inputAttachmentCount;
    647 			DE_NULL,										// const VkAttachmentReference*		pInputAttachments;
    648 			colorAttachmentCount,							// deUint32							colorAttachmentCount;
    649 			pColorAttachments,								// const VkAttachmentReference*		pColorAttachments;
    650 			DE_NULL,										// const VkAttachmentReference*		pResolveAttachments;
    651 			pDepthStencilAttachment,						// const VkAttachmentReference*		pDepthStencilAttachment;
    652 			0u,												// deUint32							preserveAttachmentCount;
    653 			DE_NULL,										// const VkAttachmentReference*		pPreserveAttachments;
    654 		}
    655 	};
    656 
    657 	const VkRenderPassCreateInfo			renderPassCreateInfo	=
    658 	{
    659 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,			// VkStructureType					sType;
    660 		DE_NULL,											// const void*						pNext;
    661 		0u,													// VkRenderPassCreateFlags			flags;
    662 		1u,													// deUint32							attachmentCount;
    663 		attachments,										// const VkAttachmentDescription*	pAttachments;
    664 		1u,													// deUint32							subpassCount;
    665 		subpassDesc,										// const VkSubpassDescription*		pSubpasses;
    666 		0u,													// deUint32							dependencyCount;
    667 		DE_NULL,											// const VkSubpassDependency*		pDependencies;
    668 	};
    669 
    670 	return vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
    671 }
    672 
    673 Move<VkFramebuffer> ImageClearingTestInstance::createFrameBuffer (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight) const
    674 {
    675 	const VkImageView						attachmentViews[1]		=
    676 	{
    677 		imageView
    678 	};
    679 
    680 	const VkFramebufferCreateInfo			framebufferCreateInfo	=
    681 	{
    682 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,	// VkStructureType			sType;
    683 		DE_NULL,									// const void*				pNext;
    684 		0u,											// VkFramebufferCreateFlags	flags;
    685 		renderPass,									// VkRenderPass				renderPass;
    686 		1,											// deUint32					attachmentCount;
    687 		attachmentViews,							// const VkImageView*		pAttachments;
    688 		imageWidth,									// deUint32					width;
    689 		imageHeight,								// deUint32					height;
    690 		1u,											// deUint32					layers;
    691 	};
    692 
    693 	return createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL);
    694 }
    695 
    696 void ImageClearingTestInstance::beginCommandBuffer (VkCommandBufferUsageFlags usageFlags) const
    697 {
    698 	const VkCommandBufferBeginInfo			commandBufferBeginInfo	=
    699 	{
    700 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,			// VkStructureType                          sType;
    701 		DE_NULL,												// const void*                              pNext;
    702 		usageFlags,												// VkCommandBufferUsageFlags                flags;
    703 		DE_NULL													// const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
    704 	};
    705 
    706 	VK_CHECK(m_vkd.beginCommandBuffer(*m_commandBuffer, &commandBufferBeginInfo));
    707 }
    708 
    709 void ImageClearingTestInstance::endCommandBuffer (void) const
    710 {
    711 	VK_CHECK(m_vkd.endCommandBuffer(*m_commandBuffer));
    712 }
    713 
    714 void ImageClearingTestInstance::submitCommandBuffer (void) const
    715 {
    716 	const VkFenceCreateInfo fenceCreateInfo							=
    717 	{
    718 		VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,					// VkStructureType       sType;
    719 		DE_NULL,												// const void*           pNext;
    720 		0u														// VkFenceCreateFlags    flags;
    721 	};
    722 
    723 	const Unique<VkFence>					fence					(createFence(m_vkd, m_device, &fenceCreateInfo));
    724 
    725 	const VkSubmitInfo						submitInfo				=
    726 	{
    727 		VK_STRUCTURE_TYPE_SUBMIT_INFO,							// VkStructureType                sType;
    728 		DE_NULL,												// const void*                    pNext;
    729 		0u,														// deUint32                       waitSemaphoreCount;
    730 		DE_NULL,												// const VkSemaphore*             pWaitSemaphores;
    731 		DE_NULL,												// const VkPipelineStageFlags*    pWaitDstStageMask;
    732 		1u,														// deUint32                       commandBufferCount;
    733 		&(*m_commandBuffer),									// const VkCommandBuffer*         pCommandBuffers;
    734 		0u,														// deUint32                       signalSemaphoreCount;
    735 		DE_NULL													// const VkSemaphore*             pSignalSemaphores;
    736 	};
    737 
    738 	VK_CHECK(m_vkd.queueSubmit(m_queue, 1, &submitInfo, *fence));
    739 
    740 	VK_CHECK(m_vkd.waitForFences(m_device, 1, &fence.get(), VK_TRUE, ~0ull));
    741 }
    742 
    743 void ImageClearingTestInstance::pipelineImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout) const
    744 {
    745 	const VkImageMemoryBarrier		imageBarrier	=
    746 	{
    747 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,		// VkStructureType			sType;
    748 		DE_NULL,									// const void*				pNext;
    749 		srcAccessMask,								// VkAccessFlags			srcAccessMask;
    750 		dstAccessMask,								// VkAccessFlags			dstAccessMask;
    751 		oldLayout,									// VkImageLayout			oldLayout;
    752 		newLayout,									// VkImageLayout			newLayout;
    753 		VK_QUEUE_FAMILY_IGNORED,					// deUint32					srcQueueFamilyIndex;
    754 		VK_QUEUE_FAMILY_IGNORED,					// deUint32					destQueueFamilyIndex;
    755 		*m_image,									// VkImage					image;
    756 		{
    757 			m_imageAspectFlags,							// VkImageAspectFlags	aspectMask;
    758 			0u,											// deUint32				baseMipLevel;
    759 			VK_REMAINING_MIP_LEVELS,					// deUint32				levelCount;
    760 			0u,											// deUint32				baseArrayLayer;
    761 			1u,											// deUint32				layerCount;
    762 		},											// VkImageSubresourceRange	subresourceRange;
    763 	};
    764 
    765 	m_vkd.cmdPipelineBarrier(*m_commandBuffer, srcStageMask, dstStageMask, 0, 0, DE_NULL, 0, DE_NULL, 1, &imageBarrier);
    766 }
    767 
    768 de::MovePtr<TextureLevelPyramid> ImageClearingTestInstance::readImage (VkImageAspectFlags aspectMask) const
    769 {
    770 	const TextureFormat					tcuFormat		= aspectMask == VK_IMAGE_ASPECT_COLOR_BIT ? mapVkFormat(m_params.imageFormat) :
    771 														  aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT ? getDepthCopyFormat(m_params.imageFormat) :
    772 														  aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT ? getStencilCopyFormat(m_params.imageFormat) :
    773 														  TextureFormat();
    774 	const deUint32						pixelSize		= getPixelSize(tcuFormat);
    775 	const deUint32						alignment		= 4;	// subsequent mip levels aligned to 4 bytes
    776 	const std::vector<deUint32>			mipLevelSizes	= getImageMipLevelSizes(pixelSize, m_params.imageExtent, m_imageMipLevels, alignment);
    777 	const VkDeviceSize					imageTotalSize	= std::accumulate(mipLevelSizes.begin(), mipLevelSizes.end(), 0u);
    778 
    779 	de::MovePtr<TextureLevelPyramid>	result			(new TextureLevelPyramid(tcuFormat, m_imageMipLevels));
    780 	Move<VkBuffer>						buffer;
    781 	de::MovePtr<Allocation>				bufferAlloc;
    782 
    783 	// Create destination buffer
    784 	{
    785 		const VkBufferCreateInfo	bufferParams	=
    786 		{
    787 			VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,		// VkStructureType		sType;
    788 			DE_NULL,									// const void*			pNext;
    789 			0u,											// VkBufferCreateFlags	flags;
    790 			imageTotalSize,								// VkDeviceSize			size;
    791 			VK_BUFFER_USAGE_TRANSFER_DST_BIT,			// VkBufferUsageFlags	usage;
    792 			VK_SHARING_MODE_EXCLUSIVE,					// VkSharingMode		sharingMode;
    793 			0u,											// deUint32				queueFamilyIndexCount;
    794 			DE_NULL										// const deUint32*		pQueueFamilyIndices;
    795 		};
    796 
    797 		buffer		= createBuffer(m_vkd, m_device, &bufferParams);
    798 		bufferAlloc	= m_allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, *buffer), MemoryRequirement::HostVisible);
    799 		VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
    800 	}
    801 
    802 	// Barriers for copying image to buffer
    803 
    804 	const VkBufferMemoryBarrier		bufferBarrier	=
    805 	{
    806 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,	// VkStructureType	sType;
    807 		DE_NULL,									// const void*		pNext;
    808 		VK_ACCESS_TRANSFER_WRITE_BIT,				// VkAccessFlags	srcAccessMask;
    809 		VK_ACCESS_HOST_READ_BIT,					// VkAccessFlags	dstAccessMask;
    810 		VK_QUEUE_FAMILY_IGNORED,					// deUint32			srcQueueFamilyIndex;
    811 		VK_QUEUE_FAMILY_IGNORED,					// deUint32			dstQueueFamilyIndex;
    812 		*buffer,									// VkBuffer			buffer;
    813 		0u,											// VkDeviceSize		offset;
    814 		imageTotalSize,								// VkDeviceSize		size;
    815 	};
    816 
    817 	// Copy image to buffer
    818 	std::vector<VkBufferImageCopy> copyRegions;
    819 	{
    820 		deUint32 offset = 0u;
    821 		for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
    822 		{
    823 			const VkExtent3D		extent	= getMipLevelExtent(m_params.imageExtent, mipLevel);
    824 			const VkBufferImageCopy	region	=
    825 			{
    826 				offset,									// VkDeviceSize				bufferOffset;
    827 				0u,										// deUint32					bufferRowLength;
    828 				0u,										// deUint32					bufferImageHeight;
    829 				{ aspectMask, mipLevel, 0u, 1u },		// VkImageSubresourceLayers	imageSubresource;
    830 				{ 0, 0, 0 },							// VkOffset3D				imageOffset;
    831 				extent									// VkExtent3D				imageExtent;
    832 			};
    833 			copyRegions.push_back(region);
    834 			offset += mipLevelSizes[mipLevel];
    835 		}
    836 	}
    837 
    838 	beginCommandBuffer(0);
    839 
    840 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
    841 						 VK_PIPELINE_STAGE_TRANSFER_BIT,
    842 						 VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
    843 						 VK_ACCESS_TRANSFER_READ_BIT,
    844 						 VK_IMAGE_LAYOUT_GENERAL,
    845 						 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
    846 
    847 	m_vkd.cmdCopyImageToBuffer(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, static_cast<deUint32>(copyRegions.size()), &copyRegions[0]);
    848 	m_vkd.cmdPipelineBarrier(*m_commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
    849 
    850 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
    851 						 VK_PIPELINE_STAGE_TRANSFER_BIT,
    852 						 VK_ACCESS_TRANSFER_READ_BIT,
    853 						 VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
    854 						 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
    855 						 VK_IMAGE_LAYOUT_GENERAL);
    856 
    857 	endCommandBuffer();
    858 	submitCommandBuffer();
    859 
    860 	invalidateMappedMemoryRange(m_vkd, m_device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), imageTotalSize);
    861 
    862 	{
    863 		deUint32 offset = 0u;
    864 		for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
    865 		{
    866 			const VkExtent3D	extent		= getMipLevelExtent(m_params.imageExtent, mipLevel);
    867 			const void*			pLevelData	= static_cast<const void*>(reinterpret_cast<deUint8*>(bufferAlloc->getHostPtr()) + offset);
    868 
    869 			result->allocLevel(mipLevel, extent.width, extent.height, extent.depth);
    870 			copy(result->getLevel(mipLevel), ConstPixelBufferAccess(result->getFormat(), result->getLevel(mipLevel).getSize(), pLevelData));
    871 
    872 			offset += mipLevelSizes[mipLevel];
    873 		}
    874 	}
    875 
    876 	return result;
    877 }
    878 
    879 tcu::TestStatus ImageClearingTestInstance::verifyResultImage (const std::string& successMessage, const UVec4& clearCoords) const
    880 {
    881 	const bool useClearRange = clearCoords != UVec4();
    882 	DE_ASSERT(!useClearRange || m_params.imageExtent.depth == 1u);
    883 
    884 	if (getIsDepthFormat(m_params.imageFormat))
    885 	{
    886 		DE_ASSERT(m_imageMipLevels == 1u);
    887 
    888 		de::MovePtr<TextureLevelPyramid>	image			= readImage(VK_IMAGE_ASPECT_DEPTH_BIT);
    889 		std::string							message;
    890 		float								depthValue;
    891 
    892 		for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
    893 		for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
    894 		{
    895 			if (!useClearRange || isInClearRange(clearCoords, x, y))
    896 				depthValue = m_params.clearValue[0].depthStencil.depth;
    897 			else
    898 				depthValue = m_params.initValue.depthStencil.depth;
    899 
    900 			if (!comparePixelToDepthClearValue(image->getLevel(0), x, y, depthValue, message))
    901 				return TestStatus::fail("Depth value mismatch! " + message);
    902 		}
    903 	}
    904 
    905 	if (getIsStencilFormat(m_params.imageFormat))
    906 	{
    907 		DE_ASSERT(m_imageMipLevels == 1u);
    908 
    909 		de::MovePtr<TextureLevelPyramid>	image			= readImage(VK_IMAGE_ASPECT_STENCIL_BIT);
    910 		std::string							message;
    911 		deUint32							stencilValue;
    912 
    913 		for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
    914 		for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
    915 		{
    916 			if (!useClearRange || isInClearRange(clearCoords, x, y))
    917 				stencilValue = m_params.clearValue[0].depthStencil.stencil;
    918 			else
    919 				stencilValue = m_params.initValue.depthStencil.stencil;
    920 
    921 			if (!comparePixelToStencilClearValue(image->getLevel(0), x, y, stencilValue, message))
    922 				return TestStatus::fail("Stencil value mismatch! " + message);
    923 		}
    924 	}
    925 
    926 	if (!isDepthStencilFormat(m_params.imageFormat))
    927 	{
    928 		de::MovePtr<TextureLevelPyramid>	image			= readImage(VK_IMAGE_ASPECT_COLOR_BIT);
    929 		std::string							message;
    930 		const VkClearColorValue*			pColorValue;
    931 
    932 		for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
    933 		{
    934 			const int			clearColorNdx	= (mipLevel < m_thresholdMipLevel ? 0 : 1);
    935 			const VkExtent3D	extent			= getMipLevelExtent(m_params.imageExtent, mipLevel);
    936 
    937 			for (deUint32 z = 0; z < extent.depth;  ++z)
    938 			for (deUint32 y = 0; y < extent.height; ++y)
    939 			for (deUint32 x = 0; x < extent.width;  ++x)
    940 			{
    941 				if (!useClearRange || isInClearRange(clearCoords, x, y))
    942 					pColorValue = &m_params.clearValue[clearColorNdx].color;
    943 				else
    944 					pColorValue = &m_params.initValue.color;
    945 
    946 				if (!comparePixelToColorClearValue(image->getLevel(mipLevel), x, y, z, *pColorValue, message))
    947 					return TestStatus::fail("Color value mismatch! " + message);
    948 			}
    949 		}
    950 	}
    951 
    952 	return TestStatus::pass(successMessage);
    953 }
    954 
    955 void ImageClearingTestInstance::beginRenderPass (VkSubpassContents content, VkClearValue clearValue) const
    956 {
    957 	const VkRenderPassBeginInfo renderPassBeginInfo =
    958 	{
    959 		VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,				// VkStructureType		sType;
    960 		DE_NULL,												// const void*			pNext;
    961 		*m_renderPass,											// VkRenderPass			renderPass;
    962 		*m_frameBuffer,											// VkFramebuffer		framebuffer;
    963 		{
    964 			{ 0, 0 },												// VkOffset2D			offset;
    965 			{
    966 				m_params.imageExtent.width,								// deUint32				width;
    967 				m_params.imageExtent.height								// deUint32				height;
    968 			}														// VkExtent2D			extent;
    969 		},														// VkRect2D				renderArea;
    970 		1u,														// deUint32				clearValueCount;
    971 		&clearValue												// const VkClearValue*	pClearValues;
    972 	};
    973 
    974 	m_vkd.cmdBeginRenderPass(*m_commandBuffer, &renderPassBeginInfo, content);
    975 }
    976 
    977 class ClearColorImageTestInstance : public ImageClearingTestInstance
    978 {
    979 public:
    980 				ClearColorImageTestInstance	(Context& context, const TestParams& testParams) : ImageClearingTestInstance (context, testParams) {}
    981 	TestStatus	iterate						(void);
    982 };
    983 
    984 TestStatus ClearColorImageTestInstance::iterate (void)
    985 {
    986 	std::vector<VkImageSubresourceRange> subresourceRanges;
    987 
    988 	if (m_imageMipLevels == 1)
    989 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, 0u, 1u, 0u, 1u));
    990 	else
    991 	{
    992 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags,	0u,						m_thresholdMipLevel,		0u, 1u));
    993 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags,	m_thresholdMipLevel,	VK_REMAINING_MIP_LEVELS,	0u, 1u));
    994 	}
    995 
    996 	beginCommandBuffer(0);
    997 
    998 	pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,				// VkPipelineStageFlags		srcStageMask
    999 						 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,			// VkPipelineStageFlags		dstStageMask
   1000 						 0,												// VkAccessFlags			srcAccessMask
   1001 						 (m_isAttachmentFormat
   1002 							? VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
   1003 							: VK_ACCESS_TRANSFER_WRITE_BIT),			// VkAccessFlags			dstAccessMask
   1004 						 VK_IMAGE_LAYOUT_UNDEFINED,						// VkImageLayout			oldLayout;
   1005 						 (m_isAttachmentFormat
   1006 							? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
   1007 							: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));	// VkImageLayout			newLayout;
   1008 
   1009 	if (m_isAttachmentFormat)
   1010 	{
   1011 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
   1012 		m_vkd.cmdEndRenderPass(*m_commandBuffer);
   1013 
   1014 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,		// VkPipelineStageFlags		srcStageMask
   1015 			VK_PIPELINE_STAGE_TRANSFER_BIT,								// VkPipelineStageFlags		dstStageMask
   1016 			VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,						// VkAccessFlags			srcAccessMask
   1017 			VK_ACCESS_TRANSFER_WRITE_BIT,								// VkAccessFlags			dstAccessMask
   1018 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,					// VkImageLayout			oldLayout;
   1019 			VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);						// VkImageLayout			newLayout;
   1020 	}
   1021 
   1022 	// Different clear color per range
   1023 	for (std::size_t i = 0u; i < subresourceRanges.size(); ++i)
   1024 		m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[i].color, 1, &subresourceRanges[i]);
   1025 
   1026 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		srcStageMask
   1027 						 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
   1028 						 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			srcAccessMask
   1029 						 VK_ACCESS_TRANSFER_READ_BIT,					// VkAccessFlags			dstAccessMask
   1030 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,			// VkImageLayout			oldLayout;
   1031 						 VK_IMAGE_LAYOUT_GENERAL);						// VkImageLayout			newLayout;
   1032 
   1033 	endCommandBuffer();
   1034 	submitCommandBuffer();
   1035 
   1036 	return verifyResultImage("cmdClearColorImage passed");
   1037 }
   1038 
   1039 class ClearDepthStencilImageTestInstance : public ImageClearingTestInstance
   1040 {
   1041 public:
   1042 				ClearDepthStencilImageTestInstance	(Context& context, const TestParams& testParams) : ImageClearingTestInstance (context, testParams) {}
   1043 	TestStatus	iterate								(void);
   1044 };
   1045 
   1046 TestStatus ClearDepthStencilImageTestInstance::iterate (void)
   1047 {
   1048 	const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(m_imageAspectFlags, 0u, 1u, 0u, 1u);
   1049 
   1050 	beginCommandBuffer(0);
   1051 
   1052 	pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,					// VkPipelineStageFlags		srcStageMask
   1053 						 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,				// VkPipelineStageFlags		dstStageMask
   1054 						 0,													// VkAccessFlags			srcAccessMask
   1055 						 (m_isAttachmentFormat
   1056 							?	VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
   1057 							:	VK_ACCESS_TRANSFER_WRITE_BIT),				// VkAccessFlags			dstAccessMask
   1058 						 VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout			oldLayout;
   1059 						 (m_isAttachmentFormat
   1060 							?	VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
   1061 							:	VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));		// VkImageLayout			newLayout;
   1062 
   1063 	if (m_isAttachmentFormat)
   1064 	{
   1065 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
   1066 		m_vkd.cmdEndRenderPass(*m_commandBuffer);
   1067 
   1068 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,					// VkPipelineStageFlags		srcStageMask
   1069 							 VK_PIPELINE_STAGE_TRANSFER_BIT,						// VkPipelineStageFlags		dstStageMask
   1070 							 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,			// VkAccessFlags			srcAccessMask
   1071 							 VK_ACCESS_TRANSFER_WRITE_BIT,							// VkAccessFlags			dstAccessMask
   1072 							 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,		// VkImageLayout			oldLayout;
   1073 							 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);					// VkImageLayout			newLayout;
   1074 	}
   1075 
   1076 	m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, 1, &subresourceRange);
   1077 
   1078 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,					// VkPipelineStageFlags		srcStageMask
   1079 						 VK_PIPELINE_STAGE_TRANSFER_BIT,					// VkPipelineStageFlags		dstStageMask
   1080 						 VK_ACCESS_TRANSFER_WRITE_BIT,						// VkAccessFlags			srcAccessMask
   1081 						 VK_ACCESS_TRANSFER_READ_BIT,						// VkAccessFlags			dstAccessMask
   1082 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,				// VkImageLayout			oldLayout;
   1083 						 VK_IMAGE_LAYOUT_GENERAL);							// VkImageLayout			newLayout;
   1084 
   1085 	endCommandBuffer();
   1086 	submitCommandBuffer();
   1087 
   1088 	return verifyResultImage("cmdClearDepthStencilImage passed");
   1089 }
   1090 
   1091 class ClearAttachmentTestInstance : public ImageClearingTestInstance
   1092 {
   1093 public:
   1094 	enum ClearType
   1095 	{
   1096 		FULL_CLEAR,
   1097 		PARTIAL_CLEAR,
   1098 	};
   1099 
   1100 	ClearAttachmentTestInstance (Context& context, const TestParams& testParams, const ClearType clearType = FULL_CLEAR)
   1101 		: ImageClearingTestInstance	(context, testParams)
   1102 		, m_clearType				(clearType)
   1103 	{
   1104 		if (!m_isAttachmentFormat)
   1105 			TCU_THROW(NotSupportedError, "Format not renderable");
   1106 	}
   1107 
   1108 	TestStatus iterate (void)
   1109 	{
   1110 		const VkClearAttachment clearAttachment =
   1111 		{
   1112 			m_imageAspectFlags,					// VkImageAspectFlags	aspectMask;
   1113 			0u,									// deUint32				colorAttachment;
   1114 			m_params.clearValue[0]				// VkClearValue			clearValue;
   1115 		};
   1116 
   1117 		UVec4						clearCoords;
   1118 		std::vector<VkClearRect>	clearRects;
   1119 
   1120 		if (m_clearType == FULL_CLEAR)
   1121 		{
   1122 			const VkClearRect rect =
   1123 			{
   1124 				{
   1125 					{ 0, 0 },																	// VkOffset2D    offset;
   1126 					{ m_params.imageExtent.width, m_params.imageExtent.height }					// VkExtent2D    extent;
   1127 				},																			// VkRect2D	rect;
   1128 				0u,																			// deUint32	baseArrayLayer;
   1129 				1u																			// deUint32	layerCount;
   1130 			};
   1131 
   1132 			clearRects.push_back(rect);
   1133 		}
   1134 		else
   1135 		{
   1136 			const deUint32	clearX		= m_params.imageExtent.width  / 4u;
   1137 			const deUint32	clearY		= m_params.imageExtent.height / 4u;
   1138 			const deUint32	clearWidth	= m_params.imageExtent.width  / 2u;
   1139 			const deUint32	clearHeight	= m_params.imageExtent.height / 2u;
   1140 
   1141 			clearCoords	= UVec4(clearX,					clearY,
   1142 								clearX + clearWidth,	clearY + clearHeight);
   1143 
   1144 			const VkClearRect rects[2] =
   1145 			{
   1146 				{
   1147 					{
   1148 						{ 0,							static_cast<deInt32>(clearY)	},		// VkOffset2D    offset;
   1149 						{ m_params.imageExtent.width,	clearHeight						}		// VkExtent2D    extent;
   1150 					},																		// VkRect2D	rect;
   1151 					0u,																		// deUint32	baseArrayLayer;
   1152 					1u																		// deUint32	layerCount;
   1153 				},
   1154 				{
   1155 					{
   1156 						{ static_cast<deInt32>(clearX),	0							},			// VkOffset2D    offset;
   1157 						{ clearWidth,					m_params.imageExtent.height	}			// VkExtent2D    extent;
   1158 					},																		// VkRect2D	rect;
   1159 					0u,																		// deUint32	baseArrayLayer;
   1160 					1u																		// deUint32	layerCount;
   1161 				}
   1162 			};
   1163 
   1164 			clearRects.push_back(rects[0]);
   1165 			clearRects.push_back(rects[1]);
   1166 		}
   1167 
   1168 		const bool			isDepthStencil		= isDepthStencilFormat(m_params.imageFormat);
   1169 		const VkAccessFlags	accessMask			= (isDepthStencil ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT     : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
   1170 		const VkImageLayout	attachmentLayout	= (isDepthStencil ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
   1171 
   1172 		beginCommandBuffer(0);
   1173 
   1174 		pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,				// VkPipelineStageFlags		srcStageMask
   1175 							 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,			// VkPipelineStageFlags		dstStageMask
   1176 							 0,												// VkAccessFlags			srcAccessMask
   1177 							 accessMask,									// VkAccessFlags			dstAccessMask
   1178 							 VK_IMAGE_LAYOUT_UNDEFINED,						// VkImageLayout			oldLayout;
   1179 							 attachmentLayout);								// VkImageLayout			newLayout;
   1180 
   1181 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
   1182 		m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, static_cast<deUint32>(clearRects.size()), &clearRects[0]);
   1183 		m_vkd.cmdEndRenderPass(*m_commandBuffer);
   1184 
   1185 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,			// VkPipelineStageFlags		srcStageMask
   1186 							 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
   1187 							 accessMask,									// VkAccessFlags			srcAccessMask
   1188 							 VK_ACCESS_TRANSFER_READ_BIT,					// VkAccessFlags			dstAccessMask
   1189 							 attachmentLayout,								// VkImageLayout			oldLayout;
   1190 							 VK_IMAGE_LAYOUT_GENERAL);						// VkImageLayout			newLayout;
   1191 
   1192 		endCommandBuffer();
   1193 		submitCommandBuffer();
   1194 
   1195 		return verifyResultImage("cmdClearAttachments passed", clearCoords);
   1196 	}
   1197 
   1198 private:
   1199 	const ClearType	m_clearType;
   1200 };
   1201 
   1202 class PartialClearAttachmentTestInstance : public ClearAttachmentTestInstance
   1203 {
   1204 public:
   1205 	PartialClearAttachmentTestInstance (Context& context, const TestParams& testParams) : ClearAttachmentTestInstance (context, testParams, PARTIAL_CLEAR) {}
   1206 };
   1207 
   1208 VkClearValue makeClearColorValue (VkFormat format, float r, float g, float b, float a)
   1209 {
   1210 	const	TextureFormat tcuFormat	= mapVkFormat(format);
   1211 	VkClearValue clearValue;
   1212 
   1213 	if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_FLOATING_POINT
   1214 		|| getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_FIXED_POINT
   1215 		|| getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT)
   1216 	{
   1217 		clearValue.color.float32[0] = r;
   1218 		clearValue.color.float32[1] = g;
   1219 		clearValue.color.float32[2] = b;
   1220 		clearValue.color.float32[3] = a;
   1221 	}
   1222 	else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
   1223 	{
   1224 		UVec4 maxValues = getFormatMaxUintValue(tcuFormat);
   1225 
   1226 		clearValue.color.uint32[0] = (deUint32)((float)maxValues[0] * r);
   1227 		clearValue.color.uint32[1] = (deUint32)((float)maxValues[1] * g);
   1228 		clearValue.color.uint32[2] = (deUint32)((float)maxValues[2] * b);
   1229 		clearValue.color.uint32[3] = (deUint32)((float)maxValues[3] * a);
   1230 	}
   1231 	else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER)
   1232 	{
   1233 		IVec4 maxValues = getFormatMaxIntValue(tcuFormat);
   1234 
   1235 		clearValue.color.int32[0] = (deUint32)((float)maxValues[0] * r);
   1236 		clearValue.color.int32[1] = (deUint32)((float)maxValues[1] * g);
   1237 		clearValue.color.int32[2] = (deUint32)((float)maxValues[2] * b);
   1238 		clearValue.color.int32[3] = (deUint32)((float)maxValues[3] * a);
   1239 	}
   1240 	else
   1241 		DE_FATAL("Unknown channel class");
   1242 
   1243 	return clearValue;
   1244 }
   1245 
   1246 std::string getFormatCaseName (VkFormat format)
   1247 {
   1248 	return de::toLower(de::toString(getFormatStr(format)).substr(10));
   1249 }
   1250 
   1251 const char* getImageTypeCaseName (VkImageType type)
   1252 {
   1253 	const char* s_names[] =
   1254 	{
   1255 		"1d",
   1256 		"2d",
   1257 		"3d"
   1258 	};
   1259 	return de::getSizedArrayElement<VK_IMAGE_TYPE_LAST>(s_names, type);
   1260 }
   1261 
   1262 } // anonymous
   1263 
   1264 TestCaseGroup* createImageClearingTests (TestContext& testCtx)
   1265 {
   1266 	// Main testgroup.
   1267 	de::MovePtr<TestCaseGroup>	imageClearingTests						(new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
   1268 
   1269 	de::MovePtr<TestCaseGroup>	colorImageClearTests					(new TestCaseGroup(testCtx, "clear_color_image", "Color Image Clear Tests"));
   1270 	de::MovePtr<TestCaseGroup>	depthStencilImageClearTests				(new TestCaseGroup(testCtx, "clear_depth_stencil_image", "Color Depth/Stencil Image Tests"));
   1271 	de::MovePtr<TestCaseGroup>	colorAttachmentClearTests				(new TestCaseGroup(testCtx, "clear_color_attachment", "Color Color Attachment Tests"));
   1272 	de::MovePtr<TestCaseGroup>	depthStencilAttachmentClearTests		(new TestCaseGroup(testCtx, "clear_depth_stencil_attachment", "Color Depth/Stencil Attachment Tests"));
   1273 	de::MovePtr<TestCaseGroup>	partialColorAttachmentClearTests		(new TestCaseGroup(testCtx, "partial_clear_color_attachment", "Clear Partial Color Attachment Tests"));
   1274 	de::MovePtr<TestCaseGroup>	partialDepthStencilAttachmentClearTests	(new TestCaseGroup(testCtx, "partial_clear_depth_stencil_attachment", "Clear Partial Depth/Stencil Attachment Tests"));
   1275 
   1276 	// Some formats are commented out due to the tcu::TextureFormat does not support them yet.
   1277 	const VkFormat		colorImageFormatsToTest[]	=
   1278 	{
   1279 		VK_FORMAT_R4G4_UNORM_PACK8,
   1280 		VK_FORMAT_R4G4B4A4_UNORM_PACK16,
   1281 		VK_FORMAT_B4G4R4A4_UNORM_PACK16,
   1282 		VK_FORMAT_R5G6B5_UNORM_PACK16,
   1283 		VK_FORMAT_B5G6R5_UNORM_PACK16,
   1284 		VK_FORMAT_R5G5B5A1_UNORM_PACK16,
   1285 		VK_FORMAT_B5G5R5A1_UNORM_PACK16,
   1286 		VK_FORMAT_A1R5G5B5_UNORM_PACK16,
   1287 		VK_FORMAT_R8_UNORM,
   1288 		VK_FORMAT_R8_SNORM,
   1289 		VK_FORMAT_R8_USCALED,
   1290 		VK_FORMAT_R8_SSCALED,
   1291 		VK_FORMAT_R8_UINT,
   1292 		VK_FORMAT_R8_SINT,
   1293 		VK_FORMAT_R8_SRGB,
   1294 		VK_FORMAT_R8G8_UNORM,
   1295 		VK_FORMAT_R8G8_SNORM,
   1296 		VK_FORMAT_R8G8_USCALED,
   1297 		VK_FORMAT_R8G8_SSCALED,
   1298 		VK_FORMAT_R8G8_UINT,
   1299 		VK_FORMAT_R8G8_SINT,
   1300 		VK_FORMAT_R8G8_SRGB,
   1301 		VK_FORMAT_R8G8B8_UNORM,
   1302 		VK_FORMAT_R8G8B8_SNORM,
   1303 		VK_FORMAT_R8G8B8_USCALED,
   1304 		VK_FORMAT_R8G8B8_SSCALED,
   1305 		VK_FORMAT_R8G8B8_UINT,
   1306 		VK_FORMAT_R8G8B8_SINT,
   1307 		VK_FORMAT_R8G8B8_SRGB,
   1308 		VK_FORMAT_B8G8R8_UNORM,
   1309 		VK_FORMAT_B8G8R8_SNORM,
   1310 		VK_FORMAT_B8G8R8_USCALED,
   1311 		VK_FORMAT_B8G8R8_SSCALED,
   1312 		VK_FORMAT_B8G8R8_UINT,
   1313 		VK_FORMAT_B8G8R8_SINT,
   1314 		VK_FORMAT_B8G8R8_SRGB,
   1315 		VK_FORMAT_R8G8B8A8_UNORM,
   1316 		VK_FORMAT_R8G8B8A8_SNORM,
   1317 		VK_FORMAT_R8G8B8A8_USCALED,
   1318 		VK_FORMAT_R8G8B8A8_SSCALED,
   1319 		VK_FORMAT_R8G8B8A8_UINT,
   1320 		VK_FORMAT_R8G8B8A8_SINT,
   1321 		VK_FORMAT_R8G8B8A8_SRGB,
   1322 		VK_FORMAT_B8G8R8A8_UNORM,
   1323 		VK_FORMAT_B8G8R8A8_SNORM,
   1324 		VK_FORMAT_B8G8R8A8_USCALED,
   1325 		VK_FORMAT_B8G8R8A8_SSCALED,
   1326 		VK_FORMAT_B8G8R8A8_UINT,
   1327 		VK_FORMAT_B8G8R8A8_SINT,
   1328 		VK_FORMAT_B8G8R8A8_SRGB,
   1329 		VK_FORMAT_A8B8G8R8_UNORM_PACK32,
   1330 		VK_FORMAT_A8B8G8R8_SNORM_PACK32,
   1331 		VK_FORMAT_A8B8G8R8_USCALED_PACK32,
   1332 		VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
   1333 		VK_FORMAT_A8B8G8R8_UINT_PACK32,
   1334 		VK_FORMAT_A8B8G8R8_SINT_PACK32,
   1335 		VK_FORMAT_A8B8G8R8_SRGB_PACK32,
   1336 		VK_FORMAT_A2R10G10B10_UNORM_PACK32,
   1337 		VK_FORMAT_A2R10G10B10_SNORM_PACK32,
   1338 		VK_FORMAT_A2R10G10B10_USCALED_PACK32,
   1339 		VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
   1340 		VK_FORMAT_A2R10G10B10_UINT_PACK32,
   1341 		VK_FORMAT_A2R10G10B10_SINT_PACK32,
   1342 		VK_FORMAT_A2B10G10R10_UNORM_PACK32,
   1343 		VK_FORMAT_A2B10G10R10_SNORM_PACK32,
   1344 		VK_FORMAT_A2B10G10R10_USCALED_PACK32,
   1345 		VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
   1346 		VK_FORMAT_A2B10G10R10_UINT_PACK32,
   1347 		VK_FORMAT_A2B10G10R10_SINT_PACK32,
   1348 		VK_FORMAT_R16_UNORM,
   1349 		VK_FORMAT_R16_SNORM,
   1350 		VK_FORMAT_R16_USCALED,
   1351 		VK_FORMAT_R16_SSCALED,
   1352 		VK_FORMAT_R16_UINT,
   1353 		VK_FORMAT_R16_SINT,
   1354 		VK_FORMAT_R16_SFLOAT,
   1355 		VK_FORMAT_R16G16_UNORM,
   1356 		VK_FORMAT_R16G16_SNORM,
   1357 		VK_FORMAT_R16G16_USCALED,
   1358 		VK_FORMAT_R16G16_SSCALED,
   1359 		VK_FORMAT_R16G16_UINT,
   1360 		VK_FORMAT_R16G16_SINT,
   1361 		VK_FORMAT_R16G16_SFLOAT,
   1362 		VK_FORMAT_R16G16B16_UNORM,
   1363 		VK_FORMAT_R16G16B16_SNORM,
   1364 		VK_FORMAT_R16G16B16_USCALED,
   1365 		VK_FORMAT_R16G16B16_SSCALED,
   1366 		VK_FORMAT_R16G16B16_UINT,
   1367 		VK_FORMAT_R16G16B16_SINT,
   1368 		VK_FORMAT_R16G16B16_SFLOAT,
   1369 		VK_FORMAT_R16G16B16A16_UNORM,
   1370 		VK_FORMAT_R16G16B16A16_SNORM,
   1371 		VK_FORMAT_R16G16B16A16_USCALED,
   1372 		VK_FORMAT_R16G16B16A16_SSCALED,
   1373 		VK_FORMAT_R16G16B16A16_UINT,
   1374 		VK_FORMAT_R16G16B16A16_SINT,
   1375 		VK_FORMAT_R16G16B16A16_SFLOAT,
   1376 		VK_FORMAT_R32_UINT,
   1377 		VK_FORMAT_R32_SINT,
   1378 		VK_FORMAT_R32_SFLOAT,
   1379 		VK_FORMAT_R32G32_UINT,
   1380 		VK_FORMAT_R32G32_SINT,
   1381 		VK_FORMAT_R32G32_SFLOAT,
   1382 		VK_FORMAT_R32G32B32_UINT,
   1383 		VK_FORMAT_R32G32B32_SINT,
   1384 		VK_FORMAT_R32G32B32_SFLOAT,
   1385 		VK_FORMAT_R32G32B32A32_UINT,
   1386 		VK_FORMAT_R32G32B32A32_SINT,
   1387 		VK_FORMAT_R32G32B32A32_SFLOAT,
   1388 //		VK_FORMAT_R64_UINT,
   1389 //		VK_FORMAT_R64_SINT,
   1390 //		VK_FORMAT_R64_SFLOAT,
   1391 //		VK_FORMAT_R64G64_UINT,
   1392 //		VK_FORMAT_R64G64_SINT,
   1393 //		VK_FORMAT_R64G64_SFLOAT,
   1394 //		VK_FORMAT_R64G64B64_UINT,
   1395 //		VK_FORMAT_R64G64B64_SINT,
   1396 //		VK_FORMAT_R64G64B64_SFLOAT,
   1397 //		VK_FORMAT_R64G64B64A64_UINT,
   1398 //		VK_FORMAT_R64G64B64A64_SINT,
   1399 //		VK_FORMAT_R64G64B64A64_SFLOAT,
   1400 		VK_FORMAT_B10G11R11_UFLOAT_PACK32,
   1401 		VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
   1402 //		VK_FORMAT_BC1_RGB_UNORM_BLOCK,
   1403 //		VK_FORMAT_BC1_RGB_SRGB_BLOCK,
   1404 //		VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
   1405 //		VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
   1406 //		VK_FORMAT_BC2_UNORM_BLOCK,
   1407 //		VK_FORMAT_BC2_SRGB_BLOCK,
   1408 //		VK_FORMAT_BC3_UNORM_BLOCK,
   1409 //		VK_FORMAT_BC3_SRGB_BLOCK,
   1410 //		VK_FORMAT_BC4_UNORM_BLOCK,
   1411 //		VK_FORMAT_BC4_SNORM_BLOCK,
   1412 //		VK_FORMAT_BC5_UNORM_BLOCK,
   1413 //		VK_FORMAT_BC5_SNORM_BLOCK,
   1414 //		VK_FORMAT_BC6H_UFLOAT_BLOCK,
   1415 //		VK_FORMAT_BC6H_SFLOAT_BLOCK,
   1416 //		VK_FORMAT_BC7_UNORM_BLOCK,
   1417 //		VK_FORMAT_BC7_SRGB_BLOCK,
   1418 //		VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
   1419 //		VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
   1420 //		VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
   1421 //		VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
   1422 //		VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
   1423 //		VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
   1424 //		VK_FORMAT_EAC_R11_UNORM_BLOCK,
   1425 //		VK_FORMAT_EAC_R11_SNORM_BLOCK,
   1426 //		VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
   1427 //		VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
   1428 //		VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
   1429 //		VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
   1430 //		VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
   1431 //		VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
   1432 //		VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
   1433 //		VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
   1434 //		VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
   1435 //		VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
   1436 //		VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
   1437 //		VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
   1438 //		VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
   1439 //		VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
   1440 //		VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
   1441 //		VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
   1442 //		VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
   1443 //		VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
   1444 //		VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
   1445 //		VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
   1446 //		VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
   1447 //		VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
   1448 //		VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
   1449 //		VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
   1450 //		VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
   1451 //		VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
   1452 //		VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
   1453 //		VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
   1454 //		VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
   1455 //		VK_FORMAT_ASTC_12x12_SRGB_BLOCK
   1456 	};
   1457 	const size_t	numOfColorImageFormatsToTest			= DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
   1458 
   1459 	const VkFormat	depthStencilImageFormatsToTest[]		=
   1460 	{
   1461 		VK_FORMAT_D16_UNORM,
   1462 		VK_FORMAT_X8_D24_UNORM_PACK32,
   1463 		VK_FORMAT_D32_SFLOAT,
   1464 		VK_FORMAT_S8_UINT,
   1465 		VK_FORMAT_D16_UNORM_S8_UINT,
   1466 		VK_FORMAT_D24_UNORM_S8_UINT,
   1467 		VK_FORMAT_D32_SFLOAT_S8_UINT
   1468 	};
   1469 	const size_t	numOfDepthStencilImageFormatsToTest		= DE_LENGTH_OF_ARRAY(depthStencilImageFormatsToTest);
   1470 
   1471 	// Clear color image
   1472 	{
   1473 		const VkImageType			imageTypesToTest[]		=
   1474 		{
   1475 			VK_IMAGE_TYPE_1D,
   1476 			VK_IMAGE_TYPE_2D,
   1477 			VK_IMAGE_TYPE_3D
   1478 		};
   1479 		const size_t				numOfImageTypesToTest	= DE_LENGTH_OF_ARRAY(imageTypesToTest);
   1480 
   1481 		const VkExtent3D			imageDimensionsByType[]	=
   1482 		{
   1483 			{ 256, 1, 1},
   1484 			{ 256, 256, 1},
   1485 			{ 256, 256, 16}
   1486 		};
   1487 
   1488 		for (size_t	imageTypeIndex = 0; imageTypeIndex < numOfImageTypesToTest; ++imageTypeIndex)
   1489 		for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
   1490 		{
   1491 			const VkFormat		format		= colorImageFormatsToTest[imageFormatIndex];
   1492 			const TestParams	testParams	=
   1493 			{
   1494 				false,														// bool				useSingleMipLevel;
   1495 				imageTypesToTest[imageTypeIndex],							// VkImageType		imageType;
   1496 				format,														// VkFormat			imageFormat;
   1497 				imageDimensionsByType[imageTypeIndex],						// VkExtent3D		imageExtent;
   1498 				makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),		// VkClearValue		initValue;
   1499 				{
   1500 					makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),	// VkClearValue		clearValue[0];
   1501 					makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),	// VkClearValue		clearValue[1];
   1502 				}
   1503 			};
   1504 
   1505 			std::ostringstream	testCaseName;
   1506 			testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(format);
   1507 
   1508 			colorImageClearTests->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Image", testParams));
   1509 		}
   1510 
   1511 		imageClearingTests->addChild(colorImageClearTests.release());
   1512 	}
   1513 
   1514 	// Clear depth/stencil image
   1515 	{
   1516 		TestParams testParams =
   1517 		{
   1518 			true,											// bool				useSingleMipLevel;
   1519 			VK_IMAGE_TYPE_2D,								// VkImageType		imageType;
   1520 			VK_FORMAT_UNDEFINED,							// VkFormat			format;
   1521 			{ 256, 256, 1 },								// VkExtent3D		extent;
   1522 			makeClearValueDepthStencil(0.5f, 0x03),			// VkClearValue		initValue
   1523 			{
   1524 				makeClearValueDepthStencil(0.1f, 0x06),		// VkClearValue		clearValue[0];
   1525 				makeClearValueDepthStencil(0.3f, 0x04),		// VkClearValue		clearValue[1];
   1526 			}
   1527 		};
   1528 
   1529 		for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
   1530 		{
   1531 			testParams.imageFormat = depthStencilImageFormatsToTest[imageFormatIndex];
   1532 
   1533 			std::ostringstream	testCaseName;
   1534 			testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(testParams.imageFormat);
   1535 
   1536 			depthStencilImageClearTests->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Image", testParams));
   1537 		}
   1538 
   1539 		imageClearingTests->addChild(depthStencilImageClearTests.release());
   1540 	}
   1541 
   1542 	// Clear color attachment
   1543 	{
   1544 		for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
   1545 		{
   1546 			const VkFormat		format		= colorImageFormatsToTest[imageFormatIndex];
   1547 			const TestParams	testParams	=
   1548 			{
   1549 				true,														// bool				useSingleMipLevel;
   1550 				VK_IMAGE_TYPE_2D,											// VkImageType		imageType;
   1551 				format,														// VkFormat			format;
   1552 				{ 256, 256, 1 },											// VkExtent3D		extent;
   1553 				makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),		// VkClearValue		initValue
   1554 				{
   1555 					makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),	// VkClearValue		clearValue[0];
   1556 					makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),	// VkClearValue		clearValue[1];
   1557 				}
   1558 			};
   1559 
   1560 			std::ostringstream	testCaseName;
   1561 			testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(format);
   1562 
   1563 			colorAttachmentClearTests->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Attachment", testParams));
   1564 			partialColorAttachmentClearTests->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Partial Clear Color Attachment", testParams));
   1565 		}
   1566 
   1567 		imageClearingTests->addChild(colorAttachmentClearTests.release());
   1568 		imageClearingTests->addChild(partialColorAttachmentClearTests.release());
   1569 	}
   1570 
   1571 	// Clear depth/stencil attachment
   1572 	{
   1573 		TestParams testParams =
   1574 		{
   1575 			true,											// bool				useSingleMipLevel;
   1576 			VK_IMAGE_TYPE_2D,								// VkImageType		imageType;
   1577 			VK_FORMAT_UNDEFINED,							// VkFormat			format;
   1578 			{ 256, 256, 1 },								// VkExtent3D		extent;
   1579 			makeClearValueDepthStencil(0.5f, 0x03),			// VkClearValue		initValue
   1580 			{
   1581 				makeClearValueDepthStencil(0.1f, 0x06),		// VkClearValue		clearValue[0];
   1582 				makeClearValueDepthStencil(0.3f, 0x04),		// VkClearValue		clearValue[1];
   1583 			}
   1584 		};
   1585 
   1586 		for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
   1587 		{
   1588 			testParams.imageFormat = depthStencilImageFormatsToTest[imageFormatIndex];
   1589 
   1590 			std::ostringstream	testCaseName;
   1591 			testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(testParams.imageFormat);
   1592 
   1593 			depthStencilAttachmentClearTests->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Attachment", testParams));
   1594 			partialDepthStencilAttachmentClearTests->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Parital Clear Depth/Stencil Attachment", testParams));
   1595 		}
   1596 
   1597 		imageClearingTests->addChild(depthStencilAttachmentClearTests.release());
   1598 		imageClearingTests->addChild(partialDepthStencilAttachmentClearTests.release());
   1599 	}
   1600 
   1601 	return imageClearingTests.release();
   1602 }
   1603 
   1604 } // api
   1605 } // vkt
   1606