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 ESMTP id 8052944BD0 for ; Tue, 8 Nov 2022 13:12:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D487068BB90; Tue, 8 Nov 2022 15:12:43 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BBCF768B934 for ; Tue, 8 Nov 2022 15:12:37 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 6CEEF40DFC; Tue, 8 Nov 2022 14:12:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1667913157; bh=Vpcbo1J2FwGiLoUClnqPG5YtY70CKNHdXFfg5Fbv7Gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cj6/j06jknZWF0NkEDN0mnc9WzRtJagP15N+XvLs18IiI3IiBlZB68KeBHeEaDLR8 Ofpm8fUj0FS2uSRigvQ+ICDzoDCQnUqHXa0n1PkLuak6e6aV4l0bFn0EfrloPCqoRG CIieR9jxn0SbkBQfeB62scfLUjHgb9m706XoajFY= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Nov 2022 14:12:30 +0100 Message-Id: <20221108131230.39188-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221108131230.39188-1-ffmpeg@haasn.xyz> References: <20221108131230.39188-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_libplacebo: support all supported pixfmts 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 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".