• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
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 Utilities for creating commonly used Vulkan objects
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vkDefs.hpp"
25 #include "vkRefUtil.hpp"
26 #include "vkImageUtil.hpp"
27 #include "vkObjUtil.hpp"
28 #include "vkTypeUtil.hpp"
29 #include "vkQueryUtil.hpp"
30 
31 #include "tcuVector.hpp"
32 
33 #include "deSTLUtil.hpp"
34 
35 #include <algorithm>
36 
37 namespace vk
38 {
39 
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkPipelineCreateFlags pipelineFlags,const void * pipelinePNext,const VkShaderModule shaderModule,const VkPipelineShaderStageCreateFlags shaderFlags,const VkSpecializationInfo * specializationInfo,const VkPipelineCache pipelineCache,const uint32_t subgroupSize)40 Move<VkPipeline> makeComputePipeline (const DeviceInterface&					vk,
41 									  const VkDevice							device,
42 									  const VkPipelineLayout					pipelineLayout,
43 									  const VkPipelineCreateFlags				pipelineFlags,
44 									  const void*								pipelinePNext,
45 									  const VkShaderModule						shaderModule,
46 									  const VkPipelineShaderStageCreateFlags	shaderFlags,
47 									  const VkSpecializationInfo*				specializationInfo,
48 									  const VkPipelineCache						pipelineCache,
49 									  const uint32_t							subgroupSize)
50 {
51 	const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT subgroupSizeCreateInfo =
52 	{
53 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT,	// VkStructureType	sType;
54 		DE_NULL,																		// void*			pNext;
55 		subgroupSize																	// uint32_t			requiredSubgroupSize;
56 	};
57 	const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
58 	{
59 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType						sType;
60 		subgroupSize != 0 ? &subgroupSizeCreateInfo : nullptr,	// const void*							pNext;
61 		shaderFlags,											// VkPipelineShaderStageCreateFlags		flags;
62 		VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits				stage;
63 		shaderModule,											// VkShaderModule						module;
64 		"main",													// const char*							pName;
65 		specializationInfo,										// const VkSpecializationInfo*			pSpecializationInfo;
66 	};
67 	const VkComputePipelineCreateInfo pipelineCreateInfo =
68 	{
69 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,		// VkStructureType					sType;
70 		pipelinePNext,										// const void*						pNext;
71 		pipelineFlags,										// VkPipelineCreateFlags			flags;
72 		pipelineShaderStageParams,							// VkPipelineShaderStageCreateInfo	stage;
73 		pipelineLayout,										// VkPipelineLayout					layout;
74 		DE_NULL,											// VkPipeline						basePipelineHandle;
75 		0,													// deInt32							basePipelineIndex;
76 	};
77 	return createComputePipeline(vk, device, pipelineCache, &pipelineCreateInfo);
78 }
79 
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule shaderModule)80 Move<VkPipeline> makeComputePipeline (const DeviceInterface&	vk,
81 									  const VkDevice			device,
82 									  const VkPipelineLayout	pipelineLayout,
83 									  const VkShaderModule		shaderModule)
84 {
85 	return makeComputePipeline(vk,
86 							   device,
87 							   pipelineLayout,
88 							   static_cast<VkPipelineCreateFlags>(0u),
89 							   DE_NULL,
90 							   shaderModule,
91 							   static_cast<VkPipelineShaderStageCreateFlags>(0u),
92 							   DE_NULL);
93 }
94 
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule vertexShaderModule,const VkShaderModule tessellationControlShaderModule,const VkShaderModule tessellationEvalShaderModule,const VkShaderModule geometryShaderModule,const VkShaderModule fragmentShaderModule,const VkRenderPass renderPass,const std::vector<VkViewport> & viewports,const std::vector<VkRect2D> & scissors,const VkPrimitiveTopology topology,const deUint32 subpass,const deUint32 patchControlPoints,const VkPipelineVertexInputStateCreateInfo * vertexInputStateCreateInfo,const VkPipelineRasterizationStateCreateInfo * rasterizationStateCreateInfo,const VkPipelineMultisampleStateCreateInfo * multisampleStateCreateInfo,const VkPipelineDepthStencilStateCreateInfo * depthStencilStateCreateInfo,const VkPipelineColorBlendStateCreateInfo * colorBlendStateCreateInfo,const VkPipelineDynamicStateCreateInfo * dynamicStateCreateInfo,const void * pNext,const VkPipelineCreateFlags pipelineCreateFlags)95 Move<VkPipeline> makeGraphicsPipeline(const DeviceInterface&						vk,
96 									  const VkDevice								device,
97 									  const VkPipelineLayout						pipelineLayout,
98 									  const VkShaderModule							vertexShaderModule,
99 									  const VkShaderModule							tessellationControlShaderModule,
100 									  const VkShaderModule							tessellationEvalShaderModule,
101 									  const VkShaderModule							geometryShaderModule,
102 									  const VkShaderModule							fragmentShaderModule,
103 									  const VkRenderPass							renderPass,
104 									  const std::vector<VkViewport>&				viewports,
105 									  const std::vector<VkRect2D>&					scissors,
106 									  const VkPrimitiveTopology						topology,
107 									  const deUint32								subpass,
108 									  const deUint32								patchControlPoints,
109 									  const VkPipelineVertexInputStateCreateInfo*	vertexInputStateCreateInfo,
110 									  const VkPipelineRasterizationStateCreateInfo*	rasterizationStateCreateInfo,
111 									  const VkPipelineMultisampleStateCreateInfo*	multisampleStateCreateInfo,
112 									  const VkPipelineDepthStencilStateCreateInfo*	depthStencilStateCreateInfo,
113 									  const VkPipelineColorBlendStateCreateInfo*	colorBlendStateCreateInfo,
114 									  const VkPipelineDynamicStateCreateInfo*		dynamicStateCreateInfo,
115 									  const void*									pNext,
116 									  const VkPipelineCreateFlags					pipelineCreateFlags)
117 {
118 	const VkPipelineInputAssemblyStateCreateInfo	inputAssemblyStateCreateInfo		=
119 	{
120 		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,	// VkStructureType                            sType
121 		DE_NULL,														// const void*                                pNext
122 		0u,																// VkPipelineInputAssemblyStateCreateFlags    flags
123 		topology,														// VkPrimitiveTopology                        topology
124 		VK_FALSE														// VkBool32                                   primitiveRestartEnable
125 	};
126 
127 	const VkPipelineTessellationStateCreateInfo		tessStateCreateInfo					=
128 	{
129 		VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,	// VkStructureType                           sType
130 		DE_NULL,													// const void*                               pNext
131 		0u,															// VkPipelineTessellationStateCreateFlags    flags
132 		patchControlPoints											// deUint32                                  patchControlPoints
133 	};
134 
135 	const VkPipelineViewportStateCreateInfo			viewportStateCreateInfo				=
136 	{
137 		VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,	// VkStructureType                             sType
138 		DE_NULL,												// const void*                                 pNext
139 		(VkPipelineViewportStateCreateFlags)0,					// VkPipelineViewportStateCreateFlags          flags
140 		viewports.empty() ? 1u : (deUint32)viewports.size(),	// deUint32                                    viewportCount
141 		viewports.empty() ? DE_NULL : &viewports[0],			// const VkViewport*                           pViewports
142 		viewports.empty() ? 1u : (deUint32)scissors.size(),		// deUint32                                    scissorCount
143 		scissors.empty() ? DE_NULL : &scissors[0]				// const VkRect2D*                             pScissors
144 	};
145 
146 	std::vector<VkDynamicState>						dynamicStates;
147 
148 	if (viewports.empty())
149 		dynamicStates.push_back(VK_DYNAMIC_STATE_VIEWPORT);
150 	if (scissors.empty())
151 		dynamicStates.push_back(VK_DYNAMIC_STATE_SCISSOR);
152 
153 	const VkPipelineDynamicStateCreateInfo			dynamicStateCreateInfoDefault		=
154 	{
155 		VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,	// VkStructureType                      sType
156 		DE_NULL,												// const void*                          pNext
157 		0u,														// VkPipelineDynamicStateCreateFlags    flags
158 		(deUint32)dynamicStates.size(),							// deUint32                             dynamicStateCount
159 		dynamicStates.empty() ? DE_NULL : &dynamicStates[0]		// const VkDynamicState*                pDynamicStates
160 	};
161 
162 	const VkPipelineDynamicStateCreateInfo*			dynamicStateCreateInfoDefaultPtr	= dynamicStates.empty() ? DE_NULL : &dynamicStateCreateInfoDefault;
163 
164 	return makeGraphicsPipeline (vk, device, pipelineLayout, vertexShaderModule, tessellationControlShaderModule,
165 								 tessellationEvalShaderModule, geometryShaderModule, fragmentShaderModule,
166 								 renderPass, subpass, vertexInputStateCreateInfo, &inputAssemblyStateCreateInfo,
167 								 &tessStateCreateInfo, &viewportStateCreateInfo, rasterizationStateCreateInfo,
168 								 multisampleStateCreateInfo, depthStencilStateCreateInfo, colorBlendStateCreateInfo,
169 								 dynamicStateCreateInfo ? dynamicStateCreateInfo : dynamicStateCreateInfoDefaultPtr,
170 								 pNext, pipelineCreateFlags);
171 }
172 
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule vertexShaderModule,const VkShaderModule tessellationControlShaderModule,const VkShaderModule tessellationEvalShaderModule,const VkShaderModule geometryShaderModule,const VkShaderModule fragmentShaderModule,const VkRenderPass renderPass,const deUint32 subpass,const VkPipelineVertexInputStateCreateInfo * vertexInputStateCreateInfo,const VkPipelineInputAssemblyStateCreateInfo * inputAssemblyStateCreateInfo,const VkPipelineTessellationStateCreateInfo * tessStateCreateInfo,const VkPipelineViewportStateCreateInfo * viewportStateCreateInfo,const VkPipelineRasterizationStateCreateInfo * rasterizationStateCreateInfo,const VkPipelineMultisampleStateCreateInfo * multisampleStateCreateInfo,const VkPipelineDepthStencilStateCreateInfo * depthStencilStateCreateInfo,const VkPipelineColorBlendStateCreateInfo * colorBlendStateCreateInfo,const VkPipelineDynamicStateCreateInfo * dynamicStateCreateInfo,const void * pNext,const VkPipelineCreateFlags pipelineCreateFlags)173 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&							vk,
174 									   const VkDevice									device,
175 									   const VkPipelineLayout							pipelineLayout,
176 									   const VkShaderModule								vertexShaderModule,
177 									   const VkShaderModule								tessellationControlShaderModule,
178 									   const VkShaderModule								tessellationEvalShaderModule,
179 									   const VkShaderModule								geometryShaderModule,
180 									   const VkShaderModule								fragmentShaderModule,
181 									   const VkRenderPass								renderPass,
182 									   const deUint32									subpass,
183 									   const VkPipelineVertexInputStateCreateInfo*		vertexInputStateCreateInfo,
184 									   const VkPipelineInputAssemblyStateCreateInfo*	inputAssemblyStateCreateInfo,
185 									   const VkPipelineTessellationStateCreateInfo*		tessStateCreateInfo,
186 									   const VkPipelineViewportStateCreateInfo*			viewportStateCreateInfo,
187 									   const VkPipelineRasterizationStateCreateInfo*	rasterizationStateCreateInfo,
188 									   const VkPipelineMultisampleStateCreateInfo*		multisampleStateCreateInfo,
189 									   const VkPipelineDepthStencilStateCreateInfo*		depthStencilStateCreateInfo,
190 									   const VkPipelineColorBlendStateCreateInfo*		colorBlendStateCreateInfo,
191 									   const VkPipelineDynamicStateCreateInfo*			dynamicStateCreateInfo,
192 									   const void*										pNext,
193 									   const VkPipelineCreateFlags						pipelineCreateFlags)
194 {
195 	DE_ASSERT(tessStateCreateInfo || (tessellationControlShaderModule == DE_NULL && tessellationEvalShaderModule == DE_NULL));
196 
197 	const VkBool32									disableRasterization				= (fragmentShaderModule == DE_NULL);
198 
199 	VkPipelineShaderStageCreateInfo					stageCreateInfo						=
200 	{
201 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType                     sType
202 		DE_NULL,												// const void*                         pNext
203 		0u,														// VkPipelineShaderStageCreateFlags    flags
204 		VK_SHADER_STAGE_VERTEX_BIT,								// VkShaderStageFlagBits               stage
205 		DE_NULL,												// VkShaderModule                      module
206 		"main",													// const char*                         pName
207 		DE_NULL													// const VkSpecializationInfo*         pSpecializationInfo
208 	};
209 
210 	std::vector<VkPipelineShaderStageCreateInfo>	pipelineShaderStageParams;
211 
212 	{
213 		stageCreateInfo.stage	= VK_SHADER_STAGE_VERTEX_BIT;
214 		stageCreateInfo.module	= vertexShaderModule;
215 		pipelineShaderStageParams.push_back(stageCreateInfo);
216 	}
217 
218 	if (tessellationControlShaderModule != DE_NULL)
219 	{
220 		stageCreateInfo.stage	= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
221 		stageCreateInfo.module	= tessellationControlShaderModule;
222 		pipelineShaderStageParams.push_back(stageCreateInfo);
223 	}
224 
225 	if (tessellationEvalShaderModule != DE_NULL)
226 	{
227 		stageCreateInfo.stage	= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
228 		stageCreateInfo.module	= tessellationEvalShaderModule;
229 		pipelineShaderStageParams.push_back(stageCreateInfo);
230 	}
231 
232 	if (geometryShaderModule != DE_NULL)
233 	{
234 		stageCreateInfo.stage	= VK_SHADER_STAGE_GEOMETRY_BIT;
235 		stageCreateInfo.module	= geometryShaderModule;
236 		pipelineShaderStageParams.push_back(stageCreateInfo);
237 	}
238 
239 	if (fragmentShaderModule != DE_NULL)
240 	{
241 		stageCreateInfo.stage	= VK_SHADER_STAGE_FRAGMENT_BIT;
242 		stageCreateInfo.module	= fragmentShaderModule;
243 		pipelineShaderStageParams.push_back(stageCreateInfo);
244 	}
245 
246 	const VkVertexInputBindingDescription			vertexInputBindingDescription		=
247 	{
248 		0u,								// deUint32             binding
249 		sizeof(tcu::Vec4),				// deUint32             stride
250 		VK_VERTEX_INPUT_RATE_VERTEX,	// VkVertexInputRate    inputRate
251 	};
252 
253 	const VkVertexInputAttributeDescription			vertexInputAttributeDescription		=
254 	{
255 		0u,								// deUint32    location
256 		0u,								// deUint32    binding
257 		VK_FORMAT_R32G32B32A32_SFLOAT,	// VkFormat    format
258 		0u								// deUint32    offset
259 	};
260 
261 	const VkPipelineVertexInputStateCreateInfo		vertexInputStateCreateInfoDefault	=
262 	{
263 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,	// VkStructureType                             sType
264 		DE_NULL,													// const void*                                 pNext
265 		(VkPipelineVertexInputStateCreateFlags)0,					// VkPipelineVertexInputStateCreateFlags       flags
266 		1u,															// deUint32                                    vertexBindingDescriptionCount
267 		&vertexInputBindingDescription,								// const VkVertexInputBindingDescription*      pVertexBindingDescriptions
268 		1u,															// deUint32                                    vertexAttributeDescriptionCount
269 		&vertexInputAttributeDescription							// const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions
270 	};
271 
272 	const VkPipelineInputAssemblyStateCreateInfo	inputAssemblyStateCreateInfoDefault	=
273 	{
274 		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,	// VkStructureType                            sType
275 		DE_NULL,														// const void*                                pNext
276 		0u,																// VkPipelineInputAssemblyStateCreateFlags    flags
277 		VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,							// VkPrimitiveTopology                        topology
278 		VK_FALSE														// VkBool32                                   primitiveRestartEnable
279 	};
280 
281 	const VkViewport								viewport							= makeViewport(256, 256);
282 	const VkRect2D									scissor								= makeRect2D(256, 256);
283 
284 	const VkPipelineViewportStateCreateInfo			viewportStateCreateInfoDefault		=
285 	{
286 		VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,	// VkStructureType                             sType
287 		DE_NULL,												// const void*                                 pNext
288 		(VkPipelineViewportStateCreateFlags)0,					// VkPipelineViewportStateCreateFlags          flags
289 		1u,														// deUint32                                    viewportCount
290 		&viewport,												// const VkViewport*                           pViewports
291 		1u,														// deUint32                                    scissorCount
292 		&scissor												// const VkRect2D*                             pScissors
293 	};
294 
295 	const VkPipelineRasterizationStateCreateInfo	rasterizationStateCreateInfoDefault	=
296 	{
297 		VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,	// VkStructureType                            sType
298 		DE_NULL,													// const void*                                pNext
299 		0u,															// VkPipelineRasterizationStateCreateFlags    flags
300 		VK_FALSE,													// VkBool32                                   depthClampEnable
301 		disableRasterization,										// VkBool32                                   rasterizerDiscardEnable
302 		VK_POLYGON_MODE_FILL,										// VkPolygonMode                              polygonMode
303 		VK_CULL_MODE_NONE,											// VkCullModeFlags                            cullMode
304 		VK_FRONT_FACE_COUNTER_CLOCKWISE,							// VkFrontFace                                frontFace
305 		VK_FALSE,													// VkBool32                                   depthBiasEnable
306 		0.0f,														// float                                      depthBiasConstantFactor
307 		0.0f,														// float                                      depthBiasClamp
308 		0.0f,														// float                                      depthBiasSlopeFactor
309 		1.0f														// float                                      lineWidth
310 	};
311 
312 	const VkPipelineMultisampleStateCreateInfo		multisampleStateCreateInfoDefault	=
313 	{
314 		VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,	// VkStructureType                          sType
315 		DE_NULL,													// const void*                              pNext
316 		0u,															// VkPipelineMultisampleStateCreateFlags    flags
317 		VK_SAMPLE_COUNT_1_BIT,										// VkSampleCountFlagBits                    rasterizationSamples
318 		VK_FALSE,													// VkBool32                                 sampleShadingEnable
319 		1.0f,														// float                                    minSampleShading
320 		DE_NULL,													// const VkSampleMask*                      pSampleMask
321 		VK_FALSE,													// VkBool32                                 alphaToCoverageEnable
322 		VK_FALSE													// VkBool32                                 alphaToOneEnable
323 	};
324 
325 	const VkStencilOpState							stencilOpState						=
326 	{
327 		VK_STENCIL_OP_KEEP,		// VkStencilOp    failOp
328 		VK_STENCIL_OP_KEEP,		// VkStencilOp    passOp
329 		VK_STENCIL_OP_KEEP,		// VkStencilOp    depthFailOp
330 		VK_COMPARE_OP_NEVER,	// VkCompareOp    compareOp
331 		0,						// deUint32       compareMask
332 		0,						// deUint32       writeMask
333 		0						// deUint32       reference
334 	};
335 
336 	const VkPipelineDepthStencilStateCreateInfo		depthStencilStateCreateInfoDefault	=
337 	{
338 		VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,	// VkStructureType                          sType
339 		DE_NULL,													// const void*                              pNext
340 		0u,															// VkPipelineDepthStencilStateCreateFlags   flags
341 		VK_FALSE,													// VkBool32                                 depthTestEnable
342 		VK_FALSE,													// VkBool32                                 depthWriteEnable
343 		VK_COMPARE_OP_LESS_OR_EQUAL,								// VkCompareOp                              depthCompareOp
344 		VK_FALSE,													// VkBool32                                 depthBoundsTestEnable
345 		VK_FALSE,													// VkBool32                                 stencilTestEnable
346 		stencilOpState,												// VkStencilOpState                         front
347 		stencilOpState,												// VkStencilOpState                         back
348 		0.0f,														// float                                    minDepthBounds
349 		1.0f,														// float                                    maxDepthBounds
350 	};
351 
352 	const VkPipelineColorBlendAttachmentState		colorBlendAttachmentState			=
353 	{
354 		VK_FALSE,					// VkBool32                 blendEnable
355 		VK_BLEND_FACTOR_ZERO,		// VkBlendFactor            srcColorBlendFactor
356 		VK_BLEND_FACTOR_ZERO,		// VkBlendFactor            dstColorBlendFactor
357 		VK_BLEND_OP_ADD,			// VkBlendOp                colorBlendOp
358 		VK_BLEND_FACTOR_ZERO,		// VkBlendFactor            srcAlphaBlendFactor
359 		VK_BLEND_FACTOR_ZERO,		// VkBlendFactor            dstAlphaBlendFactor
360 		VK_BLEND_OP_ADD,			// VkBlendOp                alphaBlendOp
361 		VK_COLOR_COMPONENT_R_BIT	// VkColorComponentFlags    colorWriteMask
362 		| VK_COLOR_COMPONENT_G_BIT
363 		| VK_COLOR_COMPONENT_B_BIT
364 		| VK_COLOR_COMPONENT_A_BIT
365 	};
366 
367 	const VkPipelineColorBlendStateCreateInfo		colorBlendStateCreateInfoDefault	=
368 	{
369 		VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,	// VkStructureType                               sType
370 		DE_NULL,													// const void*                                   pNext
371 		0u,															// VkPipelineColorBlendStateCreateFlags          flags
372 		VK_FALSE,													// VkBool32                                      logicOpEnable
373 		VK_LOGIC_OP_CLEAR,											// VkLogicOp                                     logicOp
374 		1u,															// deUint32                                      attachmentCount
375 		&colorBlendAttachmentState,									// const VkPipelineColorBlendAttachmentState*    pAttachments
376 		{ 0.0f, 0.0f, 0.0f, 0.0f }									// float                                         blendConstants[4]
377 	};
378 
379 	const VkGraphicsPipelineCreateInfo				pipelineCreateInfo					=
380 	{
381 		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,														// VkStructureType                                  sType
382 		pNext,																									// const void*                                      pNext
383 		pipelineCreateFlags,																					// VkPipelineCreateFlags                            flags
384 		(deUint32)pipelineShaderStageParams.size(),																// deUint32                                         stageCount
385 		&pipelineShaderStageParams[0],																			// const VkPipelineShaderStageCreateInfo*           pStages
386 		vertexInputStateCreateInfo ? vertexInputStateCreateInfo : &vertexInputStateCreateInfoDefault,			// const VkPipelineVertexInputStateCreateInfo*      pVertexInputState
387 		inputAssemblyStateCreateInfo ? inputAssemblyStateCreateInfo : &inputAssemblyStateCreateInfoDefault,		// const VkPipelineInputAssemblyStateCreateInfo*    pInputAssemblyState
388 		tessStateCreateInfo,																					// const VkPipelineTessellationStateCreateInfo*     pTessellationState
389 		viewportStateCreateInfo ? viewportStateCreateInfo : &viewportStateCreateInfoDefault,					// const VkPipelineViewportStateCreateInfo*         pViewportState
390 		rasterizationStateCreateInfo ? rasterizationStateCreateInfo : &rasterizationStateCreateInfoDefault,		// const VkPipelineRasterizationStateCreateInfo*    pRasterizationState
391 		multisampleStateCreateInfo ? multisampleStateCreateInfo: &multisampleStateCreateInfoDefault,			// const VkPipelineMultisampleStateCreateInfo*      pMultisampleState
392 		depthStencilStateCreateInfo ? depthStencilStateCreateInfo : &depthStencilStateCreateInfoDefault,		// const VkPipelineDepthStencilStateCreateInfo*     pDepthStencilState
393 		colorBlendStateCreateInfo ? colorBlendStateCreateInfo : &colorBlendStateCreateInfoDefault,				// const VkPipelineColorBlendStateCreateInfo*       pColorBlendState
394 		dynamicStateCreateInfo ? dynamicStateCreateInfo : DE_NULL,												// const VkPipelineDynamicStateCreateInfo*          pDynamicState
395 		pipelineLayout,																							// VkPipelineLayout                                 layout
396 		renderPass,																								// VkRenderPass                                     renderPass
397 		subpass,																								// deUint32                                         subpass
398 		DE_NULL,																								// VkPipeline                                       basePipelineHandle
399 		0																										// deInt32                                          basePipelineIndex;
400 	};
401 
402 	return createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
403 }
404 
405 #ifndef CTS_USES_VULKANSC
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule taskShaderModule,const VkShaderModule meshShaderModule,const VkShaderModule fragmentShaderModule,const VkRenderPass renderPass,const std::vector<VkViewport> & viewports,const std::vector<VkRect2D> & scissors,const deUint32 subpass,const VkPipelineRasterizationStateCreateInfo * rasterizationStateCreateInfo,const VkPipelineMultisampleStateCreateInfo * multisampleStateCreateInfo,const VkPipelineDepthStencilStateCreateInfo * depthStencilStateCreateInfo,const VkPipelineColorBlendStateCreateInfo * colorBlendStateCreateInfo,const VkPipelineDynamicStateCreateInfo * dynamicStateCreateInfo,const VkPipelineCreateFlags pipelineCreateFlags,const void * pNext)406 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&							vk,
407 									   const VkDevice									device,
408 									   const VkPipelineLayout							pipelineLayout,
409 									   const VkShaderModule								taskShaderModule,
410 									   const VkShaderModule								meshShaderModule,
411 									   const VkShaderModule								fragmentShaderModule,
412 									   const VkRenderPass								renderPass,
413 									   const std::vector<VkViewport>&					viewports,
414 									   const std::vector<VkRect2D>&						scissors,
415 									   const deUint32									subpass,
416 									   const VkPipelineRasterizationStateCreateInfo*	rasterizationStateCreateInfo,
417 									   const VkPipelineMultisampleStateCreateInfo*		multisampleStateCreateInfo,
418 									   const VkPipelineDepthStencilStateCreateInfo*		depthStencilStateCreateInfo,
419 									   const VkPipelineColorBlendStateCreateInfo*		colorBlendStateCreateInfo,
420 									   const VkPipelineDynamicStateCreateInfo*			dynamicStateCreateInfo,
421 									   const VkPipelineCreateFlags						pipelineCreateFlags,
422 									   const void*										pNext)
423 {
424 	VkPipelineShaderStageCreateInfo					stageCreateInfo						=
425 	{
426 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType                     sType
427 		nullptr,												// const void*                         pNext
428 		0u,														// VkPipelineShaderStageCreateFlags    flags
429 		VK_SHADER_STAGE_VERTEX_BIT,								// VkShaderStageFlagBits               stage
430 		DE_NULL,												// VkShaderModule                      module
431 		"main",													// const char*                         pName
432 		nullptr													// const VkSpecializationInfo*         pSpecializationInfo
433 	};
434 
435 	std::vector<VkPipelineShaderStageCreateInfo>	pipelineShaderStageParams;
436 
437 	if (taskShaderModule != DE_NULL)
438 	{
439 		stageCreateInfo.stage	= VK_SHADER_STAGE_TASK_BIT_EXT;
440 		stageCreateInfo.module	= taskShaderModule;
441 		pipelineShaderStageParams.push_back(stageCreateInfo);
442 	}
443 
444 	{
445 		stageCreateInfo.stage	= VK_SHADER_STAGE_MESH_BIT_EXT;
446 		stageCreateInfo.module	= meshShaderModule;
447 		pipelineShaderStageParams.push_back(stageCreateInfo);
448 	}
449 
450 	if (fragmentShaderModule != DE_NULL)
451 	{
452 		stageCreateInfo.stage	= VK_SHADER_STAGE_FRAGMENT_BIT;
453 		stageCreateInfo.module	= fragmentShaderModule;
454 		pipelineShaderStageParams.push_back(stageCreateInfo);
455 	}
456 
457 	return makeGraphicsPipeline(
458 		vk,
459 		device,
460 		DE_NULL,
461 		pipelineLayout,
462 		pipelineCreateFlags,
463 		pipelineShaderStageParams,
464 		renderPass,
465 		viewports,
466 		scissors,
467 		subpass,
468 		rasterizationStateCreateInfo,
469 		multisampleStateCreateInfo,
470 		depthStencilStateCreateInfo,
471 		colorBlendStateCreateInfo,
472 		dynamicStateCreateInfo,
473 		pNext);
474 }
475 #endif // CTS_USES_VULKANSC
476 
477 namespace
478 {
479 
480 // Returns true if the shader stage create info structure contains information on the fragment shader.
481 // We could do this with a lambda but it's a bit more clear this way.
isFragShaderInfo(const VkPipelineShaderStageCreateInfo & shaderInfo)482 bool isFragShaderInfo (const VkPipelineShaderStageCreateInfo& shaderInfo)
483 {
484 	return (shaderInfo.stage == VK_SHADER_STAGE_FRAGMENT_BIT);
485 }
486 
487 }
488 
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipeline basePipelineHandle,const VkPipelineLayout pipelineLayout,const VkPipelineCreateFlags pipelineCreateFlags,const std::vector<VkPipelineShaderStageCreateInfo> & pipelineShaderStageParams,const VkRenderPass renderPass,const std::vector<VkViewport> & viewports,const std::vector<VkRect2D> & scissors,const deUint32 subpass,const VkPipelineRasterizationStateCreateInfo * rasterizationStateCreateInfo,const VkPipelineMultisampleStateCreateInfo * multisampleStateCreateInfo,const VkPipelineDepthStencilStateCreateInfo * depthStencilStateCreateInfo,const VkPipelineColorBlendStateCreateInfo * colorBlendStateCreateInfo,const VkPipelineDynamicStateCreateInfo * dynamicStateCreateInfo,const void * pNext)489 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&								vk,
490 									   const VkDevice										device,
491 									   const VkPipeline										basePipelineHandle,
492 									   const VkPipelineLayout								pipelineLayout,
493 									   const VkPipelineCreateFlags							pipelineCreateFlags,
494 									   const std::vector<VkPipelineShaderStageCreateInfo>&	pipelineShaderStageParams,
495 									   const VkRenderPass									renderPass,
496 									   const std::vector<VkViewport>&						viewports,
497 									   const std::vector<VkRect2D>&							scissors,
498 									   const deUint32										subpass,
499 									   const VkPipelineRasterizationStateCreateInfo*		rasterizationStateCreateInfo,
500 									   const VkPipelineMultisampleStateCreateInfo*			multisampleStateCreateInfo,
501 									   const VkPipelineDepthStencilStateCreateInfo*			depthStencilStateCreateInfo,
502 									   const VkPipelineColorBlendStateCreateInfo*			colorBlendStateCreateInfo,
503 									   const VkPipelineDynamicStateCreateInfo*				dynamicStateCreateInfo,
504 									   const void*											pNext)
505 {
506 	// Disable rasterization if no fragment shader info is found in pipelineShaderStageParams.
507 	const auto										fragFound							= std::any_of(begin(pipelineShaderStageParams), end(pipelineShaderStageParams), isFragShaderInfo);
508 	const VkBool32									disableRasterization				= (!fragFound);
509 
510 	VkPipelineViewportStateCreateInfo viewportStateCreateInfo = initVulkanStructure();
511 	viewportStateCreateInfo.viewportCount	= static_cast<uint32_t>(viewports.size());
512 	viewportStateCreateInfo.pViewports		= de::dataOrNull(viewports);
513 	viewportStateCreateInfo.scissorCount	= static_cast<uint32_t>(scissors.size());
514 	viewportStateCreateInfo.pScissors		= de::dataOrNull(scissors);
515 
516 	VkPipelineRasterizationStateCreateInfo rasterizationStateCreateInfoDefault = initVulkanStructure();
517 	rasterizationStateCreateInfoDefault.rasterizerDiscardEnable	= disableRasterization;
518 	rasterizationStateCreateInfoDefault.lineWidth				= 1.0f;
519 
520 	VkPipelineMultisampleStateCreateInfo multisampleStateCreateInfoDefault = initVulkanStructure();
521 	multisampleStateCreateInfoDefault.rasterizationSamples	= VK_SAMPLE_COUNT_1_BIT;
522 	multisampleStateCreateInfoDefault.minSampleShading		= 1.0f;
523 
524 	VkPipelineDepthStencilStateCreateInfo depthStencilStateCreateInfoDefault = initVulkanStructure();
525 	depthStencilStateCreateInfoDefault.maxDepthBounds = 1.0f;
526 
527 	VkPipelineColorBlendAttachmentState colorBlendAttachmentState = {};
528 	colorBlendAttachmentState.colorWriteMask = (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT);
529 
530 	VkPipelineColorBlendStateCreateInfo colorBlendStateCreateInfoDefault = initVulkanStructure();
531 	colorBlendStateCreateInfoDefault.attachmentCount	= 1u;
532 	colorBlendStateCreateInfoDefault.pAttachments		= &colorBlendAttachmentState;
533 
534 	std::vector<VkDynamicState> dynamicStates;
535 
536 	if (viewports.empty())
537 		dynamicStates.push_back(VK_DYNAMIC_STATE_VIEWPORT);
538 	if (scissors.empty())
539 		dynamicStates.push_back(VK_DYNAMIC_STATE_SCISSOR);
540 
541 	VkPipelineDynamicStateCreateInfo dynamicStateCreateInfoDefault = initVulkanStructure();
542 	dynamicStateCreateInfoDefault.dynamicStateCount	= static_cast<uint32_t>(dynamicStates.size());
543 	dynamicStateCreateInfoDefault.pDynamicStates	= de::dataOrNull(dynamicStates);
544 
545 	const VkPipelineDynamicStateCreateInfo*	dynamicStateCreateInfoDefaultPtr	= dynamicStates.empty() ? nullptr : &dynamicStateCreateInfoDefault;
546 
547 	const VkGraphicsPipelineCreateInfo		pipelineCreateInfo					=
548 	{
549 		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,														// VkStructureType                                  sType
550 		pNext,																									// const void*                                      pNext
551 		pipelineCreateFlags,																					// VkPipelineCreateFlags                            flags
552 		static_cast<uint32_t>(pipelineShaderStageParams.size()),												// deUint32                                         stageCount
553 		de::dataOrNull(pipelineShaderStageParams),																// const VkPipelineShaderStageCreateInfo*           pStages
554 		nullptr,																								// const VkPipelineVertexInputStateCreateInfo*      pVertexInputState
555 		nullptr,																								// const VkPipelineInputAssemblyStateCreateInfo*    pInputAssemblyState
556 		nullptr,																								// const VkPipelineTessellationStateCreateInfo*     pTessellationState
557 		&viewportStateCreateInfo,																				// const VkPipelineViewportStateCreateInfo*         pViewportState
558 		rasterizationStateCreateInfo	? rasterizationStateCreateInfo	: &rasterizationStateCreateInfoDefault,	// const VkPipelineRasterizationStateCreateInfo*    pRasterizationState
559 		multisampleStateCreateInfo		? multisampleStateCreateInfo	: &multisampleStateCreateInfoDefault,	// const VkPipelineMultisampleStateCreateInfo*      pMultisampleState
560 		depthStencilStateCreateInfo		? depthStencilStateCreateInfo	: &depthStencilStateCreateInfoDefault,	// const VkPipelineDepthStencilStateCreateInfo*     pDepthStencilState
561 		colorBlendStateCreateInfo		? colorBlendStateCreateInfo		: &colorBlendStateCreateInfoDefault,	// const VkPipelineColorBlendStateCreateInfo*       pColorBlendState
562 		dynamicStateCreateInfo			? dynamicStateCreateInfo		: dynamicStateCreateInfoDefaultPtr,		// const VkPipelineDynamicStateCreateInfo*          pDynamicState
563 		pipelineLayout,																							// VkPipelineLayout                                 layout
564 		renderPass,																								// VkRenderPass                                     renderPass
565 		subpass,																								// deUint32                                         subpass
566 		basePipelineHandle,																						// VkPipeline                                       basePipelineHandle
567 		-1																										// deInt32                                          basePipelineIndex;
568 	};
569 
570 	return createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
571 }
572 
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const VkFormat depthStencilFormat,const VkAttachmentLoadOp loadOperation,const VkImageLayout finalLayoutColor,const VkImageLayout finalLayoutDepthStencil,const VkImageLayout subpassLayoutColor,const VkImageLayout subpassLayoutDepthStencil,const VkAllocationCallbacks * const allocationCallbacks,const void * pNext)573 Move<VkRenderPass> makeRenderPass (const DeviceInterface&				vk,
574 								   const VkDevice						device,
575 								   const VkFormat						colorFormat,
576 								   const VkFormat						depthStencilFormat,
577 								   const VkAttachmentLoadOp				loadOperation,
578 								   const VkImageLayout					finalLayoutColor,
579 								   const VkImageLayout					finalLayoutDepthStencil,
580 								   const VkImageLayout					subpassLayoutColor,
581 								   const VkImageLayout					subpassLayoutDepthStencil,
582 								   const VkAllocationCallbacks* const	allocationCallbacks,
583 								   const void*							pNext)
584 {
585 	const bool								hasColor							= colorFormat != VK_FORMAT_UNDEFINED;
586 	const bool								hasDepthStencil						= depthStencilFormat != VK_FORMAT_UNDEFINED;
587 	const VkImageLayout						initialLayoutColor					= loadOperation == VK_ATTACHMENT_LOAD_OP_LOAD ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
588 	const VkImageLayout						initialLayoutDepthStencil			= loadOperation == VK_ATTACHMENT_LOAD_OP_LOAD ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
589 
590 	const VkAttachmentDescription			colorAttachmentDescription			=
591 	{
592 		(VkAttachmentDescriptionFlags)0,	// VkAttachmentDescriptionFlags    flags
593 		colorFormat,						// VkFormat                        format
594 		VK_SAMPLE_COUNT_1_BIT,				// VkSampleCountFlagBits           samples
595 		loadOperation,						// VkAttachmentLoadOp              loadOp
596 		VK_ATTACHMENT_STORE_OP_STORE,		// VkAttachmentStoreOp             storeOp
597 		VK_ATTACHMENT_LOAD_OP_DONT_CARE,	// VkAttachmentLoadOp              stencilLoadOp
598 		VK_ATTACHMENT_STORE_OP_DONT_CARE,	// VkAttachmentStoreOp             stencilStoreOp
599 		initialLayoutColor,					// VkImageLayout                   initialLayout
600 		finalLayoutColor					// VkImageLayout                   finalLayout
601 	};
602 
603 	const VkAttachmentDescription			depthStencilAttachmentDescription	=
604 	{
605 		(VkAttachmentDescriptionFlags)0,	// VkAttachmentDescriptionFlags    flags
606 		depthStencilFormat,					// VkFormat                        format
607 		VK_SAMPLE_COUNT_1_BIT,				// VkSampleCountFlagBits           samples
608 		loadOperation,						// VkAttachmentLoadOp              loadOp
609 		VK_ATTACHMENT_STORE_OP_STORE,		// VkAttachmentStoreOp             storeOp
610 		loadOperation,						// VkAttachmentLoadOp              stencilLoadOp
611 		VK_ATTACHMENT_STORE_OP_STORE,		// VkAttachmentStoreOp             stencilStoreOp
612 		initialLayoutDepthStencil,			// VkImageLayout                   initialLayout
613 		finalLayoutDepthStencil				// VkImageLayout                   finalLayout
614 	};
615 
616 	std::vector<VkAttachmentDescription>	attachmentDescriptions;
617 
618 	if (hasColor)
619 		attachmentDescriptions.push_back(colorAttachmentDescription);
620 	if (hasDepthStencil)
621 		attachmentDescriptions.push_back(depthStencilAttachmentDescription);
622 
623 	const VkAttachmentReference				colorAttachmentRef					=
624 	{
625 		0u,					// deUint32         attachment
626 		subpassLayoutColor	// VkImageLayout    layout
627 	};
628 
629 	const VkAttachmentReference				depthStencilAttachmentRef			=
630 	{
631 		hasColor ? 1u : 0u,			// deUint32         attachment
632 		subpassLayoutDepthStencil	// VkImageLayout    layout
633 	};
634 
635 	const VkSubpassDescription				subpassDescription					=
636 	{
637 		(VkSubpassDescriptionFlags)0,							// VkSubpassDescriptionFlags       flags
638 		VK_PIPELINE_BIND_POINT_GRAPHICS,						// VkPipelineBindPoint             pipelineBindPoint
639 		0u,														// deUint32                        inputAttachmentCount
640 		DE_NULL,												// const VkAttachmentReference*    pInputAttachments
641 		hasColor ? 1u : 0u,										// deUint32                        colorAttachmentCount
642 		hasColor ? &colorAttachmentRef : DE_NULL,				// const VkAttachmentReference*    pColorAttachments
643 		DE_NULL,												// const VkAttachmentReference*    pResolveAttachments
644 		hasDepthStencil ? &depthStencilAttachmentRef : DE_NULL,	// const VkAttachmentReference*    pDepthStencilAttachment
645 		0u,														// deUint32                        preserveAttachmentCount
646 		DE_NULL													// const deUint32*                 pPreserveAttachments
647 	};
648 
649 	const VkRenderPassCreateInfo			renderPassInfo						=
650 	{
651 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,									// VkStructureType                   sType
652 		pNext,																		// const void*                       pNext
653 		(VkRenderPassCreateFlags)0,													// VkRenderPassCreateFlags           flags
654 		(deUint32)attachmentDescriptions.size(),									// deUint32                          attachmentCount
655 		attachmentDescriptions.size() > 0 ? &attachmentDescriptions[0] : DE_NULL,	// const VkAttachmentDescription*    pAttachments
656 		1u,																			// deUint32                          subpassCount
657 		&subpassDescription,														// const VkSubpassDescription*       pSubpasses
658 		0u,																			// deUint32                          dependencyCount
659 		DE_NULL																		// const VkSubpassDependency*        pDependencies
660 	};
661 
662 	return createRenderPass(vk, device, &renderPassInfo, allocationCallbacks);
663 }
664 
makeImageView(const DeviceInterface & vk,const VkDevice vkDevice,const VkImage image,const VkImageViewType imageViewType,const VkFormat format,const VkImageSubresourceRange subresourceRange,const VkImageViewUsageCreateInfo * imageUsageCreateInfo)665 Move<VkImageView> makeImageView (const DeviceInterface&				vk,
666 								 const VkDevice						vkDevice,
667 								 const VkImage						image,
668 								 const VkImageViewType				imageViewType,
669 								 const VkFormat						format,
670 								 const VkImageSubresourceRange		subresourceRange,
671 								 const VkImageViewUsageCreateInfo*	imageUsageCreateInfo)
672 {
673 	const VkImageViewCreateInfo imageViewParams =
674 	{
675 		VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,		// VkStructureType			sType;
676 		imageUsageCreateInfo,							// const void*				pNext;
677 		0u,												// VkImageViewCreateFlags	flags;
678 		image,											// VkImage					image;
679 		imageViewType,									// VkImageViewType			viewType;
680 		format,											// VkFormat					format;
681 		makeComponentMappingRGBA(),						// VkComponentMapping		components;
682 		subresourceRange,								// VkImageSubresourceRange	subresourceRange;
683 	};
684 	return createImageView(vk, vkDevice, &imageViewParams);
685 }
686 
makeBufferView(const DeviceInterface & vk,const VkDevice vkDevice,const VkBuffer buffer,const VkFormat format,const VkDeviceSize offset,const VkDeviceSize size)687 Move<VkBufferView> makeBufferView (const DeviceInterface&	vk,
688 								   const VkDevice			vkDevice,
689 								   const VkBuffer			buffer,
690 								   const VkFormat			format,
691 								   const VkDeviceSize		offset,
692 								   const VkDeviceSize		size)
693 {
694 	const VkBufferViewCreateInfo bufferViewParams =
695 	{
696 		VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,	// VkStructureType			sType;
697 		DE_NULL,									// const void*				pNext;
698 		0u,											// VkBufferViewCreateFlags	flags;
699 		buffer,										// VkBuffer					buffer;
700 		format,										// VkFormat					format;
701 		offset,										// VkDeviceSize				offset;
702 		size,										// VkDeviceSize				range;
703 	};
704 	return createBufferView(vk, vkDevice, &bufferViewParams);
705 }
706 
makeDescriptorSet(const DeviceInterface & vk,const VkDevice device,const VkDescriptorPool descriptorPool,const VkDescriptorSetLayout setLayout,const void * pNext)707 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface&			vk,
708 										 const VkDevice					device,
709 										 const VkDescriptorPool			descriptorPool,
710 										 const VkDescriptorSetLayout	setLayout,
711 										 const void*					pNext)
712 {
713 	const VkDescriptorSetAllocateInfo allocateParams =
714 	{
715 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,	// VkStructureType				sType;
716 		pNext,											// const void*					pNext;
717 		descriptorPool,									// VkDescriptorPool				descriptorPool;
718 		1u,												// deUint32						setLayoutCount;
719 		&setLayout,										// const VkDescriptorSetLayout*	pSetLayouts;
720 	};
721 	return allocateDescriptorSet(vk, device, &allocateParams);
722 }
723 
makeBufferCreateInfo(const VkDeviceSize size,const VkBufferUsageFlags usage)724 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize			size,
725 										 const VkBufferUsageFlags	usage)
726 {
727 	const VkBufferCreateInfo bufferCreateInfo =
728 	{
729 		VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,	// VkStructureType		sType;
730 		DE_NULL,								// const void*			pNext;
731 		(VkBufferCreateFlags)0,					// VkBufferCreateFlags	flags;
732 		size,									// VkDeviceSize			size;
733 		usage,									// VkBufferUsageFlags	usage;
734 		VK_SHARING_MODE_EXCLUSIVE,				// VkSharingMode		sharingMode;
735 		0u,										// deUint32				queueFamilyIndexCount;
736 		DE_NULL,								// const deUint32*		pQueueFamilyIndices;
737 	};
738 	return bufferCreateInfo;
739 }
740 
makeBufferCreateInfo(const VkDeviceSize size,const VkBufferUsageFlags usage,const std::vector<deUint32> & queueFamilyIndices,const VkBufferCreateFlags createFlags)741 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize				size,
742 										 const VkBufferUsageFlags		usage,
743 										 const std::vector<deUint32>&	queueFamilyIndices,
744 										 const VkBufferCreateFlags		createFlags)
745 {
746 	const deUint32				queueFamilyIndexCount	= static_cast<deUint32>(queueFamilyIndices.size());
747 	const deUint32*				pQueueFamilyIndices		= de::dataOrNull(queueFamilyIndices);
748 	const VkBufferCreateInfo	bufferCreateInfo		=
749 	{
750 		VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,	// VkStructureType		sType;
751 		DE_NULL,								// const void*			pNext;
752 		createFlags,							// VkBufferCreateFlags	flags;
753 		size,									// VkDeviceSize			size;
754 		usage,									// VkBufferUsageFlags	usage;
755 		VK_SHARING_MODE_EXCLUSIVE,				// VkSharingMode		sharingMode;
756 		queueFamilyIndexCount,					// deUint32				queueFamilyIndexCount;
757 		pQueueFamilyIndices,					// const deUint32*		pQueueFamilyIndices;
758 	};
759 
760 	return bufferCreateInfo;
761 }
762 
763 
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout descriptorSetLayout,const VkPushConstantRange * pushConstantRange)764 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&		vk,
765 										   const VkDevice				device,
766 										   const VkDescriptorSetLayout	descriptorSetLayout,
767 										   const VkPushConstantRange*	pushConstantRange)
768 {
769 	const uint32_t layoutCount	= ((descriptorSetLayout == DE_NULL) ? 0u : 1u);
770 	const uint32_t rangeCount	= ((pushConstantRange == nullptr) ? 0u : 1u);
771 	return makePipelineLayout(vk, device, layoutCount, &descriptorSetLayout, rangeCount, pushConstantRange);
772 }
773 
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const std::vector<VkDescriptorSetLayout> & descriptorSetLayouts)774 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&					vk,
775 										   const VkDevice							device,
776 										   const std::vector<VkDescriptorSetLayout>	&descriptorSetLayouts)
777 {
778 	const deUint32					setLayoutCount		= descriptorSetLayouts.empty() ? 0u : (deUint32)descriptorSetLayouts.size();
779 	const VkDescriptorSetLayout*	descriptorSetLayout	= descriptorSetLayouts.empty() ? DE_NULL : descriptorSetLayouts.data();
780 
781 	return makePipelineLayout(vk, device, setLayoutCount, descriptorSetLayout);
782 }
783 
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const std::vector<vk::Move<VkDescriptorSetLayout>> & descriptorSetLayouts)784 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&								vk,
785 										   const VkDevice										device,
786 										   const std::vector<vk::Move<VkDescriptorSetLayout>>	&descriptorSetLayouts)
787 {
788 	// Create a list of descriptor sets without move pointers.
789 	std::vector<vk::VkDescriptorSetLayout> descriptorSetLayoutsUnWrapped;
790 	for (const auto& descriptorSetLayout : descriptorSetLayouts)
791 	{
792 		descriptorSetLayoutsUnWrapped.push_back(descriptorSetLayout.get());
793 	}
794 	return vk::makePipelineLayout(vk, device, static_cast<deUint32>(descriptorSetLayoutsUnWrapped.size()), descriptorSetLayoutsUnWrapped.data());
795 }
796 
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const deUint32 setLayoutCount,const VkDescriptorSetLayout * descriptorSetLayout,const VkPipelineLayoutCreateFlags flags)797 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&				vk,
798 										   const VkDevice						device,
799 										   const deUint32						setLayoutCount,
800 										   const VkDescriptorSetLayout*			descriptorSetLayout,
801 										   const VkPipelineLayoutCreateFlags	flags)
802 {
803 	const VkPipelineLayoutCreateInfo pipelineLayoutParams =
804 	{
805 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,		// VkStructureType					sType;
806 		DE_NULL,											// const void*						pNext;
807 		flags,	// VkPipelineLayoutCreateFlags		flags;
808 		setLayoutCount,										// deUint32							setLayoutCount;
809 		descriptorSetLayout,								// const VkDescriptorSetLayout*		pSetLayouts;
810 		0u,													// deUint32							pushConstantRangeCount;
811 		DE_NULL,											// const VkPushConstantRange*		pPushConstantRanges;
812 	};
813 
814 	return createPipelineLayout(vk, device, &pipelineLayoutParams);
815 }
816 
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const deUint32 setLayoutCount,const VkDescriptorSetLayout * descriptorSetLayout,const deUint32 pushConstantRangeCount,const VkPushConstantRange * pPushConstantRanges,const VkPipelineLayoutCreateFlags flags)817 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&				vk,
818 										   const VkDevice						device,
819 										   const deUint32						setLayoutCount,
820 										   const VkDescriptorSetLayout*			descriptorSetLayout,
821 										   const deUint32						pushConstantRangeCount,
822 										   const VkPushConstantRange*			pPushConstantRanges,
823 										   const VkPipelineLayoutCreateFlags	flags)
824 {
825 	const VkPipelineLayoutCreateInfo pipelineLayoutParams =
826 	{
827 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,		// VkStructureType					sType;
828 		DE_NULL,											// const void*						pNext;
829 		flags,	// VkPipelineLayoutCreateFlags		flags;
830 		setLayoutCount,										// deUint32							setLayoutCount;
831 		descriptorSetLayout,								// const VkDescriptorSetLayout*		pSetLayouts;
832 		pushConstantRangeCount,								// deUint32							pushConstantRangeCount;
833 		pPushConstantRanges,								// const VkPushConstantRange*		pPushConstantRanges;
834 	};
835 
836 	return createPipelineLayout(vk, device, &pipelineLayoutParams);
837 }
838 
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const VkImageView colorAttachment,const deUint32 width,const deUint32 height,const deUint32 layers)839 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface&	vk,
840 									 const VkDevice			device,
841 									 const VkRenderPass		renderPass,
842 									 const VkImageView		colorAttachment,
843 									 const deUint32			width,
844 									 const deUint32			height,
845 									 const deUint32			layers)
846 {
847 	return makeFramebuffer(vk, device, renderPass, 1u, &colorAttachment, width, height, layers);
848 }
849 
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const deUint32 attachmentCount,const VkImageView * attachmentsArray,const deUint32 width,const deUint32 height,const deUint32 layers)850 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface&	vk,
851 									 const VkDevice			device,
852 									 const VkRenderPass		renderPass,
853 									 const deUint32			attachmentCount,
854 									 const VkImageView*		attachmentsArray,
855 									 const deUint32			width,
856 									 const deUint32			height,
857 									 const deUint32			layers)
858 {
859 	const VkFramebufferCreateInfo framebufferInfo =
860 	{
861 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,	// VkStructureType			sType;
862 		DE_NULL,									// const void*				pNext;
863 		(VkFramebufferCreateFlags)0,				// VkFramebufferCreateFlags	flags;
864 		renderPass,									// VkRenderPass				renderPass;
865 		attachmentCount,							// uint32_t					attachmentCount;
866 		attachmentsArray,							// const VkImageView*		pAttachments;
867 		width,										// uint32_t					width;
868 		height,										// uint32_t					height;
869 		layers,										// uint32_t					layers;
870 	};
871 
872 	return createFramebuffer(vk, device, &framebufferInfo);
873 }
874 
makeCommandPool(const DeviceInterface & vk,const VkDevice device,const deUint32 queueFamilyIndex)875 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk,
876 									 const VkDevice			device,
877 									 const deUint32			queueFamilyIndex)
878 {
879 	const VkCommandPoolCreateInfo commandPoolParams =
880 	{
881 		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,			// VkStructureType			sType;
882 		DE_NULL,											// const void*				pNext;
883 		VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,	// VkCommandPoolCreateFlags	flags;
884 		queueFamilyIndex,									// deUint32					queueFamilyIndex;
885 	};
886 
887 	return createCommandPool(vk, device, &commandPoolParams);
888 }
889 
makeBufferImageCopy(const VkExtent3D extent,const VkImageSubresourceLayers subresourceLayers)890 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D					extent,
891 									   const VkImageSubresourceLayers	subresourceLayers)
892 {
893 	const VkBufferImageCopy copyParams =
894 	{
895 		0ull,					//	VkDeviceSize				bufferOffset;
896 		0u,						//	deUint32					bufferRowLength;
897 		0u,						//	deUint32					bufferImageHeight;
898 		subresourceLayers,		//	VkImageSubresourceLayers	imageSubresource;
899 		makeOffset3D(0, 0, 0),	//	VkOffset3D					imageOffset;
900 		extent,					//	VkExtent3D					imageExtent;
901 	};
902 	return copyParams;
903 }
904 
CommandPoolWithBuffer(const DeviceInterface & vkd,const VkDevice device,const deUint32 queueFamilyIndex)905 CommandPoolWithBuffer::CommandPoolWithBuffer (
906 										const DeviceInterface& vkd,
907 										const VkDevice         device,
908 										const deUint32         queueFamilyIndex) {
909 	cmdPool		= makeCommandPool(vkd, device, queueFamilyIndex);
910 	cmdBuffer	= allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY);
911 }
912 
913 } // vk
914