* [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format
@ 2022-11-08 13:12 Niklas Haas
2022-11-08 13:12 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_libplacebo: support all supported pixfmts Niklas Haas
2022-11-15 13:09 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
0 siblings, 2 replies; 4+ messages in thread
From: Niklas Haas @ 2022-11-08 13:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
Instead of doing it ad-hoc in `filter_frame`. This is not a huge change
on its own, but paves the way for adding support for more formats in the
future, in particular formats other than AV_PIX_FMT_VULKAN.
---
libavfilter/vf_libplacebo.c | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index cfee1117e8..cb6b021816 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -56,7 +56,6 @@ static const struct pl_tone_map_function * const tonemapping_funcs[TONE_MAP_COUN
typedef struct LibplaceboContext {
/* lavfi vulkan*/
FFVulkanContext vkctx;
- int initialized;
/* libplacebo */
pl_log log;
@@ -237,10 +236,17 @@ static int init_vulkan(AVFilterContext *avctx)
{
int err = 0;
LibplaceboContext *s = avctx->priv;
- const AVVulkanDeviceContext *hwctx = s->vkctx.hwctx;
+ const AVVulkanDeviceContext *hwctx;
uint8_t *buf = NULL;
size_t buf_len;
+ if (!avctx->hw_device_ctx) {
+ av_log(s, AV_LOG_ERROR, "Missing vulkan hwdevice for vf_libplacebo.\n");
+ return AVERROR(EINVAL);
+ }
+
+ hwctx = ((AVHWDeviceContext*) avctx->hw_device_ctx->data)->hwctx;
+
/* Import libavfilter vulkan context into libplacebo */
s->vulkan = pl_vulkan_import(s->log, pl_vulkan_import_params(
.instance = hwctx->inst,
@@ -289,7 +295,6 @@ static int init_vulkan(AVFilterContext *avctx)
fail:
if (buf)
av_file_unmap(buf, buf_len);
- s->initialized = 1;
return err;
}
@@ -303,7 +308,6 @@ static void libplacebo_uninit(AVFilterContext *avctx)
pl_vulkan_destroy(&s->vulkan);
pl_log_destroy(&s->log);
ff_vk_uninit(&s->vkctx);
- s->initialized = 0;
s->gpu = NULL;
}
@@ -452,8 +456,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
}
pl_log_level_update(s->log, get_log_level());
- if (!s->initialized)
- RET(init_vulkan(ctx));
RET(av_frame_copy_props(out, in));
out->width = outlink->w;
@@ -505,6 +507,25 @@ fail:
return err;
}
+static int libplacebo_query_format(AVFilterContext *ctx)
+{
+ int err = 0;
+ static const enum AVPixelFormat pix_fmts[] = {
+ AV_PIX_FMT_VULKAN, AV_PIX_FMT_NONE,
+ };
+
+ RET(init_vulkan(ctx));
+
+ RET(ff_formats_ref(ff_make_format_list(pix_fmts),
+ &ctx->inputs[0]->outcfg.formats));
+ RET(ff_formats_ref(ff_make_format_list(pix_fmts),
+ &ctx->outputs[0]->incfg.formats));
+ return 0;
+
+fail:
+ return err;
+}
+
static int libplacebo_config_output(AVFilterLink *outlink)
{
int err;
@@ -755,7 +776,7 @@ const AVFilter ff_vf_libplacebo = {
.process_command = &ff_filter_process_command,
FILTER_INPUTS(libplacebo_inputs),
FILTER_OUTPUTS(libplacebo_outputs),
- FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN),
+ FILTER_QUERY_FUNC(libplacebo_query_format),
.priv_class = &libplacebo_class,
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
};
--
2.38.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] avfilter/vf_libplacebo: support all supported pixfmts
2022-11-08 13:12 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
@ 2022-11-08 13:12 ` Niklas Haas
2022-11-15 13:09 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
1 sibling, 0 replies; 4+ messages in thread
From: Niklas Haas @ 2022-11-08 13:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
This is done only to the inputs, not the outputs, because we always
output vulkan hwframes.
Doing so also requires keeping track of backing textures for non-hwdec
formats, but is otherwise a mostly straightforward change to the format
query function. Special care needs to be taken to avoid crashing on
older libplacebo due to AV_PIX_FMT_RGBF32LE et al.
---
libavfilter/vf_libplacebo.c | 41 ++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index cb6b021816..fa9a7675d1 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -62,6 +62,7 @@ typedef struct LibplaceboContext {
pl_vulkan vulkan;
pl_gpu gpu;
pl_renderer renderer;
+ pl_tex tex[4];
/* settings */
char *out_format_string;
@@ -302,6 +303,8 @@ static void libplacebo_uninit(AVFilterContext *avctx)
{
LibplaceboContext *s = avctx->priv;
+ for (int i = 0; i < FF_ARRAY_ELEMS(s->tex); i++)
+ pl_tex_destroy(s->gpu, &s->tex[i]);
for (int i = 0; i < s->num_hooks; i++)
pl_mpv_user_shader_destroy(&s->hooks[i]);
pl_renderer_destroy(&s->renderer);
@@ -321,6 +324,7 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out, AVFrame *in)
struct pl_frame image, target;
ok = pl_map_avframe_ex(s->gpu, &image, pl_avframe_params(
.frame = in,
+ .tex = s->tex,
.map_dovi = s->apply_dovi,
));
@@ -510,22 +514,49 @@ fail:
static int libplacebo_query_format(AVFilterContext *ctx)
{
int err = 0;
- static const enum AVPixelFormat pix_fmts[] = {
+ LibplaceboContext *s = ctx->priv;
+ const AVPixFmtDescriptor *desc = NULL;
+ AVFilterFormats *in_fmts = NULL;
+ static const enum AVPixelFormat out_fmts[] = {
AV_PIX_FMT_VULKAN, AV_PIX_FMT_NONE,
};
RET(init_vulkan(ctx));
- RET(ff_formats_ref(ff_make_format_list(pix_fmts),
- &ctx->inputs[0]->outcfg.formats));
- RET(ff_formats_ref(ff_make_format_list(pix_fmts),
+ while ((desc = av_pix_fmt_desc_next(desc))) {
+
+#if PL_API_VER < 232
+ // Older libplacebo can't handle >64-bit pixel formats, so safe-guard
+ // this to prevent triggering an assertion
+ if (av_get_bits_per_pixel(desc) > 64)
+ continue;
+#endif
+
+ enum AVPixelFormat pixfmt = av_pix_fmt_desc_get_id(desc);
+ if (pl_test_pixfmt(s->gpu, pixfmt)) {
+ if ((err = ff_add_format(&in_fmts, pixfmt)) < 0)
+ return err;
+ }
+ }
+
+ RET(ff_formats_ref(in_fmts, &ctx->inputs[0]->outcfg.formats));
+ RET(ff_formats_ref(ff_make_format_list(out_fmts),
&ctx->outputs[0]->incfg.formats));
+
return 0;
fail:
return err;
}
+static int libplacebo_config_input(AVFilterLink *inlink)
+{
+ if (inlink->format == AV_PIX_FMT_VULKAN)
+ return ff_vk_filter_config_input(inlink);
+
+ return 0;
+}
+
static int libplacebo_config_output(AVFilterLink *outlink)
{
int err;
@@ -755,7 +786,7 @@ static const AVFilterPad libplacebo_inputs[] = {
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.filter_frame = &filter_frame,
- .config_props = &ff_vk_filter_config_input,
+ .config_props = &libplacebo_config_input,
},
};
--
2.38.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format
2022-11-08 13:12 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
2022-11-08 13:12 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_libplacebo: support all supported pixfmts Niklas Haas
@ 2022-11-15 13:09 ` Niklas Haas
2022-11-15 15:50 ` Niklas Haas
1 sibling, 1 reply; 4+ messages in thread
From: Niklas Haas @ 2022-11-15 13:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
Merging in 48 hours if no replies.
On Tue, 08 Nov 2022 14:12:29 +0100 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> From: Niklas Haas <git@haasn.dev>
>
> Instead of doing it ad-hoc in `filter_frame`. This is not a huge change
> on its own, but paves the way for adding support for more formats in the
> future, in particular formats other than AV_PIX_FMT_VULKAN.
> ---
> libavfilter/vf_libplacebo.c | 35 ++++++++++++++++++++++++++++-------
> 1 file changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> index cfee1117e8..cb6b021816 100644
> --- a/libavfilter/vf_libplacebo.c
> +++ b/libavfilter/vf_libplacebo.c
> @@ -56,7 +56,6 @@ static const struct pl_tone_map_function * const tonemapping_funcs[TONE_MAP_COUN
> typedef struct LibplaceboContext {
> /* lavfi vulkan*/
> FFVulkanContext vkctx;
> - int initialized;
>
> /* libplacebo */
> pl_log log;
> @@ -237,10 +236,17 @@ static int init_vulkan(AVFilterContext *avctx)
> {
> int err = 0;
> LibplaceboContext *s = avctx->priv;
> - const AVVulkanDeviceContext *hwctx = s->vkctx.hwctx;
> + const AVVulkanDeviceContext *hwctx;
> uint8_t *buf = NULL;
> size_t buf_len;
>
> + if (!avctx->hw_device_ctx) {
> + av_log(s, AV_LOG_ERROR, "Missing vulkan hwdevice for vf_libplacebo.\n");
> + return AVERROR(EINVAL);
> + }
> +
> + hwctx = ((AVHWDeviceContext*) avctx->hw_device_ctx->data)->hwctx;
> +
> /* Import libavfilter vulkan context into libplacebo */
> s->vulkan = pl_vulkan_import(s->log, pl_vulkan_import_params(
> .instance = hwctx->inst,
> @@ -289,7 +295,6 @@ static int init_vulkan(AVFilterContext *avctx)
> fail:
> if (buf)
> av_file_unmap(buf, buf_len);
> - s->initialized = 1;
> return err;
> }
>
> @@ -303,7 +308,6 @@ static void libplacebo_uninit(AVFilterContext *avctx)
> pl_vulkan_destroy(&s->vulkan);
> pl_log_destroy(&s->log);
> ff_vk_uninit(&s->vkctx);
> - s->initialized = 0;
> s->gpu = NULL;
> }
>
> @@ -452,8 +456,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
> }
>
> pl_log_level_update(s->log, get_log_level());
> - if (!s->initialized)
> - RET(init_vulkan(ctx));
>
> RET(av_frame_copy_props(out, in));
> out->width = outlink->w;
> @@ -505,6 +507,25 @@ fail:
> return err;
> }
>
> +static int libplacebo_query_format(AVFilterContext *ctx)
> +{
> + int err = 0;
> + static const enum AVPixelFormat pix_fmts[] = {
> + AV_PIX_FMT_VULKAN, AV_PIX_FMT_NONE,
> + };
> +
> + RET(init_vulkan(ctx));
> +
> + RET(ff_formats_ref(ff_make_format_list(pix_fmts),
> + &ctx->inputs[0]->outcfg.formats));
> + RET(ff_formats_ref(ff_make_format_list(pix_fmts),
> + &ctx->outputs[0]->incfg.formats));
> + return 0;
> +
> +fail:
> + return err;
> +}
> +
> static int libplacebo_config_output(AVFilterLink *outlink)
> {
> int err;
> @@ -755,7 +776,7 @@ const AVFilter ff_vf_libplacebo = {
> .process_command = &ff_filter_process_command,
> FILTER_INPUTS(libplacebo_inputs),
> FILTER_OUTPUTS(libplacebo_outputs),
> - FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN),
> + FILTER_QUERY_FUNC(libplacebo_query_format),
> .priv_class = &libplacebo_class,
> .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
> };
> --
> 2.38.0
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format
2022-11-15 13:09 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
@ 2022-11-15 15:50 ` Niklas Haas
0 siblings, 0 replies; 4+ messages in thread
From: Niklas Haas @ 2022-11-15 15:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
Merged as c0b93c4f8 after ACK via IRC.
On Tue, 15 Nov 2022 14:09:50 +0100 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> Merging in 48 hours if no replies.
>
> On Tue, 08 Nov 2022 14:12:29 +0100 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> > From: Niklas Haas <git@haasn.dev>
> >
> > Instead of doing it ad-hoc in `filter_frame`. This is not a huge change
> > on its own, but paves the way for adding support for more formats in the
> > future, in particular formats other than AV_PIX_FMT_VULKAN.
> > ---
> > libavfilter/vf_libplacebo.c | 35 ++++++++++++++++++++++++++++-------
> > 1 file changed, 28 insertions(+), 7 deletions(-)
> >
> > diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> > index cfee1117e8..cb6b021816 100644
> > --- a/libavfilter/vf_libplacebo.c
> > +++ b/libavfilter/vf_libplacebo.c
> > @@ -56,7 +56,6 @@ static const struct pl_tone_map_function * const tonemapping_funcs[TONE_MAP_COUN
> > typedef struct LibplaceboContext {
> > /* lavfi vulkan*/
> > FFVulkanContext vkctx;
> > - int initialized;
> >
> > /* libplacebo */
> > pl_log log;
> > @@ -237,10 +236,17 @@ static int init_vulkan(AVFilterContext *avctx)
> > {
> > int err = 0;
> > LibplaceboContext *s = avctx->priv;
> > - const AVVulkanDeviceContext *hwctx = s->vkctx.hwctx;
> > + const AVVulkanDeviceContext *hwctx;
> > uint8_t *buf = NULL;
> > size_t buf_len;
> >
> > + if (!avctx->hw_device_ctx) {
> > + av_log(s, AV_LOG_ERROR, "Missing vulkan hwdevice for vf_libplacebo.\n");
> > + return AVERROR(EINVAL);
> > + }
> > +
> > + hwctx = ((AVHWDeviceContext*) avctx->hw_device_ctx->data)->hwctx;
> > +
> > /* Import libavfilter vulkan context into libplacebo */
> > s->vulkan = pl_vulkan_import(s->log, pl_vulkan_import_params(
> > .instance = hwctx->inst,
> > @@ -289,7 +295,6 @@ static int init_vulkan(AVFilterContext *avctx)
> > fail:
> > if (buf)
> > av_file_unmap(buf, buf_len);
> > - s->initialized = 1;
> > return err;
> > }
> >
> > @@ -303,7 +308,6 @@ static void libplacebo_uninit(AVFilterContext *avctx)
> > pl_vulkan_destroy(&s->vulkan);
> > pl_log_destroy(&s->log);
> > ff_vk_uninit(&s->vkctx);
> > - s->initialized = 0;
> > s->gpu = NULL;
> > }
> >
> > @@ -452,8 +456,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
> > }
> >
> > pl_log_level_update(s->log, get_log_level());
> > - if (!s->initialized)
> > - RET(init_vulkan(ctx));
> >
> > RET(av_frame_copy_props(out, in));
> > out->width = outlink->w;
> > @@ -505,6 +507,25 @@ fail:
> > return err;
> > }
> >
> > +static int libplacebo_query_format(AVFilterContext *ctx)
> > +{
> > + int err = 0;
> > + static const enum AVPixelFormat pix_fmts[] = {
> > + AV_PIX_FMT_VULKAN, AV_PIX_FMT_NONE,
> > + };
> > +
> > + RET(init_vulkan(ctx));
> > +
> > + RET(ff_formats_ref(ff_make_format_list(pix_fmts),
> > + &ctx->inputs[0]->outcfg.formats));
> > + RET(ff_formats_ref(ff_make_format_list(pix_fmts),
> > + &ctx->outputs[0]->incfg.formats));
> > + return 0;
> > +
> > +fail:
> > + return err;
> > +}
> > +
> > static int libplacebo_config_output(AVFilterLink *outlink)
> > {
> > int err;
> > @@ -755,7 +776,7 @@ const AVFilter ff_vf_libplacebo = {
> > .process_command = &ff_filter_process_command,
> > FILTER_INPUTS(libplacebo_inputs),
> > FILTER_OUTPUTS(libplacebo_outputs),
> > - FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN),
> > + FILTER_QUERY_FUNC(libplacebo_query_format),
> > .priv_class = &libplacebo_class,
> > .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
> > };
> > --
> > 2.38.0
> >
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-15 15:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 13:12 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
2022-11-08 13:12 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_libplacebo: support all supported pixfmts Niklas Haas
2022-11-15 13:09 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_libplacebo: init vulkan device in query_format Niklas Haas
2022-11-15 15:50 ` Niklas Haas
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git