aboutsummaryrefslogtreecommitdiff
path: root/src/vulkan/graphics_pipeline.cc
diff options
context:
space:
mode:
authorasuonpaa <34128694+asuonpaa@users.noreply.github.com>2021-11-12 12:25:00 +0200
committerGitHub <noreply@github.com>2021-11-12 10:25:00 +0000
commit5bd7d35a38e410892fb73c7a54fd2a20534480cd (patch)
tree6922c41a2aa5ad8d37c70818ae887f1567f0e299 /src/vulkan/graphics_pipeline.cc
parent02dc821ced6d786af712fcacd13462210bb34009 (diff)
downloadamber-5bd7d35a38e410892fb73c7a54fd2a20534480cd.tar.gz
Add support for multisample resolve (#970)
Multisample images were already supported, but graphics pipelines were not able to resolve these into single sample images.
Diffstat (limited to 'src/vulkan/graphics_pipeline.cc')
-rw-r--r--src/vulkan/graphics_pipeline.cc38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/vulkan/graphics_pipeline.cc b/src/vulkan/graphics_pipeline.cc
index 5536440..9e3c7ac 100644
--- a/src/vulkan/graphics_pipeline.cc
+++ b/src/vulkan/graphics_pipeline.cc
@@ -386,6 +386,7 @@ GraphicsPipeline::GraphicsPipeline(
Device* device,
const std::vector<amber::Pipeline::BufferInfo>& color_buffers,
amber::Pipeline::BufferInfo depth_stencil_buffer,
+ const std::vector<amber::Pipeline::BufferInfo>& resolve_targets,
uint32_t fence_timeout_ms,
const std::vector<VkPipelineShaderStageCreateInfo>& shader_stage_info)
: Pipeline(PipelineType::kGraphics,
@@ -395,6 +396,8 @@ GraphicsPipeline::GraphicsPipeline(
depth_stencil_buffer_(depth_stencil_buffer) {
for (const auto& info : color_buffers)
color_buffers_.push_back(&info);
+ for (const auto& info : resolve_targets)
+ resolve_targets_.push_back(&info);
}
GraphicsPipeline::~GraphicsPipeline() {
@@ -412,6 +415,7 @@ Result GraphicsPipeline::CreateRenderPass() {
std::vector<VkAttachmentReference> color_refer;
VkAttachmentReference depth_refer = VkAttachmentReference();
+ std::vector<VkAttachmentReference> resolve_refer;
for (const auto* info : color_buffers_) {
attachment_desc.push_back(kDefaultAttachmentDesc);
@@ -421,6 +425,8 @@ Result GraphicsPipeline::CreateRenderPass() {
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachment_desc.back().finalLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ attachment_desc.back().samples =
+ static_cast<VkSampleCountFlagBits>(info->buffer->GetSamples());
VkAttachmentReference ref = VkAttachmentReference();
ref.attachment = static_cast<uint32_t>(attachment_desc.size() - 1);
@@ -446,6 +452,23 @@ Result GraphicsPipeline::CreateRenderPass() {
subpass_desc.pDepthStencilAttachment = &depth_refer;
}
+ for (const auto* info : resolve_targets_) {
+ attachment_desc.push_back(kDefaultAttachmentDesc);
+ attachment_desc.back().format =
+ device_->GetVkFormat(*info->buffer->GetFormat());
+ attachment_desc.back().initialLayout =
+ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ attachment_desc.back().finalLayout =
+ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ VkAttachmentReference ref = VkAttachmentReference();
+ ref.attachment = static_cast<uint32_t>(attachment_desc.size() - 1);
+ ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ resolve_refer.push_back(ref);
+ }
+
+ subpass_desc.pResolveAttachments = resolve_refer.data();
+
VkRenderPassCreateInfo render_pass_info = VkRenderPassCreateInfo();
render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
render_pass_info.attachmentCount =
@@ -621,6 +644,16 @@ Result GraphicsPipeline::CreateVkGraphicsPipeline(
VK_FALSE, /* alphaToOneEnable */
};
+ // Search for multisampled color buffers and adjust the rasterization samples
+ // to match.
+ for (const auto& cb : color_buffers_) {
+ uint32_t samples = cb->buffer->GetSamples();
+ assert(static_cast<VkSampleCountFlagBits>(samples) >=
+ multisampleInfo.rasterizationSamples);
+ multisampleInfo.rasterizationSamples =
+ static_cast<VkSampleCountFlagBits>(samples);
+ }
+
VkGraphicsPipelineCreateInfo pipeline_info = VkGraphicsPipelineCreateInfo();
pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipeline_info.stageCount = static_cast<uint32_t>(shader_stage_info.size());
@@ -704,8 +737,9 @@ Result GraphicsPipeline::Initialize(uint32_t width,
if (!r.IsSuccess())
return r;
- frame_ = MakeUnique<FrameBuffer>(device_, color_buffers_,
- depth_stencil_buffer_, width, height);
+ frame_ =
+ MakeUnique<FrameBuffer>(device_, color_buffers_, depth_stencil_buffer_,
+ resolve_targets_, width, height);
r = frame_->Initialize(render_pass_);
if (!r.IsSuccess())
return r;