Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: gpu/vulkan/vulkan_command_buffer.h

Issue 1776453003: Added initial implementation of Vulkan Render Passes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn_vulkan
Patch Set: Fix SwapBuffers() present layout, test in unittests instead of injections Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 gpu {
14
15 class VulkanCommandPool;
16
17 class VulkanCommandBuffer {
18 public:
19 VulkanCommandBuffer(VulkanCommandPool* command_pool, bool primary);
20 ~VulkanCommandBuffer();
21
22 bool Initialize();
23 void Destroy();
24
25 // Submit primary command buffer to the queue.
26 bool Submit(VkQueue queue,
27 uint32_t num_wait_semaphores,
28 VkSemaphore* wait_semaphores,
29 uint32_t num_signal_semaphores,
30 VkSemaphore* signal_semaphores);
31
32 // Enqueue secondary command buffer within a primary command buffer.
33 void Enqueue(VkCommandBuffer primary_command_buffer);
34
35 void Clear();
36
37 private:
38 friend class CommandBufferRecorderBase;
39
40 enum RecordType {
41 // Nothing has been recorded yet.
42 RECORD_TYPE_EMPTY,
43
44 // Recorded for single use, will be reset upon submission.
45 RECORD_TYPE_SINGLE_USE,
46
47 // Recording for multi use, once submitted it can't be modified until reset.
48 RECORD_TYPE_MULTI_USE,
49
50 // Recorded for multi-use, can no longer be modified unless reset.
51 RECORD_TYPE_RECORDED,
52
53 // Dirty, should be cleared before use. This assumes its externally
54 // synchronized and the command buffer is no longer in use.
55 RECORD_TYPE_DIRTY,
56 };
57
58 void PostExecution();
59 void ResetIfDirty();
60
61 const bool primary_;
62 bool recording_ = false;
63 RecordType record_type_ = RECORD_TYPE_EMPTY;
64 VulkanCommandPool* command_pool_;
65 VkCommandBuffer command_buffer_ = VK_NULL_HANDLE;
66
67 DISALLOW_COPY_AND_ASSIGN(VulkanCommandBuffer);
68 };
69
70 class CommandBufferRecorderBase {
71 public:
72 VkCommandBuffer handle() { return handle_; }
73
74 protected:
75 CommandBufferRecorderBase(VulkanCommandBuffer& command_buffer)
76 : handle_(command_buffer.command_buffer_) {
77 command_buffer.ResetIfDirty();
78 }
79
80 virtual ~CommandBufferRecorderBase();
81
82 void ValidateSingleUse(VulkanCommandBuffer& command_buffer) {
83 DCHECK((VulkanCommandBuffer::RECORD_TYPE_SINGLE_USE ==
84 command_buffer.record_type_) ||
85 (VulkanCommandBuffer::RECORD_TYPE_EMPTY ==
86 command_buffer.record_type_));
87 command_buffer.record_type_ = VulkanCommandBuffer::RECORD_TYPE_SINGLE_USE;
88 }
89
90 void ValidateMultiUse(VulkanCommandBuffer& command_buffer) {
91 DCHECK((VulkanCommandBuffer::RECORD_TYPE_MULTI_USE ==
92 command_buffer.record_type_) ||
93 (VulkanCommandBuffer::RECORD_TYPE_EMPTY ==
94 command_buffer.record_type_));
95 command_buffer.record_type_ = VulkanCommandBuffer::RECORD_TYPE_MULTI_USE;
96 }
97
98 VkCommandBuffer handle_;
99 };
100
101 class ScopedMultiUseCommandBufferRecorder : public CommandBufferRecorderBase {
102 public:
103 ScopedMultiUseCommandBufferRecorder(VulkanCommandBuffer& command_buffer)
104 : CommandBufferRecorderBase(command_buffer) {
105 ValidateMultiUse(command_buffer);
106 VkCommandBufferBeginInfo begin_info = {};
107 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
108 vkBeginCommandBuffer(handle_, &begin_info);
109 }
110
111 ~ScopedMultiUseCommandBufferRecorder() override {}
112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(ScopedMultiUseCommandBufferRecorder);
115 };
116
117 class ScopedSingleUseCommandBufferRecorder : public CommandBufferRecorderBase {
118 public:
119 ScopedSingleUseCommandBufferRecorder(VulkanCommandBuffer& command_buffer)
120 : CommandBufferRecorderBase(command_buffer) {
121 ValidateSingleUse(command_buffer);
122 VkCommandBufferBeginInfo begin_info = {};
123 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
124 begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
125 vkBeginCommandBuffer(handle_, &begin_info);
126 }
127
128 ~ScopedSingleUseCommandBufferRecorder() override {}
129
130 private:
131 DISALLOW_COPY_AND_ASSIGN(ScopedSingleUseCommandBufferRecorder);
132 };
133
134 } // namespace gpu
135
136 #endif // GPU_VULKAN_VULKAN_COMMAND_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698