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