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