From e0c9c015062318b18685c34ec1e345965884eb68 Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Thu, 29 Jan 2026 22:34:40 -0500 Subject: [PATCH] Add convenience methods for using vk_semaphore --- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 5552f9d6a1..9d9398ec18 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -2410,6 +2410,24 @@ static vk_semaphore ggml_vk_create_timeline_semaphore(ggml_backend_vk_context * return ctx->gc.tl_semaphores[ctx->semaphore_idx++]; } +// Record that the given semaphore should be waited on in the next submission of the given context. +// For timeline semaphores, set the value of the vk_semaphore before calling this method to define which value to await. +static void ggml_vk_semaphore_await(vk_context& subctx, const vk_semaphore& semaphore) { + VK_LOG_DEBUG("ggml_vk_semaphore_await(" << subctx << ", " << semaphore << ")"); + GGML_ASSERT(!subctx->seqs.empty() && !subctx->seqs.back().empty() && "ggml_vk_semaphore_await called on context without active submission - call ggml_vk_ctx_begin first"); + + subctx->seqs.back().back().wait_semaphores.push_back(semaphore); +} + +// Record that the given semaphore should be signaled at the end of the execution of the given context. +// For timeline semaphores, set the value of the vk_semaphore before calling this method to define which value to set. +static void ggml_vk_semaphore_signal(vk_context& subctx, const vk_semaphore& semaphore) { + VK_LOG_DEBUG("ggml_vk_semaphore_signal(" << subctx << ", " << semaphore << ")"); + GGML_ASSERT(!subctx->seqs.empty() && !subctx->seqs.back().empty() && "ggml_vk_semaphore_signal called on context without active submission - call ggml_vk_ctx_begin first"); + + subctx->seqs.back().back().signal_semaphores.push_back(semaphore); +} + static vk::Event ggml_vk_create_event(ggml_backend_vk_context * ctx) { if (ctx->event_idx >= ctx->gc.events.size()) { ctx->gc.events.push_back(ctx->device->device.createEvent({}));