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 "deSTLUtil.hpp"
30 #include "deStringUtil.hpp"
31 #include "deUniquePtr.hpp"
32 #include "deArrayUtil.hpp"
33 #include "deInt32.h"
34 #include "vkImageUtil.hpp"
35 #include "vkMemUtil.hpp"
36 #include "vktTestCase.hpp"
37 #include "vktTestCaseUtil.hpp"
38 #include "vktTestGroupUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vkTypeUtil.hpp"
42 #include "vkCmdUtil.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuTexture.hpp"
45 #include "tcuTextureUtil.hpp"
46 #include "tcuVectorType.hpp"
47 #include "tcuTexture.hpp"
48 #include "tcuFloat.hpp"
49 #include "tcuTestLog.hpp"
50 #include "tcuVectorUtil.hpp"
51 #include <sstream>
52 #include <numeric>
53 
54 namespace vkt
55 {
56 
57 namespace api
58 {
59 
60 using namespace vk;
61 using namespace tcu;
62 
63 namespace
64 {
65 
66 enum AllocationKind
67 {
68 	ALLOCATION_KIND_SUBALLOCATED = 0,
69 	ALLOCATION_KIND_DEDICATED,
70 
71 	ALLOCATION_KIND_LAST,
72 };
73 
allocateBuffer(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkBuffer & buffer,const MemoryRequirement requirement,Allocator & allocator,AllocationKind allocationKind)74 de::MovePtr<Allocation> allocateBuffer (const InstanceInterface&	vki,
75 										const DeviceInterface&		vkd,
76 										const VkPhysicalDevice&		physDevice,
77 										const VkDevice				device,
78 										const VkBuffer&				buffer,
79 										const MemoryRequirement		requirement,
80 										Allocator&					allocator,
81 										AllocationKind				allocationKind)
82 {
83 	switch (allocationKind)
84 	{
85 		case ALLOCATION_KIND_SUBALLOCATED:
86 		{
87 			const VkMemoryRequirements memoryRequirements = getBufferMemoryRequirements(vkd, device, buffer);
88 
89 			return allocator.allocate(memoryRequirements, requirement);
90 		}
91 
92 		case ALLOCATION_KIND_DEDICATED:
93 		{
94 			return allocateDedicated(vki, vkd, physDevice, device, buffer, requirement);
95 		}
96 
97 		default:
98 		{
99 			TCU_THROW(InternalError, "Invalid allocation kind");
100 		}
101 	}
102 }
103 
allocateImage(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice & physDevice,const VkDevice device,const VkImage & image,const MemoryRequirement requirement,Allocator & allocator,AllocationKind allocationKind)104 de::MovePtr<Allocation> allocateImage (const InstanceInterface&		vki,
105 									   const DeviceInterface&		vkd,
106 									   const VkPhysicalDevice&		physDevice,
107 									   const VkDevice				device,
108 									   const VkImage&				image,
109 									   const MemoryRequirement		requirement,
110 									   Allocator&					allocator,
111 									   AllocationKind				allocationKind)
112 {
113 	switch (allocationKind)
114 	{
115 		case ALLOCATION_KIND_SUBALLOCATED:
116 		{
117 			const VkMemoryRequirements memoryRequirements = getImageMemoryRequirements(vkd, device, image);
118 
119 			return allocator.allocate(memoryRequirements, requirement);
120 		}
121 
122 		case ALLOCATION_KIND_DEDICATED:
123 		{
124 			return allocateDedicated(vki, vkd, physDevice, device, image, requirement);
125 		}
126 
127 		default:
128 		{
129 			TCU_THROW(InternalError, "Invalid allocation kind");
130 		}
131 	}
132 }
133 
getMipLevelExtent(VkExtent3D baseExtent,const deUint32 mipLevel)134 VkExtent3D getMipLevelExtent (VkExtent3D baseExtent, const deUint32 mipLevel)
135 {
136 	baseExtent.width	= std::max(baseExtent.width  >> mipLevel, 1u);
137 	baseExtent.height	= std::max(baseExtent.height >> mipLevel, 1u);
138 	baseExtent.depth	= std::max(baseExtent.depth  >> mipLevel, 1u);
139 	return baseExtent;
140 }
141 
getNumMipLevels(const VkExtent3D & baseExtent,const deUint32 maxMipLevels)142 deUint32 getNumMipLevels (const VkExtent3D& baseExtent, const deUint32 maxMipLevels)
143 {
144 	const deUint32 widestEdge = std::max(std::max(baseExtent.width, baseExtent.height), baseExtent.depth);
145 	return std::min(static_cast<deUint32>(deFloatLog2(static_cast<float>(widestEdge))) + 1u, maxMipLevels);
146 }
147 
greatestCommonDivisor(const deUint32 a,const deUint32 b)148 deUint32 greatestCommonDivisor (const deUint32 a, const deUint32 b)
149 {
150 	/* Find GCD */
151 	deUint32 temp;
152 	deUint32 x=a;
153 	deUint32 y=b;
154 
155 	while (x%y != 0)
156 	{
157 		temp = y;
158 		y = x%y;
159 		x = temp;
160 	}
161 	return y;
162 }
163 
lowestCommonMultiple(const deUint32 a,const deUint32 b)164 deUint32 lowestCommonMultiple (const deUint32 a, const deUint32 b)
165 {
166 	return (a*b)/greatestCommonDivisor(a,b);
167 }
168 
getImageMipLevelSizes(const deUint32 pixelSize,const VkExtent3D & baseExtent,const deUint32 numMipLevels,const deUint32 perLevelAlignment=1u)169 std::vector<deUint32> getImageMipLevelSizes (const deUint32 pixelSize, const VkExtent3D& baseExtent, const deUint32 numMipLevels, const deUint32 perLevelAlignment = 1u)
170 {
171 	std::vector<deUint32> results(numMipLevels);
172 
173 	for (deUint32 mipLevel = 0; mipLevel < numMipLevels; ++mipLevel)
174 	{
175 		const VkExtent3D extent = getMipLevelExtent(baseExtent, mipLevel);
176 		results[mipLevel] = static_cast<deUint32>(extent.width * extent.height * extent.depth * pixelSize);
177 		results[mipLevel] = ((results[mipLevel] + perLevelAlignment-1) / perLevelAlignment) * perLevelAlignment;
178 	}
179 
180 	return results;
181 }
182 
183 struct LayerRange
184 {
185 	deUint32 baseArrayLayer;
186 	deUint32 layerCount;
187 };
188 
isInClearRange(const UVec4 & clearCoords,const deUint32 x,const deUint32 y,deUint32 arrayLayer=0,tcu::Maybe<LayerRange> imageViewLayerRange=tcu::Maybe<LayerRange> (),tcu::Maybe<LayerRange> attachmentClearLayerRange=tcu::Maybe<LayerRange> ())189 inline bool isInClearRange (const UVec4& clearCoords, const deUint32 x, const deUint32 y, deUint32 arrayLayer = 0, tcu::Maybe<LayerRange> imageViewLayerRange = tcu::Maybe<LayerRange>(), tcu::Maybe<LayerRange> attachmentClearLayerRange = tcu::Maybe<LayerRange>())
190 {
191 	if (attachmentClearLayerRange)
192 	{
193 		// Only layers in range passed to clear command are cleared
194 
195 		const deUint32	clearBaseLayer	= (imageViewLayerRange ? imageViewLayerRange->baseArrayLayer : 0) + attachmentClearLayerRange->baseArrayLayer;
196 		const deUint32	clearLayerCount	= (attachmentClearLayerRange->layerCount == VK_REMAINING_ARRAY_LAYERS) ? imageViewLayerRange->layerCount : clearBaseLayer + attachmentClearLayerRange->layerCount;
197 
198 		if ((arrayLayer < clearBaseLayer) || (arrayLayer >= (clearLayerCount)))
199 		{
200 			return false;
201 		}
202 	}
203 
204 	if (clearCoords == UVec4())
205 	{
206 		return true;
207 	}
208 
209 	//! Check if a point lies in a cross-like area.
210 	return !((x <  clearCoords[0] && y <  clearCoords[1]) ||
211 			 (x <  clearCoords[0] && y >= clearCoords[3]) ||
212 			 (x >= clearCoords[2] && y <  clearCoords[1]) ||
213 			 (x >= clearCoords[2] && y >= clearCoords[3]));
214 }
215 
isInInitialClearRange(bool isAttachmentformat,deUint32 mipLevel,deUint32 arrayLayer,LayerRange imageViewLayerRange)216 inline bool isInInitialClearRange (bool isAttachmentformat, deUint32 mipLevel, deUint32 arrayLayer, LayerRange imageViewLayerRange)
217 {
218 	if (!isAttachmentformat)
219 	{
220 		// initial clear is done using renderpass load op - does not apply for non-renderable formats
221 		return false;
222 	}
223 
224 	if (mipLevel > 0)
225 	{
226 		// intial clear is done using FB bound to level 0 only
227 		return false;
228 	}
229 
230 	// Only layers in range bound to framebuffer are cleared to initial color
231 	if ((arrayLayer < imageViewLayerRange.baseArrayLayer) || (arrayLayer >= (imageViewLayerRange.baseArrayLayer + imageViewLayerRange.layerCount)))
232 	{
233 		return false;
234 	}
235 
236 	return true;
237 }
238 
239 // This method is copied from the vktRenderPassTests.cpp. It should be moved to a common place.
calcFloatDiff(float a,float b)240 int calcFloatDiff (float a, float b)
241 {
242 	const int			asign	= Float32(a).sign();
243 	const int			bsign	= Float32(a).sign();
244 
245 	const deUint32		avalue	= (Float32(a).bits() & ((0x1u << 31u) - 1u));
246 	const deUint32		bvalue	= (Float32(b).bits() & ((0x1u << 31u) - 1u));
247 
248 	if (asign != bsign)
249 		return avalue + bvalue + 1u;
250 	else if (avalue < bvalue)
251 		return bvalue - avalue;
252 	else
253 		return avalue - bvalue;
254 }
255 
256 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
comparePixelToDepthClearValue(const ConstPixelBufferAccess & access,int x,int y,float ref,std::string & stringResult)257 bool comparePixelToDepthClearValue (const ConstPixelBufferAccess&	access,
258 									int								x,
259 									int								y,
260 									float							ref,
261 									std::string&					stringResult)
262 {
263 	const TextureFormat			format			= getEffectiveDepthStencilTextureFormat(access.getFormat(), Sampler::MODE_DEPTH);
264 	const TextureChannelClass	channelClass	= getTextureChannelClass(format.type);
265 
266 	switch (channelClass)
267 	{
268 		case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
269 		case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
270 		{
271 			const int	bitDepth	= getTextureFormatBitDepth(format).x();
272 			const float	depth		= access.getPixDepth(x, y);
273 			const float	threshold	= 2.0f / (float)((1 << bitDepth) - 1);
274 			const bool	result		= deFloatAbs(depth - ref) <= threshold;
275 
276 			if (!result)
277 			{
278 				std::stringstream s;
279 				s << "Ref:" << ref << " Threshold:" << threshold << " Depth:" << depth;
280 				stringResult	= s.str();
281 			}
282 
283 			return result;
284 		}
285 
286 		case TEXTURECHANNELCLASS_FLOATING_POINT:
287 		{
288 			const float	depth			= access.getPixDepth(x, y);
289 			const int	mantissaBits	= getTextureFormatMantissaBitDepth(format).x();
290 			const int	threshold		= 10 * 1 << (23 - mantissaBits);
291 
292 			DE_ASSERT(mantissaBits <= 23);
293 
294 			const bool	result			= calcFloatDiff(depth, ref) <= threshold;
295 
296 			if (!result)
297 			{
298 				float				floatThreshold	= Float32((deUint32)threshold).asFloat();
299 				std::stringstream	s;
300 
301 				s << "Ref:" << ref << " Threshold:" << floatThreshold << " Depth:" << depth;
302 				stringResult	= s.str();
303 			}
304 
305 			return result;
306 		}
307 
308 		default:
309 			DE_FATAL("Invalid channel class");
310 			return false;
311 	}
312 }
313 
314 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
comparePixelToStencilClearValue(const ConstPixelBufferAccess & access,int x,int y,deUint32 ref,std::string & stringResult)315 bool comparePixelToStencilClearValue (const ConstPixelBufferAccess&	access,
316 									  int							x,
317 									  int							y,
318 									  deUint32						ref,
319 									  std::string&					stringResult)
320 {
321 	const deUint32	stencil	= access.getPixStencil(x, y);
322 	const bool		result	= stencil == ref;
323 
324 	if (!result)
325 	{
326 		std::stringstream s;
327 		s << "Ref:" << ref << " Threshold:0" << " Stencil:" << stencil;
328 		stringResult	= s.str();
329 	}
330 
331 	return result;
332 }
333 
334 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
comparePixelToColorClearValue(const ConstPixelBufferAccess & access,int x,int y,int z,const VkClearColorValue & ref,std::string & stringResult)335 bool comparePixelToColorClearValue (const ConstPixelBufferAccess&	access,
336 									int								x,
337 									int								y,
338 									int								z,
339 									const VkClearColorValue&		ref,
340 									std::string&					stringResult)
341 {
342 	const TextureFormat				format			= access.getFormat();
343 	const TextureChannelClass		channelClass	= getTextureChannelClass(format.type);
344 	const BVec4						channelMask		= getTextureFormatChannelMask(format);
345 
346 	switch (channelClass)
347 	{
348 		case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
349 		case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
350 		{
351 			const IVec4	bitDepth	(getTextureFormatBitDepth(format));
352 			const Vec4	resColor	(access.getPixel(x, y, z));
353 			Vec4		refColor	(ref.float32[0],
354 									 ref.float32[1],
355 									 ref.float32[2],
356 									 ref.float32[3]);
357 			const int	modifier	= (channelClass == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT) ? 0 : 1;
358 			const Vec4	threshold	(bitDepth[0] > 0 ? 1.0f / ((float)(1 << (bitDepth[0] - modifier)) - 1.0f) : 1.0f,
359 									 bitDepth[1] > 0 ? 1.0f / ((float)(1 << (bitDepth[1] - modifier)) - 1.0f) : 1.0f,
360 									 bitDepth[2] > 0 ? 1.0f / ((float)(1 << (bitDepth[2] - modifier)) - 1.0f) : 1.0f,
361 									 bitDepth[3] > 0 ? 1.0f / ((float)(1 << (bitDepth[3] - modifier)) - 1.0f) : 1.0f);
362 
363 			if (isSRGB(access.getFormat()))
364 				refColor	= linearToSRGB(refColor);
365 
366 			const bool	result		= !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
367 
368 			if (!result)
369 			{
370 				std::stringstream s;
371 				s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
372 				stringResult	= s.str();
373 			}
374 
375 			return result;
376 		}
377 
378 		case TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
379 		{
380 			const UVec4	resColor	(access.getPixelUint(x, y, z));
381 			const UVec4	refColor	(ref.uint32[0],
382 									 ref.uint32[1],
383 									 ref.uint32[2],
384 									 ref.uint32[3]);
385 			const UVec4	threshold	(1);
386 
387 			const bool	result		= !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
388 
389 			if (!result)
390 			{
391 				std::stringstream s;
392 				s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
393 				stringResult	= s.str();
394 			}
395 
396 			return result;
397 		}
398 
399 		case TEXTURECHANNELCLASS_SIGNED_INTEGER:
400 		{
401 			const IVec4	resColor	(access.getPixelInt(x, y, z));
402 			const IVec4	refColor	(ref.int32[0],
403 									 ref.int32[1],
404 									 ref.int32[2],
405 									 ref.int32[3]);
406 			const IVec4	threshold	(1);
407 
408 			const bool	result		= !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
409 
410 			if (!result)
411 			{
412 				std::stringstream s;
413 				s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
414 				stringResult	= s.str();
415 			}
416 
417 			return result;
418 		}
419 
420 		case TEXTURECHANNELCLASS_FLOATING_POINT:
421 		{
422 			const Vec4	resColor		(access.getPixel(x, y, z));
423 			const Vec4	refColor		(ref.float32[0],
424 										 ref.float32[1],
425 										 ref.float32[2],
426 										 ref.float32[3]);
427 			const IVec4	mantissaBits	(getTextureFormatMantissaBitDepth(format));
428 			const IVec4	threshold		(10 * IVec4(1) << (23 - mantissaBits));
429 
430 			DE_ASSERT(allEqual(greaterThanEqual(threshold, IVec4(0)), BVec4(true)));
431 
432 			for (int ndx = 0; ndx < 4; ndx++)
433 			{
434 				const bool result	= !(calcFloatDiff(resColor[ndx], refColor[ndx]) > threshold[ndx] && channelMask[ndx]);
435 
436 				if (!result)
437 				{
438 					float				floatThreshold	= Float32((deUint32)(threshold)[0]).asFloat();
439 					Vec4				thresholdVec4	(floatThreshold,
440 														 floatThreshold,
441 														 floatThreshold,
442 														 floatThreshold);
443 					std::stringstream	s;
444 					s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << thresholdVec4 << " Color:" << resColor;
445 					stringResult	= s.str();
446 
447 					return false;
448 				}
449 			}
450 
451 			return true;
452 		}
453 
454 		default:
455 			DE_FATAL("Invalid channel class");
456 			return false;
457 	}
458 }
459 
extentToString(VkExtent3D extent,VkImageType imageType)460 std::string extentToString (VkExtent3D extent, VkImageType imageType)
461 {
462 	// Don't append image dimensions when using the dimensions found in original test cases. This avoids name clashing with the old versions.
463 	if (imageType == VK_IMAGE_TYPE_1D && extent.width == 256u) return "";
464 	if (imageType == VK_IMAGE_TYPE_2D && extent.width == 256u && extent.height == 256u) return "";
465 	if (imageType == VK_IMAGE_TYPE_3D && extent.width == 256u && extent.height == 256u && extent.depth == 16u) return "";
466 
467 	return (std::string("_") + de::toString(extent.width) + std::string("x") + de::toString(extent.height) + (extent.depth != 1 ? (std::string("x") + de::toString(extent.depth)) : ""));
468 }
469 
470 enum SeparateDepthStencilLayoutMode
471 {
472 	SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE = 0,
473 	SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH,
474 	SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL,
475 };
476 
477 struct TestParams
478 {
479 	bool							useSingleMipLevel;	//!< only mip level 0, otherwise up to maxMipLevels
480 	VkImageType						imageType;
481 	VkFormat						imageFormat;
482 	VkImageTiling					imageTiling;
483 	VkExtent3D						imageExtent;
484 	deUint32						imageLayerCount;
485 	LayerRange						imageViewLayerRange;
486 	VkClearValue					initValue;
487 	VkClearValue					clearValue[2];		//!< the second value is used with more than one mip map
488 	bool							useSeparateExpectedClearValue;
489 	VkClearValue					expectedClearValue[2];
490 	LayerRange						clearLayerRange;
491 	AllocationKind					allocationKind;
492 	bool							isCube;
493 	SeparateDepthStencilLayoutMode	separateDepthStencilLayoutMode;
494 	bool							isColorMultipleSubresourceRangeTest;
495 };
496 
497 class ImageClearingTestInstance : public vkt::TestInstance
498 {
499 public:
500 										ImageClearingTestInstance		(Context&			context,
501 																		 const TestParams&	testParams);
502 
503 	Move<VkCommandPool>					createCommandPool				(VkCommandPoolCreateFlags commandPoolCreateFlags) const;
504 	Move<VkCommandBuffer>				allocatePrimaryCommandBuffer	(VkCommandPool commandPool) const;
505 	Move<VkImage>						createImage						(VkImageType imageType, VkFormat format, VkImageTiling tiling, VkExtent3D extent, deUint32 arrayLayerCount, VkImageUsageFlags usage) const;
506 	Move<VkImageView>					createImageView					(VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask, LayerRange layerRange) const;
507 	Move<VkRenderPass>					createRenderPass				(VkFormat format) const;
508 	Move<VkFramebuffer>					createFrameBuffer				(VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight, deUint32 imageLayersCount) const;
509 
510 	void								beginCommandBuffer				(VkCommandBufferUsageFlags usageFlags) const;
511 	void								endCommandBuffer				(void) const;
512 	void								submitCommandBuffer				(void) const;
513 	void								beginRenderPass					(VkSubpassContents content, VkClearValue clearValue) const;
514 
515 	void								pipelineImageBarrier			(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImageAspectFlags aspectMask = 0u) const;
516 	de::MovePtr<TextureLevelPyramid>	readImage						(VkImageAspectFlags aspectMask, deUint32 baseLayer) const;
517 	tcu::TestStatus						verifyResultImage				(const std::string& successMessage, const UVec4& clearCoords = UVec4()) const;
518 
519 protected:
520 	enum ViewType
521 	{
522 		VIEW_TYPE_SINGLE,
523 		VIEW_TYPE_ARRAY,
524 		VIEW_TYPE_CUBE
525 	};
526 	VkImageViewType						getCorrespondingImageViewType	(VkImageType imageType, ViewType viewType) const;
527 	VkImageUsageFlags					getImageUsageFlags				(VkFormat format) const;
528 	VkImageAspectFlags					getImageAspectFlags				(VkFormat format) const;
529 	bool								getIsAttachmentFormat			(VkFormat format, VkImageTiling tiling) const;
530 	bool								getIsStencilFormat				(VkFormat format) const;
531 	bool								getIsDepthFormat				(VkFormat format) const;
532 	VkImageFormatProperties				getImageFormatProperties		(void) const;
533 	VkImageCreateFlags					getImageCreateFlags				(void) const;
534 	ViewType							getViewType						(deUint32 imageLayerCount) const;
535 	de::MovePtr<Allocation>				allocateAndBindImageMemory		(VkImage image) const;
536 
537 	const TestParams&					m_params;
538 	const VkDevice						m_device;
539 	const InstanceInterface&			m_vki;
540 	const DeviceInterface&				m_vkd;
541 	const VkQueue						m_queue;
542 	const deUint32						m_queueFamilyIndex;
543 	Allocator&							m_allocator;
544 
545 	const bool							m_isAttachmentFormat;
546 	const VkImageUsageFlags				m_imageUsageFlags;
547 	const VkImageAspectFlags			m_imageAspectFlags;
548 	const VkImageFormatProperties		m_imageFormatProperties;
549 	const deUint32						m_imageMipLevels;
550 	const deUint32						m_thresholdMipLevel;
551 
552 	Unique<VkCommandPool>				m_commandPool;
553 	Unique<VkCommandBuffer>				m_commandBuffer;
554 
555 	Unique<VkImage>						m_image;
556 	de::MovePtr<Allocation>				m_imageMemory;
557 	Unique<VkImageView>					m_imageView;
558 	Move<VkRenderPass>					m_renderPass;
559 	Move<VkFramebuffer>					m_frameBuffer;
560 };
561 
ImageClearingTestInstance(Context & context,const TestParams & params)562 ImageClearingTestInstance::ImageClearingTestInstance (Context& context, const TestParams& params)
563 	: TestInstance				(context)
564 	, m_params					(params)
565 	, m_device					(context.getDevice())
566 	, m_vki						(context.getInstanceInterface())
567 	, m_vkd						(context.getDeviceInterface())
568 	, m_queue					(context.getUniversalQueue())
569 	, m_queueFamilyIndex		(context.getUniversalQueueFamilyIndex())
570 	, m_allocator				(context.getDefaultAllocator())
571 	, m_isAttachmentFormat		(getIsAttachmentFormat(params.imageFormat, params.imageTiling))
572 	, m_imageUsageFlags			(getImageUsageFlags(params.imageFormat))
573 	, m_imageAspectFlags		(getImageAspectFlags(params.imageFormat))
574 	, m_imageFormatProperties	(getImageFormatProperties())
575 	, m_imageMipLevels			(params.useSingleMipLevel ? 1u : getNumMipLevels(params.imageExtent, m_imageFormatProperties.maxMipLevels))
576 	, m_thresholdMipLevel		(std::max(m_imageMipLevels / 2u, 1u))
577 	, m_commandPool				(createCommandPool(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
578 	, m_commandBuffer			(allocatePrimaryCommandBuffer(*m_commandPool))
579 
580 	, m_image					(createImage(params.imageType,
581 											 params.imageFormat,
582 											 params.imageTiling,
583 											 params.imageExtent,
584 											 params.imageLayerCount,
585 											 m_imageUsageFlags))
586 
587 	, m_imageMemory				(allocateAndBindImageMemory(*m_image))
588 	, m_imageView				(m_isAttachmentFormat ? createImageView(*m_image,
589 												 getCorrespondingImageViewType(params.imageType, getViewType(params.imageLayerCount)),
590 												 params.imageFormat,
591 												 m_imageAspectFlags,
592 												 params.imageViewLayerRange) : vk::Move<VkImageView>())
593 
594 {
595 	if (m_params.allocationKind == ALLOCATION_KIND_DEDICATED)
596 		context.requireDeviceFunctionality("VK_KHR_dedicated_allocation");
597 
598 	if (m_params.separateDepthStencilLayoutMode != SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE)
599 		context.requireDeviceFunctionality("VK_KHR_separate_depth_stencil_layouts");
600 
601 	if (m_isAttachmentFormat)
602 	{
603 		m_renderPass = createRenderPass(params.imageFormat);
604 		m_frameBuffer = createFrameBuffer(*m_imageView, *m_renderPass, params.imageExtent.width, params.imageExtent.height, params.imageViewLayerRange.layerCount);
605 	}
606 }
607 
getViewType(deUint32 imageLayerCount) const608 ImageClearingTestInstance::ViewType ImageClearingTestInstance::getViewType (deUint32 imageLayerCount) const
609 {
610 	if (imageLayerCount > 1u)
611 		return m_params.isCube ? VIEW_TYPE_CUBE : VIEW_TYPE_ARRAY;
612 	else
613 		return VIEW_TYPE_SINGLE;
614 }
615 
getCorrespondingImageViewType(VkImageType imageType,ViewType viewType) const616 VkImageViewType ImageClearingTestInstance::getCorrespondingImageViewType (VkImageType imageType, ViewType viewType) const
617 {
618 	switch (imageType)
619 	{
620 	case VK_IMAGE_TYPE_1D:
621 		return (viewType == VIEW_TYPE_ARRAY) ?  VK_IMAGE_VIEW_TYPE_1D_ARRAY : VK_IMAGE_VIEW_TYPE_1D;
622 	case VK_IMAGE_TYPE_2D:
623 		if (viewType == VIEW_TYPE_ARRAY)
624 			return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
625 		else if (viewType == VIEW_TYPE_CUBE)
626 			return VK_IMAGE_VIEW_TYPE_CUBE;
627 		else
628 			return VK_IMAGE_VIEW_TYPE_2D;
629 	case VK_IMAGE_TYPE_3D:
630 		if (viewType != VIEW_TYPE_SINGLE)
631 		{
632 			DE_FATAL("Cannot have 3D image array");
633 		}
634 		return VK_IMAGE_VIEW_TYPE_3D;
635 	default:
636 		DE_FATAL("Unknown image type!");
637 	}
638 
639 	return VK_IMAGE_VIEW_TYPE_2D;
640 }
641 
getImageUsageFlags(VkFormat format) const642 VkImageUsageFlags ImageClearingTestInstance::getImageUsageFlags (VkFormat format) const
643 {
644 	VkImageUsageFlags	commonFlags	= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
645 
646 	if (m_isAttachmentFormat)
647 	{
648 		if (isDepthStencilFormat(format))
649 			return commonFlags | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
650 
651 		return commonFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
652 	}
653 	return commonFlags;
654 }
655 
getImageAspectFlags(VkFormat format) const656 VkImageAspectFlags ImageClearingTestInstance::getImageAspectFlags (VkFormat format) const
657 {
658 	VkImageAspectFlags	imageAspectFlags	= 0;
659 
660 	if (getIsDepthFormat(format))
661 		imageAspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
662 
663 	if (getIsStencilFormat(format))
664 		imageAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
665 
666 	if (imageAspectFlags == 0)
667 		imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
668 
669 	return imageAspectFlags;
670 }
671 
getIsAttachmentFormat(VkFormat format,VkImageTiling tiling) const672 bool ImageClearingTestInstance::getIsAttachmentFormat (VkFormat format, VkImageTiling tiling) const
673 {
674 	const VkFormatProperties props		= vk::getPhysicalDeviceFormatProperties(m_vki, m_context.getPhysicalDevice(), format);
675 	const VkFormatFeatureFlags features	= tiling == VK_IMAGE_TILING_OPTIMAL ? props.optimalTilingFeatures : props.linearTilingFeatures;
676 
677 	return (features & (vk::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) != 0;
678 }
679 
getIsStencilFormat(VkFormat format) const680 bool ImageClearingTestInstance::getIsStencilFormat (VkFormat format) const
681 {
682 	const TextureFormat tcuFormat	= mapVkFormat(format);
683 
684 	if (tcuFormat.order == TextureFormat::S || tcuFormat.order == TextureFormat::DS)
685 		return true;
686 
687 	return false;
688 }
689 
getIsDepthFormat(VkFormat format) const690 bool ImageClearingTestInstance::getIsDepthFormat (VkFormat format) const
691 {
692 	const TextureFormat	tcuFormat	= mapVkFormat(format);
693 
694 	if (tcuFormat.order == TextureFormat::D || tcuFormat.order == TextureFormat::DS)
695 		return true;
696 
697 	return false;
698 }
699 
getImageCreateFlags(void) const700 VkImageCreateFlags ImageClearingTestInstance::getImageCreateFlags (void) const
701 {
702 	return m_params.isCube ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : (VkImageCreateFlags)0;
703 }
704 
getImageFormatProperties(void) const705 VkImageFormatProperties ImageClearingTestInstance::getImageFormatProperties (void) const
706 {
707 	VkImageFormatProperties properties;
708 	const VkResult result = m_vki.getPhysicalDeviceImageFormatProperties(m_context.getPhysicalDevice(), m_params.imageFormat, m_params.imageType,
709 																		 m_params.imageTiling, m_imageUsageFlags, getImageCreateFlags(), &properties);
710 
711 	if (result == VK_ERROR_FORMAT_NOT_SUPPORTED)
712 		TCU_THROW(NotSupportedError, "Format not supported");
713 	else
714 		return properties;
715 }
716 
allocateAndBindImageMemory(VkImage image) const717 de::MovePtr<Allocation> ImageClearingTestInstance::allocateAndBindImageMemory (VkImage image) const
718 {
719 	de::MovePtr<Allocation>	imageMemory	(allocateImage(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, image, MemoryRequirement::Any, m_allocator, m_params.allocationKind));
720 	VK_CHECK(m_vkd.bindImageMemory(m_device, image, imageMemory->getMemory(), imageMemory->getOffset()));
721 	return imageMemory;
722 }
723 
createCommandPool(VkCommandPoolCreateFlags commandPoolCreateFlags) const724 Move<VkCommandPool> ImageClearingTestInstance::createCommandPool (VkCommandPoolCreateFlags commandPoolCreateFlags) const
725 {
726 	return vk::createCommandPool(m_vkd, m_device, commandPoolCreateFlags, m_queueFamilyIndex);
727 }
728 
allocatePrimaryCommandBuffer(VkCommandPool commandPool) const729 Move<VkCommandBuffer> ImageClearingTestInstance::allocatePrimaryCommandBuffer (VkCommandPool commandPool) const
730 {
731 	return vk::allocateCommandBuffer(m_vkd, m_device, commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
732 }
733 
createImage(VkImageType imageType,VkFormat format,VkImageTiling tiling,VkExtent3D extent,deUint32 arrayLayerCount,VkImageUsageFlags usage) const734 Move<VkImage> ImageClearingTestInstance::createImage (VkImageType imageType, VkFormat format, VkImageTiling tiling, VkExtent3D extent, deUint32 arrayLayerCount, VkImageUsageFlags usage) const
735 {
736 	if (arrayLayerCount > m_imageFormatProperties.maxArrayLayers)
737 		TCU_THROW(NotSupportedError, "Device does not support enough image array layers");
738 
739 	const VkImageCreateInfo					imageCreateInfo			=
740 	{
741 		VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,		// VkStructureType			sType;
742 		DE_NULL,									// const void*				pNext;
743 		getImageCreateFlags(),						// VkImageCreateFlags		flags;
744 		imageType,									// VkImageType				imageType;
745 		format,										// VkFormat					format;
746 		extent,										// VkExtent3D				extent;
747 		m_imageMipLevels,							// deUint32					mipLevels;
748 		arrayLayerCount,							// deUint32					arrayLayers;
749 		VK_SAMPLE_COUNT_1_BIT,						// VkSampleCountFlagBits	samples;
750 		tiling,										// VkImageTiling			tiling;
751 		usage,										// VkImageUsageFlags		usage;
752 		VK_SHARING_MODE_EXCLUSIVE,					// VkSharingMode			sharingMode;
753 		1u,											// deUint32					queueFamilyIndexCount;
754 		&m_queueFamilyIndex,						// const deUint32*			pQueueFamilyIndices;
755 		VK_IMAGE_LAYOUT_UNDEFINED					// VkImageLayout			initialLayout;
756 	};
757 
758 	return vk::createImage(m_vkd, m_device, &imageCreateInfo, DE_NULL);
759 }
760 
createImageView(VkImage image,VkImageViewType viewType,VkFormat format,VkImageAspectFlags aspectMask,LayerRange layerRange) const761 Move<VkImageView> ImageClearingTestInstance::createImageView (VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask, LayerRange layerRange) const
762 {
763 	const VkImageViewCreateInfo				imageViewCreateInfo		=
764 	{
765 		VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,	// VkStructureType				sType;
766 		DE_NULL,									// const void*					pNext;
767 		0u,											// VkImageViewCreateFlags		flags;
768 		image,										// VkImage						image;
769 		viewType,									// VkImageViewType				viewType;
770 		format,										// VkFormat						format;
771 		{
772 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			r;
773 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			g;
774 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			b;
775 			VK_COMPONENT_SWIZZLE_IDENTITY,				// VkComponentSwizzle			a;
776 		},											// VkComponentMapping			components;
777 		{
778 			aspectMask,									// VkImageAspectFlags			aspectMask;
779 			0u,											// deUint32						baseMipLevel;
780 			1u,											// deUint32						mipLevels;
781 			layerRange.baseArrayLayer,					// deUint32						baseArrayLayer;
782 			layerRange.layerCount,						// deUint32						arraySize;
783 		},												// VkImageSubresourceRange		subresourceRange;
784 	};
785 
786 	return vk::createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL);
787 }
788 
createRenderPass(VkFormat format) const789 Move<VkRenderPass> ImageClearingTestInstance::createRenderPass (VkFormat format) const
790 {
791 	if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE)
792 	{
793 		VkImageLayout							imageLayout;
794 
795 		if (isDepthStencilFormat(format))
796 			imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
797 		else
798 			imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
799 
800 		const VkAttachmentDescription			attachmentDesc			=
801 		{
802 			0u,													// VkAttachmentDescriptionFlags		flags;
803 			format,												// VkFormat							format;
804 			VK_SAMPLE_COUNT_1_BIT,								// VkSampleCountFlagBits			samples;
805 			VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				loadOp;
806 			VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				storeOp;
807 			VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				stencilLoadOp;
808 			VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				stencilStoreOp;
809 			imageLayout,										// VkImageLayout					initialLayout;
810 			imageLayout,										// VkImageLayout					finalLayout;
811 		};
812 
813 		const VkAttachmentDescription			attachments[1]			=
814 		{
815 			attachmentDesc
816 		};
817 
818 		const VkAttachmentReference				attachmentRef			=
819 		{
820 			0u,													// deUint32							attachment;
821 			imageLayout,										// VkImageLayout					layout;
822 		};
823 
824 		const VkAttachmentReference*			pColorAttachments		= DE_NULL;
825 		const VkAttachmentReference*			pDepthStencilAttachment	= DE_NULL;
826 		deUint32								colorAttachmentCount	= 1;
827 
828 		if (isDepthStencilFormat(format))
829 		{
830 			colorAttachmentCount	= 0;
831 			pDepthStencilAttachment	= &attachmentRef;
832 		}
833 		else
834 		{
835 			colorAttachmentCount	= 1;
836 			pColorAttachments		= &attachmentRef;
837 		}
838 
839 		const VkSubpassDescription				subpassDesc[1]			=
840 		{
841 			{
842 				0u,												// VkSubpassDescriptionFlags		flags;
843 				VK_PIPELINE_BIND_POINT_GRAPHICS,				// VkPipelineBindPoint				pipelineBindPoint;
844 				0u,												// deUint32							inputAttachmentCount;
845 				DE_NULL,										// const VkAttachmentReference*		pInputAttachments;
846 				colorAttachmentCount,							// deUint32							colorAttachmentCount;
847 				pColorAttachments,								// const VkAttachmentReference*		pColorAttachments;
848 				DE_NULL,										// const VkAttachmentReference*		pResolveAttachments;
849 				pDepthStencilAttachment,						// const VkAttachmentReference*		pDepthStencilAttachment;
850 				0u,												// deUint32							preserveAttachmentCount;
851 				DE_NULL,										// const VkAttachmentReference*		pPreserveAttachments;
852 			}
853 		};
854 
855 		const VkRenderPassCreateInfo			renderPassCreateInfo	=
856 		{
857 			VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,			// VkStructureType					sType;
858 			DE_NULL,											// const void*						pNext;
859 			0u,													// VkRenderPassCreateFlags			flags;
860 			1u,													// deUint32							attachmentCount;
861 			attachments,										// const VkAttachmentDescription*	pAttachments;
862 			1u,													// deUint32							subpassCount;
863 			subpassDesc,										// const VkSubpassDescription*		pSubpasses;
864 			0u,													// deUint32							dependencyCount;
865 			DE_NULL,											// const VkSubpassDependency*		pDependencies;
866 		};
867 
868 		return vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
869 	}
870 	else
871 	{
872 		// Make sure VK_KHR_create_renderpass2 is supported. Due to InstanceFactory1 being used and the render pass being created in
873 		// the instance constructor and not every time, this is the best moment to check.
874 		m_context.requireDeviceFunctionality("VK_KHR_create_renderpass2");
875 
876 		VkImageLayout								initialLayout			= VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
877 		VkImageLayout								finalLayout				= VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
878 		VkAttachmentDescriptionStencilLayoutKHR		stencilLayouts			=
879 		{
880 			VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR,
881 			DE_NULL,
882 			VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
883 			VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
884 		};
885 
886 		VkImageLayout								imageLayout;
887 		VkAttachmentReferenceStencilLayoutKHR		stencilLayoutRef		=
888 		{
889 			VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR,
890 			DE_NULL,
891 			VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
892 		};
893 
894 		if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
895 		{
896 			initialLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
897 			finalLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
898 			stencilLayouts.stencilInitialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
899 			stencilLayouts.stencilFinalLayout = VK_IMAGE_LAYOUT_GENERAL;
900 			imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
901 			stencilLayoutRef.stencilLayout = VK_IMAGE_LAYOUT_GENERAL;
902 		}
903 		else
904 		{
905 			initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
906 			finalLayout = VK_IMAGE_LAYOUT_GENERAL;
907 			stencilLayouts.stencilInitialLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
908 			stencilLayouts.stencilFinalLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
909 			imageLayout = VK_IMAGE_LAYOUT_GENERAL;
910 			stencilLayoutRef.stencilLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
911 		}
912 
913 		const VkAttachmentDescription2KHR			attachmentDesc			=
914 		{
915 			VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR,		// VkStructureType					sType;
916 			&stencilLayouts,									// const void*						pNext;
917 			0u,													// VkAttachmentDescriptionFlags		flags;
918 			format,												// VkFormat							format;
919 			VK_SAMPLE_COUNT_1_BIT,								// VkSampleCountFlagBits			samples;
920 			VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				loadOp;
921 			VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				storeOp;
922 			VK_ATTACHMENT_LOAD_OP_CLEAR,						// VkAttachmentLoadOp				stencilLoadOp;
923 			VK_ATTACHMENT_STORE_OP_STORE,						// VkAttachmentStoreOp				stencilStoreOp;
924 			initialLayout,										// VkImageLayout					initialLayout;
925 			finalLayout,										// VkImageLayout					finalLayout;
926 		};
927 
928 		const VkAttachmentReference2KHR				attachmentRef			=
929 		{
930 			VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR,		// VkStructureType		sType;
931 			&stencilLayoutRef,									// const void*			pNext;
932 			0u,													// deUint32				attachment;
933 			imageLayout,										// VkImageLayout		layout;
934 			0u,													// VkImageAspectFlags	aspectMask;
935 		};
936 
937 		const VkSubpassDescription2KHR				subpassDesc			=
938 		{
939 			VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR,	// VkStructureType					sType;
940 			DE_NULL,										// const void*						pNext;
941 			0u,												// VkSubpassDescriptionFlags		flags;
942 			VK_PIPELINE_BIND_POINT_GRAPHICS,				// VkPipelineBindPoint				pipelineBindPoint;
943 			0u,												// deUint32							viewMask;
944 			0u,												// deUint32							inputAttachmentCount;
945 			DE_NULL,										// const VkAttachmentReference2KHR*	pInputAttachments;
946 			0u,												// deUint32							colorAttachmentCount;
947 			DE_NULL,										// const VkAttachmentReference2KHR*	pColorAttachments;
948 			DE_NULL,										// const VkAttachmentReference2KHR*	pResolveAttachments;
949 			&attachmentRef,									// const VkAttachmentReference2KHR*	pDepthStencilAttachment;
950 			0u,												// deUint32							preserveAttachmentCount;
951 			DE_NULL,										// const VkAttachmentReference2KHR*	pPreserveAttachments;
952 		};
953 
954 		const VkRenderPassCreateInfo2KHR			renderPassCreateInfo	=
955 		{
956 			VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR,	// VkStructureType					sType;
957 			DE_NULL,											// const void*						pNext;
958 			0u,													// VkRenderPassCreateFlags			flags;
959 			1u,													// deUint32							attachmentCount;
960 			&attachmentDesc,									// const VkAttachmentDescription*	pAttachments;
961 			1u,													// deUint32							subpassCount;
962 			&subpassDesc,										// const VkSubpassDescription*		pSubpasses;
963 			0u,													// deUint32							dependencyCount;
964 			DE_NULL,											// const VkSubpassDependency*		pDependencies;
965 			0u,													// deUint32							correlatedViewMaskCount;
966 			DE_NULL,											// const deUint32*					pCorrelatedViewMasks;
967 		};
968 
969 		return vk::createRenderPass2(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
970 	}
971 }
972 
createFrameBuffer(VkImageView imageView,VkRenderPass renderPass,deUint32 imageWidth,deUint32 imageHeight,deUint32 imageLayersCount) const973 Move<VkFramebuffer> ImageClearingTestInstance::createFrameBuffer (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight, deUint32 imageLayersCount) const
974 {
975 	const VkImageView						attachmentViews[1]		=
976 	{
977 		imageView
978 	};
979 
980 	const VkFramebufferCreateInfo			framebufferCreateInfo	=
981 	{
982 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,	// VkStructureType			sType;
983 		DE_NULL,									// const void*				pNext;
984 		0u,											// VkFramebufferCreateFlags	flags;
985 		renderPass,									// VkRenderPass				renderPass;
986 		1,											// deUint32					attachmentCount;
987 		attachmentViews,							// const VkImageView*		pAttachments;
988 		imageWidth,									// deUint32					width;
989 		imageHeight,								// deUint32					height;
990 		imageLayersCount,							// deUint32					layers;
991 	};
992 
993 	return createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL);
994 }
995 
beginCommandBuffer(VkCommandBufferUsageFlags usageFlags) const996 void ImageClearingTestInstance::beginCommandBuffer (VkCommandBufferUsageFlags usageFlags) const
997 {
998 	vk::beginCommandBuffer(m_vkd, *m_commandBuffer, usageFlags);
999 }
1000 
endCommandBuffer(void) const1001 void ImageClearingTestInstance::endCommandBuffer (void) const
1002 {
1003 	vk::endCommandBuffer(m_vkd, *m_commandBuffer);
1004 }
1005 
submitCommandBuffer(void) const1006 void ImageClearingTestInstance::submitCommandBuffer (void) const
1007 {
1008 	submitCommandsAndWait(m_vkd, m_device, m_queue, m_commandBuffer.get());
1009 }
1010 
pipelineImageBarrier(VkPipelineStageFlags srcStageMask,VkPipelineStageFlags dstStageMask,VkAccessFlags srcAccessMask,VkAccessFlags dstAccessMask,VkImageLayout oldLayout,VkImageLayout newLayout,VkImageAspectFlags aspectMask) const1011 void ImageClearingTestInstance::pipelineImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImageAspectFlags aspectMask) const
1012 {
1013 	if (!aspectMask || m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE)
1014 		aspectMask = m_imageAspectFlags;
1015 
1016 	const VkImageMemoryBarrier		imageBarrier	=
1017 	{
1018 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,		// VkStructureType			sType;
1019 		DE_NULL,									// const void*				pNext;
1020 		srcAccessMask,								// VkAccessFlags			srcAccessMask;
1021 		dstAccessMask,								// VkAccessFlags			dstAccessMask;
1022 		oldLayout,									// VkImageLayout			oldLayout;
1023 		newLayout,									// VkImageLayout			newLayout;
1024 		VK_QUEUE_FAMILY_IGNORED,					// deUint32					srcQueueFamilyIndex;
1025 		VK_QUEUE_FAMILY_IGNORED,					// deUint32					destQueueFamilyIndex;
1026 		*m_image,									// VkImage					image;
1027 		{
1028 			aspectMask,									// VkImageAspectFlags	aspectMask;
1029 			0u,											// deUint32				baseMipLevel;
1030 			VK_REMAINING_MIP_LEVELS,					// deUint32				levelCount;
1031 			0u,											// deUint32				baseArrayLayer;
1032 			VK_REMAINING_ARRAY_LAYERS,					// deUint32				layerCount;
1033 		},											// VkImageSubresourceRange	subresourceRange;
1034 	};
1035 
1036 	m_vkd.cmdPipelineBarrier(*m_commandBuffer, srcStageMask, dstStageMask, 0, 0, DE_NULL, 0, DE_NULL, 1, &imageBarrier);
1037 }
1038 
readImage(VkImageAspectFlags aspectMask,deUint32 arrayLayer) const1039 de::MovePtr<TextureLevelPyramid> ImageClearingTestInstance::readImage (VkImageAspectFlags aspectMask, deUint32 arrayLayer) const
1040 {
1041 	const TextureFormat					tcuFormat		= aspectMask == VK_IMAGE_ASPECT_COLOR_BIT ? mapVkFormat(m_params.imageFormat) :
1042 														  aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT ? getDepthCopyFormat(m_params.imageFormat) :
1043 														  aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT ? getStencilCopyFormat(m_params.imageFormat) :
1044 														  TextureFormat();
1045 	const deUint32						pixelSize		= getPixelSize(tcuFormat);
1046 	deUint32							alignment		= 4;	// subsequent mip levels aligned to 4 bytes
1047 
1048 	if (!getIsDepthFormat(m_params.imageFormat) && !getIsStencilFormat(m_params.imageFormat))
1049 		alignment = lowestCommonMultiple(pixelSize, alignment); // alignment must be multiple of pixel size, if not D/S.
1050 
1051 	const std::vector<deUint32>			mipLevelSizes	= getImageMipLevelSizes(pixelSize, m_params.imageExtent, m_imageMipLevels, alignment);
1052 	const VkDeviceSize					imageTotalSize	= std::accumulate(mipLevelSizes.begin(), mipLevelSizes.end(), 0u);
1053 
1054 	de::MovePtr<TextureLevelPyramid>	result			(new TextureLevelPyramid(tcuFormat, m_imageMipLevels));
1055 	Move<VkBuffer>						buffer;
1056 	de::MovePtr<Allocation>				bufferAlloc;
1057 
1058 	// Create destination buffer
1059 	{
1060 		const VkBufferCreateInfo	bufferParams	=
1061 		{
1062 			VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,		// VkStructureType		sType;
1063 			DE_NULL,									// const void*			pNext;
1064 			0u,											// VkBufferCreateFlags	flags;
1065 			imageTotalSize,								// VkDeviceSize			size;
1066 			VK_BUFFER_USAGE_TRANSFER_DST_BIT,			// VkBufferUsageFlags	usage;
1067 			VK_SHARING_MODE_EXCLUSIVE,					// VkSharingMode		sharingMode;
1068 			0u,											// deUint32				queueFamilyIndexCount;
1069 			DE_NULL										// const deUint32*		pQueueFamilyIndices;
1070 		};
1071 
1072 		buffer		= createBuffer(m_vkd, m_device, &bufferParams);
1073 		bufferAlloc	= allocateBuffer(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, *buffer, MemoryRequirement::HostVisible, m_allocator, m_params.allocationKind);
1074 		VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
1075 	}
1076 
1077 	// Barriers for copying image to buffer
1078 
1079 	const VkBufferMemoryBarrier		bufferBarrier	=
1080 	{
1081 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,	// VkStructureType	sType;
1082 		DE_NULL,									// const void*		pNext;
1083 		VK_ACCESS_TRANSFER_WRITE_BIT,				// VkAccessFlags	srcAccessMask;
1084 		VK_ACCESS_HOST_READ_BIT,					// VkAccessFlags	dstAccessMask;
1085 		VK_QUEUE_FAMILY_IGNORED,					// deUint32			srcQueueFamilyIndex;
1086 		VK_QUEUE_FAMILY_IGNORED,					// deUint32			dstQueueFamilyIndex;
1087 		*buffer,									// VkBuffer			buffer;
1088 		0u,											// VkDeviceSize		offset;
1089 		imageTotalSize,								// VkDeviceSize		size;
1090 	};
1091 
1092 	// Copy image to buffer
1093 	std::vector<VkBufferImageCopy> copyRegions;
1094 	{
1095 		deUint32 offset = 0u;
1096 		for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
1097 		{
1098 			const VkExtent3D		extent	= getMipLevelExtent(m_params.imageExtent, mipLevel);
1099 			const VkBufferImageCopy	region	=
1100 			{
1101 				offset,										// VkDeviceSize				bufferOffset;
1102 				0u,											// deUint32					bufferRowLength;
1103 				0u,											// deUint32					bufferImageHeight;
1104 				{ aspectMask, mipLevel, arrayLayer, 1u },	// VkImageSubresourceLayers	imageSubresource;
1105 				{ 0, 0, 0 },								// VkOffset3D				imageOffset;
1106 				extent										// VkExtent3D				imageExtent;
1107 			};
1108 			copyRegions.push_back(region);
1109 			offset += mipLevelSizes[mipLevel];
1110 		}
1111 	}
1112 
1113 	beginCommandBuffer(0);
1114 
1115 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
1116 						 VK_PIPELINE_STAGE_TRANSFER_BIT,
1117 						 VK_ACCESS_TRANSFER_WRITE_BIT,
1118 						 VK_ACCESS_TRANSFER_READ_BIT,
1119 						 VK_IMAGE_LAYOUT_GENERAL,
1120 						 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1121 						 aspectMask);
1122 
1123 	m_vkd.cmdCopyImageToBuffer(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, static_cast<deUint32>(copyRegions.size()), &copyRegions[0]);
1124 	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);
1125 
1126 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
1127 						 VK_PIPELINE_STAGE_TRANSFER_BIT,
1128 						 VK_ACCESS_TRANSFER_READ_BIT,
1129 						 VK_ACCESS_TRANSFER_READ_BIT,
1130 						 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1131 						 VK_IMAGE_LAYOUT_GENERAL,
1132 						 aspectMask);
1133 
1134 	endCommandBuffer();
1135 	submitCommandBuffer();
1136 
1137 	invalidateAlloc(m_vkd, m_device, *bufferAlloc);
1138 
1139 	{
1140 		deUint32 offset = 0u;
1141 		for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
1142 		{
1143 			const VkExtent3D	extent		= getMipLevelExtent(m_params.imageExtent, mipLevel);
1144 			const void*			pLevelData	= static_cast<const void*>(reinterpret_cast<deUint8*>(bufferAlloc->getHostPtr()) + offset);
1145 
1146 			result->allocLevel(mipLevel, extent.width, extent.height, extent.depth);
1147 			copy(result->getLevel(mipLevel), ConstPixelBufferAccess(result->getFormat(), result->getLevel(mipLevel).getSize(), pLevelData));
1148 
1149 			offset += mipLevelSizes[mipLevel];
1150 		}
1151 	}
1152 
1153 	return result;
1154 }
1155 
verifyResultImage(const std::string & successMessage,const UVec4 & clearCoords) const1156 tcu::TestStatus ImageClearingTestInstance::verifyResultImage (const std::string& successMessage, const UVec4& clearCoords) const
1157 {
1158 	DE_ASSERT((clearCoords == UVec4()) || m_params.imageExtent.depth == 1u);
1159 
1160 	if (getIsDepthFormat(m_params.imageFormat) && m_params.separateDepthStencilLayoutMode != SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL)
1161 	{
1162 		DE_ASSERT(m_imageMipLevels == 1u);
1163 
1164 		for (deUint32 arrayLayer = 0; arrayLayer < m_params.imageLayerCount; ++arrayLayer)
1165 		{
1166 			de::MovePtr<TextureLevelPyramid>	image			= readImage(VK_IMAGE_ASPECT_DEPTH_BIT, arrayLayer);
1167 			std::string							message;
1168 			float								depthValue;
1169 
1170 			for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
1171 			for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
1172 			{
1173 				if (isInClearRange(clearCoords, x, y, arrayLayer, m_params.imageViewLayerRange, m_params.clearLayerRange))
1174 					depthValue = m_params.clearValue[0].depthStencil.depth;
1175 				else
1176 				if (isInInitialClearRange(m_isAttachmentFormat, 0u /* mipLevel */, arrayLayer, m_params.imageViewLayerRange))
1177 				{
1178 					depthValue = m_params.initValue.depthStencil.depth;
1179 				}
1180 				else
1181 					continue;
1182 
1183 				if (!comparePixelToDepthClearValue(image->getLevel(0), x, y, depthValue, message))
1184 					return TestStatus::fail("Depth value mismatch! " + message);
1185 			}
1186 		}
1187 	}
1188 
1189 	if (getIsStencilFormat(m_params.imageFormat) && m_params.separateDepthStencilLayoutMode != SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
1190 	{
1191 		DE_ASSERT(m_imageMipLevels == 1u);
1192 
1193 		for (deUint32 arrayLayer = 0; arrayLayer < m_params.imageLayerCount; ++arrayLayer)
1194 		{
1195 			de::MovePtr<TextureLevelPyramid>	image			= readImage(VK_IMAGE_ASPECT_STENCIL_BIT, arrayLayer);
1196 			std::string							message;
1197 			deUint32							stencilValue;
1198 
1199 			for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
1200 			for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
1201 			{
1202 				if (isInClearRange(clearCoords, x, y, arrayLayer, m_params.imageViewLayerRange, m_params.clearLayerRange))
1203 					stencilValue = m_params.clearValue[0].depthStencil.stencil;
1204 				else
1205 				if (isInInitialClearRange(m_isAttachmentFormat, 0u /* mipLevel */, arrayLayer, m_params.imageViewLayerRange))
1206 				{
1207 					stencilValue = m_params.initValue.depthStencil.stencil;
1208 				}
1209 				else
1210 					continue;
1211 
1212 				if (!comparePixelToStencilClearValue(image->getLevel(0), x, y, stencilValue, message))
1213 					return TestStatus::fail("Stencil value mismatch! " + message);
1214 			}
1215 		}
1216 	}
1217 
1218 	if (!isDepthStencilFormat(m_params.imageFormat))
1219 	{
1220 		for (deUint32 arrayLayer = 0; arrayLayer < m_params.imageLayerCount; ++arrayLayer)
1221 		{
1222 			de::MovePtr<TextureLevelPyramid>	image			= readImage(VK_IMAGE_ASPECT_COLOR_BIT, arrayLayer);
1223 			std::string							message;
1224 			const VkClearColorValue*			pColorValue;
1225 
1226 			for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
1227 			{
1228 				const int					clearColorNdx	= ((mipLevel < m_thresholdMipLevel || m_params.isColorMultipleSubresourceRangeTest) ? 0 : 1);
1229 				const VkExtent3D			extent			= getMipLevelExtent(m_params.imageExtent, mipLevel);
1230 				const VkClearColorValue*	pExpectedColorValue = &(m_params.useSeparateExpectedClearValue ? m_params.expectedClearValue : m_params.clearValue)[clearColorNdx].color;
1231 
1232 				for (deUint32 z = 0; z < extent.depth;  ++z)
1233 				for (deUint32 y = 0; y < extent.height; ++y)
1234 				for (deUint32 x = 0; x < extent.width;  ++x)
1235 				{
1236 					if (isInClearRange(clearCoords, x, y, arrayLayer, m_params.imageViewLayerRange, m_params.clearLayerRange))
1237 					{
1238 						pColorValue = pExpectedColorValue;
1239 					}
1240 					else
1241 					{
1242 						if (isInInitialClearRange(m_isAttachmentFormat, mipLevel, arrayLayer, m_params.imageViewLayerRange))
1243 						{
1244 							pColorValue = &m_params.initValue.color;
1245 						}
1246 						else
1247 						{
1248 							continue;
1249 						}
1250 					}
1251 					if (!comparePixelToColorClearValue(image->getLevel(mipLevel), x, y, z, *pColorValue, message))
1252 						return TestStatus::fail("Color value mismatch! " + message);
1253 				}
1254 			}
1255 		}
1256 	}
1257 
1258 	return TestStatus::pass(successMessage);
1259 }
1260 
beginRenderPass(VkSubpassContents content,VkClearValue clearValue) const1261 void ImageClearingTestInstance::beginRenderPass (VkSubpassContents content, VkClearValue clearValue) const
1262 {
1263 	vk::beginRenderPass(m_vkd, *m_commandBuffer, *m_renderPass, *m_frameBuffer, makeRect2D(0, 0, m_params.imageExtent.width, m_params.imageExtent.height), clearValue, content);
1264 }
1265 
1266 class ClearColorImageTestInstance : public ImageClearingTestInstance
1267 {
1268 public:
ClearColorImageTestInstance(Context & context,const TestParams & testParams,bool twoStep=false)1269 						ClearColorImageTestInstance	(Context& context, const TestParams& testParams, bool twoStep = false) : ImageClearingTestInstance (context, testParams), m_twoStep(twoStep) {}
1270 	virtual TestStatus	iterate						(void);
1271 protected:
1272 	bool				m_twoStep;
1273 };
1274 
1275 class TwoStepClearColorImageTestInstance : public ClearColorImageTestInstance
1276 {
1277 public:
TwoStepClearColorImageTestInstance(Context & context,const TestParams & testParams)1278 	TwoStepClearColorImageTestInstance (Context& context, const TestParams& testParams) : ClearColorImageTestInstance(context, testParams, true) {}
1279 };
1280 
1281 class ClearColorImageMultipleSubresourceRangeTestInstance : public ClearColorImageTestInstance
1282 {
1283 public:
ClearColorImageMultipleSubresourceRangeTestInstance(Context & context,const TestParams & testParams)1284 	ClearColorImageMultipleSubresourceRangeTestInstance	(Context& context, const TestParams& testParams) : ClearColorImageTestInstance(context, testParams, false) {}
1285 	virtual TestStatus	iterate			(void);
1286 };
1287 
iterate(void)1288 TestStatus ClearColorImageMultipleSubresourceRangeTestInstance::iterate(void)
1289 {
1290 	std::vector<VkImageSubresourceRange> subresourceRanges;
1291 
1292 	DE_ASSERT(m_imageMipLevels > 1u);
1293 
1294 	deUint32 mipLevel = 0u;
1295 	// Create a subresource range per mipmap level.
1296 	do {
1297 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, mipLevel++, 1u, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1298 	} while (mipLevel < m_imageMipLevels);
1299 
1300 	beginCommandBuffer(0);
1301 
1302 	pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,				// VkPipelineStageFlags		srcStageMask
1303 						 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,			// VkPipelineStageFlags		dstStageMask
1304 						 0,												// VkAccessFlags			srcAccessMask
1305 						 (m_isAttachmentFormat
1306 							? VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
1307 							: VK_ACCESS_TRANSFER_WRITE_BIT),			// VkAccessFlags			dstAccessMask
1308 						 VK_IMAGE_LAYOUT_UNDEFINED,						// VkImageLayout			oldLayout;
1309 						 (m_isAttachmentFormat
1310 							? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
1311 							: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));	// VkImageLayout			newLayout;
1312 
1313 	if (m_isAttachmentFormat)
1314 	{
1315 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1316 		endRenderPass(m_vkd, *m_commandBuffer);
1317 
1318 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,		// VkPipelineStageFlags		srcStageMask
1319 			VK_PIPELINE_STAGE_TRANSFER_BIT,								// VkPipelineStageFlags		dstStageMask
1320 			VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,						// VkAccessFlags			srcAccessMask
1321 			VK_ACCESS_TRANSFER_WRITE_BIT,								// VkAccessFlags			dstAccessMask
1322 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,					// VkImageLayout			oldLayout;
1323 			VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);						// VkImageLayout			newLayout;
1324 	}
1325 
1326 	// Test clear color in all ranges
1327 	m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].color, static_cast<deUint32>(subresourceRanges.size()), subresourceRanges.data());
1328 
1329 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		srcStageMask
1330 						 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
1331 						 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			srcAccessMask
1332 						 VK_ACCESS_TRANSFER_READ_BIT,					// VkAccessFlags			dstAccessMask
1333 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,			// VkImageLayout			oldLayout;
1334 						 VK_IMAGE_LAYOUT_GENERAL);						// VkImageLayout			newLayout;
1335 
1336 	endCommandBuffer();
1337 	submitCommandBuffer();
1338 
1339 	return verifyResultImage("cmdClearColorImage passed");
1340 }
1341 
iterate(void)1342 TestStatus ClearColorImageTestInstance::iterate (void)
1343 {
1344 	std::vector<VkImageSubresourceRange> subresourceRanges;
1345 	std::vector<VkImageSubresourceRange> steptwoRanges;
1346 
1347 	if (m_imageMipLevels == 1)
1348 	{
1349 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, 0u,					1u,							m_params.clearLayerRange.baseArrayLayer, m_twoStep ? 1 : m_params.clearLayerRange.layerCount));
1350 		steptwoRanges.push_back(	makeImageSubresourceRange(m_imageAspectFlags, 0u,					VK_REMAINING_MIP_LEVELS,	m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS));
1351 	}
1352 	else
1353 	{
1354 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, 0u,					m_thresholdMipLevel,		m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1355 		subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, m_thresholdMipLevel,	VK_REMAINING_MIP_LEVELS,	m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1356 		steptwoRanges.push_back(	makeImageSubresourceRange(m_imageAspectFlags, 0u,					m_thresholdMipLevel,		m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS));
1357 		steptwoRanges.push_back(	makeImageSubresourceRange(m_imageAspectFlags, m_thresholdMipLevel,	VK_REMAINING_MIP_LEVELS,	m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS));
1358 	}
1359 
1360 	beginCommandBuffer(0);
1361 
1362 	pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,				// VkPipelineStageFlags		srcStageMask
1363 						 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,			// VkPipelineStageFlags		dstStageMask
1364 						 0,												// VkAccessFlags			srcAccessMask
1365 						 (m_isAttachmentFormat
1366 							? VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
1367 							: VK_ACCESS_TRANSFER_WRITE_BIT),			// VkAccessFlags			dstAccessMask
1368 						 VK_IMAGE_LAYOUT_UNDEFINED,						// VkImageLayout			oldLayout;
1369 						 (m_isAttachmentFormat
1370 							? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
1371 							: VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));	// VkImageLayout			newLayout;
1372 
1373 	if (m_isAttachmentFormat)
1374 	{
1375 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1376 		endRenderPass(m_vkd, *m_commandBuffer);
1377 
1378 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,		// VkPipelineStageFlags		srcStageMask
1379 			VK_PIPELINE_STAGE_TRANSFER_BIT,								// VkPipelineStageFlags		dstStageMask
1380 			VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,						// VkAccessFlags			srcAccessMask
1381 			VK_ACCESS_TRANSFER_WRITE_BIT,								// VkAccessFlags			dstAccessMask
1382 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,					// VkImageLayout			oldLayout;
1383 			VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);						// VkImageLayout			newLayout;
1384 	}
1385 
1386 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		srcStageMask
1387 						 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
1388 						 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			srcAccessMask
1389 						 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			dstAccessMask
1390 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,			// VkImageLayout			oldLayout;
1391 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);			// VkImageLayout			newLayout;
1392 
1393 	// Different clear color per range
1394 	for (std::size_t i = 0u; i < subresourceRanges.size(); ++i)
1395 	{
1396 		m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[i].color, 1, &subresourceRanges[i]);
1397 
1398 		if (m_twoStep)
1399 		{
1400 			pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		srcStageMask
1401 								 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
1402 								 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			srcAccessMask
1403 								 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			dstAccessMask
1404 								 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,			// VkImageLayout			oldLayout;
1405 								 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);			// VkImageLayout			newLayout;
1406 
1407 			m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[i].color, 1, &steptwoRanges[i]);
1408 		}
1409 	}
1410 
1411 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		srcStageMask
1412 						 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
1413 						 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			srcAccessMask
1414 						 VK_ACCESS_TRANSFER_READ_BIT,					// VkAccessFlags			dstAccessMask
1415 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,			// VkImageLayout			oldLayout;
1416 						 VK_IMAGE_LAYOUT_GENERAL);						// VkImageLayout			newLayout;
1417 
1418 	endCommandBuffer();
1419 	submitCommandBuffer();
1420 
1421 	return verifyResultImage("cmdClearColorImage passed");
1422 }
1423 
1424 class ClearDepthStencilImageTestInstance : public ImageClearingTestInstance
1425 {
1426 public:
ClearDepthStencilImageTestInstance(Context & context,const TestParams & testParams,bool twoStep=false)1427 						ClearDepthStencilImageTestInstance	(Context& context, const TestParams& testParams, bool twoStep = false) : ImageClearingTestInstance (context, testParams), m_twoStep(twoStep) {}
1428 	virtual TestStatus	iterate								(void);
1429 protected:
1430 	bool				m_twoStep;
1431 };
1432 
1433 class TwoStepClearDepthStencilImageTestInstance : public ClearDepthStencilImageTestInstance
1434 {
1435 public:
TwoStepClearDepthStencilImageTestInstance(Context & context,const TestParams & testParams)1436 	TwoStepClearDepthStencilImageTestInstance (Context& context, const TestParams& testParams) : ClearDepthStencilImageTestInstance (context, testParams, true) { }
1437 };
1438 
1439 class ClearDepthStencilImageMultipleSubresourceRangeTestInstance : public ClearDepthStencilImageTestInstance
1440 {
1441 public:
ClearDepthStencilImageMultipleSubresourceRangeTestInstance(Context & context,const TestParams & testParams)1442 	ClearDepthStencilImageMultipleSubresourceRangeTestInstance	(Context& context, const TestParams& testParams) :  ClearDepthStencilImageTestInstance(context, testParams, false) { }
1443 	virtual TestStatus	iterate					(void);
1444 };
1445 
iterate(void)1446 TestStatus ClearDepthStencilImageMultipleSubresourceRangeTestInstance::iterate (void)
1447 {
1448 	VkImageLayout		layout	= (m_isAttachmentFormat
1449 									?	VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
1450 									:	VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1451 	VkImageAspectFlags	aspectMask	= m_imageAspectFlags;
1452 
1453 	// Depth/Stencil formats only. No separate layout modes.
1454 	DE_ASSERT(m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE);
1455 
1456 	std::vector<VkImageSubresourceRange> subresourceRanges;
1457 
1458     subresourceRanges.push_back(makeImageSubresourceRange(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1459     subresourceRanges.push_back(makeImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, m_params.clearLayerRange.baseArrayLayer, m_params.clearLayerRange.layerCount));
1460 
1461 	beginCommandBuffer(0);
1462 
1463 	pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,					// VkPipelineStageFlags		srcStageMask
1464 						 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,				// VkPipelineStageFlags		dstStageMask
1465 						 0,													// VkAccessFlags			srcAccessMask
1466 						 (m_isAttachmentFormat
1467 							?	VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
1468 							:	VK_ACCESS_TRANSFER_WRITE_BIT),				// VkAccessFlags			dstAccessMask
1469 						 VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout			oldLayout;
1470 						 layout,											// VkImageLayout			newLayout;
1471 						 aspectMask);										// VkImageAspectFlags		aspectMask;
1472 
1473 	if (m_isAttachmentFormat)
1474 	{
1475 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1476 		endRenderPass(m_vkd, *m_commandBuffer);
1477 
1478 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,					// VkPipelineStageFlags		srcStageMask
1479 							 VK_PIPELINE_STAGE_TRANSFER_BIT,						// VkPipelineStageFlags		dstStageMask
1480 							 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,			// VkAccessFlags			srcAccessMask
1481 							 VK_ACCESS_TRANSFER_WRITE_BIT,							// VkAccessFlags			dstAccessMask
1482 							 layout,												// VkImageLayout			oldLayout;
1483 							 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,					// VkImageLayout			newLayout;
1484 							 aspectMask);											// VkImageAspectFlags		aspectMask;
1485 	}
1486 
1487 	m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, static_cast<deUint32>(subresourceRanges.size()), subresourceRanges.data());
1488 
1489 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,					// VkPipelineStageFlags		srcStageMask
1490 						 VK_PIPELINE_STAGE_TRANSFER_BIT,					// VkPipelineStageFlags		dstStageMask
1491 						 VK_ACCESS_TRANSFER_WRITE_BIT,						// VkAccessFlags			srcAccessMask
1492 						 VK_ACCESS_TRANSFER_READ_BIT,						// VkAccessFlags			dstAccessMask
1493 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,				// VkImageLayout			oldLayout;
1494 						 VK_IMAGE_LAYOUT_GENERAL,							// VkImageLayout			newLayout;
1495 						 aspectMask);										// VkImageAspectFlags		aspectMask;
1496 
1497 	endCommandBuffer();
1498 	submitCommandBuffer();
1499 
1500 	return verifyResultImage("cmdClearDepthStencilImage passed");
1501 }
1502 
iterate(void)1503 TestStatus ClearDepthStencilImageTestInstance::iterate (void)
1504 {
1505 	VkImageLayout		layout	= (m_isAttachmentFormat
1506 									?	VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
1507 									:	VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1508 	VkImageAspectFlags	aspectMask	= m_imageAspectFlags;
1509 	if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
1510 	{
1511 		layout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
1512 		aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1513 	}
1514 	else if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL)
1515 	{
1516 		layout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
1517 		aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
1518 	}
1519 
1520 	const VkImageSubresourceRange subresourceRange	= makeImageSubresourceRange(aspectMask, 0u, 1u,							m_params.clearLayerRange.baseArrayLayer, m_twoStep ? 1 : m_params.clearLayerRange.layerCount);
1521 	const VkImageSubresourceRange steptwoRange		= makeImageSubresourceRange(aspectMask, 0u, VK_REMAINING_MIP_LEVELS,	m_params.clearLayerRange.baseArrayLayer, VK_REMAINING_ARRAY_LAYERS);
1522 
1523 	beginCommandBuffer(0);
1524 
1525 	pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,					// VkPipelineStageFlags		srcStageMask
1526 						 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,				// VkPipelineStageFlags		dstStageMask
1527 						 0,													// VkAccessFlags			srcAccessMask
1528 						 (m_isAttachmentFormat
1529 							?	VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
1530 							:	VK_ACCESS_TRANSFER_WRITE_BIT),				// VkAccessFlags			dstAccessMask
1531 						 VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout			oldLayout;
1532 						 layout,											// VkImageLayout			newLayout;
1533 						 aspectMask);										// VkImageAspectFlags		aspectMask;
1534 
1535 	if (m_isAttachmentFormat)
1536 	{
1537 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1538 		endRenderPass(m_vkd, *m_commandBuffer);
1539 
1540 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,					// VkPipelineStageFlags		srcStageMask
1541 							 VK_PIPELINE_STAGE_TRANSFER_BIT,						// VkPipelineStageFlags		dstStageMask
1542 							 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,			// VkAccessFlags			srcAccessMask
1543 							 VK_ACCESS_TRANSFER_WRITE_BIT,							// VkAccessFlags			dstAccessMask
1544 							 layout,												// VkImageLayout			oldLayout;
1545 							 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,					// VkImageLayout			newLayout;
1546 							 aspectMask);											// VkImageAspectFlags		aspectMask;
1547 	}
1548 
1549 	m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, 1, &subresourceRange);
1550 
1551 	if (m_twoStep) {
1552 		pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		srcStageMask
1553 							 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
1554 							 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			srcAccessMask
1555 							 VK_ACCESS_TRANSFER_WRITE_BIT,					// VkAccessFlags			dstAccessMask
1556 							 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,			// VkImageLayout			oldLayout;
1557 							 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);			// VkImageLayout			newLayout;
1558 
1559 		m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, 1, &steptwoRange);
1560     }
1561 
1562 	pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,					// VkPipelineStageFlags		srcStageMask
1563 						 VK_PIPELINE_STAGE_TRANSFER_BIT,					// VkPipelineStageFlags		dstStageMask
1564 						 VK_ACCESS_TRANSFER_WRITE_BIT,						// VkAccessFlags			srcAccessMask
1565 						 VK_ACCESS_TRANSFER_READ_BIT,						// VkAccessFlags			dstAccessMask
1566 						 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,				// VkImageLayout			oldLayout;
1567 						 VK_IMAGE_LAYOUT_GENERAL,							// VkImageLayout			newLayout;
1568 						 aspectMask);										// VkImageAspectFlags		aspectMask;
1569 
1570 	endCommandBuffer();
1571 	submitCommandBuffer();
1572 
1573 	return verifyResultImage("cmdClearDepthStencilImage passed");
1574 }
1575 
1576 class ClearAttachmentTestInstance : public ImageClearingTestInstance
1577 {
1578 public:
1579 	enum ClearType
1580 	{
1581 		FULL_CLEAR,
1582 		PARTIAL_CLEAR,
1583 	};
1584 
ClearAttachmentTestInstance(Context & context,const TestParams & testParams,const ClearType clearType=FULL_CLEAR)1585 	ClearAttachmentTestInstance (Context& context, const TestParams& testParams, const ClearType clearType = FULL_CLEAR)
1586 		: ImageClearingTestInstance	(context, testParams)
1587 		, m_clearType				(clearType)
1588 	{
1589 		if (!m_isAttachmentFormat)
1590 			TCU_THROW(NotSupportedError, "Format not renderable");
1591 	}
1592 
iterate(void)1593 	TestStatus iterate (void)
1594 	{
1595 		const bool			isDepthStencil		= isDepthStencilFormat(m_params.imageFormat);
1596 		const VkAccessFlags	accessMask			= (isDepthStencil ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT     : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1597 		VkImageLayout		attachmentLayout	= (isDepthStencil ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
1598 		VkImageAspectFlags	aspectMask			= m_imageAspectFlags;
1599 
1600 		if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH)
1601 		{
1602 			attachmentLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
1603 			aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1604 		}
1605 		else if (m_params.separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL)
1606 		{
1607 			attachmentLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
1608 			aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
1609 		}
1610 
1611 		const VkClearAttachment clearAttachment =
1612 		{
1613 			aspectMask,							// VkImageAspectFlags	aspectMask;
1614 			0u,									// deUint32				colorAttachment;
1615 			m_params.clearValue[0]				// VkClearValue			clearValue;
1616 		};
1617 
1618 		UVec4						clearCoords;
1619 		std::vector<VkClearRect>	clearRects;
1620 
1621 		if (m_clearType == FULL_CLEAR)
1622 		{
1623 			const VkClearRect rect =
1624 			{
1625 				{
1626 					{ 0, 0 },																	// VkOffset2D    offset;
1627 					{ m_params.imageExtent.width, m_params.imageExtent.height }					// VkExtent2D    extent;
1628 				},																			// VkRect2D	rect;
1629 				m_params.clearLayerRange.baseArrayLayer,								// deUint32	baseArrayLayer;
1630 				m_params.clearLayerRange.layerCount,									// deUint32	layerCount;
1631 			};
1632 
1633 			clearRects.push_back(rect);
1634 		}
1635 		else
1636 		{
1637 			const deUint32	clearX		= m_params.imageExtent.width  / 8u;
1638 			const deUint32	clearY		= m_params.imageExtent.height / 8u;
1639 			const deUint32	clearWidth	= m_params.imageExtent.width  / 2u;
1640 			const deUint32	clearHeight	= m_params.imageExtent.height / 2u;
1641 
1642 			clearCoords	= UVec4(clearX,					clearY,
1643 								clearX + clearWidth,	clearY + clearHeight);
1644 
1645 			const VkClearRect rects[2] =
1646 			{
1647 				{
1648 					{
1649 						{ 0,							static_cast<deInt32>(clearY)	},		// VkOffset2D    offset;
1650 						{ m_params.imageExtent.width,	clearHeight						}		// VkExtent2D    extent;
1651 					},																		// VkRect2D	rect;
1652 					m_params.clearLayerRange.baseArrayLayer,								// deUint32	baseArrayLayer;
1653 					m_params.clearLayerRange.layerCount										// deUint32	layerCount;
1654 				},
1655 				{
1656 					{
1657 						{ static_cast<deInt32>(clearX),	0							},			// VkOffset2D    offset;
1658 						{ clearWidth,					m_params.imageExtent.height	}			// VkExtent2D    extent;
1659 					},																		// VkRect2D	rect;
1660 					m_params.clearLayerRange.baseArrayLayer,								// deUint32	baseArrayLayer;
1661 					m_params.clearLayerRange.layerCount										// deUint32	layerCount;
1662 				}
1663 			};
1664 
1665 			clearRects.push_back(rects[0]);
1666 			clearRects.push_back(rects[1]);
1667 		}
1668 
1669 		beginCommandBuffer(0);
1670 
1671 		pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,				// VkPipelineStageFlags		srcStageMask
1672 							 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,			// VkPipelineStageFlags		dstStageMask
1673 							 0,												// VkAccessFlags			srcAccessMask
1674 							 accessMask,									// VkAccessFlags			dstAccessMask
1675 							 VK_IMAGE_LAYOUT_UNDEFINED,						// VkImageLayout			oldLayout;
1676 							 attachmentLayout,								// VkImageLayout			newLayout;
1677 							 aspectMask);									// VkImageAspectFlags		aspectMask;
1678 
1679 		beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1680 		m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, static_cast<deUint32>(clearRects.size()), &clearRects[0]);
1681 		endRenderPass(m_vkd, *m_commandBuffer);
1682 
1683 		pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,			// VkPipelineStageFlags		srcStageMask
1684 							 VK_PIPELINE_STAGE_TRANSFER_BIT,				// VkPipelineStageFlags		dstStageMask
1685 							 accessMask,									// VkAccessFlags			srcAccessMask
1686 							 VK_ACCESS_TRANSFER_READ_BIT,					// VkAccessFlags			dstAccessMask
1687 							 attachmentLayout,								// VkImageLayout			oldLayout;
1688 							 VK_IMAGE_LAYOUT_GENERAL,						// VkImageLayout			newLayout;
1689 							 aspectMask);									// VkImageAspectFlags		aspectMask;
1690 
1691 		endCommandBuffer();
1692 		submitCommandBuffer();
1693 
1694 		return verifyResultImage("cmdClearAttachments passed", clearCoords);
1695 	}
1696 
1697 private:
1698 	const ClearType	m_clearType;
1699 };
1700 
1701 class PartialClearAttachmentTestInstance : public ClearAttachmentTestInstance
1702 {
1703 public:
PartialClearAttachmentTestInstance(Context & context,const TestParams & testParams)1704 	PartialClearAttachmentTestInstance (Context& context, const TestParams& testParams) : ClearAttachmentTestInstance (context, testParams, PARTIAL_CLEAR) {}
1705 };
1706 
makeClearColorValue(VkFormat format,float r,float g,float b,float a)1707 VkClearValue makeClearColorValue (VkFormat format, float r, float g, float b, float a)
1708 {
1709 	const	TextureFormat tcuFormat	= mapVkFormat(format);
1710 	VkClearValue clearValue;
1711 
1712 	if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_FLOATING_POINT
1713 		|| getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_FIXED_POINT
1714 		|| getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT)
1715 	{
1716 		clearValue.color.float32[0] = r;
1717 		clearValue.color.float32[1] = g;
1718 		clearValue.color.float32[2] = b;
1719 		clearValue.color.float32[3] = a;
1720 	}
1721 	else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
1722 	{
1723 		UVec4 maxValues = getFormatMaxUintValue(tcuFormat);
1724 
1725 		clearValue.color.uint32[0] = (deUint32)((float)maxValues[0] * r);
1726 		clearValue.color.uint32[1] = (deUint32)((float)maxValues[1] * g);
1727 		clearValue.color.uint32[2] = (deUint32)((float)maxValues[2] * b);
1728 		clearValue.color.uint32[3] = (deUint32)((float)maxValues[3] * a);
1729 	}
1730 	else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER)
1731 	{
1732 		IVec4 maxValues = getFormatMaxIntValue(tcuFormat);
1733 
1734 		clearValue.color.int32[0] = (deUint32)((float)maxValues[0] * r);
1735 		clearValue.color.int32[1] = (deUint32)((float)maxValues[1] * g);
1736 		clearValue.color.int32[2] = (deUint32)((float)maxValues[2] * b);
1737 		clearValue.color.int32[3] = (deUint32)((float)maxValues[3] * a);
1738 	}
1739 	else
1740 		DE_FATAL("Unknown channel class");
1741 
1742 	return clearValue;
1743 }
1744 
getFormatCaseName(VkFormat format)1745 std::string getFormatCaseName (VkFormat format)
1746 {
1747 	return de::toLower(de::toString(getFormatStr(format)).substr(10));
1748 }
1749 
getImageTypeCaseName(VkImageType type)1750 const char* getImageTypeCaseName (VkImageType type)
1751 {
1752 	const char* s_names[] =
1753 	{
1754 		"1d",
1755 		"2d",
1756 		"3d"
1757 	};
1758 	return de::getSizedArrayElement<VK_CORE_IMAGE_TYPE_LAST>(s_names, type);
1759 }
1760 
getImageTilingCaseName(VkImageTiling tiling)1761 const char* getImageTilingCaseName (VkImageTiling tiling)
1762 {
1763 	const char* s_names[] =
1764 	{
1765 		"optimal",
1766 		"linear",
1767 	};
1768 	return de::getSizedArrayElement<VK_CORE_IMAGE_TILING_LAST>(s_names, tiling);
1769 }
1770 
createImageClearingTestsCommon(TestContext & testCtx,tcu::TestCaseGroup * imageClearingTests,AllocationKind allocationKind)1771 TestCaseGroup* createImageClearingTestsCommon (TestContext& testCtx, tcu::TestCaseGroup* imageClearingTests, AllocationKind allocationKind)
1772 {
1773 	de::MovePtr<TestCaseGroup>	colorImageClearTests					(new TestCaseGroup(testCtx, "clear_color_image", "Color Image Clear Tests"));
1774 	de::MovePtr<TestCaseGroup>	depthStencilImageClearTests				(new TestCaseGroup(testCtx, "clear_depth_stencil_image", "Color Depth/Stencil Image Tests"));
1775 	de::MovePtr<TestCaseGroup>	colorAttachmentClearTests				(new TestCaseGroup(testCtx, "clear_color_attachment", "Color Color Attachment Tests"));
1776 	de::MovePtr<TestCaseGroup>	depthStencilAttachmentClearTests		(new TestCaseGroup(testCtx, "clear_depth_stencil_attachment", "Color Depth/Stencil Attachment Tests"));
1777 	de::MovePtr<TestCaseGroup>	partialColorAttachmentClearTests		(new TestCaseGroup(testCtx, "partial_clear_color_attachment", "Clear Partial Color Attachment Tests"));
1778 	de::MovePtr<TestCaseGroup>	partialDepthStencilAttachmentClearTests	(new TestCaseGroup(testCtx, "partial_clear_depth_stencil_attachment", "Clear Partial Depth/Stencil Attachment Tests"));
1779 
1780 	// Some formats are commented out due to the tcu::TextureFormat does not support them yet.
1781 	const VkFormat		colorImageFormatsToTest[]	=
1782 	{
1783 		VK_FORMAT_R4G4_UNORM_PACK8,
1784 		VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1785 		VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1786 		VK_FORMAT_R5G6B5_UNORM_PACK16,
1787 		VK_FORMAT_B5G6R5_UNORM_PACK16,
1788 		VK_FORMAT_R5G5B5A1_UNORM_PACK16,
1789 		VK_FORMAT_B5G5R5A1_UNORM_PACK16,
1790 		VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1791 		VK_FORMAT_R8_UNORM,
1792 		VK_FORMAT_R8_SNORM,
1793 		VK_FORMAT_R8_USCALED,
1794 		VK_FORMAT_R8_SSCALED,
1795 		VK_FORMAT_R8_UINT,
1796 		VK_FORMAT_R8_SINT,
1797 		VK_FORMAT_R8_SRGB,
1798 		VK_FORMAT_R8G8_UNORM,
1799 		VK_FORMAT_R8G8_SNORM,
1800 		VK_FORMAT_R8G8_USCALED,
1801 		VK_FORMAT_R8G8_SSCALED,
1802 		VK_FORMAT_R8G8_UINT,
1803 		VK_FORMAT_R8G8_SINT,
1804 		VK_FORMAT_R8G8_SRGB,
1805 		VK_FORMAT_R8G8B8_UNORM,
1806 		VK_FORMAT_R8G8B8_SNORM,
1807 		VK_FORMAT_R8G8B8_USCALED,
1808 		VK_FORMAT_R8G8B8_SSCALED,
1809 		VK_FORMAT_R8G8B8_UINT,
1810 		VK_FORMAT_R8G8B8_SINT,
1811 		VK_FORMAT_R8G8B8_SRGB,
1812 		VK_FORMAT_B8G8R8_UNORM,
1813 		VK_FORMAT_B8G8R8_SNORM,
1814 		VK_FORMAT_B8G8R8_USCALED,
1815 		VK_FORMAT_B8G8R8_SSCALED,
1816 		VK_FORMAT_B8G8R8_UINT,
1817 		VK_FORMAT_B8G8R8_SINT,
1818 		VK_FORMAT_B8G8R8_SRGB,
1819 		VK_FORMAT_R8G8B8A8_UNORM,
1820 		VK_FORMAT_R8G8B8A8_SNORM,
1821 		VK_FORMAT_R8G8B8A8_USCALED,
1822 		VK_FORMAT_R8G8B8A8_SSCALED,
1823 		VK_FORMAT_R8G8B8A8_UINT,
1824 		VK_FORMAT_R8G8B8A8_SINT,
1825 		VK_FORMAT_R8G8B8A8_SRGB,
1826 		VK_FORMAT_B8G8R8A8_UNORM,
1827 		VK_FORMAT_B8G8R8A8_SNORM,
1828 		VK_FORMAT_B8G8R8A8_USCALED,
1829 		VK_FORMAT_B8G8R8A8_SSCALED,
1830 		VK_FORMAT_B8G8R8A8_UINT,
1831 		VK_FORMAT_B8G8R8A8_SINT,
1832 		VK_FORMAT_B8G8R8A8_SRGB,
1833 		VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1834 		VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1835 		VK_FORMAT_A8B8G8R8_USCALED_PACK32,
1836 		VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
1837 		VK_FORMAT_A8B8G8R8_UINT_PACK32,
1838 		VK_FORMAT_A8B8G8R8_SINT_PACK32,
1839 		VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1840 		VK_FORMAT_A2R10G10B10_UNORM_PACK32,
1841 		VK_FORMAT_A2R10G10B10_SNORM_PACK32,
1842 		VK_FORMAT_A2R10G10B10_USCALED_PACK32,
1843 		VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
1844 		VK_FORMAT_A2R10G10B10_UINT_PACK32,
1845 		VK_FORMAT_A2R10G10B10_SINT_PACK32,
1846 		VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1847 		VK_FORMAT_A2B10G10R10_SNORM_PACK32,
1848 		VK_FORMAT_A2B10G10R10_USCALED_PACK32,
1849 		VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
1850 		VK_FORMAT_A2B10G10R10_UINT_PACK32,
1851 		VK_FORMAT_A2B10G10R10_SINT_PACK32,
1852 		VK_FORMAT_R16_UNORM,
1853 		VK_FORMAT_R16_SNORM,
1854 		VK_FORMAT_R16_USCALED,
1855 		VK_FORMAT_R16_SSCALED,
1856 		VK_FORMAT_R16_UINT,
1857 		VK_FORMAT_R16_SINT,
1858 		VK_FORMAT_R16_SFLOAT,
1859 		VK_FORMAT_R16G16_UNORM,
1860 		VK_FORMAT_R16G16_SNORM,
1861 		VK_FORMAT_R16G16_USCALED,
1862 		VK_FORMAT_R16G16_SSCALED,
1863 		VK_FORMAT_R16G16_UINT,
1864 		VK_FORMAT_R16G16_SINT,
1865 		VK_FORMAT_R16G16_SFLOAT,
1866 		VK_FORMAT_R16G16B16_UNORM,
1867 		VK_FORMAT_R16G16B16_SNORM,
1868 		VK_FORMAT_R16G16B16_USCALED,
1869 		VK_FORMAT_R16G16B16_SSCALED,
1870 		VK_FORMAT_R16G16B16_UINT,
1871 		VK_FORMAT_R16G16B16_SINT,
1872 		VK_FORMAT_R16G16B16_SFLOAT,
1873 		VK_FORMAT_R16G16B16A16_UNORM,
1874 		VK_FORMAT_R16G16B16A16_SNORM,
1875 		VK_FORMAT_R16G16B16A16_USCALED,
1876 		VK_FORMAT_R16G16B16A16_SSCALED,
1877 		VK_FORMAT_R16G16B16A16_UINT,
1878 		VK_FORMAT_R16G16B16A16_SINT,
1879 		VK_FORMAT_R16G16B16A16_SFLOAT,
1880 		VK_FORMAT_R32_UINT,
1881 		VK_FORMAT_R32_SINT,
1882 		VK_FORMAT_R32_SFLOAT,
1883 		VK_FORMAT_R32G32_UINT,
1884 		VK_FORMAT_R32G32_SINT,
1885 		VK_FORMAT_R32G32_SFLOAT,
1886 		VK_FORMAT_R32G32B32_UINT,
1887 		VK_FORMAT_R32G32B32_SINT,
1888 		VK_FORMAT_R32G32B32_SFLOAT,
1889 		VK_FORMAT_R32G32B32A32_UINT,
1890 		VK_FORMAT_R32G32B32A32_SINT,
1891 		VK_FORMAT_R32G32B32A32_SFLOAT,
1892 //		VK_FORMAT_R64_UINT,
1893 //		VK_FORMAT_R64_SINT,
1894 //		VK_FORMAT_R64_SFLOAT,
1895 //		VK_FORMAT_R64G64_UINT,
1896 //		VK_FORMAT_R64G64_SINT,
1897 //		VK_FORMAT_R64G64_SFLOAT,
1898 //		VK_FORMAT_R64G64B64_UINT,
1899 //		VK_FORMAT_R64G64B64_SINT,
1900 //		VK_FORMAT_R64G64B64_SFLOAT,
1901 //		VK_FORMAT_R64G64B64A64_UINT,
1902 //		VK_FORMAT_R64G64B64A64_SINT,
1903 //		VK_FORMAT_R64G64B64A64_SFLOAT,
1904 		VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1905 		VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1906 //		VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1907 //		VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1908 //		VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1909 //		VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1910 //		VK_FORMAT_BC2_UNORM_BLOCK,
1911 //		VK_FORMAT_BC2_SRGB_BLOCK,
1912 //		VK_FORMAT_BC3_UNORM_BLOCK,
1913 //		VK_FORMAT_BC3_SRGB_BLOCK,
1914 //		VK_FORMAT_BC4_UNORM_BLOCK,
1915 //		VK_FORMAT_BC4_SNORM_BLOCK,
1916 //		VK_FORMAT_BC5_UNORM_BLOCK,
1917 //		VK_FORMAT_BC5_SNORM_BLOCK,
1918 //		VK_FORMAT_BC6H_UFLOAT_BLOCK,
1919 //		VK_FORMAT_BC6H_SFLOAT_BLOCK,
1920 //		VK_FORMAT_BC7_UNORM_BLOCK,
1921 //		VK_FORMAT_BC7_SRGB_BLOCK,
1922 //		VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1923 //		VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1924 //		VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1925 //		VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1926 //		VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1927 //		VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1928 //		VK_FORMAT_EAC_R11_UNORM_BLOCK,
1929 //		VK_FORMAT_EAC_R11_SNORM_BLOCK,
1930 //		VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1931 //		VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1932 //		VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1933 //		VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1934 //		VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1935 //		VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1936 //		VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1937 //		VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1938 //		VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1939 //		VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1940 //		VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1941 //		VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1942 //		VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1943 //		VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1944 //		VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1945 //		VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1946 //		VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1947 //		VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1948 //		VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1949 //		VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1950 //		VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1951 //		VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1952 //		VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1953 //		VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1954 //		VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1955 //		VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1956 //		VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1957 //		VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1958 //		VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1959 //		VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
1960 
1961 		VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT,
1962 		VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT,
1963 	};
1964 	const size_t	numOfColorImageFormatsToTest			= DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
1965 
1966 	const VkFormat	depthStencilImageFormatsToTest[]		=
1967 	{
1968 		VK_FORMAT_D16_UNORM,
1969 		VK_FORMAT_X8_D24_UNORM_PACK32,
1970 		VK_FORMAT_D32_SFLOAT,
1971 		VK_FORMAT_S8_UINT,
1972 		VK_FORMAT_D16_UNORM_S8_UINT,
1973 		VK_FORMAT_D24_UNORM_S8_UINT,
1974 		VK_FORMAT_D32_SFLOAT_S8_UINT
1975 	};
1976 	const size_t	numOfDepthStencilImageFormatsToTest		= DE_LENGTH_OF_ARRAY(depthStencilImageFormatsToTest);
1977 
1978 	struct ClearTestColorParams
1979 	{
1980 		bool				matchTextureChannelClass;
1981 		TextureChannelClass	textureChannelClass;
1982 		const char*			testNameSuffix;
1983 		float				clearColors[2][4];
1984 		bool				useSeparateExpectedColors;
1985 		float				expectedColors[2][4];
1986 	};
1987 	const ClearTestColorParams clearColorsToTest[] =
1988 	{
1989 		{
1990 			false,										// matchTextureChannelClass
1991 			TEXTURECHANNELCLASS_LAST,					// textureChannelClass
1992 			"",											// testNameSuffix
1993 			{
1994 				{ 0.1f, 0.5f, 0.3f, 0.9f },				// clearColors[0]
1995 				{ 0.3f, 0.6f, 0.2f, 0.7f },				// clearColors[1]
1996 			},
1997 			false,										// useSeparateExpectedColors
1998 			{ }											// expectedColors
1999 		},
2000 		{
2001 			true,										// matchTextureChannelClass
2002 			TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT,	// textureChannelClass
2003 			"_clamp_input",								// testNameSuffix
2004 			{
2005 				{ -0.1f, -1e6f, -0.3f, -1.5f },			// clearColors[0]
2006 				{ -1.5f, -0.6f, -1e6f, -0.7f },			// clearColors[1]
2007 			},
2008 			true,										// useSeparateExpectedColors
2009 			{
2010 				{ 0.0f, 0.0f, 0.0f, 0.0f },				// expectedColors[0]
2011 				{ 0.0f, 0.0f, 0.0f, 0.0f },				// expectedColors[1]
2012 			}
2013 		}
2014 	};
2015 	const size_t	numOfClearColorsToTest			= DE_LENGTH_OF_ARRAY(clearColorsToTest);
2016 
2017 	struct ImageLayerParams
2018 	{
2019 		deUint32		imageLayerCount;
2020 		LayerRange		imageViewRange;
2021 		LayerRange		clearLayerRange;
2022 		bool			twoStep;
2023 		const char*		testName;
2024 		bool			isCube;
2025 	};
2026 	const ImageLayerParams imageLayerParamsToTest[] =
2027 	{
2028 		{
2029 			1u,									// imageLayerCount
2030 			{0u, 1u},							// imageViewRange
2031 			{0u, 1u},							// clearLayerRange
2032 			false,								// twoStep
2033 			"single_layer",						// testName
2034 			false								// isCube
2035 		},
2036 		{
2037 			16u,								// imageLayerCount
2038 			{3u, 12u},							// imageViewRange
2039 			{2u, 5u},							// clearLayerRange
2040 			false,								// twoStep
2041 			"multiple_layers",					// testName
2042 			false								// isCube
2043 		},
2044 		{
2045 			15u,								// imageLayerCount
2046 			{ 3u, 6u },							// imageViewRange
2047 			{ 2u, 1u },							// clearLayerRange
2048 			false,								// twoStep
2049 			"cube_layers",						// testName
2050 			true								// isCube
2051 		},
2052 		{
2053 			16u,								// imageLayerCount
2054 			{ 3u, 12u },						// imageViewRange
2055 			{ 8u, VK_REMAINING_ARRAY_LAYERS },	// clearLayerRange
2056 			false,								// twoStep
2057 			"remaining_array_layers",			// testName
2058 			false								// isCube
2059 		},
2060 		{
2061 			16u,								// imageLayerCount
2062 			{ 3u, 12u },						// imageViewRange
2063 			{ 8u, VK_REMAINING_ARRAY_LAYERS },	// clearLayerRange
2064 			true,								// twoStep
2065 			"remaining_array_layers_twostep",	// testName
2066 			false								// isCube
2067 		}
2068 	};
2069 
2070 	// Include test cases with VK_REMAINING_ARRAY_LAYERS when using vkCmdClearColorImage
2071 	const size_t		numOfImageLayerParamsToTest			= DE_LENGTH_OF_ARRAY(imageLayerParamsToTest);
2072 
2073 	// Exclude test cases with VK_REMAINING_ARRAY_LAYERS when using vkCmdClearAttachments
2074 	const size_t		numOfAttachmentLayerParamsToTest	= numOfImageLayerParamsToTest - 2;
2075 
2076 	const VkExtent3D	imageDimensions[]					=
2077 	{
2078 		{ 256,	1,		1},
2079 		{ 256,	256,	1},
2080 		{ 256,	256,	16},
2081 		{ 200,	1,		1},
2082 		{ 200,	180,	1},
2083 		{ 200,	180,	16},
2084 		{ 71,	1,		1},
2085 		{ 1,	33,		1},
2086 		{ 55,	21,		11},
2087 		{ 64,	11,		1},
2088 		{ 33,	128,	1},
2089 		{ 32,	29,		3}
2090 	};
2091 
2092 	// Clear color image
2093 	{
2094 		const VkImageType			imageTypesToTest[]		=
2095 		{
2096 			VK_IMAGE_TYPE_1D,
2097 			VK_IMAGE_TYPE_2D,
2098 			VK_IMAGE_TYPE_3D
2099 		};
2100 		const size_t				numOfImageTypesToTest	= DE_LENGTH_OF_ARRAY(imageTypesToTest);
2101 
2102 		const VkImageTiling			imageTilingsToTest[]	=
2103 		{
2104 			VK_IMAGE_TILING_OPTIMAL,
2105 			VK_IMAGE_TILING_LINEAR,
2106 		};
2107 		const size_t				numOfImageTilingsToTest	= DE_LENGTH_OF_ARRAY(imageTilingsToTest);
2108 
2109 		for (size_t	imageTypeIndex = 0; imageTypeIndex < numOfImageTypesToTest; ++imageTypeIndex)
2110 		{
2111 			de::MovePtr<TestCaseGroup> imageTypeGroup(new TestCaseGroup(testCtx, getImageTypeCaseName(imageTypesToTest[imageTypeIndex]), ""));
2112 
2113 			for (size_t	imageTilingIndex = 0; imageTilingIndex < numOfImageTilingsToTest; ++imageTilingIndex)
2114 			{
2115 				de::MovePtr<TestCaseGroup> imageTilingGroup(new TestCaseGroup(testCtx, getImageTilingCaseName(imageTilingsToTest[imageTilingIndex]), ""));
2116 
2117 				for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
2118 				{
2119 					// 3D ARRAY images are not supported
2120 					if (imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount > 1u && imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_3D)
2121 						continue;
2122 
2123 					// CUBE images are not tested in clear image tests (they are tested in clear attachment tests)
2124 					if (imageLayerParamsToTest[imageLayerParamsIndex].isCube)
2125 						continue;
2126 
2127 					de::MovePtr<TestCaseGroup> imageLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2128 
2129 					for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2130 					{
2131 						const VkExtent3D	dimensions			= imageDimensions[imageDimensionsIndex];
2132 						const std::string	dimensionsString	= extentToString(dimensions, imageTypesToTest[imageTypeIndex]);
2133 
2134 						if (imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_1D && dimensions.height > 1)
2135 							continue;
2136 						if (imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_2D && (dimensions.depth > 1 || dimensions.height == 1))
2137 							continue;
2138 						if (imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_3D && dimensions.depth == 1)
2139 							continue;
2140 
2141 						for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
2142 						{
2143 							const	VkFormat			format			= colorImageFormatsToTest[imageFormatIndex];
2144 							const	TextureFormat		tcuFormat		= mapVkFormat(format);
2145 							const	TextureChannelClass	channelClass	= getTextureChannelClass(tcuFormat.type);
2146 							for (size_t clearColorIndex = 0; clearColorIndex < numOfClearColorsToTest; ++clearColorIndex)
2147 							{
2148 								const	ClearTestColorParams&	colorParams		= clearColorsToTest[clearColorIndex];
2149 
2150 								if (colorParams.matchTextureChannelClass && channelClass != colorParams.textureChannelClass)
2151 									continue;
2152 
2153 								VkClearValue					clearColors[2]	=
2154 								{
2155 									makeClearColorValue(format, colorParams.clearColors[0][0], colorParams.clearColors[0][1], colorParams.clearColors[0][2], colorParams.clearColors[0][3]),
2156 									makeClearColorValue(format, colorParams.clearColors[1][0], colorParams.clearColors[1][1], colorParams.clearColors[1][2], colorParams.clearColors[1][3]),
2157 								};
2158 								VkClearValue					expectedColors[2];
2159 								if (clearColorsToTest[clearColorIndex].useSeparateExpectedColors)
2160 								{
2161 									expectedColors[0] = makeClearColorValue(format, colorParams.expectedColors[0][0], colorParams.expectedColors[0][1], colorParams.expectedColors[0][2], colorParams.expectedColors[0][3]);
2162 									expectedColors[1] = makeClearColorValue(format, colorParams.expectedColors[1][0], colorParams.expectedColors[1][1], colorParams.expectedColors[1][2], colorParams.expectedColors[1][3]);
2163 								}
2164 								else
2165 								{
2166 									expectedColors[0] = clearColors[0];
2167 									expectedColors[1] = clearColors[1];
2168 								}
2169 
2170 								std::string						testCaseName	= getFormatCaseName(format) + dimensionsString + colorParams.testNameSuffix;
2171 								TestParams						testParams		=
2172 								{
2173 									false,																// bool								useSingleMipLevel;
2174 									imageTypesToTest[imageTypeIndex],									// VkImageType						imageType;
2175 									format,																// VkFormat							imageFormat;
2176 									imageTilingsToTest[imageTilingIndex],								// VkImageTiling					imageTiling;
2177 									dimensions,															// VkExtent3D						imageExtent;
2178 									imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,		// deUint32							imageLayerCount;
2179 									{
2180 										0u,
2181 										imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
2182 									},																	// LayerRange						imageViewLayerRange;
2183 									makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),				// VkClearValue						initValue;
2184 									{
2185 										clearColors[0],													// VkClearValue						clearValue[0];
2186 										clearColors[1],													// VkClearValue						clearValue[1];
2187 									},
2188 									clearColorsToTest[clearColorIndex].useSeparateExpectedColors,		// bool								useSeparateExpectedClearValue;
2189 									{
2190 										expectedColors[0],												// VkClearValue						expectedClearValue[0];
2191 										expectedColors[1],												// VkClearValue						expectedClearValue[1];
2192 									},
2193 									imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,		// LayerRange						clearLayerRange;
2194 									allocationKind,														// AllocationKind					allocationKind;
2195 									false,																// bool								isCube;
2196 									SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE,							// SeparateDepthStencilLayoutMode	separateDepthStencilLayoutMode;
2197 									false,																// bool								isColorMultipleSubresourceRangeTest;
2198 								};
2199 
2200 								if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2201 								{
2202 									imageLayersGroup->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image", testParams));
2203 
2204 									// Removing linear images as the miplevels may be 1
2205 									if (imageTilingsToTest[imageTilingIndex] == VK_IMAGE_TILING_OPTIMAL)
2206 									{
2207 										testParams.isColorMultipleSubresourceRangeTest = true;
2208 										testCaseName += "_multiple_subresourcerange";
2209 										imageLayersGroup->addChild(new InstanceFactory1<ClearColorImageMultipleSubresourceRangeTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image with two ranges", testParams));
2210 									}
2211 								}
2212 								else
2213 								{
2214 									imageLayersGroup->addChild(new InstanceFactory1<TwoStepClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image", testParams));
2215 								}
2216 							}
2217 						}
2218 					}
2219 					imageTilingGroup->addChild(imageLayersGroup.release());
2220 				}
2221 				imageTypeGroup->addChild(imageTilingGroup.release());
2222 			}
2223 			colorImageClearTests->addChild(imageTypeGroup.release());
2224 		}
2225 		imageClearingTests->addChild(colorImageClearTests.release());
2226 	}
2227 
2228 	// Clear depth/stencil image
2229 	{
2230 		for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
2231 		{
2232 			// CUBE images are not tested in clear image tests (they are tested in clear attachment tests)
2233 			if (imageLayerParamsToTest[imageLayerParamsIndex].isCube)
2234 				continue;
2235 
2236 			de::MovePtr<TestCaseGroup> imageLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2237 
2238 			for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2239 			{
2240 				const VkExtent3D	dimensions			= imageDimensions[imageDimensionsIndex];
2241 				const std::string	dimensionsString	= extentToString(dimensions, VK_IMAGE_TYPE_2D);
2242 
2243 				if (dimensions.height == 1 || dimensions.depth > 1)
2244 					continue;
2245 
2246 				for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
2247 				{
2248 					const VkFormat	format						= depthStencilImageFormatsToTest[imageFormatIndex];
2249 					const bool		hasDepth					= tcu::hasDepthComponent(mapVkFormat(format).order);
2250 					const bool		hasStencil					= tcu::hasStencilComponent(mapVkFormat(format).order);
2251 					const int		separateLayoutsLoopCount	= (hasDepth && hasStencil) ? 3 : 1;
2252 
2253 					for (int separateDepthStencilLayoutMode = 0; separateDepthStencilLayoutMode < separateLayoutsLoopCount; ++separateDepthStencilLayoutMode)
2254 					{
2255 						const std::string	testCaseName	= getFormatCaseName(format) +
2256 							((separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH) ? "_separate_layouts_depth" :
2257 							 (separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL) ? "_separate_layouts_stencil" :
2258 							 "")
2259 							+ dimensionsString;
2260 						TestParams	testParams		=
2261 						{
2262 							true,																// bool								useSingleMipLevel;
2263 							VK_IMAGE_TYPE_2D,													// VkImageType						imageType;
2264 							format,																// VkFormat							format;
2265 							VK_IMAGE_TILING_OPTIMAL,											// VkImageTiling					tiling;
2266 							dimensions,															// VkExtent3D						extent;
2267 							imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,		// deUint32							imageLayerCount;
2268 							{
2269 								0u,
2270 								imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
2271 							},																	// LayerRange						imageViewLayerRange;
2272 							makeClearValueDepthStencil(0.5f, 0x03),								// VkClearValue						initValue
2273 							{
2274 								makeClearValueDepthStencil(0.1f, 0x06),								// VkClearValue						clearValue[0];
2275 								makeClearValueDepthStencil(0.3f, 0x04),								// VkClearValue						clearValue[1];
2276 							},
2277 							false,																// bool								useSeparateExpectedClearValue;
2278 							{ },																// VkClearValue[2]					expectedClearValue;
2279 							imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,		// LayerRange						clearLayerRange;
2280 							allocationKind,														// AllocationKind					allocationKind;
2281 							false,																// bool								isCube;
2282 							SeparateDepthStencilLayoutMode(separateDepthStencilLayoutMode),		// SeparateDepthStencilLayoutMode	separateDepthStencilLayoutMode;
2283 							false,																// bool								isColorMultipleSubresourceRangeTest;
2284 						};
2285 
2286 						if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2287 						{
2288 							imageLayersGroup->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Image", testParams));
2289 
2290 							if (separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE && hasDepth && hasStencil)
2291 							{
2292 								const std::string	testCaseNameRanges	= getFormatCaseName(format) + dimensionsString + "_multiple_subresourcerange";
2293 								imageLayersGroup->addChild(new InstanceFactory1<ClearDepthStencilImageMultipleSubresourceRangeTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseNameRanges, "Clear Depth/Stencil Image with ranges", testParams));
2294 							}
2295 						}
2296 						else
2297 						{
2298 							imageLayersGroup->addChild(new InstanceFactory1<TwoStepClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Image", testParams));
2299 						}
2300 					}
2301 				}
2302 			}
2303 			depthStencilImageClearTests->addChild(imageLayersGroup.release());
2304 		}
2305 		imageClearingTests->addChild(depthStencilImageClearTests.release());
2306 	}
2307 
2308 	// Clear color attachment
2309 	{
2310 		for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfAttachmentLayerParamsToTest; ++imageLayerParamsIndex)
2311 		{
2312 			if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2313 			{
2314 				de::MovePtr<TestCaseGroup> colorAttachmentClearLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2315 				de::MovePtr<TestCaseGroup> partialColorAttachmentClearLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2316 
2317 				for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2318 				{
2319 					const VkExtent3D	dimensions			= imageDimensions[imageDimensionsIndex];
2320 					const std::string	dimensionsString	= extentToString(dimensions, VK_IMAGE_TYPE_2D);
2321 
2322 					if (dimensions.height == 1 || dimensions.depth > 1)
2323 						continue;
2324 
2325 					if (imageLayerParamsToTest[imageLayerParamsIndex].isCube && dimensions.width != dimensions.height)
2326 						continue;
2327 
2328 					for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
2329 					{
2330 						const	VkFormat			format			= colorImageFormatsToTest[imageFormatIndex];
2331 						const	TextureFormat		tcuFormat		= mapVkFormat(format);
2332 						const	TextureChannelClass	channelClass	= getTextureChannelClass(tcuFormat.type);
2333 						for (size_t clearColorIndex = 0; clearColorIndex < numOfClearColorsToTest; ++clearColorIndex)
2334 						{
2335 							const	ClearTestColorParams&	colorParams		= clearColorsToTest[clearColorIndex];
2336 
2337 							if (colorParams.matchTextureChannelClass && channelClass != colorParams.textureChannelClass)
2338 								continue;
2339 
2340 							VkClearValue					clearColors[2]	=
2341 							{
2342 								makeClearColorValue(format, colorParams.clearColors[0][0], colorParams.clearColors[0][1], colorParams.clearColors[0][2], colorParams.clearColors[0][3]),
2343 								makeClearColorValue(format, colorParams.clearColors[1][0], colorParams.clearColors[1][1], colorParams.clearColors[1][2], colorParams.clearColors[1][3]),
2344 							};
2345 							VkClearValue					expectedColors[2];
2346 							if (clearColorsToTest[clearColorIndex].useSeparateExpectedColors)
2347 							{
2348 								expectedColors[0] = makeClearColorValue(format, colorParams.expectedColors[0][0], colorParams.expectedColors[0][1], colorParams.expectedColors[0][2], colorParams.expectedColors[0][3]);
2349 								expectedColors[1] = makeClearColorValue(format, colorParams.expectedColors[1][0], colorParams.expectedColors[1][1], colorParams.expectedColors[1][2], colorParams.expectedColors[1][3]);
2350 							}
2351 							else
2352 							{
2353 								expectedColors[0] = clearColors[0];
2354 								expectedColors[1] = clearColors[1];
2355 							}
2356 
2357 							const std::string	testCaseName	= getFormatCaseName(format) + dimensionsString + colorParams.testNameSuffix;
2358 							const TestParams	testParams		=
2359 							{
2360 								true,															// bool								useSingleMipLevel;
2361 								VK_IMAGE_TYPE_2D,												// VkImageType						imageType;
2362 								format,															// VkFormat							format;
2363 								VK_IMAGE_TILING_OPTIMAL,										// VkImageTiling					tiling;
2364 								dimensions,														// VkExtent3D						extent;
2365 								imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,	// deUint32							imageLayerCount;
2366 								imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange,	// LayerRange						imageViewLayerRange;
2367 								makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),			// VkClearValue						initValue
2368 								{
2369 									clearColors[0],												// VkClearValue						clearValue[0];
2370 									clearColors[1]												// VkClearValue						clearValue[1];
2371 								},
2372 								colorParams.useSeparateExpectedColors,							// bool								useSeparateExpectedClearValue;
2373 								{
2374 									expectedColors[0],											// VkClearValue						expectedClearValue[0];
2375 									expectedColors[1]											// VkClearValue						expectedClearValue[1];
2376 								},
2377 								imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,	// LayerRange						clearLayerRange;
2378 								allocationKind,													// AllocationKind					allocationKind;
2379 								imageLayerParamsToTest[imageLayerParamsIndex].isCube,			// bool								isCube;
2380 								SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_NONE,						// SeparateDepthStencilLayoutMode	separateDepthStencilLayoutMode;
2381 								false,															// bool								isColorMultipleSubresourceRangeTest;
2382 							};
2383 							colorAttachmentClearLayersGroup->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Attachment", testParams));
2384 							if (dimensions.width > 1)
2385 								partialColorAttachmentClearLayersGroup->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Partial Clear Color Attachment", testParams));
2386 						}
2387 					}
2388 				}
2389 				colorAttachmentClearTests->addChild(colorAttachmentClearLayersGroup.release());
2390 				partialColorAttachmentClearTests->addChild(partialColorAttachmentClearLayersGroup.release());
2391 			}
2392 		}
2393 		imageClearingTests->addChild(colorAttachmentClearTests.release());
2394 		imageClearingTests->addChild(partialColorAttachmentClearTests.release());
2395 	}
2396 
2397 	// Clear depth/stencil attachment
2398 	{
2399 		for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfAttachmentLayerParamsToTest; ++imageLayerParamsIndex)
2400 		{
2401 			if (!imageLayerParamsToTest[imageLayerParamsIndex].twoStep)
2402 			{
2403 				de::MovePtr<TestCaseGroup> depthStencilLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2404 				de::MovePtr<TestCaseGroup> partialDepthStencilLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
2405 
2406 				for (size_t imageDimensionsIndex = 0; imageDimensionsIndex < DE_LENGTH_OF_ARRAY(imageDimensions); ++imageDimensionsIndex)
2407 				{
2408 					const VkExtent3D	dimensions			= imageDimensions[imageDimensionsIndex];
2409 					const std::string	dimensionsString	= extentToString(dimensions, VK_IMAGE_TYPE_2D);
2410 
2411 					if (dimensions.height == 1 || dimensions.depth > 1)
2412 						continue;
2413 
2414 					if (imageLayerParamsToTest[imageLayerParamsIndex].isCube && dimensions.width != dimensions.height)
2415 						continue;
2416 
2417 					for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
2418 					{
2419 						const VkFormat		format						= depthStencilImageFormatsToTest[imageFormatIndex];
2420 						const bool			hasDepth					= tcu::hasDepthComponent(mapVkFormat(format).order);
2421 						const bool			hasStencil					= tcu::hasStencilComponent(mapVkFormat(format).order);
2422 						const int			separateLayoutsLoopCount	= (hasDepth && hasStencil) ? 3 : 1;
2423 
2424 						for (int separateDepthStencilLayoutMode = 0; separateDepthStencilLayoutMode < separateLayoutsLoopCount; ++separateDepthStencilLayoutMode)
2425 						{
2426 							const std::string	testCaseName	= getFormatCaseName(format) +
2427 							((separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_DEPTH) ? "_separate_layouts_depth" :
2428 							 (separateDepthStencilLayoutMode == SEPARATE_DEPTH_STENCIL_LAYOUT_MODE_STENCIL) ? "_separate_layouts_stencil" :
2429 							 "")
2430 							+ dimensionsString;
2431 
2432 							const TestParams	testParams						=
2433 							{
2434 								true,															// bool								useSingleMipLevel;
2435 								VK_IMAGE_TYPE_2D,												// VkImageType						imageType;
2436 								format,															// VkFormat							format;
2437 								VK_IMAGE_TILING_OPTIMAL,										// VkImageTiling					tiling;
2438 								dimensions,														// VkExtent3D						extent;
2439 								imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,	// deUint32							imageLayerCount;
2440 								imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange,	// LayerRange						imageViewLayerRange;
2441 								makeClearValueDepthStencil(0.5f, 0x03),							// VkClearValue						initValue
2442 								{
2443 									makeClearValueDepthStencil(0.1f, 0x06),							// VkClearValue						clearValue[0];
2444 									makeClearValueDepthStencil(0.3f, 0x04),							// VkClearValue						clearValue[1];
2445 								},
2446 								false,															// bool								useSeparateExpectedClearValue;
2447 								{ },															// VkClearValue[2]					expectedClearValue;
2448 								imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,	// LayerRange						clearLayerRange;
2449 								allocationKind,													// AllocationKind					allocationKind;
2450 								imageLayerParamsToTest[imageLayerParamsIndex].isCube,			// bool								isCube;
2451 								SeparateDepthStencilLayoutMode(separateDepthStencilLayoutMode),	// SeparateDepthStencilLayoutMode	separateDepthStencilLayoutMode;
2452 								false,															// bool								isColorMultipleSubresourceRangeTest;
2453 							};
2454 							depthStencilLayersGroup->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Attachment", testParams));
2455 							if (dimensions.width > 1)
2456 								partialDepthStencilLayersGroup->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Partial Clear Depth/Stencil Attachment", testParams));
2457 						}
2458 					}
2459 				}
2460 				depthStencilAttachmentClearTests->addChild(depthStencilLayersGroup.release());
2461 				partialDepthStencilAttachmentClearTests->addChild(partialDepthStencilLayersGroup.release());
2462 			}
2463 		}
2464 		imageClearingTests->addChild(depthStencilAttachmentClearTests.release());
2465 		imageClearingTests->addChild(partialDepthStencilAttachmentClearTests.release());
2466 	}
2467 
2468 	return imageClearingTests;
2469 }
2470 
createCoreImageClearingTests(tcu::TestCaseGroup * group)2471 void createCoreImageClearingTests (tcu::TestCaseGroup* group)
2472 {
2473 	createImageClearingTestsCommon(group->getTestContext(), group, ALLOCATION_KIND_SUBALLOCATED);
2474 }
2475 
createDedicatedAllocationImageClearingTests(tcu::TestCaseGroup * group)2476 void createDedicatedAllocationImageClearingTests (tcu::TestCaseGroup* group)
2477 {
2478 	createImageClearingTestsCommon(group->getTestContext(), group, ALLOCATION_KIND_DEDICATED);
2479 }
2480 
2481 } // anonymous
2482 
createImageClearingTests(TestContext & testCtx)2483 TestCaseGroup* createImageClearingTests (TestContext& testCtx)
2484 {
2485 	de::MovePtr<TestCaseGroup>	imageClearingTests	(new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
2486 
2487 	imageClearingTests->addChild(createTestGroup(testCtx, "core",					"Core Image Clearing Tests",							createCoreImageClearingTests));
2488 	imageClearingTests->addChild(createTestGroup(testCtx, "dedicated_allocation",	"Image Clearing Tests For Dedicated Memory Allocation",	createDedicatedAllocationImageClearingTests));
2489 
2490 	return imageClearingTests.release();
2491 }
2492 
2493 } // api
2494 } // vkt
2495