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