Chromium Code Reviews| Index: gpu/vulkan/vulkan_command_buffer.cc |
| diff --git a/gpu/vulkan/vulkan_command_buffer.cc b/gpu/vulkan/vulkan_command_buffer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4865294e9c0585bd373ff6aa9efc629d0e40c9ee |
| --- /dev/null |
| +++ b/gpu/vulkan/vulkan_command_buffer.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "gpu/vulkan/vulkan_command_buffer.h" |
| + |
| +#include "gpu/vulkan/vulkan_implementation.h" |
| + |
| +namespace gfx { |
| + |
| +VulkanCommandBuffer::VulkanCommandBuffer(VkCommandPool command_pool, |
| + bool primary) |
| + : primary_(primary), command_pool_(command_pool) {} |
| + |
| +VulkanCommandBuffer::~VulkanCommandBuffer() { |
| + DCHECK_EQ(reinterpret_cast<VkCommandBuffer>(VK_NULL_HANDLE), command_buffer_); |
|
piman
2016/03/09 01:25:33
nit: static_cast
David Yen
2016/03/10 01:39:48
Done.
|
| + DCHECK(!recording_); |
| +} |
| + |
| +bool VulkanCommandBuffer::Initialize() { |
| + VkCommandBufferAllocateInfo command_buffer_info = {}; |
| + command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| + command_buffer_info.commandPool = command_pool_; |
| + command_buffer_info.level = primary_ ? VK_COMMAND_BUFFER_LEVEL_PRIMARY |
| + : VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
| + command_buffer_info.commandBufferCount = 1; |
| + |
| + VkResult result = vkAllocateCommandBuffers( |
| + GetVulkanDevice(), &command_buffer_info, &command_buffer_); |
| + if (VK_SUCCESS != result) { |
| + LOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result; |
|
piman
2016/03/09 01:25:33
nit: DLOG
David Yen
2016/03/10 01:39:48
Done.
|
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +void VulkanCommandBuffer::Destroy() { |
| + if (VK_NULL_HANDLE != command_buffer_) { |
| + vkFreeCommandBuffers(GetVulkanDevice(), command_pool_, 1, &command_buffer_); |
| + command_buffer_ = VK_NULL_HANDLE; |
| + } |
| +} |
| + |
| +bool VulkanCommandBuffer::Submit() { |
| + DCHECK(primary_); |
| + VkSubmitInfo submit_info = {}; |
| + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| + submit_info.commandBufferCount = 1; |
| + submit_info.pCommandBuffers = &command_buffer_; |
| + VkResult result = |
| + vkQueueSubmit(GetVulkanQueue(), 1, &submit_info, VK_NULL_HANDLE); |
| + PostExecution(); |
| + if (VK_SUCCESS != result) { |
| + LOG(ERROR) << "vkQueueSubmit() failed: " << result; |
|
piman
2016/03/09 01:25:33
nit: DLOG
David Yen
2016/03/10 01:39:48
Done.
|
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +void VulkanCommandBuffer::Enqueue(VkCommandBuffer primary_command_buffer) { |
| + DCHECK(!primary_); |
| + vkCmdExecuteCommands(primary_command_buffer, 1, &command_buffer_); |
| + PostExecution(); |
| +} |
| + |
| +void VulkanCommandBuffer::PostExecution() { |
| + if (record_type_ == RECORD_TYPE_SINGLE_USE) { |
| + // Clear upon next use. |
| + record_type_ = RECORD_TYPE_DIRTY; |
| + } else if (record_type_ == RECORD_TYPE_MULTI_USE) { |
| + // Can no longer record new items unless marked as clear. |
| + record_type_ = RECORD_TYPE_RECORDED; |
| + } |
| +} |
| + |
| +void VulkanCommandBuffer::ResetIfDirty() { |
| + DCHECK(!recording_); |
| + if (record_type_ == RECORD_TYPE_DIRTY) { |
| + vkResetCommandPool(GetVulkanDevice(), command_pool_, |
| + VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); |
| + record_type_ = RECORD_TYPE_EMPTY; |
| + } |
| +} |
| + |
| +CommandBufferRecorderBase::~CommandBufferRecorderBase() { |
| + vkEndCommandBuffer(handle_); |
| +}; |
| + |
| +} // namespace gfx |