| 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..07c5febec21c6e24b9fcb4b1368a4a2260b447d5
|
| --- /dev/null
|
| +++ b/gpu/vulkan/vulkan_command_buffer.cc
|
| @@ -0,0 +1,109 @@
|
| +// 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_command_pool.h"
|
| +#include "gpu/vulkan/vulkan_implementation.h"
|
| +
|
| +namespace gpu {
|
| +
|
| +VulkanCommandBuffer::VulkanCommandBuffer(VulkanCommandPool* command_pool,
|
| + bool primary)
|
| + : primary_(primary), command_pool_(command_pool) {
|
| + command_pool_->IncrementCommandBufferCount();
|
| +}
|
| +
|
| +VulkanCommandBuffer::~VulkanCommandBuffer() {
|
| + DCHECK_EQ(static_cast<VkCommandBuffer>(VK_NULL_HANDLE), command_buffer_);
|
| + DCHECK(!recording_);
|
| + command_pool_->DecrementCommandBufferCount();
|
| +}
|
| +
|
| +bool VulkanCommandBuffer::Initialize() {
|
| + VkCommandBufferAllocateInfo command_buffer_info = {};
|
| + command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
| + command_buffer_info.commandPool = command_pool_->handle();
|
| + 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) {
|
| + DLOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result;
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +void VulkanCommandBuffer::Destroy() {
|
| + if (VK_NULL_HANDLE != command_buffer_) {
|
| + vkFreeCommandBuffers(GetVulkanDevice(), command_pool_->handle(), 1,
|
| + &command_buffer_);
|
| + command_buffer_ = VK_NULL_HANDLE;
|
| + }
|
| +}
|
| +
|
| +bool VulkanCommandBuffer::Submit(VkQueue queue,
|
| + uint32_t num_wait_semaphores,
|
| + VkSemaphore* wait_semaphores,
|
| + uint32_t num_signal_semaphores,
|
| + VkSemaphore* signal_semaphores) {
|
| + DCHECK(primary_);
|
| + VkSubmitInfo submit_info = {};
|
| + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
| + submit_info.commandBufferCount = 1;
|
| + submit_info.pCommandBuffers = &command_buffer_;
|
| +
|
| + if (num_wait_semaphores) {
|
| + submit_info.waitSemaphoreCount = num_wait_semaphores;
|
| + submit_info.pWaitSemaphores = wait_semaphores;
|
| + }
|
| +
|
| + if (num_signal_semaphores) {
|
| + submit_info.signalSemaphoreCount = num_signal_semaphores;
|
| + submit_info.pSignalSemaphores = signal_semaphores;
|
| + }
|
| +
|
| + VkResult result = vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
|
| + PostExecution();
|
| + if (VK_SUCCESS != result) {
|
| + DLOG(ERROR) << "vkQueueSubmit() failed: " << result;
|
| + 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_->handle(),
|
| + VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
|
| + record_type_ = RECORD_TYPE_EMPTY;
|
| + }
|
| +}
|
| +
|
| +CommandBufferRecorderBase::~CommandBufferRecorderBase() {
|
| + vkEndCommandBuffer(handle_);
|
| +};
|
| +
|
| +} // namespace gpu
|
|
|