summaryrefslogtreecommitdiff
path: root/libavfilter/vf_overlay_vulkan.c
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2021-11-19 07:46:15 +0100
committerLynne <dev@lynne.ee>2021-11-19 13:44:45 +0100
commitd1133e8c44f457f0698c48f2efcedbd8626b3cee (patch)
tree034ac8f51d6225eca4a9408c30be20335adced06 /libavfilter/vf_overlay_vulkan.c
parent8c150d3d9794c29a54bbdf2f2a88066277c7197e (diff)
lavu/vulkan: move common Vulkan code from libavfilter to libavutil
Diffstat (limited to 'libavfilter/vf_overlay_vulkan.c')
-rw-r--r--libavfilter/vf_overlay_vulkan.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/libavfilter/vf_overlay_vulkan.c b/libavfilter/vf_overlay_vulkan.c
index b902ad83f5..ab97cf2c17 100644
--- a/libavfilter/vf_overlay_vulkan.c
+++ b/libavfilter/vf_overlay_vulkan.c
@@ -82,15 +82,16 @@ static av_cold int init_filter(AVFilterContext *ctx)
int err;
FFVkSampler *sampler;
OverlayVulkanContext *s = ctx->priv;
+ FFVulkanContext *vkctx = &s->vkctx;
const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
- ff_vk_qf_init(ctx, &s->qf, VK_QUEUE_COMPUTE_BIT, 0);
+ ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT, 0);
- sampler = ff_vk_init_sampler(ctx, 1, VK_FILTER_NEAREST);
+ sampler = ff_vk_init_sampler(vkctx, 1, VK_FILTER_NEAREST);
if (!sampler)
return AVERROR_EXTERNAL;
- s->pl = ff_vk_create_pipeline(ctx, &s->qf);
+ s->pl = ff_vk_create_pipeline(vkctx, &s->qf);
if (!s->pl)
return AVERROR(ENOMEM);
@@ -138,15 +139,15 @@ static av_cold int init_filter(AVFilterContext *ctx)
.buf_content = "ivec2 o_offset[3], o_size[3];",
};
- FFSPIRVShader *shd = ff_vk_init_shader(ctx, s->pl, "overlay_compute",
- VK_SHADER_STAGE_COMPUTE_BIT);
+ FFVkSPIRVShader *shd = ff_vk_init_shader(s->pl, "overlay_compute",
+ VK_SHADER_STAGE_COMPUTE_BIT);
if (!shd)
return AVERROR(ENOMEM);
- ff_vk_set_compute_shader_sizes(ctx, shd, CGROUPS);
+ ff_vk_set_compute_shader_sizes(shd, CGROUPS);
- RET(ff_vk_add_descriptor_set(ctx, s->pl, shd, desc_i, 3, 0)); /* set 0 */
- RET(ff_vk_add_descriptor_set(ctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */
+ RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, desc_i, 3, 0)); /* set 0 */
+ RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */
GLSLD( overlay_noalpha );
GLSLD( overlay_alpha );
@@ -162,11 +163,11 @@ static av_cold int init_filter(AVFilterContext *ctx)
GLSLC(1, } );
GLSLC(0, } );
- RET(ff_vk_compile_shader(ctx, shd, "main"));
+ RET(ff_vk_compile_shader(vkctx, shd, "main"));
}
- RET(ff_vk_init_pipeline_layout(ctx, s->pl));
- RET(ff_vk_init_compute_pipeline(ctx, s->pl));
+ RET(ff_vk_init_pipeline_layout(vkctx, s->pl));
+ RET(ff_vk_init_compute_pipeline(vkctx, s->pl));
{ /* Create and update buffer */
const AVPixFmtDescriptor *desc;
@@ -179,14 +180,14 @@ static av_cold int init_filter(AVFilterContext *ctx)
int32_t o_size[2*3];
} *par;
- err = ff_vk_create_buf(ctx, &s->params_buf,
+ err = ff_vk_create_buf(vkctx, &s->params_buf,
sizeof(*par),
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
if (err)
return err;
- err = ff_vk_map_buffers(ctx, &s->params_buf, (uint8_t **)&par, 1, 0);
+ err = ff_vk_map_buffers(vkctx, &s->params_buf, (uint8_t **)&par, 1, 0);
if (err)
return err;
@@ -206,18 +207,18 @@ static av_cold int init_filter(AVFilterContext *ctx)
par->o_size[4] = par->o_size[0] >> desc->log2_chroma_w;
par->o_size[5] = par->o_size[1] >> desc->log2_chroma_h;
- err = ff_vk_unmap_buffers(ctx, &s->params_buf, 1, 1);
+ err = ff_vk_unmap_buffers(vkctx, &s->params_buf, 1, 1);
if (err)
return err;
s->params_desc.buffer = s->params_buf.buf;
s->params_desc.range = VK_WHOLE_SIZE;
- ff_vk_update_descriptor_set(ctx, s->pl, 1);
+ ff_vk_update_descriptor_set(vkctx, s->pl, 1);
}
/* Execution context */
- RET(ff_vk_create_exec_ctx(ctx, &s->exec, &s->qf));
+ RET(ff_vk_create_exec_ctx(vkctx, &s->exec, &s->qf));
s->initialized = 1;
@@ -233,7 +234,8 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f,
int err;
VkCommandBuffer cmd_buf;
OverlayVulkanContext *s = avctx->priv;
- FFVulkanFunctions *vk = &s->vkctx.vkfn;
+ FFVulkanContext *vkctx = &s->vkctx;
+ FFVulkanFunctions *vk = &vkctx->vkfn;
int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
AVVkFrame *out = (AVVkFrame *)out_f->data[0];
@@ -244,22 +246,22 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f,
AVHWFramesContext *overlay_fc = (AVHWFramesContext*)overlay_f->hw_frames_ctx->data;
/* Update descriptors and init the exec context */
- ff_vk_start_exec_recording(avctx, s->exec);
- cmd_buf = ff_vk_get_exec_buf(avctx, s->exec);
+ ff_vk_start_exec_recording(vkctx, s->exec);
+ cmd_buf = ff_vk_get_exec_buf(s->exec);
for (int i = 0; i < planes; i++) {
- RET(ff_vk_create_imageview(avctx, s->exec, &s->main_images[i].imageView,
- main->img[i],
+ RET(ff_vk_create_imageview(vkctx, s->exec,
+ &s->main_images[i].imageView, main->img[i],
av_vkfmt_from_pixfmt(main_fc->sw_format)[i],
ff_comp_identity_map));
- RET(ff_vk_create_imageview(avctx, s->exec, &s->overlay_images[i].imageView,
- overlay->img[i],
+ RET(ff_vk_create_imageview(vkctx, s->exec,
+ &s->overlay_images[i].imageView, overlay->img[i],
av_vkfmt_from_pixfmt(overlay_fc->sw_format)[i],
ff_comp_identity_map));
- RET(ff_vk_create_imageview(avctx, s->exec, &s->output_images[i].imageView,
- out->img[i],
+ RET(ff_vk_create_imageview(vkctx, s->exec,
+ &s->output_images[i].imageView, out->img[i],
av_vkfmt_from_pixfmt(s->vkctx.output_format)[i],
ff_comp_identity_map));
@@ -268,7 +270,7 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f,
s->output_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
}
- ff_vk_update_descriptor_set(avctx, s->pl, 0);
+ ff_vk_update_descriptor_set(vkctx, s->pl, 0);
for (int i = 0; i < planes; i++) {
VkImageMemoryBarrier bar[3] = {
@@ -327,17 +329,17 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f,
out->access[i] = bar[2].dstAccessMask;
}
- ff_vk_bind_pipeline_exec(avctx, s->exec, s->pl);
+ ff_vk_bind_pipeline_exec(vkctx, s->exec, s->pl);
vk->CmdDispatch(cmd_buf,
FFALIGN(s->vkctx.output_width, CGROUPS[0])/CGROUPS[0],
FFALIGN(s->vkctx.output_height, CGROUPS[1])/CGROUPS[1], 1);
- ff_vk_add_exec_dep(avctx, s->exec, main_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
- ff_vk_add_exec_dep(avctx, s->exec, overlay_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
- ff_vk_add_exec_dep(avctx, s->exec, out_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
+ ff_vk_add_exec_dep(vkctx, s->exec, main_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
+ ff_vk_add_exec_dep(vkctx, s->exec, overlay_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
+ ff_vk_add_exec_dep(vkctx, s->exec, out_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
- err = ff_vk_submit_exec_queue(avctx, s->exec);
+ err = ff_vk_submit_exec_queue(vkctx, s->exec);
if (err)
return err;
@@ -346,7 +348,7 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f,
return err;
fail:
- ff_vk_discard_exec_deps(avctx, s->exec);
+ ff_vk_discard_exec_deps(s->exec);
return err;
}
@@ -438,11 +440,10 @@ static void overlay_vulkan_uninit(AVFilterContext *avctx)
{
OverlayVulkanContext *s = avctx->priv;
- ff_vk_filter_uninit(avctx);
+ ff_vk_free_buf(&s->vkctx, &s->params_buf);
+ ff_vk_uninit(&s->vkctx);
ff_framesync_uninit(&s->fs);
- ff_vk_free_buf(avctx, &s->params_buf);
-
s->initialized = 0;
}