Skip to content

Commit a598ed2

Browse files
trivedivivekSS-JIA
authored andcommitted
[ET-VK] 3/n Split dispatches between multiple command buffers. Track previous semaphore in context. (#12523)
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at bottom): * #12525 * __->__ #12523 * #12522 * #12519 This diff is the third part of a series of diffs aiming to split dispatches between multiple command buffers. In this diff, we are tracking the previous semaphore in the context. A new member variable `prev_semaphore_` was added to the `Context` class. This variable is used to store the semaphore of the previously submitted command buffer. Differential Revision: [D78360037](https://our.internmc.facebook.com/intern/diff/D78360037/) --------- Co-authored-by: Stephen Jia <[email protected]>
1 parent 97beaf0 commit a598ed2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

backends/vulkan/runtime/api/Context.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Context::Context(vkapi::Adapter* adapter, const ContextConfig& config)
3939
// Command buffer submission
4040
cmd_mutex_{},
4141
cmd_(VK_NULL_HANDLE, VK_NULL_HANDLE, 0u),
42+
prev_semaphore_(VK_NULL_HANDLE),
4243
submit_count_{0u},
4344
// Memory Management
4445
buffer_clearlist_mutex_{},
@@ -195,10 +196,21 @@ void Context::register_blit(
195196
}
196197

197198
void Context::submit_cmd_to_gpu(VkFence fence_handle, const bool final_use) {
199+
// Wait semaphore would be previous command buffer's signal semaphore
200+
VkSemaphore wait_semaphore = prev_semaphore_;
201+
// Signal semaphore for the the current command buffer
202+
VkSemaphore signal_semaphore = cmd_.get_signal_semaphore();
203+
// Next command buffer would wait on this command buffer's signal semaphore
204+
prev_semaphore_ = signal_semaphore;
205+
198206
if (cmd_) {
199207
cmd_.end();
200208
adapter_p_->submit_cmd(
201-
queue_, cmd_.get_submit_handle(final_use), fence_handle);
209+
queue_,
210+
cmd_.get_submit_handle(final_use),
211+
fence_handle,
212+
wait_semaphore,
213+
signal_semaphore);
202214

203215
submit_count_ = 0u;
204216
}
@@ -214,6 +226,8 @@ void Context::flush() {
214226
if (cmd_) {
215227
cmd_.invalidate();
216228
}
229+
// Reset previous command buffer semaphore
230+
prev_semaphore_ = VK_NULL_HANDLE;
217231

218232
std::lock_guard<std::mutex> bufferlist_lock(buffer_clearlist_mutex_);
219233
std::lock_guard<std::mutex> imagelist_lock(image_clearlist_mutex_);

backends/vulkan/runtime/api/Context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class Context final {
6868
// Command buffers submission
6969
std::mutex cmd_mutex_;
7070
vkapi::CommandBuffer cmd_;
71+
// Semaphore for the previously submitted command buffer, if any
72+
VkSemaphore prev_semaphore_;
7173
uint32_t submit_count_;
7274
// Memory Management
7375
std::mutex buffer_clearlist_mutex_;

0 commit comments

Comments
 (0)