From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 7E96B4EECB for ; Wed, 14 May 2025 17:22:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B3EC968CB95; Wed, 14 May 2025 20:22:30 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 972F168CA56 for ; Wed, 14 May 2025 20:22:24 +0300 (EEST) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id 21C77406F9; Wed, 14 May 2025 19:22:24 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 May 2025 19:22:13 +0200 Message-ID: <20250514172213.20463-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_libplacebo: add shader_cache_dir option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas 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 }, +#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"}, -- 2.49.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".