vk_scheduler: Add api for defering operations (#311)

This commit is contained in:
TheTurtle 2024-07-21 15:42:32 +03:00 committed by GitHub
parent 64459f1a76
commit 403a5a57b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -100,6 +100,12 @@ void Scheduler::SubmitExecution(vk::Semaphore signal_semaphore, vk::Semaphore wa
master_semaphore.SubmitWork(current_cmdbuf, wait_semaphore, signal_semaphore, signal_value);
master_semaphore.Refresh();
AllocateWorkerCommandBuffers();
// Apply pending operations
while (IsFree(pending_ops.back().gpu_tick)) {
pending_ops.back().callback();
pending_ops.pop();
}
}
} // namespace Vulkan

View File

@ -71,6 +71,11 @@ public:
return &master_semaphore;
}
/// Defers an operation until the gpu has reached the current cpu tick.
void DeferOperation(auto&& func) {
pending_ops.emplace(func, CurrentTick());
}
std::mutex submit_mutex;
private:
@ -84,6 +89,11 @@ private:
CommandPool command_pool;
vk::CommandBuffer current_cmdbuf;
std::condition_variable_any event_cv;
struct PendingOp {
std::function<void()> callback;
u64 gpu_tick;
};
std::queue<PendingOp> pending_ops;
RenderState render_state;
bool is_rendering = false;
tracy::VkCtxScope* profiler_scope{};