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 #ifndef GPU_VULKAN_VULKAN_COMMAND_BUFFER_H_ | |
| 6 #define GPU_VULKAN_VULKAN_COMMAND_BUFFER_H_ | |
| 7 | |
| 8 #include <vulkan/vulkan.h> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 | |
| 15 class VulkanCommandBuffer { | |
| 16 public: | |
| 17 VulkanCommandBuffer(VkCommandPool command_pool, bool primary); | |
| 18 ~VulkanCommandBuffer(); | |
| 19 | |
| 20 bool Initialize(); | |
| 21 void Destroy(); | |
| 22 | |
| 23 // Submit primary command buffer to the queue. | |
| 24 bool Submit(); | |
|
piman
2016/03/09 01:25:33
I would prefer being explicit here and passing the
David Yen
2016/03/10 01:39:48
Done.
| |
| 25 | |
| 26 // Enqueue secondary command buffer within a primary command buffer. | |
| 27 void Enqueue(VkCommandBuffer primary_command_buffer); | |
| 28 | |
| 29 void Clear(); | |
| 30 | |
| 31 private: | |
| 32 friend class CommandBufferRecorderBase; | |
| 33 | |
| 34 enum RecordType { | |
| 35 // Nothing has been recorded yet. | |
| 36 RECORD_TYPE_EMPTY, | |
| 37 | |
| 38 // Recorded for single use, will be reset upon submission. | |
| 39 RECORD_TYPE_SINGLE_USE, | |
| 40 | |
| 41 // Recording for multi use, once submitted it can't be modified until reset. | |
| 42 RECORD_TYPE_MULTI_USE, | |
| 43 | |
| 44 // Recorded for multi-use, can no longer be modified unless reset. | |
| 45 RECORD_TYPE_RECORDED, | |
| 46 | |
| 47 // Dirty, should be cleared before use. This assumes its externally | |
| 48 // synchronized and the command buffer is no longer in use. | |
| 49 RECORD_TYPE_DIRTY, | |
| 50 }; | |
| 51 | |
| 52 void PostExecution(); | |
| 53 void ResetIfDirty(); | |
| 54 | |
| 55 const bool primary_; | |
| 56 bool recording_ = false; | |
| 57 RecordType record_type_ = RECORD_TYPE_EMPTY; | |
| 58 VkCommandBuffer command_buffer_ = VK_NULL_HANDLE; | |
| 59 VkCommandPool command_pool_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(VulkanCommandBuffer); | |
| 62 }; | |
| 63 | |
| 64 class CommandBufferRecorderBase { | |
| 65 public: | |
| 66 VkCommandBuffer handle() { return handle_; } | |
| 67 | |
| 68 protected: | |
| 69 CommandBufferRecorderBase(VulkanCommandBuffer& command_buffer) | |
| 70 : handle_(command_buffer.command_buffer_) { | |
| 71 command_buffer.ResetIfDirty(); | |
| 72 } | |
| 73 | |
| 74 virtual ~CommandBufferRecorderBase(); | |
| 75 | |
| 76 void ValidateSingleUse(VulkanCommandBuffer& command_buffer) { | |
| 77 DCHECK((VulkanCommandBuffer::RECORD_TYPE_SINGLE_USE == | |
| 78 command_buffer.record_type_) || | |
| 79 (VulkanCommandBuffer::RECORD_TYPE_EMPTY == | |
| 80 command_buffer.record_type_)); | |
| 81 command_buffer.record_type_ = VulkanCommandBuffer::RECORD_TYPE_SINGLE_USE; | |
| 82 } | |
| 83 | |
| 84 void ValidateMultiUse(VulkanCommandBuffer& command_buffer) { | |
| 85 DCHECK((VulkanCommandBuffer::RECORD_TYPE_MULTI_USE == | |
| 86 command_buffer.record_type_) || | |
| 87 (VulkanCommandBuffer::RECORD_TYPE_EMPTY == | |
| 88 command_buffer.record_type_)); | |
| 89 command_buffer.record_type_ = VulkanCommandBuffer::RECORD_TYPE_MULTI_USE; | |
| 90 } | |
| 91 | |
| 92 VkCommandBuffer handle_; | |
| 93 }; | |
| 94 | |
| 95 class ScopedMultiUseCommandBufferRecorder : public CommandBufferRecorderBase { | |
| 96 public: | |
| 97 ScopedMultiUseCommandBufferRecorder(VulkanCommandBuffer& command_buffer) | |
| 98 : CommandBufferRecorderBase(command_buffer) { | |
| 99 ValidateMultiUse(command_buffer); | |
| 100 VkCommandBufferBeginInfo begin_info = {}; | |
| 101 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | |
| 102 vkBeginCommandBuffer(handle_, &begin_info); | |
| 103 } | |
| 104 | |
| 105 ~ScopedMultiUseCommandBufferRecorder() override {} | |
| 106 | |
| 107 private: | |
| 108 DISALLOW_COPY_AND_ASSIGN(ScopedMultiUseCommandBufferRecorder); | |
| 109 }; | |
| 110 | |
| 111 class ScopedSingleUseCommandBufferRecorder : public CommandBufferRecorderBase { | |
| 112 public: | |
| 113 ScopedSingleUseCommandBufferRecorder(VulkanCommandBuffer& command_buffer) | |
| 114 : CommandBufferRecorderBase(command_buffer) { | |
| 115 ValidateSingleUse(command_buffer); | |
| 116 VkCommandBufferBeginInfo begin_info = {}; | |
| 117 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | |
| 118 begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; | |
| 119 vkBeginCommandBuffer(handle_, &begin_info); | |
| 120 } | |
| 121 | |
| 122 ~ScopedSingleUseCommandBufferRecorder() override {} | |
| 123 | |
| 124 private: | |
| 125 DISALLOW_COPY_AND_ASSIGN(ScopedSingleUseCommandBufferRecorder); | |
| 126 }; | |
| 127 | |
| 128 } // namespace gfx | |
| 129 | |
| 130 #endif // GPU_VULKAN_VULKAN_COMMAND_BUFFER_H_ | |
| OLD | NEW |