From aeb187e009cc123e348d4be4ca65d1686b4d5d21 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 8 Jul 2019 16:07:23 -0400 Subject: [PATCH] [vulkan] Fixup colour attachment setup for render pass. (#572) * [vulkan] fixes the render pass creation code when using multiple colour attachments. Fixes #543 --- src/vulkan/graphics_pipeline.cc | 56 ++++++++++++++++++--------------- src/vulkan/graphics_pipeline.h | 4 +-- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/vulkan/graphics_pipeline.cc b/src/vulkan/graphics_pipeline.cc index 78112efc9..31c194c29 100644 --- a/src/vulkan/graphics_pipeline.cc +++ b/src/vulkan/graphics_pipeline.cc @@ -422,11 +422,9 @@ Result GraphicsPipeline::CreateRenderPass() { ref.attachment = static_cast(attachment_desc.size() - 1); ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; color_refer.push_back(ref); - - subpass_desc.colorAttachmentCount = - static_cast(color_refer.size()); - subpass_desc.pColorAttachments = color_refer.data(); } + subpass_desc.colorAttachmentCount = static_cast(color_refer.size()); + subpass_desc.pColorAttachments = color_refer.data(); if (depth_stencil_format_.IsFormatKnown()) { attachment_desc.push_back(kDefaultAttachmentDesc); @@ -503,26 +501,31 @@ GraphicsPipeline::GetVkPipelineDepthStencilInfo( return depthstencil_info; } -VkPipelineColorBlendAttachmentState +std::vector GraphicsPipeline::GetVkPipelineColorBlendAttachmentState( const PipelineData* pipeline_data) { - VkPipelineColorBlendAttachmentState colorblend_attachment = - VkPipelineColorBlendAttachmentState(); - colorblend_attachment.blendEnable = pipeline_data->GetEnableBlend(); - colorblend_attachment.srcColorBlendFactor = - ToVkBlendFactor(pipeline_data->GetSrcColorBlendFactor()); - colorblend_attachment.dstColorBlendFactor = - ToVkBlendFactor(pipeline_data->GetDstColorBlendFactor()); - colorblend_attachment.colorBlendOp = - ToVkBlendOp(pipeline_data->GetColorBlendOp()); - colorblend_attachment.srcAlphaBlendFactor = - ToVkBlendFactor(pipeline_data->GetSrcAlphaBlendFactor()); - colorblend_attachment.dstAlphaBlendFactor = - ToVkBlendFactor(pipeline_data->GetDstAlphaBlendFactor()); - colorblend_attachment.alphaBlendOp = - ToVkBlendOp(pipeline_data->GetAlphaBlendOp()); - colorblend_attachment.colorWriteMask = pipeline_data->GetColorWriteMask(); - return colorblend_attachment; + std::vector states; + + for (size_t i = 0; i < color_buffers_.size(); ++i) { + VkPipelineColorBlendAttachmentState colorblend_attachment = + VkPipelineColorBlendAttachmentState(); + colorblend_attachment.blendEnable = pipeline_data->GetEnableBlend(); + colorblend_attachment.srcColorBlendFactor = + ToVkBlendFactor(pipeline_data->GetSrcColorBlendFactor()); + colorblend_attachment.dstColorBlendFactor = + ToVkBlendFactor(pipeline_data->GetDstColorBlendFactor()); + colorblend_attachment.colorBlendOp = + ToVkBlendOp(pipeline_data->GetColorBlendOp()); + colorblend_attachment.srcAlphaBlendFactor = + ToVkBlendFactor(pipeline_data->GetSrcAlphaBlendFactor()); + colorblend_attachment.dstAlphaBlendFactor = + ToVkBlendFactor(pipeline_data->GetDstAlphaBlendFactor()); + colorblend_attachment.alphaBlendOp = + ToVkBlendOp(pipeline_data->GetAlphaBlendOp()); + colorblend_attachment.colorWriteMask = pipeline_data->GetColorWriteMask(); + states.push_back(colorblend_attachment); + } + return states; } Result GraphicsPipeline::CreateVkGraphicsPipeline( @@ -653,16 +656,17 @@ Result GraphicsPipeline::CreateVkGraphicsPipeline( VkPipelineColorBlendStateCreateInfo colorblend_info = VkPipelineColorBlendStateCreateInfo(); - VkPipelineColorBlendAttachmentState colorblend_attachment; - colorblend_attachment = GetVkPipelineColorBlendAttachmentState(pipeline_data); + auto colorblend_attachment = + GetVkPipelineColorBlendAttachmentState(pipeline_data); colorblend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorblend_info.logicOpEnable = pipeline_data->GetEnableLogicOp(); colorblend_info.logicOp = ToVkLogicOp(pipeline_data->GetLogicOp()); - colorblend_info.attachmentCount = 1; - colorblend_info.pAttachments = &colorblend_attachment; + colorblend_info.attachmentCount = + static_cast(colorblend_attachment.size()); + colorblend_info.pAttachments = colorblend_attachment.data(); pipeline_info.pColorBlendState = &colorblend_info; pipeline_info.layout = pipeline_layout; diff --git a/src/vulkan/graphics_pipeline.h b/src/vulkan/graphics_pipeline.h index 2130e0ff9..f8be8a732 100644 --- a/src/vulkan/graphics_pipeline.h +++ b/src/vulkan/graphics_pipeline.h @@ -82,8 +82,8 @@ class GraphicsPipeline : public Pipeline { VkPipelineDepthStencilStateCreateInfo GetVkPipelineDepthStencilInfo( const PipelineData* pipeline_data); - VkPipelineColorBlendAttachmentState GetVkPipelineColorBlendAttachmentState( - const PipelineData* pipeline_data); + std::vector + GetVkPipelineColorBlendAttachmentState(const PipelineData* pipeline_data); VkRenderPass render_pass_ = VK_NULL_HANDLE; std::unique_ptr frame_;