[FFmpeg-cvslog] vulkan: synchronize access to execution pool fences
Lynne
git at videolan.org
Thu Jun 8 00:59:49 EEST 2023
ffmpeg | branch: master | Lynne <dev at lynne.ee> | Wed Jun 7 00:24:43 2023 +0200| [975cd48bb3a45aefe314be3b9f8f3b8f0e4f614c] | committer: Lynne
vulkan: synchronize access to execution pool fences
vkResetFences is specified as being user-synchronized
(yet vkWaitFences, is not).
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=975cd48bb3a45aefe314be3b9f8f3b8f0e4f614c
---
libavutil/vulkan.c | 16 +++++++++++++---
libavutil/vulkan.h | 2 ++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index bc4466e6c9..b1c585292e 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -241,6 +241,7 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX);
vk->DestroyFence(s->hwctx->act_dev, e->fence, s->hwctx->alloc);
}
+ pthread_mutex_destroy(&e->lock);
ff_vk_exec_discard_deps(s, e);
@@ -379,12 +380,17 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
/* Init contexts */
for (int i = 0; i < pool->pool_size; i++) {
FFVkExecContext *e = &pool->contexts[i];
-
- /* Fence */
VkFenceCreateInfo fence_create = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.flags = VK_FENCE_CREATE_SIGNALED_BIT,
};
+
+ /* Mutex */
+ err = pthread_mutex_init(&e->lock, NULL);
+ if (err != 0)
+ return AVERROR(err);
+
+ /* Fence */
ret = vk->CreateFence(s->hwctx->act_dev, &fence_create, s->hwctx->alloc,
&e->fence);
if (ret != VK_SUCCESS) {
@@ -488,9 +494,13 @@ int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
};
- /* Create the fence and don't wait for it initially */
+ /* Wait for the fence to be signalled */
vk->WaitForFences(s->hwctx->act_dev, 1, &e->fence, VK_TRUE, UINT64_MAX);
+
+ /* vkResetFences is defined as being host-synchronized */
+ pthread_mutex_lock(&e->lock);
vk->ResetFences(s->hwctx->act_dev, 1, &e->fence);
+ pthread_mutex_unlock(&e->lock);
/* Discard queue dependencies */
ff_vk_exec_discard_deps(s, e);
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 58da720a1c..bbbc9374ae 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -23,6 +23,7 @@
#include <stdatomic.h>
+#include "thread.h"
#include "pixdesc.h"
#include "bprint.h"
#include "hwcontext.h"
@@ -152,6 +153,7 @@ typedef struct FFVulkanPipeline {
typedef struct FFVkExecContext {
int idx;
const struct FFVkExecPool *parent;
+ pthread_mutex_t lock;
/* Queue for the execution context */
VkQueue queue;
More information about the ffmpeg-cvslog
mailing list