From 1876026f83bd1d270b014bab35139445245b5d1b Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 18 Nov 2024 06:15:39 +0100 Subject: [PATCH] vulkan: add ff_vk_exec_add_dep_sw_frame Some software frames may be mapped, and we'd like to have them as proper dependencies. --- libavutil/vulkan.c | 26 ++++++++++++++++++++++++++ libavutil/vulkan.h | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index d5299ffb06..a04dfbfadf 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -255,6 +255,7 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool) ff_vk_exec_discard_deps(s, e); av_free(e->frame_deps); + av_free(e->sw_frame_deps); av_free(e->buf_deps); av_free(e->queue_family_dst); av_free(e->layout_dst); @@ -551,6 +552,10 @@ void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e) av_buffer_unref(&e->buf_deps[j]); e->nb_buf_deps = 0; + for (int j = 0; j < e->nb_sw_frame_deps; j++) + av_frame_free(&e->sw_frame_deps[j]); + e->nb_sw_frame_deps = 0; + for (int j = 0; j < e->nb_frame_deps; j++) { AVFrame *f = e->frame_deps[j]; if (e->frame_locked[j]) { @@ -595,6 +600,27 @@ int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, return 0; } +int ff_vk_exec_add_dep_sw_frame(FFVulkanContext *s, FFVkExecContext *e, + AVFrame *f) +{ + AVFrame **dst = av_fast_realloc(e->sw_frame_deps, &e->sw_frame_deps_alloc_size, + (e->nb_sw_frame_deps + 1) * sizeof(*dst)); + if (!dst) { + ff_vk_exec_discard_deps(s, e); + return AVERROR(ENOMEM); + } + + e->sw_frame_deps = dst; + + e->sw_frame_deps[e->nb_sw_frame_deps] = av_frame_clone(f); + if (!e->sw_frame_deps[e->nb_sw_frame_deps]) { + ff_vk_exec_discard_deps(s, e); + return AVERROR(ENOMEM); + } + + return 0; +} + #define ARR_REALLOC(str, arr, alloc_s, cnt) \ do { \ arr = av_fast_realloc(str->arr, alloc_s, (cnt + 1)*sizeof(*arr)); \ diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h index 4394894baa..9b46a279ca 100644 --- a/libavutil/vulkan.h +++ b/libavutil/vulkan.h @@ -134,6 +134,11 @@ typedef struct FFVkExecContext { unsigned int frame_deps_alloc_size; int nb_frame_deps; + /* Software frame dependencies */ + AVFrame **sw_frame_deps; + unsigned int sw_frame_deps_alloc_size; + int nb_sw_frame_deps; + VkSemaphoreSubmitInfo *sem_wait; unsigned int sem_wait_alloc; int sem_wait_cnt; @@ -441,6 +446,8 @@ int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e, int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage); +int ff_vk_exec_add_dep_sw_frame(FFVulkanContext *s, FFVkExecContext *e, + AVFrame *f); void ff_vk_exec_update_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar); int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e,