diff options
author | Lynne <dev@lynne.ee> | 2024-11-28 00:36:42 +0900 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2024-11-28 01:29:21 +0900 |
commit | 187fd52864e6374156b6ded75c23dd6658e03ebf (patch) | |
tree | a0b446682fcbaa438021697516129d95b0d124fd | |
parent | 41f65b7326ea437d0b19744810903a5a588047fd (diff) | |
download | ffmpeg-187fd52864e6374156b6ded75c23dd6658e03ebf.tar.gz |
vulkan: fix use of atomics for the current context index
The code used to use atomic, but over time, this got broken.
This commit also remmoves the is-the-last-submission-ready
shortcut, which rarely did anything.
There's also value in relying on the fact that contexts
always carry their frames in a strictly incremental order
with no gaps.
-rw-r--r-- | libavutil/vulkan.c | 14 | ||||
-rw-r--r-- | libavutil/vulkan.h | 2 |
2 files changed, 4 insertions, 12 deletions
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index 904d3a9a55..dc30539115 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -317,6 +317,8 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, const VkQueryPoolVideoEncodeFeedbackCreateInfoKHR *ef = NULL; + atomic_init(&pool->idx, 0); + if (query_type == VK_QUERY_TYPE_VIDEO_ENCODE_FEEDBACK_KHR) { ef = ff_vk_find_struct(query_create_pnext, VK_STRUCTURE_TYPE_QUERY_POOL_VIDEO_ENCODE_FEEDBACK_CREATE_INFO_KHR); @@ -490,17 +492,7 @@ VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, FFVkExecContext *ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool) { - FFVulkanFunctions *vk = &s->vkfn; - FFVkExecContext *e = &pool->contexts[pool->idx]; - - /* Check if last submission has already finished. - * If so, don't waste resources and reuse the same buffer. */ - if (e->had_submission && - vk->GetFenceStatus(s->hwctx->act_dev, e->fence) == VK_SUCCESS) - return e; - - pool->idx = (pool->idx + 1) % pool->pool_size; - return &pool->contexts[pool->idx]; + return &pool->contexts[atomic_fetch_add(&pool->idx, 1) % pool->pool_size]; } void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e) diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index ec20d1ef56..ef39f76675 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -248,7 +248,7 @@ typedef struct FFVulkanShaderData { typedef struct FFVkExecPool { FFVkExecContext *contexts; - atomic_int_least64_t idx; + atomic_uint_least64_t idx; VkCommandPool cmd_buf_pool; VkCommandBuffer *cmd_bufs; |