Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_buffer.h" | |
| 6 | |
| 7 #include "gpu/vulkan/vulkan_command_pool.h" | |
| 8 #include "gpu/vulkan/vulkan_implementation.h" | |
| 9 | |
| 10 namespace gpu { | |
| 11 | |
| 12 VulkanCommandBuffer::VulkanCommandBuffer(VulkanCommandPool* command_pool, | |
| 13 bool primary) | |
| 14 : primary_(primary), command_pool_(command_pool) { | |
| 15 command_pool_->IncrementCommandBufferCount(); | |
| 16 } | |
| 17 | |
| 18 VulkanCommandBuffer::~VulkanCommandBuffer() { | |
| 19 DCHECK_EQ(static_cast<VkCommandBuffer>(VK_NULL_HANDLE), command_buffer_); | |
| 20 DCHECK(!recording_); | |
| 21 command_pool_->DecrementCommandBufferCount(); | |
| 22 } | |
| 23 | |
| 24 bool VulkanCommandBuffer::Initialize() { | |
| 25 VkCommandBufferAllocateInfo command_buffer_info = {}; | |
| 26 command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; | |
| 27 command_buffer_info.commandPool = command_pool_->handle(); | |
| 28 command_buffer_info.level = primary_ ? VK_COMMAND_BUFFER_LEVEL_PRIMARY | |
| 29 : VK_COMMAND_BUFFER_LEVEL_SECONDARY; | |
| 30 command_buffer_info.commandBufferCount = 1; | |
| 31 | |
| 32 VkResult result = vkAllocateCommandBuffers( | |
| 33 GetVulkanDevice(), &command_buffer_info, &command_buffer_); | |
| 34 if (VK_SUCCESS != result) { | |
| 35 DLOG(ERROR) << "vkAllocateCommandBuffers() failed: " << result; | |
| 36 return false; | |
| 37 } | |
| 38 return true; | |
| 39 } | |
| 40 | |
| 41 void VulkanCommandBuffer::Destroy() { | |
| 42 if (VK_NULL_HANDLE != command_buffer_) { | |
| 43 vkFreeCommandBuffers(GetVulkanDevice(), command_pool_->handle(), 1, | |
| 44 &command_buffer_); | |
| 45 command_buffer_ = VK_NULL_HANDLE; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 bool VulkanCommandBuffer::Submit(VkQueue queue, | |
| 50 uint32_t num_wait_semaphores, | |
| 51 VkSemaphore* wait_semaphores, | |
| 52 uint32_t num_signal_semaphores, | |
| 53 VkSemaphore* signal_semaphores) { | |
| 54 DCHECK(primary_); | |
| 55 VkSubmitInfo submit_info = {}; | |
| 56 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; | |
| 57 submit_info.commandBufferCount = 1; | |
| 58 submit_info.pCommandBuffers = &command_buffer_; | |
| 59 | |
| 60 if (num_wait_semaphores) { | |
|
piman
2016/03/11 03:07:52
nit: the if here and below are unnecessary, in fac
David Yen
2016/03/21 18:26:31
Good point. Done.
| |
| 61 submit_info.waitSemaphoreCount = num_wait_semaphores; | |
| 62 submit_info.pWaitSemaphores = wait_semaphores; | |
| 63 } | |
| 64 | |
| 65 if (num_signal_semaphores) { | |
| 66 submit_info.signalSemaphoreCount = num_signal_semaphores; | |
| 67 submit_info.pSignalSemaphores = signal_semaphores; | |
| 68 } | |
| 69 | |
| 70 VkResult result = vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); | |
| 71 PostExecution(); | |
| 72 if (VK_SUCCESS != result) { | |
| 73 DLOG(ERROR) << "vkQueueSubmit() failed: " << result; | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 void VulkanCommandBuffer::Enqueue(VkCommandBuffer primary_command_buffer) { | |
| 81 DCHECK(!primary_); | |
| 82 vkCmdExecuteCommands(primary_command_buffer, 1, &command_buffer_); | |
| 83 PostExecution(); | |
| 84 } | |
| 85 | |
| 86 void VulkanCommandBuffer::PostExecution() { | |
| 87 if (record_type_ == RECORD_TYPE_SINGLE_USE) { | |
| 88 // Clear upon next use. | |
| 89 record_type_ = RECORD_TYPE_DIRTY; | |
| 90 } else if (record_type_ == RECORD_TYPE_MULTI_USE) { | |
| 91 // Can no longer record new items unless marked as clear. | |
| 92 record_type_ = RECORD_TYPE_RECORDED; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void VulkanCommandBuffer::ResetIfDirty() { | |
| 97 DCHECK(!recording_); | |
| 98 if (record_type_ == RECORD_TYPE_DIRTY) { | |
| 99 vkResetCommandPool(GetVulkanDevice(), command_pool_->handle(), | |
| 100 VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); | |
| 101 record_type_ = RECORD_TYPE_EMPTY; | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 CommandBufferRecorderBase::~CommandBufferRecorderBase() { | |
| 106 vkEndCommandBuffer(handle_); | |
| 107 }; | |
| 108 | |
| 109 } // namespace gpu | |
| OLD | NEW |