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

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: added fence to command buffer Created 4 years, 8 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 #include "gpu/vulkan/vulkan_export.h"
13
14 namespace gpu {
15
16 class VulkanCommandPool;
17
18 class VULKAN_EXPORT VulkanCommandBuffer {
19 public:
20 VulkanCommandBuffer(VulkanCommandPool* command_pool, bool primary);
21 ~VulkanCommandBuffer();
22
23 bool Initialize();
24 void Destroy();
25
26 // Submit primary command buffer to the queue.
27 bool Submit(VkQueue queue,
28 uint32_t num_wait_semaphores,
29 VkSemaphore* wait_semaphores,
30 uint32_t num_signal_semaphores,
31 VkSemaphore* signal_semaphores);
32
33 // Enqueue secondary command buffer within a primary command buffer.
34 void Enqueue(VkCommandBuffer primary_command_buffer);
35
36 void Clear();
37
38 // This blocks until the commands are done being submitted. Note that this
39 // means empty command buffers will return immediately and recorded commands
40 // which have not been submitted will block indefinitely until the command
41 // buffer is submitted.
42 void Wait(uint64_t timeout);
43
44 // This simply tests asynchronously if the commands are submitted.
45 bool SubmissionFinished();
46
47 private:
48 friend class CommandBufferRecorderBase;
49
50 enum RecordType {
51 // Nothing has been recorded yet.
52 RECORD_TYPE_EMPTY,
53
54 // Recorded for single use, will be reset upon submission.
55 RECORD_TYPE_SINGLE_USE,
56
57 // Recording for multi use, once submitted it can't be modified until reset.
58 RECORD_TYPE_MULTI_USE,
59
60 // Recorded for multi-use, can no longer be modified unless reset.
61 RECORD_TYPE_RECORDED,
62
63 // Dirty, should be cleared before use. This assumes its externally
64 // synchronized and the command buffer is no longer in use.
65 RECORD_TYPE_DIRTY,
66 };
67
68 void PostExecution();
69 void ResetIfDirty();
70
71 const bool primary_;
72 bool recording_ = false;
73 RecordType record_type_ = RECORD_TYPE_EMPTY;
74 VulkanCommandPool* command_pool_;
75 VkCommandBuffer command_buffer_ = VK_NULL_HANDLE;
76 VkFence submission_fence_ = VK_NULL_HANDLE;
77
78 DISALLOW_COPY_AND_ASSIGN(VulkanCommandBuffer);
79 };
80
81 class VULKAN_EXPORT CommandBufferRecorderBase {
82 public:
83 VkCommandBuffer handle() const { return handle_; }
84
85 protected:
86 CommandBufferRecorderBase(VulkanCommandBuffer& command_buffer)
87 : handle_(command_buffer.command_buffer_) {
88 command_buffer.ResetIfDirty();
89 }
90
91 virtual ~CommandBufferRecorderBase();
92
93 void ValidateSingleUse(VulkanCommandBuffer& command_buffer) {
94 DCHECK((VulkanCommandBuffer::RECORD_TYPE_SINGLE_USE ==
95 command_buffer.record_type_) ||
96 (VulkanCommandBuffer::RECORD_TYPE_EMPTY ==
97 command_buffer.record_type_));
98 command_buffer.record_type_ = VulkanCommandBuffer::RECORD_TYPE_SINGLE_USE;
99 }
100
101 void ValidateMultiUse(VulkanCommandBuffer& command_buffer) {
102 DCHECK((VulkanCommandBuffer::RECORD_TYPE_MULTI_USE ==
103 command_buffer.record_type_) ||
104 (VulkanCommandBuffer::RECORD_TYPE_EMPTY ==
105 command_buffer.record_type_));
106 command_buffer.record_type_ = VulkanCommandBuffer::RECORD_TYPE_MULTI_USE;
107 }
108
109 VkCommandBuffer handle_;
110 };
111
112 class VULKAN_EXPORT ScopedMultiUseCommandBufferRecorder
113 : public CommandBufferRecorderBase {
114 public:
115 ScopedMultiUseCommandBufferRecorder(VulkanCommandBuffer& command_buffer);
116 ~ScopedMultiUseCommandBufferRecorder() override {}
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(ScopedMultiUseCommandBufferRecorder);
120 };
121
122 class VULKAN_EXPORT ScopedSingleUseCommandBufferRecorder
123 : public CommandBufferRecorderBase {
124 public:
125 ScopedSingleUseCommandBufferRecorder(VulkanCommandBuffer& command_buffer);
126 ~ScopedSingleUseCommandBufferRecorder() override {}
127
128 private:
129 DISALLOW_COPY_AND_ASSIGN(ScopedSingleUseCommandBufferRecorder);
130 };
131
132 } // namespace gpu
133
134 #endif // GPU_VULKAN_VULKAN_COMMAND_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698