From e93e6bf31d0000d34807a576e6ef38f83c49616b Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Sat, 6 Jul 2019 11:51:58 -0400 Subject: [PATCH 1/4] [vulkan] Fixup colour attachment setup for render pass. This CL 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..d50cb6667 100644 --- a/src/vulkan/graphics_pipeline.cc +++ b/src/vulkan/graphics_pipeline.cc @@ -422,11 +422,10 @@ 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 +502,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 +657,16 @@ 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..ebb938189 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_; From 12c43b872a1a9d5b4f2afb73b1e95c2ee23c8162 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 8 Jul 2019 09:55:41 -0400 Subject: [PATCH 2/4] Update graphics_pipeline.cc --- src/vulkan/graphics_pipeline.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vulkan/graphics_pipeline.cc b/src/vulkan/graphics_pipeline.cc index d50cb6667..78de00825 100644 --- a/src/vulkan/graphics_pipeline.cc +++ b/src/vulkan/graphics_pipeline.cc @@ -658,7 +658,8 @@ Result GraphicsPipeline::CreateVkGraphicsPipeline( VkPipelineColorBlendStateCreateInfo colorblend_info = VkPipelineColorBlendStateCreateInfo(); - auto colorblend_attachment = GetVkPipelineColorBlendAttachmentState(pipeline_data); + auto colorblend_attachment = + GetVkPipelineColorBlendAttachmentState(pipeline_data); colorblend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; From 1bb5c12bbf2574fb5ffd2494cf71f7ff4c5e4318 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 8 Jul 2019 10:35:49 -0400 Subject: [PATCH 3/4] Update graphics_pipeline.cc --- src/vulkan/graphics_pipeline.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vulkan/graphics_pipeline.cc b/src/vulkan/graphics_pipeline.cc index 78de00825..31c194c29 100644 --- a/src/vulkan/graphics_pipeline.cc +++ b/src/vulkan/graphics_pipeline.cc @@ -423,8 +423,7 @@ Result GraphicsPipeline::CreateRenderPass() { ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; color_refer.push_back(ref); } - subpass_desc.colorAttachmentCount = - static_cast(color_refer.size()); + subpass_desc.colorAttachmentCount = static_cast(color_refer.size()); subpass_desc.pColorAttachments = color_refer.data(); if (depth_stencil_format_.IsFormatKnown()) { From b2cf5f6977b7e1a43e0ef73682b7364d2764f39b Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 8 Jul 2019 10:36:42 -0400 Subject: [PATCH 4/4] Update graphics_pipeline.h --- src/vulkan/graphics_pipeline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vulkan/graphics_pipeline.h b/src/vulkan/graphics_pipeline.h index ebb938189..f8be8a732 100644 --- a/src/vulkan/graphics_pipeline.h +++ b/src/vulkan/graphics_pipeline.h @@ -83,7 +83,7 @@ class GraphicsPipeline : public Pipeline { VkPipelineDepthStencilStateCreateInfo GetVkPipelineDepthStencilInfo( const PipelineData* pipeline_data); std::vector - GetVkPipelineColorBlendAttachmentState(const PipelineData* pipeline_data); + GetVkPipelineColorBlendAttachmentState(const PipelineData* pipeline_data); VkRenderPass render_pass_ = VK_NULL_HANDLE; std::unique_ptr frame_;