aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2019-03-25 09:54:55 -0400
committerJaebaek Seo <duke.acacia@gmail.com>2019-03-25 09:54:55 -0400
commit724d61f7ae34d5b20787f73b26f20af67ad32d2d (patch)
treef4cb0021c2acbf6eb1ca275713402ce64b9e02bf /src
parentafe0881acf57b7185230601200e1e69df587c88d (diff)
downloadamber-724d61f7ae34d5b20787f73b26f20af67ad32d2d.tar.gz
[vulkan] merge Descriptor and BufferDescriptor. (#410)
This CL merges the Descriptor and BufferDescriptor classes together into BufferDescriptor. Currently BufferDescriptor is the only subclass of Descriptor. This allows simplifying the code as we don't have to assume other kinds of descriptors.
Diffstat (limited to 'src')
-rw-r--r--src/vulkan/CMakeLists.txt1
-rw-r--r--src/vulkan/buffer_descriptor.cc59
-rw-r--r--src/vulkan/buffer_descriptor.h50
-rw-r--r--src/vulkan/compute_pipeline.cc4
-rw-r--r--src/vulkan/descriptor.cc76
-rw-r--r--src/vulkan/descriptor.h120
-rw-r--r--src/vulkan/engine_vulkan.cc1
-rw-r--r--src/vulkan/engine_vulkan.h1
-rw-r--r--src/vulkan/graphics_pipeline.cc4
-rw-r--r--src/vulkan/pipeline.cc65
-rw-r--r--src/vulkan/pipeline.h6
11 files changed, 90 insertions, 297 deletions
diff --git a/src/vulkan/CMakeLists.txt b/src/vulkan/CMakeLists.txt
index 4eaa5ea..376ea53 100644
--- a/src/vulkan/CMakeLists.txt
+++ b/src/vulkan/CMakeLists.txt
@@ -17,7 +17,6 @@ set(VULKAN_ENGINE_SOURCES
command_buffer.cc
command_pool.cc
compute_pipeline.cc
- descriptor.cc
device.cc
engine_vulkan.cc
format_data.cc
diff --git a/src/vulkan/buffer_descriptor.cc b/src/vulkan/buffer_descriptor.cc
index d58e59d..360adb6 100644
--- a/src/vulkan/buffer_descriptor.cc
+++ b/src/vulkan/buffer_descriptor.cc
@@ -23,6 +23,7 @@
#include "src/engine.h"
#include "src/make_unique.h"
#include "src/vulkan/command_buffer.h"
+#include "src/vulkan/device.h"
namespace amber {
namespace vulkan {
@@ -32,10 +33,11 @@ BufferDescriptor::BufferDescriptor(Buffer* buffer,
Device* device,
uint32_t desc_set,
uint32_t binding)
- : Descriptor(type, device, desc_set, binding), amber_buffer_(buffer) {
- assert(type == DescriptorType::kStorageBuffer ||
- type == DescriptorType::kUniformBuffer);
-}
+ : device_(device),
+ amber_buffer_(buffer),
+ type_(type),
+ descriptor_set_(desc_set),
+ binding_(binding) {}
BufferDescriptor::~BufferDescriptor() = default;
@@ -56,17 +58,18 @@ Result BufferDescriptor::CreateResourceIfNeeded(
transfer_buffer_ =
MakeUnique<TransferBuffer>(device_, size_in_bytes, properties);
- Result r = transfer_buffer_->Initialize(GetVkBufferUsage() |
- VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
- VK_BUFFER_USAGE_TRANSFER_DST_BIT);
+ Result r = transfer_buffer_->Initialize(
+ (IsStorageBuffer() ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
+ : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) |
+ VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
if (!r.IsSuccess())
return r;
- SetUpdateDescriptorSetNeeded();
+ is_descriptor_set_update_needed_ = true;
return {};
}
-Result BufferDescriptor::RecordCopyDataToResourceIfNeeded(
+void BufferDescriptor::RecordCopyDataToResourceIfNeeded(
CommandBuffer* command) {
if (amber_buffer_ && !amber_buffer_->ValuePtr()->empty()) {
transfer_buffer_->UpdateMemoryWithRawData(*amber_buffer_->ValuePtr());
@@ -74,14 +77,12 @@ Result BufferDescriptor::RecordCopyDataToResourceIfNeeded(
}
transfer_buffer_->CopyToDevice(command);
- return {};
}
Result BufferDescriptor::RecordCopyDataToHost(CommandBuffer* command) {
if (!transfer_buffer_) {
return Result(
- "Vulkan: BufferDescriptor::RecordCopyDataToHost() |vk_buffer| is "
- "empty");
+ "Vulkan: BufferDescriptor::RecordCopyDataToHost() no transfer buffer");
}
return transfer_buffer_->CopyToHost(command);
@@ -90,8 +91,8 @@ Result BufferDescriptor::RecordCopyDataToHost(CommandBuffer* command) {
Result BufferDescriptor::MoveResourceToBufferOutput() {
if (!transfer_buffer_) {
return Result(
- "Vulkan: BufferDescriptor::MoveResourceToBufferOutput() |vk_buffer| "
- "is empty");
+ "Vulkan: BufferDescriptor::MoveResourceToBufferOutput() no transfer"
+ " buffer");
}
// Only need to copy the buffer back if we have an attached amber buffer to
@@ -100,8 +101,8 @@ Result BufferDescriptor::MoveResourceToBufferOutput() {
void* resource_memory_ptr = transfer_buffer_->HostAccessibleMemoryPtr();
if (!resource_memory_ptr) {
return Result(
- "Vulkan: BufferDescriptor::MoveResourceToBufferOutput() |vk_buffer| "
- "has nullptr host accessible memory");
+ "Vulkan: BufferDescriptor::MoveResourceToBufferOutput() "
+ "no host accessible memory pointer");
}
if (!amber_buffer_->ValuePtr()->empty()) {
@@ -121,18 +122,29 @@ Result BufferDescriptor::MoveResourceToBufferOutput() {
return {};
}
-Result BufferDescriptor::UpdateDescriptorSetIfNeeded(
+void BufferDescriptor::UpdateDescriptorSetIfNeeded(
VkDescriptorSet descriptor_set) {
- if (!IsDescriptorSetUpdateNeeded())
- return {};
+ if (!is_descriptor_set_update_needed_)
+ return;
VkDescriptorBufferInfo buffer_info = VkDescriptorBufferInfo();
buffer_info.buffer = transfer_buffer_->GetVkBuffer();
buffer_info.offset = 0;
buffer_info.range = VK_WHOLE_SIZE;
- return Descriptor::UpdateDescriptorSetForBuffer(
- descriptor_set, GetVkDescriptorType(), buffer_info);
+ VkWriteDescriptorSet write = VkWriteDescriptorSet();
+ write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ write.dstSet = descriptor_set;
+ write.dstBinding = binding_;
+ write.dstArrayElement = 0;
+ write.descriptorCount = 1;
+ write.descriptorType = IsStorageBuffer() ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
+ : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ write.pBufferInfo = &buffer_info;
+
+ device_->GetPtrs()->vkUpdateDescriptorSets(device_->GetVkDevice(), 1, &write,
+ 0, nullptr);
+ is_descriptor_set_update_needed_ = false;
}
Result BufferDescriptor::AddToBuffer(DataType type,
@@ -153,5 +165,10 @@ Result BufferDescriptor::AddToBuffer(DataType type,
return {};
}
+VkDescriptorType BufferDescriptor::GetVkDescriptorType() const {
+ return IsStorageBuffer() ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
+ : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+}
+
} // namespace vulkan
} // namespace amber
diff --git a/src/vulkan/buffer_descriptor.h b/src/vulkan/buffer_descriptor.h
index 3d2c098..c4ba908 100644
--- a/src/vulkan/buffer_descriptor.h
+++ b/src/vulkan/buffer_descriptor.h
@@ -24,7 +24,6 @@
#include "src/buffer.h"
#include "src/datum_type.h"
#include "src/engine.h"
-#include "src/vulkan/descriptor.h"
#include "src/vulkan/transfer_buffer.h"
namespace amber {
@@ -33,24 +32,40 @@ namespace vulkan {
class CommandBuffer;
class Device;
+enum class DescriptorType : uint8_t {
+ kStorageBuffer = 0,
+ kUniformBuffer,
+};
+
// Among Vulkan descriptor types, this class handles Storage Buffers
// and Uniform Buffers.
-class BufferDescriptor : public Descriptor {
+class BufferDescriptor {
public:
BufferDescriptor(Buffer* buffer,
DescriptorType type,
Device* device,
uint32_t desc_set,
uint32_t binding);
- ~BufferDescriptor() override;
+ ~BufferDescriptor();
+
+ uint32_t GetDescriptorSet() const { return descriptor_set_; }
+ uint32_t GetBinding() const { return binding_; }
+
+ VkDescriptorType GetVkDescriptorType() const;
+
+ bool IsStorageBuffer() const {
+ return type_ == DescriptorType::kStorageBuffer;
+ }
+ bool IsUniformBuffer() const {
+ return type_ == DescriptorType::kUniformBuffer;
+ }
- // Descriptor
Result CreateResourceIfNeeded(
- const VkPhysicalDeviceMemoryProperties& properties) override;
- Result RecordCopyDataToResourceIfNeeded(CommandBuffer* command) override;
- Result RecordCopyDataToHost(CommandBuffer* command) override;
- Result MoveResourceToBufferOutput() override;
- Result UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set) override;
+ const VkPhysicalDeviceMemoryProperties& properties);
+ void RecordCopyDataToResourceIfNeeded(CommandBuffer* command);
+ Result RecordCopyDataToHost(CommandBuffer* command);
+ Result MoveResourceToBufferOutput();
+ void UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set);
Result AddToBuffer(DataType type,
uint32_t offset,
@@ -58,18 +73,15 @@ class BufferDescriptor : public Descriptor {
const std::vector<Value>& values);
private:
- VkBufferUsageFlagBits GetVkBufferUsage() const {
- return IsStorageBuffer() ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
- : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
- }
-
- VkDescriptorType GetVkDescriptorType() const {
- return IsStorageBuffer() ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
- : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- }
-
+ Device* device_ = nullptr;
Buffer* amber_buffer_ = nullptr;
std::unique_ptr<TransferBuffer> transfer_buffer_;
+
+ DescriptorType type_ = DescriptorType::kStorageBuffer;
+
+ bool is_descriptor_set_update_needed_ = false;
+ uint32_t descriptor_set_ = 0;
+ uint32_t binding_ = 0;
};
} // namespace vulkan
diff --git a/src/vulkan/compute_pipeline.cc b/src/vulkan/compute_pipeline.cc
index 41dcdf9..da6c0de 100644
--- a/src/vulkan/compute_pipeline.cc
+++ b/src/vulkan/compute_pipeline.cc
@@ -86,9 +86,7 @@ Result ComputePipeline::Compute(uint32_t x, uint32_t y, uint32_t z) {
// Note that a command updating a descriptor set and a command using
// it must be submitted separately, because using a descriptor set
// while updating it is not safe.
- r = UpdateDescriptorSetsIfNeeded();
- if (!r.IsSuccess())
- return r;
+ UpdateDescriptorSetsIfNeeded();
{
CommandBufferGuard guard(GetCommandBuffer());
diff --git a/src/vulkan/descriptor.cc b/src/vulkan/descriptor.cc
deleted file mode 100644
index a54b575..0000000
--- a/src/vulkan/descriptor.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2018 The Amber Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "src/vulkan/descriptor.h"
-
-#include "src/vulkan/device.h"
-
-namespace amber {
-namespace vulkan {
-
-Descriptor::Descriptor(DescriptorType type,
- Device* device,
- uint32_t desc_set,
- uint32_t binding)
- : descriptor_set_(desc_set),
- binding_(binding),
- device_(device),
- type_(type) {}
-
-Descriptor::~Descriptor() = default;
-
-VkWriteDescriptorSet Descriptor::GetWriteDescriptorSet(
- VkDescriptorSet descriptor_set,
- VkDescriptorType descriptor_type) const {
- VkWriteDescriptorSet write = VkWriteDescriptorSet();
- write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- write.dstSet = descriptor_set;
- write.dstBinding = binding_;
- write.dstArrayElement = 0;
- write.descriptorCount = 1;
- write.descriptorType = descriptor_type;
- return write;
-}
-
-Result Descriptor::UpdateDescriptorSetForBuffer(
- VkDescriptorSet descriptor_set,
- VkDescriptorType descriptor_type,
- const VkDescriptorBufferInfo& buffer_info) {
- VkWriteDescriptorSet write =
- GetWriteDescriptorSet(descriptor_set, descriptor_type);
- switch (descriptor_type) {
- case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
- case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
- case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
- case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
- write.pBufferInfo = &buffer_info;
- break;
- default:
- return Result(
- "Vulkan::UpdateDescriptorSetForBuffer not descriptor based on "
- "buffer");
- }
-
- UpdateVkDescriptorSet(write);
- return {};
-}
-
-void Descriptor::UpdateVkDescriptorSet(const VkWriteDescriptorSet& write) {
- device_->GetPtrs()->vkUpdateDescriptorSets(device_->GetVkDevice(), 1, &write,
- 0, nullptr);
- is_descriptor_set_update_needed_ = false;
-}
-
-} // namespace vulkan
-} // namespace amber
diff --git a/src/vulkan/descriptor.h b/src/vulkan/descriptor.h
deleted file mode 100644
index 1c8300a..0000000
--- a/src/vulkan/descriptor.h
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2018 The Amber Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef SRC_VULKAN_DESCRIPTOR_H_
-#define SRC_VULKAN_DESCRIPTOR_H_
-
-#include <memory>
-#include <vector>
-
-#include "amber/result.h"
-#include "amber/vulkan_header.h"
-#include "src/datum_type.h"
-#include "src/engine.h"
-#include "src/vulkan/resource.h"
-
-namespace amber {
-namespace vulkan {
-
-enum class DescriptorType : uint8_t {
- kStorageBuffer = 0,
- kUniformBuffer,
-};
-
-class CommandBuffer;
-class Device;
-
-class Descriptor {
- public:
- Descriptor(DescriptorType type,
- Device* device,
- uint32_t desc_set,
- uint32_t binding);
-
- virtual ~Descriptor();
-
- uint32_t GetDescriptorSet() const { return descriptor_set_; }
- uint32_t GetBinding() const { return binding_; }
-
- DescriptorType GetType() const { return type_; }
-
- bool IsStorageBuffer() const {
- return type_ == DescriptorType::kStorageBuffer;
- }
- bool IsUniformBuffer() const {
- return type_ == DescriptorType::kUniformBuffer;
- }
-
- // Call vkUpdateDescriptorSets() to update the backing resource
- // for this descriptor only when the backing resource was newly
- // created or changed.
- virtual Result UpdateDescriptorSetIfNeeded(VkDescriptorSet) = 0;
-
- // Create vulkan resource e.g., buffer or image used for this
- // descriptor if needed. This method assumes that the resource is empty when
- // it is called that means the resource must be created only when it is
- // actually needed i.e., compute or draw command and destroyed right after
- // those commands.
- virtual Result CreateResourceIfNeeded(
- const VkPhysicalDeviceMemoryProperties& properties) = 0;
-
- // Record a command for copying buffer data to the resource in device. After
- // the copy it clears the internal buffer data. Note that
- // it only records the command and the actual submission must be
- // done later.
- virtual Result RecordCopyDataToResourceIfNeeded(CommandBuffer* command) = 0;
-
- // Only record the copy command for copying the resource data to
- // the host accessible memory. The actual submission of the command
- // must be done later.
- virtual Result RecordCopyDataToHost(CommandBuffer* command) = 0;
-
- // Copy contents of resource e.g., VkBuffer to host buffer.
- // This method assumes that we already copy the resource data to the host
- // accessible memory by calling RecordCopyDataToHost() method and submitting
- // the command buffer. After copying the contents, it destroys |buffer_|.
- virtual Result MoveResourceToBufferOutput() = 0;
-
- protected:
- Result UpdateDescriptorSetForBuffer(
- VkDescriptorSet descriptor_set,
- VkDescriptorType descriptor_type,
- const VkDescriptorBufferInfo& buffer_info);
-
- void SetUpdateDescriptorSetNeeded() {
- is_descriptor_set_update_needed_ = true;
- }
- bool IsDescriptorSetUpdateNeeded() {
- return is_descriptor_set_update_needed_;
- }
-
- uint32_t descriptor_set_ = 0;
- uint32_t binding_ = 0;
- Device* device_ = nullptr;
-
- private:
- VkWriteDescriptorSet GetWriteDescriptorSet(
- VkDescriptorSet descriptor_set,
- VkDescriptorType descriptor_type) const;
- void UpdateVkDescriptorSet(const VkWriteDescriptorSet& write);
-
- DescriptorType type_ = DescriptorType::kStorageBuffer;
-
- bool is_descriptor_set_update_needed_ = false;
-};
-
-} // namespace vulkan
-} // namespace amber
-
-#endif // SRC_VULKAN_DESCRIPTOR_H_
diff --git a/src/vulkan/engine_vulkan.cc b/src/vulkan/engine_vulkan.cc
index 9c147aa..cb177a3 100644
--- a/src/vulkan/engine_vulkan.cc
+++ b/src/vulkan/engine_vulkan.cc
@@ -21,7 +21,6 @@
#include "amber/amber_vulkan.h"
#include "src/make_unique.h"
#include "src/vulkan/compute_pipeline.h"
-#include "src/vulkan/descriptor.h"
#include "src/vulkan/format_data.h"
#include "src/vulkan/graphics_pipeline.h"
diff --git a/src/vulkan/engine_vulkan.h b/src/vulkan/engine_vulkan.h
index 9374775..fae2b5a 100644
--- a/src/vulkan/engine_vulkan.h
+++ b/src/vulkan/engine_vulkan.h
@@ -25,6 +25,7 @@
#include "src/cast_hash.h"
#include "src/engine.h"
#include "src/pipeline.h"
+#include "src/vulkan/buffer_descriptor.h"
#include "src/vulkan/command_pool.h"
#include "src/vulkan/device.h"
#include "src/vulkan/pipeline.h"
diff --git a/src/vulkan/graphics_pipeline.cc b/src/vulkan/graphics_pipeline.cc
index 705ca37..b9f7736 100644
--- a/src/vulkan/graphics_pipeline.cc
+++ b/src/vulkan/graphics_pipeline.cc
@@ -848,9 +848,7 @@ Result GraphicsPipeline::Draw(const DrawArraysCommand* command,
// Note that a command updating a descriptor set and a command using
// it must be submitted separately, because using a descriptor set
// while updating it is not safe.
- r = UpdateDescriptorSetsIfNeeded();
- if (!r.IsSuccess())
- return r;
+ UpdateDescriptorSetsIfNeeded();
{
CommandBufferGuard cmd_buf_guard(GetCommandBuffer());
diff --git a/src/vulkan/pipeline.cc b/src/vulkan/pipeline.cc
index de7c20c..d0257f3 100644
--- a/src/vulkan/pipeline.cc
+++ b/src/vulkan/pipeline.cc
@@ -32,21 +32,6 @@ namespace {
const char* kDefaultEntryPointName = "main";
-Result ToVkDescriptorType(DescriptorType type, VkDescriptorType* ret) {
- Result r = Result("Unknown resource type");
- switch (type) {
- case DescriptorType::kStorageBuffer:
- *ret = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
- r = {};
- break;
- case DescriptorType::kUniformBuffer:
- *ret = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- r = {};
- break;
- }
- return r;
-}
-
} // namespace
Pipeline::Pipeline(
@@ -109,15 +94,10 @@ Result Pipeline::CreateDescriptorSetLayouts() {
// If there are no descriptors for this descriptor set we only
// need to create its layout and there will be no bindings.
std::vector<VkDescriptorSetLayoutBinding> bindings;
- for (auto& desc : info.descriptors_) {
- VkDescriptorType desc_type = VK_DESCRIPTOR_TYPE_MAX_ENUM;
- Result r = ToVkDescriptorType(desc->GetType(), &desc_type);
- if (!r.IsSuccess())
- return r;
-
+ for (auto& desc : info.buffer_descriptors) {
bindings.emplace_back();
bindings.back().binding = desc->GetBinding();
- bindings.back().descriptorType = desc_type;
+ bindings.back().descriptorType = desc->GetVkDescriptorType();
bindings.back().descriptorCount = 1;
bindings.back().stageFlags = VK_SHADER_STAGE_ALL;
}
@@ -140,12 +120,8 @@ Result Pipeline::CreateDescriptorPools() {
continue;
std::vector<VkDescriptorPoolSize> pool_sizes;
- for (auto& desc : info.descriptors_) {
- VkDescriptorType type;
- Result r = ToVkDescriptorType(desc->GetType(), &type);
- if (!r.IsSuccess())
- return r;
-
+ for (auto& desc : info.buffer_descriptors) {
+ VkDescriptorType type = desc->GetVkDescriptorType();
auto it = find_if(pool_sizes.begin(), pool_sizes.end(),
[&type](const VkDescriptorPoolSize& size) {
return size.type == type;
@@ -250,16 +226,11 @@ Result Pipeline::CreateVkDescriptorRelatedObjectsIfNeeded() {
return {};
}
-Result Pipeline::UpdateDescriptorSetsIfNeeded() {
+void Pipeline::UpdateDescriptorSetsIfNeeded() {
for (auto& info : descriptor_set_info_) {
- for (auto& desc : info.descriptors_) {
- Result r = desc->UpdateDescriptorSetIfNeeded(info.vk_desc_set);
- if (!r.IsSuccess())
- return r;
- }
+ for (auto& desc : info.buffer_descriptors)
+ desc->UpdateDescriptorSetIfNeeded(info.vk_desc_set);
}
-
- return {};
}
Result Pipeline::RecordPushConstant(const VkPipelineLayout& pipeline_layout) {
@@ -300,8 +271,8 @@ Result Pipeline::AddDescriptor(const BufferCommand* cmd) {
}
descriptor_set_info_[desc_set].empty = false;
- auto& descriptors = descriptor_set_info_[desc_set].descriptors_;
- Descriptor* desc = nullptr;
+ auto& descriptors = descriptor_set_info_[desc_set].buffer_descriptors;
+ BufferDescriptor* desc = nullptr;
for (auto& descriptor : descriptors) {
if (descriptor->GetBinding() == cmd->GetBinding())
desc = descriptor.get();
@@ -347,7 +318,7 @@ Result Pipeline::SendDescriptorDataToDeviceIfNeeded() {
return guard.GetResult();
for (auto& info : descriptor_set_info_) {
- for (auto& desc : info.descriptors_) {
+ for (auto& desc : info.buffer_descriptors) {
Result r = desc->CreateResourceIfNeeded(memory_properties_);
if (!r.IsSuccess())
return r;
@@ -370,11 +341,8 @@ Result Pipeline::SendDescriptorDataToDeviceIfNeeded() {
return guard.GetResult();
for (auto& info : descriptor_set_info_) {
- for (auto& desc : info.descriptors_) {
- Result r = desc->RecordCopyDataToResourceIfNeeded(command_.get());
- if (!r.IsSuccess())
- return r;
- }
+ for (auto& desc : info.buffer_descriptors)
+ desc->RecordCopyDataToResourceIfNeeded(command_.get());
}
return guard.Submit(GetFenceTimeout());
}
@@ -400,11 +368,8 @@ Result Pipeline::ReadbackDescriptorsToHostDataQueue() {
return guard.GetResult();
for (auto& desc_set : descriptor_set_info_) {
- for (auto& desc : desc_set.descriptors_) {
- Result r = desc->RecordCopyDataToHost(command_.get());
- if (!r.IsSuccess())
- return r;
- }
+ for (auto& desc : desc_set.buffer_descriptors)
+ desc->RecordCopyDataToHost(command_.get());
}
Result r = guard.Submit(GetFenceTimeout());
@@ -413,7 +378,7 @@ Result Pipeline::ReadbackDescriptorsToHostDataQueue() {
}
for (auto& desc_set : descriptor_set_info_) {
- for (auto& desc : desc_set.descriptors_) {
+ for (auto& desc : desc_set.buffer_descriptors) {
Result r = desc->MoveResourceToBufferOutput();
if (!r.IsSuccess())
return r;
diff --git a/src/vulkan/pipeline.h b/src/vulkan/pipeline.h
index 7240910..4a9a099 100644
--- a/src/vulkan/pipeline.h
+++ b/src/vulkan/pipeline.h
@@ -24,8 +24,8 @@
#include "amber/vulkan_header.h"
#include "src/cast_hash.h"
#include "src/engine.h"
+#include "src/vulkan/buffer_descriptor.h"
#include "src/vulkan/command_buffer.h"
-#include "src/vulkan/descriptor.h"
#include "src/vulkan/push_constant.h"
namespace amber {
@@ -77,7 +77,7 @@ class Pipeline {
// Initialize the pipeline.
Result Initialize(CommandPool* pool, VkQueue queue);
- Result UpdateDescriptorSetsIfNeeded();
+ void UpdateDescriptorSetsIfNeeded();
Result SendDescriptorDataToDeviceIfNeeded();
void BindVkDescriptorSets(const VkPipelineLayout& pipeline_layout);
@@ -105,7 +105,7 @@ class Pipeline {
VkDescriptorSetLayout layout = VK_NULL_HANDLE;
VkDescriptorPool pool = VK_NULL_HANDLE;
VkDescriptorSet vk_desc_set = VK_NULL_HANDLE;
- std::vector<std::unique_ptr<Descriptor>> descriptors_;
+ std::vector<std::unique_ptr<BufferDescriptor>> buffer_descriptors;
};
// Create Vulkan descriptor related objects i.e.,