34 VkPipelineRasterizationProvokingVertexStateCreateInfoEXT
64 VkPipeline vk_pipeline_base)
68 build_graphics_pipeline(extensions, graphics_info, vk_pipeline_base);
70 build_input_assembly_state(graphics_info.
vertex_in);
72 build_vertex_input_state(device, graphics_info.
vertex_in);
75 build_shader_stages(graphics_info.
shaders);
76 const bool do_specialization_constants =
78 if (do_specialization_constants) {
79 build_specialization_constants(graphics_info.
shaders);
81 build_dynamic_state(graphics_info.
shaders, extensions, workarounds);
82 build_multisample_state();
83 build_viewport_state(graphics_info.
shaders, workarounds);
84 build_rasterization_state(graphics_info.
shaders, extensions);
85 build_depth_stencil_state(graphics_info.
shaders);
87 build_color_blend_attachment_states(graphics_info.
fragment_out);
88 build_color_blend_state();
97 VkPipeline vk_pipeline_base)
100 build_graphics_pipeline_library(VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT);
101 build_graphics_pipeline_vertex_input_lib(vk_pipeline_base, extensions);
102 build_input_assembly_state(vertex_input_info);
103 build_dynamic_state_for_vertex_input(extensions);
106 build_vertex_input_state(device, vertex_input_info);
116 VkPipeline vk_pipeline_base)
118 build_graphics_pipeline_library(
119 VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT |
120 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT);
121 build_graphics_pipeline_shaders_lib(shaders_info, vk_pipeline_base);
123 build_shader_stages(shaders_info);
125 if (do_specialization_constants) {
126 build_specialization_constants(shaders_info);
128 build_dynamic_state(shaders_info, extensions, workarounds);
129 build_multisample_state();
130 build_viewport_state(shaders_info, workarounds);
131 build_rasterization_state(shaders_info, extensions);
132 build_depth_stencil_state(shaders_info);
133 build_dynamic_rendering_shaders_lib(extensions, shaders_info);
141 VkPipeline vk_pipeline_base)
143 build_graphics_pipeline_library(
144 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT);
145 build_graphics_pipeline_fragment_output_lib(vk_pipeline_base);
146 build_multisample_state();
147 build_color_blend_attachment_states(fragment_output_info);
148 build_color_blend_state();
149 build_dynamic_rendering(fragment_output_info);
153 void build_graphics_pipeline(
const VKExtensions &extensions,
155 VkPipeline vk_pipeline_base)
183 void build_graphics_pipeline_vertex_input_lib(VkPipeline vk_pipeline_base,
184 const VKExtensions &extensions)
187 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
189 VK_PIPELINE_CREATE_LIBRARY_BIT_KHR |
190 VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
193 extensions.vertex_input_dynamic_state ?
nullptr :
210 void build_graphics_pipeline_shaders_lib(
const VKGraphicsInfo::Shaders &shaders_info,
211 VkPipeline vk_pipeline_base)
214 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
216 VK_PIPELINE_CREATE_LIBRARY_BIT_KHR |
217 VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
218 shaders_info.vk_geometry_module == VK_NULL_HANDLE ? 2u : 3u,
229 shaders_info.vk_pipeline_layout,
237 void build_graphics_pipeline_fragment_output_lib(VkPipeline vk_pipeline_base)
240 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
242 VK_PIPELINE_CREATE_LIBRARY_BIT_KHR |
243 VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
263 void build_graphics_pipeline_library(VkGraphicsPipelineLibraryFlagsEXT flags)
266 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
nullptr, flags};
269 void build_shader_stages(
const VKGraphicsInfo::Shaders &shaders_info)
274 VK_SHADER_STAGE_VERTEX_BIT,
275 shaders_info.vk_vertex_module,
281 VK_SHADER_STAGE_FRAGMENT_BIT,
282 shaders_info.vk_fragment_module,
288 VK_SHADER_STAGE_GEOMETRY_BIT,
289 shaders_info.vk_geometry_module,
294 void build_specialization_constants(
const VKGraphicsInfo::Shaders &shaders_info)
306 shaders_info.specialization_constants.size() *
sizeof(
uint32_t),
307 shaders_info.specialization_constants.data()};
310 void build_multisample_state()
313 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
316 VK_SAMPLE_COUNT_1_BIT,
324 void build_viewport_state(
const VKGraphicsInfo::Shaders &shaders_info,
325 const VKWorkarounds &workarounds)
328 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
331 shaders_info.viewport_count,
333 shaders_info.viewport_count,
335 if (workarounds.static_viewport_scissor) {
336 BLI_assert(shaders_info.viewports.size() == shaders_info.viewport_count);
337 BLI_assert(shaders_info.scissors.size() == shaders_info.viewport_count);
343 void build_input_assembly_state(
const VKGraphicsInfo::VertexIn &vertex_input_info)
346 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO};
349 ELEM(vertex_input_info.vk_topology,
350 VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
351 VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
352 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
353 VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY) ?
358 void build_vertex_input_state(VKDevice &device,
359 const VKGraphicsInfo::VertexIn &vertex_input_info)
361 BLI_assert_msg(!device.extensions_get().vertex_input_dynamic_state,
362 "No need to set vertex input state as dynamic state is supported.");
363 const VKVertexInputDescription &description = device.vertex_input_descriptions.get(
364 vertex_input_info.vertex_input_key);
366 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO};
369 for (
const VkVertexInputAttributeDescription2EXT &attr : description.attributes) {
371 {attr.location, attr.binding, attr.format, attr.offset});
373 for (
const VkVertexInputBindingDescription2EXT &bind : description.bindings) {
387 void build_rasterization_state(
const VKGraphicsInfo::Shaders &shaders_info,
388 const VKExtensions &extensions)
392 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
396 if (extensions.provoking_vertex) {
399 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_PROVOKING_VERTEX_STATE_CREATE_INFO_EXT;
402 VK_PROVOKING_VERTEX_MODE_LAST_VERTEX_EXT :
403 VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT;
411 if (!extensions.extended_dynamic_state && !shaders_info.state.invert_facing) {
415 if (extensions.line_rasterization) {
419 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT;
421 VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
432 void build_dynamic_state(
const VKGraphicsInfo::Shaders &shaders_info,
433 const VKExtensions &extensions,
434 const VKWorkarounds &workarounds)
438 if (!workarounds.static_viewport_scissor) {
442 const bool is_line_topology =
ELEM(shaders_info.vk_topology,
443 VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
444 VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY,
445 VK_PRIMITIVE_TOPOLOGY_LINE_STRIP);
446 if (is_line_topology) {
449 if (shaders_info.has_stencil && shaders_info.state.stencil_test !=
GPU_STENCIL_NONE) {
454 if (extensions.extended_dynamic_state) {
457 if (extensions.vertex_input_dynamic_state) {
467 void build_dynamic_state_for_vertex_input(
const VKExtensions &extensions)
469 if (extensions.vertex_input_dynamic_state) {
479 void build_depth_stencil_state(
const VKGraphicsInfo::Shaders &shaders_info)
482 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO};
483 if (shaders_info.has_depth) {
487 (shaders_info.state.write_mask &
GPU_WRITE_DEPTH) ? VK_TRUE : VK_FALSE;
490 switch (shaders_info.state.depth_test) {
505 VK_COMPARE_OP_GREATER_OR_EQUAL;
517 if (shaders_info.has_stencil) {
521 switch (shaders_info.state.stencil_test) {
540 switch (shaders_info.state.stencil_op) {
552 VK_STENCIL_OP_DECREMENT_AND_WRAP;
557 VK_STENCIL_OP_INCREMENT_AND_WRAP;
564 VK_STENCIL_OP_INCREMENT_AND_WRAP;
568 VK_STENCIL_OP_DECREMENT_AND_WRAP;
583 void build_dynamic_rendering(
const VKGraphicsInfo::FragmentOut &fragment_output_info)
586 VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
589 uint32_t(fragment_output_info.color_attachment_formats.size()),
590 fragment_output_info.color_attachment_formats.data(),
591 fragment_output_info.depth_attachment_format,
592 fragment_output_info.stencil_attachment_format};
600 void build_dynamic_rendering_shaders_lib(
const VKExtensions &extensions,
601 const VKGraphicsInfo::Shaders &shaders_info)
604 if (extensions.dynamic_rendering_local_read && shaders_info.max_input_attachment_index > 0) {
605 const uint32_t color_attachment_count = shaders_info.color_attachment_count;
613 VK_STRUCTURE_TYPE_RENDERING_INPUT_ATTACHMENT_INDEX_INFO;
619 void build_color_blend_attachment_states(
const VKGraphicsInfo::FragmentOut &fragment_output_info)
621 VkPipelineColorBlendAttachmentState attachment_state = {VK_TRUE,
622 VK_BLEND_FACTOR_DST_ALPHA,
625 VK_BLEND_FACTOR_ZERO,
626 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
630 switch (fragment_output_info.state.blend) {
633 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
634 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
635 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
636 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
640 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
641 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
642 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
643 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
647 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
648 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
649 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
650 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
658 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
659 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
660 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
661 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
665 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_DST_COLOR;
666 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
667 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA;
668 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
672 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
673 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
674 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
675 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
679 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
680 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
681 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
682 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
686 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
687 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
688 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
689 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
693 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
694 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
695 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
696 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
700 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
701 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_SRC1_COLOR;
702 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
703 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_SRC1_ALPHA;
707 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ZERO;
708 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
709 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
710 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
714 attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
715 attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
716 attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
717 attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
722 attachment_state.alphaBlendOp = VK_BLEND_OP_MIN;
723 attachment_state.colorBlendOp = VK_BLEND_OP_MIN;
725 else if (fragment_output_info.state.blend ==
GPU_BLEND_MAX) {
726 attachment_state.alphaBlendOp = VK_BLEND_OP_MAX;
727 attachment_state.colorBlendOp = VK_BLEND_OP_MAX;
730 attachment_state.alphaBlendOp = VK_BLEND_OP_REVERSE_SUBTRACT;
731 attachment_state.colorBlendOp = VK_BLEND_OP_REVERSE_SUBTRACT;
734 attachment_state.alphaBlendOp = VK_BLEND_OP_ADD;
735 attachment_state.colorBlendOp = VK_BLEND_OP_ADD;
739 attachment_state.blendEnable = VK_TRUE;
742 attachment_state.blendEnable = VK_FALSE;
746 if ((fragment_output_info.state.write_mask &
GPU_WRITE_RED) != 0) {
747 attachment_state.colorWriteMask |= VK_COLOR_COMPONENT_R_BIT;
750 attachment_state.colorWriteMask |= VK_COLOR_COMPONENT_G_BIT;
752 if ((fragment_output_info.state.write_mask &
GPU_WRITE_BLUE) != 0) {
753 attachment_state.colorWriteMask |= VK_COLOR_COMPONENT_B_BIT;
756 attachment_state.colorWriteMask |= VK_COLOR_COMPONENT_A_BIT;
760 attachment_state, fragment_output_info.color_attachment_formats.size());
763 void build_color_blend_state()
766 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
773 {1.0f, 1.0f, 1.0f, 1.0f}};