83 = getPipelineAttributes();
85 VkShaderModule vertShaderModule
87 VkShaderModule fragShaderModule
90 VkPipelineShaderStageCreateInfo vertShaderStageInfo {};
91 vertShaderStageInfo.sType
92 = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
93 vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
94 vertShaderStageInfo.module = vertShaderModule;
95 vertShaderStageInfo.pName
98 VkPipelineShaderStageCreateInfo fragShaderStageInfo {};
99 fragShaderStageInfo.sType
100 = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
101 fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
102 fragShaderStageInfo.module = fragShaderModule;
103 fragShaderStageInfo.pName =
"main";
105 VkPipelineShaderStageCreateInfo shaderStages[]
106 = { vertShaderStageInfo, fragShaderStageInfo };
111 VkPipelineVertexInputStateCreateInfo vertexInputInfo {};
112 vertexInputInfo.sType
113 = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
114 vertexInputInfo.vertexBindingDescriptionCount
115 =
static_cast<uint32_t
>(bindingDescription.size());
116 vertexInputInfo.vertexAttributeDescriptionCount
117 =
static_cast<uint32_t
>(attributeDescriptions.size());
118 vertexInputInfo.pVertexBindingDescriptions = bindingDescription.data();
119 vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
121 VkPipelineInputAssemblyStateCreateInfo inputAssembly {};
123 = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
124 inputAssembly.topology
127 inputAssembly.primitiveRestartEnable = VK_FALSE;
129 VkViewport viewport {};
132 viewport.width = (float)(*swapChain).swapChainExtent.width;
133 viewport.height = (float)(*swapChain).swapChainExtent.height;
134 viewport.minDepth = 0.0f;
135 viewport.maxDepth = 1.0f;
138 scissor.offset = { 0, 0 };
139 scissor.extent = (*swapChain).swapChainExtent;
141 VkPipelineViewportStateCreateInfo viewportState {};
142 viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
143 viewportState.viewportCount = 1;
144 viewportState.pViewports = &viewport;
145 viewportState.scissorCount = 1;
146 viewportState.pScissors = &scissor;
148 VkPipelineRasterizationStateCreateInfo rasterizer {};
150 = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
151 rasterizer.depthClampEnable = VK_FALSE;
152 rasterizer.rasterizerDiscardEnable = VK_FALSE;
153 rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
154 rasterizer.lineWidth = 1.0f;
155 rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
156 rasterizer.frontFace = pipelineAttributes.
frontFace;
157 rasterizer.depthBiasEnable = VK_FALSE;
158 rasterizer.depthBiasConstantFactor = 0.0f;
159 rasterizer.depthBiasClamp = 0.0f;
160 rasterizer.depthBiasSlopeFactor = 0.0f;
162 VkPipelineMultisampleStateCreateInfo multisampling {};
164 = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
165 multisampling.sampleShadingEnable = VK_FALSE;
166 multisampling.rasterizationSamples = device->msaaSamples;
167 multisampling.minSampleShading = 1.0f;
168 multisampling.pSampleMask =
nullptr;
169 multisampling.alphaToCoverageEnable = VK_FALSE;
170 multisampling.alphaToOneEnable = VK_FALSE;
171 multisampling.sampleShadingEnable = VK_TRUE;
173 VkPipelineColorBlendStateCreateInfo colorBlending {};
175 = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
176 colorBlending.logicOpEnable = VK_FALSE;
177 colorBlending.logicOp = VK_LOGIC_OP_COPY;
178 colorBlending.attachmentCount = 1;
180 colorBlending.blendConstants[0] = 0.0f;
181 colorBlending.blendConstants[1] = 0.0f;
182 colorBlending.blendConstants[2] = 0.0f;
183 colorBlending.blendConstants[3] = 0.0f;
185 std::vector<VkDynamicState> dynamicStates
186 = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
187 VkPipelineDynamicStateCreateInfo dynamicState {};
188 dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
189 dynamicState.dynamicStateCount
190 =
static_cast<uint32_t
>(dynamicStates.size());
191 dynamicState.pDynamicStates = dynamicStates.data();
193 VkPipelineLayoutCreateInfo pipelineLayoutInfo {};
194 pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
195 pipelineLayoutInfo.setLayoutCount = 1;
196 pipelineLayoutInfo.pSetLayouts = &descriptorSetLayout;
197 pipelineLayoutInfo.pushConstantRangeCount = 0;
198 pipelineLayoutInfo.pPushConstantRanges =
nullptr;
200 if (vkCreatePipelineLayout(
201 device->device, &pipelineLayoutInfo,
nullptr, &pipelineLayout)
203 throw std::runtime_error(
"failed to create pipeline layout!");
206 VkGraphicsPipelineCreateInfo pipelineInfo {};
207 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
208 pipelineInfo.stageCount = 2;
209 pipelineInfo.pStages = shaderStages;
210 pipelineInfo.pVertexInputState = &vertexInputInfo;
211 pipelineInfo.pInputAssemblyState = &inputAssembly;
212 pipelineInfo.pViewportState = &viewportState;
213 pipelineInfo.pRasterizationState = &rasterizer;
214 pipelineInfo.pMultisampleState = &multisampling;
215 pipelineInfo.pDepthStencilState =
nullptr;
216 pipelineInfo.pColorBlendState = &colorBlending;
217 pipelineInfo.pDynamicState = &dynamicState;
218 pipelineInfo.layout = pipelineLayout;
219 pipelineInfo.renderPass = *renderPass;
220 pipelineInfo.subpass = 0;
221 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
222 pipelineInfo.basePipelineIndex = -1;
224 if (vkCreateGraphicsPipelines(device->device, VK_NULL_HANDLE, 1,
225 &pipelineInfo,
nullptr, &graphicsPipeline)
227 throw std::runtime_error(
"failed to create graphics pipeline!");
231 vkDestroyShaderModule(device->device, fragShaderModule,
nullptr);
232 vkDestroyShaderModule(device->device, vertShaderModule,
nullptr);