From patchwork Thu Nov 4 04:18:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31288 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:a610:0:0:0:0:0 with SMTP id q16csp72478ioi; Wed, 3 Nov 2021 21:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyi31ixRyCodwdjjqq5eVRbm0LSpUvOEzCAzQ75+UEiWrlI/an1kskrTFREVxYUSe3hBt+n X-Received: by 2002:a17:906:3755:: with SMTP id e21mr4655579ejc.335.1635999546580; Wed, 03 Nov 2021 21:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635999546; cv=none; d=google.com; s=arc-20160816; b=ouBGHPvePwNdWB64+3ZjoPSGtEE7FYM/+AyDGGAxaoREW1Cw11ya/j862nq2KvYqoI VDsYjKaO23uCZ9efIAWNKn8IndiZCkernsCHUZvIuKykudjtG8GAizoNCWC6efnfWbW8 U+ar29paK9J0IBCJpQWcZFwSGPvwiKd44yOYdyzrkjanXjrPc0b73WFWXRUgDiPqQ1VH hwCw61nIw4NkH3wm5I+SVYWQ838KMc5FDnloH+fT08Ag7UQvbihEXEN4/z/oQ0yZsTOp xVSd+LRRWlJw4J/D4XzB94+47Oh+ftFI8awG7sEsjTNWbafGIMyRx58al5Lawm47EPNH oheg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=AVbx9FZXZYH1khYKmoPjlllIdXOUdQfMUhCr61EXy7M=; b=EDUuGBcVEPC0DstFQTX/Rsa3XBw3RacZTEr9LfEk89rqshTSlDNnaS9HXZOlMmXfW8 nKlfmcKE2m7hfKic0m0vuHv1nciGvURKcqF+7J1qaWoSrycoxYjqkDM9Sb9RjQYDILMB lJRq6QOViWxpeJ+zDHGijpYNLtQpwLqGosP8xKt2DeHnBOvNK1K8VZNtzXey71dbOH5y EyTUVhHnuq4kPU1g3dWklN/PuAI70+m1kn3qkoX0mNdNlRbJ7YmednUl7BAyDYLTXgst jVs/8GuWU2gcLelhVBfugK0Jgeb1SuRgWQ9/ql+6UCOYwZAealI1kCmXSeMqOzxuO1mw OWoQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a18si6125013ejd.620.2021.11.03.21.19.05; Wed, 03 Nov 2021 21:19:06 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A36268AC6D; Thu, 4 Nov 2021 06:19:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6E689689BD7 for ; Thu, 4 Nov 2021 06:18:53 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10157"; a="231489185" X-IronPort-AV: E=Sophos;i="5.87,207,1631602800"; d="scan'208";a="231489185" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2021 21:18:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,207,1631602800"; d="scan'208";a="578438735" Received: from otc-skl-e5-server.sh.intel.com ([10.239.43.106]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2021 21:18:48 -0700 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Nov 2021 12:18:39 +0800 Message-Id: <20211104041841.95318-1-jianhua.wu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH v2 1/3] avfilter/x86/vf_exposure: add x86 SIMD optimization 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aYQbKO4G57gE Performance data(Less is better): exposure_c: 857394 exposure_sse: 327589 Signed-off-by: Wu Jianhua --- libavfilter/exposure.h | 36 +++++++++++++++++++ libavfilter/vf_exposure.c | 36 +++++++++---------- libavfilter/x86/Makefile | 2 ++ libavfilter/x86/vf_exposure.asm | 55 ++++++++++++++++++++++++++++++ libavfilter/x86/vf_exposure_init.c | 36 +++++++++++++++++++ 5 files changed, 147 insertions(+), 18 deletions(-) create mode 100644 libavfilter/exposure.h create mode 100644 libavfilter/x86/vf_exposure.asm create mode 100644 libavfilter/x86/vf_exposure_init.c diff --git a/libavfilter/exposure.h b/libavfilter/exposure.h new file mode 100644 index 0000000000..e76a517826 --- /dev/null +++ b/libavfilter/exposure.h @@ -0,0 +1,36 @@ +/* + * 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 + */ + +#ifndef AVFILTER_EXPOSURE_H +#define AVFILTER_EXPOSURE_H +#include "avfilter.h" + +typedef struct ExposureContext { + const AVClass *class; + + float exposure; + float black; + float scale; + + void (*exposure_func)(float *ptr, int length, float black, float scale); +} ExposureContext; + +void ff_exposure_init(ExposureContext *s); +void ff_exposure_init_x86(ExposureContext *s); + +#endif diff --git a/libavfilter/vf_exposure.c b/libavfilter/vf_exposure.c index 108fba7930..045ae710d3 100644 --- a/libavfilter/vf_exposure.c +++ b/libavfilter/vf_exposure.c @@ -26,23 +26,20 @@ #include "formats.h" #include "internal.h" #include "video.h" +#include "exposure.h" -typedef struct ExposureContext { - const AVClass *class; - - float exposure; - float black; +static void exposure_c(float *ptr, int length, float black, float scale) +{ + int i; - float scale; - int (*do_slice)(AVFilterContext *s, void *arg, - int jobnr, int nb_jobs); -} ExposureContext; + for (i = 0; i < length; i++) + ptr[i] = (ptr[i] - black) * scale; +} static int exposure_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { ExposureContext *s = ctx->priv; AVFrame *frame = arg; - const int width = frame->width; const int height = frame->height; const int slice_start = (height * jobnr) / nb_jobs; const int slice_end = (height * (jobnr + 1)) / nb_jobs; @@ -52,24 +49,27 @@ static int exposure_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_job for (int p = 0; p < 3; p++) { const int linesize = frame->linesize[p] / 4; float *ptr = (float *)frame->data[p] + slice_start * linesize; - for (int y = slice_start; y < slice_end; y++) { - for (int x = 0; x < width; x++) - ptr[x] = (ptr[x] - black) * scale; - - ptr += linesize; - } + s->exposure_func(ptr, linesize * (slice_end - slice_start), black, scale); } return 0; } +void ff_exposure_init(ExposureContext *s) +{ + s->exposure_func = exposure_c; + + if (ARCH_X86) + ff_exposure_init_x86(s); +} + static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; ExposureContext *s = ctx->priv; s->scale = 1.f / (exp2f(-s->exposure) - s->black); - ff_filter_execute(ctx, s->do_slice, frame, NULL, + ff_filter_execute(ctx, exposure_slice, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); return ff_filter_frame(ctx->outputs[0], frame); @@ -80,7 +80,7 @@ static av_cold int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; ExposureContext *s = ctx->priv; - s->do_slice = exposure_slice; + ff_exposure_init(s); return 0; } diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile index a29941eaeb..e84a388aa5 100644 --- a/libavfilter/x86/Makefile +++ b/libavfilter/x86/Makefile @@ -8,6 +8,7 @@ OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif_init.o OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp_init.o OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_convolution_init.o OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq_init.o +OBJS-$(CONFIG_EXPOSURE_FILTER) += x86/vf_exposure_init.o OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp_init.o OBJS-$(CONFIG_GBLUR_FILTER) += x86/vf_gblur_init.o OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o @@ -49,6 +50,7 @@ X86ASM-OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif.o X86ASM-OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp.o X86ASM-OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_convolution.o X86ASM-OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o +X86ASM-OBJS-$(CONFIG_EXPOSURE_FILTER) += x86/vf_exposure.o X86ASM-OBJS-$(CONFIG_FRAMERATE_FILTER) += x86/vf_framerate.o X86ASM-OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o X86ASM-OBJS-$(CONFIG_GBLUR_FILTER) += x86/vf_gblur.o diff --git a/libavfilter/x86/vf_exposure.asm b/libavfilter/x86/vf_exposure.asm new file mode 100644 index 0000000000..3351c6fb3b --- /dev/null +++ b/libavfilter/x86/vf_exposure.asm @@ -0,0 +1,55 @@ +;***************************************************************************** +;* x86-optimized functions for exposure filter +;* +;* 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/x86/x86util.asm" + +SECTION .text + +;******************************************************************************* +; void ff_exposure(float *ptr, int length, float black, float scale); +;******************************************************************************* +%macro EXPOSURE 0 +cglobal exposure, 2, 2, 4, ptr, length, black, scale + movsxdifnidn lengthq, lengthd +%if WIN64 + VBROADCASTSS m0, xmm2 + VBROADCASTSS m1, xmm3 +%else + VBROADCASTSS m0, xmm0 + VBROADCASTSS m1, xmm1 +%endif + +.loop: + movu m2, [ptrq] + subps m2, m2, m0 + mulps m2, m2, m1 + movu [ptrq], m2 + add ptrq, mmsize + sub lengthq, mmsize/4 + + jg .loop + + RET +%endmacro + +%if ARCH_X86_64 +INIT_XMM sse +EXPOSURE +%endif diff --git a/libavfilter/x86/vf_exposure_init.c b/libavfilter/x86/vf_exposure_init.c new file mode 100644 index 0000000000..de1b360f6c --- /dev/null +++ b/libavfilter/x86/vf_exposure_init.c @@ -0,0 +1,36 @@ +/* + * 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 "config.h" + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/x86/cpu.h" +#include "libavfilter/exposure.h" + +void ff_exposure_sse(float *ptr, int length, float black, float scale); + +av_cold void ff_exposure_init_x86(ExposureContext *s) +{ + int cpu_flags = av_get_cpu_flags(); + +#if ARCH_X86_64 + if (EXTERNAL_SSE(cpu_flags)) + s->exposure_func = ff_exposure_sse; +#endif +} From patchwork Thu Nov 4 04:18:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31287 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:a610:0:0:0:0:0 with SMTP id q16csp72646ioi; Wed, 3 Nov 2021 21:19:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/JomuBcfs+hDXz4hSyizQZ5CLcv6wmb+wfNjMSLfm6lF35YlkUg188eQ2J4RTrcj2UP8l X-Received: by 2002:a17:907:2627:: with SMTP id aq7mr51141735ejc.483.1635999558525; Wed, 03 Nov 2021 21:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635999558; cv=none; d=google.com; s=arc-20160816; b=p+CogoeinPw+w+R0xg4Y4JI1aiTGX/OPu5XPvd4YWNloYXqJXn6w8UfFEChbqGzASb +tr76hq7eLz+I0/bOQ6zw4wDHe1glMbWyICvXbW1z7MRnh9Lt9NE3Qt7HQZ8kSylQ+B8 dVhtrMBJgoA2SPjAj8p6eGzWjLePiGB2jnQX0eh5m2pjSsN9mDM32z4OKxYBf7uXIoWt /1trDEhTTd0kyvNlgP3jzdTkGcTC+ZEajjijdBukiKB+piV5vc90lq96QGcVwvjiyLok QHWNB4hxQlsODIIQkzvHa/c6LlfRYKkv6aMKizCw3FlUJOe3WKlx7xbFeqDRk22MkshK c9gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=zaGnCx+krjGtGD6GYKDD2p1O04B5T/SNxYL1qtfz+fk=; b=IxiMK0mxlW56YlhtyTmFpb6Xsg4Vc640Bkk2x1OAzwlPE5G08B4hUIKI4oOzK9rex1 14FzHCplDBIYdwu4U5ZWTYSar05AHniXxzO1rVO88iGCQBUsN6c9brl4Kqwsvy0DfuUr 4Lo/JiiCqaKs7ZwzCEMJERZEW5rQ2gboRU6HOLBvL1LtEzvPucMxtxT2f+CFXJn4V2pe PoflS0PQ5IEr1Dw3sk7E8fx+sFHP7ciQg4ZI+H+EkLjgNCLNWtBQQ3pmORXye3mAL6lx UNDD3dwmUcJRCJMo5WysNNNE5Fke88PgZ5ZvPjCBPZ5vlPj81w/C8YF3TbfpBKHXSe9Q FHqg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ds3si9214562ejc.113.2021.11.03.21.19.18; Wed, 03 Nov 2021 21:19:18 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F80968AC65; Thu, 4 Nov 2021 06:19:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5DC4268AC6A for ; Thu, 4 Nov 2021 06:18:59 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10157"; a="231489187" X-IronPort-AV: E=Sophos;i="5.87,207,1631602800"; d="scan'208";a="231489187" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2021 21:18:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,207,1631602800"; d="scan'208";a="578438739" Received: from otc-skl-e5-server.sh.intel.com ([10.239.43.106]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2021 21:18:50 -0700 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Nov 2021 12:18:40 +0800 Message-Id: <20211104041841.95318-2-jianhua.wu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211104041841.95318-1-jianhua.wu@intel.com> References: <20211104041841.95318-1-jianhua.wu@intel.com> Subject: [FFmpeg-devel] [PATCH v2 2/3] avfilter/x86/vf_exposure: add ff_exposure_avx2 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MAN5OFHt5IYq Performance data(Less is better): exposure_sse: 500491 exposure_avx2: 449122 Signed-off-by: Wu Jianhua --- libavfilter/x86/vf_exposure.asm | 15 +++++++++++++++ libavfilter/x86/vf_exposure_init.c | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/libavfilter/x86/vf_exposure.asm b/libavfilter/x86/vf_exposure.asm index 3351c6fb3b..f271167805 100644 --- a/libavfilter/x86/vf_exposure.asm +++ b/libavfilter/x86/vf_exposure.asm @@ -36,11 +36,21 @@ cglobal exposure, 2, 2, 4, ptr, length, black, scale VBROADCASTSS m1, xmm1 %endif +%if cpuflag(fma3) || cpuflag(fma4) + mulps m0, m0, m1 ; black * scale +%endif + .loop: +%if cpuflag(fma3) || cpuflag(fma4) + mova m2, m0 + vfmsub231ps m2, m1, [ptrq] + movu [ptrq], m2 +%else movu m2, [ptrq] subps m2, m2, m0 mulps m2, m2, m1 movu [ptrq], m2 +%endif add ptrq, mmsize sub lengthq, mmsize/4 @@ -52,4 +62,9 @@ cglobal exposure, 2, 2, 4, ptr, length, black, scale %if ARCH_X86_64 INIT_XMM sse EXPOSURE + +%if HAVE_AVX2_EXTERNAL +INIT_YMM avx2 +EXPOSURE +%endif %endif diff --git a/libavfilter/x86/vf_exposure_init.c b/libavfilter/x86/vf_exposure_init.c index de1b360f6c..80dae6164e 100644 --- a/libavfilter/x86/vf_exposure_init.c +++ b/libavfilter/x86/vf_exposure_init.c @@ -24,6 +24,7 @@ #include "libavfilter/exposure.h" void ff_exposure_sse(float *ptr, int length, float black, float scale); +void ff_exposure_avx2(float *ptr, int length, float black, float scale); av_cold void ff_exposure_init_x86(ExposureContext *s) { @@ -32,5 +33,10 @@ av_cold void ff_exposure_init_x86(ExposureContext *s) #if ARCH_X86_64 if (EXTERNAL_SSE(cpu_flags)) s->exposure_func = ff_exposure_sse; + +#if HAVE_AVX2_EXTERNAL + if (EXTERNAL_AVX2_FAST(cpu_flags)) + s->exposure_func = ff_exposure_avx2; +#endif #endif } From patchwork Thu Nov 4 04:18:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Jianhua X-Patchwork-Id: 31286 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:a610:0:0:0:0:0 with SMTP id q16csp72765ioi; Wed, 3 Nov 2021 21:19:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8EoPnJt5MgsLx7X8qLDBzqWX1xtd0+grpQYnCBnc/jE7OkE2BotTS1HlC0mRzOPEXKCgP X-Received: by 2002:a05:6402:b04:: with SMTP id bm4mr53280927edb.173.1635999569701; Wed, 03 Nov 2021 21:19:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635999569; cv=none; d=google.com; s=arc-20160816; b=D5gD5Qs6rbRvf+2Ayy3R3TDU7hBmGx6+KmNO3LPLnGq+s/WnfAqbjftEPG8ur6e9Lm ksyIzi3QrHwV0+2SrJsFN/xCvTOPIV8P1ffO76OI3z0YRvXgLfOl275tC4hDw8FwMSeG VkEv3MvwaIsa6ZPx/NVWWYUk3QFT9Ra27l7H7uehOsZLse0jV1Hx42dHyGYL2VCwBLia 4jsqSqYxwKMg+FyLZs+5mRfwXfqRhgJ5KiX2pwwecxOvbljQ3XBCQVaNghg3Y/0IFyBU CzejuIqGf1eO7wXqHFz3/ZkvngXcliZA11YxeYNOpLL4e7cdT/xSLV83w2ArOdms/G6O 17yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=37EBpfoMGOcR/oYlTpUMeM+eQGoWTsYiKJ6mJtFUx3c=; b=uWvjOXXTUH+3DOQSKBa+FV2FwBHOLjc4J8AMYMAE4gx/UgR3GbDCUlQs+b8QDj3prb 6VMhGzSBaducyLjYnV9snqxkb1DZ5dJLfaPKktc6D++i7hKmG0p51KsaiPPozi8SwavE 5I51gW4SuBe0QPHl3I1T8HFA9/h2ipMH9tkB9U4W1OwssMM//775rC/NQy/U1xUxhMak 0/ITqOgaJsWs6AF3ggtKwQc6XhA1eZeQ9RT50ViXozTNLf+jjYHkfdiHsdmiHd6LJBnj UEsB9FH7s2MwuVSAGxZLuNdVR4sRGJlYghCBkO5nxAC5NQXk+J5nbyZFrdG/qQDlYJPH 3zlg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t15si5262515ejx.503.2021.11.03.21.19.28; Wed, 03 Nov 2021 21:19:29 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A475068ACE5; Thu, 4 Nov 2021 06:19:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A944468AC65 for ; Thu, 4 Nov 2021 06:19:00 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10157"; a="231489189" X-IronPort-AV: E=Sophos;i="5.87,207,1631602800"; d="scan'208";a="231489189" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2021 21:18:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,207,1631602800"; d="scan'208";a="578438743" Received: from otc-skl-e5-server.sh.intel.com ([10.239.43.106]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2021 21:18:51 -0700 From: Wu Jianhua To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Nov 2021 12:18:41 +0800 Message-Id: <20211104041841.95318-3-jianhua.wu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211104041841.95318-1-jianhua.wu@intel.com> References: <20211104041841.95318-1-jianhua.wu@intel.com> Subject: [FFmpeg-devel] [PATCH v2 3/3] tests/checkasm: add check for vf_exposure 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QDbJab0r8LkK Signed-off-by: Wu Jianhua --- tests/checkasm/Makefile | 1 + tests/checkasm/checkasm.c | 3 ++ tests/checkasm/checkasm.h | 1 + tests/checkasm/vf_exposure.c | 62 ++++++++++++++++++++++++++++++++++++ tests/fate/checkasm.mak | 1 + 5 files changed, 68 insertions(+) create mode 100644 tests/checkasm/vf_exposure.c diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index 4ef5fa87da..7b86ffca6b 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -37,6 +37,7 @@ AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += af_afir.o AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o AVFILTEROBJS-$(CONFIG_EQ_FILTER) += vf_eq.o +AVFILTEROBJS-$(CONFIG_EXPOSURE_FILTER) += vf_exposure.o AVFILTEROBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o AVFILTEROBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER) += vf_threshold.o diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index b1353f7cbe..50961d9961 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -169,6 +169,9 @@ static const struct { #if CONFIG_EQ_FILTER { "vf_eq", checkasm_check_vf_eq }, #endif + #if CONFIG_EXPOSURE_FILTER + { "vf_exposure", checkasm_check_vf_exposure }, + #endif #if CONFIG_GBLUR_FILTER { "vf_gblur", checkasm_check_vf_gblur }, #endif diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 68b0697d3e..b402894ad3 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -78,6 +78,7 @@ void checkasm_check_utvideodsp(void); void checkasm_check_v210dec(void); void checkasm_check_v210enc(void); void checkasm_check_vf_eq(void); +void checkasm_check_vf_exposure(void); void checkasm_check_vf_gblur(void); void checkasm_check_vf_hflip(void); void checkasm_check_vf_threshold(void); diff --git a/tests/checkasm/vf_exposure.c b/tests/checkasm/vf_exposure.c new file mode 100644 index 0000000000..14f0efed5f --- /dev/null +++ b/tests/checkasm/vf_exposure.c @@ -0,0 +1,62 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 +#include +#include "checkasm.h" +#include "libavfilter/exposure.h" + +#define PIXELS 256 +#define BUF_SIZE (PIXELS * 4) + +#define randomize_buffers(buf, size) \ + do { \ + int j; \ + float *tmp_buf = (float *)buf; \ + for (j = 0; j < size; j++) \ + tmp_buf[j] = (float)(rnd() & 0xFF); \ + } while (0) + +void checkasm_check_vf_exposure(void) +{ + float *dst_ref = av_malloc(BUF_SIZE); + float *dst_new = av_malloc(BUF_SIZE); + ExposureContext s; + + s.exposure = 0.5f; + s.black = 0.1f; + s.scale = 1.f / (exp2f(-s.exposure) - s.black); + + randomize_buffers(dst_ref, PIXELS); + memcpy(dst_new, dst_ref, BUF_SIZE); + + ff_exposure_init(&s); + + if (check_func(s.exposure_func, "exposure")) { + declare_func(void, float *dst, int length, float black, float scale); + call_ref(dst_ref, PIXELS, s.black, s.scale); + call_new(dst_new, PIXELS, s.black, s.scale); + if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) + fail(); + bench_new(dst_new, PIXELS, s.black, s.scale); + } + report("exposure"); + + av_freep(&dst_ref); + av_freep(&dst_new); +} diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak index 6e7edbe655..4d4cd6cc88 100644 --- a/tests/fate/checkasm.mak +++ b/tests/fate/checkasm.mak @@ -34,6 +34,7 @@ FATE_CHECKASM = fate-checkasm-aacpsdsp \ fate-checkasm-vf_blend \ fate-checkasm-vf_colorspace \ fate-checkasm-vf_eq \ + fate-checkasm-vf_exposure \ fate-checkasm-vf_gblur \ fate-checkasm-vf_hflip \ fate-checkasm-vf_nlmeans \