@@ -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 */
@@ -2254,7 +2254,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);
@@ -3191,7 +3191,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);
@@ -4099,7 +4099,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) \
\