29 const std::vector<char> vertCode = readFile(vertFilepath);
30 const std::vector<char> fragCode = readFile(fragFilepath);
32 createShaderModule(vertCode, &m_vertShaderModule);
33 createShaderModule(fragCode, &m_fragShaderModule);
35 std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages{};
36 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
37 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
38 shaderStages[0].module = m_vertShaderModule;
39 shaderStages[0].pName =
"main";
40 shaderStages[0].flags = 0;
41 shaderStages[0].pNext =
nullptr;
42 shaderStages[0].pSpecializationInfo =
nullptr;
44 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
45 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
46 shaderStages[1].module = m_fragShaderModule;
47 shaderStages[1].pName =
"main";
48 shaderStages[1].flags = 0;
49 shaderStages[1].pNext =
nullptr;
50 shaderStages[1].pSpecializationInfo =
nullptr;
54 VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
55 vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
56 vertexInputInfo.vertexAttributeDescriptionCount =
static_cast<uint32_t
>(attributeDescriptions.size());
57 vertexInputInfo.vertexBindingDescriptionCount =
static_cast<uint32_t
>(bindingDescriptions.size());
58 vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
59 vertexInputInfo.pVertexBindingDescriptions = bindingDescriptions.data();
62 VkPipelineViewportStateCreateInfo viewportInfo{};
63 viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
64 viewportInfo.viewportCount = 1;
65 viewportInfo.pViewports =
nullptr;
66 viewportInfo.scissorCount = 1;
67 viewportInfo.pScissors =
nullptr;
70 VkGraphicsPipelineCreateInfo pipelineInfo{};
71 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
72 pipelineInfo.stageCount = 2;
73 pipelineInfo.pStages = shaderStages.data();
74 pipelineInfo.pVertexInputState = &vertexInputInfo;
76 pipelineInfo.pViewportState = &viewportInfo;
85 pipelineInfo.renderPass = configInfo.
renderPass;
86 pipelineInfo.subpass = configInfo.
subpass;
88 pipelineInfo.basePipelineIndex = -1;
89 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
91 if (vkCreateGraphicsPipelines(m_device.device(), VK_NULL_HANDLE, 1, &pipelineInfo,
nullptr, &m_graphicsPipeline) != VK_SUCCESS) {
92 throw std::runtime_error(
"failed to create graphics pipeline");
110 configInfo.
inputAssemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
114 configInfo.
rasterizationInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
126 configInfo.
multisampleInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
128 configInfo.
multisampleInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
134 configInfo.
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
143 configInfo.
colorBlendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
153 configInfo.
depthStencilInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
165 configInfo.
dynamicStateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;