Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_libplacebo: add shader_cache_dir option
Date: Thu, 15 May 2025 13:08:12 +0200
Message-ID: <GV1P250MB073727437FEFA299AD35709E8F90A@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20250514172213.20463-1-ffmpeg@haasn.xyz>

Niklas Haas:
> From: Niklas Haas <git@haasn.dev>
> 
> Useful to speed up shader compilation. May significantly lower startup
> times, in particular with large or complex shaders.
> 
> Sponsored-by: nxtedition
> ---
>  doc/filters.texi            |  5 +++++
>  libavfilter/vf_libplacebo.c | 29 +++++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 679b71f290..66cb3e6c20 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -16307,6 +16307,11 @@ as a list of @var{key}=@var{value} pairs separated by ':'. The following example
>  shows how to configure a custom filter kernel ("EWA LanczosSharp") and use it
>  to double the input image resolution:
>  
> +@item shader_cache_dir
> +If set to the path of a directory that exists, libplacebo will store and use
> +cached shader objects in this directory. This cache is not cleaned up
> +automatically.
> +
>  @example
>  -vf "libplacebo=w=iw*2:h=ih*2:extra_opts='upscaler=custom\:upscaler_preset=ewa_lanczos\:upscaler_blur=0.9812505644269356'"
>  @end example
> diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> index 86e1f43dea..ca7d9e253a 100644
> --- a/libavfilter/vf_libplacebo.c
> +++ b/libavfilter/vf_libplacebo.c
> @@ -195,6 +195,11 @@ typedef struct LibplaceboContext {
>      int color_trc;
>      AVDictionary *extra_opts;
>  
> +#if PL_API_VER >= 351
> +    pl_cache cache;
> +    char *shader_cache_dir;
> +#endif
> +
>      int have_hwdevice;
>  
>      /* pl_render_params */
> @@ -522,6 +527,21 @@ static int libplacebo_init(AVFilterContext *avctx)
>          return AVERROR(ENOMEM);
>      }
>  
> +#if PL_API_VER >= 351
> +    if (s->shader_cache_dir && s->shader_cache_dir[0]) {
> +        s->cache = pl_cache_create(pl_cache_params(
> +            .log  = s->log,
> +            .get  = pl_cache_get_dir,
> +            .set  = pl_cache_set_dir,
> +            .priv = s->shader_cache_dir,
> +        ));
> +        if (!s->cache) {
> +            libplacebo_uninit(avctx);
> +            return AVERROR(ENOMEM);
> +        }
> +    }
> +#endif
> +
>      if (s->out_format_string) {
>          s->out_format = av_get_pix_fmt(s->out_format_string);
>          if (s->out_format == AV_PIX_FMT_NONE) {
> @@ -676,6 +696,9 @@ static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwct
>      }
>  
>      s->gpu = s->vulkan->gpu;
> +#if PL_API_VER >= 351
> +    pl_gpu_set_cache(s->gpu, s->cache);
> +#endif
>  
>      /* Parse the user shaders, if requested */
>      if (s->shader_bin_len)
> @@ -714,6 +737,9 @@ static void libplacebo_uninit(AVFilterContext *avctx)
>          av_freep(&s->inputs);
>      }
>  
> +#if PL_API_VER >= 351
> +    pl_cache_destroy(&s->cache);
> +#endif
>      pl_options_free(&s->opts);
>      pl_vulkan_destroy(&s->vulkan);
>      pl_log_destroy(&s->log);
> @@ -1328,6 +1354,9 @@ static const AVOption libplacebo_options[] = {
>      { "fillcolor", "Background fill color", OFFSET(fillcolor), AV_OPT_TYPE_COLOR, {.str = "black@0"}, .flags = DYNAMIC },
>      { "corner_rounding", "Corner rounding radius", OFFSET(corner_rounding), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, .flags = DYNAMIC },
>      { "extra_opts", "Pass extra libplacebo-specific options using a :-separated list of key=value pairs", OFFSET(extra_opts), AV_OPT_TYPE_DICT, .flags = DYNAMIC },
> +#if PL_API_VER >= 351
> +    { "shader_cache_dir",  "Set shader cache directory", OFFSET(shader_cache_dir), AV_OPT_TYPE_STRING, {.str=""}, .flags = STATIC },

Why do you set the default to "" instead of NULL? This gives an
allocation even when the option is never set and makes the check for
whether it is set unnecessarily complicated.

> +#endif
>  
>      {"colorspace", "select colorspace", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_SPC_NB-1, DYNAMIC, .unit = "colorspace"},
>      {"auto", "keep the same colorspace",  0, AV_OPT_TYPE_CONST, {.i64=-1},                          INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},

_______________________________________________
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".

  reply	other threads:[~2025-05-15 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 17:22 Niklas Haas
2025-05-15 11:08 ` Andreas Rheinhardt [this message]
2025-05-15 12:13   ` Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB073727437FEFA299AD35709E8F90A@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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