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