• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file  vktSparseResourcesImageMemoryAliasing.cpp
21  * \brief Sparse image memory aliasing tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktSparseResourcesImageMemoryAliasing.hpp"
25 #include "vktSparseResourcesTestsUtil.hpp"
26 #include "vktSparseResourcesBase.hpp"
27 #include "vktTestCaseUtil.hpp"
28 
29 #include "vkDefs.hpp"
30 #include "vkRef.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkPlatform.hpp"
33 #include "vkPrograms.hpp"
34 #include "vkRefUtil.hpp"
35 #include "vkMemUtil.hpp"
36 #include "vkBarrierUtil.hpp"
37 #include "vkQueryUtil.hpp"
38 #include "vkBuilderUtil.hpp"
39 #include "vkTypeUtil.hpp"
40 #include "vkCmdUtil.hpp"
41 #include "vkObjUtil.hpp"
42 
43 #include "deStringUtil.hpp"
44 #include "deUniquePtr.hpp"
45 #include "deSharedPtr.hpp"
46 
47 #include "tcuTexture.hpp"
48 #include "tcuTextureUtil.hpp"
49 #include "tcuTexVerifierUtil.hpp"
50 
51 #include <deMath.h>
52 #include <string>
53 #include <vector>
54 
55 using namespace vk;
56 
57 namespace vkt
58 {
59 namespace sparse
60 {
61 namespace
62 {
63 
64 const deUint32 MODULO_DIVISOR = 127;
65 
getCoordStr(const ImageType imageType,const std::string & x,const std::string & y,const std::string & z)66 const std::string getCoordStr	(const ImageType	imageType,
67 								 const std::string&	x,
68 								 const std::string&	y,
69 								 const std::string&	z)
70 {
71 	switch (imageType)
72 	{
73 		case IMAGE_TYPE_1D:
74 		case IMAGE_TYPE_BUFFER:
75 			return x;
76 
77 		case IMAGE_TYPE_1D_ARRAY:
78 		case IMAGE_TYPE_2D:
79 			return "ivec2(" + x + "," + y + ")";
80 
81 		case IMAGE_TYPE_2D_ARRAY:
82 		case IMAGE_TYPE_3D:
83 		case IMAGE_TYPE_CUBE:
84 		case IMAGE_TYPE_CUBE_ARRAY:
85 			return "ivec3(" + x + "," + y + "," + z + ")";
86 
87 		default:
88 			DE_FATAL("Unexpected image type");
89 			return "";
90 	}
91 }
92 
93 class ImageSparseMemoryAliasingCase : public TestCase
94 {
95 public:
96 	ImageSparseMemoryAliasingCase	(tcu::TestContext&		testCtx,
97 									 const std::string&		name,
98 									 const std::string&		description,
99 									 const ImageType		imageType,
100 									 const tcu::UVec3&		imageSize,
101 									 const VkFormat			format,
102 									 const glu::GLSLVersion	glslVersion,
103 									 const bool				useDeviceGroups);
104 
105 	void			initPrograms	(SourceCollections&		sourceCollections) const;
106 	TestInstance*	createInstance	(Context&				context) const;
107 	virtual void	checkSupport	(Context&				context) const;
108 
109 
110 private:
111 	const bool				m_useDeviceGroups;
112 	const ImageType			m_imageType;
113 	const tcu::UVec3		m_imageSize;
114 	const VkFormat			m_format;
115 	const glu::GLSLVersion	m_glslVersion;
116 };
117 
ImageSparseMemoryAliasingCase(tcu::TestContext & testCtx,const std::string & name,const std::string & description,const ImageType imageType,const tcu::UVec3 & imageSize,const VkFormat format,const glu::GLSLVersion glslVersion,const bool useDeviceGroups)118 ImageSparseMemoryAliasingCase::ImageSparseMemoryAliasingCase	(tcu::TestContext&		testCtx,
119 																 const std::string&		name,
120 																 const std::string&		description,
121 																 const ImageType		imageType,
122 																 const tcu::UVec3&		imageSize,
123 																 const VkFormat			format,
124 																 const glu::GLSLVersion	glslVersion,
125 																 const bool				useDeviceGroups)
126 	: TestCase			(testCtx, name, description)
127 	, m_useDeviceGroups	(useDeviceGroups)
128 	, m_imageType		(imageType)
129 	, m_imageSize		(imageSize)
130 	, m_format			(format)
131 	, m_glslVersion		(glslVersion)
132 {
133 }
134 
checkSupport(Context & context) const135 void ImageSparseMemoryAliasingCase::checkSupport (Context& context) const
136 {
137 	const InstanceInterface&	instance		= context.getInstanceInterface();
138 	const VkPhysicalDevice		physicalDevice	= context.getPhysicalDevice();
139 
140 	context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_ALIASED);
141 
142 	// Check if image size does not exceed device limits
143 	if (!isImageSizeSupported(instance, physicalDevice, m_imageType, m_imageSize))
144 		TCU_THROW(NotSupportedError, "Image size not supported for device");
145 
146 	// Check if device supports sparse operations for image type
147 	if (!checkSparseSupportForImageType(instance, physicalDevice, m_imageType))
148 		TCU_THROW(NotSupportedError, "Sparse residency for image type is not supported");
149 
150 	if (formatIsR64(m_format))
151 	{
152 		context.requireDeviceFunctionality("VK_EXT_shader_image_atomic_int64");
153 
154 		if (context.getShaderImageAtomicInt64FeaturesEXT().shaderImageInt64Atomics == VK_FALSE)
155 		{
156 			TCU_THROW(NotSupportedError, "shaderImageInt64Atomics is not supported");
157 		}
158 
159 		if (context.getShaderImageAtomicInt64FeaturesEXT().sparseImageInt64Atomics == VK_FALSE)
160 		{
161 			TCU_THROW(NotSupportedError, "sparseImageInt64Atomics is not supported for device");
162 		}
163 	}
164 }
165 
166 class ImageSparseMemoryAliasingInstance : public SparseResourcesBaseInstance
167 {
168 public:
169 	ImageSparseMemoryAliasingInstance	(Context&			context,
170 										 const ImageType	imageType,
171 										 const tcu::UVec3&	imageSize,
172 										 const VkFormat		format,
173 										 const bool			useDeviceGroups);
174 
175 	tcu::TestStatus	iterate				(void);
176 
177 private:
178 	const bool			m_useDeviceGroups;
179 	const ImageType		m_imageType;
180 	const tcu::UVec3	m_imageSize;
181 	const VkFormat		m_format;
182 };
183 
ImageSparseMemoryAliasingInstance(Context & context,const ImageType imageType,const tcu::UVec3 & imageSize,const VkFormat format,const bool useDeviceGroups)184 ImageSparseMemoryAliasingInstance::ImageSparseMemoryAliasingInstance	(Context&			context,
185 																		 const ImageType	imageType,
186 																		 const tcu::UVec3&	imageSize,
187 																		 const VkFormat		format,
188 																		 const bool			useDeviceGroups)
189 	: SparseResourcesBaseInstance	(context, useDeviceGroups)
190 	, m_useDeviceGroups				(useDeviceGroups)
191 	, m_imageType					(imageType)
192 	, m_imageSize					(imageSize)
193 	, m_format						(format)
194 {
195 }
196 
iterate(void)197 tcu::TestStatus ImageSparseMemoryAliasingInstance::iterate (void)
198 {
199 	const float					epsilon					= 1e-5f;
200 	const InstanceInterface&	instance				= m_context.getInstanceInterface();
201 
202 	{
203 		// Create logical device supporting both sparse and compute queues
204 		QueueRequirementsVec queueRequirements;
205 		queueRequirements.push_back(QueueRequirements(VK_QUEUE_SPARSE_BINDING_BIT, 1u));
206 		queueRequirements.push_back(QueueRequirements(VK_QUEUE_COMPUTE_BIT, 1u));
207 
208 		createDeviceSupportingQueues(queueRequirements, formatIsR64(m_format));
209 	}
210 
211 	const VkPhysicalDevice		physicalDevice			= getPhysicalDevice();
212 	const tcu::UVec3			maxWorkGroupSize		= tcu::UVec3(128u, 128u, 64u);
213 	const tcu::UVec3			maxWorkGroupCount		= tcu::UVec3(65535u, 65535u, 65535u);
214 	const deUint32				maxWorkGroupInvocations	= 128u;
215 	VkImageCreateInfo			imageSparseInfo;
216 	std::vector<DeviceMemorySp>	deviceMemUniquePtrVec;
217 
218 	//vsk getting queues should be outside the loop
219 	//see these in all image files
220 
221 	const DeviceInterface&			deviceInterface		= getDeviceInterface();
222 	const Queue&					sparseQueue			= getQueue(VK_QUEUE_SPARSE_BINDING_BIT, 0);
223 	const Queue&					computeQueue		= getQueue(VK_QUEUE_COMPUTE_BIT, 0);
224 	const PlanarFormatDescription	formatDescription	= getPlanarFormatDescription(m_format);
225 
226 	// Go through all physical devices
227 	for (deUint32 physDevID = 0; physDevID < m_numPhysicalDevices; physDevID++)
228 	{
229 		const deUint32	firstDeviceID	= physDevID;
230 		const deUint32	secondDeviceID	= (firstDeviceID + 1) % m_numPhysicalDevices;
231 
232 		imageSparseInfo.sType					= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
233 		imageSparseInfo.pNext					= DE_NULL;
234 		imageSparseInfo.flags					= VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT |
235 												  VK_IMAGE_CREATE_SPARSE_ALIASED_BIT   |
236 												  VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
237 		imageSparseInfo.imageType				= mapImageType(m_imageType);
238 		imageSparseInfo.format					= m_format;
239 		imageSparseInfo.extent					= makeExtent3D(getLayerSize(m_imageType, m_imageSize));
240 		imageSparseInfo.arrayLayers				= getNumLayers(m_imageType, m_imageSize);
241 		imageSparseInfo.samples					= VK_SAMPLE_COUNT_1_BIT;
242 		imageSparseInfo.tiling					= VK_IMAGE_TILING_OPTIMAL;
243 		imageSparseInfo.initialLayout			= VK_IMAGE_LAYOUT_UNDEFINED;
244 		imageSparseInfo.usage					= VK_IMAGE_USAGE_TRANSFER_DST_BIT |
245 												  VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
246 												  VK_IMAGE_USAGE_STORAGE_BIT;
247 		imageSparseInfo.sharingMode				= VK_SHARING_MODE_EXCLUSIVE;
248 		imageSparseInfo.queueFamilyIndexCount	= 0u;
249 		imageSparseInfo.pQueueFamilyIndices		= DE_NULL;
250 
251 		if (m_imageType == IMAGE_TYPE_CUBE || m_imageType == IMAGE_TYPE_CUBE_ARRAY)
252 			imageSparseInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
253 
254 		// Check if device supports sparse operations for image format
255 		if (!checkSparseSupportForImageFormat(instance, physicalDevice, imageSparseInfo))
256 			TCU_THROW(NotSupportedError, "The image format does not support sparse operations");
257 
258 		{
259 			// Assign maximum allowed mipmap levels to image
260 			VkImageFormatProperties imageFormatProperties;
261 			if (instance.getPhysicalDeviceImageFormatProperties(physicalDevice,
262 				imageSparseInfo.format,
263 				imageSparseInfo.imageType,
264 				imageSparseInfo.tiling,
265 				imageSparseInfo.usage,
266 				imageSparseInfo.flags,
267 				&imageFormatProperties) == VK_ERROR_FORMAT_NOT_SUPPORTED)
268 			{
269 				TCU_THROW(NotSupportedError, "Image format does not support sparse operations");
270 			}
271 
272 			imageSparseInfo.mipLevels = getMipmapCount(m_format, formatDescription, imageFormatProperties, imageSparseInfo.extent);
273 		}
274 
275 		// Create sparse image
276 		const Unique<VkImage> imageRead(createImage(deviceInterface, getDevice(), &imageSparseInfo));
277 		const Unique<VkImage> imageWrite(createImage(deviceInterface, getDevice(), &imageSparseInfo));
278 
279 		// Create semaphores to synchronize sparse binding operations with other operations on the sparse images
280 		const Unique<VkSemaphore> memoryBindSemaphoreTransfer(createSemaphore(deviceInterface, getDevice()));
281 		const Unique<VkSemaphore> memoryBindSemaphoreCompute(createSemaphore(deviceInterface, getDevice()));
282 
283 		const VkSemaphore imageMemoryBindSemaphores[] = { memoryBindSemaphoreTransfer.get(), memoryBindSemaphoreCompute.get() };
284 
285 		std::vector<VkSparseImageMemoryRequirements> sparseMemoryRequirements;
286 
287 		{
288 			// Get sparse image general memory requirements
289 			const VkMemoryRequirements imageMemoryRequirements = getImageMemoryRequirements(deviceInterface, getDevice(), *imageRead);
290 
291 			// Check if required image memory size does not exceed device limits
292 			if (imageMemoryRequirements.size > getPhysicalDeviceProperties(instance, getPhysicalDevice(secondDeviceID)).limits.sparseAddressSpaceSize)
293 				TCU_THROW(NotSupportedError, "Required memory size for sparse resource exceeds device limits");
294 
295 			DE_ASSERT((imageMemoryRequirements.size % imageMemoryRequirements.alignment) == 0);
296 
297 			const deUint32 memoryType = findMatchingMemoryType(instance, getPhysicalDevice(secondDeviceID), imageMemoryRequirements, MemoryRequirement::Any);
298 
299 			if (memoryType == NO_MATCH_FOUND)
300 				return tcu::TestStatus::fail("No matching memory type found");
301 
302 			if (firstDeviceID != secondDeviceID)
303 			{
304 				VkPeerMemoryFeatureFlags	peerMemoryFeatureFlags	= (VkPeerMemoryFeatureFlags)0;
305 				const deUint32				heapIndex				= getHeapIndexForMemoryType(instance, getPhysicalDevice(secondDeviceID), memoryType);
306 				deviceInterface.getDeviceGroupPeerMemoryFeatures(getDevice(), heapIndex, firstDeviceID, secondDeviceID, &peerMemoryFeatureFlags);
307 
308 				if (((peerMemoryFeatureFlags & VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT) == 0) ||
309 					((peerMemoryFeatureFlags & VK_PEER_MEMORY_FEATURE_COPY_DST_BIT) == 0) ||
310 					((peerMemoryFeatureFlags & VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT) == 0))
311 				{
312 					TCU_THROW(NotSupportedError, "Peer memory does not support COPY_SRC, COPY_DST, and GENERIC_DST");
313 				}
314 			}
315 
316 			// Get sparse image sparse memory requirements
317 			sparseMemoryRequirements = getImageSparseMemoryRequirements(deviceInterface, getDevice(), *imageRead);
318 
319 			DE_ASSERT(sparseMemoryRequirements.size() != 0);
320 
321 			std::vector<VkSparseImageMemoryBind> imageResidencyMemoryBinds;
322 			std::vector<VkSparseMemoryBind>		 imageReadMipTailBinds;
323 			std::vector<VkSparseMemoryBind>		 imageWriteMipTailBinds;
324 
325 			for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
326 			{
327 				const VkImageAspectFlags		aspect				= (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
328 				const deUint32					aspectIndex			= getSparseAspectRequirementsIndex(sparseMemoryRequirements, aspect);
329 
330 				if (aspectIndex == NO_MATCH_FOUND)
331 					TCU_THROW(NotSupportedError, "Not supported image aspect");
332 
333 				VkSparseImageMemoryRequirements	aspectRequirements	= sparseMemoryRequirements[aspectIndex];
334 
335 				DE_ASSERT((aspectRequirements.imageMipTailSize % imageMemoryRequirements.alignment) == 0);
336 
337 				VkExtent3D						imageGranularity	= aspectRequirements.formatProperties.imageGranularity;
338 
339 				// Bind memory for each layer
340 				for (deUint32 layerNdx = 0; layerNdx < imageSparseInfo.arrayLayers; ++layerNdx)
341 				{
342 					for (deUint32 mipLevelNdx = 0; mipLevelNdx < aspectRequirements.imageMipTailFirstLod; ++mipLevelNdx)
343 					{
344 						const VkExtent3D			mipExtent			= getPlaneExtent(formatDescription, imageSparseInfo.extent, planeNdx, mipLevelNdx);
345 						const tcu::UVec3			sparseBlocks		= alignedDivide(mipExtent, imageGranularity);
346 						const deUint32				numSparseBlocks		= sparseBlocks.x() * sparseBlocks.y() * sparseBlocks.z();
347 						const VkImageSubresource	subresource			= { aspect, mipLevelNdx, layerNdx };
348 
349 						const VkSparseImageMemoryBind imageMemoryBind	= makeSparseImageMemoryBind(deviceInterface, getDevice(),
350 							imageMemoryRequirements.alignment * numSparseBlocks, memoryType, subresource, makeOffset3D(0u, 0u, 0u), mipExtent);
351 
352 						deviceMemUniquePtrVec.push_back(makeVkSharedPtr(Move<VkDeviceMemory>(check<VkDeviceMemory>(imageMemoryBind.memory), Deleter<VkDeviceMemory>(deviceInterface, getDevice(), DE_NULL))));
353 
354 						imageResidencyMemoryBinds.push_back(imageMemoryBind);
355 					}
356 
357 					if (!(aspectRequirements.formatProperties.flags & VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT) && aspectRequirements.imageMipTailFirstLod < imageSparseInfo.mipLevels)
358 					{
359 						const VkSparseMemoryBind imageReadMipTailMemoryBind = makeSparseMemoryBind(deviceInterface, getDevice(),
360 							aspectRequirements.imageMipTailSize, memoryType, aspectRequirements.imageMipTailOffset + layerNdx * aspectRequirements.imageMipTailStride);
361 
362 						deviceMemUniquePtrVec.push_back(makeVkSharedPtr(Move<VkDeviceMemory>(check<VkDeviceMemory>(imageReadMipTailMemoryBind.memory), Deleter<VkDeviceMemory>(deviceInterface, getDevice(), DE_NULL))));
363 
364 						imageReadMipTailBinds.push_back(imageReadMipTailMemoryBind);
365 
366 						const VkSparseMemoryBind imageWriteMipTailMemoryBind = makeSparseMemoryBind(deviceInterface, getDevice(),
367 							aspectRequirements.imageMipTailSize, memoryType, aspectRequirements.imageMipTailOffset + layerNdx * aspectRequirements.imageMipTailStride);
368 
369 						deviceMemUniquePtrVec.push_back(makeVkSharedPtr(Move<VkDeviceMemory>(check<VkDeviceMemory>(imageWriteMipTailMemoryBind.memory), Deleter<VkDeviceMemory>(deviceInterface, getDevice(), DE_NULL))));
370 
371 						imageWriteMipTailBinds.push_back(imageWriteMipTailMemoryBind);
372 					}
373 				}
374 
375 				if ((aspectRequirements.formatProperties.flags & VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT) && aspectRequirements.imageMipTailFirstLod < imageSparseInfo.mipLevels)
376 				{
377 					const VkSparseMemoryBind imageReadMipTailMemoryBind = makeSparseMemoryBind(deviceInterface, getDevice(),
378 						aspectRequirements.imageMipTailSize, memoryType, aspectRequirements.imageMipTailOffset);
379 
380 					deviceMemUniquePtrVec.push_back(makeVkSharedPtr(Move<VkDeviceMemory>(check<VkDeviceMemory>(imageReadMipTailMemoryBind.memory), Deleter<VkDeviceMemory>(deviceInterface, getDevice(), DE_NULL))));
381 
382 					imageReadMipTailBinds.push_back(imageReadMipTailMemoryBind);
383 
384 					const VkSparseMemoryBind imageWriteMipTailMemoryBind = makeSparseMemoryBind(deviceInterface, getDevice(),
385 						aspectRequirements.imageMipTailSize, memoryType, aspectRequirements.imageMipTailOffset);
386 
387 					deviceMemUniquePtrVec.push_back(makeVkSharedPtr(Move<VkDeviceMemory>(check<VkDeviceMemory>(imageWriteMipTailMemoryBind.memory), Deleter<VkDeviceMemory>(deviceInterface, getDevice(), DE_NULL))));
388 
389 					imageWriteMipTailBinds.push_back(imageWriteMipTailMemoryBind);
390 				}
391 			}
392 
393 			const VkDeviceGroupBindSparseInfo devGroupBindSparseInfo =
394 			{
395 				VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO,		//VkStructureType							sType;
396 				DE_NULL,												//const void*								pNext;
397 				firstDeviceID,											//deUint32									resourceDeviceIndex;
398 				secondDeviceID,											//deUint32									memoryDeviceIndex;
399 			};
400 
401 			VkBindSparseInfo bindSparseInfo =
402 			{
403 				VK_STRUCTURE_TYPE_BIND_SPARSE_INFO,						//VkStructureType							sType;
404 				m_useDeviceGroups ? &devGroupBindSparseInfo : DE_NULL,	//const void*								pNext;
405 				0u,														//deUint32									waitSemaphoreCount;
406 				DE_NULL,												//const VkSemaphore*						pWaitSemaphores;
407 				0u,														//deUint32									bufferBindCount;
408 				DE_NULL,												//const VkSparseBufferMemoryBindInfo*		pBufferBinds;
409 				0u,														//deUint32									imageOpaqueBindCount;
410 				DE_NULL,												//const VkSparseImageOpaqueMemoryBindInfo*	pImageOpaqueBinds;
411 				0u,														//deUint32									imageBindCount;
412 				DE_NULL,												//const VkSparseImageMemoryBindInfo*		pImageBinds;
413 				2u,														//deUint32									signalSemaphoreCount;
414 				imageMemoryBindSemaphores								//const VkSemaphore*						pSignalSemaphores;
415 			};
416 
417 			VkSparseImageMemoryBindInfo			imageResidencyBindInfo[2];
418 			VkSparseImageOpaqueMemoryBindInfo	imageMipTailBindInfo[2];
419 
420 			if (imageResidencyMemoryBinds.size() > 0)
421 			{
422 				imageResidencyBindInfo[0].image		= *imageRead;
423 				imageResidencyBindInfo[0].bindCount = static_cast<deUint32>(imageResidencyMemoryBinds.size());
424 				imageResidencyBindInfo[0].pBinds	= imageResidencyMemoryBinds.data();
425 
426 				imageResidencyBindInfo[1].image		= *imageWrite;
427 				imageResidencyBindInfo[1].bindCount = static_cast<deUint32>(imageResidencyMemoryBinds.size());
428 				imageResidencyBindInfo[1].pBinds	= imageResidencyMemoryBinds.data();
429 
430 				bindSparseInfo.imageBindCount		= 2u;
431 				bindSparseInfo.pImageBinds			= imageResidencyBindInfo;
432 			}
433 
434 			if (imageReadMipTailBinds.size() > 0)
435 			{
436 				imageMipTailBindInfo[0].image		= *imageRead;
437 				imageMipTailBindInfo[0].bindCount	= static_cast<deUint32>(imageReadMipTailBinds.size());
438 				imageMipTailBindInfo[0].pBinds		= imageReadMipTailBinds.data();
439 
440 				imageMipTailBindInfo[1].image		= *imageWrite;
441 				imageMipTailBindInfo[1].bindCount	= static_cast<deUint32>(imageWriteMipTailBinds.size());
442 				imageMipTailBindInfo[1].pBinds		= imageWriteMipTailBinds.data();
443 
444 				bindSparseInfo.imageOpaqueBindCount = 2u;
445 				bindSparseInfo.pImageOpaqueBinds	= imageMipTailBindInfo;
446 			}
447 
448 			// Submit sparse bind commands for execution
449 			VK_CHECK(deviceInterface.queueBindSparse(sparseQueue.queueHandle, 1u, &bindSparseInfo, DE_NULL));
450 		}
451 
452 		deUint32							imageSizeInBytes = 0;
453 		std::vector<std::vector<deUint32>>	planeOffsets( imageSparseInfo.mipLevels );
454 		std::vector<std::vector<deUint32>>	planeRowPitches( imageSparseInfo.mipLevels );
455 
456 		for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
457 		{
458 			planeOffsets[mipmapNdx].resize(formatDescription.numPlanes, 0);
459 			planeRowPitches[mipmapNdx].resize(formatDescription.numPlanes, 0);
460 		}
461 
462 		for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
463 		{
464 			for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
465 			{
466 				const tcu::UVec3	gridSize			= getShaderGridSize(m_imageType, m_imageSize, mipmapNdx);
467 				planeOffsets[mipmapNdx][planeNdx]		= imageSizeInBytes;
468 				const deUint32		planeW				= gridSize.x() / (formatDescription.blockWidth * formatDescription.planes[planeNdx].widthDivisor);
469 				planeRowPitches[mipmapNdx][planeNdx]	= formatDescription.planes[planeNdx].elementSizeBytes * planeW;
470 				imageSizeInBytes						+= getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
471 			}
472 		}
473 
474 		std::vector <VkBufferImageCopy>	bufferImageCopy(formatDescription.numPlanes * imageSparseInfo.mipLevels);
475 		{
476 			deUint32 bufferOffset = 0;
477 
478 			for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
479 			{
480 				const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
481 
482 				for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
483 				{
484 					bufferImageCopy[planeNdx*imageSparseInfo.mipLevels + mipmapNdx] =
485 					{
486 						bufferOffset,																		//	VkDeviceSize				bufferOffset;
487 						0u,																					//	deUint32					bufferRowLength;
488 						0u,																					//	deUint32					bufferImageHeight;
489 						makeImageSubresourceLayers(aspect, mipmapNdx, 0u, imageSparseInfo.arrayLayers),		//	VkImageSubresourceLayers	imageSubresource;
490 						makeOffset3D(0, 0, 0),																//	VkOffset3D					imageOffset;
491 						vk::getPlaneExtent(formatDescription, imageSparseInfo.extent, planeNdx, mipmapNdx)	//	VkExtent3D					imageExtent;
492 					};
493 					bufferOffset += getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
494 				}
495 			}
496 		}
497 
498 		// Create command buffer for compute and transfer operations
499 		const Unique<VkCommandPool>		commandPool(makeCommandPool(deviceInterface, getDevice(), computeQueue.queueFamilyIndex));
500 		const Unique<VkCommandBuffer>	commandBuffer(allocateCommandBuffer(deviceInterface, getDevice(), *commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
501 
502 		// Start recording commands
503 		beginCommandBuffer(deviceInterface, *commandBuffer);
504 
505 		const VkBufferCreateInfo		inputBufferCreateInfo	= makeBufferCreateInfo(imageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
506 		const Unique<VkBuffer>			inputBuffer				(createBuffer(deviceInterface, getDevice(), &inputBufferCreateInfo));
507 		const de::UniquePtr<Allocation>	inputBufferAlloc		(bindBuffer(deviceInterface, getDevice(), getAllocator(), *inputBuffer, MemoryRequirement::HostVisible));
508 
509 		std::vector<deUint8> referenceData(imageSizeInBytes);
510 
511 		for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
512 			for (deUint32 mipmapNdx = 0u; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
513 			{
514 				const deUint32 mipLevelSizeInBytes	= getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx, BUFFER_IMAGE_COPY_OFFSET_GRANULARITY);
515 				const deUint32 bufferOffset			= static_cast<deUint32>(bufferImageCopy[planeNdx*imageSparseInfo.mipLevels + mipmapNdx].bufferOffset);
516 
517 				deMemset(&referenceData[bufferOffset], mipmapNdx + 1u, mipLevelSizeInBytes);
518 			}
519 
520 		deMemcpy(inputBufferAlloc->getHostPtr(), referenceData.data(), imageSizeInBytes);
521 
522 		flushAlloc(deviceInterface, getDevice(), *inputBufferAlloc);
523 
524 		{
525 			const VkBufferMemoryBarrier inputBufferBarrier = makeBufferMemoryBarrier
526 			(
527 				VK_ACCESS_HOST_WRITE_BIT,
528 				VK_ACCESS_TRANSFER_READ_BIT,
529 				*inputBuffer,
530 				0u,
531 				imageSizeInBytes
532 			);
533 
534 			deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 1u, &inputBufferBarrier, 0u, DE_NULL);
535 		}
536 
537 		{
538 			std::vector<VkImageMemoryBarrier> imageSparseTransferDstBarriers;
539 
540 			for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
541 			{
542 				const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
543 
544 				imageSparseTransferDstBarriers.emplace_back(makeImageMemoryBarrier
545 				(
546 					0u,
547 					VK_ACCESS_TRANSFER_WRITE_BIT,
548 					VK_IMAGE_LAYOUT_UNDEFINED,
549 					VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
550 					*imageRead,
551 					makeImageSubresourceRange(aspect, 0u, imageSparseInfo.mipLevels, 0u, imageSparseInfo.arrayLayers),
552 					sparseQueue.queueFamilyIndex != computeQueue.queueFamilyIndex ? sparseQueue.queueFamilyIndex : VK_QUEUE_FAMILY_IGNORED,
553 					sparseQueue.queueFamilyIndex != computeQueue.queueFamilyIndex ? computeQueue.queueFamilyIndex : VK_QUEUE_FAMILY_IGNORED
554 				));
555 			}
556 
557 			deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, static_cast<deUint32>(imageSparseTransferDstBarriers.size()), imageSparseTransferDstBarriers.data());
558 		}
559 
560 		deviceInterface.cmdCopyBufferToImage(*commandBuffer, *inputBuffer, *imageRead, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast<deUint32>(bufferImageCopy.size()), bufferImageCopy.data());
561 
562 		{
563 			std::vector<VkImageMemoryBarrier> imageSparseTransferSrcBarriers;
564 
565 			for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
566 			{
567 				const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
568 
569 				imageSparseTransferSrcBarriers.emplace_back(makeImageMemoryBarrier
570 				(
571 					VK_ACCESS_TRANSFER_WRITE_BIT,
572 					VK_ACCESS_TRANSFER_READ_BIT,
573 					VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
574 					VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
575 					*imageRead,
576 					makeImageSubresourceRange(aspect, 0u, imageSparseInfo.mipLevels, 0u, imageSparseInfo.arrayLayers)
577 				));
578 			}
579 
580 			deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, static_cast<deUint32>(imageSparseTransferSrcBarriers.size()), imageSparseTransferSrcBarriers.data());
581 		}
582 
583 		{
584 			std::vector<VkImageMemoryBarrier> imageSparseShaderStorageBarriers;
585 
586 			for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
587 			{
588 				const VkImageAspectFlags aspect = (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
589 
590 				imageSparseShaderStorageBarriers.emplace_back(makeImageMemoryBarrier
591 				(
592 					0u,
593 					VK_ACCESS_SHADER_WRITE_BIT,
594 					VK_IMAGE_LAYOUT_UNDEFINED,
595 					VK_IMAGE_LAYOUT_GENERAL,
596 					*imageWrite,
597 					makeImageSubresourceRange(aspect, 0u, imageSparseInfo.mipLevels, 0u, imageSparseInfo.arrayLayers)
598 				));
599 			}
600 
601 			deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, static_cast<deUint32>(imageSparseShaderStorageBarriers.size()), imageSparseShaderStorageBarriers.data());
602 		}
603 
604 		// Create descriptor set layout
605 		const Unique<VkDescriptorSetLayout> descriptorSetLayout(
606 			DescriptorSetLayoutBuilder()
607 			.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
608 			.build(deviceInterface, getDevice()));
609 
610 		Unique<VkPipelineLayout> pipelineLayout(makePipelineLayout(deviceInterface, getDevice(), *descriptorSetLayout));
611 
612 		Unique<VkDescriptorPool> descriptorPool(
613 			DescriptorPoolBuilder()
614 			.addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, imageSparseInfo.mipLevels)
615 			.build(deviceInterface, getDevice(), VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, imageSparseInfo.mipLevels));
616 
617 		typedef de::SharedPtr< Unique<VkImageView> >		SharedVkImageView;
618 		std::vector<SharedVkImageView>						imageViews;
619 		imageViews.resize(imageSparseInfo.mipLevels);
620 
621 		typedef de::SharedPtr< Unique<VkDescriptorSet> >	SharedVkDescriptorSet;
622 		std::vector<SharedVkDescriptorSet>					descriptorSets;
623 		descriptorSets.resize(imageSparseInfo.mipLevels);
624 
625 		typedef de::SharedPtr< Unique<VkPipeline> >			SharedVkPipeline;
626 		std::vector<SharedVkPipeline>						computePipelines;
627 		computePipelines.resize(imageSparseInfo.mipLevels);
628 
629 		for (deUint32 mipLevelNdx = 0u; mipLevelNdx < imageSparseInfo.mipLevels; ++mipLevelNdx)
630 		{
631 			std::ostringstream name;
632 			name << "comp" << mipLevelNdx;
633 
634 			// Create and bind compute pipeline
635 			Unique<VkShaderModule> shaderModule(createShaderModule(deviceInterface, getDevice(), m_context.getBinaryCollection().get(name.str()), DE_NULL));
636 
637 			computePipelines[mipLevelNdx]	= makeVkSharedPtr(makeComputePipeline(deviceInterface, getDevice(), *pipelineLayout, *shaderModule));
638 			VkPipeline computePipeline		= **computePipelines[mipLevelNdx];
639 
640 			deviceInterface.cmdBindPipeline(*commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, computePipeline);
641 
642 			// Create and bind descriptor set
643 			descriptorSets[mipLevelNdx]		= makeVkSharedPtr(makeDescriptorSet(deviceInterface, getDevice(), *descriptorPool, *descriptorSetLayout));
644 			VkDescriptorSet descriptorSet	= **descriptorSets[mipLevelNdx];
645 
646 			// Select which mipmap level to bind
647 			const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, mipLevelNdx, 1u, 0u, imageSparseInfo.arrayLayers);
648 
649 			imageViews[mipLevelNdx] = makeVkSharedPtr(makeImageView(deviceInterface, getDevice(), *imageWrite, mapImageViewType(m_imageType), imageSparseInfo.format, subresourceRange));
650 			VkImageView imageView	= **imageViews[mipLevelNdx];
651 
652 			const VkDescriptorImageInfo descriptorImageSparseInfo = makeDescriptorImageInfo(DE_NULL, imageView, VK_IMAGE_LAYOUT_GENERAL);
653 
654 			DescriptorSetUpdateBuilder()
655 				.writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageSparseInfo)
656 				.update(deviceInterface, getDevice());
657 
658 			deviceInterface.cmdBindDescriptorSets(*commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
659 
660 			const tcu::UVec3	gridSize			= getShaderGridSize(m_imageType, m_imageSize, mipLevelNdx);
661 			const deUint32		xWorkGroupSize		= std::min(std::min(gridSize.x(), maxWorkGroupSize.x()), maxWorkGroupInvocations);
662 			const deUint32		yWorkGroupSize		= std::min(std::min(gridSize.y(), maxWorkGroupSize.y()), maxWorkGroupInvocations / xWorkGroupSize);
663 			const deUint32		zWorkGroupSize		= std::min(std::min(gridSize.z(), maxWorkGroupSize.z()), maxWorkGroupInvocations / (xWorkGroupSize * yWorkGroupSize));
664 
665 			const deUint32		xWorkGroupCount		= gridSize.x() / xWorkGroupSize + (gridSize.x() % xWorkGroupSize ? 1u : 0u);
666 			const deUint32		yWorkGroupCount		= gridSize.y() / yWorkGroupSize + (gridSize.y() % yWorkGroupSize ? 1u : 0u);
667 			const deUint32		zWorkGroupCount		= gridSize.z() / zWorkGroupSize + (gridSize.z() % zWorkGroupSize ? 1u : 0u);
668 
669 			if (maxWorkGroupCount.x() < xWorkGroupCount ||
670 				maxWorkGroupCount.y() < yWorkGroupCount ||
671 				maxWorkGroupCount.z() < zWorkGroupCount)
672 			{
673 				TCU_THROW(NotSupportedError, "Image size is not supported");
674 			}
675 
676 			deviceInterface.cmdDispatch(*commandBuffer, xWorkGroupCount, yWorkGroupCount, zWorkGroupCount);
677 		}
678 
679 		{
680 			const VkMemoryBarrier memoryBarrier = makeMemoryBarrier(VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
681 
682 			deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 1u, &memoryBarrier, 0u, DE_NULL, 0u, DE_NULL);
683 		}
684 
685 		const VkBufferCreateInfo		outputBufferCreateInfo	= makeBufferCreateInfo(imageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
686 		const Unique<VkBuffer>			outputBuffer			(createBuffer(deviceInterface, getDevice(), &outputBufferCreateInfo));
687 		const de::UniquePtr<Allocation>	outputBufferAlloc		(bindBuffer(deviceInterface, getDevice(), getAllocator(), *outputBuffer, MemoryRequirement::HostVisible));
688 
689 		deviceInterface.cmdCopyImageToBuffer(*commandBuffer, *imageRead, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *outputBuffer, static_cast<deUint32>(bufferImageCopy.size()), bufferImageCopy.data());
690 
691 		{
692 			const VkBufferMemoryBarrier outputBufferBarrier = makeBufferMemoryBarrier
693 			(
694 				VK_ACCESS_TRANSFER_WRITE_BIT,
695 				VK_ACCESS_HOST_READ_BIT,
696 				*outputBuffer,
697 				0u,
698 				imageSizeInBytes
699 			);
700 
701 			deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &outputBufferBarrier, 0u, DE_NULL);
702 		}
703 
704 		// End recording commands
705 		endCommandBuffer(deviceInterface, *commandBuffer);
706 
707 		const VkPipelineStageFlags stageBits[] = { VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT };
708 
709 		// Submit commands for execution and wait for completion
710 		submitCommandsAndWait(deviceInterface, getDevice(), computeQueue.queueHandle, *commandBuffer, 2u, imageMemoryBindSemaphores, stageBits,
711 								0, DE_NULL, m_useDeviceGroups, firstDeviceID);
712 
713 		// Retrieve data from buffer to host memory
714 		invalidateAlloc(deviceInterface, getDevice(), *outputBufferAlloc);
715 
716 		deUint8* outputData = static_cast<deUint8*>(outputBufferAlloc->getHostPtr());
717 
718 		std::vector<std::vector<void*>> planePointers(imageSparseInfo.mipLevels);
719 
720 		for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
721 			planePointers[mipmapNdx].resize(formatDescription.numPlanes);
722 
723 		for (deUint32 planeNdx = 0; planeNdx < formatDescription.numPlanes; ++planeNdx)
724 			for (deUint32 mipmapNdx = 0; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
725 				planePointers[mipmapNdx][planeNdx] = outputData + static_cast<size_t>(planeOffsets[mipmapNdx][planeNdx]);
726 
727 		// Wait for sparse queue to become idle
728 		deviceInterface.queueWaitIdle(sparseQueue.queueHandle);
729 
730 		for (deUint32 channelNdx = 0; channelNdx < 4; ++channelNdx)
731 		{
732 			if (!formatDescription.hasChannelNdx(channelNdx))
733 				continue;
734 
735 			deUint32							planeNdx			= formatDescription.channels[channelNdx].planeNdx;
736 			const VkImageAspectFlags			aspect				= (formatDescription.numPlanes > 1) ? getPlaneAspect(planeNdx) : VK_IMAGE_ASPECT_COLOR_BIT;
737 			const deUint32						aspectIndex			= getSparseAspectRequirementsIndex(sparseMemoryRequirements, aspect);
738 
739 			if (aspectIndex == NO_MATCH_FOUND)
740 				TCU_THROW(NotSupportedError, "Not supported image aspect");
741 
742 			VkSparseImageMemoryRequirements aspectRequirements	= sparseMemoryRequirements[aspectIndex];
743 
744 			for (deUint32 mipmapNdx = 0; mipmapNdx < aspectRequirements.imageMipTailFirstLod; ++mipmapNdx)
745 			{
746 				const	tcu::UVec3						gridSize		= getShaderGridSize(m_imageType, m_imageSize, mipmapNdx);
747 				const	tcu::ConstPixelBufferAccess		pixelBuffer		= vk::getChannelAccess(formatDescription, gridSize, planeRowPitches[mipmapNdx].data(), (const void* const*)planePointers[mipmapNdx].data(), channelNdx);
748 				tcu::IVec3								pixelDivider	= pixelBuffer.getDivider();
749 
750 				for (deUint32 offsetZ = 0u; offsetZ < gridSize.z(); ++offsetZ)
751 				for (deUint32 offsetY = 0u; offsetY < gridSize.y(); ++offsetY)
752 				for (deUint32 offsetX = 0u; offsetX < gridSize.x(); ++offsetX)
753 				{
754 					const deUint32	index			= offsetX + gridSize.x() * offsetY + gridSize.x() * gridSize.y() * offsetZ;
755 					deUint32		iReferenceValue;
756 					float			fReferenceValue;
757 					float			acceptableError	= epsilon;
758 
759 					switch (channelNdx)
760 					{
761 						case 0:
762 						case 1:
763 						case 2:
764 							iReferenceValue = index % MODULO_DIVISOR;
765 							fReferenceValue = static_cast<float>(iReferenceValue) / static_cast<float>(MODULO_DIVISOR);
766 							break;
767 						case 3:
768 							iReferenceValue = 1u;
769 							fReferenceValue = 1.f;
770 							break;
771 						default:	DE_FATAL("Unexpected channel index");	break;
772 					}
773 
774 					switch (formatDescription.channels[channelNdx].type)
775 					{
776 						case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
777 						case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
778 						{
779 							const tcu::UVec4 outputValue = pixelBuffer.getPixelUint(offsetX * pixelDivider.x(), offsetY * pixelDivider.y(), offsetZ * pixelDivider.z());
780 
781 							if (outputValue.x() != iReferenceValue)
782 								return tcu::TestStatus::fail("Failed");
783 
784 							break;
785 						}
786 						case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
787 						case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
788 						{
789 							float fixedPointError = tcu::TexVerifierUtil::computeFixedPointError(formatDescription.channels[channelNdx].sizeBits);
790 							acceptableError += fixedPointError;
791 							const tcu::Vec4 outputValue = pixelBuffer.getPixel(offsetX * pixelDivider.x(), offsetY * pixelDivider.y(), offsetZ * pixelDivider.z());
792 
793 							if (deAbs(outputValue.x() - fReferenceValue) > acceptableError)
794 								return tcu::TestStatus::fail("Failed");
795 
796 							break;
797 						}
798 						case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
799 						{
800 							const tcu::Vec4 outputValue = pixelBuffer.getPixel(offsetX * pixelDivider.x(), offsetY * pixelDivider.y(), offsetZ * pixelDivider.z());
801 
802 							if (deAbs(outputValue.x() - fReferenceValue) > acceptableError)
803 								return tcu::TestStatus::fail("Failed");
804 
805 							break;
806 						}
807 						default:	DE_FATAL("Unexpected channel type");	break;
808 					}
809 				}
810 			}
811 
812 			for (deUint32 mipmapNdx = aspectRequirements.imageMipTailFirstLod; mipmapNdx < imageSparseInfo.mipLevels; ++mipmapNdx)
813 			{
814 				const deUint32 mipLevelSizeInBytes	= getImageMipLevelSizeInBytes(imageSparseInfo.extent, imageSparseInfo.arrayLayers, formatDescription, planeNdx, mipmapNdx);
815 				const deUint32 bufferOffset			= static_cast<deUint32>(bufferImageCopy[planeNdx*imageSparseInfo.mipLevels + mipmapNdx].bufferOffset);
816 
817 				if (deMemCmp(outputData + bufferOffset, &referenceData[bufferOffset], mipLevelSizeInBytes) != 0)
818 					return tcu::TestStatus::fail("Failed");
819 			}
820 		}
821 	}
822 
823 	return tcu::TestStatus::pass("Passed");
824 }
825 
initPrograms(SourceCollections & sourceCollections) const826 void ImageSparseMemoryAliasingCase::initPrograms(SourceCollections&	sourceCollections) const
827 {
828 	const char* const				versionDecl				= glu::getGLSLVersionDeclaration(m_glslVersion);
829 	const PlanarFormatDescription	formatDescription		= getPlanarFormatDescription(m_format);
830 	const std::string				imageTypeStr			= getShaderImageType(formatDescription, m_imageType);
831 	const std::string				formatQualifierStr		= getShaderImageFormatQualifier(m_format);
832 	const std::string				formatDataStr			= getShaderImageDataType(formatDescription);
833 	const deUint32					maxWorkGroupInvocations = 128u;
834 	const tcu::UVec3				maxWorkGroupSize		= tcu::UVec3(128u, 128u, 64u);
835 	VkExtent3D						layerExtent				= makeExtent3D(getLayerSize(m_imageType, m_imageSize));
836 	VkImageFormatProperties			imageFormatProperties;
837 	imageFormatProperties.maxMipLevels						= 20;
838 	const deUint32					mipLevels				= getMipmapCount(m_format, formatDescription, imageFormatProperties, layerExtent);
839 
840 	std::ostringstream formatValueStr;
841 	switch (formatDescription.channels[0].type)
842 	{
843 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
844 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
845 			formatValueStr << "( index % " << MODULO_DIVISOR << ", index % " << MODULO_DIVISOR << ", index % " << MODULO_DIVISOR << ", 1)";
846 			break;
847 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
848 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
849 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
850 			formatValueStr << "( float( index % " << MODULO_DIVISOR << ") / " << MODULO_DIVISOR << ".0, float( index % " << MODULO_DIVISOR << ") / " << MODULO_DIVISOR << ".0, float( index % " << MODULO_DIVISOR << ") / " << MODULO_DIVISOR << ".0, 1.0)";
851 			break;
852 		default:	DE_FATAL("Unexpected channel type");	break;
853 	}
854 
855 
856 	for (deUint32 mipLevelNdx = 0; mipLevelNdx < mipLevels; ++mipLevelNdx)
857 	{
858 		// Create compute program
859 		const tcu::UVec3	gridSize		= getShaderGridSize(m_imageType, m_imageSize, mipLevelNdx);
860 		const deUint32		xWorkGroupSize  = std::min(std::min(gridSize.x(), maxWorkGroupSize.x()), maxWorkGroupInvocations);
861 		const deUint32		yWorkGroupSize  = std::min(std::min(gridSize.y(), maxWorkGroupSize.y()), maxWorkGroupInvocations / xWorkGroupSize);
862 		const deUint32		zWorkGroupSize  = std::min(std::min(gridSize.z(), maxWorkGroupSize.z()), maxWorkGroupInvocations / (xWorkGroupSize * yWorkGroupSize));
863 
864 		std::ostringstream src;
865 
866 		src << versionDecl << "\n";
867 		if (formatIsR64(m_format))
868 		{
869 			src << "#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require\n"
870 				<< "#extension GL_EXT_shader_image_int64 : require\n";
871 		}
872 		src << "layout (local_size_x = " << xWorkGroupSize << ", local_size_y = " << yWorkGroupSize << ", local_size_z = " << zWorkGroupSize << ") in; \n"
873 			<< "layout (binding = 0, " << formatQualifierStr << ") writeonly uniform highp " << imageTypeStr << " u_image;\n"
874 			<< "void main (void)\n"
875 			<< "{\n"
876 			<< "	if( gl_GlobalInvocationID.x < " << gridSize.x() << " ) \n"
877 			<< "	if( gl_GlobalInvocationID.y < " << gridSize.y() << " ) \n"
878 			<< "	if( gl_GlobalInvocationID.z < " << gridSize.z() << " ) \n"
879 			<< "	{\n"
880 			<< "		int index = int( gl_GlobalInvocationID.x + "<< gridSize.x() << " * gl_GlobalInvocationID.y + " << gridSize.x() << " * " << gridSize.y() << " * gl_GlobalInvocationID.z );\n"
881 			<< "		imageStore(u_image, " << getCoordStr(m_imageType, "gl_GlobalInvocationID.x", "gl_GlobalInvocationID.y", "gl_GlobalInvocationID.z") << ","
882 			<< formatDataStr << formatValueStr.str() <<"); \n"
883 			<< "	}\n"
884 			<< "}\n";
885 
886 		std::ostringstream name;
887 		name << "comp" << mipLevelNdx;
888 		sourceCollections.glslSources.add(name.str()) << glu::ComputeSource(src.str());
889 	}
890 }
891 
createInstance(Context & context) const892 TestInstance* ImageSparseMemoryAliasingCase::createInstance (Context& context) const
893 {
894 	return new ImageSparseMemoryAliasingInstance(context, m_imageType, m_imageSize, m_format, m_useDeviceGroups);
895 }
896 
897 } // anonymous ns
898 
createImageSparseMemoryAliasingTestsCommon(tcu::TestContext & testCtx,de::MovePtr<tcu::TestCaseGroup> testGroup,const bool useDeviceGroup=false)899 tcu::TestCaseGroup* createImageSparseMemoryAliasingTestsCommon(tcu::TestContext& testCtx, de::MovePtr<tcu::TestCaseGroup> testGroup, const bool useDeviceGroup = false)
900 {
901 
902 	const std::vector<TestImageParameters> imageParameters
903 	{
904 		{ IMAGE_TYPE_2D,		{ tcu::UVec3(512u, 256u, 1u),	tcu::UVec3(128u, 128u, 1u),	tcu::UVec3(503u, 137u, 1u),	tcu::UVec3(11u, 37u, 1u) },	getTestFormats(IMAGE_TYPE_2D) },
905 		{ IMAGE_TYPE_2D_ARRAY,	{ tcu::UVec3(512u, 256u, 6u),	tcu::UVec3(128u, 128u, 8u),	tcu::UVec3(503u, 137u, 3u),	tcu::UVec3(11u, 37u, 3u) },	getTestFormats(IMAGE_TYPE_2D_ARRAY) },
906 		{ IMAGE_TYPE_CUBE,		{ tcu::UVec3(256u, 256u, 1u),	tcu::UVec3(128u, 128u, 1u),	tcu::UVec3(137u, 137u, 1u),	tcu::UVec3(11u, 11u, 1u) },	getTestFormats(IMAGE_TYPE_CUBE) },
907 		{ IMAGE_TYPE_CUBE_ARRAY,{ tcu::UVec3(256u, 256u, 6u),	tcu::UVec3(128u, 128u, 8u),	tcu::UVec3(137u, 137u, 3u),	tcu::UVec3(11u, 11u, 3u) },	getTestFormats(IMAGE_TYPE_CUBE_ARRAY) },
908 		{ IMAGE_TYPE_3D,		{ tcu::UVec3(256u, 256u, 16u),	tcu::UVec3(128u, 128u, 8u),	tcu::UVec3(503u, 137u, 3u),	tcu::UVec3(11u, 37u, 3u) },	getTestFormats(IMAGE_TYPE_3D) }
909 	};
910 
911 	for (size_t imageTypeNdx = 0; imageTypeNdx < imageParameters.size(); ++imageTypeNdx)
912 	{
913 		const ImageType					imageType = imageParameters[imageTypeNdx].imageType;
914 		de::MovePtr<tcu::TestCaseGroup> imageTypeGroup(new tcu::TestCaseGroup(testCtx, getImageTypeName(imageType).c_str(), ""));
915 
916 		for (size_t formatNdx = 0; formatNdx < imageParameters[imageTypeNdx].formats.size(); ++formatNdx)
917 		{
918 			VkFormat						format				= imageParameters[imageTypeNdx].formats[formatNdx].format;
919 			tcu::UVec3						imageSizeAlignment	= getImageSizeAlignment(format);
920 			de::MovePtr<tcu::TestCaseGroup> formatGroup			(new tcu::TestCaseGroup(testCtx, getImageFormatID(format).c_str(), ""));
921 
922 			for (size_t imageSizeNdx = 0; imageSizeNdx < imageParameters[imageTypeNdx].imageSizes.size(); ++imageSizeNdx)
923 			{
924 				const tcu::UVec3 imageSize = imageParameters[imageTypeNdx].imageSizes[imageSizeNdx];
925 
926 				// skip test for images with odd sizes for some YCbCr formats
927 				if ((imageSize.x() % imageSizeAlignment.x()) != 0)
928 					continue;
929 				if ((imageSize.y() % imageSizeAlignment.y()) != 0)
930 					continue;
931 
932 				std::ostringstream stream;
933 				stream << imageSize.x() << "_" << imageSize.y() << "_" << imageSize.z();
934 
935 				formatGroup->addChild(new ImageSparseMemoryAliasingCase(testCtx, stream.str(), "", imageType, imageSize, format, glu::GLSL_VERSION_440, useDeviceGroup));
936 			}
937 			imageTypeGroup->addChild(formatGroup.release());
938 		}
939 		testGroup->addChild(imageTypeGroup.release());
940 	}
941 
942 	return testGroup.release();
943 }
944 
createImageSparseMemoryAliasingTests(tcu::TestContext & testCtx)945 tcu::TestCaseGroup* createImageSparseMemoryAliasingTests(tcu::TestContext& testCtx)
946 {
947 	de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "image_sparse_memory_aliasing", "Sparse Image Memory Aliasing"));
948 	return createImageSparseMemoryAliasingTestsCommon(testCtx, testGroup);
949 }
950 
createDeviceGroupImageSparseMemoryAliasingTests(tcu::TestContext & testCtx)951 tcu::TestCaseGroup* createDeviceGroupImageSparseMemoryAliasingTests(tcu::TestContext& testCtx)
952 {
953 	de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "device_group_image_sparse_memory_aliasing", "Sparse Image Memory Aliasing"));
954 	return createImageSparseMemoryAliasingTestsCommon(testCtx, testGroup, true);
955 }
956 
957 } // sparse
958 } // vkt
959