dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gpu/vulkan/vulkan_command_pool.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "gpu/vulkan/vulkan_command_buffer.h" |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 9 | #include "gpu/vulkan/vulkan_device_queue.h" |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 10 | #include "gpu/vulkan/vulkan_implementation.h" |
| 11 | |
| 12 | namespace gpu { |
| 13 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 14 | VulkanCommandPool::VulkanCommandPool(VulkanDeviceQueue* device_queue) |
| 15 | : device_queue_(device_queue) {} |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 16 | |
| 17 | VulkanCommandPool::~VulkanCommandPool() { |
| 18 | DCHECK_EQ(0u, command_buffer_count_); |
| 19 | DCHECK_EQ(static_cast<VkCommandPool>(VK_NULL_HANDLE), handle_); |
| 20 | } |
| 21 | |
| 22 | bool VulkanCommandPool::Initialize() { |
| 23 | VkCommandPoolCreateInfo command_pool_create_info = {}; |
| 24 | command_pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 25 | command_pool_create_info.flags = |
| 26 | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 27 | command_pool_create_info.queueFamilyIndex = |
| 28 | device_queue_->GetVulkanQueueIndex(); |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 29 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 30 | VkResult result = |
| 31 | vkCreateCommandPool(device_queue_->GetVulkanDevice(), |
| 32 | &command_pool_create_info, nullptr, &handle_); |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 33 | if (VK_SUCCESS != result) { |
| 34 | DLOG(ERROR) << "vkCreateCommandPool() failed: " << result; |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | void VulkanCommandPool::Destroy() { |
| 42 | DCHECK_EQ(0u, command_buffer_count_); |
| 43 | if (VK_NULL_HANDLE != handle_) { |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 44 | vkDestroyCommandPool(device_queue_->GetVulkanDevice(), handle_, nullptr); |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 45 | handle_ = VK_NULL_HANDLE; |
| 46 | } |
| 47 | } |
| 48 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 49 | std::unique_ptr<VulkanCommandBuffer> |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 50 | VulkanCommandPool::CreatePrimaryCommandBuffer() { |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 51 | std::unique_ptr<VulkanCommandBuffer> command_buffer( |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 52 | new VulkanCommandBuffer(device_queue_, this, true)); |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 53 | if (!command_buffer->Initialize()) |
| 54 | return nullptr; |
| 55 | |
| 56 | return command_buffer; |
| 57 | } |
| 58 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 59 | std::unique_ptr<VulkanCommandBuffer> |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 60 | VulkanCommandPool::CreateSecondaryCommandBuffer() { |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 61 | std::unique_ptr<VulkanCommandBuffer> command_buffer( |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 62 | new VulkanCommandBuffer(device_queue_, this, false)); |
dyen | 4ec04ecc | 2016-03-30 22:45:46 | [diff] [blame] | 63 | if (!command_buffer->Initialize()) |
| 64 | return nullptr; |
| 65 | |
| 66 | return command_buffer; |
| 67 | } |
| 68 | |
| 69 | void VulkanCommandPool::IncrementCommandBufferCount() { |
| 70 | command_buffer_count_++; |
| 71 | } |
| 72 | |
| 73 | void VulkanCommandPool::DecrementCommandBufferCount() { |
| 74 | DCHECK_LT(0u, command_buffer_count_); |
| 75 | command_buffer_count_--; |
| 76 | } |
| 77 | |
| 78 | } // namespace gpu |