aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_scale_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_scale_vulkan.c
parent8c150d3d9794c29a54bbdf2f2a88066277c7197e (diff)
downloadffmpeg-d1133e8c44f457f0698c48f2efcedbd8626b3cee.tar.gz
lavu/vulkan: move common Vulkan code from libavfilter to libavutil
Diffstat (limited to 'libavfilter/vf_scale_vulkan.c')
-rw-r--r--libavfilter/vf_scale_vulkan.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/libavfilter/vf_scale_vulkan.c b/libavfilter/vf_scale_vulkan.c
index 3a2251f8df..c2f6fe85e2 100644
--- a/libavfilter/vf_scale_vulkan.c
+++ b/libavfilter/vf_scale_vulkan.c
@@ -111,6 +111,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
FFVkSampler *sampler;
VkFilter sampler_mode;
ScaleVulkanContext *s = ctx->priv;
+ FFVulkanContext *vkctx = &s->vkctx;
int crop_x = in->crop_left;
int crop_y = in->crop_top;
@@ -118,7 +119,7 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
int crop_h = in->height - (in->crop_top + in->crop_bottom);
int in_planes = av_pix_fmt_count_planes(s->vkctx.input_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);
switch (s->scaler) {
case F_NEAREST:
@@ -130,11 +131,11 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
};
/* Create a sampler */
- sampler = ff_vk_init_sampler(ctx, 0, sampler_mode);
+ sampler = ff_vk_init_sampler(vkctx, 0, sampler_mode);
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);
@@ -171,15 +172,15 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
.buf_content = "mat4 yuv_matrix;",
};
- FFSPIRVShader *shd = ff_vk_init_shader(ctx, s->pl, "scale_compute",
- VK_SHADER_STAGE_COMPUTE_BIT);
+ FFVkSPIRVShader *shd = ff_vk_init_shader(s->pl, "scale_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, 2, 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, 2, 0)); /* set 0 */
+ RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */
GLSLD( scale_bilinear );
@@ -229,11 +230,11 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
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));
if (s->vkctx.output_format != s->vkctx.input_format) {
const struct LumaCoefficients *lcoeffs;
@@ -249,14 +250,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
return AVERROR(EINVAL);
}
- 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;
@@ -270,18 +271,18 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
par->yuv_matrix[3][3] = 1.0;
- 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;
@@ -296,19 +297,20 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *in_f)
int err = 0;
VkCommandBuffer cmd_buf;
ScaleVulkanContext *s = avctx->priv;
- FFVulkanFunctions *vk = &s->vkctx.vkfn;
+ FFVulkanContext *vkctx = &s->vkctx;
+ FFVulkanFunctions *vk = &vkctx->vkfn;
AVVkFrame *in = (AVVkFrame *)in_f->data[0];
AVVkFrame *out = (AVVkFrame *)out_f->data[0];
VkImageMemoryBarrier barriers[AV_NUM_DATA_POINTERS*2];
int barrier_count = 0;
/* 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 < av_pix_fmt_count_planes(s->vkctx.input_format); i++) {
- RET(ff_vk_create_imageview(avctx, s->exec, &s->input_images[i].imageView,
- in->img[i],
+ RET(ff_vk_create_imageview(vkctx, s->exec,
+ &s->input_images[i].imageView, in->img[i],
av_vkfmt_from_pixfmt(s->vkctx.input_format)[i],
ff_comp_identity_map));
@@ -316,15 +318,15 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *in_f)
}
for (int i = 0; i < av_pix_fmt_count_planes(s->vkctx.output_format); i++) {
- 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));
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 < av_pix_fmt_count_planes(s->vkctx.input_format); i++) {
VkImageMemoryBarrier bar = {
@@ -372,16 +374,16 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *in_f)
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0,
0, NULL, 0, NULL, barrier_count, barriers);
- 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);
+ FFALIGN(vkctx->output_width, CGROUPS[0])/CGROUPS[0],
+ FFALIGN(vkctx->output_height, CGROUPS[1])/CGROUPS[1], 1);
- ff_vk_add_exec_dep(avctx, s->exec, in_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, in_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;
@@ -390,7 +392,7 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *in_f)
return err;
fail:
- ff_vk_discard_exec_deps(avctx, s->exec);
+ ff_vk_discard_exec_deps(s->exec);
return err;
}
@@ -436,11 +438,12 @@ static int scale_vulkan_config_output(AVFilterLink *outlink)
int err;
AVFilterContext *avctx = outlink->src;
ScaleVulkanContext *s = avctx->priv;
+ FFVulkanContext *vkctx = &s->vkctx;
AVFilterLink *inlink = outlink->src->inputs[0];
err = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
- &s->vkctx.output_width,
- &s->vkctx.output_height);
+ &vkctx->output_width,
+ &vkctx->output_height);
if (err < 0)
return err;
@@ -481,8 +484,8 @@ static void scale_vulkan_uninit(AVFilterContext *avctx)
{
ScaleVulkanContext *s = avctx->priv;
- ff_vk_filter_uninit(avctx);
- ff_vk_free_buf(avctx, &s->params_buf);
+ ff_vk_free_buf(&s->vkctx, &s->params_buf);
+ ff_vk_uninit(&s->vkctx);
s->initialized = 0;
}