vulkan: check if current buffer has finished execution before picking another

This saves resources, as dependencies are freed/reclaimed with a lower latency,
and provies a speedup.
pull/153/merge
Lynne 4 months ago
parent 877c5a9692
commit 37d5cb84e8
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
  1. 4
      libavcodec/vulkan_decode.c
  2. 2
      libavcodec/vulkan_encode.c
  3. 2
      libavfilter/vf_nlmeans_vulkan.c
  4. 6
      libavfilter/vulkan_filter.c
  5. 6
      libavutil/hwcontext_vulkan.c
  6. 15
      libavutil/vulkan.c
  7. 2
      libavutil/vulkan.h
  8. 1
      libavutil/vulkan_functions.h

@ -293,7 +293,7 @@ void ff_vk_decode_flush(AVCodecContext *avctx)
};
VkCommandBuffer cmd_buf;
FFVkExecContext *exec = ff_vk_exec_get(&dec->exec_pool);
FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &dec->exec_pool);
int had_submission = exec->had_submission;
ff_vk_exec_start(&ctx->s, exec);
cmd_buf = exec->buf;
@ -345,7 +345,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx,
size_t data_size = FFALIGN(vp->slices_size,
ctx->caps.minBitstreamBufferSizeAlignment);
FFVkExecContext *exec = ff_vk_exec_get(&dec->exec_pool);
FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &dec->exec_pool);
/* The current decoding reference has to be bound as an inactive reference */
VkVideoReferenceSlotInfoKHR *cur_vk_ref;

@ -339,7 +339,7 @@ static int vulkan_encode_issue(AVCodecContext *avctx,
size_align);
/* Start command buffer recording */
exec = vp->exec = ff_vk_exec_get(&ctx->enc_pool);
exec = vp->exec = ff_vk_exec_get(&ctx->s, &ctx->enc_pool);
ff_vk_exec_start(&ctx->s, exec);
cmd_buf = exec->buf;

@ -836,7 +836,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
}
/* Execution context */
exec = ff_vk_exec_get(&s->e);
exec = ff_vk_exec_get(&s->vkctx, &s->e);
ff_vk_exec_start(vkctx, exec);
/* Dependencies */

@ -249,7 +249,7 @@ int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e,
int nb_img_bar = 0;
/* Update descriptors and init the exec context */
FFVkExecContext *exec = ff_vk_exec_get(e);
FFVkExecContext *exec = ff_vk_exec_get(vkctx, e);
ff_vk_exec_start(vkctx, exec);
RET(ff_vk_exec_add_dep_frame(vkctx, exec, out_f,
@ -321,7 +321,7 @@ int ff_vk_filter_process_2pass(FFVulkanContext *vkctx, FFVkExecPool *e,
int nb_img_bar = 0;
/* Update descriptors and init the exec context */
FFVkExecContext *exec = ff_vk_exec_get(e);
FFVkExecContext *exec = ff_vk_exec_get(vkctx, e);
ff_vk_exec_start(vkctx, exec);
RET(ff_vk_exec_add_dep_frame(vkctx, exec, in,
@ -409,7 +409,7 @@ int ff_vk_filter_process_Nin(FFVulkanContext *vkctx, FFVkExecPool *e,
int nb_img_bar = 0;
/* Update descriptors and init the exec context */
FFVkExecContext *exec = ff_vk_exec_get(e);
FFVkExecContext *exec = ff_vk_exec_get(vkctx, e);
ff_vk_exec_start(vkctx, exec);
/* Add deps and create temporary imageviews */

@ -2253,7 +2253,7 @@ static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
};
VkCommandBuffer cmd_buf;
FFVkExecContext *exec = ff_vk_exec_get(ectx);
FFVkExecContext *exec = ff_vk_exec_get(&p->vkctx, ectx);
cmd_buf = exec->buf;
ff_vk_exec_start(&p->vkctx, exec);
@ -3190,7 +3190,7 @@ static int vulkan_map_from_drm_frame_sync(AVHWFramesContext *hwfc, AVFrame *dst,
}
}
exec = ff_vk_exec_get(&fp->compute_exec);
exec = ff_vk_exec_get(&p->vkctx, &fp->compute_exec);
cmd_buf = exec->buf;
ff_vk_exec_start(&p->vkctx, exec);
@ -4098,7 +4098,7 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc,
}
}
exec = ff_vk_exec_get(&fp->upload_exec);
exec = ff_vk_exec_get(&p->vkctx, &fp->upload_exec);
cmd_buf = exec->buf;
ff_vk_exec_start(&p->vkctx, exec);

@ -482,11 +482,18 @@ VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e,
pool->qd_size, qf);
}
FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool)
FFVkExecContext *ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
{
uint32_t idx = pool->idx++;
idx %= pool->pool_size;
return &pool->contexts[idx];
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 (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];
}
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)

@ -387,7 +387,7 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool);
/**
* Retrieve an execution pool. Threadsafe.
*/
FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool);
FFVkExecContext *ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool);
/**
* Performs nb_queries queries and returns their results and statuses.

@ -110,6 +110,7 @@ typedef enum FFVulkanExtensions {
/* Fences */ \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateFence) \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, WaitForFences) \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetFenceStatus) \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, ResetFences) \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyFence) \
\

Loading…
Cancel
Save