30 vk_compute_pipeline_create_info_.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
31 vk_compute_pipeline_create_info_.pNext =
nullptr;
32 vk_compute_pipeline_create_info_.flags = 0;
33 vk_compute_pipeline_create_info_.layout = VK_NULL_HANDLE;
34 vk_compute_pipeline_create_info_.basePipelineHandle = VK_NULL_HANDLE;
35 vk_compute_pipeline_create_info_.basePipelineIndex = 0;
36 VkPipelineShaderStageCreateInfo &vk_pipeline_shader_stage_create_info =
37 vk_compute_pipeline_create_info_.stage;
38 vk_pipeline_shader_stage_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
39 vk_pipeline_shader_stage_create_info.pNext =
nullptr;
40 vk_pipeline_shader_stage_create_info.flags = 0;
41 vk_pipeline_shader_stage_create_info.stage = VK_SHADER_STAGE_COMPUTE_BIT;
42 vk_pipeline_shader_stage_create_info.module = VK_NULL_HANDLE;
43 vk_pipeline_shader_stage_create_info.pName =
"main";
46 vk_graphics_pipeline_create_info_ = {};
47 vk_graphics_pipeline_create_info_.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
48 vk_graphics_pipeline_create_info_.pNext = &vk_pipeline_rendering_create_info_;
49 vk_graphics_pipeline_create_info_.stageCount = 0;
50 vk_graphics_pipeline_create_info_.pStages = vk_pipeline_shader_stage_create_info_;
51 vk_graphics_pipeline_create_info_.pInputAssemblyState =
52 &vk_pipeline_input_assembly_state_create_info_;
53 vk_graphics_pipeline_create_info_.pVertexInputState =
54 &vk_pipeline_vertex_input_state_create_info_;
55 vk_graphics_pipeline_create_info_.pRasterizationState =
56 &vk_pipeline_rasterization_state_create_info_;
57 vk_graphics_pipeline_create_info_.pViewportState = &vk_pipeline_viewport_state_create_info_;
58 vk_graphics_pipeline_create_info_.pMultisampleState =
59 &vk_pipeline_multisample_state_create_info_;
60 vk_graphics_pipeline_create_info_.pColorBlendState = &vk_pipeline_color_blend_state_create_info_;
63 vk_pipeline_rendering_create_info_ = {};
64 vk_pipeline_rendering_create_info_.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
68 vk_pipeline_shader_stage_create_info_[i].sType =
69 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
70 vk_pipeline_shader_stage_create_info_[i].pNext =
nullptr;
71 vk_pipeline_shader_stage_create_info_[i].flags = 0;
72 vk_pipeline_shader_stage_create_info_[i].module = VK_NULL_HANDLE;
73 vk_pipeline_shader_stage_create_info_[i].pName =
"main";
75 vk_pipeline_shader_stage_create_info_[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
76 vk_pipeline_shader_stage_create_info_[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
77 vk_pipeline_shader_stage_create_info_[2].stage = VK_SHADER_STAGE_GEOMETRY_BIT;
80 vk_pipeline_input_assembly_state_create_info_ = {};
81 vk_pipeline_input_assembly_state_create_info_.sType =
82 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
85 vk_pipeline_vertex_input_state_create_info_ = {};
86 vk_pipeline_vertex_input_state_create_info_.sType =
87 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
90 vk_pipeline_rasterization_state_create_info_ = {};
91 vk_pipeline_rasterization_state_create_info_.sType =
92 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
93 vk_pipeline_rasterization_state_create_info_.lineWidth = 1.0f;
94 vk_pipeline_rasterization_state_create_info_.frontFace = VK_FRONT_FACE_CLOCKWISE;
96 vk_pipeline_viewport_state_create_info_ = {};
97 vk_pipeline_viewport_state_create_info_.sType =
98 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
101 vk_pipeline_multisample_state_create_info_ = {};
102 vk_pipeline_multisample_state_create_info_.sType =
103 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
104 vk_pipeline_multisample_state_create_info_.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
105 vk_pipeline_multisample_state_create_info_.minSampleShading = 1.0f;
108 vk_pipeline_color_blend_state_create_info_ = {};
109 vk_pipeline_color_blend_state_create_info_.sType =
110 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
111 vk_pipeline_color_blend_attachment_state_template_.colorWriteMask = VK_COLOR_COMPONENT_R_BIT |
112 VK_COLOR_COMPONENT_G_BIT |
113 VK_COLOR_COMPONENT_B_BIT |
114 VK_COLOR_COMPONENT_A_BIT;
116 vk_pipeline_depth_stencil_state_create_info_ = {};
117 vk_pipeline_depth_stencil_state_create_info_.sType =
118 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
121 vk_specialization_info_.mapEntryCount = 0;
122 vk_specialization_info_.pMapEntries =
nullptr;
123 vk_specialization_info_.dataSize = 0;
124 vk_specialization_info_.pData =
nullptr;
126 vk_push_constant_range_.stageFlags = 0;
127 vk_push_constant_range_.offset = 0;
128 vk_push_constant_range_.size = 0;
216 const bool is_static_shader,
217 VkPipeline vk_pipeline_base)
219 std::scoped_lock
lock(mutex_);
221 const VkPipeline *found_pipeline = graphic_pipelines_.lookup_ptr(graphics_info);
222 if (found_pipeline) {
223 VkPipeline result = *found_pipeline;
229 VkSpecializationInfo *specialization_info = specialization_info_update(
233 vk_graphics_pipeline_create_info_.stageCount =
235 vk_pipeline_shader_stage_create_info_[0].module =
237 vk_pipeline_shader_stage_create_info_[0].pSpecializationInfo = specialization_info;
238 vk_pipeline_shader_stage_create_info_[1].module =
240 vk_pipeline_shader_stage_create_info_[1].pSpecializationInfo = specialization_info;
241 vk_pipeline_shader_stage_create_info_[2].module =
243 vk_pipeline_shader_stage_create_info_[2].pSpecializationInfo = specialization_info;
247 vk_pipeline_input_assembly_state_create_info_.primitiveRestartEnable =
249 VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
250 VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
251 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
252 VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY) ?
255 vk_pipeline_vertex_input_state_create_info_.pVertexAttributeDescriptions =
257 vk_pipeline_vertex_input_state_create_info_.vertexAttributeDescriptionCount =
259 vk_pipeline_vertex_input_state_create_info_.pVertexBindingDescriptions =
261 vk_pipeline_vertex_input_state_create_info_.vertexBindingDescriptionCount =
265 vk_pipeline_rasterization_state_create_info_.frontFace = graphics_info.
state.
invert_facing ?
266 VK_FRONT_FACE_COUNTER_CLOCKWISE :
267 VK_FRONT_FACE_CLOCKWISE;
271 vk_pipeline_rasterization_state_create_info_.depthBiasEnable = VK_TRUE;
272 vk_pipeline_rasterization_state_create_info_.depthBiasSlopeFactor = 2.0f;
273 vk_pipeline_rasterization_state_create_info_.depthBiasConstantFactor = 1.0f;
274 vk_pipeline_rasterization_state_create_info_.depthBiasClamp = 0.0f;
277 vk_pipeline_rasterization_state_create_info_.depthBiasEnable = VK_FALSE;
279 vk_pipeline_rasterization_state_create_info_.frontFace = graphics_info.
state.
invert_facing ?
280 VK_FRONT_FACE_COUNTER_CLOCKWISE :
281 VK_FRONT_FACE_CLOCKWISE;
284 vk_pipeline_viewport_state_create_info_.pViewports =
286 vk_pipeline_viewport_state_create_info_.viewportCount =
288 vk_pipeline_viewport_state_create_info_.pScissors =
290 vk_pipeline_viewport_state_create_info_.scissorCount =
295 VkPipelineColorBlendStateCreateInfo &cb = vk_pipeline_color_blend_state_create_info_;
296 VkPipelineColorBlendAttachmentState &att_state =
297 vk_pipeline_color_blend_attachment_state_template_;
299 att_state.blendEnable = VK_TRUE;
300 att_state.alphaBlendOp = VK_BLEND_OP_ADD;
301 att_state.colorBlendOp = VK_BLEND_OP_ADD;
302 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_DST_ALPHA;
303 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
304 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
305 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
306 att_state.colorWriteMask = 0;
307 cb.blendConstants[0] = 1.0f;
308 cb.blendConstants[1] = 1.0f;
309 cb.blendConstants[2] = 1.0f;
310 cb.blendConstants[3] = 1.0f;
315 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
316 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
317 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
318 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
322 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
323 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
324 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
325 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
329 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
330 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
331 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
332 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
337 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
338 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
339 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
340 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
344 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_DST_COLOR;
345 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
346 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA;
347 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
351 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
352 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
353 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
354 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
358 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
359 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
360 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
361 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
365 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
366 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
367 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
368 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
372 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
373 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
374 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
375 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
379 att_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
380 att_state.dstColorBlendFactor = VK_BLEND_FACTOR_SRC1_COLOR;
381 att_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
382 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_SRC1_ALPHA;
387 att_state.alphaBlendOp = VK_BLEND_OP_REVERSE_SUBTRACT;
388 att_state.colorBlendOp = VK_BLEND_OP_REVERSE_SUBTRACT;
391 att_state.alphaBlendOp = VK_BLEND_OP_ADD;
392 att_state.colorBlendOp = VK_BLEND_OP_ADD;
396 att_state.blendEnable = VK_TRUE;
399 att_state.blendEnable = VK_FALSE;
404 att_state.colorWriteMask |= VK_COLOR_COMPONENT_R_BIT;
407 att_state.colorWriteMask |= VK_COLOR_COMPONENT_G_BIT;
410 att_state.colorWriteMask |= VK_COLOR_COMPONENT_B_BIT;
413 att_state.colorWriteMask |= VK_COLOR_COMPONENT_A_BIT;
416 vk_pipeline_color_blend_attachment_states_.
clear();
418 vk_pipeline_color_blend_attachment_state_template_,
420 vk_pipeline_color_blend_state_create_info_.attachmentCount =
421 vk_pipeline_color_blend_attachment_states_.
size();
422 vk_pipeline_color_blend_state_create_info_.pAttachments =
423 vk_pipeline_color_blend_attachment_states_.
data();
427 vk_graphics_pipeline_create_info_.pDepthStencilState =
428 &vk_pipeline_depth_stencil_state_create_info_;
429 vk_pipeline_depth_stencil_state_create_info_.depthWriteEnable =
432 vk_pipeline_depth_stencil_state_create_info_.depthTestEnable = VK_TRUE;
435 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_LESS;
438 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
441 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_EQUAL;
444 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_GREATER;
447 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp =
448 VK_COMPARE_OP_GREATER_OR_EQUAL;
451 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_ALWAYS;
454 vk_pipeline_depth_stencil_state_create_info_.depthTestEnable = VK_FALSE;
455 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_NEVER;
461 vk_graphics_pipeline_create_info_.pDepthStencilState =
462 &vk_pipeline_depth_stencil_state_create_info_;
466 vk_pipeline_depth_stencil_state_create_info_.stencilTestEnable = VK_TRUE;
467 vk_pipeline_depth_stencil_state_create_info_.front.compareOp = VK_COMPARE_OP_NOT_EQUAL;
470 vk_pipeline_depth_stencil_state_create_info_.stencilTestEnable = VK_TRUE;
471 vk_pipeline_depth_stencil_state_create_info_.front.compareOp = VK_COMPARE_OP_EQUAL;
474 vk_pipeline_depth_stencil_state_create_info_.stencilTestEnable = VK_TRUE;
475 vk_pipeline_depth_stencil_state_create_info_.front.compareOp = VK_COMPARE_OP_ALWAYS;
478 vk_pipeline_depth_stencil_state_create_info_.stencilTestEnable = VK_FALSE;
479 vk_pipeline_depth_stencil_state_create_info_.front.compareOp = VK_COMPARE_OP_ALWAYS;
483 vk_pipeline_depth_stencil_state_create_info_.front.compareMask =
485 vk_pipeline_depth_stencil_state_create_info_.front.reference =
487 vk_pipeline_depth_stencil_state_create_info_.front.writeMask =
492 vk_pipeline_depth_stencil_state_create_info_.front.failOp = VK_STENCIL_OP_KEEP;
493 vk_pipeline_depth_stencil_state_create_info_.front.passOp = VK_STENCIL_OP_REPLACE;
494 vk_pipeline_depth_stencil_state_create_info_.front.depthFailOp = VK_STENCIL_OP_KEEP;
495 vk_pipeline_depth_stencil_state_create_info_.back =
496 vk_pipeline_depth_stencil_state_create_info_.front;
500 vk_pipeline_depth_stencil_state_create_info_.front.failOp = VK_STENCIL_OP_KEEP;
501 vk_pipeline_depth_stencil_state_create_info_.front.passOp =
502 VK_STENCIL_OP_DECREMENT_AND_WRAP;
503 vk_pipeline_depth_stencil_state_create_info_.front.depthFailOp = VK_STENCIL_OP_KEEP;
504 vk_pipeline_depth_stencil_state_create_info_.back =
505 vk_pipeline_depth_stencil_state_create_info_.front;
506 vk_pipeline_depth_stencil_state_create_info_.back.passOp =
507 VK_STENCIL_OP_INCREMENT_AND_WRAP;
511 vk_pipeline_depth_stencil_state_create_info_.front.failOp = VK_STENCIL_OP_KEEP;
512 vk_pipeline_depth_stencil_state_create_info_.front.passOp = VK_STENCIL_OP_KEEP;
513 vk_pipeline_depth_stencil_state_create_info_.front.depthFailOp =
514 VK_STENCIL_OP_INCREMENT_AND_WRAP;
515 vk_pipeline_depth_stencil_state_create_info_.back =
516 vk_pipeline_depth_stencil_state_create_info_.front;
517 vk_pipeline_depth_stencil_state_create_info_.back.depthFailOp =
518 VK_STENCIL_OP_DECREMENT_AND_WRAP;
523 vk_pipeline_depth_stencil_state_create_info_.front.failOp = VK_STENCIL_OP_KEEP;
524 vk_pipeline_depth_stencil_state_create_info_.front.passOp = VK_STENCIL_OP_KEEP;
525 vk_pipeline_depth_stencil_state_create_info_.front.depthFailOp = VK_STENCIL_OP_KEEP;
526 vk_pipeline_depth_stencil_state_create_info_.back =
527 vk_pipeline_depth_stencil_state_create_info_.front;
533 vk_pipeline_rendering_create_info_.depthAttachmentFormat =
535 vk_pipeline_rendering_create_info_.stencilAttachmentFormat =
537 vk_pipeline_rendering_create_info_.colorAttachmentCount =
539 vk_pipeline_rendering_create_info_.pColorAttachmentFormats =
545 vk_graphics_pipeline_create_info_.basePipelineHandle = vk_pipeline_base;
552 VkPipeline pipeline = VK_NULL_HANDLE;
553 vkCreateGraphicsPipelines(device.
vk_handle(),
554 is_static_shader ? vk_pipeline_cache_static_ :
555 vk_pipeline_cache_non_static_,
557 &vk_graphics_pipeline_create_info_,
558 vk_allocation_callbacks,
560 graphic_pipelines_.add(graphics_info, pipeline);
563 specialization_info_reset();
564 vk_graphics_pipeline_create_info_.stageCount = 0;
565 vk_graphics_pipeline_create_info_.layout = VK_NULL_HANDLE;
566 vk_graphics_pipeline_create_info_.basePipelineHandle = VK_NULL_HANDLE;
567 for (VkPipelineShaderStageCreateInfo &info :
570 info.module = VK_NULL_HANDLE;
571 info.pSpecializationInfo =
nullptr;
573 vk_pipeline_input_assembly_state_create_info_.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
574 vk_pipeline_input_assembly_state_create_info_.primitiveRestartEnable = VK_TRUE;
575 vk_pipeline_vertex_input_state_create_info_.pVertexAttributeDescriptions =
nullptr;
576 vk_pipeline_vertex_input_state_create_info_.vertexAttributeDescriptionCount = 0;
577 vk_pipeline_vertex_input_state_create_info_.pVertexBindingDescriptions =
nullptr;
578 vk_pipeline_vertex_input_state_create_info_.vertexBindingDescriptionCount = 0;
579 vk_pipeline_rasterization_state_create_info_.frontFace = VK_FRONT_FACE_CLOCKWISE;
580 vk_pipeline_rasterization_state_create_info_.cullMode = VK_CULL_MODE_NONE;
581 vk_pipeline_rasterization_state_create_info_.depthBiasEnable = VK_FALSE;
582 vk_pipeline_rasterization_state_create_info_.depthBiasSlopeFactor = 0.0f;
583 vk_pipeline_rasterization_state_create_info_.depthBiasConstantFactor = 0.0f;
584 vk_pipeline_rasterization_state_create_info_.depthBiasClamp = 0.0f;
585 vk_pipeline_rasterization_state_create_info_.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
586 vk_pipeline_viewport_state_create_info_.pScissors =
nullptr;
587 vk_pipeline_viewport_state_create_info_.scissorCount = 0;
588 vk_pipeline_viewport_state_create_info_.pViewports =
nullptr;
589 vk_pipeline_viewport_state_create_info_.viewportCount = 0;
590 vk_pipeline_color_blend_state_create_info_.attachmentCount = 0;
591 vk_pipeline_color_blend_state_create_info_.pAttachments =
nullptr;
592 vk_pipeline_rendering_create_info_.colorAttachmentCount = 0;
593 vk_pipeline_rendering_create_info_.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
594 vk_pipeline_rendering_create_info_.pColorAttachmentFormats =
nullptr;
595 vk_pipeline_rendering_create_info_.stencilAttachmentFormat = VK_FORMAT_UNDEFINED;
596 vk_pipeline_depth_stencil_state_create_info_.depthTestEnable = VK_FALSE;
597 vk_pipeline_depth_stencil_state_create_info_.depthWriteEnable = VK_FALSE;
598 vk_pipeline_depth_stencil_state_create_info_.depthCompareOp = VK_COMPARE_OP_NEVER;
599 vk_pipeline_depth_stencil_state_create_info_.stencilTestEnable = VK_FALSE;
600 vk_pipeline_depth_stencil_state_create_info_.front = {};
601 vk_pipeline_depth_stencil_state_create_info_.back = {};
602 vk_graphics_pipeline_create_info_.pDepthStencilState =
nullptr;