From 532a274fb38a0b17acd3c2e913355c12e016c744 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 12 Mar 2019 12:44:26 -0400 Subject: [vulkan] Set correct colour attachment locations. (#353) This CL fixes the colour attachment code to set the colour attachment into the requested location, not the order they were attached. This allows setting the locations out of order. Note, the locations must be a complete set of numbers starting from 0. --- src/vulkan/frame_buffer.cc | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/vulkan/frame_buffer.cc b/src/vulkan/frame_buffer.cc index f32f0e3..4642454 100644 --- a/src/vulkan/frame_buffer.cc +++ b/src/vulkan/frame_buffer.cc @@ -14,6 +14,7 @@ #include "src/vulkan/frame_buffer.h" +#include #include #include #include @@ -44,18 +45,34 @@ Result FrameBuffer::Initialize( const VkPhysicalDeviceMemoryProperties& properties) { std::vector attachments; - for (auto* info : color_attachments_) { - color_images_.push_back(MakeUnique( - device_, - ToVkFormat(info->buffer->AsFormatBuffer()->GetFormat().GetFormatType()), - VK_IMAGE_ASPECT_COLOR_BIT, width_, height_, depth_, properties)); - - Result r = color_images_.back()->Initialize( - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); - if (!r.IsSuccess()) - return r; + if (!color_attachments_.empty()) { + std::vector seen_idx(color_attachments_.size(), -1); + for (auto* info : color_attachments_) { + if (info->location >= color_attachments_.size()) + return Result("color attachment locations must be sequential from 0"); + if (seen_idx[info->location] != -1) { + return Result("duplicate attachment location: " + + std::to_string(info->location)); + } + seen_idx[info->location] = static_cast(info->location); + } - attachments.push_back(color_images_.back()->GetVkImageView()); + attachments.resize(color_attachments_.size()); + for (auto* info : color_attachments_) { + color_images_.push_back(MakeUnique( + device_, + ToVkFormat( + info->buffer->AsFormatBuffer()->GetFormat().GetFormatType()), + VK_IMAGE_ASPECT_COLOR_BIT, width_, height_, depth_, properties)); + + Result r = + color_images_.back()->Initialize(VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); + if (!r.IsSuccess()) + return r; + + attachments[info->location] = color_images_.back()->GetVkImageView(); + } } if (depth_format != VK_FORMAT_UNDEFINED) { -- cgit v1.2.3