• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2018 Google 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
21  * \brief Descriptor set tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "amber/vktAmberTestCase.hpp"
25 #include "vktApiDescriptorSetTests.hpp"
26 #include "vktTestCaseUtil.hpp"
27 #include "vkCmdUtil.hpp"
28 #include "vkMemUtil.hpp"
29 #include "vktApiBufferComputeInstance.hpp"
30 #include "vktApiComputeInstanceResultBuffer.hpp"
31 #include "vkBufferWithMemory.hpp"
32 #include "vkObjUtil.hpp"
33 
34 #include "vkQueryUtil.hpp"
35 #include "vkRefUtil.hpp"
36 #include "vkPrograms.hpp"
37 
38 namespace vkt
39 {
40 namespace api
41 {
42 
43 namespace
44 {
45 
46 using namespace std;
47 using namespace vk;
48 
49 // Descriptor set layout used to create a pipeline layout is destroyed prior to creating a pipeline
createPipelineLayoutDestroyDescriptorSetLayout(Context & context)50 Move<VkPipelineLayout> createPipelineLayoutDestroyDescriptorSetLayout (Context& context)
51 {
52 	const DeviceInterface&					vk							= context.getDeviceInterface();
53 	const VkDevice							device						= context.getDevice();
54 	Unique<VkDescriptorSetLayout>			descriptorSetLayout			(createDescriptorSetLayout(context));
55 
56 	const VkPipelineLayoutCreateInfo		pipelineLayoutCreateInfo	=
57 	{
58 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,			// VkStructureType					sType;
59 		DE_NULL,												// const void*						pNext;
60 		(VkPipelineLayoutCreateFlags)0,							// VkPipelineLayoutCreateFlags		flags;
61 		1u,														// deUint32							setLayoutCount;
62 		&descriptorSetLayout.get(),								// const VkDescriptorSetLayout*		pSetLayouts;
63 		0u,														// deUint32							pushConstantRangeCount;
64 		DE_NULL													// const VkPushConstantRange*		pPushConstantRanges;
65 	};
66 
67 	return createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
68 }
69 
descriptorSetLayoutLifetimeGraphicsTest(Context & context)70 tcu::TestStatus descriptorSetLayoutLifetimeGraphicsTest (Context& context)
71 {
72 	const DeviceInterface&							vk								= context.getDeviceInterface();
73 	const VkDevice									device							= context.getDevice();
74     deUint32					                    queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
75     const VkQueue					                queue				            = context.getUniversalQueue();
76 
77 	Unique<VkPipelineLayout>						pipelineLayout					(createPipelineLayoutDestroyDescriptorSetLayout(context));
78 
79 	const Unique<VkShaderModule>					vertexShaderModule				(createShaderModule(vk, device, context.getBinaryCollection().get("vertex"), 0));
80 
81 	const VkPipelineShaderStageCreateInfo			shaderStageCreateInfo			=
82 	{
83 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType					sType;
84 		DE_NULL,												// const void*						pNext;
85 		(VkPipelineShaderStageCreateFlags)0,					// VkPipelineShaderStageCreateFlags	flags;
86 		VK_SHADER_STAGE_VERTEX_BIT,								// VkShaderStageFlagBits			stage;
87 		vertexShaderModule.get(),								// VkShaderModule					shader;
88 		"main",													// const char*						pName;
89 		DE_NULL,												// const VkSpecializationInfo*		pSpecializationInfo;
90 	};
91 
92 	const VkPipelineVertexInputStateCreateInfo		vertexInputStateCreateInfo		=
93 	{
94 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,	// VkStructureType							sType;
95 		DE_NULL,													// const void*								pNext;
96 		(VkPipelineVertexInputStateCreateFlags)0,					// VkPipelineVertexInputStateCreateFlags	flags;
97 		0u,															// deUint32									vertexBindingDescriptionCount;
98 		DE_NULL,													// const VkVertexInputBindingDescription*	pVertexBindingDescriptions;
99 		0u,															// deUint32									vertexAttributeDescriptionCount;
100 		DE_NULL														// const VkVertexInputAttributeDescription*	pVertexAttributeDescriptions;
101 	};
102 
103 	const VkPipelineInputAssemblyStateCreateInfo	inputAssemblyStateCreateInfo	=
104 	{
105 		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,	// VkStructureType							sType;
106 		DE_NULL,														// const void*								pNext;
107 		(VkPipelineInputAssemblyStateCreateFlags)0,						// VkPipelineInputAssemblyStateCreateFlags	flags;
108 		VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,							// VkPrimitiveTopology						topology;
109 		VK_FALSE														// VkBool32									primitiveRestartEnable;
110 	};
111 
112 	const VkPipelineRasterizationStateCreateInfo	rasterizationStateCreateInfo	=
113 	{
114 		VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,		// VkStructureType							sType;
115 		DE_NULL,														// const void*								pNext;
116 		(VkPipelineRasterizationStateCreateFlags)0,						// VkPipelineRasterizationStateCreateFlags	flags;
117 		VK_FALSE,														// VkBool32									depthClampEnable;
118 		VK_TRUE,														// VkBool32									rasterizerDiscardEnable;
119 		VK_POLYGON_MODE_FILL,											// VkPolygonMode							polygonMode;
120 		VK_CULL_MODE_NONE,												// VkCullModeFlags							cullMode;
121 		VK_FRONT_FACE_CLOCKWISE,										// VkFrontFace								frontFace;
122 		VK_FALSE,														// VkBool32									depthBiasEnable;
123 		0.0f,															// float									depthBiasConstantFactor;
124 		0.0f,															// float									depthBiasClamp;
125 		0.0f,															// float									depthBiasSlopeFactor;
126 		1.0f															// float									lineWidth;
127 	};
128 
129 	const VkSubpassDescription						subpassDescription				=
130 	{
131 		(VkSubpassDescriptionFlags)0,		// VkSubpassDescriptionFlags		flags;
132 		VK_PIPELINE_BIND_POINT_GRAPHICS,	// VkPipelineBindPoint				pipelineBindPoint
133 		0u,									// deUint32							inputAttachmentCount
134 		DE_NULL,							// const VkAttachmentReference*		pInputAttachments
135 		0u,									// deUint32							colorAttachmentCount
136 		DE_NULL,							// const VkAttachmentReference*		pColorAttachments
137 		DE_NULL,							// const VkAttachmentReference*		pResolveAttachments
138 		DE_NULL,							// const VkAttachmentReference*		pDepthStencilAttachment
139 		0u,									// deUint32							preserveAttachmentCount
140 		DE_NULL								// const deUint32*					pPreserveAttachments
141 	};
142 
143 	const VkRenderPassCreateInfo					renderPassCreateInfo			=
144 	{
145 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,		// VkStructureType					sType;
146 		DE_NULL,										// const void*						pNext;
147 		(VkRenderPassCreateFlags)0,						// VkRenderPassCreateFlags			flags;
148 		0u,												// deUint32							attachmentCount
149 		DE_NULL,										// const VkAttachmentDescription*	pAttachments
150 		1u,												// deUint32							subpassCount
151 		&subpassDescription,							// const VkSubpassDescription*		pSubpasses
152 		0u,												// deUint32							dependencyCount
153 		DE_NULL											// const VkSubpassDependency*		pDependencies
154 	};
155 
156 	Unique<VkRenderPass>							renderPass						(createRenderPass(vk, device, &renderPassCreateInfo));
157 
158 	const VkGraphicsPipelineCreateInfo				graphicsPipelineCreateInfo		=
159 	{
160 		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,	// VkStructureType									sType;
161 		DE_NULL,											// const void*										pNext;
162 		(VkPipelineCreateFlags)0,							// VkPipelineCreateFlags							flags;
163 		1u,													// deUint32											stageCount;
164 		&shaderStageCreateInfo,								// const VkPipelineShaderStageCreateInfo*			pStages;
165 		&vertexInputStateCreateInfo,						// const VkPipelineVertexInputStateCreateInfo*		pVertexInputState;
166 		&inputAssemblyStateCreateInfo,						// const VkPipelineInputAssemblyStateCreateInfo*	pInputAssemblyState;
167 		DE_NULL,											// const VkPipelineTessellationStateCreateInfo*		pTessellationState;
168 		DE_NULL,											// const VkPipelineViewportStateCreateInfo*			pViewportState;
169 		&rasterizationStateCreateInfo,						// const VkPipelineRasterizationStateCreateInfo*	pRasterizationState;
170 		DE_NULL,											// const VkPipelineMultisampleStateCreateInfo*		pMultisampleState;
171 		DE_NULL,											// const VkPipelineDepthStencilStateCreateInfo*		pDepthStencilState;
172 		DE_NULL,											// const VkPipelineColorBlendStateCreateInfo*		pColorBlendState;
173 		DE_NULL,											// const VkPipelineDynamicStateCreateInfo*			pDynamicState;
174 		pipelineLayout.get(),								// VkPipelineLayout									layout;
175 		renderPass.get(),									// VkRenderPass										renderPass;
176 		0u,													// deUint32											subpass;
177 		DE_NULL,											// VkPipeline										basePipelineHandle;
178 		0													// int												basePipelineIndex;
179 	};
180 
181 	Unique<VkPipeline>								graphicsPipeline				(createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineCreateInfo));
182 
183 
184 	VkFramebufferCreateInfo framebufferCreateInfo
185 	{
186 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,		// VkStructureType			sType
187 		DE_NULL,										// const void*				pNext
188 		0,												// VkFramebufferCreateFlags	flags
189 		*renderPass,									// VkRenderPass				renderPass
190 		0,												// uint32_t					attachmentCount
191 		DE_NULL,										// const VkImageView*		pAttachments
192 		16,												// uint32_t					width
193 		16,												// uint32_t					height
194 		1												// uint32_t					layers
195 	};
196 
197 	Move <VkFramebuffer> framebuffer = createFramebuffer(vk, device, &framebufferCreateInfo);
198 
199 	const VkCommandPoolCreateInfo cmdPoolInfo			=
200 	{
201 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,		// Stype
202 		DE_NULL,										// PNext
203 		DE_NULL,										// flags
204 		queueFamilyIndex,								// queuefamilyindex
205 	};
206 
207 	const Unique<VkCommandPool>				cmdPool(createCommandPool(vk, device, &cmdPoolInfo));
208 
209 	const VkCommandBufferAllocateInfo		cmdBufParams =
210 	{
211 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,	//	VkStructureType			sType;
212 		DE_NULL,										//	const void*				pNext;
213 		*cmdPool,										//	VkCommandPool			pool;
214 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,				//	VkCommandBufferLevel	level;
215 		1u,												//	uint32_t				bufferCount;
216 	};
217 
218 	const Unique<VkCommandBuffer>			cmdBuf(allocateCommandBuffer(vk, device, &cmdBufParams));
219 
220 	const VkRenderPassBeginInfo renderPassBeginInfo		=
221 	{
222 		VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
223 		DE_NULL,
224 		*renderPass,
225 		*framebuffer,
226 		{{0, 0}, {16, 16}},
227 		0,
228 		DE_NULL
229 	};
230 
231 	beginCommandBuffer(vk, *cmdBuf, 0u);
232 	{
233 		vk.cmdBeginRenderPass(*cmdBuf, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
234 		vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
235 		vk.cmdDraw(*cmdBuf, 3u, 1u, 0, 0);
236 		vk.cmdEndRenderPass(*cmdBuf);
237     }
238     endCommandBuffer(vk, *cmdBuf);
239 
240     submitCommandsAndWait(vk, device, queue, *cmdBuf);
241 
242 	// Test should always pass
243 	return tcu::TestStatus::pass("Pass");
244 }
245 
descriptorSetLayoutLifetimeComputeTest(Context & context)246 tcu::TestStatus descriptorSetLayoutLifetimeComputeTest (Context& context)
247 {
248 	const DeviceInterface&					vk							= context.getDeviceInterface();
249 	const VkDevice							device						= context.getDevice();
250     deUint32					            queueFamilyIndex            = context.getUniversalQueueFamilyIndex();
251     const VkQueue					        queue				        = context.getUniversalQueue();
252     Allocator&								allocator = context.getDefaultAllocator();
253     const ComputeInstanceResultBuffer		result(vk, device, allocator, 0.0f);
254 
255 
256     Unique<VkPipelineLayout>				pipelineLayout				(createPipelineLayoutDestroyDescriptorSetLayout(context));
257 
258 	const Unique<VkShaderModule>			computeShaderModule			(createShaderModule(vk, device, context.getBinaryCollection().get("compute"), 0));
259 
260 	const VkPipelineShaderStageCreateInfo	shaderStageCreateInfo		=
261 	{
262 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType					sType;
263 		DE_NULL,												// const void*						pNext;
264 		(VkPipelineShaderStageCreateFlags)0,					// VkPipelineShaderStageCreateFlags	flags;
265 		VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits			stage;
266 		computeShaderModule.get(),								// VkShaderModule					shader;
267 		"main",													// const char*						pName;
268 		DE_NULL													// const VkSpecializationInfo*		pSpecializationInfo;
269 	};
270 
271 	const VkComputePipelineCreateInfo		computePipelineCreateInfo	=
272 	{
273 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,			// VkStructureType					sType
274 		DE_NULL,												// const void*						pNext
275 		(VkPipelineCreateFlags)0,								// VkPipelineCreateFlags			flags
276 		shaderStageCreateInfo,									// VkPipelineShaderStageCreateInfo	stage
277 		pipelineLayout.get(),									// VkPipelineLayout					layout
278 		DE_NULL,												// VkPipeline						basePipelineHandle
279 		0														// int								basePipelineIndex
280 	};
281 
282 	const deUint32							offset = (0u);
283 	const deUint32							addressableSize = 256;
284 	const deUint32							dataSize = 8;
285 	de::MovePtr<Allocation>					bufferMem;
286 	const Unique<VkBuffer>					buffer						(createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem));
287 	const Unique<VkDescriptorSetLayout>		descriptorSetLayout			(createDescriptorSetLayout(context));
288 	const Unique<VkDescriptorPool>			descriptorPool				(createDescriptorPool(context));
289 	const Unique<VkDescriptorSet>			descriptorSet				(createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer()));
290 
291 	Unique<VkPipeline>						computePipeline				(createComputePipeline(vk, device, DE_NULL, &computePipelineCreateInfo));
292 
293 	const VkCommandPoolCreateInfo cmdPoolInfo				=
294 	{
295 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,				// Stype
296 		DE_NULL,												// PNext
297 		DE_NULL,												// flags
298 		queueFamilyIndex,										// queuefamilyindex
299 	};
300 
301 	const Unique<VkCommandPool>				cmdPool(createCommandPool(vk, device, &cmdPoolInfo));
302 
303 	const VkCommandBufferAllocateInfo		cmdBufParams	=
304 	{
305 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,			//	VkStructureType			sType;
306 		DE_NULL,												//	const void*				pNext;
307 		*cmdPool,												//	VkCommandPool			pool;
308 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,						//	VkCommandBufferLevel	level;
309 		1u,														//	uint32_t				bufferCount;
310 	};
311 
312 	const Unique<VkCommandBuffer>			cmdBuf(allocateCommandBuffer(vk, device, &cmdBufParams));
313 
314 	beginCommandBuffer(vk, *cmdBuf, 0u);
315 	{
316 		vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *computePipeline);
317 		vk.cmdBindDescriptorSets(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, 1u, &*descriptorSet, 0, 0);
318 		vk.cmdDispatch(*cmdBuf, 1u, 1u, 1u);
319 	}
320 	endCommandBuffer(vk, *cmdBuf);
321 
322 	submitCommandsAndWait(vk, device, queue, *cmdBuf);
323 
324 	// Test should always pass
325 	return tcu::TestStatus::pass("Pass");
326 }
327 
emptyDescriptorSetLayoutTest(Context & context,VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags)328 tcu::TestStatus emptyDescriptorSetLayoutTest (Context& context, VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags)
329 {
330 	const DeviceInterface&					vk								= context.getDeviceInterface();
331 	const VkDevice							device							= context.getDevice();
332 
333 #ifndef CTS_USES_VULKANSC
334 	if (descriptorSetLayoutCreateFlags == VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR)
335 		if (!context.isDeviceFunctionalitySupported("VK_KHR_push_descriptor"))
336 			TCU_THROW(NotSupportedError, "VK_KHR_push_descriptor extension not supported");
337 #endif // CTS_USES_VULKANSC
338 
339 	const VkDescriptorSetLayoutCreateInfo	descriptorSetLayoutCreateInfo	=
340 	{
341 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,	// VkStructureType                        sType;
342 		DE_NULL,												// const void*                            pNext;
343 		descriptorSetLayoutCreateFlags,							// VkDescriptorSetLayoutCreateFlags       flags;
344 		0u,														// deUint32                               bindingCount;
345 		DE_NULL													// const VkDescriptorSetLayoutBinding*    pBindings;
346 	};
347 
348 	Unique<VkDescriptorSetLayout>			descriptorSetLayout				(createDescriptorSetLayout(vk, device, &descriptorSetLayoutCreateInfo));
349 
350 	// Test should always pass
351 	return tcu::TestStatus::pass("Pass");
352 }
353 
descriptorSetLayoutBindingOrderingTest(Context & context)354 tcu::TestStatus descriptorSetLayoutBindingOrderingTest (Context& context)
355 {
356 	/*
357 		This test tests that if dstBinding has fewer than
358 		descriptorCount array elements remaining starting from dstArrayElement,
359 		then the remainder will be used to update the subsequent binding.
360 	*/
361 
362 	const DeviceInterface&		vk					= context.getDeviceInterface();
363 	const VkDevice				device				= context.getDevice();
364 	deUint32					queueFamilyIndex	= context.getUniversalQueueFamilyIndex();
365 	const VkQueue				queue				= context.getUniversalQueue();
366 
367 	const Unique<VkShaderModule> computeShaderModule (createShaderModule(vk, device, context.getBinaryCollection().get("compute"), 0));
368 
369 	de::MovePtr<BufferWithMemory> buffer;
370 	buffer			= de::MovePtr<BufferWithMemory>(new BufferWithMemory(vk,
371 																		device,
372 																		context.getDefaultAllocator(),
373 																		makeBufferCreateInfo(4u, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT),
374 																		MemoryRequirement::HostVisible));
375 	deUint32 *bufferPtr = (deUint32 *)buffer->getAllocation().getHostPtr();
376 	*bufferPtr = 5;
377 
378 	de::MovePtr<BufferWithMemory> resultBuffer;
379 	resultBuffer	= de::MovePtr<BufferWithMemory>(new BufferWithMemory(vk,
380 																		device,
381 																		context.getDefaultAllocator(),
382 																		makeBufferCreateInfo(4u * 3, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT),
383 																		MemoryRequirement::HostVisible));
384 
385 	const VkDescriptorBufferInfo	descriptorBufferInfos[]		=
386 	{
387 		{
388 			buffer->get(),		// VkBuffer			buffer
389 			0u,					// VkDeviceSize		offset
390 			VK_WHOLE_SIZE		// VkDeviceSize		range
391 		},
392 		{
393 			buffer->get(),		// VkBuffer			buffer
394 			0u,					// VkDeviceSize		offset
395 			VK_WHOLE_SIZE		// VkDeviceSize		range
396 		},
397 		{
398 			buffer->get(),		// VkBuffer			buffer
399 			0u,					// VkDeviceSize		offset
400 			VK_WHOLE_SIZE		// VkDeviceSize		range
401 		},
402 	};
403 
404 	const VkDescriptorBufferInfo	descriptorBufferInfoResult	=
405 	{
406 		resultBuffer->get(),	// VkBuffer			buffer
407 		0u,						// VkDeviceSize		offset
408 		VK_WHOLE_SIZE			// VkDeviceSize		range
409 	};
410 
411 	const VkDescriptorSetLayoutBinding layoutBindings[] =
412 	{
413 		{
414 			0u,										// deUint32				binding;
415 			VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,		// VkDescriptorType		descriptorType;
416 			2u,										// deUint32				descriptorCount;
417 			VK_SHADER_STAGE_ALL,					// VkShaderStageFlags	stageFlags;
418 			DE_NULL									// const VkSampler*		pImmutableSamplers;
419 		},
420 		{
421 			1u,										// deUint32				binding;
422 			VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,		// VkDescriptorType		descriptorType;
423 			1u,										// deUint32				descriptorCount;
424 			VK_SHADER_STAGE_ALL,					// VkShaderStageFlags	stageFlags;
425 			DE_NULL									// const VkSampler*		pImmutableSamplers;
426 		},
427 		{
428 			2u,										// deUint32				binding;
429 			VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,		// VkDescriptorType		descriptorType;
430 			1u,										// deUint32				descriptorCount;
431 			VK_SHADER_STAGE_ALL,					// VkShaderStageFlags	stageFlags;
432 			DE_NULL									// const VkSampler*		pImmutableSamplers;
433 		}
434 	};
435 
436 	const VkDescriptorSetLayoutCreateInfo	descriptorSetLayoutCreateInfo	=
437 	{
438 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,	// VkStructureType							sType;
439 		DE_NULL,												// const void*								pNext;
440 		0u,														// VkDescriptorSetLayoutCreateFlags			flags;
441 		DE_LENGTH_OF_ARRAY(layoutBindings),						// deUint32									bindingCount;
442 		layoutBindings											// const VkDescriptorSetLayoutBinding*		pBindings;
443 	};
444 
445 	Move<VkDescriptorSetLayout> descriptorSetLayout(createDescriptorSetLayout(vk, device, &descriptorSetLayoutCreateInfo));
446 
447 	const VkDescriptorPoolSize				poolSize[]						=
448 	{
449 		{
450 			VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,			// VkDescriptorType				type
451 			3u											// uint32_t						descriptorCount
452 		},
453 		{
454 			VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,			// VkDescriptorType				type
455 			1u											// uint32_t						descriptorCount
456 		}
457 	};
458 
459 	const VkDescriptorPoolCreateInfo		descriptorPoolCreateInfo		=
460 	{
461 		VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,	// VkStructureType				sType
462 		DE_NULL,										// const void*					pNext
463 		0u,												// VkDescriptorPoolCreateFlags	flags
464 		1u,												// uint32_t						maxSets
465 		2u,												// uint32_t						poolSizeCount
466 		poolSize										// const VkDescriptorPoolSize*	pPoolSizes
467 	};
468 
469 	Move<VkDescriptorPool> descriptorPool(createDescriptorPool(vk, device, &descriptorPoolCreateInfo));
470 
471 	VkDescriptorSet descriptorSet;
472 	{
473 		const VkDescriptorSetAllocateInfo allocInfo =
474 		{
475 			VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,		// VkStructure						sType
476 			DE_NULL,											// const void*						pNext
477 			*descriptorPool,									// VkDescriptorPool					descriptorPool
478 			1u,													// uint32_t							descriptorSetCount
479 			&*descriptorSetLayout								// const VkDescriptorSetLayout*		pSetLayouts
480 		};
481 
482 		VK_CHECK(vk.allocateDescriptorSets(device, &allocInfo, &descriptorSet));
483 	}
484 
485 	const VkWriteDescriptorSet				descriptorWrite			=
486 	{
487 		VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,					// VkStructureType					sType
488 		DE_NULL,												// const void*						pNext
489 		descriptorSet,											// VkDescriptorSet					dstSet
490 		0u,														// deUint32							dstBinding
491 		0u,														// deUint32							dstArrayElement
492 		3u,														// deUint32							descriptorCount
493 		VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,						// VkDescriptorType					descriptorType
494 		DE_NULL,												// const VkDescriptorImageInfo		pImageInfo
495 		descriptorBufferInfos,									// const VkDescriptorBufferInfo*	pBufferInfo
496 		DE_NULL													// const VkBufferView*				pTexelBufferView
497 	};
498 
499 	const VkWriteDescriptorSet				descriptorWriteResult	=
500 	{
501 		VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,					// VkStructureType					sType
502 		DE_NULL,												// const void*						pNext
503 		descriptorSet,											// VkDescriptorSet					dstSet
504 		2u,														// deUint32							dstBinding
505 		0u,														// deUint32							dstArrayElement
506 		1u,														// deUint32							descriptorCount
507 		VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,						// VkDescriptorType					descriptorType
508 		DE_NULL,												// const VkDescriptorImageInfo		pImageInfo
509 		&descriptorBufferInfoResult,							// const VkDescriptorBufferInfo*	pBufferInfo
510 		DE_NULL													// const VkBufferView*				pTexelBufferView
511 	};
512 
513 	const VkCommandPoolCreateInfo			cmdPoolInfo				=
514 	{
515 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,				// VkStructureType					Stype
516 		DE_NULL,												// const void*						PNext
517 		DE_NULL,												// VkCommandPoolCreateFlags			flags
518 		queueFamilyIndex,										// uint32_t							queuefamilyindex
519 	};
520 
521 	const Unique<VkCommandPool>				cmdPool(createCommandPool(vk, device, &cmdPoolInfo));
522 
523 	const VkCommandBufferAllocateInfo		cmdBufParams			=
524 	{
525 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,			// VkStructureType					sType;
526 		DE_NULL,												// const void*						pNext;
527 		*cmdPool,												// VkCommandPool					pool;
528 		VK_COMMAND_BUFFER_LEVEL_PRIMARY,						// VkCommandBufferLevel				level;
529 		1u,														// uint32_t							bufferCount;
530 	};
531 
532 	const Unique<VkCommandBuffer>			cmdBuf(allocateCommandBuffer(vk, device, &cmdBufParams));
533 
534 	const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
535 	{
536 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,			// VkStructureType					sType
537 		DE_NULL,												// const void*						pNext
538 		0,														// VkPipelineLayoutCreateFlags		flags
539 		1u,														// uint32_t							setLayoutCount
540 		&*descriptorSetLayout,									// const VkDescriptorSetLayout*		pSetLayouts
541 		0u,														// uint32_t							pushConstantRangeCount
542 		nullptr													// const VkPushConstantRange*		pPushConstantRanges
543 	};
544 
545 	Move<VkPipelineLayout> pipelineLayout(createPipelineLayout(vk, device, &pipelineLayoutCreateInfo));
546 
547 	const VkPipelineShaderStageCreateInfo	shaderStageCreateInfo		=
548 	{
549 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType					sType;
550 		DE_NULL,												// const void*						pNext;
551 		(VkPipelineShaderStageCreateFlags)0,					// VkPipelineShaderStageCreateFlags	flags;
552 		VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits			stage;
553 		computeShaderModule.get(),								// VkShaderModule					shader;
554 		"main",													// const char*						pName;
555 		DE_NULL													// const VkSpecializationInfo*		pSpecializationInfo;
556 	};
557 
558 	const VkComputePipelineCreateInfo		computePipelineCreateInfo	=
559 	{
560 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,			// VkStructureType					sType
561 		DE_NULL,												// const void*						pNext
562 		(VkPipelineCreateFlags)0,								// VkPipelineCreateFlags			flags
563 		shaderStageCreateInfo,									// VkPipelineShaderStageCreateInfo	stage
564 		*pipelineLayout,										// VkPipelineLayout					layout
565 		DE_NULL,												// VkPipeline						basePipelineHandle
566 		0														// int								basePipelineIndex
567 	};
568 
569 	Unique<VkPipeline> computePipeline(createComputePipeline(vk, device, DE_NULL, &computePipelineCreateInfo));
570 
571 	beginCommandBuffer(vk, *cmdBuf, 0u);
572 	{
573 		vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *computePipeline);
574 		vk.updateDescriptorSets(device, 1u, &descriptorWrite, 0u, DE_NULL);
575 		vk.updateDescriptorSets(device, 1u, &descriptorWriteResult, 0u, DE_NULL);
576 		vk.cmdBindDescriptorSets(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, 1u, &descriptorSet, 0, nullptr);
577 		flushAlloc(vk, device, buffer->getAllocation());
578 		vk.cmdDispatch(*cmdBuf, 1u, 1u, 1u);
579 	}
580 
581 	endCommandBuffer(vk, *cmdBuf);
582 	submitCommandsAndWait(vk, device, queue, *cmdBuf);
583 
584 	const Allocation& bufferAllocationResult = resultBuffer->getAllocation();
585 	invalidateAlloc(vk, device, bufferAllocationResult);
586 
587 	const deUint32* resultPtr = static_cast<deUint32*>(bufferAllocationResult.getHostPtr());
588 
589 	if (resultPtr[0] == 5 && resultPtr[1] == 5 && resultPtr[2] == 5)
590 		return tcu::TestStatus::pass("Pass");
591 	else
592 		return tcu::TestStatus::fail("Fail");
593 }
594 } // anonymous
595 
createDescriptorSetLayoutLifetimeGraphicsSource(SourceCollections & dst)596 void createDescriptorSetLayoutLifetimeGraphicsSource (SourceCollections& dst)
597 {
598 	dst.glslSources.add("vertex") << glu::VertexSource(
599 		"#version 310 es\n"
600 		"void main (void)\n"
601 		"{\n"
602 		"    gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
603 		"}\n");
604 }
605 
createDescriptorSetLayoutLifetimeComputeSource(SourceCollections & dst)606 void createDescriptorSetLayoutLifetimeComputeSource (SourceCollections& dst)
607 {
608 	dst.glslSources.add("compute") << glu::ComputeSource(
609 		"#version 310 es\n"
610 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
611 		"void main (void)\n"
612 		"{\n"
613 		"}\n");
614 }
615 
createDescriptorSetLayoutBindingOrderingSource(SourceCollections & dst)616 void createDescriptorSetLayoutBindingOrderingSource (SourceCollections& dst)
617 {
618 	dst.glslSources.add("compute") << glu::ComputeSource(
619 		"#version 310 es\n"
620 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
621 		"layout (set = 0, binding = 0) uniform UniformBuffer0 {\n"
622 		"	int data;\n"
623 		"} uniformbufferarray[2];\n"
624 		"layout (set = 0, binding = 1) uniform UniformBuffer2 {\n"
625 		"	int data;\n"
626 		"} uniformbuffer2;\n"
627 		"layout (set = 0, binding = 2) buffer StorageBuffer {\n"
628 		"	int result0;\n"
629 		"	int result1;\n"
630 		"	int result2;\n"
631 		"} results;\n"
632 		"\n"
633 		"void main (void)\n"
634 		"{\n"
635 		"	results.result0 = uniformbufferarray[0].data;\n"
636 		"	results.result1 = uniformbufferarray[1].data;\n"
637 		"	results.result2 = uniformbuffer2.data;\n"
638 		"}\n");
639 }
640 
createDescriptorSetLayoutLifetimeTests(tcu::TestContext & testCtx)641 tcu::TestCaseGroup* createDescriptorSetLayoutLifetimeTests (tcu::TestContext& testCtx)
642 {
643 	de::MovePtr<tcu::TestCaseGroup> descriptorSetLayoutLifetimeTests(new tcu::TestCaseGroup(testCtx, "descriptor_set_layout_lifetime", "Descriptor set layout lifetime tests"));
644 
645 	addFunctionCaseWithPrograms(descriptorSetLayoutLifetimeTests.get(), "graphics", "Test descriptor set layout lifetime in graphics pipeline", createDescriptorSetLayoutLifetimeGraphicsSource, descriptorSetLayoutLifetimeGraphicsTest);
646 	addFunctionCaseWithPrograms(descriptorSetLayoutLifetimeTests.get(), "compute", "Test descriptor set layout lifetime in compute pipeline", createDescriptorSetLayoutLifetimeComputeSource,  descriptorSetLayoutLifetimeComputeTest);
647 
648 	return descriptorSetLayoutLifetimeTests.release();
649 }
650 
createEmptyDescriptorSetLayoutTests(tcu::TestContext & testCtx)651 tcu::TestCaseGroup* createEmptyDescriptorSetLayoutTests (tcu::TestContext& testCtx)
652 {
653 	de::MovePtr<tcu::TestCaseGroup> emptyDescriptorSetLayoutTests(new tcu::TestCaseGroup(testCtx, "empty_set", "Create empty descriptor set layout tests"));
654 
655 	addFunctionCase(emptyDescriptorSetLayoutTests.get(), "normal", "Create empty desciptor set layout", emptyDescriptorSetLayoutTest, (VkDescriptorSetLayoutCreateFlags)0u);
656 #ifndef CTS_USES_VULKANSC
657 	// Removed from Vulkan SC test set: VK_KHR_push_descriptor extension removed from Vulkan SC
658 	addFunctionCase(emptyDescriptorSetLayoutTests.get(), "push_descriptor", "Create empty push descriptor set layout", emptyDescriptorSetLayoutTest, (VkDescriptorSetLayoutCreateFlags)VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
659 #endif // CTS_USES_VULKANSC
660 	return emptyDescriptorSetLayoutTests.release();
661 }
662 
createDescriptorSetLayoutBindingOrderingTests(tcu::TestContext & testCtx)663 tcu::TestCaseGroup* createDescriptorSetLayoutBindingOrderingTests (tcu::TestContext& testCtx)
664 {
665 	de::MovePtr<tcu::TestCaseGroup> descriptorSetLayoutBindingOrderingTests(new tcu::TestCaseGroup(testCtx, "descriptor_set_layout_binding", "Create descriptor set layout ordering tests"));
666 	addFunctionCaseWithPrograms(descriptorSetLayoutBindingOrderingTests.get(), "update_subsequent_binding", "Test subsequent binding update with remaining elements", createDescriptorSetLayoutBindingOrderingSource, descriptorSetLayoutBindingOrderingTest);
667 
668 #ifndef CTS_USES_VULKANSC
669 	static const char dataDir[] = "api/descriptor_set/descriptor_set_layout_binding";
670 	descriptorSetLayoutBindingOrderingTests->addChild(cts_amber::createAmberTestCase(testCtx, "layout_binding_order", "Test descriptor set layout binding order", dataDir, "layout_binding_order.amber"));
671 #endif // CTS_USES_VULKANSC
672 
673 	return descriptorSetLayoutBindingOrderingTests.release();
674 }
675 
createDescriptorSetLayoutTests(tcu::TestContext & testCtx)676 tcu::TestCaseGroup* createDescriptorSetLayoutTests (tcu::TestContext& testCtx)
677 {
678 	de::MovePtr<tcu::TestCaseGroup> descriptorSetLayoutTests(new tcu::TestCaseGroup(testCtx, "descriptor_set_layout", "Descriptor set layout tests"));
679 
680 	descriptorSetLayoutTests->addChild(createEmptyDescriptorSetLayoutTests(testCtx));
681 
682 	return descriptorSetLayoutTests.release();
683 }
684 
createDescriptorSetTests(tcu::TestContext & testCtx)685 tcu::TestCaseGroup* createDescriptorSetTests (tcu::TestContext& testCtx)
686 {
687 	de::MovePtr<tcu::TestCaseGroup> descriptorSetTests(new tcu::TestCaseGroup(testCtx, "descriptor_set", "Descriptor set tests"));
688 
689 	descriptorSetTests->addChild(createDescriptorSetLayoutLifetimeTests(testCtx));
690 	descriptorSetTests->addChild(createDescriptorSetLayoutTests(testCtx));
691 	descriptorSetTests->addChild(createDescriptorSetLayoutBindingOrderingTests(testCtx));
692 
693 	return descriptorSetTests.release();
694 }
695 
696 } // api
697 } // vkt
698