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