vk_scheduler: Add api for defering operations

This commit is contained in:
IndecisiveTurtle 2024-07-21 15:08:05 +03:00
parent 64459f1a76
commit d32e24cbbc
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{};