Skip to content

Commit

Permalink
igl | vulkan | Implement VulkanImmediateCommands::nextSubmitHandle()
Browse files Browse the repository at this point in the history
Summary:
Implemented `VulkanImmediateCommands::nextSubmitHandle()`.

This way there's no need to store a pointer or reference to the current command buffer wrapper. This is a much cleaner approach.

Backported corporateshark@5ceaf6c.

Reviewed By: EricGriffith, pixelperfect3, mmaurer

Differential Revision: D62999820

fbshipit-source-id: 6205f6f1c1d72b73316af3e5176feafa54d1d195
  • Loading branch information
corporateshark authored and facebook-github-bot committed Sep 21, 2024
1 parent d38c867 commit 7849c4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/igl/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,8 +1677,7 @@ void VulkanContext::updateBindingsBuffers(VkCommandBuffer IGL_NONNULL cmdBuf,

void VulkanContext::deferredTask(std::packaged_task<void()>&& task, SubmitHandle handle) const {
if (handle.empty()) {
handle = immediate_->currentCmdBufWrapper_ ? immediate_->currentCmdBufWrapper_->handle_
: immediate_->getLastSubmitHandle();
handle = immediate_->getNextSubmitHandle();
}
deferredTasks_.emplace_back(std::move(task), handle);
deferredTasks_.back().frameId_ = this->getFrameNumber();
Expand Down
14 changes: 8 additions & 6 deletions src/igl/vulkan/VulkanImmediateCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ void VulkanImmediateCommands::purge() {

const VulkanImmediateCommands::CommandBufferWrapper& VulkanImmediateCommands::acquire() {
IGL_PROFILER_FUNCTION();
IGL_ASSERT_MSG(!currentCmdBufWrapper_,
IGL_ASSERT_MSG(nextSubmitHandle_.empty(),
"VulkanImmediateCommands::acquire() is not reentrant. You should submit() the "
"previous buffer before calling acquire() again.");

if (IGL_UNEXPECTED(currentCmdBufWrapper_)) {
if (IGL_UNEXPECTED(!nextSubmitHandle_.empty())) {
IGL_LOG_ERROR(
"VulkanImmediateCommands::acquire() is not reentrant. You should submit() the "
"previous buffer before calling acquire() again.");
Expand Down Expand Up @@ -121,7 +121,7 @@ const VulkanImmediateCommands::CommandBufferWrapper& VulkanImmediateCommands::ac
current->isEncoding_ = true;
VK_ASSERT(ivkBeginCommandBuffer(&vf_, current->cmdBuf_));

currentCmdBufWrapper_ = current;
nextSubmitHandle_ = current->handle_;
return *current;
}

Expand Down Expand Up @@ -212,8 +212,6 @@ bool VulkanImmediateCommands::isReady(const SubmitHandle handle) const {
VulkanImmediateCommands::SubmitHandle VulkanImmediateCommands::submit(
const CommandBufferWrapper& wrapper) {
IGL_PROFILER_FUNCTION_COLOR(IGL_PROFILER_COLOR_SUBMIT);
IGL_ASSERT(wrapper.cmdBuf_ == currentCmdBufWrapper_->cmdBuf_ &&
wrapper.handle_.handle() == currentCmdBufWrapper_->handle_.handle());
IGL_ASSERT(wrapper.isEncoding_);
VK_ASSERT(ivkEndCommandBuffer(&vf_, wrapper.cmdBuf_));

Expand Down Expand Up @@ -257,7 +255,7 @@ VulkanImmediateCommands::SubmitHandle VulkanImmediateCommands::submit(
submitCounter_++;
}

currentCmdBufWrapper_ = nullptr;
nextSubmitHandle_ = {};

return lastSubmitHandle_;
}
Expand All @@ -276,6 +274,10 @@ VulkanImmediateCommands::SubmitHandle VulkanImmediateCommands::getLastSubmitHand
return lastSubmitHandle_;
}

VulkanImmediateCommands::SubmitHandle VulkanImmediateCommands::getNextSubmitHandle() const {
return nextSubmitHandle_.empty() ? lastSubmitHandle_ : nextSubmitHandle_;
}

VkFence VulkanImmediateCommands::getVkFenceFromSubmitHandle(SubmitHandle handle) {
IGL_ASSERT(handle.bufferIndex_ < buffers_.size());

Expand Down
4 changes: 2 additions & 2 deletions src/igl/vulkan/VulkanImmediateCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class VulkanImmediateCommands final {

/// @brief Returns the last SubmitHandle, which was submitted when `submit()` was last called
[[nodiscard]] SubmitHandle getLastSubmitHandle() const;
[[nodiscard]] SubmitHandle getNextSubmitHandle() const;

/** @brief Checks whether a SubmitHandle is ready. A SubmitHandle is ready if it is recycled or
* empty. If it has not been recycled and is not empty, a SubmitHandle is ready if the fence
Expand All @@ -156,8 +157,6 @@ class VulkanImmediateCommands final {
/// Returns `VK_NULL_HANDLE` otherwise.
VkFence getVkFenceFromSubmitHandle(SubmitHandle handle);

VulkanImmediateCommands::CommandBufferWrapper* currentCmdBufWrapper_ = nullptr;

private:
/// @brief Resets all commands buffers and their associated fences that are valid, are not being
/// encoded, and have completed execution by the GPU (their fences have been signaled). Resets the
Expand All @@ -178,6 +177,7 @@ class VulkanImmediateCommands final {

/// @brief The last submitted handle. Updated on `submit()`
SubmitHandle lastSubmitHandle_ = SubmitHandle();
SubmitHandle nextSubmitHandle_ = SubmitHandle();

/// @brief The semaphore submitted with the last command buffer. Updated on `submit()`
VkSemaphore lastSubmitSemaphore_ = VK_NULL_HANDLE;
Expand Down

0 comments on commit 7849c4a

Please sign in to comment.