[FFmpeg-cvslog] vulkan: fix use of atomics for the current context index
Lynne
git at videolan.org
Wed Nov 27 18:32:50 EET 2024
ffmpeg | branch: master | Lynne <dev at lynne.ee> | Thu Nov 28 00:36:42 2024 +0900| [187fd52864e6374156b6ded75c23dd6658e03ebf] | committer: Lynne
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.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=187fd52864e6374156b6ded75c23dd6658e03ebf
---
libavutil/vulkan.c | 14 +++-----------
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;
More information about the ffmpeg-cvslog
mailing list