SpiecsEngine
 
Loading...
Searching...
No Matches
VulkanPipeline.cpp
Go to the documentation of this file.
1/**
2* @file VulkanPipeline.cpp.
3* @brief The VulkanPipeline Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9#include "Resources/Mesh/Mesh.h"
10#include "Resources/ResourcePool/ResourcePool.h"
11#include "Resources/Shader/Shader.h"
12#include "Render/Renderer/RendererPass/RendererPass.h"
13
14namespace Spices {
15
17 VulkanState& vulkanState ,
18 const std::string& pipelineName ,
19 const ShaderMap& shaders ,
20 const PipelineConfigInfo& config
21 )
22 : VulkanObject(vulkanState)
23 {
25
26 /**
27 * @brief Receive PipelineLayout from parameter.
28 */
29 m_PipelineLayout = config.pipelineLayout;
30
31 /**
32 * @brief Create the VulkanShaderModule.
33 */
34 std::vector<std::shared_ptr<VulkanShaderModule>> shaderModules;
35 for (auto& pair : shaders)
36 {
37 if (pair.first == "rchit") continue;
38
39 for (size_t i = 0; i < pair.second.size(); i++)
40 {
41 std::stringstream ss;
42 ss << pair.first << "." << pair.second[i];
43
44 shaderModules.push_back(ResourcePool<Shader>::Load<Shader>(ss.str(), pair.second[i], pair.first)->GetShaderModule());
45 }
46 }
47
48 /**
49 * @brief Instance VkPipelineShaderStageCreateInfo.
50 */
51 std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
52 for (size_t i = 0; i < shaderModules.size(); i++)
53 {
54 shaderStages.push_back(shaderModules[i]->GetShaderStageCreateInfo());
55 }
56
57 auto& bindingDescriptions = config.bindingDescriptions;
58 auto& attributeDescriptions = config.attributeDescriptions;
59
60 /**
61 * @brief Instance a VkPipelineVertexInputStateCreateInfo.
62 */
63 VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
64 vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
65 vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
66 vertexInputInfo.vertexBindingDescriptionCount = static_cast<uint32_t>(bindingDescriptions.size());
67 vertexInputInfo.pVertexAttributeDescriptions = vertexInputInfo.vertexAttributeDescriptionCount > 0 ? attributeDescriptions.data() : nullptr;
68 vertexInputInfo.pVertexBindingDescriptions = vertexInputInfo.vertexBindingDescriptionCount > 0 ? bindingDescriptions.data() : nullptr;
69
70 /**
71 * @brief Instance a VkGraphicsPipelineCreateInfo.
72 */
73 VkGraphicsPipelineCreateInfo pipelineInfo{};
74 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
75 pipelineInfo.flags = VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV;
76 pipelineInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
77 pipelineInfo.pStages = shaderStages.data();
78 pipelineInfo.pVertexInputState = &vertexInputInfo;
79 pipelineInfo.pInputAssemblyState = &config.inputAssemblyInfo;
80 pipelineInfo.pViewportState = &config.viewportInfo;
81 pipelineInfo.pRasterizationState = &config.rasterizationInfo;
82 pipelineInfo.pMultisampleState = &config.multisampleInfo;
83 pipelineInfo.pColorBlendState = &config.colorBlendInfo;
84 pipelineInfo.pDepthStencilState = &config.depthStencilInfo;
85 pipelineInfo.pDynamicState = &config.dynamicStateInfo;
86
87 pipelineInfo.layout = m_PipelineLayout;
88 pipelineInfo.renderPass = config.renderPass->Get();
89 pipelineInfo.subpass = config.subpass;
90
91 pipelineInfo.basePipelineIndex = -1;
92 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
93
94 /**
95 * @brief Create Pipeline.
96 */
97 VK_CHECK(vkCreateGraphicsPipelines(m_VulkanState.m_Device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_Pipeline))
98 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(m_Pipeline), m_VulkanState.m_Device, pipelineName)
99 }
100
102 {
104
105 /**
106 * @brief Destroy PipelineLayout.
107 */
108 vkDestroyPipelineLayout(m_VulkanState.m_Device, m_PipelineLayout, nullptr);
109
110 /**
111 * @brief Destroy Pipeline.
112 */
113 vkDestroyPipeline(m_VulkanState.m_Device, m_Pipeline, nullptr);
114 }
115
117 {
119
120 /**
121 * @brief VkPipelineInputAssemblyStateCreateInfo.
122 */
123 configInfo.inputAssemblyInfo = VkPipelineInputAssemblyStateCreateInfo{};
124 configInfo.inputAssemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
125 configInfo.inputAssemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
126 configInfo.inputAssemblyInfo.primitiveRestartEnable = VK_FALSE;
127
128 /**
129 * @brief VkPipelineViewportStateCreateInfo.
130 */
131 configInfo.viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
132 configInfo.viewportInfo.viewportCount = 1;
133 configInfo.viewportInfo.pViewports = &configInfo.viewport;
134 configInfo.viewportInfo.scissorCount = 1;
135 configInfo.viewportInfo.pScissors = &configInfo.scissor;
136
137 /**
138 * @brief VkPipelineRasterizationStateCreateInfo.
139 */
140 configInfo.rasterizationInfo = VkPipelineRasterizationStateCreateInfo{};
141 configInfo.rasterizationInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
142 configInfo.rasterizationInfo.depthClampEnable = VK_FALSE;
143 configInfo.rasterizationInfo.rasterizerDiscardEnable = VK_FALSE;
144 configInfo.rasterizationInfo.polygonMode = VK_POLYGON_MODE_FILL;
145 configInfo.rasterizationInfo.lineWidth = 1.0f;
146 configInfo.rasterizationInfo.cullMode = VK_CULL_MODE_BACK_BIT;
147 configInfo.rasterizationInfo.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; // negative clockwise
148 configInfo.rasterizationInfo.depthBiasEnable = VK_FALSE;
149 configInfo.rasterizationInfo.depthBiasConstantFactor = 0.0f;
150 configInfo.rasterizationInfo.depthBiasClamp = 0.0f;
151 configInfo.rasterizationInfo.depthBiasSlopeFactor = 0.0f;
152
153 /**
154 * @brief VkPipelineMultisampleStateCreateInfo.
155 */
156 configInfo.multisampleInfo = VkPipelineMultisampleStateCreateInfo{};
157 configInfo.multisampleInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
158 configInfo.multisampleInfo.sampleShadingEnable = VK_FALSE;
159 configInfo.multisampleInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; // TODO: Configurable, Disable MASS : VK_SAMPLE_COUNT_1_BIT, Enable MASS: VK_SAMPLE_COUNT_8_BIT.
160 configInfo.multisampleInfo.minSampleShading = 1.0f;
161 configInfo.multisampleInfo.pSampleMask = nullptr;
162 configInfo.multisampleInfo.alphaToCoverageEnable = VK_FALSE;
163 configInfo.multisampleInfo.alphaToOneEnable = VK_FALSE;
164
165 /**
166 * @brief VkPipelineColorBlendStateCreateInfo.
167 */
168 configInfo.colorBlendInfo = VkPipelineColorBlendStateCreateInfo{};
169 configInfo.colorBlendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
170 configInfo.colorBlendInfo.logicOpEnable = VK_FALSE;
171 configInfo.colorBlendInfo.logicOp = VK_LOGIC_OP_COPY;
172
173 configInfo.colorBlendInfo.attachmentCount = 0;
174 configInfo.colorBlendInfo.pAttachments = nullptr;
175 configInfo.colorBlendInfo.blendConstants[0] = 0.0f;
176 configInfo.colorBlendInfo.blendConstants[1] = 0.0f;
177 configInfo.colorBlendInfo.blendConstants[2] = 0.0f;
178 configInfo.colorBlendInfo.blendConstants[3] = 0.0f;
179
180 /**
181 * @brief VkPipelineDepthStencilStateCreateInfo.
182 */
183 configInfo.depthStencilInfo = VkPipelineDepthStencilStateCreateInfo{};
184 configInfo.depthStencilInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
185 configInfo.depthStencilInfo.depthTestEnable = VK_TRUE;
186 configInfo.depthStencilInfo.depthWriteEnable = VK_TRUE;
187 configInfo.depthStencilInfo.depthCompareOp = VK_COMPARE_OP_GREATER_OR_EQUAL; /* @brief Though we reverse z depth, allow greater value pass. */
188 configInfo.depthStencilInfo.depthBoundsTestEnable = VK_FALSE;
189 configInfo.depthStencilInfo.minDepthBounds = 0.0f;
190 configInfo.depthStencilInfo.maxDepthBounds = 1.0f;
191 configInfo.depthStencilInfo.stencilTestEnable = VK_FALSE;
192 configInfo.depthStencilInfo.front = {};
193 configInfo.depthStencilInfo.back = {};
194
195 /**
196 * @brief VkDynamicState.
197 */
198 configInfo.dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
199 configInfo.dynamicStateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
200 configInfo.dynamicStateInfo.pDynamicStates = configInfo.dynamicStateEnables.data();
201 configInfo.dynamicStateInfo.dynamicStateCount = static_cast<uint32_t>(configInfo.dynamicStateEnables.size());
202 configInfo.dynamicStateInfo.flags = 0;
203
204 /**
205 * @brief VkVertexInputBindingDescription.
206 */
207 configInfo.bindingDescriptions = InputAssembly::GetBindingDescriptions();
208
209 /**
210 * @brief VkVertexInputAttributeDescription.
211 */
212 configInfo.attributeDescriptions = InputAssembly::GetAttributeDescriptions();
213 }
214
216 VulkanState& vulkanState ,
217 const std::string& pipelineName ,
218 const ShaderMap& shaders ,
219 const PipelineConfigInfo& config
220 )
221 : VulkanPipeline(vulkanState)
222 {
224
225 /**
226 * @brief Receive PipelineLayout from parameter.
227 */
228 m_PipelineLayout = config.pipelineLayout;
229
230 /**
231 * @brief Create the VulkanShaderModule.
232 */
233 std::vector<std::shared_ptr<VulkanShaderModule>> shaderModules;
234 for (auto& pair : shaders)
235 {
236 for(size_t i = 0; i < pair.second.size(); i++)
237 {
238 std::stringstream ss;
239 ss << pair.first << "." << pair.second[i];
240
241 shaderModules.push_back(ResourcePool<Shader>::Load<Shader>(ss.str(), pair.second[i], pair.first)->GetShaderModule());
242 }
243 }
244
245 /**
246 * @brief Instance VkPipelineShaderStageCreateInfo.
247 */
248 std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
249 for (size_t i = 0; i < shaderModules.size(); i++)
250 {
251 shaderStages.push_back(shaderModules[i]->GetShaderStageCreateInfo());
252 }
253
254 /**
255 * @brief Shader groups.
256 */
257 VkRayTracingShaderGroupCreateInfoKHR group{};
258 group.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR;
259 group.anyHitShader = VK_SHADER_UNUSED_KHR;
260 group.closestHitShader = VK_SHADER_UNUSED_KHR;
261 group.generalShader = VK_SHADER_UNUSED_KHR;
262 group.intersectionShader = VK_SHADER_UNUSED_KHR;
263
264 std::vector<VkRayTracingShaderGroupCreateInfoKHR> m_RTShaderGroups;
265
266 for (auto& pair : shaders)
267 {
268 /**
269 * @brief Raygen.
270 */
271 if(pair.first == "rgen")
272 {
273 for(size_t i = 0; i < pair.second.size(); i++)
274 {
275 group.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR;
276 group.generalShader = static_cast<uint32_t>(m_RTShaderGroups.size());
277
278 m_RTShaderGroups.push_back(group);
279 }
280 }
281
282 /**
283 * @brief Miss.
284 */
285 else if(pair.first == "rmiss")
286 {
287 for(size_t i = 0; i < pair.second.size(); i++)
288 {
289 group.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR;
290 group.generalShader = static_cast<uint32_t>(m_RTShaderGroups.size());
291
292 m_RTShaderGroups.push_back(group);
293 }
294 }
295
296 /**
297 * @brief Closest hit.
298 */
299 else if(pair.first == "rchit")
300 {
301 for(size_t i = 0; i < pair.second.size(); i++)
302 {
303 group.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR;
304 group.generalShader = VK_SHADER_UNUSED_KHR;
305 group.closestHitShader = static_cast<uint32_t>(m_RTShaderGroups.size());
306
307 m_RTShaderGroups.push_back(group);
308 }
309 }
310 else
311 {
312 SPICES_CORE_ERROR("RayTracing Pipeline: Not Supported Sahder Stage from material.");
313 }
314 }
315
316 /**
317 * @brief Instance a VkGraphicsPipelineCreateInfo.
318 */
319 VkRayTracingPipelineCreateInfoKHR rayPipelineInfo{};
320 rayPipelineInfo.sType = VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR;
321 rayPipelineInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
322 rayPipelineInfo.pStages = shaderStages.data();
323 rayPipelineInfo.groupCount = static_cast<uint32_t>(m_RTShaderGroups.size());
324 rayPipelineInfo.pGroups = m_RTShaderGroups.data();
325 rayPipelineInfo.maxPipelineRayRecursionDepth = 2; /* @brief Ray depth */
326 rayPipelineInfo.layout = m_PipelineLayout;
327
328 /**
329 * @brief Create Pipeline.
330 */
331 VK_CHECK(m_VulkanState.m_VkFunc.vkCreateRayTracingPipelinesKHR(m_VulkanState.m_Device, {}, {}, 1, &rayPipelineInfo, nullptr, &m_Pipeline))
332 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(m_Pipeline), m_VulkanState.m_Device, pipelineName)
333 }
334
336 VulkanState& vulkanState ,
337 const std::string& pipelineName ,
338 const ShaderMap& shaders ,
339 const PipelineConfigInfo& config
340 )
341 :VulkanPipeline(vulkanState)
342 {
344
345 /**
346 * @brief Receive PipelineLayout from parameter.
347 */
348 m_PipelineLayout = config.pipelineLayout;
349
350 /**
351 * @brief Create the VulkanShaderModule.
352 */
353 std::vector<std::shared_ptr<VulkanShaderModule>> shaderModules;
354 for (auto& pair : shaders)
355 {
356 if (pair.first == "comp")
357 {
358 std::stringstream ss;
359 ss << pair.first << "." << pair.second[0];
360
361 shaderModules.push_back(ResourcePool<Shader>::Load<Shader>(ss.str(), pair.second[0], pair.first)->GetShaderModule());
362
363 break;
364 }
365 }
366
367 /**
368 * @brief Instance VkPipelineShaderStageCreateInfo.
369 */
370 std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
371 for (size_t i = 0; i < shaderModules.size(); i++)
372 {
373 shaderStages.push_back(shaderModules[i]->GetShaderStageCreateInfo());
374 }
375
376 /**
377 * @brief Instance VkComputePipelineCreateInfo.
378 * @note one shader stage per compute pipeline.
379 */
380 VkComputePipelineCreateInfo pipelineInfo {};
381 pipelineInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
382 //pipelineInfo.flags = VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV;
383 pipelineInfo.layout = m_PipelineLayout;
384 pipelineInfo.stage = shaderStages[0];
385
386 /**
387 * @brief Create Pipeline.
388 */
389 VK_CHECK(vkCreateComputePipelines(m_VulkanState.m_Device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_Pipeline))
390 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(m_Pipeline), m_VulkanState.m_Device, pipelineName)
391 }
392
394 VulkanState& vulkanState ,
395 const std::string& pipelineName ,
396 const ShaderMap& shaders,
397 const PipelineConfigInfo& config
398 )
399 :VulkanPipeline(vulkanState)
400 {
402
403 /**
404 * @brief Receive PipelineLayout from parameter.
405 */
406 m_PipelineLayout = config.pipelineLayout;
407
408 /**
409 * @brief Create the VulkanShaderModule.
410 */
411 std::vector<std::shared_ptr<VulkanShaderModule>> shaderModules;
412 {
413 SPICES_PROFILE_ZONEN("Create the VulkanShaderModule");
414
415 for (auto& pair : shaders)
416 {
417 if (pair.first == "rchit") continue;
418
419 for (size_t i = 0; i < pair.second.size(); i++)
420 {
421 std::stringstream ss;
422 ss << pair.first << "." << pair.second[i];
423
424 shaderModules.push_back(ResourcePool<Shader>::Load<Shader>(ss.str(), pair.second[i], pair.first)->GetShaderModule());
425 }
426 }
427 }
428
429 /**
430 * @brief Instance VkPipelineShaderStageCreateInfo.
431 */
432 std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
433 for (size_t i = 0; i < shaderModules.size(); i++)
434 {
435 shaderStages.push_back(shaderModules[i]->GetShaderStageCreateInfo());
436 }
437
438 /**
439 * @brief Instance a VkGraphicsPipelineCreateInfo.
440 */
441 VkGraphicsPipelineCreateInfo pipelineInfo{};
442 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
443 pipelineInfo.flags = VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV;
444 pipelineInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
445 pipelineInfo.pStages = shaderStages.data();
446 pipelineInfo.pVertexInputState = nullptr;
447 pipelineInfo.pInputAssemblyState = nullptr;
448 pipelineInfo.pViewportState = &config.viewportInfo;
449 pipelineInfo.pRasterizationState = &config.rasterizationInfo;
450 pipelineInfo.pMultisampleState = &config.multisampleInfo;
451 pipelineInfo.pColorBlendState = &config.colorBlendInfo;
452 pipelineInfo.pDepthStencilState = &config.depthStencilInfo;
453 pipelineInfo.pDynamicState = &config.dynamicStateInfo;
454
455 pipelineInfo.layout = m_PipelineLayout;
456 pipelineInfo.renderPass = config.renderPass->Get();
457 pipelineInfo.subpass = config.subpass;
458
459 pipelineInfo.basePipelineIndex = -1;
460 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
461
462 /**
463 * @brief Create Pipeline.
464 */
465 VK_CHECK(vkCreateGraphicsPipelines(m_VulkanState.m_Device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_Pipeline))
466 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(m_Pipeline), m_VulkanState.m_Device, pipelineName)
467 }
468
470 VulkanState& vulkanState ,
471 const std::string& pipelineName ,
472 const std::string& materialName ,
473 const std::vector<VkPipeline>& pipelineRef ,
474 const PipelineConfigInfo& config
475 )
476 : VulkanPipeline(vulkanState)
477 {
479
480 /**
481 * @brief Receive PipelineLayout from parameter.
482 */
483 m_PipelineLayout = config.pipelineLayout;
484
485 /**
486 * @brief Shader groups.
487 * We use pipeline reference here, so not need create shader group.
488 * Pass any group to create info will be fine.
489 */
490 const auto material = ResourcePool<Material>::Load<Material>(materialName, materialName);
491
492 std::stringstream ss;
493 ss << "vert" << "." << material->GetShaderPath("vert")[0];
494
495 VkPipelineShaderStageCreateInfo stage = ResourcePool<Shader>::Load<Shader>(ss.str(), material->GetShaderPath("vert")[0], ShaderStage::vert)->GetShaderModule()->GetShaderStageCreateInfo();
496
497 VkGraphicsShaderGroupCreateInfoNV group{};
498 group.sType = VK_STRUCTURE_TYPE_GRAPHICS_SHADER_GROUP_CREATE_INFO_NV;
499 group.stageCount = 1;
500 group.pStages = &stage;
501
502 /**
503 * @brief Instance a VkGraphicsPipelineShaderGroupsCreateInfoNV.
504 */
505 VkGraphicsPipelineShaderGroupsCreateInfoNV groupsCreateInfo{};
506 groupsCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_SHADER_GROUPS_CREATE_INFO_NV;
507 groupsCreateInfo.pipelineCount = static_cast<uint32_t>(pipelineRef.size());
508 groupsCreateInfo.pPipelines = pipelineRef.data();
509 groupsCreateInfo.groupCount = 1;
510 groupsCreateInfo.pGroups = &group;
511
512 auto& bindingDescriptions = config.bindingDescriptions;
513 auto& attributeDescriptions = config.attributeDescriptions;
514
515 /**
516 * @brief Instance a VkPipelineVertexInputStateCreateInfo.
517 */
518 VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
519 vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
520 vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
521 vertexInputInfo.vertexBindingDescriptionCount = static_cast<uint32_t>(bindingDescriptions.size());
522 vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
523 vertexInputInfo.pVertexBindingDescriptions = bindingDescriptions.data();
524
525 /**
526 * @brief Instance a VkGraphicsPipelineCreateInfo.
527 * Only pRasterizationState must be setted in pipeline reference.
528 */
529 VkGraphicsPipelineCreateInfo pipelineInfo{};
530 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
531 pipelineInfo.flags = VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV;
532 pipelineInfo.stageCount = 1;
533 pipelineInfo.pStages = &stage;
534 pipelineInfo.pVertexInputState = &vertexInputInfo;
535 pipelineInfo.pInputAssemblyState = &config.inputAssemblyInfo;
536 pipelineInfo.pViewportState = &config.viewportInfo;
537 pipelineInfo.pRasterizationState = &config.rasterizationInfo;
538 pipelineInfo.pMultisampleState = &config.multisampleInfo;
539 pipelineInfo.pColorBlendState = &config.colorBlendInfo;
540 pipelineInfo.pDepthStencilState = &config.depthStencilInfo;
541 pipelineInfo.pDynamicState = &config.dynamicStateInfo;
542
543 pipelineInfo.layout = m_PipelineLayout;
544 pipelineInfo.renderPass = config.renderPass->Get();
545 pipelineInfo.subpass = config.subpass;
546
547 pipelineInfo.basePipelineIndex = -1;
548 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
549 pipelineInfo.pNext = &groupsCreateInfo;
550
551 /**
552 * @brief Create Pipeline.
553 */
554 VK_CHECK(vkCreateGraphicsPipelines(m_VulkanState.m_Device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_Pipeline))
555 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(m_Pipeline), m_VulkanState.m_Device, pipelineName)
556 }
557
559 VulkanState& vulkanState ,
560 const std::string& pipelineName ,
561 const std::string& materialName ,
562 const std::vector<VkPipeline>& pipelineRef ,
563 const PipelineConfigInfo& config
564 )
565 : VulkanPipeline(vulkanState)
566 {
568
569 /**
570 * @brief Receive PipelineLayout from parameter.
571 */
572 m_PipelineLayout = config.pipelineLayout;
573
574 /**
575 * @brief Shader groups.
576 * We use pipeline reference here, so not need create shader group.
577 * Pass any group to create info will be fine.
578 */
579 const auto material = ResourcePool<Material>::Load<Material>(materialName, materialName);
580
581 std::stringstream ss;
582 ss << "mesh" << "." << material->GetShaderPath("mesh")[0];
583
584 VkPipelineShaderStageCreateInfo stage = ResourcePool<Shader>::Load<Shader>(ss.str(), material->GetShaderPath("mesh")[0], ShaderStage::vert)->GetShaderModule()->GetShaderStageCreateInfo();
585
586
587 VkGraphicsShaderGroupCreateInfoNV group{};
588 group.sType = VK_STRUCTURE_TYPE_GRAPHICS_SHADER_GROUP_CREATE_INFO_NV;
589 group.stageCount = 1;
590 group.pStages = &stage;
591
592 /**
593 * @brief Instance a VkGraphicsPipelineShaderGroupsCreateInfoNV.
594 */
595 VkGraphicsPipelineShaderGroupsCreateInfoNV groupsCreateInfo{};
596 groupsCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_SHADER_GROUPS_CREATE_INFO_NV;
597 groupsCreateInfo.pipelineCount = static_cast<uint32_t>(pipelineRef.size());
598 groupsCreateInfo.pPipelines = pipelineRef.data();
599 groupsCreateInfo.groupCount = 1;
600 groupsCreateInfo.pGroups = &group;
601
602 /**
603 * @brief Instance a VkGraphicsPipelineCreateInfo.
604 * Only pRasterizationState must be setted in pipeline reference.
605 */
606 VkGraphicsPipelineCreateInfo pipelineInfo{};
607 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
608 pipelineInfo.flags = VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV;
609 pipelineInfo.stageCount = 1;
610 pipelineInfo.pStages = &stage;
611 pipelineInfo.pVertexInputState = nullptr;
612 pipelineInfo.pInputAssemblyState = nullptr;
613 pipelineInfo.pViewportState = &config.viewportInfo;
614 pipelineInfo.pRasterizationState = &config.rasterizationInfo;
615 pipelineInfo.pMultisampleState = &config.multisampleInfo;
616 pipelineInfo.pColorBlendState = &config.colorBlendInfo;
617 pipelineInfo.pDepthStencilState = &config.depthStencilInfo;
618 pipelineInfo.pDynamicState = &config.dynamicStateInfo;
619
620 pipelineInfo.layout = m_PipelineLayout;
621 pipelineInfo.renderPass = config.renderPass->Get();
622 pipelineInfo.subpass = config.subpass;
623
624 pipelineInfo.basePipelineIndex = -1;
625 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
626 pipelineInfo.pNext = &groupsCreateInfo;
627
628 /**
629 * @brief Create Pipeline.
630 */
631 VK_CHECK(vkCreateGraphicsPipelines(m_VulkanState.m_Device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &m_Pipeline))
632 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(m_Pipeline), m_VulkanState.m_Device, pipelineName)
633 }
634}
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
Definition VulkanUtils.h:68
VulkanComputePipeline(VulkanState &vulkanState, const std::string &pipelineName, const ShaderMap &shaders, const PipelineConfigInfo &config)
Constructor Function. Create VkPipeline.
This class is a wrapper of Compute Pipeline.
VulkanIndirectMeshPipelineNV(VulkanState &vulkanState, const std::string &pipelineName, const std::string &materialName, const std::vector< VkPipeline > &pipelineRef, const PipelineConfigInfo &config)
Constructor Function. Create VkPipeline.
This class is a wrapper of Indirect Mesh Pipeline.
VulkanIndirectPipelineNV(VulkanState &vulkanState, const std::string &pipelineName, const std::string &materialName, const std::vector< VkPipeline > &pipelineRef, const PipelineConfigInfo &config)
Constructor Function. Create VkPipeline.
This class is a wrapper of Indirect Pipeline.
VulkanMeshPipeline(VulkanState &vulkanState, const std::string &pipelineName, const ShaderMap &shaders, const PipelineConfigInfo &config)
Constructor Function. Create VkPipeline.
This class is a wrapper of Mesh Pipeline.
VulkanObject(VulkanState &vulkanState)
Constructor Function. Init member variables.
VulkanObject Class. This class defines the basic behaves of VulkanObject. When we create an new Vulka...
VulkanPipeline(VulkanState &vulkanState)
Constructor Function.
virtual ~VulkanPipeline() override
Destructor Function.
static void DefaultPipelineConfigInfo(PipelineConfigInfo &configInfo)
Create a PipelineConfigInfo with default parameter.
VulkanPipeline(VulkanState &vulkanState, const std::string &pipelineName, const ShaderMap &shaders, const PipelineConfigInfo &config)
Constructor Function. Create VkPipeline.
This class is a wrapper of VkPipelineLayout and VkPipeline.
VulkanRayTracingPipeline(VulkanState &vulkanState, const std::string &pipelineName, const ShaderMap &shaders, const PipelineConfigInfo &config)
Constructor Function. Create VkPipeline.
This class is a wrapper of RayTracing Pipeline.
This struct included all infos usd to create a VkPipeline.
This struct contains all Vulkan object in used global.
Definition VulkanUtils.h:74