diff options
author | dan sinclair <dj2@everburning.com> | 2019-03-12 12:44:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-12 12:44:26 -0400 |
commit | 532a274fb38a0b17acd3c2e913355c12e016c744 (patch) | |
tree | 31aa7a8e10004c98e8466ddbe4243d1c2038f3b1 | |
parent | 6bebb11e52056e8ec7bb1b367b86f47e20cd0e9c (diff) | |
download | amber-532a274fb38a0b17acd3c2e913355c12e016c744.tar.gz |
[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.
-rw-r--r-- | src/vulkan/frame_buffer.cc | 39 |
1 files 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 <algorithm> #include <cassert> #include <limits> #include <vector> @@ -44,18 +45,34 @@ Result FrameBuffer::Initialize( const VkPhysicalDeviceMemoryProperties& properties) { std::vector<VkImageView> attachments; - for (auto* info : color_attachments_) { - color_images_.push_back(MakeUnique<Image>( - 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<int32_t> 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<int32_t>(info->location); + } - attachments.push_back(color_images_.back()->GetVkImageView()); + attachments.resize(color_attachments_.size()); + for (auto* info : color_attachments_) { + color_images_.push_back(MakeUnique<Image>( + 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) { |