From patchwork Sun Jan 2 14:51:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Jianhua" X-Patchwork-Id: 33011 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp15455921iog; Sun, 2 Jan 2022 06:52:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvrRcsS9DYU+jC/s88wtbEbTV67nFvIgFGU3iAbL3kRC9xOvXCWITgD1cCvMSjTIMUCCST X-Received: by 2002:a05:6402:2747:: with SMTP id z7mr41311659edd.124.1641135133426; Sun, 02 Jan 2022 06:52:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641135133; cv=none; d=google.com; s=arc-20160816; b=0Mv4fWnRlXLjWKyPGBpNlhP6EIiu9HIwhQfwAxubKdWKYJzH906hcKQ0vPGxuJGF9a AZWsu+3GVF74fWuJhtkYsiUeY/zfvN6Kw788FOwTR724CG4rbvlDZz3dAwY8IJMYHNWz AG6h86QCqRZB3HRYLEM4+5Yjw4jg2GSc/AWD4CeJ5LPTjKfslujk4ukDwKopWJrUTFop PCM1p+OzImqvOPSf6n0wMFK+ai5bI7umCtwEdGlzhP3M6rP7AA7J5e9nQfDEkD7W4IJD lSgHEtWXv6WYu6bLBmjvJ2Ek52oBmbjGb1OUA76qcWg5jwEPNPsQoy9jHkSTK4lcXnum VA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=RfeGPbDGZducksrpKRpStKTQodJ5KGDKPqnqTh5yGI8=; b=kWBPmYurSXrHXI9ynMkiweGTSgyI1L/4BxhJnh4vGaq/QA0U52j1pUjl1FbxGNvWbB A+vBIzrmk9hE0b5jfneYwFwyhjan/bW3xPm4md1nYgjvKvXPEnPDIdr/OiyvYQ6whZLZ aV8tGXlSCFzwo2V/oy7+Kjrmuo0X1JdOa0SZqyBuwDwDiTmsvVbxAWlGd8mjIcmA6vs6 L7W8dzjfVtWVqTPhdOQ2wAatVkpuvDTTON8xlF7rQohUr1Gm+Bl5aySm/nMPZRN13uFb GlEN8uDDVXRo7vL712RBL/UfYNHnoLMA+EQxiVgyL7k12501rYME/82qJuHNPYbHhGKO XJWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=j3ywziRD; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qf36si17989663ejc.638.2022.01.02.06.52.13; Sun, 02 Jan 2022 06:52:13 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=j3ywziRD; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C819468B15E; Sun, 2 Jan 2022 16:52:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF2AC6807A1 for ; Sun, 2 Jan 2022 16:52:03 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641135129; x=1672671129; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=7Xcg7RMm0ipNu3c/78JM+ZpIc82f5NE1RPqvRMb29zE=; b=j3ywziRDMaELttSVUtUiP5ukch6Bxd/3HsBsyQ+llOSApTEhMr2QolbE OKT/FZVaXUM9A1OEECVFuVNxf1HqOz7v9APV0AkrOj38XofzDeAhUlrd1 dTs5i7LQgOUQXCxbU0z4R6pscpKC4VnABuuzgr4tD5ub+bEyg6W96vMq2 6KPVqa+KVhNPNjBWpexgz/dI3CIVncukSizKzNfL6CqCyIFKST1lSRqwH fUqlw7QvYUOY8SNEcm2KPvRE0DmXE333t1QcvOZq/68ViNAawFI98M0e3 G4XTiCAxdFV+12EVZO+axhH+ae3LWSPmT1mADvqi3wAzuU5reieZTv17j w==; X-IronPort-AV: E=McAfee;i="6200,9189,10214"; a="221965995" X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="221965995" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2022 06:52:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="667176291" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga001.fm.intel.com with ESMTP; 02 Jan 2022 06:52:00 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jan 2022 22:51:38 +0800 Message-Id: <20220102145142.4083918-1-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avutil/hwcontext_vulkan: fixed validation error VUID 01387 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: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nonvEmGp9EXb This commit fixed the validation error that occurred on the Windows platform. Validation Error: [ VUID-vkCreateDevice-ppEnabledExtensionNames-01387 ] Object 0: \ handle = 0x2ab1cfa0db0, type = VK_OBJECT_TYPE_INSTANCE; | MessageID = 0x12537a2c | \ Missing extension required by the device extension VK_EXT_hdr_metadata: VK_KHR_swapchain. \ The Vulkan spec states: All required device extensions for each extension in the \ VkDeviceCreateInfo::ppEnabledExtensionNames list must also be present in that list \ (https://vulkan.lunarg.com/doc/view/1.2.198.1/windows/1.2-extensions/vkspec.html#\ VUID-vkCreateDevice-ppEnabledExtensionNames-01387) Signed-off-by: Wu Jianhua --- libavutil/hwcontext_vulkan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 83a7527198..a2a175a063 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -335,7 +335,11 @@ typedef struct VulkanOptExtension { } VulkanOptExtension; static const VulkanOptExtension optional_instance_exts[] = { - /* For future use */ + /* Misc or required by other extensions */ +#ifdef _WIN32 + { VK_KHR_WIN32_SURFACE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, + { VK_KHR_SURFACE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#endif }; static const VulkanOptExtension optional_device_exts[] = { @@ -344,6 +348,9 @@ static const VulkanOptExtension optional_device_exts[] = { { VK_EXT_HDR_METADATA_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, { VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, { VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#ifdef _WIN32 + { VK_KHR_SWAPCHAIN_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#endif /* Imports/exports */ { VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, FF_VK_EXT_EXTERNAL_FD_MEMORY }, From patchwork Sun Jan 2 14:51:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Jianhua" X-Patchwork-Id: 33012 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp15455980iog; Sun, 2 Jan 2022 06:52:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7Nce7Gg5q4fttWHvtcGoY0o1oitD9PtKP/cjPMa5M3Z5+UB2uV11tsRsCQ+6iNBPGlnm4 X-Received: by 2002:a17:906:a3c6:: with SMTP id ca6mr33081076ejb.639.1641135142869; Sun, 02 Jan 2022 06:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641135142; cv=none; d=google.com; s=arc-20160816; b=HUA7UnfEMLA82cQ2dSondEUyOTPSh8NCVmR+BAmhj7uM5nzmJ1rBNz/+lpFrDWI7SA Asaml7aQa3AqVttrCAyUpcacQmSrIDFiZLv/hlbdixqeZ+b8UPvUCf3PL9lm0Akj66J9 Ul2pNQmFvQWbRbHYvMTaDaz1v4K7y08wEqLayaXAa47qsb+fLYumwRSPHmG3UCyzPtKh lUDkjfWOC2KWyNVc7TlUmwa5/CxoYKHr0Nh2RlyEuiAYBsNxBOROQsTBXyi4+LnJ8flH /YHn8ET+mwSyO0y5JYiWBHBs3gjGAeNL8d4kJynGgKRpKhCwHuMyeRtue9Vc5haiNb6y s6MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=+yTfv2dR21Hoyk2y7jTyV9ynXNtyXlvVUXczwoI+KBI=; b=rS/cpCbaG02j+gPy7cWFNtE0m8hHMhPFaBmbxW6/dVy/BHTmqt1a11OkcxDsG4n7TO WMi9Cr7ouycKozdIebfusqKyFWGFSCF6ylgjcDWHHcgaCgpTILCjUY+SZIyqzZKBVhwz uxzTY4G4jkMlhgH6DHgD+dz4jZz/OZ49fLWK3bETJSqsiMgvgKS6bRArysptyQpK/PUz noA/Z/ddKrD/aqCrOHjuzCxIqhjWTf0cA1BOsRr3fEiKS9Vn00fPiZeAtW/ZSG/6hdUH 9W0Ekn0YmHuPwXrsfGVuRGla5+n3AHeYw/antHI+nuoEvP1C4rVizYNZHkCpB/AjOUuF bFzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=XPlqRs+I; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l14si17894220ejo.394.2022.01.02.06.52.22; Sun, 02 Jan 2022 06:52:22 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=XPlqRs+I; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C64D368B162; Sun, 2 Jan 2022 16:52:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37BB568B13F for ; Sun, 2 Jan 2022 16:52:05 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641135130; x=1672671130; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DM7w7eydk3ghh6QK8YoDYHquJA8UOTYzO0IQmds6hSw=; b=XPlqRs+I5UODT+zV51sstD8EtE3jR+EUyIjc9zYqWPwe2P6V7b6Hod1a tfY8I05Ht/usjqaCIx4V9q0TMWxNm0vlnkNmg3EVOmh/TjDNtCGADjkuT J0N5sYUs9tj4BGOrvjv+3euZyS3DTNH/k6AAnqy1qbybtMLek8X35r6qC bJi0q0Rl1L/qlRZlIJMwtnlXPWw53hx4BxL4rYh3Wl99dKmErLvCkY8gF 2dy13ZjD2NyLudpahgXu92K0zF28vHpI15qg9e1b8SCUfMqRGdpauSJb+ WjCW1/vT6EeZDLfQSFZa+pZy29XOMyIY40PI0Wyp4mYXc/wAMDwXG2+Qr Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10214"; a="221965999" X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="221965999" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2022 06:52:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="667176299" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga001.fm.intel.com with ESMTP; 02 Jan 2022 06:52:01 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jan 2022 22:51:39 +0800 Message-Id: <20220102145142.4083918-2-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220102145142.4083918-1-jianhua.wu@intel.com> References: <20220102145142.4083918-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] transpose_vulkan: add passthrough 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: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TySHl5nv+UbO The following command is on how to apply passthrough option: ffmpeg -init_hw_device vulkan -i input.264 -vf hwupload=extra_hw_frames=16,transpose_vulkan=passthrough=landscape,hwdownload,format=yuv420p output.264 Signed-off-by: Wu Jianhua --- libavfilter/vf_transpose_vulkan.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libavfilter/vf_transpose_vulkan.c b/libavfilter/vf_transpose_vulkan.c index ce83cf0fd7..30d052e08c 100644 --- a/libavfilter/vf_transpose_vulkan.c +++ b/libavfilter/vf_transpose_vulkan.c @@ -35,6 +35,7 @@ typedef struct TransposeVulkanContext { VkDescriptorImageInfo output_images[3]; int dir; + int passthrough; int initialized; } TransposeVulkanContext; @@ -222,6 +223,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) TransposeVulkanContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; + if (s->passthrough) + return ff_filter_frame(outlink, in); + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { err = AVERROR(ENOMEM); @@ -267,6 +271,17 @@ static int config_props_output(AVFilterLink *outlink) FFVulkanContext *vkctx = &s->vkctx; AVFilterLink *inlink = avctx->inputs[0]; + if ((inlink->w >= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) || + (inlink->w <= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) { + av_log(avctx, AV_LOG_VERBOSE, + "w:%d h:%d -> w:%d h:%d (passthrough mode)\n", + inlink->w, inlink->h, inlink->w, inlink->h); + outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx); + return outlink->hw_frames_ctx ? 0 : AVERROR(ENOMEM); + } else { + s->passthrough = TRANSPOSE_PT_TYPE_NONE; + } + vkctx->output_width = inlink->h; vkctx->output_height = inlink->w; @@ -288,6 +303,13 @@ static const AVOption transpose_vulkan_options[] = { { "clock", "rotate clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK }, .flags=FLAGS, .unit = "dir" }, { "cclock", "rotate counter-clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK }, .flags=FLAGS, .unit = "dir" }, { "clock_flip", "rotate clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK_FLIP }, .flags=FLAGS, .unit = "dir" }, + + { "passthrough", "do not apply transposition if the input matches the specified geometry", + OFFSET(passthrough), AV_OPT_TYPE_INT, {.i64=TRANSPOSE_PT_TYPE_NONE}, 0, INT_MAX, FLAGS, "passthrough" }, + { "none", "always apply transposition", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_NONE}, INT_MIN, INT_MAX, FLAGS, "passthrough" }, + { "portrait", "preserve portrait geometry", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_PORTRAIT}, INT_MIN, INT_MAX, FLAGS, "passthrough" }, + { "landscape", "preserve landscape geometry", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_LANDSCAPE}, INT_MIN, INT_MAX, FLAGS, "passthrough" }, + { NULL } }; From patchwork Sun Jan 2 14:51:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Jianhua" X-Patchwork-Id: 33013 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp15456032iog; Sun, 2 Jan 2022 06:52:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZcFzRtyG2Ect7N1eJS89089ar7VmIsdspR0tbcKX3LrQn8tQlgPRJ3bnnQ71BDWWHt4r8 X-Received: by 2002:a50:d65e:: with SMTP id c30mr40591271edj.77.1641135151642; Sun, 02 Jan 2022 06:52:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641135151; cv=none; d=google.com; s=arc-20160816; b=VyA9/R9syTq7jNpUCwV4VvCvjEDmGMddsLtPCa/v1BFy7KPDlNWSdXxcphfnrl8Wev qNMgO+zEW8EqFlv5RGgXg0aX5XhyXqrkdezrFUuyOwOF3lRgc3b+4OV960A7+bUFQgG0 KJf+CTUSpKcjXIuyBsIwMUiHad5U4WA3Tifs2Xn8wYSDXrUMjtVCj6g5DpJSZWyCPiEe qU79Rk4iAjnnY76nb9w5prmpGUYGR1qYSpvkTIyNbh+FDuGdcTwO4J7TNOCvBhSCKrTt TD345UZqcWh96D8X49Y78nt+gjD4mNp/aYcucnYcaovrtDnpv/90pw3XANgXYoRYGx/f lVGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=h3JVeFLTwhmIWU9urkpie9Nz5xBBfDwn7Y7r3WWZiUQ=; b=uY4UDTy1OaTT/ogVwhsFVvqZWDjbO57QsOHtIfYS+Fkq2KHA+sPB+UNmPRibudZ4zS 4r3UrwgGRtmd1HYacgDGQ5hAhLoIsNRAqJJy0crImKxKrK0EQUkLzZMRuVl/Lg15740c WAjKkRDlR9HexlD+Y/BLET7+Cj8hOdMt0LiiQjAQSriK2EP+/03mloaPAaj5XO8aOW6v 2mvrzWbdn3iEr4GTO7a4mSCEh5Ogsp9A5OwcCgPpXeHmmBnFgzCNC4wpuBIqNwhAhXZD 33Sbb6nujDTQ5W7x6NaHyICg/miVE+h+FuJu5XXBClu0Bjr2Gtba4VC6qrZ5EK2PMqa0 U+eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=VQltRTxS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cw22si15471611ejc.866.2022.01.02.06.52.31; Sun, 02 Jan 2022 06:52:31 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=VQltRTxS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D263668B16B; Sun, 2 Jan 2022 16:52:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82D4368B144 for ; Sun, 2 Jan 2022 16:52:06 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641135131; x=1672671131; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q7eN2EC/YdCXG3afd9uH98u9fvEvuE5g34RELTeUXoA=; b=VQltRTxSBGK0PB2k20ed9/rWYGunQMxS8UWtPFpTUekYdHUTC+qrZchr lE9T8fpmHW1j3lX4oqH2jZTB2OikI85o0uLwsr/O+PgjQMeyTjzoOGH1j BxJUCKBkb2veU+uXgtSicpoHeXNdT/JeOAidfLHEomfufWITZ5DQjE9Ex XmvRugxWPalPaDs8OPB2YwUiu6NIJJb7IjI+PwaH+nEIGE5jYqjJwiu4b eneWpJP4AFlLqYPmBsvUOMhTvo73w20VGBvBquOsKJvgml2hhCRAlidBu S8G9hDkfsh4hasSPtOgoEjoluqX1M0OoN4FiI8iZ3tJHb8myXUKRxS8Oh A==; X-IronPort-AV: E=McAfee;i="6200,9189,10214"; a="221966000" X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="221966000" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2022 06:52:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="667176307" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga001.fm.intel.com with ESMTP; 02 Jan 2022 06:52:02 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jan 2022 22:51:40 +0800 Message-Id: <20220102145142.4083918-3-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220102145142.4083918-1-jianhua.wu@intel.com> References: <20220102145142.4083918-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avfilter/vf_scale_vulkan: align struct ScaleVulkanContext 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: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: CW4HPGzhMto6 On 64 bit Operating System, sizeof(ScaleVulkanContext): reduce from 2400 to 2392 on Linux reduce from 2416 to 2408 on Windows Signed-off-by: Wu Jianhua --- libavfilter/vf_scale_vulkan.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_scale_vulkan.c b/libavfilter/vf_scale_vulkan.c index cfce5ab1f8..c87a8d7e2e 100644 --- a/libavfilter/vf_scale_vulkan.c +++ b/libavfilter/vf_scale_vulkan.c @@ -35,7 +35,6 @@ enum ScalerFunc { typedef struct ScaleVulkanContext { FFVulkanContext vkctx; - int initialized; FFVkQueueFamilyCtx qf; FFVkExecContext *exec; FFVulkanPipeline *pl; @@ -46,11 +45,14 @@ typedef struct ScaleVulkanContext { VkDescriptorImageInfo output_images[3]; VkDescriptorBufferInfo params_desc; - enum ScalerFunc scaler; char *out_format_string; - enum AVColorRange out_range; char *w_expr; char *h_expr; + + enum ScalerFunc scaler; + enum AVColorRange out_range; + + int initialized; } ScaleVulkanContext; static const char scale_bilinear[] = { From patchwork Sun Jan 2 14:51:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Jianhua" X-Patchwork-Id: 33014 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp15456091iog; Sun, 2 Jan 2022 06:52:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/xrKGKwqrnP3S0L2VRjm6BzDHOZc/8RvqddofCKyIUtwzeiRsxT9pmlbZiCBN8SoArlGk X-Received: by 2002:aa7:cd45:: with SMTP id v5mr42785131edw.163.1641135160583; Sun, 02 Jan 2022 06:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641135160; cv=none; d=google.com; s=arc-20160816; b=qkapBJbsVrMvq7MmBqjYLLO9VJIx06tfpCNG7yI6hJQDd+KL7HNe+LVviMEbZnzBjd TrRu0XLDpz8hX+Zmt07HH8U1Ca2N3/FUFrDB6Ztgp49YKKlLavz0xlX80h+W079xnYjx IRSkbLK1eQp0K9RJmzo2Bnx4VCawHdtflMi0576G3Ija4PtZ+XkYnwSGqyzKAv6chi7p bM4LgGkojVSo0ABkZ6uIS/9XicRQiRK/sSoiJqLflt+xNNingjCKynAW7h9KWMotES+l XS8R540QUc3GaImP+YycfZn1i+FDBvQC7ve2GVKsuTDHcjVM/tZwiuUIo0Q1Wr6z6KX8 Dfrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=9nOZxvpYQ/qHO/+hUXg4iMSePIXOk2mxNOqS1yIoIZQ=; b=ym+8ep9m7DW7Wng9DqaANHYavEOrcI+9gvUa7Cz9Iy1+Y6uRCya2qCV1yh70fbF60I N81TaV5dXYTMEWJdHT+Ojg/PV5yxw8ZUt0OaEB+KVCYLfx5PA8bUXPxVxNe3koUs74u+ suq5tasJHv8GjIWMIDLZGiywWflAIBaVnf54tqmTZX5rjQMuEUMqaySzKaDGlRqj/jiH ygCWyWMB+/9Ti6QlOAT7eWvZDBueMkOVQMHNsOA153kTpYnN419ISX9TwSb+EFmF2Eyq IXkUR857XL6J5bM51KV7lowtkNmOD6xO8+xjS/NIP6Eh7WI+2CJF7LSMjHNm91F9m8/e pweQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=In2aLZY7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d22si15532058edt.371.2022.01.02.06.52.40; Sun, 02 Jan 2022 06:52:40 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=In2aLZY7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D3D9D68B16F; Sun, 2 Jan 2022 16:52:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D41868B16F for ; Sun, 2 Jan 2022 16:52:09 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641135135; x=1672671135; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wAc/ZgFAhlu4xaJzye7+slQIlVehz7JmfSwaKNMg4EU=; b=In2aLZY7cXUrKbyWW9kXfeeD5XAx1hnbb90oxm1sF95qKmM/z5UxgqOG 0xOZ1Vtwy0D3D0zwUmLSNzdaegrB1gDC+Or4uI3XYDFxtcXNHxLJnUwcd o+oaksoV077w3O4Yy0N2AS0IhxyGgwnElaytAMoYB7DzTdeTwaVb1mlDI +/n7aJDwpWC5DasATFORqJDEq0dHeL5TJH8GRqMKxz3aC1Ktwr94vBewO 5im8hYu5tC38XgeZ22XP/DTUiMYoZpyneh/2ZxTEIFcck5tc7zq3nqGV2 SHa1SKwjFRV1iHhVTqejU/RxJzAuECqbqXUJzVWaNLfcoTG0SLVNUc3Cq w==; X-IronPort-AV: E=McAfee;i="6200,9189,10214"; a="221966001" X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="221966001" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2022 06:52:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="667176314" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga001.fm.intel.com with ESMTP; 02 Jan 2022 06:52:03 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jan 2022 22:51:41 +0800 Message-Id: <20220102145142.4083918-4-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220102145142.4083918-1-jianhua.wu@intel.com> References: <20220102145142.4083918-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avfilter: add a blend_vulkan filter 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: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: y+nY2HkmZOZ6 This commit adds a blend_vulkan filter and a normal blend mode, and reserves support for introducing the blend modes in the future. Use the commands below to test: (href: https://trac.ffmpeg.org/wiki/Blend) I. make an image for test ffmpeg -f lavfi -i color=s=256x256,geq=r='H-1-Y':g='H-1-Y':b='H-1-Y' -frames 1 \ -y -pix_fmt yuv420p test.jpg II. blend in sw ffmpeg -i test.jpg -vf "split[a][b];[b]transpose[b];[a][b]blend=all_mode=normal,\ pseudocolor=preset=turbo" -y normal_sw.jpg III. blend in vulkan ffmpeg -init_hw_device vulkan -i test.jpg -vf "split[a][b];[b]transpose[b];\ [a]hwupload[a];[b]hwupload[b];[a][b]blend_vulkan=all_mode=normal,hwdownload,\ format=yuv420p,pseudocolor=preset=turbo" -y normal_vulkan.jpg Signed-off-by: Wu Jianhua --- configure | 1 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_blend_vulkan.c | 501 ++++++++++++++++++++++++++++++++++ 4 files changed, 504 insertions(+) create mode 100644 libavfilter/vf_blend_vulkan.c diff --git a/configure b/configure index 6ad70b9f7b..f6c9e38051 100755 --- a/configure +++ b/configure @@ -3609,6 +3609,7 @@ avgblur_opencl_filter_deps="opencl" avgblur_vulkan_filter_deps="vulkan spirv_compiler" azmq_filter_deps="libzmq" blackframe_filter_deps="gpl" +blend_vulkan_filter_deps="vulkan spirv_compiler" bm3d_filter_deps="avcodec" bm3d_filter_select="dct" boxblur_filter_deps="gpl" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 090944a99c..ed727e3fd9 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -192,6 +192,7 @@ OBJS-$(CONFIG_BITPLANENOISE_FILTER) += vf_bitplanenoise.o OBJS-$(CONFIG_BLACKDETECT_FILTER) += vf_blackdetect.o OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o OBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o framesync.o +OBJS-$(CONFIG_BLEND_VULKAN_FILTER) += vf_blend_vulkan.o framesync.o vulkan.o vulkan_filter.o OBJS-$(CONFIG_BM3D_FILTER) += vf_bm3d.o framesync.o OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o boxblur.o OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \ diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index caa755320e..84ba9fdf54 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -183,6 +183,7 @@ extern const AVFilter ff_vf_bitplanenoise; extern const AVFilter ff_vf_blackdetect; extern const AVFilter ff_vf_blackframe; extern const AVFilter ff_vf_blend; +extern const AVFilter ff_vf_blend_vulkan; extern const AVFilter ff_vf_bm3d; extern const AVFilter ff_vf_boxblur; extern const AVFilter ff_vf_boxblur_opencl; diff --git a/libavfilter/vf_blend_vulkan.c b/libavfilter/vf_blend_vulkan.c new file mode 100644 index 0000000000..fac1be532d --- /dev/null +++ b/libavfilter/vf_blend_vulkan.c @@ -0,0 +1,501 @@ +/* + * copyright (c) 2021 Wu Jianhua + * The blend modes are based on the blend.c. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/random_seed.h" +#include "libavutil/opt.h" +#include "vulkan_filter.h" +#include "internal.h" +#include "framesync.h" +#include "blend.h" + +#define CGS 32 + +typedef struct FilterParamsVulkan { + const char *blend; + const char *blend_func; + double opacity; + enum BlendMode mode; +} FilterParamsVulkan; + +typedef struct BlendVulkanContext { + FFVulkanContext vkctx; + FFVkQueueFamilyCtx qf; + FFVkExecContext *exec; + FFVulkanPipeline *pl; + FFFrameSync fs; + + VkDescriptorImageInfo top_images[3]; + VkDescriptorImageInfo bottom_images[3]; + VkDescriptorImageInfo output_images[3]; + + FilterParamsVulkan params[4]; + double all_opacity; + enum BlendMode all_mode; + + int initialized; +} BlendVulkanContext; + +#define DEFINE_BLEND_MODE(MODE, EXPR) \ +static const char blend_##MODE[] = "blend_"#MODE; \ +static const char blend_##MODE##_func[] = { \ + C(0, vec4 blend_##MODE(vec4 top, vec4 bottom, float opacity) { ) \ + C(1, vec4 dst = EXPR; ) \ + C(1, return dst; ) \ + C(0, } ) \ +}; + +#define TOP 0 +#define BOTTOM 1 + +#define A top +#define B bottom + +DEFINE_BLEND_MODE(NORMAL, A * opacity + B * (1.f - opacity)) + +static inline void init_blend_func(FilterParamsVulkan *param) +{ +#define CASE(MODE) case BLEND_##MODE: \ + param->blend = blend_##MODE;\ + param->blend_func = blend_##MODE##_func; \ + break; + + switch (param->mode) { + CASE(NORMAL) + default: param->blend = NULL; break; + } + +#undef CASE +} + +static int config_params(AVFilterContext *avctx) +{ + BlendVulkanContext *s = avctx->priv; + + for (int plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) { + FilterParamsVulkan *param = &s->params[plane]; + + if (s->all_mode >= 0) + param->mode = s->all_mode; + if (s->all_opacity < 1) + param->opacity = s->all_opacity; + + init_blend_func(param); + if (!param->blend) { + av_log(avctx, AV_LOG_ERROR, + "Currently the blend mode specified is not supported yet.\n"); + return AVERROR(EINVAL); + } + } + + return 0; +} + +static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + int ret; + + ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags); + if (ret < 0) + return ret; + + return config_params(ctx); +} + +static av_cold int init_filter(AVFilterContext *avctx) +{ + int err = 0; + FFVkSampler *sampler; + FFVkSPIRVShader *shd; + BlendVulkanContext *s = avctx->priv; + FFVulkanContext *vkctx = &s->vkctx; + const int planes = av_pix_fmt_count_planes(s->vkctx.output_format); + + ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT, 0); + + sampler = ff_vk_init_sampler(vkctx, 1, VK_FILTER_LINEAR); + if (!sampler) + return AVERROR_EXTERNAL; + + s->pl = ff_vk_create_pipeline(vkctx, &s->qf); + if (!s->pl) + return AVERROR(ENOMEM); + + { + FFVulkanDescriptorSetBinding image_descs[] = { + { + .name = "top_images", + .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .dimensions = 2, + .elems = planes, + .stages = VK_SHADER_STAGE_COMPUTE_BIT, + .updater = s->top_images, + .sampler = sampler, + }, + { + .name = "bottom_images", + .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .dimensions = 2, + .elems = planes, + .stages = VK_SHADER_STAGE_COMPUTE_BIT, + .updater = s->bottom_images, + .sampler = sampler, + }, + { + .name = "output_images", + .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format), + .mem_quali = "writeonly", + .dimensions = 2, + .elems = planes, + .stages = VK_SHADER_STAGE_COMPUTE_BIT, + .updater = s->output_images, + }, + }; + + shd = ff_vk_init_shader(s->pl, "blend_compute", image_descs[0].stages); + if (!shd) + return AVERROR(ENOMEM); + + ff_vk_set_compute_shader_sizes(shd, (int [3]){ CGS, CGS, 1 }); + RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, image_descs, FF_ARRAY_ELEMS(image_descs), 0)); + + for (int i = 0, j = 0; i < planes; i++) { + for (j = 0; j < i; j++) + if (s->params[i].blend_func == s->params[j].blend_func) + break; + /* note: the bracket is needed, for GLSLD is a macro with multiple statements. */ + if (j == i) { + GLSLD(s->params[i].blend_func); + } + } + + GLSLC(0, void main() ); + GLSLC(0, { ); + GLSLC(1, ivec2 size; ); + GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); ); + for (int i = 0; i < planes; i++) { + GLSLC(0, ); + GLSLF(1, size = imageSize(output_images[%i]); ,i); + GLSLC(1, if (IS_WITHIN(pos, size)) { ); + GLSLF(2, const vec4 top = texture(top_images[%i], pos); ,i); + GLSLF(2, const vec4 bottom = texture(bottom_images[%i], pos); ,i); + GLSLF(2, const float opacity = %f; ,s->params[i].opacity); + GLSLF(2, vec4 dst = %s(top, bottom, opacity);,s->params[i].blend); + GLSLC(0, ); + GLSLF(2, imageStore(output_images[%i], pos, dst); ,i); + GLSLC(1, } ); + } + GLSLC(0, } ); + + RET(ff_vk_compile_shader(vkctx, shd, "main")); + RET(ff_vk_init_pipeline_layout(vkctx, s->pl)); + RET(ff_vk_init_compute_pipeline(vkctx, s->pl)); + } + + RET(ff_vk_create_exec_ctx(vkctx, &s->exec, &s->qf)); + + s->initialized = 1; + +fail: + return err; +} + +static int process_frames(AVFilterContext *avctx, AVFrame *out_frame, AVFrame *top_frame, AVFrame *bottom_frame) +{ + int err = 0; + VkCommandBuffer cmd_buf; + BlendVulkanContext *s = avctx->priv; + FFVulkanContext *vkctx = &s->vkctx; + FFVulkanFunctions *vk = &s->vkctx.vkfn; + const int planes = av_pix_fmt_count_planes(s->vkctx.output_format); + + AVVkFrame *out = (AVVkFrame *)out_frame->data[0]; + AVVkFrame *top = (AVVkFrame *)top_frame->data[0]; + AVVkFrame *bottom = (AVVkFrame *)bottom_frame->data[0]; + + AVHWFramesContext *top_fc = (AVHWFramesContext*)top_frame->hw_frames_ctx->data; + AVHWFramesContext *bottom_fc = (AVHWFramesContext*)bottom_frame->hw_frames_ctx->data; + + const VkFormat *top_formats = av_vkfmt_from_pixfmt(top_fc->sw_format); + const VkFormat *bottom_formats = av_vkfmt_from_pixfmt(bottom_fc->sw_format); + const VkFormat *output_formats = av_vkfmt_from_pixfmt(s->vkctx.output_format); + + ff_vk_start_exec_recording(vkctx, s->exec); + cmd_buf = ff_vk_get_exec_buf(s->exec); + + for (int i = 0; i < planes; i++) { + RET(ff_vk_create_imageview(vkctx, s->exec, + &s->top_images[i].imageView, top->img[i], + top_formats[i], + ff_comp_identity_map)); + + RET(ff_vk_create_imageview(vkctx, s->exec, + &s->bottom_images[i].imageView, bottom->img[i], + bottom_formats[i], + ff_comp_identity_map)); + + RET(ff_vk_create_imageview(vkctx, s->exec, + &s->output_images[i].imageView, out->img[i], + output_formats[i], + ff_comp_identity_map)); + + s->top_images[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + s->bottom_images[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + s->output_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; + } + + ff_vk_update_descriptor_set(vkctx, s->pl, 0); + + for (int i = 0; i < planes; i++) { + VkImageMemoryBarrier barriers[] = { + { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = 0, + .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, + .oldLayout = top->layout[i], + .newLayout = s->top_images[i].imageLayout, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = top->img[i], + .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange.levelCount = 1, + .subresourceRange.layerCount = 1, + }, + { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = 0, + .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, + .oldLayout = bottom->layout[i], + .newLayout = s->bottom_images[i].imageLayout, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = bottom->img[i], + .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange.levelCount = 1, + .subresourceRange.layerCount = 1, + }, + { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = 0, + .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT, + .oldLayout = out->layout[i], + .newLayout = s->output_images[i].imageLayout, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = out->img[i], + .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .subresourceRange.levelCount = 1, + .subresourceRange.layerCount = 1, + }, + }; + + vk->CmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, + 0, NULL, 0, NULL, FF_ARRAY_ELEMS(barriers), barriers); + + top->layout[i] = barriers[0].newLayout; + top->access[i] = barriers[0].dstAccessMask; + + bottom->layout[i] = barriers[1].newLayout; + bottom->access[i] = barriers[1].dstAccessMask; + + out->layout[i] = barriers[2].newLayout; + out->access[i] = barriers[2].dstAccessMask; + } + + ff_vk_bind_pipeline_exec(vkctx, s->exec, s->pl); + vk->CmdDispatch(cmd_buf, FFALIGN(s->vkctx.output_width, CGS) / CGS, + FFALIGN(s->vkctx.output_height, CGS) / CGS, 1); + + ff_vk_add_exec_dep(vkctx, s->exec, top_frame, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); + ff_vk_add_exec_dep(vkctx, s->exec, bottom_frame, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); + ff_vk_add_exec_dep(vkctx, s->exec, out_frame, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); + + err = ff_vk_submit_exec_queue(vkctx, s->exec); + if (err) + return err; + + ff_vk_qf_rotate(&s->qf); + + return 0; + +fail: + ff_vk_discard_exec_deps(s->exec); + return err; +} + +static int blend_frame(FFFrameSync *fs) +{ + int err; + AVFilterContext *avctx = fs->parent; + BlendVulkanContext *s = avctx->priv; + AVFilterLink *outlink = avctx->outputs[0]; + AVFrame *top, *bottom, *out; + + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + err = AVERROR(ENOMEM); + goto fail; + } + + RET(ff_framesync_get_frame(fs, TOP, &top, 0)); + RET(ff_framesync_get_frame(fs, BOTTOM, &bottom, 0)); + + RET(av_frame_copy_props(out, top)); + + if (!s->initialized) { + AVHWFramesContext *top_fc = (AVHWFramesContext*)top->hw_frames_ctx->data; + AVHWFramesContext *bottom_fc = (AVHWFramesContext*)bottom->hw_frames_ctx->data; + if (top_fc->sw_format != bottom_fc->sw_format) { + av_log(avctx, AV_LOG_ERROR, + "Currently the sw format of the bottom video need to match the top!\n"); + return AVERROR(EINVAL); + } + RET(init_filter(avctx)); + } + + RET(process_frames(avctx, out, top, bottom)); + + return ff_filter_frame(outlink, out); + +fail: + av_frame_free(&out); + return err; +} + +static av_cold int init(AVFilterContext *avctx) +{ + BlendVulkanContext *s = avctx->priv; + + s->fs.on_event = blend_frame; + + return ff_vk_filter_init(avctx); +} + +static av_cold void uninit(AVFilterContext *avctx) +{ + BlendVulkanContext *s = avctx->priv; + + ff_framesync_uninit(&s->fs); + + ff_vk_uninit(&s->vkctx); + + s->initialized = 0; +} + +static int config_props_output(AVFilterLink *outlink) +{ + int err; + AVFilterContext *avctx = outlink->src; + BlendVulkanContext *s = avctx->priv; + AVFilterLink *toplink = avctx->inputs[TOP]; + AVFilterLink *bottomlink = avctx->inputs[BOTTOM]; + + if (toplink->w != bottomlink->w || toplink->h != bottomlink->h) { + av_log(avctx, AV_LOG_ERROR, "First input link %s parameters " + "(size %dx%d) do not match the corresponding " + "second input link %s parameters (size %dx%d)\n", + avctx->input_pads[TOP].name, toplink->w, toplink->h, + avctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h); + return AVERROR(EINVAL); + } + + outlink->sample_aspect_ratio = toplink->sample_aspect_ratio; + outlink->frame_rate = toplink->frame_rate; + + RET(ff_vk_filter_config_output(outlink)); + + RET(ff_framesync_init_dualinput(&s->fs, avctx)); + + RET(ff_framesync_configure(&s->fs)); + outlink->time_base = s->fs.time_base; + + RET(config_params(avctx)); + +fail: + return err; +} + +static int activate(AVFilterContext *avctx) +{ + BlendVulkanContext *s = avctx->priv; + return ff_framesync_activate(&s->fs); +} + +#define OFFSET(x) offsetof(BlendVulkanContext, x) +#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) + +static const AVOption blend_vulkan_options[] = { + { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, BLEND_NB - 1, FLAGS, "mode" }, + { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, BLEND_NB - 1, FLAGS, "mode" }, + { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, BLEND_NB - 1, FLAGS, "mode" }, + { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, BLEND_NB - 1, FLAGS, "mode" }, + { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, BLEND_NB - 1, FLAGS, "mode" }, + { "normal", "", 0, AV_OPT_TYPE_CONST, { .i64 = BLEND_NORMAL }, 0, 0, FLAGS, "mode" }, + + { "c0_opacity", "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS }, + { "c1_opacity", "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS }, + { "c2_opacity", "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS }, + { "c3_opacity", "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS }, + { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, { .dbl = 1 }, 0, 1, FLAGS }, + + { NULL } +}; + +AVFILTER_DEFINE_CLASS(blend_vulkan); + +static const AVFilterPad blend_vulkan_inputs[] = { + { + .name = "top", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = &ff_vk_filter_config_input, + }, + { + .name = "bottom", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = &ff_vk_filter_config_input, + }, +}; + + +static const AVFilterPad blend_vulkan_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = &config_props_output, + } +}; + +const AVFilter ff_vf_blend_vulkan = { + .name = "blend_vulkan", + .description = NULL_IF_CONFIG_SMALL("Blend two video frames in Vulkan"), + .priv_size = sizeof(BlendVulkanContext), + .init = &init, + .uninit = &uninit, + .activate = &activate, + FILTER_INPUTS(blend_vulkan_inputs), + FILTER_OUTPUTS(blend_vulkan_outputs), + FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN), + .priv_class = &blend_vulkan_class, + .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, + .process_command = &process_command, +}; From patchwork Sun Jan 2 14:51:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Jianhua" X-Patchwork-Id: 33015 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp15456146iog; Sun, 2 Jan 2022 06:52:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJweqvS23dEh2u0OIRn9DTCViWkQwwUnMmLvGLvqOYkygCPdRMj5tUi70LTqkCT8m2wlICkt X-Received: by 2002:a05:6402:50ca:: with SMTP id h10mr31112824edb.331.1641135170705; Sun, 02 Jan 2022 06:52:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641135170; cv=none; d=google.com; s=arc-20160816; b=yG/am3P6YAhvyhB7Lh4tNDfj7ItP8HOgbO4gOMgfQloRhaoSIbjZkOlzKAfuHnNWcr BpkppRrwovYc6VrfPBy7PNMwrSQXm4O5le3f2VlzNQaFsO8kVaeg2OwDV30At6lHn7BH qrZJbbITheGUsAnAgI8lE6aJD7pB3LHd7Afp16r0pXWkWNk6zoIRpO6X6UasbxwnSJy3 OVh3Aiqv6Ps7sUoitXEzjhawhS78TQuFbA+J0LSTbUoUs8mg+N7tZyNIvqdHr/r77dij CX2Q/0sN69L9IjbQY2Dfp7f7BlMGGc6hSr5BVkTOd7rx5yxDgb4WzsySZP/iHR/ctAUj 5tEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=D83h1KTm4aMQzFAJAVXwRPL5ETGt4FCghf7arfKrIE0=; b=l4gwQUxXOr16eZv6CQCRzbCtclCAa9aRN9T4P3yq/vsTz9iIcSVYxBNm4j0ORgFbp/ /hAD6N+B8IE5C7Og4xb+f7QQxmKYqk2sGtvhYbfx+83kC0142khBuVkQzvULpo2URREA jQZbQ7Fn1mH7X8iiscNmucBgi9R8S2Fpx8LSmo5UfU9FwJ7EcRvP4xtiF24obNJPyVU1 EEo3xO9zKxEWZIefPe2glZ+IGNQH0v6gJ82om4vPEZc4k6aoLluTWUxMHZU5aojZaO88 9DaaPokkDEZEku7ckphSMj6u4xftmPSvCBLbJ1V3Vzca3MFS2EtaWycZ5rQdYKKnpHGH 6i1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=JCbbaP+V; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cq4si16027460edb.52.2022.01.02.06.52.50; Sun, 02 Jan 2022 06:52:50 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=JCbbaP+V; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CED4768B178; Sun, 2 Jan 2022 16:52:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37DBD68B16F for ; Sun, 2 Jan 2022 16:52:11 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641135136; x=1672671136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tWZJ7PgKT3cYAbas2CjemCgv5HqU94xSL1MoB+/ksqk=; b=JCbbaP+VS5MkRnGXkxRhjQ7/wOIzPNBa9omzZ4BjsV1ogXtLnF67diMw 6zbt8xrRMvHluA9vmb854ZlsA2HcQ0BO36oJUkKndabh+IoeSddkAmPrD wEplFyVUJtXXR031Ug6yuMI2DfJkyZU09jbDIzufw7sSccf2Vg+jYGPXC jWd9pSuQW1FLp8otRU/8BYE5e+oXDW18+30vtC/weJgFD7if2se+iDZyK TMHVBLGVHwxO2fzwVMJB7gMKqyQxWf3qKPDby9034IF5tU8p8jySyJqHq crgpMYUbMaEdinHta0rUBPByrCVgu63GUTWmK/LAppnFAmuPL/ubbdB4Q Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10214"; a="221966003" X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="221966003" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2022 06:52:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,256,1635231600"; d="scan'208";a="667176325" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga001.fm.intel.com with ESMTP; 02 Jan 2022 06:52:05 -0800 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jan 2022 22:51:42 +0800 Message-Id: <20220102145142.4083918-5-jianhua.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220102145142.4083918-1-jianhua.wu@intel.com> References: <20220102145142.4083918-1-jianhua.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avfilter/vf_blend: fix un-checked potential memory allocation failure 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: Wu Jianhua Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cY95R70j84UG Signed-off-by: Wu Jianhua --- libavfilter/vf_blend.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c index b6f3c4fed3..2d433e439f 100644 --- a/libavfilter/vf_blend.c +++ b/libavfilter/vf_blend.c @@ -279,7 +279,11 @@ static AVFrame *blend_frame(AVFilterContext *ctx, AVFrame *top_buf, dst_buf = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!dst_buf) return top_buf; - av_frame_copy_props(dst_buf, top_buf); + + if (av_frame_copy_props(dst_buf, top_buf) < 0) { + av_frame_free(&dst_buf); + return top_buf; + } for (plane = 0; plane < s->nb_planes; plane++) { int hsub = plane == 1 || plane == 2 ? s->hsub : 0;