diff options
author | dan sinclair <dj2@everburning.com> | 2019-03-14 09:35:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 09:35:20 -0400 |
commit | f25114b40a6852618f553a2e3dca4d3947868a61 (patch) | |
tree | 02646e44335afa4d7409052ea27c9bf3e61f4ba1 /src/vulkan | |
parent | 841680c8f76b2c69abf288c7397b181709a27bcf (diff) | |
download | amber-f25114b40a6852618f553a2e3dca4d3947868a61.tar.gz |
[vulkan] remove Shutdown methods. (#366)
This CL moves Shutdown methods to destructors where possible.
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/buffer_descriptor.cc | 6 | ||||
-rw-r--r-- | src/vulkan/buffer_descriptor.h | 1 | ||||
-rw-r--r-- | src/vulkan/command_buffer.cc | 20 | ||||
-rw-r--r-- | src/vulkan/command_buffer.h | 1 | ||||
-rw-r--r-- | src/vulkan/command_pool.cc | 16 | ||||
-rw-r--r-- | src/vulkan/command_pool.h | 1 | ||||
-rw-r--r-- | src/vulkan/descriptor.h | 2 | ||||
-rw-r--r-- | src/vulkan/engine_vulkan.cc | 6 | ||||
-rw-r--r-- | src/vulkan/frame_buffer.cc | 20 | ||||
-rw-r--r-- | src/vulkan/frame_buffer.h | 1 | ||||
-rw-r--r-- | src/vulkan/graphics_pipeline.cc | 7 | ||||
-rw-r--r-- | src/vulkan/index_buffer.cc | 5 | ||||
-rw-r--r-- | src/vulkan/index_buffer.h | 3 | ||||
-rw-r--r-- | src/vulkan/pipeline.cc | 7 | ||||
-rw-r--r-- | src/vulkan/resource.h | 1 | ||||
-rw-r--r-- | src/vulkan/transfer_buffer.cc | 30 | ||||
-rw-r--r-- | src/vulkan/transfer_buffer.h | 2 | ||||
-rw-r--r-- | src/vulkan/transfer_image.cc | 48 | ||||
-rw-r--r-- | src/vulkan/transfer_image.h | 2 | ||||
-rw-r--r-- | src/vulkan/vertex_buffer.cc | 5 | ||||
-rw-r--r-- | src/vulkan/vertex_buffer.h | 2 |
21 files changed, 63 insertions, 123 deletions
diff --git a/src/vulkan/buffer_descriptor.cc b/src/vulkan/buffer_descriptor.cc index e03292f..d40625f 100644 --- a/src/vulkan/buffer_descriptor.cc +++ b/src/vulkan/buffer_descriptor.cc @@ -117,7 +117,6 @@ Result BufferDescriptor::MoveResourceToBufferOutput() { size_in_bytes); } - transfer_buffer_->Shutdown(); transfer_buffer_ = nullptr; return {}; } @@ -136,11 +135,6 @@ Result BufferDescriptor::UpdateDescriptorSetIfNeeded( descriptor_set, GetVkDescriptorType(), buffer_info); } -void BufferDescriptor::Shutdown() { - if (transfer_buffer_) - transfer_buffer_->Shutdown(); -} - Result BufferDescriptor::AddToBuffer(DataType type, uint32_t offset, uint32_t size_in_bytes, diff --git a/src/vulkan/buffer_descriptor.h b/src/vulkan/buffer_descriptor.h index f7bbfdc..3d2c098 100644 --- a/src/vulkan/buffer_descriptor.h +++ b/src/vulkan/buffer_descriptor.h @@ -51,7 +51,6 @@ class BufferDescriptor : public Descriptor { Result RecordCopyDataToHost(CommandBuffer* command) override; Result MoveResourceToBufferOutput() override; Result UpdateDescriptorSetIfNeeded(VkDescriptorSet descriptor_set) override; - void Shutdown() override; Result AddToBuffer(DataType type, uint32_t offset, diff --git a/src/vulkan/command_buffer.cc b/src/vulkan/command_buffer.cc index 2e00307..86dd5a6 100644 --- a/src/vulkan/command_buffer.cc +++ b/src/vulkan/command_buffer.cc @@ -23,7 +23,15 @@ namespace vulkan { CommandBuffer::CommandBuffer(Device* device, CommandPool* pool, VkQueue queue) : device_(device), pool_(pool), queue_(queue) {} -CommandBuffer::~CommandBuffer() = default; +CommandBuffer::~CommandBuffer() { + if (fence_ != VK_NULL_HANDLE) + device_->GetPtrs()->vkDestroyFence(device_->GetDevice(), fence_, nullptr); + + if (command_ != VK_NULL_HANDLE) { + device_->GetPtrs()->vkFreeCommandBuffers( + device_->GetDevice(), pool_->GetCommandPool(), 1, &command_); + } +} Result CommandBuffer::Initialize() { VkCommandBufferAllocateInfo command_info = VkCommandBufferAllocateInfo(); @@ -110,15 +118,5 @@ Result CommandBuffer::SubmitAndReset(uint32_t timeout_ms) { return {}; } -void CommandBuffer::Shutdown() { - if (fence_ != VK_NULL_HANDLE) - device_->GetPtrs()->vkDestroyFence(device_->GetDevice(), fence_, nullptr); - - if (command_ != VK_NULL_HANDLE) { - device_->GetPtrs()->vkFreeCommandBuffers( - device_->GetDevice(), pool_->GetCommandPool(), 1, &command_); - } -} - } // namespace vulkan } // namespace amber diff --git a/src/vulkan/command_buffer.h b/src/vulkan/command_buffer.h index cbfab45..b958db8 100644 --- a/src/vulkan/command_buffer.h +++ b/src/vulkan/command_buffer.h @@ -41,7 +41,6 @@ class CommandBuffer { Result Initialize(); VkCommandBuffer GetCommandBuffer() const { return command_; } - void Shutdown(); // Do nothing and return if it is already ready to record. If it is in // initial state, call command begin API and make it ready to record. diff --git a/src/vulkan/command_pool.cc b/src/vulkan/command_pool.cc index eaaff5c..224e9b3 100644 --- a/src/vulkan/command_pool.cc +++ b/src/vulkan/command_pool.cc @@ -21,7 +21,13 @@ namespace vulkan { CommandPool::CommandPool(Device* device) : device_(device) {} -CommandPool::~CommandPool() = default; +CommandPool::~CommandPool() { + if (pool_ == VK_NULL_HANDLE) + return; + + device_->GetPtrs()->vkDestroyCommandPool(device_->GetDevice(), pool_, + nullptr); +} Result CommandPool::Initialize(uint32_t queue_family_index) { VkCommandPoolCreateInfo pool_info = VkCommandPoolCreateInfo(); @@ -37,13 +43,5 @@ Result CommandPool::Initialize(uint32_t queue_family_index) { return {}; } -void CommandPool::Shutdown() { - if (pool_ == VK_NULL_HANDLE) - return; - - device_->GetPtrs()->vkDestroyCommandPool(device_->GetDevice(), pool_, - nullptr); -} - } // namespace vulkan } // namespace amber diff --git a/src/vulkan/command_pool.h b/src/vulkan/command_pool.h index af47d6b..f594a2c 100644 --- a/src/vulkan/command_pool.h +++ b/src/vulkan/command_pool.h @@ -30,7 +30,6 @@ class CommandPool { Result Initialize(uint32_t queue_family_index); VkCommandPool GetCommandPool() const { return pool_; } - void Shutdown(); private: Device* device_ = nullptr; diff --git a/src/vulkan/descriptor.h b/src/vulkan/descriptor.h index 9b5fdbc..d85bde0 100644 --- a/src/vulkan/descriptor.h +++ b/src/vulkan/descriptor.h @@ -88,8 +88,6 @@ class Descriptor { // the command buffer. After copying the contents, it destroys |buffer_|. virtual Result MoveResourceToBufferOutput() = 0; - virtual void Shutdown() = 0; - protected: Result UpdateDescriptorSetForBuffer( VkDescriptorSet descriptor_set, diff --git a/src/vulkan/engine_vulkan.cc b/src/vulkan/engine_vulkan.cc index bef04a2..01f040b 100644 --- a/src/vulkan/engine_vulkan.cc +++ b/src/vulkan/engine_vulkan.cc @@ -138,12 +138,9 @@ Result EngineVulkan::Shutdown() { } info.vk_pipeline->Shutdown(); - if (info.vertex_buffer) - info.vertex_buffer->Shutdown(); } - if (pool_) - pool_->Shutdown(); + pool_ = nullptr; return {}; } @@ -363,7 +360,6 @@ Result EngineVulkan::DoDrawRect(const DrawRectCommand* command) { if (!r.IsSuccess()) return r; - vertex_buffer->Shutdown(); return {}; } diff --git a/src/vulkan/frame_buffer.cc b/src/vulkan/frame_buffer.cc index 587a7d6..13bd831 100644 --- a/src/vulkan/frame_buffer.cc +++ b/src/vulkan/frame_buffer.cc @@ -37,7 +37,12 @@ FrameBuffer::FrameBuffer( width_(width), height_(height) {} -FrameBuffer::~FrameBuffer() = default; +FrameBuffer::~FrameBuffer() { + if (frame_ != VK_NULL_HANDLE) { + device_->GetPtrs()->vkDestroyFramebuffer(device_->GetDevice(), frame_, + nullptr); + } +} Result FrameBuffer::Initialize( VkRenderPass render_pass, @@ -170,19 +175,6 @@ Result FrameBuffer::ChangeFrameImageLayout(CommandBuffer* command, return {}; } -void FrameBuffer::Shutdown() { - if (frame_ != VK_NULL_HANDLE) { - device_->GetPtrs()->vkDestroyFramebuffer(device_->GetDevice(), frame_, - nullptr); - } - - for (auto& img : color_images_) - img->Shutdown(); - - if (depth_image_) - depth_image_->Shutdown(); -} - Result FrameBuffer::CopyColorImagesToHost(CommandBuffer* command) { for (auto& img : color_images_) { ChangeFrameImageLayout(command, FrameImageState::kProbe); diff --git a/src/vulkan/frame_buffer.h b/src/vulkan/frame_buffer.h index 3852586..d84cb47 100644 --- a/src/vulkan/frame_buffer.h +++ b/src/vulkan/frame_buffer.h @@ -45,7 +45,6 @@ class FrameBuffer { Result Initialize(VkRenderPass render_pass, VkFormat depth_format, const VkPhysicalDeviceMemoryProperties& properties); - void Shutdown(); Result ChangeFrameImageLayout(CommandBuffer* command, FrameImageState layout); diff --git a/src/vulkan/graphics_pipeline.cc b/src/vulkan/graphics_pipeline.cc index 1a36f86..8684f6c 100644 --- a/src/vulkan/graphics_pipeline.cc +++ b/src/vulkan/graphics_pipeline.cc @@ -930,18 +930,15 @@ Result GraphicsPipeline::Draw(const DrawArraysCommand* command, Result GraphicsPipeline::ProcessCommands() { DeactivateRenderPassIfNeeded(); - return Pipeline::ProcessCommands(); } void GraphicsPipeline::Shutdown() { DeactivateRenderPassIfNeeded(); - if (index_buffer_) - index_buffer_->Shutdown(); - + index_buffer_ = nullptr; Pipeline::Shutdown(); - frame_->Shutdown(); + frame_ = nullptr; if (render_pass_ != VK_NULL_HANDLE) { device_->GetPtrs()->vkDestroyRenderPass(device_->GetDevice(), render_pass_, diff --git a/src/vulkan/index_buffer.cc b/src/vulkan/index_buffer.cc index ad97304..5bcf2ad 100644 --- a/src/vulkan/index_buffer.cc +++ b/src/vulkan/index_buffer.cc @@ -29,11 +29,6 @@ IndexBuffer::IndexBuffer(Device* device) : device_(device) {} IndexBuffer::~IndexBuffer() = default; -void IndexBuffer::Shutdown() { - if (transfer_buffer_) - transfer_buffer_->Shutdown(); -} - Result IndexBuffer::SendIndexData( CommandBuffer* command, const VkPhysicalDeviceMemoryProperties& properties, diff --git a/src/vulkan/index_buffer.h b/src/vulkan/index_buffer.h index 41ad7fa..835c1c2 100644 --- a/src/vulkan/index_buffer.h +++ b/src/vulkan/index_buffer.h @@ -39,9 +39,6 @@ class IndexBuffer { explicit IndexBuffer(Device* device); ~IndexBuffer(); - // Destroy |buffer_| if it is not nullptr. - void Shutdown(); - // Assuming that |buffer_| is nullptr and |values| is not empty, // it creates |buffer_| whose size is |sizeof(uint32_t) * values.size()| // and coverts |values| as uint32 values and copies them to |buffer_|. diff --git a/src/vulkan/pipeline.cc b/src/vulkan/pipeline.cc index a75d8da..a5b715e 100644 --- a/src/vulkan/pipeline.cc +++ b/src/vulkan/pipeline.cc @@ -73,7 +73,7 @@ void Pipeline::Shutdown() { if (r.IsSuccess()) command_->SubmitAndReset(fence_timeout_ms_); - command_->Shutdown(); + command_ = nullptr; } for (auto& info : descriptor_set_info_) { @@ -89,11 +89,6 @@ void Pipeline::Shutdown() { device_->GetPtrs()->vkDestroyDescriptorPool(device_->GetDevice(), info.pool, nullptr); } - - for (auto& desc : info.descriptors_) { - if (desc) - desc->Shutdown(); - } } } diff --git a/src/vulkan/resource.h b/src/vulkan/resource.h index 6dd4e71..c2606ff 100644 --- a/src/vulkan/resource.h +++ b/src/vulkan/resource.h @@ -48,7 +48,6 @@ class Resource { virtual ~Resource(); virtual Result CopyToHost(CommandBuffer* command) = 0; - virtual void Shutdown() = 0; void* HostAccessibleMemoryPtr() const { return memory_ptr_; } diff --git a/src/vulkan/transfer_buffer.cc b/src/vulkan/transfer_buffer.cc index d5e813b..a0b25ab 100644 --- a/src/vulkan/transfer_buffer.cc +++ b/src/vulkan/transfer_buffer.cc @@ -45,7 +45,20 @@ TransferBuffer::TransferBuffer( const VkPhysicalDeviceMemoryProperties& properties) : Resource(device, size_in_bytes, properties) {} -TransferBuffer::~TransferBuffer() = default; +TransferBuffer::~TransferBuffer() { + if (view_ != VK_NULL_HANDLE) { + device_->GetPtrs()->vkDestroyBufferView(device_->GetDevice(), view_, + nullptr); + } + + if (memory_ != VK_NULL_HANDLE) { + UnMapMemory(memory_); + device_->GetPtrs()->vkFreeMemory(device_->GetDevice(), memory_, nullptr); + } + + if (buffer_ != VK_NULL_HANDLE) + device_->GetPtrs()->vkDestroyBuffer(device_->GetDevice(), buffer_, nullptr); +} Result TransferBuffer::Initialize(const VkBufferUsageFlags usage) { Result r = CreateVkBuffer(&buffer_, usage); @@ -100,21 +113,6 @@ Result TransferBuffer::CopyToHost(CommandBuffer* command) { return {}; } -void TransferBuffer::Shutdown() { - if (view_ != VK_NULL_HANDLE) { - device_->GetPtrs()->vkDestroyBufferView(device_->GetDevice(), view_, - nullptr); - } - - if (memory_ != VK_NULL_HANDLE) { - UnMapMemory(memory_); - device_->GetPtrs()->vkFreeMemory(device_->GetDevice(), memory_, nullptr); - } - - if (buffer_ != VK_NULL_HANDLE) - device_->GetPtrs()->vkDestroyBuffer(device_->GetDevice(), buffer_, nullptr); -} - void TransferBuffer::UpdateMemoryWithRawData( const std::vector<uint8_t>& raw_data) { size_t effective_size = diff --git a/src/vulkan/transfer_buffer.h b/src/vulkan/transfer_buffer.h index c18c84b..61ea89b 100644 --- a/src/vulkan/transfer_buffer.h +++ b/src/vulkan/transfer_buffer.h @@ -61,8 +61,6 @@ class TransferBuffer : public Resource { // make it available to host domain. Result CopyToHost(CommandBuffer* command) override; - void Shutdown() override; - private: VkBuffer buffer_ = VK_NULL_HANDLE; VkBufferView view_ = VK_NULL_HANDLE; diff --git a/src/vulkan/transfer_image.cc b/src/vulkan/transfer_image.cc index f40ab3f..ad33197 100644 --- a/src/vulkan/transfer_image.cc +++ b/src/vulkan/transfer_image.cc @@ -59,7 +59,29 @@ TransferImage::TransferImage(Device* device, image_info_.extent = {x, y, z}; } -TransferImage::~TransferImage() = default; +TransferImage::~TransferImage() { + if (view_ != VK_NULL_HANDLE) { + device_->GetPtrs()->vkDestroyImageView(device_->GetDevice(), view_, + nullptr); + } + + if (image_ != VK_NULL_HANDLE) + device_->GetPtrs()->vkDestroyImage(device_->GetDevice(), image_, nullptr); + + if (memory_ != VK_NULL_HANDLE) + device_->GetPtrs()->vkFreeMemory(device_->GetDevice(), memory_, nullptr); + + if (host_accessible_memory_ != VK_NULL_HANDLE) { + UnMapMemory(host_accessible_memory_); + device_->GetPtrs()->vkFreeMemory(device_->GetDevice(), + host_accessible_memory_, nullptr); + } + + if (host_accessible_buffer_ != VK_NULL_HANDLE) { + device_->GetPtrs()->vkDestroyBuffer(device_->GetDevice(), + host_accessible_buffer_, nullptr); + } +} Result TransferImage::Initialize(VkImageUsageFlags usage) { if (image_ != VK_NULL_HANDLE) @@ -135,30 +157,6 @@ Result TransferImage::CreateVkImageView() { return {}; } -void TransferImage::Shutdown() { - if (view_ != VK_NULL_HANDLE) { - device_->GetPtrs()->vkDestroyImageView(device_->GetDevice(), view_, - nullptr); - } - - if (image_ != VK_NULL_HANDLE) - device_->GetPtrs()->vkDestroyImage(device_->GetDevice(), image_, nullptr); - - if (memory_ != VK_NULL_HANDLE) - device_->GetPtrs()->vkFreeMemory(device_->GetDevice(), memory_, nullptr); - - if (host_accessible_memory_ != VK_NULL_HANDLE) { - UnMapMemory(host_accessible_memory_); - device_->GetPtrs()->vkFreeMemory(device_->GetDevice(), - host_accessible_memory_, nullptr); - } - - if (host_accessible_buffer_ != VK_NULL_HANDLE) { - device_->GetPtrs()->vkDestroyBuffer(device_->GetDevice(), - host_accessible_buffer_, nullptr); - } -} - Result TransferImage::CopyToHost(CommandBuffer* command) { VkBufferImageCopy copy_region = VkBufferImageCopy(); copy_region.bufferOffset = 0; diff --git a/src/vulkan/transfer_image.h b/src/vulkan/transfer_image.h index ea41732..879a3eb 100644 --- a/src/vulkan/transfer_image.h +++ b/src/vulkan/transfer_image.h @@ -53,8 +53,6 @@ class TransferImage : public Resource { // must be done later. Result CopyToHost(CommandBuffer* command) override; - void Shutdown() override; - private: Result CreateVkImageView(); Result AllocateAndBindMemoryToVkImage(VkImage image, diff --git a/src/vulkan/vertex_buffer.cc b/src/vulkan/vertex_buffer.cc index fdc31e6..7b05cf3 100644 --- a/src/vulkan/vertex_buffer.cc +++ b/src/vulkan/vertex_buffer.cc @@ -202,11 +202,6 @@ VertexBuffer::VertexBuffer(Device* device) : device_(device) {} VertexBuffer::~VertexBuffer() = default; -void VertexBuffer::Shutdown() { - if (transfer_buffer_) - transfer_buffer_->Shutdown(); -} - void VertexBuffer::SetData(uint8_t location, const Format& format, const std::vector<Value>& values) { diff --git a/src/vulkan/vertex_buffer.h b/src/vulkan/vertex_buffer.h index 268ed5a..f078c93 100644 --- a/src/vulkan/vertex_buffer.h +++ b/src/vulkan/vertex_buffer.h @@ -35,8 +35,6 @@ class VertexBuffer { explicit VertexBuffer(Device* device); ~VertexBuffer(); - void Shutdown(); - Result SendVertexData(CommandBuffer* command, const VkPhysicalDeviceMemoryProperties& properties); bool VertexDataSent() const { return !is_vertex_data_pending_; } |