From patchwork Mon May 6 04:59:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruiling Song X-Patchwork-Id: 13002 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4041B44750F for ; Mon, 6 May 2019 07:00:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24ECA68ABF7; Mon, 6 May 2019 07:00:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D288768ABC6 for ; Mon, 6 May 2019 07:00:21 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 May 2019 21:00:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,435,1549958400"; d="scan'208";a="148888023" Received: from ruiling-nuc.sh.intel.com ([10.239.158.179]) by fmsmga007.fm.intel.com with ESMTP; 05 May 2019 21:00:18 -0700 From: Ruiling Song To: ffmpeg-devel@ffmpeg.org Date: Mon, 6 May 2019 12:59:02 +0800 Message-Id: <20190506045902.7128-1-ruiling.song@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] lavfi/gblur: doing several columns at the same time X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Ruiling Song MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Instead of doing each column one by one, doing several columns together gives about 30% better performance. Signed-off-by: Ruiling Song --- below is some of performance numbers(fps) on my i7-6770HQ (decode + gblur): resolution: 480p | 720p | 1080p | 4k without patch: 393 | 146 | 71 | 14 with patch: 502 | 184 | 95 | 18 libavfilter/vf_gblur.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c index 5d05cac44c..9f07705ec4 100644 --- a/libavfilter/vf_gblur.c +++ b/libavfilter/vf_gblur.c @@ -108,6 +108,40 @@ static int filter_horizontally(AVFilterContext *ctx, void *arg, int jobnr, int n return 0; } +static void do_vertical_columns(float *buffer, int width, int height, + int column_begin, int column_end, int steps, + float nu, float boundaryscale, int column_step) +{ + const int numpixels = width * height; + int i, x, k, step; + float *ptr; + for (x = column_begin; x < column_end;) { + for (step = 0; step < steps; step++) { + ptr = buffer + x; + for (k = 0; k < column_step; k++) { + ptr[k] *= boundaryscale; + } + /* Filter downwards */ + for (i = width; i < numpixels; i += width) { + for (k = 0; k < column_step; k++) { + ptr[i + k] += nu * ptr[i - width + k]; + } + } + i = numpixels - width; + + for (k = 0; k < column_step; k++) + ptr[i + k] *= boundaryscale; + + /* Filter upwards */ + for (; i > 0; i -= width) { + for (k = 0; k < column_step; k++) + ptr[i - width + k] += nu * ptr[i + k]; + } + } + x += column_step; + } +} + static int filter_vertically(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { GBlurContext *s = ctx->priv; @@ -117,31 +151,19 @@ static int filter_vertically(AVFilterContext *ctx, void *arg, int jobnr, int nb_ const int slice_start = (width * jobnr ) / nb_jobs; const int slice_end = (width * (jobnr+1)) / nb_jobs; const float boundaryscale = s->boundaryscaleV; - const int numpixels = width * height; const int steps = s->steps; const float nu = s->nuV; float *buffer = s->buffer; - int i, x, step; - float *ptr; - - /* Filter vertically along each column */ - for (x = slice_start; x < slice_end; x++) { - for (step = 0; step < steps; step++) { - ptr = buffer + x; - ptr[0] *= boundaryscale; - - /* Filter downwards */ - for (i = width; i < numpixels; i += width) - ptr[i] += nu * ptr[i - width]; - - ptr[i = numpixels - width] *= boundaryscale; + int aligned_end; - /* Filter upwards */ - for (; i > 0; i -= width) - ptr[i - width] += nu * ptr[i]; - } - } + aligned_end = slice_start + (((slice_end - slice_start) >> 3) << 3); + /* Filter vertically along columns (process 8 columns in each step) */ + do_vertical_columns(buffer, width, height, slice_start, aligned_end, + steps, nu, boundaryscale, 8); + // Filter un-aligned columns one by one + do_vertical_columns(buffer, width, height, aligned_end, slice_end, + steps, nu, boundaryscale, 1); return 0; }