33 const std::vector<char> vertCode = readFile(vertFilepath);
34 const std::vector<char> fragCode = readFile(fragFilepath);
36 createShaderModule(vertCode, &m_vertShaderModule);
37 createShaderModule(fragCode, &m_fragShaderModule);
39 VkPipelineShaderStageCreateInfo shaderStages[2];
40 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
41 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
42 shaderStages[0].module = m_vertShaderModule;
43 shaderStages[0].pName =
"main";
44 shaderStages[0].flags = 0;
45 shaderStages[0].pNext =
nullptr;
46 shaderStages[0].pSpecializationInfo =
nullptr;
48 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
49 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
50 shaderStages[1].module = m_fragShaderModule;
51 shaderStages[1].pName =
"main";
52 shaderStages[1].flags = 0;
53 shaderStages[1].pNext =
nullptr;
54 shaderStages[1].pSpecializationInfo =
nullptr;
58 VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
59 vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
60 vertexInputInfo.vertexAttributeDescriptionCount =
static_cast<uint32_t
>(attributeDescriptions.size());
61 vertexInputInfo.vertexBindingDescriptionCount =
static_cast<uint32_t
>(bindingDescriptions.size());
62 vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
63 vertexInputInfo.pVertexBindingDescriptions = bindingDescriptions.data();
66 VkPipelineViewportStateCreateInfo viewportInfo{};
67 viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
68 viewportInfo.viewportCount = 1;
69 viewportInfo.pViewports =
nullptr;
70 viewportInfo.scissorCount = 1;
71 viewportInfo.pScissors =
nullptr;
74 VkGraphicsPipelineCreateInfo pipelineInfo{};
75 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
76 pipelineInfo.stageCount = 2;
77 pipelineInfo.pStages = shaderStages;
78 pipelineInfo.pVertexInputState = &vertexInputInfo;
80 pipelineInfo.pViewportState = &viewportInfo;
89 pipelineInfo.renderPass = configInfo.
renderPass;
90 pipelineInfo.subpass = configInfo.
subpass;
92 pipelineInfo.basePipelineIndex = -1;
93 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
95 if (vkCreateGraphicsPipelines(m_device.device(), VK_NULL_HANDLE, 1, &pipelineInfo,
nullptr, &m_graphicsPipeline) != VK_SUCCESS) {
96 throw std::runtime_error(
"failed to create graphics pipeline");
114 configInfo.
inputAssemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
118 configInfo.
rasterizationInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
130 configInfo.
multisampleInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
132 configInfo.
multisampleInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
138 configInfo.
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
147 configInfo.
colorBlendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
157 configInfo.
depthStencilInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
169 configInfo.
dynamicStateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;