From a0e1319aef0da6ffcd5efd55a54926469bdccfdf Mon Sep 17 00:00:00 2001 From: InkSoul Date: Tue, 5 Mar 2024 00:09:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8D=95=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E7=AE=A1=E7=BA=BF=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VulkanTutorial.cpp | 29 +++++++++++++++++++++++++++++ VulkanTutorial.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/VulkanTutorial.cpp b/VulkanTutorial.cpp index cb3dc3e..37abcc4 100644 --- a/VulkanTutorial.cpp +++ b/VulkanTutorial.cpp @@ -133,6 +133,8 @@ void HelloTriangleApplication::cleanup(GLFWwindow* window) { std::cout << "\nstart to destroy resource\n" << std::endl; + + vkDestroyPipeline(device, graphicsPipeline, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyRenderPass(device, renderPass, nullptr); @@ -791,6 +793,33 @@ void HelloTriangleApplication::createGraphicPipeline() throw std::runtime_error("failed to create pipeline Layout in createGraphicPipeline"); } + VkGraphicsPipelineCreateInfo pipelineInfo{}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages; + + pipelineInfo.pVertexInputState = &vertexInputInfo; + pipelineInfo.pInputAssemblyState = &inputAsseblyState; + pipelineInfo.pViewportState = &viewportState; + pipelineInfo.pRasterizationState = &rasterizer; + pipelineInfo.pMultisampleState = &multisampling; + pipelineInfo.pDepthStencilState = nullptr; + pipelineInfo.pColorBlendState = &colorBlendState; + pipelineInfo.pDynamicState = &dynamicState; + // + pipelineInfo.layout = pipelineLayout; + pipelineInfo.renderPass = renderPass; + pipelineInfo.subpass = 0; + + pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; + pipelineInfo.basePipelineIndex = -1; + + + if (vkCreateGraphicsPipelines(device,VK_NULL_HANDLE,1,&pipelineInfo,nullptr,&graphicsPipeline) != VK_SUCCESS) + { + throw std::runtime_error("failed to create graphics pipeline in createGraphicPipeline"); + } + // 管道创建完成后销毁着色器模块 vkDestroyShaderModule(device, fragShaderModule, nullptr); vkDestroyShaderModule(device, vertShaderModule, nullptr); diff --git a/VulkanTutorial.h b/VulkanTutorial.h index d49b886..64c8bdc 100644 --- a/VulkanTutorial.h +++ b/VulkanTutorial.h @@ -66,6 +66,8 @@ private: VkRenderPass renderPass; VkPipelineLayout pipelineLayout; + VkPipeline graphicsPipeline; + struct QueueFamilyIndices { std::optional graphicsFamily;