1 | # Create graphic pipeline
|
---|
2 | vertex_input_create = VkPipelineVertexInputStateCreateInfo(
|
---|
3 | sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
---|
4 | flags = 0,
|
---|
5 | vertexBindingDescriptionCount = 1,
|
---|
6 | pVertexBindingDescriptions = buffers.standard.description,
|
---|
7 | vertexAttributeDescriptionCount = len(buffers.standard.attributes),
|
---|
8 | pVertexAttributeDescriptions = buffers.standard.attributes);
|
---|
9 |
|
---|
10 | input_assembly_create = VkPipelineInputAssemblyStateCreateInfo(
|
---|
11 | sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
---|
12 | flags = 0,
|
---|
13 | topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
---|
14 | primitiveRestartEnable = VK_FALSE);
|
---|
15 | viewport = VkViewport(
|
---|
16 | x = 0., y = 0., width = float(self.extent.width), height = float(self.extent.height),
|
---|
17 | minDepth = 0., maxDepth = 1.);
|
---|
18 |
|
---|
19 | scissor_offset = VkOffset2D(x = 0, y = 0);
|
---|
20 | scissor = VkRect2D(offset = scissor_offset, extent = self.extent);
|
---|
21 | viewport_state_create = VkPipelineViewportStateCreateInfo(
|
---|
22 | sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
---|
23 | flags = 0,
|
---|
24 | viewportCount = 1,
|
---|
25 | pViewports = [viewport],
|
---|
26 | scissorCount = 1,
|
---|
27 | pScissors = [scissor]);
|
---|
28 |
|
---|
29 | rasterizer_create = VkPipelineRasterizationStateCreateInfo(
|
---|
30 | sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
---|
31 | flags = 0,
|
---|
32 | depthClampEnable = VK_FALSE,
|
---|
33 | rasterizerDiscardEnable = VK_FALSE,
|
---|
34 | polygonMode = VK_POLYGON_MODE_FILL,
|
---|
35 | lineWidth = 1,
|
---|
36 | cullMode = VK_CULL_MODE_NONE, #VK_CULL_MODE_BACK_BIT,
|
---|
37 | frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, #VK_FRONT_FACE_CLOCKWISE,
|
---|
38 | depthBiasEnable = VK_FALSE,
|
---|
39 | depthBiasConstantFactor = 0.,
|
---|
40 | depthBiasClamp = 0.,
|
---|
41 | depthBiasSlopeFactor = 0.);
|
---|
42 |
|
---|
43 | multisample_create = VkPipelineMultisampleStateCreateInfo(
|
---|
44 | sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
---|
45 | flags = 0,
|
---|
46 | sampleShadingEnable = VK_TRUE,
|
---|
47 | rasterizationSamples = 2 * *self.config["multisamplelevel"],
|
---|
48 | minSampleShading = 1,
|
---|
49 | pSampleMask = None,
|
---|
50 | alphaToCoverageEnable = VK_FALSE,
|
---|
51 | alphaToOneEnable = VK_FALSE);
|
---|
52 |
|
---|
53 | color_blend_attachement = VkPipelineColorBlendAttachmentState(
|
---|
54 | colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
|
---|
55 | blendEnable = VK_FALSE,
|
---|
56 | srcColorBlendFactor = VK_BLEND_FACTOR_SRC_COLOR,
|
---|
57 | dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
|
---|
58 | colorBlendOp = VK_BLEND_OP_ADD,
|
---|
59 | #srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
---|
60 | #dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
---|
61 | alphaBlendOp = VK_BLEND_OP_ADD);
|
---|
62 |
|
---|
63 | color_blend_create = VkPipelineColorBlendStateCreateInfo(
|
---|
64 | sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
---|
65 | flags = 0,
|
---|
66 | logicOpEnable = VK_FALSE,
|
---|
67 | logicOp = VK_LOGIC_OP_COPY,
|
---|
68 | attachmentCount = 1,
|
---|
69 | pAttachments = [color_blend_attachement],
|
---|
70 | blendConstants = [0, 0, 0, 0]);
|
---|
71 |
|
---|
72 | push_constant_ranges = VkPushConstantRange(
|
---|
73 | stageFlags = 0,
|
---|
74 | offset = 0,
|
---|
75 | size = 0);
|
---|
76 |
|
---|
77 | samplerlayoutbinding = VkDescriptorSetLayoutBinding(
|
---|
78 | binding = 1,
|
---|
79 | descriptorCount = 1,
|
---|
80 | descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
---|
81 | pImmutableSamplers = None,
|
---|
82 | stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
|
---|
83 |
|
---|
84 | );
|
---|
85 |
|
---|
86 | layoutbindings = [ubo.descriptor, samplerlayoutbinding];
|
---|
87 |
|
---|
88 | layoutinfo = VkDescriptorSetLayoutCreateInfo(
|
---|
89 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
---|
90 | bindingCount = len(layoutbindings),
|
---|
91 | pBindings = layoutbindings,
|
---|
92 |
|
---|
93 | );
|
---|
94 | self.descriptorsetlayout = vkCreateDescriptorSetLayout(self.logical_device, layoutinfo, None);
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 | pipeline_layout_create = VkPipelineLayoutCreateInfo(
|
---|
99 | sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
---|
100 | flags = 0,
|
---|
101 | setLayoutCount = 1,
|
---|
102 | pSetLayouts = [self.descriptorsetlayout],
|
---|
103 | pushConstantRangeCount = 0,
|
---|
104 | pPushConstantRanges = [push_constant_ranges]);
|
---|
105 |
|
---|
106 | self.pipeline_layout = vkCreatePipelineLayout(self.logical_device, pipeline_layout_create, None);
|
---|
107 |
|
---|
108 | depthstencil = VkPipelineDepthStencilStateCreateInfo(
|
---|
109 | sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
---|
110 | depthTestEnable = VK_TRUE,
|
---|
111 | depthWriteEnable = VK_TRUE,
|
---|
112 | depthCompareOp = VK_COMPARE_OP_LESS,
|
---|
113 | depthBoundsTestEnable = VK_FALSE,
|
---|
114 | minDepthBounds = 0,
|
---|
115 | maxDepthBounds = 1,
|
---|
116 | stencilTestEnable = VK_FALSE,
|
---|
117 | );
|
---|
118 |
|
---|
119 | # Finally create graphic pipeline
|
---|
120 | pipeline_create = VkGraphicsPipelineCreateInfo(
|
---|
121 | sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
---|
122 | flags = 0,
|
---|
123 | stageCount = 2,
|
---|
124 | pStages = [shaders.shaderlibrary["orthogonal_vert"].pipelinebit, shaders.shaderlibrary["generic_frag"].pipelinebit],
|
---|
125 | pVertexInputState = vertex_input_create,
|
---|
126 | pInputAssemblyState = input_assembly_create,
|
---|
127 | pTessellationState = None,
|
---|
128 | pViewportState = viewport_state_create,
|
---|
129 | pRasterizationState = rasterizer_create,
|
---|
130 | pMultisampleState = multisample_create,
|
---|
131 | pDepthStencilState = depthstencil,
|
---|
132 | pColorBlendState = color_blend_create,
|
---|
133 | pDynamicState = None,
|
---|
134 | layout = self.pipeline_layout,
|
---|
135 | renderPass = self.render_pass.render_pass,
|
---|
136 | subpass = 0,
|
---|
137 | basePipelineHandle = None,
|
---|
138 | basePipelineIndex = -1);
|
---|
139 |
|
---|
140 | self.pipeline = vkCreateGraphicsPipelines(self.logical_device, None, 1, [pipeline_create], None); |
---|