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  vktSparseResourcesBufferMemoryAliasing.cpp
21  * \brief Sparse buffer memory aliasing tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktSparseResourcesBufferMemoryAliasing.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 "vkQueryUtil.hpp"
37 #include "vkBuilderUtil.hpp"
38 #include "vkTypeUtil.hpp"
39 
40 #include "deStringUtil.hpp"
41 #include "deUniquePtr.hpp"
42 
43 #include <string>
44 #include <vector>
45 
46 using namespace vk;
47 
48 namespace vkt
49 {
50 namespace sparse
51 {
52 namespace
53 {
54 
55 enum ShaderParameters
56 {
57 	SIZE_OF_UINT_IN_SHADER	= 4u,
58 	MODULO_DIVISOR			= 1024u
59 };
60 
computeWorkGroupSize(const deUint32 numInvocations)61 tcu::UVec3 computeWorkGroupSize (const deUint32 numInvocations)
62 {
63 	const deUint32		maxComputeWorkGroupInvocations	= 128u;
64 	const tcu::UVec3	maxComputeWorkGroupSize			= tcu::UVec3(128u, 128u, 64u);
65 	deUint32			numInvocationsLeft				= numInvocations;
66 
67 	const deUint32 xWorkGroupSize = std::min(std::min(numInvocationsLeft, maxComputeWorkGroupSize.x()), maxComputeWorkGroupInvocations);
68 	numInvocationsLeft = numInvocationsLeft / xWorkGroupSize + ((numInvocationsLeft % xWorkGroupSize) ? 1u : 0u);
69 
70 	const deUint32 yWorkGroupSize = std::min(std::min(numInvocationsLeft, maxComputeWorkGroupSize.y()), maxComputeWorkGroupInvocations / xWorkGroupSize);
71 	numInvocationsLeft = numInvocationsLeft / yWorkGroupSize + ((numInvocationsLeft % yWorkGroupSize) ? 1u : 0u);
72 
73 	const deUint32 zWorkGroupSize = std::min(std::min(numInvocationsLeft, maxComputeWorkGroupSize.z()), maxComputeWorkGroupInvocations / (xWorkGroupSize*yWorkGroupSize));
74 	numInvocationsLeft = numInvocationsLeft / zWorkGroupSize + ((numInvocationsLeft % zWorkGroupSize) ? 1u : 0u);
75 
76 	return tcu::UVec3(xWorkGroupSize, yWorkGroupSize, zWorkGroupSize);
77 }
78 
79 class BufferSparseMemoryAliasingCase : public TestCase
80 {
81 public:
82 					BufferSparseMemoryAliasingCase	(tcu::TestContext&		testCtx,
83 													 const std::string&		name,
84 													 const std::string&		description,
85 													 const deUint32			bufferSize,
86 													 const glu::GLSLVersion	glslVersion);
87 
88 	void			initPrograms					(SourceCollections&		sourceCollections) const;
89 	TestInstance*	createInstance					(Context&				context) const;
90 
91 private:
92 	const	deUint32			m_bufferSizeInBytes;
93 	const	glu::GLSLVersion	m_glslVersion;
94 };
95 
BufferSparseMemoryAliasingCase(tcu::TestContext & testCtx,const std::string & name,const std::string & description,const deUint32 bufferSize,const glu::GLSLVersion glslVersion)96 BufferSparseMemoryAliasingCase::BufferSparseMemoryAliasingCase (tcu::TestContext&		testCtx,
97 																const std::string&		name,
98 																const std::string&		description,
99 																const deUint32			bufferSize,
100 																const glu::GLSLVersion	glslVersion)
101 	: TestCase				(testCtx, name, description)
102 	, m_bufferSizeInBytes	(bufferSize)
103 	, m_glslVersion			(glslVersion)
104 {
105 }
106 
initPrograms(SourceCollections & sourceCollections) const107 void BufferSparseMemoryAliasingCase::initPrograms (SourceCollections& sourceCollections) const
108 {
109 	// Create compute program
110 	const char* const versionDecl		= glu::getGLSLVersionDeclaration(m_glslVersion);
111 	const deUint32	  numInvocations	= m_bufferSizeInBytes / SIZE_OF_UINT_IN_SHADER;
112 	const tcu::UVec3  workGroupSize		= computeWorkGroupSize(numInvocations);
113 
114 	std::ostringstream src;
115 	src << versionDecl << "\n"
116 		<< "layout (local_size_x = " << workGroupSize.x() << ", local_size_y = " << workGroupSize.y() << ", local_size_z = " << workGroupSize.z() << ") in;\n"
117 		<< "layout(set = 0, binding = 0, std430) writeonly buffer Output\n"
118 		<< "{\n"
119 		<< "	uint result[];\n"
120 		<< "} sb_out;\n"
121 		<< "\n"
122 		<< "void main (void)\n"
123 		<< "{\n"
124 		<< "	uint index = gl_GlobalInvocationID.x + (gl_GlobalInvocationID.y + gl_GlobalInvocationID.z*gl_NumWorkGroups.y*gl_WorkGroupSize.y)*gl_NumWorkGroups.x*gl_WorkGroupSize.x;\n"
125 		<< "	if ( index < " << m_bufferSizeInBytes / SIZE_OF_UINT_IN_SHADER << "u )\n"
126 		<< "	{\n"
127 		<< "		sb_out.result[index] = index % " << MODULO_DIVISOR << "u;\n"
128 		<< "	}\n"
129 		<< "}\n";
130 
131 	sourceCollections.glslSources.add("comp") << glu::ComputeSource(src.str());
132 }
133 
134 class BufferSparseMemoryAliasingInstance : public SparseResourcesBaseInstance
135 {
136 public:
137 					BufferSparseMemoryAliasingInstance	(Context&					context,
138 														 const deUint32				bufferSize);
139 
140 	tcu::TestStatus	iterate								(void);
141 
142 private:
143 	const deUint32			m_bufferSizeInBytes;
144 };
145 
BufferSparseMemoryAliasingInstance(Context & context,const deUint32 bufferSize)146 BufferSparseMemoryAliasingInstance::BufferSparseMemoryAliasingInstance (Context&					context,
147 																		const deUint32			bufferSize)
148 	: SparseResourcesBaseInstance	(context)
149 	, m_bufferSizeInBytes			(bufferSize)
150 {
151 }
152 
iterate(void)153 tcu::TestStatus BufferSparseMemoryAliasingInstance::iterate (void)
154 {
155 	const InstanceInterface&		instance		= m_context.getInstanceInterface();
156 	const DeviceInterface&			deviceInterface	= m_context.getDeviceInterface();
157 	const VkPhysicalDevice			physicalDevice	= m_context.getPhysicalDevice();
158 	const VkPhysicalDeviceFeatures	deviceFeatures	= getPhysicalDeviceFeatures(instance, physicalDevice);
159 
160 	if (deviceFeatures.sparseBinding == false)
161 	{
162 		return tcu::TestStatus(QP_TEST_RESULT_NOT_SUPPORTED, "Sparse binding not supported");
163 	}
164 
165 	if (deviceFeatures.sparseResidencyAliased == false)
166 	{
167 		return tcu::TestStatus(QP_TEST_RESULT_NOT_SUPPORTED, "Sparse memory aliasing not supported");
168 	}
169 
170 	QueueRequirementsVec queueRequirements;
171 	queueRequirements.push_back(QueueRequirements(VK_QUEUE_SPARSE_BINDING_BIT, 1u));
172 	queueRequirements.push_back(QueueRequirements(VK_QUEUE_COMPUTE_BIT, 1u));
173 
174 	// Create logical device supporting both sparse and compute oprations
175 	if (!createDeviceSupportingQueues(queueRequirements))
176 	{
177 		return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Could not create device supporting sparse and compute queue");
178 	}
179 
180 	const VkPhysicalDeviceMemoryProperties deviceMemoryProperties = getPhysicalDeviceMemoryProperties(instance, physicalDevice);
181 
182 	// Create memory allocator for device
183 	const de::UniquePtr<Allocator> allocator(new SimpleAllocator(deviceInterface, *m_logicalDevice, deviceMemoryProperties));
184 
185 	// Create queue supporting sparse binding operations
186 	const Queue& sparseQueue = getQueue(VK_QUEUE_SPARSE_BINDING_BIT, 0);
187 
188 	// Create queue supporting compute and transfer operations
189 	const Queue& computeQueue = getQueue(VK_QUEUE_COMPUTE_BIT, 0);
190 
191 	VkBufferCreateInfo bufferCreateInfo =
192 	{
193 		VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,	// VkStructureType		sType;
194 		DE_NULL,								// const void*			pNext;
195 		VK_BUFFER_CREATE_SPARSE_BINDING_BIT |
196 		VK_BUFFER_CREATE_SPARSE_ALIASED_BIT,	// VkBufferCreateFlags	flags;
197 		m_bufferSizeInBytes,					// VkDeviceSize			size;
198 		VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
199 		VK_BUFFER_USAGE_TRANSFER_SRC_BIT,		// VkBufferUsageFlags	usage;
200 		VK_SHARING_MODE_EXCLUSIVE,				// VkSharingMode		sharingMode;
201 		0u,										// deUint32				queueFamilyIndexCount;
202 		DE_NULL									// const deUint32*		pQueueFamilyIndices;
203 	};
204 
205 	const deUint32 queueFamilyIndices[] = { sparseQueue.queueFamilyIndex, computeQueue.queueFamilyIndex };
206 
207 	if (sparseQueue.queueFamilyIndex != computeQueue.queueFamilyIndex)
208 	{
209 		bufferCreateInfo.sharingMode			= VK_SHARING_MODE_CONCURRENT;
210 		bufferCreateInfo.queueFamilyIndexCount	= 2u;
211 		bufferCreateInfo.pQueueFamilyIndices	= queueFamilyIndices;
212 	}
213 
214 	// Create sparse buffers
215 	const Unique<VkBuffer> sparseBufferWrite(createBuffer(deviceInterface, *m_logicalDevice, &bufferCreateInfo));
216 	const Unique<VkBuffer> sparseBufferRead	(createBuffer(deviceInterface, *m_logicalDevice, &bufferCreateInfo));
217 
218 	const VkMemoryRequirements		 bufferMemRequirements = getBufferMemoryRequirements(deviceInterface, *m_logicalDevice, *sparseBufferWrite);
219 	const VkPhysicalDeviceProperties deviceProperties	   = getPhysicalDeviceProperties(instance, physicalDevice);
220 
221 	if (bufferMemRequirements.size > deviceProperties.limits.sparseAddressSpaceSize)
222 	{
223 		return tcu::TestStatus(QP_TEST_RESULT_NOT_SUPPORTED, "Required memory size for sparse resources exceeds device limits");
224 	}
225 
226 	DE_ASSERT((bufferMemRequirements.size % bufferMemRequirements.alignment) == 0);
227 
228 	const deUint32 memoryType = findMatchingMemoryType(deviceMemoryProperties, bufferMemRequirements, MemoryRequirement::Any);
229 
230 	if (memoryType == NO_MATCH_FOUND)
231 	{
232 		return tcu::TestStatus(QP_TEST_RESULT_FAIL, "No matching memory type found");
233 	}
234 
235 	const VkMemoryAllocateInfo allocInfo =
236 	{
237 		VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,	//	VkStructureType			sType;
238 		DE_NULL,								//	const void*				pNext;
239 		bufferMemRequirements.size,				//	VkDeviceSize			allocationSize;
240 		memoryType,								//	deUint32				memoryTypeIndex;
241 	};
242 
243 	VkDeviceMemory deviceMemory;
244 	VK_CHECK(deviceInterface.allocateMemory(*m_logicalDevice, &allocInfo, DE_NULL, &deviceMemory));
245 
246 	Move<VkDeviceMemory> deviceMemoryPtr(check<VkDeviceMemory>(deviceMemory), Deleter<VkDeviceMemory>(deviceInterface, *m_logicalDevice, DE_NULL));
247 
248 	const VkSparseMemoryBind sparseMemoryBind = makeSparseMemoryBind
249 	(
250 		0u,							//VkDeviceSize				resourceOffset
251 		bufferMemRequirements.size,	//VkDeviceSize				size
252 		deviceMemory,				//VkDeviceMemory			memory
253 		0u,							//VkDeviceSize				memoryOffset
254 		0u							//VkSparseMemoryBindFlags	flags
255 	);
256 
257 	const VkSparseBufferMemoryBindInfo sparseBufferMemoryBindInfo[2] =
258 	{
259 		makeSparseBufferMemoryBindInfo
260 		(*sparseBufferWrite,	//VkBuffer					buffer;
261 		1u,						//deUint32					bindCount;
262 		&sparseMemoryBind		//const VkSparseMemoryBind*	Binds;
263 		),
264 
265 		makeSparseBufferMemoryBindInfo
266 		(*sparseBufferRead,		//VkBuffer					buffer;
267 		1u,						//deUint32					bindCount;
268 		&sparseMemoryBind		//const VkSparseMemoryBind*	Binds;
269 		)
270 	};
271 
272 	const Unique<VkSemaphore> bufferMemoryBindSemaphore(makeSemaphore(deviceInterface, *m_logicalDevice));
273 
274 	const VkBindSparseInfo bindSparseInfo =
275 	{
276 		VK_STRUCTURE_TYPE_BIND_SPARSE_INFO,			//VkStructureType							sType;
277 		DE_NULL,									//const void*								pNext;
278 		0u,											//deUint32									waitSemaphoreCount;
279 		DE_NULL,									//const VkSemaphore*						pWaitSemaphores;
280 		2u,											//deUint32									bufferBindCount;
281 		sparseBufferMemoryBindInfo,					//const VkSparseBufferMemoryBindInfo*		pBufferBinds;
282 		0u,											//deUint32									imageOpaqueBindCount;
283 		DE_NULL,									//const VkSparseImageOpaqueMemoryBindInfo*	pImageOpaqueBinds;
284 		0u,											//deUint32									imageBindCount;
285 		DE_NULL,									//const VkSparseImageMemoryBindInfo*		pImageBinds;
286 		1u,											//deUint32									signalSemaphoreCount;
287 		&bufferMemoryBindSemaphore.get()			//const VkSemaphore*						pSignalSemaphores;
288 	};
289 
290 	// Submit sparse bind commands for execution
291 	VK_CHECK(deviceInterface.queueBindSparse(sparseQueue.queueHandle, 1u, &bindSparseInfo, DE_NULL));
292 
293 	// Create output buffer
294 	const VkBufferCreateInfo outputBufferCreateInfo = makeBufferCreateInfo(m_bufferSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
295 	de::UniquePtr<Buffer>	 outputBuffer(new Buffer(deviceInterface, *m_logicalDevice, *allocator, outputBufferCreateInfo, MemoryRequirement::HostVisible));
296 
297 	// Create command buffer for compute and data transfer oparations
298 	const Unique<VkCommandPool>	  commandPool(makeCommandPool(deviceInterface, *m_logicalDevice, computeQueue.queueFamilyIndex));
299 	const Unique<VkCommandBuffer> commandBuffer(makeCommandBuffer(deviceInterface, *m_logicalDevice, *commandPool));
300 
301 	// Start recording commands
302 	beginCommandBuffer(deviceInterface, *commandBuffer);
303 
304 	// Create descriptor set
305 	const Unique<VkDescriptorSetLayout> descriptorSetLayout(
306 		DescriptorSetLayoutBuilder()
307 		.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
308 		.build(deviceInterface, *m_logicalDevice));
309 
310 	// Create compute pipeline
311 	const Unique<VkShaderModule>	shaderModule(createShaderModule(deviceInterface, *m_logicalDevice, m_context.getBinaryCollection().get("comp"), DE_NULL));
312 	const Unique<VkPipelineLayout>	pipelineLayout(makePipelineLayout(deviceInterface, *m_logicalDevice, *descriptorSetLayout));
313 	const Unique<VkPipeline>		computePipeline(makeComputePipeline(deviceInterface, *m_logicalDevice, *pipelineLayout, *shaderModule));
314 
315 	deviceInterface.cmdBindPipeline(*commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *computePipeline);
316 
317 	// Create descriptor set
318 	const Unique<VkDescriptorPool> descriptorPool(
319 		DescriptorPoolBuilder()
320 		.addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1u)
321 		.build(deviceInterface, *m_logicalDevice, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
322 
323 	const Unique<VkDescriptorSet> descriptorSet(makeDescriptorSet(deviceInterface, *m_logicalDevice, *descriptorPool, *descriptorSetLayout));
324 
325 	const VkDescriptorBufferInfo sparseBufferInfo = makeDescriptorBufferInfo(*sparseBufferWrite, 0u, m_bufferSizeInBytes);
326 
327 	DescriptorSetUpdateBuilder()
328 		.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &sparseBufferInfo)
329 		.update(deviceInterface, *m_logicalDevice);
330 
331 	deviceInterface.cmdBindDescriptorSets(*commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL);
332 
333 	deUint32		 numInvocationsLeft			= m_bufferSizeInBytes / SIZE_OF_UINT_IN_SHADER;
334 	const tcu::UVec3 workGroupSize				= computeWorkGroupSize(numInvocationsLeft);
335 	const tcu::UVec3 maxComputeWorkGroupCount	= tcu::UVec3(65535u, 65535u, 65535u);
336 
337 	numInvocationsLeft -= workGroupSize.x()*workGroupSize.y()*workGroupSize.z();
338 
339 	const deUint32	xWorkGroupCount = std::min(numInvocationsLeft, maxComputeWorkGroupCount.x());
340 	numInvocationsLeft = numInvocationsLeft / xWorkGroupCount + ((numInvocationsLeft % xWorkGroupCount) ? 1u : 0u);
341 	const deUint32	yWorkGroupCount = std::min(numInvocationsLeft, maxComputeWorkGroupCount.y());
342 	numInvocationsLeft = numInvocationsLeft / yWorkGroupCount + ((numInvocationsLeft % yWorkGroupCount) ? 1u : 0u);
343 	const deUint32	zWorkGroupCount = std::min(numInvocationsLeft, maxComputeWorkGroupCount.z());
344 	numInvocationsLeft = numInvocationsLeft / zWorkGroupCount + ((numInvocationsLeft % zWorkGroupCount) ? 1u : 0u);
345 
346 	if (numInvocationsLeft != 1u)
347 	{
348 		return tcu::TestStatus(QP_TEST_RESULT_NOT_SUPPORTED, "Buffer size is not supported");
349 	}
350 
351 	deviceInterface.cmdDispatch(*commandBuffer, xWorkGroupCount, yWorkGroupCount, zWorkGroupCount);
352 
353 	const VkBufferMemoryBarrier sparseBufferWriteBarrier
354 		= makeBufferMemoryBarrier(	VK_ACCESS_SHADER_WRITE_BIT,
355 									VK_ACCESS_TRANSFER_READ_BIT,
356 									*sparseBufferWrite,
357 									0ull,
358 									m_bufferSizeInBytes);
359 
360 	deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 1u, &sparseBufferWriteBarrier, 0u, DE_NULL);
361 
362 	const VkBufferCopy bufferCopy = makeBufferCopy(0u, 0u, m_bufferSizeInBytes);
363 
364 	deviceInterface.cmdCopyBuffer(*commandBuffer, *sparseBufferRead, outputBuffer->get(), 1u, &bufferCopy);
365 
366 	const VkBufferMemoryBarrier outputBufferHostBarrier
367 		= makeBufferMemoryBarrier(	VK_ACCESS_TRANSFER_WRITE_BIT,
368 									VK_ACCESS_HOST_READ_BIT,
369 									outputBuffer->get(),
370 									0ull,
371 									m_bufferSizeInBytes);
372 
373 	deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &outputBufferHostBarrier, 0u, DE_NULL);
374 
375 	// End recording commands
376 	endCommandBuffer(deviceInterface, *commandBuffer);
377 
378 	// The stage at which execution is going to wait for finish of sparse binding operations
379 	const VkPipelineStageFlags waitStageBits[] = { VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT };
380 
381 	// Submit commands for execution and wait for completion
382 	submitCommandsAndWait(deviceInterface, *m_logicalDevice, computeQueue.queueHandle, *commandBuffer, 1u, &bufferMemoryBindSemaphore.get(), waitStageBits);
383 
384 	// Retrieve data from output buffer to host memory
385 	const Allocation& allocation = outputBuffer->getAllocation();
386 
387 	invalidateMappedMemoryRange(deviceInterface, *m_logicalDevice, allocation.getMemory(), allocation.getOffset(), m_bufferSizeInBytes);
388 
389 	const deUint8*	outputData = static_cast<const deUint8*>(allocation.getHostPtr());
390 
391 	// Prepare reference data
392 	std::vector<deUint8> referenceData;
393 	referenceData.resize(m_bufferSizeInBytes);
394 
395 	std::vector<deUint32> referenceDataBlock;
396 	referenceDataBlock.resize(MODULO_DIVISOR);
397 
398 	for (deUint32 valueNdx = 0; valueNdx < MODULO_DIVISOR; ++valueNdx)
399 	{
400 		referenceDataBlock[valueNdx] = valueNdx % MODULO_DIVISOR;
401 	}
402 
403 	const deUint32 fullBlockSizeInBytes = MODULO_DIVISOR * SIZE_OF_UINT_IN_SHADER;
404 	const deUint32 lastBlockSizeInBytes = m_bufferSizeInBytes % fullBlockSizeInBytes;
405 	const deUint32 numberOfBlocks		= m_bufferSizeInBytes / fullBlockSizeInBytes + (lastBlockSizeInBytes ? 1u : 0u);
406 
407 	for (deUint32 blockNdx = 0; blockNdx < numberOfBlocks; ++blockNdx)
408 	{
409 		const deUint32 offset = blockNdx * fullBlockSizeInBytes;
410 		deMemcpy(&referenceData[0] + offset, &referenceDataBlock[0], ((offset + fullBlockSizeInBytes) <= m_bufferSizeInBytes) ? fullBlockSizeInBytes : lastBlockSizeInBytes);
411 	}
412 
413 	tcu::TestStatus testStatus = tcu::TestStatus::pass("Passed");
414 
415 	// Compare reference data with output data
416 	if (deMemCmp(&referenceData[0], outputData, m_bufferSizeInBytes) != 0)
417 	{
418 		testStatus = tcu::TestStatus::fail("Failed");
419 	}
420 
421 	// Wait for sparse queue to become idle
422 	deviceInterface.queueWaitIdle(sparseQueue.queueHandle);
423 
424 	return testStatus;
425 }
426 
createInstance(Context & context) const427 TestInstance* BufferSparseMemoryAliasingCase::createInstance (Context& context) const
428 {
429 	return new BufferSparseMemoryAliasingInstance(context, m_bufferSizeInBytes);
430 }
431 
432 } // anonymous ns
433 
createBufferSparseMemoryAliasingTests(tcu::TestContext & testCtx)434 tcu::TestCaseGroup* createBufferSparseMemoryAliasingTests (tcu::TestContext& testCtx)
435 {
436 	de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "buffer_sparse_memory_aliasing", "Sparse Buffer Memory Aliasing"));
437 
438 	testGroup->addChild(new BufferSparseMemoryAliasingCase(testCtx, "buffer_size_2_10", "", 1 << 10, glu::GLSL_VERSION_440));
439 	testGroup->addChild(new BufferSparseMemoryAliasingCase(testCtx, "buffer_size_2_12", "", 1 << 12, glu::GLSL_VERSION_440));
440 	testGroup->addChild(new BufferSparseMemoryAliasingCase(testCtx, "buffer_size_2_16", "", 1 << 16, glu::GLSL_VERSION_440));
441 	testGroup->addChild(new BufferSparseMemoryAliasingCase(testCtx, "buffer_size_2_17", "", 1 << 17, glu::GLSL_VERSION_440));
442 	testGroup->addChild(new BufferSparseMemoryAliasingCase(testCtx, "buffer_size_2_20", "", 1 << 20, glu::GLSL_VERSION_440));
443 	testGroup->addChild(new BufferSparseMemoryAliasingCase(testCtx, "buffer_size_2_24", "", 1 << 24, glu::GLSL_VERSION_440));
444 
445 	return testGroup.release();
446 }
447 
448 } // sparse
449 } // vkt
450