diff --git a/dl/vk/dl_vk.cpp b/dl/vk/dl_vk.cpp index d6aca26d..fdc0f3b9 100644 --- a/dl/vk/dl_vk.cpp +++ b/dl/vk/dl_vk.cpp @@ -46,8 +46,8 @@ void VK::_init(GLFWwindow* window) _create_descriptor_set_layout_texture(); // 1 _create_descriptor_set_layout_bone(); // 2 - _create_graphics_pipeline(); - _create_graphics_pipeline_bone(); + _create_pipeline_layout_3d(); + _create_pipeline_layout_bone(); _create_command_pool(); _create_color_resources(); @@ -100,6 +100,9 @@ void VK::_init(GLFWwindow* window) _create_gfx(); _create_skybox(); _create_shadow(); + + + _create_pipeline_all(); } void VK::_check_extension() @@ -242,7 +245,7 @@ void VK::_create_physical_device() if (_is_device_suitable(iter)) { _physicalDevice = iter; - _msaaSamples = GetMaxUsableSampleCount(); + _param._msaaLevel = GetMaxUsableSampleCount(); break; } } @@ -651,7 +654,7 @@ void VK::_create_render_pass() // color VkAttachmentDescription colorAttachment{}; colorAttachment.format = _formatSwapChainImage; - colorAttachment.samples = _msaaSamples; + colorAttachment.samples = _param._msaaLevel; colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; @@ -665,7 +668,7 @@ void VK::_create_render_pass() // depth VkAttachmentDescription depthAttachment{}; depthAttachment.format = FindDepthFormat(); - depthAttachment.samples = _msaaSamples; + depthAttachment.samples = _param._msaaLevel; depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; @@ -729,115 +732,8 @@ void VK::_create_render_pass() } } -void VK::_create_graphics_pipeline() +void VK::_create_pipeline_layout_3d() { - // 加载shader文件 - Buffer vertShaderCode = File::GetBuffer("dl/shader/3d_vert.spv"); - Buffer fragShaderCode = File::GetBuffer("dl/shader/3d_frag.spv"); - // 创建shader模块 - VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); - VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); - - VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; - vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; - vertShaderStageInfo.module = vertShaderModule; - vertShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; - fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragShaderStageInfo.module = fragShaderModule; - fragShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; - - //顶点输入状态 - auto bindingDescription = Vertex::getBindingDescription(); - auto attributeDescriptions = Vertex::getAttributeDescriptions(); - - VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; - vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = 1; - vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional - vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); - vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional - - //顶点装配状态 - VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; - inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - inputAssembly.primitiveRestartEnable = VK_FALSE; - - //管线动态状态 - std::vector dynamicStates = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - - VkPipelineDynamicStateCreateInfo dynamicState{}; - dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); - dynamicState.pDynamicStates = dynamicStates.data(); - - VkPipelineViewportStateCreateInfo viewportState{}; - viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewportState.viewportCount = 1; - viewportState.scissorCount = 1; - - //光栅器状态 - VkPipelineRasterizationStateCreateInfo rasterizer{}; - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterizer.depthClampEnable = VK_FALSE; - rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; - rasterizer.lineWidth = 1.0f; - rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; - rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - rasterizer.depthBiasEnable = VK_FALSE; - rasterizer.depthBiasConstantFactor = 0.0f; // Optional - rasterizer.depthBiasClamp = 0.0f; // Optional - rasterizer.depthBiasSlopeFactor = 0.0f; // Optional - - //多重采样状态 - VkPipelineMultisampleStateCreateInfo multisampling{}; - multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisampling.sampleShadingEnable = VK_FALSE; - multisampling.rasterizationSamples = _msaaSamples; - multisampling.minSampleShading = 1.0f; // Optional - multisampling.pSampleMask = nullptr; // Optional - multisampling.alphaToCoverageEnable = VK_FALSE; // Optional - multisampling.alphaToOneEnable = VK_FALSE; // Optional - if (OPEN_SAMPLE_SHADING) - { - multisampling.sampleShadingEnable = VK_TRUE; - // min fraction for sample shading; closer to one is smooth - multisampling.minSampleShading = .2f; - } - //混合模式 - VkPipelineColorBlendAttachmentState colorBlendAttachment{}; - colorBlendAttachment.colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT - | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlendAttachment.blendEnable = VK_TRUE; - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; - - VkPipelineColorBlendStateCreateInfo colorBlending{}; - colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlending.logicOpEnable = VK_FALSE;//启用后会禁用前者 - colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional - colorBlending.attachmentCount = 1; - colorBlending.pAttachments = &colorBlendAttachment; - colorBlending.blendConstants[0] = 0.0f; // Optional - colorBlending.blendConstants[1] = 0.0f; // Optional - colorBlending.blendConstants[2] = 0.0f; // Optional - colorBlending.blendConstants[3] = 0.0f; // Optional - // 推送常量区 VkPushConstantRange pushConstantRange{}; pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; @@ -863,159 +759,10 @@ void VK::_create_graphics_pipeline() log_damage0("创建管线布局失败!"); return; } - - // 深度模板状态 - VkPipelineDepthStencilStateCreateInfo depthStencil{}; - depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depthStencil.depthTestEnable = VK_TRUE; - depthStencil.depthWriteEnable = VK_TRUE; - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; - depthStencil.depthBoundsTestEnable = VK_FALSE; - depthStencil.minDepthBounds = 0.0f; // Optional - depthStencil.maxDepthBounds = 1.0f; // Optional - depthStencil.stencilTestEnable = VK_FALSE; - depthStencil.front = {}; // Optional - depthStencil.back = {}; // Optional - - // 图形管线 - VkGraphicsPipelineCreateInfo pipelineInfo{}; - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages;//引用shader - pipelineInfo.pVertexInputState = &vertexInputInfo; - pipelineInfo.pInputAssemblyState = &inputAssembly; - pipelineInfo.pViewportState = &viewportState; - pipelineInfo.pRasterizationState = &rasterizer; - pipelineInfo.pMultisampleState = &multisampling; - pipelineInfo.pDepthStencilState = &depthStencil; - pipelineInfo.pColorBlendState = &colorBlending; - pipelineInfo.pDynamicState = &dynamicState; - pipelineInfo.layout = _pipelineLayout;//布局 - pipelineInfo.renderPass = _renderPass;//渲染流程 - pipelineInfo.subpass = 0; - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional - pipelineInfo.basePipelineIndex = -1; // Optional - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipeline) != VK_SUCCESS) - { - log_damage0("图形管线创建失败!"); - return; - } - - //资源释放 - vkDestroyShaderModule(_device, fragShaderModule, nullptr); - vkDestroyShaderModule(_device, vertShaderModule, nullptr); } -void VK::_create_graphics_pipeline_skybox() +void VK::_create_pipeline_layout_skybox() { - // 加载shader文件 - Buffer vertShaderCode = File::GetBuffer("dl/shader/skybox_vert.spv"); - Buffer fragShaderCode = File::GetBuffer("dl/shader/skybox_frag.spv"); - // 创建shader模块 - VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); - VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); - - VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; - vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; - vertShaderStageInfo.module = vertShaderModule; - vertShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; - fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragShaderStageInfo.module = fragShaderModule; - fragShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; - - // 顶点输入状态 - auto bindingDescription = VertexSkybox::getBindingDescription(); - auto attributeDescriptions = VertexSkybox::getAttributeDescriptions(); - - VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; - vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = 1; - vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional - vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); - vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional - - // 顶点装配状态 - VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; - inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - inputAssembly.primitiveRestartEnable = VK_FALSE; - - // 管线动态状态 - std::vector dynamicStates = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - - VkPipelineDynamicStateCreateInfo dynamicState{}; - dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); - dynamicState.pDynamicStates = dynamicStates.data(); - - VkPipelineViewportStateCreateInfo viewportState{}; - viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewportState.viewportCount = 1; - viewportState.scissorCount = 1; - - // 光栅器状态 - VkPipelineRasterizationStateCreateInfo rasterizer{}; - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterizer.depthClampEnable = VK_FALSE; - rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; - rasterizer.lineWidth = 1.0f; - rasterizer.cullMode = VK_CULL_MODE_NONE; - rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - rasterizer.depthBiasEnable = VK_FALSE; - rasterizer.depthBiasConstantFactor = 0.0f; // Optional - rasterizer.depthBiasClamp = 0.0f; // Optional - rasterizer.depthBiasSlopeFactor = 0.0f; // Optional - - // 多重采样状态 - VkPipelineMultisampleStateCreateInfo multisampling{}; - multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisampling.sampleShadingEnable = VK_FALSE; - multisampling.rasterizationSamples = _msaaSamples; - multisampling.minSampleShading = 1.0f; // Optional - multisampling.pSampleMask = nullptr; // Optional - multisampling.alphaToCoverageEnable = VK_FALSE; // Optional - multisampling.alphaToOneEnable = VK_FALSE; // Optional - if (OPEN_SAMPLE_SHADING) - { - multisampling.sampleShadingEnable = VK_TRUE; - // min fraction for sample shading; closer to one is smooth - multisampling.minSampleShading = .2f; - } - // 混合模式 - VkPipelineColorBlendAttachmentState colorBlendAttachment{}; - colorBlendAttachment.colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT - | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlendAttachment.blendEnable = VK_FALSE; - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; - - VkPipelineColorBlendStateCreateInfo colorBlending{}; - colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlending.logicOpEnable = VK_FALSE;// 启用后会禁用前者 - colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional - colorBlending.attachmentCount = 1; - colorBlending.pAttachments = &colorBlendAttachment; - colorBlending.blendConstants[0] = 0.0f; // Optional - colorBlending.blendConstants[1] = 0.0f; // Optional - colorBlending.blendConstants[2] = 0.0f; // Optional - colorBlending.blendConstants[3] = 0.0f; // Optional - // 管线布局 std::array dsp_set_layout = { _skybox._descriptorSetLayout @@ -1033,54 +780,6 @@ void VK::_create_graphics_pipeline_skybox() log_damage0("创建管线布局(skybox)失败!"); return; } - - // 深度模板状态 - VkPipelineDepthStencilStateCreateInfo depthStencil{}; - depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depthStencil.depthTestEnable = VK_TRUE; - depthStencil.depthWriteEnable = VK_FALSE; - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; - depthStencil.depthBoundsTestEnable = VK_FALSE; - depthStencil.minDepthBounds = 0.0f; // Optional - depthStencil.maxDepthBounds = 1.0f; // Optional - depthStencil.stencilTestEnable = VK_FALSE; - depthStencil.front = {}; // Optional - depthStencil.back = {}; // Optional - - // 图形管线 - VkGraphicsPipelineCreateInfo pipelineInfo{}; - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages;//引用shader - pipelineInfo.pVertexInputState = &vertexInputInfo; - pipelineInfo.pInputAssemblyState = &inputAssembly; - pipelineInfo.pViewportState = &viewportState; - pipelineInfo.pRasterizationState = &rasterizer; - pipelineInfo.pMultisampleState = &multisampling; - pipelineInfo.pDepthStencilState = &depthStencil; - pipelineInfo.pColorBlendState = &colorBlending; - pipelineInfo.pDynamicState = &dynamicState; - pipelineInfo.layout = _skybox._pipelineLayout;//布局 - pipelineInfo.renderPass = _renderPass;//渲染流程 - pipelineInfo.subpass = 0; - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional - pipelineInfo.basePipelineIndex = -1; // Optional - - // 深度测试 开 <= - // 深度写入 关 - // 关闭剔除 - // 关闭混合 - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_skybox._graphicsPipeline) != VK_SUCCESS) - { - log_damage0("图形管线(skybox)创建失败!"); - return; - } - - // 资源释放 - vkDestroyShaderModule(_device, fragShaderModule, nullptr); - vkDestroyShaderModule(_device, vertShaderModule, nullptr); } void VK::_create_render_pass_shadow() @@ -1145,10 +844,40 @@ void VK::_create_render_pass_shadow() } } -VK::Pipeline VK::_create_graphics_pipeline_shadow(std::string_view vs, std::string_view ps, - VkVertexInputBindingDescription* bind_desc, VkVertexInputAttributeDescription* attr_desc, size_t num_attr) +VkPipelineLayout VK::_create_pipline_layout_shadow() { - Pipeline ret; + VkPipelineLayout ret = VK_NULL_HANDLE; + // 推送常量区 + VkPushConstantRange pushConstantRange{}; + pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + pushConstantRange.offset = 0; + pushConstantRange.size = sizeof(PushConstantCSM); + + // 管线布局 + std::array dsp_set_layout = { + _shadow._descriptorSetLayout, _descriptorSetLayoutTex, _descriptorSetLayoutBone + }; + + VkPipelineLayoutCreateInfo pipelineLayoutInfo{}; + pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipelineLayoutInfo.setLayoutCount = (uint32_t)dsp_set_layout.size(); // Optional + pipelineLayoutInfo.pSetLayouts = dsp_set_layout.data(); // Optional + pipelineLayoutInfo.pushConstantRangeCount = 1; + pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange; + + if (vkCreatePipelineLayout(_device, &pipelineLayoutInfo, nullptr, &ret) != VK_SUCCESS) + { + log_damage0("创建管线布局(shadow)失败!"); + return ret; + } + return ret; +} + +VkPipeline VK::_create_graphics_pipeline_shadow(std::string_view vs, std::string_view ps, + VkVertexInputBindingDescription* bind_desc, VkVertexInputAttributeDescription* attr_desc, size_t num_attr, + VkPipelineLayout layout) +{ + VkPipeline ret; // 加载shader文件 Buffer vertShaderCode = File::GetBuffer(vs); Buffer fragShaderCode = File::GetBuffer(ps); @@ -1253,29 +982,6 @@ VK::Pipeline VK::_create_graphics_pipeline_shadow(std::string_view vs, std::stri colorBlending.attachmentCount = 0; colorBlending.pAttachments = nullptr; - // 推送常量区 - VkPushConstantRange pushConstantRange{}; - pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - pushConstantRange.offset = 0; - pushConstantRange.size = sizeof(PushConstantCSM); - - // 管线布局 - std::array dsp_set_layout = { - _shadow._descriptorSetLayout, _descriptorSetLayoutTex, _descriptorSetLayoutBone - }; - - VkPipelineLayoutCreateInfo pipelineLayoutInfo{}; - pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - pipelineLayoutInfo.setLayoutCount = (uint32_t)dsp_set_layout.size(); // Optional - pipelineLayoutInfo.pSetLayouts = dsp_set_layout.data(); // Optional - pipelineLayoutInfo.pushConstantRangeCount = 1; - pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange; - - if (vkCreatePipelineLayout(_device, &pipelineLayoutInfo, nullptr, &ret._layout) != VK_SUCCESS) - { - log_damage0("创建管线布局(shadow)失败!"); - return ret; - } // 深度模板状态 VkPipelineDepthStencilStateCreateInfo depthStencil{}; @@ -1303,7 +1009,7 @@ VK::Pipeline VK::_create_graphics_pipeline_shadow(std::string_view vs, std::stri pipelineInfo.pDepthStencilState = &depthStencil; pipelineInfo.pColorBlendState = &colorBlending; pipelineInfo.pDynamicState = &dynamicState; - pipelineInfo.layout = ret._layout;//布局 + pipelineInfo.layout = layout;//布局 pipelineInfo.renderPass = _shadow._renderPass;//渲染流程 pipelineInfo.subpass = 0; pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional @@ -1315,7 +1021,7 @@ VK::Pipeline VK::_create_graphics_pipeline_shadow(std::string_view vs, std::stri // 关闭多重采样 if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &ret._pipe) != VK_SUCCESS) + &ret) != VK_SUCCESS) { log_damage0("图形管线(shadow)创建失败!"); return ret; @@ -1427,115 +1133,8 @@ void VK::_create_descriptor_set_layout_shadow() } } -void VK::_create_graphics_pipeline_bone() +void VK::_create_pipeline_layout_bone() { - // 加载shader文件 - Buffer vertShaderCode = File::GetBuffer("dl/shader/3d_bone_vert.spv"); - Buffer fragShaderCode = File::GetBuffer("dl/shader/3d_frag.spv"); - // 创建shader模块 - VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); - VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); - - VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; - vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; - vertShaderStageInfo.module = vertShaderModule; - vertShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; - fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragShaderStageInfo.module = fragShaderModule; - fragShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; - - // 顶点输入状态 - auto bindingDescription = VertexBone::getBindingDescription(); - auto attributeDescriptions = VertexBone::getAttributeDescriptions(); - - VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; - vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = 1; - vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional - vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); - vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional - - // 顶点装配状态 - VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; - inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - inputAssembly.primitiveRestartEnable = VK_FALSE; - - // 管线动态状态 - std::vector dynamicStates = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - - VkPipelineDynamicStateCreateInfo dynamicState{}; - dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); - dynamicState.pDynamicStates = dynamicStates.data(); - - VkPipelineViewportStateCreateInfo viewportState{}; - viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewportState.viewportCount = 1; - viewportState.scissorCount = 1; - - // 光栅器状态 - VkPipelineRasterizationStateCreateInfo rasterizer{}; - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterizer.depthClampEnable = VK_FALSE; - rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; - rasterizer.lineWidth = 1.0f; - rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; - rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - rasterizer.depthBiasEnable = VK_FALSE; - rasterizer.depthBiasConstantFactor = 0.0f; // Optional - rasterizer.depthBiasClamp = 0.0f; // Optional - rasterizer.depthBiasSlopeFactor = 0.0f; // Optional - - // 多重采样状态 - VkPipelineMultisampleStateCreateInfo multisampling{}; - multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisampling.sampleShadingEnable = VK_FALSE; - multisampling.rasterizationSamples = _msaaSamples; - multisampling.minSampleShading = 1.0f; // Optional - multisampling.pSampleMask = nullptr; // Optional - multisampling.alphaToCoverageEnable = VK_FALSE; // Optional - multisampling.alphaToOneEnable = VK_FALSE; // Optional - if (OPEN_SAMPLE_SHADING) - { - multisampling.sampleShadingEnable = VK_TRUE; - // min fraction for sample shading; closer to one is smooth - multisampling.minSampleShading = .2f; - } - // 混合模式 - VkPipelineColorBlendAttachmentState colorBlendAttachment{}; - colorBlendAttachment.colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT - | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlendAttachment.blendEnable = VK_TRUE; - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; - - VkPipelineColorBlendStateCreateInfo colorBlending{}; - colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlending.logicOpEnable = VK_FALSE;// 启用后会禁用前者 - colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional - colorBlending.attachmentCount = 1; - colorBlending.pAttachments = &colorBlendAttachment; - colorBlending.blendConstants[0] = 0.0f; // Optional - colorBlending.blendConstants[1] = 0.0f; // Optional - colorBlending.blendConstants[2] = 0.0f; // Optional - colorBlending.blendConstants[3] = 0.0f; // Optional - // 推送常量区 VkPushConstantRange pushConstantRange{}; pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; @@ -1561,48 +1160,6 @@ void VK::_create_graphics_pipeline_bone() log_damage0("创建管线布局失败!"); return; } - - // 深度模板状态 - VkPipelineDepthStencilStateCreateInfo depthStencil{}; - depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depthStencil.depthTestEnable = VK_TRUE; - depthStencil.depthWriteEnable = VK_TRUE; - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; - depthStencil.depthBoundsTestEnable = VK_FALSE; - depthStencil.minDepthBounds = 0.0f; // Optional - depthStencil.maxDepthBounds = 1.0f; // Optional - depthStencil.stencilTestEnable = VK_FALSE; - depthStencil.front = {}; // Optional - depthStencil.back = {}; // Optional - - // 图形管线 - VkGraphicsPipelineCreateInfo pipelineInfo{}; - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages;// 引用shader - pipelineInfo.pVertexInputState = &vertexInputInfo; - pipelineInfo.pInputAssemblyState = &inputAssembly; - pipelineInfo.pViewportState = &viewportState; - pipelineInfo.pRasterizationState = &rasterizer; - pipelineInfo.pMultisampleState = &multisampling; - pipelineInfo.pDepthStencilState = &depthStencil; - pipelineInfo.pColorBlendState = &colorBlending; - pipelineInfo.pDynamicState = &dynamicState; - pipelineInfo.layout = _pipelineLayoutBone;// 布局 - pipelineInfo.renderPass = _renderPass;// 渲染流程 - pipelineInfo.subpass = 0; - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional - pipelineInfo.basePipelineIndex = -1; // Optional - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipelineBone) != VK_SUCCESS) - { - log_damage0("图形管线创建失败!"); - return; - } - - // 资源释放 - vkDestroyShaderModule(_device, fragShaderModule, nullptr); - vkDestroyShaderModule(_device, vertShaderModule, nullptr); } void VK::_create_frame_buffer() @@ -3857,8 +3414,8 @@ void VK::RenderModel(VkCommandBuffer command_buffer, Model* model, size_t shadow } else { - pipe = !has_skin ? &_shadow._pipeline._pipe : &_shadow._pipelineBone._pipe; - pipe_layout = !has_skin ? &_shadow._pipeline._layout : &_shadow._pipelineBone._layout; + pipe = !has_skin ? &_shadow._pipeline : &_shadow._pipelineBone; + pipe_layout = !has_skin ? &_shadow._layout : &_shadow._layout; } //绑定管线 @@ -3973,125 +3530,8 @@ void VK::_create_2d() log_damage0("创建描述符集合失败!"); return; } - // 1.管线 - // 加载shader文件 - Buffer vertShaderCode = File::GetBuffer("dl/shader/2d_vert.spv"); - Buffer fragShaderCode = File::GetBuffer("dl/shader/2d_frag.spv"); - Buffer fragShaderCodeGray = File::GetBuffer("dl/shader/2d_gray_frag.spv"); - // 创建shader模块 - VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); - VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); - VkShaderModule fragShaderModuleGray = CreateShaderModule(fragShaderCodeGray); - - VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; - vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; - vertShaderStageInfo.module = vertShaderModule; - vertShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; - fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragShaderStageInfo.module = fragShaderModule; - fragShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo fragShaderStageInfoGray{}; - fragShaderStageInfoGray.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - fragShaderStageInfoGray.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragShaderStageInfoGray.module = fragShaderModuleGray; - fragShaderStageInfoGray.pName = "main"; - - VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; - VkPipelineShaderStageCreateInfo shaderStagesGray[] = { vertShaderStageInfo, fragShaderStageInfoGray }; - - // 顶点输入状态 - auto bindingDescription = Vertex2D::getBindingDescription(); - auto attributeDescriptions = Vertex2D::getAttributeDescriptions(); - - VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; - vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = 1; - vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional - vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); - vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional - - // 顶点装配状态 - VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; - inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - inputAssembly.primitiveRestartEnable = VK_FALSE; - - - // 管线动态状态 - std::vector dynamicStates = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - - VkPipelineDynamicStateCreateInfo dynamicState{}; - dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); - dynamicState.pDynamicStates = dynamicStates.data(); - - VkPipelineViewportStateCreateInfo viewportState{}; - viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewportState.viewportCount = 1; - viewportState.scissorCount = 1; - - // 光栅器状态 - VkPipelineRasterizationStateCreateInfo rasterizer{}; - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterizer.depthClampEnable = VK_FALSE; - rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; - rasterizer.lineWidth = 1.0f; - rasterizer.cullMode = VK_CULL_MODE_NONE;//不剔除应该更快 //VK_CULL_MODE_BACK_BIT; - rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;//与3d不同 - rasterizer.depthBiasEnable = VK_FALSE; - rasterizer.depthBiasConstantFactor = 0.0f; // Optional - rasterizer.depthBiasClamp = 0.0f; // Optional - rasterizer.depthBiasSlopeFactor = 0.0f; // Optional - - // 多重采样状态 - VkPipelineMultisampleStateCreateInfo multisampling{}; - multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisampling.sampleShadingEnable = VK_FALSE; - multisampling.rasterizationSamples = _msaaSamples;//必须匹配 - multisampling.minSampleShading = 1.0f; // Optional - multisampling.pSampleMask = nullptr; // Optional - multisampling.alphaToCoverageEnable = VK_FALSE; // Optional - multisampling.alphaToOneEnable = VK_FALSE; // Optional - if (OPEN_SAMPLE_SHADING) - { - multisampling.sampleShadingEnable = VK_TRUE; - // min fraction for sample shading; closer to one is smooth - multisampling.minSampleShading = .2f; - } - - // 混合模式 - VkPipelineColorBlendAttachmentState colorBlendAttachment{}; - colorBlendAttachment.colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT - | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlendAttachment.blendEnable = VK_FALSE; - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; - - VkPipelineColorBlendStateCreateInfo colorBlending{}; - colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlending.logicOpEnable = VK_FALSE;//启用后会禁用前者 - colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional - colorBlending.attachmentCount = 1; - colorBlending.pAttachments = &colorBlendAttachment; - colorBlending.blendConstants[0] = 0.0f; // Optional - colorBlending.blendConstants[1] = 0.0f; // Optional - colorBlending.blendConstants[2] = 0.0f; // Optional - colorBlending.blendConstants[3] = 0.0f; // Optional + // 2.管线布局 // 推送常量区 VkPushConstantRange pushConstantRange{}; pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; @@ -4112,89 +3552,6 @@ void VK::_create_2d() return; } - // 深度模板状态 - VkPipelineDepthStencilStateCreateInfo depthStencil{}; - depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depthStencil.depthTestEnable = VK_TRUE; - depthStencil.depthWriteEnable = VK_TRUE; - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; - depthStencil.depthBoundsTestEnable = VK_FALSE; - depthStencil.minDepthBounds = 0.0f; // Optional - depthStencil.maxDepthBounds = 1.0f; // Optional - depthStencil.stencilTestEnable = VK_FALSE; - depthStencil.front = {}; // Optional - depthStencil.back = {}; // Optional - - // 图形管线 - VkGraphicsPipelineCreateInfo pipelineInfo{}; - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages;//引用shader - pipelineInfo.pVertexInputState = &vertexInputInfo; - pipelineInfo.pInputAssemblyState = &inputAssembly; - pipelineInfo.pViewportState = &viewportState; - pipelineInfo.pRasterizationState = &rasterizer; - pipelineInfo.pMultisampleState = &multisampling; - pipelineInfo.pDepthStencilState = &depthStencil; - pipelineInfo.pColorBlendState = &colorBlending; - pipelineInfo.pDynamicState = &dynamicState; - pipelineInfo.layout = _2d._pipelineLayout;//布局 - pipelineInfo.renderPass = _renderPass;//渲染流程 - pipelineInfo.subpass = 0; - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional - pipelineInfo.basePipelineIndex = -1; // Optional - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_2d._graphicsPipeline) != VK_SUCCESS) - { - log_damage0("2d图形管线创建失败!"); - return; - } - - colorBlendAttachment.blendEnable = VK_TRUE; - //相等也必须混合,因为背景可能是不透明物体,在DrawCall里,一定是后画的 - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_2d._graphicsPipelineTrans) != VK_SUCCESS) - { - log_damage0("2d图形管线创建失败!Trans"); - return; - } - - pipelineInfo.pStages = shaderStagesGray; //引用shader - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_2d._graphicsPipelineGray) != VK_SUCCESS) - { - log_damage0("2d图形管线创建失败!Gray"); - return; - } - - pipelineInfo.pStages = shaderStages; // 引用shader - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_2d._graphicsPipelineEffect) != VK_SUCCESS) - { - log_damage0("2d图形管线创建失败!Effect"); - return; - } - - // 资源释放 - vkDestroyShaderModule(_device, vertShaderModule, nullptr); - vkDestroyShaderModule(_device, fragShaderModule, nullptr); - vkDestroyShaderModule(_device, fragShaderModuleGray, nullptr); - vertShaderCode.clear(); - fragShaderCode.clear(); - fragShaderCodeGray.clear(); - - // 3.纹理采样器 VkSamplerCreateInfo samplerInfo{}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; @@ -4337,10 +3694,6 @@ void VK::_delete_2d() } vkDestroyDescriptorPool(_device, _2d._descriptorPool, nullptr); vkDestroyDescriptorSetLayout(_device, _2d._descriptorSetLayout, nullptr); - vkDestroyPipeline(_device, _2d._graphicsPipeline, nullptr); - vkDestroyPipeline(_device, _2d._graphicsPipelineTrans, nullptr); - vkDestroyPipeline(_device, _2d._graphicsPipelineEffect, nullptr); - vkDestroyPipeline(_device, _2d._graphicsPipelineGray, nullptr); vkDestroyPipelineLayout(_device, _2d._pipelineLayout, nullptr); } @@ -4390,125 +3743,7 @@ void VK::_create_gfx() log_damage0("创建gfx描述符集合失败!"); return; } - //1.管线 - // 加载shader文件 - Buffer vertShaderCode = File::GetBuffer("dl/shader/gfx_vert.spv"); - Buffer fragShaderCode = File::GetBuffer("dl/shader/gfx_frag.spv"); - // 创建shader模块 - VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); - VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); - - VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; - vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; - vertShaderStageInfo.module = vertShaderModule; - vertShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; - fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - fragShaderStageInfo.module = fragShaderModule; - fragShaderStageInfo.pName = "main"; - - VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; - - // 顶点输入状态 - auto bindingDescription = VertexGfx::getBindingDescription(); - auto attributeDescriptions = VertexGfx::getAttributeDescriptions(); - - VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; - vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = 1; - vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional - vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); - vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional - - // 顶点装配状态 - VkPipelineInputAssemblyStateCreateInfo inputAssembly0{}; - inputAssembly0.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly0.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; - inputAssembly0.primitiveRestartEnable = VK_FALSE; - VkPipelineInputAssemblyStateCreateInfo inputAssembly1{}; - inputAssembly1.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly1.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; - inputAssembly1.primitiveRestartEnable = VK_FALSE; - VkPipelineInputAssemblyStateCreateInfo inputAssembly2{}; - inputAssembly2.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly2.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - inputAssembly2.primitiveRestartEnable = VK_FALSE; - - - // 管线动态状态 - std::vector dynamicStates = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; - - VkPipelineDynamicStateCreateInfo dynamicState{}; - dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); - dynamicState.pDynamicStates = dynamicStates.data(); - - VkPipelineViewportStateCreateInfo viewportState{}; - viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewportState.viewportCount = 1; - viewportState.scissorCount = 1; - - // 光栅器状态 - VkPipelineRasterizationStateCreateInfo rasterizer{}; - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterizer.depthClampEnable = VK_FALSE; - rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; - rasterizer.lineWidth = 1.0f; - rasterizer.cullMode = VK_CULL_MODE_NONE;//不剔除应该更快 //VK_CULL_MODE_BACK_BIT; - rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;//与3d不同 - rasterizer.depthBiasEnable = VK_FALSE; - rasterizer.depthBiasConstantFactor = 0.0f; // Optional - rasterizer.depthBiasClamp = 0.0f; // Optional - rasterizer.depthBiasSlopeFactor = 0.0f; // Optional - - // 多重采样状态 - VkPipelineMultisampleStateCreateInfo multisampling{}; - multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisampling.sampleShadingEnable = VK_FALSE; - multisampling.rasterizationSamples = _msaaSamples;//必须匹配 - multisampling.minSampleShading = 1.0f; // Optional - multisampling.pSampleMask = nullptr; // Optional - multisampling.alphaToCoverageEnable = VK_FALSE; // Optional - multisampling.alphaToOneEnable = VK_FALSE; // Optional - if (OPEN_SAMPLE_SHADING) - { - multisampling.sampleShadingEnable = VK_TRUE; - // min fraction for sample shading; closer to one is smooth - multisampling.minSampleShading = .2f; - } - - // 混合模式 - VkPipelineColorBlendAttachmentState colorBlendAttachment{}; - colorBlendAttachment.colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT - | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlendAttachment.blendEnable = VK_FALSE; - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; - - VkPipelineColorBlendStateCreateInfo colorBlending{}; - colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlending.logicOpEnable = VK_FALSE;//启用后会禁用前者 - colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional - colorBlending.attachmentCount = 1; - colorBlending.pAttachments = &colorBlendAttachment; - colorBlending.blendConstants[0] = 0.0f; // Optional - colorBlending.blendConstants[1] = 0.0f; // Optional - colorBlending.blendConstants[2] = 0.0f; // Optional - colorBlending.blendConstants[3] = 0.0f; // Optional - - // 管线布局 + // 3.管线布局 VkPipelineLayoutCreateInfo pipelineLayoutInfo{}; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutInfo.setLayoutCount = 1; // Optional @@ -4519,97 +3754,6 @@ void VK::_create_gfx() log_damage0("创建gfx管线布局失败!"); return; } - - // 深度模板状态 - VkPipelineDepthStencilStateCreateInfo depthStencil{}; - depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depthStencil.depthTestEnable = VK_TRUE; - depthStencil.depthWriteEnable = VK_TRUE; - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; - depthStencil.depthBoundsTestEnable = VK_FALSE; - depthStencil.minDepthBounds = 0.0f; // Optional - depthStencil.maxDepthBounds = 1.0f; // Optional - depthStencil.stencilTestEnable = VK_FALSE; - depthStencil.front = {}; // Optional - depthStencil.back = {}; // Optional - - // 图形管线 - VkGraphicsPipelineCreateInfo pipelineInfo{}; - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages;//引用shader - pipelineInfo.pVertexInputState = &vertexInputInfo; - pipelineInfo.pInputAssemblyState = &inputAssembly0; - pipelineInfo.pViewportState = &viewportState; - pipelineInfo.pRasterizationState = &rasterizer; - pipelineInfo.pMultisampleState = &multisampling; - pipelineInfo.pDepthStencilState = &depthStencil; - pipelineInfo.pColorBlendState = &colorBlending; - pipelineInfo.pDynamicState = &dynamicState; - pipelineInfo.layout = _gfx._pipelineLayout;//布局 - pipelineInfo.renderPass = _renderPass;//渲染流程 - pipelineInfo.subpass = 0; - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional - pipelineInfo.basePipelineIndex = -1; // Optional - - - // 点图元 顶点着色器需要设置 gl_PointSize - // https://github.com/KhronosGroup/Vulkan-Samples/issues/539 - - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_gfx._vecGraphicsPipeline[0]) != VK_SUCCESS) - { - log_damage0("gfx图形管线0创建失败!"); - return; - } - pipelineInfo.pInputAssemblyState = &inputAssembly1; - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_gfx._vecGraphicsPipeline[1]) != VK_SUCCESS) - { - log_damage0("gfx图形管线1创建失败!"); - return; - } - pipelineInfo.pInputAssemblyState = &inputAssembly2; - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_gfx._vecGraphicsPipeline[2]) != VK_SUCCESS) - { - log_damage0("gfx图形管线2创建失败!"); - return; - } - - colorBlendAttachment.blendEnable = VK_TRUE; - //相等也必须混合,因为背景可能是不透明物体,在DrawCall里,一定是后画的 - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; - - pipelineInfo.pInputAssemblyState = &inputAssembly0; - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_gfx._vecGraphicsPipeline[3]) != VK_SUCCESS) - { - log_damage0("gfx图形管线4创建失败!"); - return; - } - pipelineInfo.pInputAssemblyState = &inputAssembly1; - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_gfx._vecGraphicsPipeline[4]) != VK_SUCCESS) - { - log_damage0("gfx图形管线5创建失败!"); - return; - } - pipelineInfo.pInputAssemblyState = &inputAssembly2; - if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, - &_gfx._vecGraphicsPipeline[5]) != VK_SUCCESS) - { - log_damage0("gfx图形管线6创建失败!"); - return; - } - - // 资源释放 - vkDestroyShaderModule(_device, fragShaderModule, nullptr); - vkDestroyShaderModule(_device, vertShaderModule, nullptr); - vertShaderCode.clear(); - fragShaderCode.clear(); - - // 4.统一缓冲 const size_t num = _countFrame * 2; VkDeviceSize bufferSize = sizeof(VKGfx::UBO); @@ -4707,10 +3851,6 @@ void VK::_delete_gfx() } vkDestroyDescriptorPool(_device, _gfx._descriptorPool, nullptr); vkDestroyDescriptorSetLayout(_device, _gfx._descriptorSetLayout, nullptr); - for (auto& iter : _gfx._vecGraphicsPipeline) - { - vkDestroyPipeline(_device, iter, nullptr); - } vkDestroyPipelineLayout(_device, _gfx._pipelineLayout, nullptr); } @@ -4718,7 +3858,7 @@ void VK::_create_skybox() { _skybox._current = -1; _create_descriptor_set_layout_skybox(); - _create_graphics_pipeline_skybox(); + _create_pipeline_layout_skybox(); size_t num = _countFrame; @@ -4817,7 +3957,6 @@ void VK::_delete_skybox() vkDestroySampler(_device, _skybox._envSampler, nullptr); vkDestroySampler(_device, _skybox._brdfSampler, nullptr); vkDestroyDescriptorSetLayout(_device, _skybox._descriptorSetLayout, nullptr); - vkDestroyPipeline(_device, _skybox._graphicsPipeline, nullptr); vkDestroyPipelineLayout(_device, _skybox._pipelineLayout, nullptr); vkDestroyBuffer(_device, _skybox._indexBuffer, nullptr); vkFreeMemory(_device, _skybox._indexBufferMemory, nullptr); @@ -4829,24 +3968,7 @@ void VK::_create_shadow() { _create_render_pass_shadow(); _create_descriptor_set_layout_shadow(); - { - auto bind_desc = Vertex::getBindingDescription(); - auto attr_desc = Vertex::getAttributeDescriptions(); - _shadow._pipeline = _create_graphics_pipeline_shadow( - "dl/shader/csm_vert.spv", - "dl/shader/csm_frag.spv", - &bind_desc, - attr_desc.data(), attr_desc.size()); - } - { - auto bind_desc = VertexBone::getBindingDescription(); - auto attr_desc = VertexBone::getAttributeDescriptions(); - _shadow._pipelineBone = _create_graphics_pipeline_shadow( - "dl/shader/csm_bone_vert.spv", - "dl/shader/csm_bone_frag.spv", - &bind_desc, - attr_desc.data(), attr_desc.size()); - } + _shadow._layout = _create_pipline_layout_shadow(); _shadow._cascade.resize(NUM_SHADOW_CASCADE); @@ -4985,8 +4107,7 @@ void VK::_delete_shadow() vkDestroyDescriptorSetLayout(_device, _shadow._descriptorSetLayout, nullptr); - _shadow._pipeline.Delete(_device); - _shadow._pipelineBone.Delete(_device); + vkDestroyPipelineLayout(_device, _shadow._layout, nullptr); vkDestroyRenderPass(_device, _shadow._renderPass, nullptr); } @@ -5031,6 +4152,935 @@ bool VK::_check_gfx_vertex(VertexBufferGfx& vb_old) return true; } +void VK::_create_pipeline_all() +{ + _create_pipeline_gfx(); + _create_pipeline_2d(); + _create_pipeline_3d(); + _create_pipeline_bone(); + _create_pipeline_skybox(); + _create_pipeline_shadow(); +} + +void VK::_delete_pipeline_all() +{ + for (auto& iter : _gfx._vecGraphicsPipeline) + { + vkDestroyPipeline(_device, iter, nullptr); + } + vkDestroyPipeline(_device, _2d._graphicsPipeline, nullptr); + vkDestroyPipeline(_device, _2d._graphicsPipelineTrans, nullptr); + vkDestroyPipeline(_device, _2d._graphicsPipelineEffect, nullptr); + vkDestroyPipeline(_device, _2d._graphicsPipelineGray, nullptr); + + + vkDestroyPipeline(_device, _graphicsPipeline, nullptr); + vkDestroyPipeline(_device, _graphicsPipelineBone, nullptr); + vkDestroyPipeline(_device, _skybox._graphicsPipeline, nullptr); + vkDestroyPipeline(_device, _shadow._pipeline, nullptr); + vkDestroyPipeline(_device, _shadow._pipelineBone, nullptr); +} + +void VK::_create_pipeline_gfx() +{ + //1.管线 + // 加载shader文件 + Buffer vertShaderCode = File::GetBuffer("dl/shader/gfx_vert.spv"); + Buffer fragShaderCode = File::GetBuffer("dl/shader/gfx_frag.spv"); + // 创建shader模块 + VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); + VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); + + VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; + vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; + vertShaderStageInfo.module = vertShaderModule; + vertShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; + fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + fragShaderStageInfo.module = fragShaderModule; + fragShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; + + // 顶点输入状态 + auto bindingDescription = VertexGfx::getBindingDescription(); + auto attributeDescriptions = VertexGfx::getAttributeDescriptions(); + + VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; + vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional + vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); + vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional + + // 顶点装配状态 + VkPipelineInputAssemblyStateCreateInfo inputAssembly0{}; + inputAssembly0.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly0.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + inputAssembly0.primitiveRestartEnable = VK_FALSE; + VkPipelineInputAssemblyStateCreateInfo inputAssembly1{}; + inputAssembly1.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly1.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; + inputAssembly1.primitiveRestartEnable = VK_FALSE; + VkPipelineInputAssemblyStateCreateInfo inputAssembly2{}; + inputAssembly2.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly2.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + inputAssembly2.primitiveRestartEnable = VK_FALSE; + + + // 管线动态状态 + std::vector dynamicStates = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR + }; + + VkPipelineDynamicStateCreateInfo dynamicState{}; + dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); + dynamicState.pDynamicStates = dynamicStates.data(); + + VkPipelineViewportStateCreateInfo viewportState{}; + viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewportState.viewportCount = 1; + viewportState.scissorCount = 1; + + // 光栅器状态 + VkPipelineRasterizationStateCreateInfo rasterizer{}; + rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterizer.depthClampEnable = VK_FALSE; + rasterizer.rasterizerDiscardEnable = VK_FALSE; + rasterizer.polygonMode = VK_POLYGON_MODE_FILL; + rasterizer.lineWidth = 1.0f; + rasterizer.cullMode = VK_CULL_MODE_NONE;//不剔除应该更快 //VK_CULL_MODE_BACK_BIT; + rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;//与3d不同 + rasterizer.depthBiasEnable = VK_FALSE; + rasterizer.depthBiasConstantFactor = 0.0f; // Optional + rasterizer.depthBiasClamp = 0.0f; // Optional + rasterizer.depthBiasSlopeFactor = 0.0f; // Optional + + // 多重采样状态 + VkPipelineMultisampleStateCreateInfo multisampling{}; + multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling.sampleShadingEnable = VK_FALSE; + multisampling.rasterizationSamples = _param._msaaLevel;//必须匹配 + multisampling.minSampleShading = 1.0f; // Optional + multisampling.pSampleMask = nullptr; // Optional + multisampling.alphaToCoverageEnable = VK_FALSE; // Optional + multisampling.alphaToOneEnable = VK_FALSE; // Optional + if (OPEN_SAMPLE_SHADING) + { + multisampling.sampleShadingEnable = VK_TRUE; + // min fraction for sample shading; closer to one is smooth + multisampling.minSampleShading = .2f; + } + + // 混合模式 + VkPipelineColorBlendAttachmentState colorBlendAttachment{}; + colorBlendAttachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT + | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + colorBlendAttachment.blendEnable = VK_FALSE; + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + + VkPipelineColorBlendStateCreateInfo colorBlending{}; + colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + colorBlending.logicOpEnable = VK_FALSE;//启用后会禁用前者 + colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional + colorBlending.attachmentCount = 1; + colorBlending.pAttachments = &colorBlendAttachment; + colorBlending.blendConstants[0] = 0.0f; // Optional + colorBlending.blendConstants[1] = 0.0f; // Optional + colorBlending.blendConstants[2] = 0.0f; // Optional + colorBlending.blendConstants[3] = 0.0f; // Optional + + // 深度模板状态 + VkPipelineDepthStencilStateCreateInfo depthStencil{}; + depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depthStencil.depthTestEnable = VK_TRUE; + depthStencil.depthWriteEnable = VK_TRUE; + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; + depthStencil.depthBoundsTestEnable = VK_FALSE; + depthStencil.minDepthBounds = 0.0f; // Optional + depthStencil.maxDepthBounds = 1.0f; // Optional + depthStencil.stencilTestEnable = VK_FALSE; + depthStencil.front = {}; // Optional + depthStencil.back = {}; // Optional + + // 图形管线 + VkGraphicsPipelineCreateInfo pipelineInfo{}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages;//引用shader + pipelineInfo.pVertexInputState = &vertexInputInfo; + pipelineInfo.pInputAssemblyState = &inputAssembly0; + pipelineInfo.pViewportState = &viewportState; + pipelineInfo.pRasterizationState = &rasterizer; + pipelineInfo.pMultisampleState = &multisampling; + pipelineInfo.pDepthStencilState = &depthStencil; + pipelineInfo.pColorBlendState = &colorBlending; + pipelineInfo.pDynamicState = &dynamicState; + pipelineInfo.layout = _gfx._pipelineLayout;//布局 + pipelineInfo.renderPass = _renderPass;//渲染流程 + pipelineInfo.subpass = 0; + pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional + pipelineInfo.basePipelineIndex = -1; // Optional + + + // 点图元 顶点着色器需要设置 gl_PointSize + // https://github.com/KhronosGroup/Vulkan-Samples/issues/539 + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_gfx._vecGraphicsPipeline[0]) != VK_SUCCESS) + { + log_damage0("gfx图形管线0创建失败!"); + return; + } + pipelineInfo.pInputAssemblyState = &inputAssembly1; + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_gfx._vecGraphicsPipeline[1]) != VK_SUCCESS) + { + log_damage0("gfx图形管线1创建失败!"); + return; + } + pipelineInfo.pInputAssemblyState = &inputAssembly2; + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_gfx._vecGraphicsPipeline[2]) != VK_SUCCESS) + { + log_damage0("gfx图形管线2创建失败!"); + return; + } + + colorBlendAttachment.blendEnable = VK_TRUE; + //相等也必须混合,因为背景可能是不透明物体,在DrawCall里,一定是后画的 + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; + + pipelineInfo.pInputAssemblyState = &inputAssembly0; + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_gfx._vecGraphicsPipeline[3]) != VK_SUCCESS) + { + log_damage0("gfx图形管线4创建失败!"); + return; + } + pipelineInfo.pInputAssemblyState = &inputAssembly1; + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_gfx._vecGraphicsPipeline[4]) != VK_SUCCESS) + { + log_damage0("gfx图形管线5创建失败!"); + return; + } + pipelineInfo.pInputAssemblyState = &inputAssembly2; + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_gfx._vecGraphicsPipeline[5]) != VK_SUCCESS) + { + log_damage0("gfx图形管线6创建失败!"); + return; + } + + // 资源释放 + vkDestroyShaderModule(_device, fragShaderModule, nullptr); + vkDestroyShaderModule(_device, vertShaderModule, nullptr); + vertShaderCode.clear(); + fragShaderCode.clear(); +} + +void VK::_create_pipeline_2d() +{ + // 1.管线 + // 加载shader文件 + Buffer vertShaderCode = File::GetBuffer("dl/shader/2d_vert.spv"); + Buffer fragShaderCode = File::GetBuffer("dl/shader/2d_frag.spv"); + Buffer fragShaderCodeGray = File::GetBuffer("dl/shader/2d_gray_frag.spv"); + // 创建shader模块 + VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); + VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); + VkShaderModule fragShaderModuleGray = CreateShaderModule(fragShaderCodeGray); + + VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; + vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; + vertShaderStageInfo.module = vertShaderModule; + vertShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; + fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + fragShaderStageInfo.module = fragShaderModule; + fragShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo fragShaderStageInfoGray{}; + fragShaderStageInfoGray.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + fragShaderStageInfoGray.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + fragShaderStageInfoGray.module = fragShaderModuleGray; + fragShaderStageInfoGray.pName = "main"; + + VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; + VkPipelineShaderStageCreateInfo shaderStagesGray[] = { vertShaderStageInfo, fragShaderStageInfoGray }; + + // 顶点输入状态 + auto bindingDescription = Vertex2D::getBindingDescription(); + auto attributeDescriptions = Vertex2D::getAttributeDescriptions(); + + VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; + vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional + vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); + vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional + + // 顶点装配状态 + VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; + inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + inputAssembly.primitiveRestartEnable = VK_FALSE; + + + // 管线动态状态 + std::vector dynamicStates = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR + }; + + VkPipelineDynamicStateCreateInfo dynamicState{}; + dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); + dynamicState.pDynamicStates = dynamicStates.data(); + + VkPipelineViewportStateCreateInfo viewportState{}; + viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewportState.viewportCount = 1; + viewportState.scissorCount = 1; + + // 光栅器状态 + VkPipelineRasterizationStateCreateInfo rasterizer{}; + rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterizer.depthClampEnable = VK_FALSE; + rasterizer.rasterizerDiscardEnable = VK_FALSE; + rasterizer.polygonMode = VK_POLYGON_MODE_FILL; + rasterizer.lineWidth = 1.0f; + rasterizer.cullMode = VK_CULL_MODE_NONE;//不剔除应该更快 //VK_CULL_MODE_BACK_BIT; + rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;//与3d不同 + rasterizer.depthBiasEnable = VK_FALSE; + rasterizer.depthBiasConstantFactor = 0.0f; // Optional + rasterizer.depthBiasClamp = 0.0f; // Optional + rasterizer.depthBiasSlopeFactor = 0.0f; // Optional + + // 多重采样状态 + VkPipelineMultisampleStateCreateInfo multisampling{}; + multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling.sampleShadingEnable = VK_FALSE; + multisampling.rasterizationSamples = _param._msaaLevel;//必须匹配 + multisampling.minSampleShading = 1.0f; // Optional + multisampling.pSampleMask = nullptr; // Optional + multisampling.alphaToCoverageEnable = VK_FALSE; // Optional + multisampling.alphaToOneEnable = VK_FALSE; // Optional + if (OPEN_SAMPLE_SHADING) + { + multisampling.sampleShadingEnable = VK_TRUE; + // min fraction for sample shading; closer to one is smooth + multisampling.minSampleShading = .2f; + } + + // 混合模式 + VkPipelineColorBlendAttachmentState colorBlendAttachment{}; + colorBlendAttachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT + | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + colorBlendAttachment.blendEnable = VK_FALSE; + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + + VkPipelineColorBlendStateCreateInfo colorBlending{}; + colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + colorBlending.logicOpEnable = VK_FALSE;//启用后会禁用前者 + colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional + colorBlending.attachmentCount = 1; + colorBlending.pAttachments = &colorBlendAttachment; + colorBlending.blendConstants[0] = 0.0f; // Optional + colorBlending.blendConstants[1] = 0.0f; // Optional + colorBlending.blendConstants[2] = 0.0f; // Optional + colorBlending.blendConstants[3] = 0.0f; // Optional + + // 深度模板状态 + VkPipelineDepthStencilStateCreateInfo depthStencil{}; + depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depthStencil.depthTestEnable = VK_TRUE; + depthStencil.depthWriteEnable = VK_TRUE; + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; + depthStencil.depthBoundsTestEnable = VK_FALSE; + depthStencil.minDepthBounds = 0.0f; // Optional + depthStencil.maxDepthBounds = 1.0f; // Optional + depthStencil.stencilTestEnable = VK_FALSE; + depthStencil.front = {}; // Optional + depthStencil.back = {}; // Optional + + // 图形管线 + VkGraphicsPipelineCreateInfo pipelineInfo{}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages;//引用shader + pipelineInfo.pVertexInputState = &vertexInputInfo; + pipelineInfo.pInputAssemblyState = &inputAssembly; + pipelineInfo.pViewportState = &viewportState; + pipelineInfo.pRasterizationState = &rasterizer; + pipelineInfo.pMultisampleState = &multisampling; + pipelineInfo.pDepthStencilState = &depthStencil; + pipelineInfo.pColorBlendState = &colorBlending; + pipelineInfo.pDynamicState = &dynamicState; + pipelineInfo.layout = _2d._pipelineLayout;//布局 + pipelineInfo.renderPass = _renderPass;//渲染流程 + pipelineInfo.subpass = 0; + pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional + pipelineInfo.basePipelineIndex = -1; // Optional + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_2d._graphicsPipeline) != VK_SUCCESS) + { + log_damage0("2d图形管线创建失败!"); + return; + } + + colorBlendAttachment.blendEnable = VK_TRUE; + //相等也必须混合,因为背景可能是不透明物体,在DrawCall里,一定是后画的 + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_2d._graphicsPipelineTrans) != VK_SUCCESS) + { + log_damage0("2d图形管线创建失败!Trans"); + return; + } + + pipelineInfo.pStages = shaderStagesGray; //引用shader + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_2d._graphicsPipelineGray) != VK_SUCCESS) + { + log_damage0("2d图形管线创建失败!Gray"); + return; + } + + pipelineInfo.pStages = shaderStages; // 引用shader + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_2d._graphicsPipelineEffect) != VK_SUCCESS) + { + log_damage0("2d图形管线创建失败!Effect"); + return; + } + + // 资源释放 + vkDestroyShaderModule(_device, vertShaderModule, nullptr); + vkDestroyShaderModule(_device, fragShaderModule, nullptr); + vkDestroyShaderModule(_device, fragShaderModuleGray, nullptr); + vertShaderCode.clear(); + fragShaderCode.clear(); + fragShaderCodeGray.clear(); + +} + +void VK::_create_pipeline_3d() +{ + // 加载shader文件 + Buffer vertShaderCode = File::GetBuffer("dl/shader/3d_vert.spv"); + Buffer fragShaderCode = File::GetBuffer("dl/shader/3d_frag.spv"); + // 创建shader模块 + VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); + VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); + + VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; + vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; + vertShaderStageInfo.module = vertShaderModule; + vertShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; + fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + fragShaderStageInfo.module = fragShaderModule; + fragShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; + + //顶点输入状态 + auto bindingDescription = Vertex::getBindingDescription(); + auto attributeDescriptions = Vertex::getAttributeDescriptions(); + + VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; + vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional + vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); + vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional + + //顶点装配状态 + VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; + inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + inputAssembly.primitiveRestartEnable = VK_FALSE; + + //管线动态状态 + std::vector dynamicStates = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR + }; + + VkPipelineDynamicStateCreateInfo dynamicState{}; + dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); + dynamicState.pDynamicStates = dynamicStates.data(); + + VkPipelineViewportStateCreateInfo viewportState{}; + viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewportState.viewportCount = 1; + viewportState.scissorCount = 1; + + //光栅器状态 + VkPipelineRasterizationStateCreateInfo rasterizer{}; + rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterizer.depthClampEnable = VK_FALSE; + rasterizer.rasterizerDiscardEnable = VK_FALSE; + rasterizer.polygonMode = VK_POLYGON_MODE_FILL; + rasterizer.lineWidth = 1.0f; + rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; + rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + rasterizer.depthBiasEnable = VK_FALSE; + rasterizer.depthBiasConstantFactor = 0.0f; // Optional + rasterizer.depthBiasClamp = 0.0f; // Optional + rasterizer.depthBiasSlopeFactor = 0.0f; // Optional + + //多重采样状态 + VkPipelineMultisampleStateCreateInfo multisampling{}; + multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling.sampleShadingEnable = VK_FALSE; + multisampling.rasterizationSamples = _param._msaaLevel; + multisampling.minSampleShading = 1.0f; // Optional + multisampling.pSampleMask = nullptr; // Optional + multisampling.alphaToCoverageEnable = VK_FALSE; // Optional + multisampling.alphaToOneEnable = VK_FALSE; // Optional + if (OPEN_SAMPLE_SHADING) + { + multisampling.sampleShadingEnable = VK_TRUE; + // min fraction for sample shading; closer to one is smooth + multisampling.minSampleShading = .2f; + } + //混合模式 + VkPipelineColorBlendAttachmentState colorBlendAttachment{}; + colorBlendAttachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT + | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + colorBlendAttachment.blendEnable = VK_TRUE; + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + + VkPipelineColorBlendStateCreateInfo colorBlending{}; + colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + colorBlending.logicOpEnable = VK_FALSE;//启用后会禁用前者 + colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional + colorBlending.attachmentCount = 1; + colorBlending.pAttachments = &colorBlendAttachment; + colorBlending.blendConstants[0] = 0.0f; // Optional + colorBlending.blendConstants[1] = 0.0f; // Optional + colorBlending.blendConstants[2] = 0.0f; // Optional + colorBlending.blendConstants[3] = 0.0f; // Optional + + // 深度模板状态 + VkPipelineDepthStencilStateCreateInfo depthStencil{}; + depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depthStencil.depthTestEnable = VK_TRUE; + depthStencil.depthWriteEnable = VK_TRUE; + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; + depthStencil.depthBoundsTestEnable = VK_FALSE; + depthStencil.minDepthBounds = 0.0f; // Optional + depthStencil.maxDepthBounds = 1.0f; // Optional + depthStencil.stencilTestEnable = VK_FALSE; + depthStencil.front = {}; // Optional + depthStencil.back = {}; // Optional + + // 图形管线 + VkGraphicsPipelineCreateInfo pipelineInfo{}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages;//引用shader + pipelineInfo.pVertexInputState = &vertexInputInfo; + pipelineInfo.pInputAssemblyState = &inputAssembly; + pipelineInfo.pViewportState = &viewportState; + pipelineInfo.pRasterizationState = &rasterizer; + pipelineInfo.pMultisampleState = &multisampling; + pipelineInfo.pDepthStencilState = &depthStencil; + pipelineInfo.pColorBlendState = &colorBlending; + pipelineInfo.pDynamicState = &dynamicState; + pipelineInfo.layout = _pipelineLayout;//布局 + pipelineInfo.renderPass = _renderPass;//渲染流程 + pipelineInfo.subpass = 0; + pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional + pipelineInfo.basePipelineIndex = -1; // Optional + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipeline) != VK_SUCCESS) + { + log_damage0("图形管线创建失败!"); + return; + } + + //资源释放 + vkDestroyShaderModule(_device, fragShaderModule, nullptr); + vkDestroyShaderModule(_device, vertShaderModule, nullptr); +} + +void VK::_create_pipeline_bone() +{ + // 加载shader文件 + Buffer vertShaderCode = File::GetBuffer("dl/shader/3d_bone_vert.spv"); + Buffer fragShaderCode = File::GetBuffer("dl/shader/3d_frag.spv"); + // 创建shader模块 + VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); + VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); + + VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; + vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; + vertShaderStageInfo.module = vertShaderModule; + vertShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; + fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + fragShaderStageInfo.module = fragShaderModule; + fragShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; + + // 顶点输入状态 + auto bindingDescription = VertexBone::getBindingDescription(); + auto attributeDescriptions = VertexBone::getAttributeDescriptions(); + + VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; + vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional + vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); + vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional + + // 顶点装配状态 + VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; + inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + inputAssembly.primitiveRestartEnable = VK_FALSE; + + // 管线动态状态 + std::vector dynamicStates = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR + }; + + VkPipelineDynamicStateCreateInfo dynamicState{}; + dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); + dynamicState.pDynamicStates = dynamicStates.data(); + + VkPipelineViewportStateCreateInfo viewportState{}; + viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewportState.viewportCount = 1; + viewportState.scissorCount = 1; + + // 光栅器状态 + VkPipelineRasterizationStateCreateInfo rasterizer{}; + rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterizer.depthClampEnable = VK_FALSE; + rasterizer.rasterizerDiscardEnable = VK_FALSE; + rasterizer.polygonMode = VK_POLYGON_MODE_FILL; + rasterizer.lineWidth = 1.0f; + rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; + rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + rasterizer.depthBiasEnable = VK_FALSE; + rasterizer.depthBiasConstantFactor = 0.0f; // Optional + rasterizer.depthBiasClamp = 0.0f; // Optional + rasterizer.depthBiasSlopeFactor = 0.0f; // Optional + + // 多重采样状态 + VkPipelineMultisampleStateCreateInfo multisampling{}; + multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling.sampleShadingEnable = VK_FALSE; + multisampling.rasterizationSamples = _param._msaaLevel; + multisampling.minSampleShading = 1.0f; // Optional + multisampling.pSampleMask = nullptr; // Optional + multisampling.alphaToCoverageEnable = VK_FALSE; // Optional + multisampling.alphaToOneEnable = VK_FALSE; // Optional + if (OPEN_SAMPLE_SHADING) + { + multisampling.sampleShadingEnable = VK_TRUE; + // min fraction for sample shading; closer to one is smooth + multisampling.minSampleShading = .2f; + } + // 混合模式 + VkPipelineColorBlendAttachmentState colorBlendAttachment{}; + colorBlendAttachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT + | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + colorBlendAttachment.blendEnable = VK_TRUE; + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + + VkPipelineColorBlendStateCreateInfo colorBlending{}; + colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + colorBlending.logicOpEnable = VK_FALSE;// 启用后会禁用前者 + colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional + colorBlending.attachmentCount = 1; + colorBlending.pAttachments = &colorBlendAttachment; + colorBlending.blendConstants[0] = 0.0f; // Optional + colorBlending.blendConstants[1] = 0.0f; // Optional + colorBlending.blendConstants[2] = 0.0f; // Optional + colorBlending.blendConstants[3] = 0.0f; // Optional + + + // 深度模板状态 + VkPipelineDepthStencilStateCreateInfo depthStencil{}; + depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depthStencil.depthTestEnable = VK_TRUE; + depthStencil.depthWriteEnable = VK_TRUE; + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; + depthStencil.depthBoundsTestEnable = VK_FALSE; + depthStencil.minDepthBounds = 0.0f; // Optional + depthStencil.maxDepthBounds = 1.0f; // Optional + depthStencil.stencilTestEnable = VK_FALSE; + depthStencil.front = {}; // Optional + depthStencil.back = {}; // Optional + + // 图形管线 + VkGraphicsPipelineCreateInfo pipelineInfo{}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages;// 引用shader + pipelineInfo.pVertexInputState = &vertexInputInfo; + pipelineInfo.pInputAssemblyState = &inputAssembly; + pipelineInfo.pViewportState = &viewportState; + pipelineInfo.pRasterizationState = &rasterizer; + pipelineInfo.pMultisampleState = &multisampling; + pipelineInfo.pDepthStencilState = &depthStencil; + pipelineInfo.pColorBlendState = &colorBlending; + pipelineInfo.pDynamicState = &dynamicState; + pipelineInfo.layout = _pipelineLayoutBone;// 布局 + pipelineInfo.renderPass = _renderPass;// 渲染流程 + pipelineInfo.subpass = 0; + pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional + pipelineInfo.basePipelineIndex = -1; // Optional + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipelineBone) != VK_SUCCESS) + { + log_damage0("图形管线创建失败!"); + return; + } + + // 资源释放 + vkDestroyShaderModule(_device, fragShaderModule, nullptr); + vkDestroyShaderModule(_device, vertShaderModule, nullptr); +} + +void VK::_create_pipeline_skybox() +{ + // 加载shader文件 + Buffer vertShaderCode = File::GetBuffer("dl/shader/skybox_vert.spv"); + Buffer fragShaderCode = File::GetBuffer("dl/shader/skybox_frag.spv"); + // 创建shader模块 + VkShaderModule vertShaderModule = CreateShaderModule(vertShaderCode); + VkShaderModule fragShaderModule = CreateShaderModule(fragShaderCode); + + VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; + vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; + vertShaderStageInfo.module = vertShaderModule; + vertShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; + fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + fragShaderStageInfo.module = fragShaderModule; + fragShaderStageInfo.pName = "main"; + + VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo, fragShaderStageInfo }; + + // 顶点输入状态 + auto bindingDescription = VertexSkybox::getBindingDescription(); + auto attributeDescriptions = VertexSkybox::getAttributeDescriptions(); + + VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; + vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; // Optional + vertexInputInfo.vertexAttributeDescriptionCount = (uint32_t)attributeDescriptions.size(); + vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data(); // Optional + + // 顶点装配状态 + VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; + inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + inputAssembly.primitiveRestartEnable = VK_FALSE; + + // 管线动态状态 + std::vector dynamicStates = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR + }; + + VkPipelineDynamicStateCreateInfo dynamicState{}; + dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamicState.dynamicStateCount = static_cast(dynamicStates.size()); + dynamicState.pDynamicStates = dynamicStates.data(); + + VkPipelineViewportStateCreateInfo viewportState{}; + viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewportState.viewportCount = 1; + viewportState.scissorCount = 1; + + // 光栅器状态 + VkPipelineRasterizationStateCreateInfo rasterizer{}; + rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + rasterizer.depthClampEnable = VK_FALSE; + rasterizer.rasterizerDiscardEnable = VK_FALSE; + rasterizer.polygonMode = VK_POLYGON_MODE_FILL; + rasterizer.lineWidth = 1.0f; + rasterizer.cullMode = VK_CULL_MODE_NONE; + rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + rasterizer.depthBiasEnable = VK_FALSE; + rasterizer.depthBiasConstantFactor = 0.0f; // Optional + rasterizer.depthBiasClamp = 0.0f; // Optional + rasterizer.depthBiasSlopeFactor = 0.0f; // Optional + + // 多重采样状态 + VkPipelineMultisampleStateCreateInfo multisampling{}; + multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisampling.sampleShadingEnable = VK_FALSE; + multisampling.rasterizationSamples = _param._msaaLevel; + multisampling.minSampleShading = 1.0f; // Optional + multisampling.pSampleMask = nullptr; // Optional + multisampling.alphaToCoverageEnable = VK_FALSE; // Optional + multisampling.alphaToOneEnable = VK_FALSE; // Optional + if (OPEN_SAMPLE_SHADING) + { + multisampling.sampleShadingEnable = VK_TRUE; + // min fraction for sample shading; closer to one is smooth + multisampling.minSampleShading = .2f; + } + // 混合模式 + VkPipelineColorBlendAttachmentState colorBlendAttachment{}; + colorBlendAttachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT + | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + colorBlendAttachment.blendEnable = VK_FALSE; + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + + VkPipelineColorBlendStateCreateInfo colorBlending{}; + colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + colorBlending.logicOpEnable = VK_FALSE;// 启用后会禁用前者 + colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional + colorBlending.attachmentCount = 1; + colorBlending.pAttachments = &colorBlendAttachment; + colorBlending.blendConstants[0] = 0.0f; // Optional + colorBlending.blendConstants[1] = 0.0f; // Optional + colorBlending.blendConstants[2] = 0.0f; // Optional + colorBlending.blendConstants[3] = 0.0f; // Optional + + // 深度模板状态 + VkPipelineDepthStencilStateCreateInfo depthStencil{}; + depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depthStencil.depthTestEnable = VK_TRUE; + depthStencil.depthWriteEnable = VK_FALSE; + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; + depthStencil.depthBoundsTestEnable = VK_FALSE; + depthStencil.minDepthBounds = 0.0f; // Optional + depthStencil.maxDepthBounds = 1.0f; // Optional + depthStencil.stencilTestEnable = VK_FALSE; + depthStencil.front = {}; // Optional + depthStencil.back = {}; // Optional + + // 图形管线 + VkGraphicsPipelineCreateInfo pipelineInfo{}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; + pipelineInfo.stageCount = 2; + pipelineInfo.pStages = shaderStages;//引用shader + pipelineInfo.pVertexInputState = &vertexInputInfo; + pipelineInfo.pInputAssemblyState = &inputAssembly; + pipelineInfo.pViewportState = &viewportState; + pipelineInfo.pRasterizationState = &rasterizer; + pipelineInfo.pMultisampleState = &multisampling; + pipelineInfo.pDepthStencilState = &depthStencil; + pipelineInfo.pColorBlendState = &colorBlending; + pipelineInfo.pDynamicState = &dynamicState; + pipelineInfo.layout = _skybox._pipelineLayout;//布局 + pipelineInfo.renderPass = _renderPass;//渲染流程 + pipelineInfo.subpass = 0; + pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional + pipelineInfo.basePipelineIndex = -1; // Optional + + // 深度测试 开 <= + // 深度写入 关 + // 关闭剔除 + // 关闭混合 + + if (vkCreateGraphicsPipelines(_device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, + &_skybox._graphicsPipeline) != VK_SUCCESS) + { + log_damage0("图形管线(skybox)创建失败!"); + return; + } + + // 资源释放 + vkDestroyShaderModule(_device, fragShaderModule, nullptr); + vkDestroyShaderModule(_device, vertShaderModule, nullptr); +} + +void VK::_create_pipeline_shadow() +{ + { + auto bind_desc = Vertex::getBindingDescription(); + auto attr_desc = Vertex::getAttributeDescriptions(); + _shadow._pipeline = _create_graphics_pipeline_shadow( + "dl/shader/csm_vert.spv", + "dl/shader/csm_frag.spv", + &bind_desc, + attr_desc.data(), attr_desc.size(), _shadow._layout); + } + { + auto bind_desc = VertexBone::getBindingDescription(); + auto attr_desc = VertexBone::getAttributeDescriptions(); + _shadow._pipelineBone = _create_graphics_pipeline_shadow( + "dl/shader/csm_bone_vert.spv", + "dl/shader/csm_bone_frag.spv", + &bind_desc, + attr_desc.data(), attr_desc.size(), _shadow._layout); + } +} + void VK::ExportTexture(Texture tex, std::string_view path_name) { uint32_t width = tex._width; @@ -5289,7 +5339,7 @@ void VK::GenerateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, void VK::_create_depth_resources() { VkFormat depthFormat = FindDepthFormat(); - CreateImage(_extentSwapChain.width, _extentSwapChain.height, 1, _msaaSamples, + CreateImage(_extentSwapChain.width, _extentSwapChain.height, 1, _param._msaaLevel, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, _depthImage, _depthImageMemory); @@ -5301,6 +5351,17 @@ void VK::_create_depth_resources() 1); } +void VK::_create_color_resources() +{ + VkFormat colorFormat = _formatSwapChainImage; + + CreateImage(_extentSwapChain.width, _extentSwapChain.height, 1, _param._msaaLevel, colorFormat, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, _colorImage, _colorImageMemory); + _colorImageView = CreateImageView(_colorImage, colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1); +} + VkSampleCountFlagBits VK::GetMaxUsableSampleCount() { VkPhysicalDeviceProperties physicalDeviceProperties; @@ -5419,6 +5480,7 @@ void VK::SetSkybox(size_t i) VK::~VK() { + _delete_pipeline_all(); _delete_gfx(); _delete_2d(); _delete_skybox(); @@ -5482,10 +5544,8 @@ VK::~VK() vkDestroyCommandPool(_device, _commandPool, nullptr); // pipeline - vkDestroyPipeline(_device, _graphicsPipelineBone, nullptr); vkDestroyPipelineLayout(_device, _pipelineLayoutBone, nullptr); - vkDestroyPipeline(_device, _graphicsPipeline, nullptr); vkDestroyPipelineLayout(_device, _pipelineLayout, nullptr); vkDestroyRenderPass(_device, _renderPass, nullptr); diff --git a/dl/vk/dl_vk.h b/dl/vk/dl_vk.h index 676e43a8..232c627a 100644 --- a/dl/vk/dl_vk.h +++ b/dl/vk/dl_vk.h @@ -134,7 +134,7 @@ constexpr size_t NUM_START_2D_VERTEX = 4 * 1024; // 最大根坐标系数(2d的cbo数) constexpr size_t NUM_MAX_ROOT_COOR = 32; -// 样本着色 +// 样本着色(更高级的多重采样,基本不会使用) constexpr bool OPEN_SAMPLE_SHADING = false; // 线框模式(很多设备不支持) constexpr bool OPEN_FILL_MODE_NON_SOLID = false; @@ -850,17 +850,17 @@ public: ~VK(); private: - struct Pipeline - { - VkPipelineLayout _layout; // 管线布局 - VkPipeline _pipe; // 图形管线 + //struct Pipeline + //{ + // VkPipelineLayout _layout; // 管线布局 + // VkPipeline _pipe; // 图形管线 - void Delete(VkDevice device) - { - vkDestroyPipeline(device, _pipe, nullptr); - vkDestroyPipelineLayout(device, _layout, nullptr); - } - }; + // void Delete(VkDevice device) + // { + // vkDestroyPipeline(device, _pipe, nullptr); + // vkDestroyPipelineLayout(device, _layout, nullptr); + // } + //}; VkInstance _instance; // vk实例 std::vector _allExtension; // 所有扩展,返回获得 @@ -922,7 +922,6 @@ private: std::vector _ubBoneMemory; //骨骼ub内存 std::vector _mapBoneUse; //骨骼ub使用表 std::vector _allPrimitive; //所有图元 - VkSampleCountFlagBits _msaaSamples; //msaa采样数 VkImage _colorImage; //离屏图像 VkDeviceMemory _colorImageMemory; //离屏图像内存 VkImageView _colorImageView; //离屏图像视图 @@ -968,8 +967,9 @@ private: VkRenderPass _renderPass; VkDescriptorSetLayout _descriptorSetLayout; // 描述符布局 set0 std::vector _descriptorSets; // 描述符集(ubo) - Pipeline _pipeline; - Pipeline _pipelineBone; + VkPipelineLayout _layout; + VkPipeline _pipeline; + VkPipeline _pipelineBone; VkSampler _sampler; // 采样器 Texture _tex; @@ -1055,12 +1055,12 @@ private: // 创建绘图流程 void _create_render_pass(); // 创建图形管道 - void _create_graphics_pipeline(); - void _create_graphics_pipeline_skybox(); + void _create_pipeline_layout_3d(); + void _create_pipeline_layout_skybox(); //-------------------骨骼动画----------------- void _create_descriptor_set_layout_bone();//布局 - void _create_graphics_pipeline_bone();//管线 + void _create_pipeline_layout_bone();//管线 void _create_uniform_bone();//统一缓冲 void _create_ibl(); @@ -1124,16 +1124,7 @@ private: // 创建深度缓存资源 void _create_depth_resources(); // 创建msaa资源 - void _create_color_resources() - { - VkFormat colorFormat = _formatSwapChainImage; - - CreateImage(_extentSwapChain.width, _extentSwapChain.height, 1, _msaaSamples, colorFormat, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, _colorImage, _colorImageMemory); - _colorImageView = CreateImageView(_colorImage, colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1); - } + void _create_color_resources(); //2d管线 void _create_2d(); void _delete_2d(); @@ -1156,13 +1147,36 @@ private: void _create_shadow(); void _delete_shadow(); void _create_render_pass_shadow(); - Pipeline _create_graphics_pipeline_shadow(std::string_view vs, std::string_view ps, - VkVertexInputBindingDescription* bind_desc, - VkVertexInputAttributeDescription* attr_desc, size_t num_attr); + + VkPipelineLayout _create_pipline_layout_shadow(); + + VkPipeline _create_graphics_pipeline_shadow( + std::string_view vs, std::string_view ps, + VkVertexInputBindingDescription* bind_desc, VkVertexInputAttributeDescription* attr_desc, + size_t num_attr, VkPipelineLayout layout); void _create_descriptor_set_layout_shadow(); bool _check_gfx_vertex(VertexBufferGfx& vb_old); + + //------------------------------管线------------------------------------- + + void _create_pipeline_all(); + void _delete_pipeline_all(); + + void _create_pipeline_gfx(); + void _create_pipeline_2d(); + void _create_pipeline_3d(); + void _create_pipeline_bone(); + void _create_pipeline_skybox(); + void _create_pipeline_shadow(); public: + // 动态参数 + struct RenderParam + { + VkSampleCountFlagBits _msaaLevel; + + }_param; + void GfxLock() { diff --git a/project/dl_chess b/project/dl_chess index 3b7efbae..3a50383f 160000 --- a/project/dl_chess +++ b/project/dl_chess @@ -1 +1 @@ -Subproject commit 3b7efbaecb7b67897f5c780e5cd9b25fc1bf67cb +Subproject commit 3a50383faaf6f107a57a85d46d5e67d208f8cd67