Skip to content

Commit

Permalink
vk: Refactor command buffers to include protected buffers (#8246)
Browse files Browse the repository at this point in the history
By providing a queue and the family index, we can now create
protected comand buffers that will be submitted to a protected
queue.  The main abstraction is in VulkanCommands.h where we
introduced a CommandBufferPool.

Also did refactor on the "mStorage", fences, and semaphores of
the original VulkanCommands so that each buffer is associated
with one fence and one semaphore.
  • Loading branch information
phoenixxxx authored Nov 6, 2024
1 parent b8551e5 commit 46dc9e7
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 357 deletions.
41 changes: 9 additions & 32 deletions filament/backend/src/vulkan/VulkanAsyncHandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,20 @@ namespace filament::backend {

// Wrapper to enable use of shared_ptr for implementing shared ownership of low-level Vulkan fences.
struct VulkanCmdFence {
struct SetValueScope {
public:
~SetValueScope() {
mHolder->mutex.unlock();
mHolder->condition.notify_all();
}

private:
SetValueScope(VulkanCmdFence* fenceHolder, VkResult result) :
mHolder(fenceHolder) {
mHolder->mutex.lock();
mHolder->status.store(result);
}
VulkanCmdFence* mHolder;
friend struct VulkanCmdFence;
};

VulkanCmdFence(VkFence ifence);
~VulkanCmdFence() = default;

SetValueScope setValue(VkResult value) {
return {this, value};
VulkanCmdFence(VkResult initialStatus) {
// Internally we use the VK_INCOMPLETE status to mean "not yet submitted". When this fence
// gets submitted, its status changes to VK_NOT_READY. Finally, when the GPU actually
// finishes executing the command buffer, the status changes to VK_SUCCESS.
status.store(initialStatus);
}

VkFence& getFence() {
return fence;
}
~VulkanCmdFence() = default;

VkResult getStatus() {
std::unique_lock<utils::Mutex> lock(mutex);
return status.load(std::memory_order_acquire);
}
void setStatus(VkResult value) { status.store(value); }

VkResult getStatus() { return status.load(std::memory_order_acquire); }

private:
VkFence fence;
utils::Condition condition;
utils::Mutex mutex;
std::atomic<VkResult> status;
};

Expand Down
Loading

0 comments on commit 46dc9e7

Please sign in to comment.