From patchwork Mon Apr 30 16:17:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 8700 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp3666039jad; Mon, 30 Apr 2018 09:26:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpup4XwrUwRlvXdfafqo9qOd5M2Z1Q7pnt4J7Hjfn4BS0G6eBFjm+FElwJrW5sJQ6r+II5z X-Received: by 2002:adf:b004:: with SMTP id f4-v6mr9791891wra.75.1525105559975; Mon, 30 Apr 2018 09:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525105559; cv=none; d=google.com; s=arc-20160816; b=mb3w+JcIsmxDJURekbq72t5iPUoTHqudc2L13Ajc4lGlnopDUSxpZewqBszSy9T37i njW2a2a4dqsafRjIzEjkmBx5RQCN364Qp0W4sVC7bSnxyHOcV7G8jNk+82VXHvcpUTlK KepuzB1iX72pblb+VsDDtFcrPMLcLc8Xh/z8eynnim6JUnwqOtfgbptxAGjstGapLTG7 Lsacaivl7fmeKPIKxO7SnOq6punsiQzcd/SdxBY79gt3u3+x7VcNo4MLvHqEroimAj9a PHvA4c4iEkUZpbSDw/ibiuWB6Zn+7WhQE7+ZCG2DeJXunIlsuhkrrnnFTUdkD1US6seT liqQ== 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:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=EluCKWjLwob0JhTq2bmDXu6tv1eRLCBGoQJ61q0gzEY=; b=uDwlAwNwFYpg4xwnoeqWshOj475ZnLxeSjQNCWf9AyP0eRgFJ9JZqRQ23bITtd69YF KJL2TwIE3RNCQcrM7uiMK5C//FY2ex3nFXPNW7u9Dyw2hHmUixRp0ZQtscBkIgLvcQQm RfktPOfFEn21NXiT1796LIHByprRIRv3dlUv88MGD8Elfi8doVjolkxLXU4Ij1InaiQY IZijh7DsnINwezUitjNI4k17o+jupMteD35XTO64wberx9y6vhZTAbBrdU8UEarZSAo0 Lo4kqMH38ch8bUvoxyLXRjCjCMdY6dUsFP0lT2ayVAOM7xBcrFMoKApeoTPIQM16V8pB E+Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pC/kkD+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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 30-v6si6272377wra.324.2018.04.30.09.25.59; Mon, 30 Apr 2018 09:25:59 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pC/kkD+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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1751D68A369; Mon, 30 Apr 2018 19:25:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1B2B968A355 for ; Mon, 30 Apr 2018 19:25:20 +0300 (EEST) Received: by mail-wm0-f65.google.com with SMTP id f8so4658687wmc.4 for ; Mon, 30 Apr 2018 09:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=FVE6unB6Sk52WZPLel5X6JzlycE/Lf8S8cODkIA8aP8=; b=pC/kkD+VWsBJ/eqEmRnWVcBDR75N3zgX//3aDdHFc/tzeORVG+cuXjIb0TYziEO0pQ MW7F/6KsUtagxS7KDJh+pf+uUDc7S8CLs6F/Ol4sGUAPZf2pT24+BSVa8r7UVEVVdmQw 3/4l5J55hny5m3MIlMpc0l4mnGczxQgqyujXczQKD3KjkEQaQbkfj4OPMh94JwVD89UL MwqzAn6rNP9W8gJVeEu5Kl8Bqb/Zg74keoUJPt4mnqE3EF0VfR0OKeXgZO2OsMzgTEAK sXES3D49h5Jlo3rHIA23mYPItDkxEw9/VXUuQPVBYwDncjtBt3RwCzKKNK3puYk618qq 3h4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=FVE6unB6Sk52WZPLel5X6JzlycE/Lf8S8cODkIA8aP8=; b=ByVvyPmqKOjZvCLkQtcrZ2QGxQEbDRMe+Lz3j7VBulN8MC2l0MsB9uw6/4t9hdJBV7 r1qVUo4NIkQ9V+LN+NpAoCOTM98VdCfOdYSwaC2OPzI0toWhfqfYsBdloQz4T2bjL/SD TMbLhgJTFgyPAqtQGre9kxgP53rordaEumM1uyaSJ7Q+WFCIpytoc5Oea2qfSKCoPCgc 2i2vZCf1J+uslHcqPulC7PUwjUN25dJkyFcE0ty/0QEGeF3OTfdqNHztI1zn+x8BS4l2 Y6COgQRjwRRx+DHasJZ+j0VGozF/YPDy1PJcyQxwWWvJoAo0X4gcv2wIE3IngaL6+FLv FdqQ== X-Gm-Message-State: ALQs6tBSENQW2q4vl0p0m4yOFAWv6wNd1Nd3DQDyZ0Rfh5o8+kJfQGya KIDxL7qFr36bgsXAg+xm9AUysw== X-Received: by 10.28.31.71 with SMTP id f68mr7307840wmf.4.1525105102569; Mon, 30 Apr 2018 09:18:22 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id 109-v6sm7833514wra.32.2018.04.30.09.18.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 09:18:22 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Apr 2018 18:17:40 +0200 Message-Id: <20180430161740.3688-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_overlay: add x86 SIMD for yuv444 format when main stream has no alpha 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavfilter/vf_overlay.c | 76 ++++++++----------------------- libavfilter/vf_overlay.h | 84 ++++++++++++++++++++++++++++++++++ libavfilter/x86/Makefile | 2 + libavfilter/x86/vf_overlay.asm | 94 +++++++++++++++++++++++++++++++++++++++ libavfilter/x86/vf_overlay_init.c | 39 ++++++++++++++++ 5 files changed, 238 insertions(+), 57 deletions(-) create mode 100644 libavfilter/vf_overlay.h create mode 100644 libavfilter/x86/vf_overlay.asm create mode 100644 libavfilter/x86/vf_overlay_init.c diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index 8c1895cca4..81522d31a4 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -39,6 +39,7 @@ #include "drawutils.h" #include "framesync.h" #include "video.h" +#include "vf_overlay.h" typedef struct ThreadData { AVFrame *dst, *src; @@ -59,21 +60,6 @@ static const char *const var_names[] = { NULL }; -enum var_name { - VAR_MAIN_W, VAR_MW, - VAR_MAIN_H, VAR_MH, - VAR_OVERLAY_W, VAR_OW, - VAR_OVERLAY_H, VAR_OH, - VAR_HSUB, - VAR_VSUB, - VAR_X, - VAR_Y, - VAR_N, - VAR_POS, - VAR_T, - VAR_VARS_NB -}; - #define MAIN 0 #define OVERLAY 1 @@ -92,45 +78,6 @@ enum EvalMode { EVAL_MODE_NB }; -enum OverlayFormat { - OVERLAY_FORMAT_YUV420, - OVERLAY_FORMAT_YUV422, - OVERLAY_FORMAT_YUV444, - OVERLAY_FORMAT_RGB, - OVERLAY_FORMAT_GBRP, - OVERLAY_FORMAT_AUTO, - OVERLAY_FORMAT_NB -}; - -typedef struct OverlayContext { - const AVClass *class; - int x, y; ///< position of overlaid picture - - uint8_t main_is_packed_rgb; - uint8_t main_rgba_map[4]; - uint8_t main_has_alpha; - uint8_t overlay_is_packed_rgb; - uint8_t overlay_rgba_map[4]; - uint8_t overlay_has_alpha; - int format; ///< OverlayFormat - int alpha_format; - int eval_mode; ///< EvalMode - - FFFrameSync fs; - - int main_pix_step[4]; ///< steps per pixel for each plane of the main output - int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay - int hsub, vsub; ///< chroma subsampling values - const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input - - double var_values[VAR_VARS_NB]; - char *x_expr, *y_expr; - - AVExpr *x_pexpr, *y_pexpr; - - int (*blend_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); -} OverlayContext; - static av_cold void uninit(AVFilterContext *ctx) { OverlayContext *s = ctx->priv; @@ -509,6 +456,7 @@ static av_always_inline void blend_plane(AVFilterContext *ctx, int jobnr, int nb_jobs) { + OverlayContext *octx = ctx->priv; int src_wp = AV_CEIL_RSHIFT(src_w, hsub); int src_hp = AV_CEIL_RSHIFT(src_h, vsub); int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub); @@ -538,8 +486,17 @@ static av_always_inline void blend_plane(AVFilterContext *ctx, s = sp + k; a = ap + (k<blend_row) { + octx->blend_row(d, da, s, a, kmax - k, k, j, src_wp, src_hp); + dp += dst->linesize[dst_plane]; + sp += src->linesize[i]; + ap += (1 << vsub) * src->linesize[3]; + dap += (1 << vsub) * dst->linesize[3]; + continue; + } + for (; k < kmax; k++) { int alpha_v, alpha_h, alpha; // average alpha for color components, improve quality @@ -916,7 +873,7 @@ static int config_input_main(AVFilterLink *inlink) } if (!s->alpha_format) - return 0; + goto end; switch (s->format) { case OVERLAY_FORMAT_YUV420: @@ -960,6 +917,11 @@ static int config_input_main(AVFilterLink *inlink) } break; } + +end: + if (ARCH_X86) + ff_overlay_init_x86(s, s->format, s->alpha_format, s->main_has_alpha); + return 0; } diff --git a/libavfilter/vf_overlay.h b/libavfilter/vf_overlay.h new file mode 100644 index 0000000000..8eb91d9a34 --- /dev/null +++ b/libavfilter/vf_overlay.h @@ -0,0 +1,84 @@ +/* + * 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_OVERLAY_H +#define AVFILTER_OVERLAY_H + +#include "libavutil/eval.h" +#include "libavutil/pixdesc.h" +#include "framesync.h" +#include "avfilter.h" + +enum var_name { + VAR_MAIN_W, VAR_MW, + VAR_MAIN_H, VAR_MH, + VAR_OVERLAY_W, VAR_OW, + VAR_OVERLAY_H, VAR_OH, + VAR_HSUB, + VAR_VSUB, + VAR_X, + VAR_Y, + VAR_N, + VAR_POS, + VAR_T, + VAR_VARS_NB +}; + +enum OverlayFormat { + OVERLAY_FORMAT_YUV420, + OVERLAY_FORMAT_YUV422, + OVERLAY_FORMAT_YUV444, + OVERLAY_FORMAT_RGB, + OVERLAY_FORMAT_GBRP, + OVERLAY_FORMAT_AUTO, + OVERLAY_FORMAT_NB +}; + +typedef struct OverlayContext { + const AVClass *class; + int x, y; ///< position of overlaid picture + + uint8_t main_is_packed_rgb; + uint8_t main_rgba_map[4]; + uint8_t main_has_alpha; + uint8_t overlay_is_packed_rgb; + uint8_t overlay_rgba_map[4]; + uint8_t overlay_has_alpha; + int format; ///< OverlayFormat + int alpha_format; + int eval_mode; ///< EvalMode + + FFFrameSync fs; + + int main_pix_step[4]; ///< steps per pixel for each plane of the main output + int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay + int hsub, vsub; ///< chroma subsampling values + const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input + + double var_values[VAR_VARS_NB]; + char *x_expr, *y_expr; + + AVExpr *x_pexpr, *y_pexpr; + + void (*blend_row)(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a, int w, int x, int y, int src_w, int src_h); + int (*blend_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); +} OverlayContext; + +void ff_overlay_init_x86(OverlayContext *s, int format, int alpha_format, int main_has_alpha); + +#endif /* AVFILTER_OVERLAY_H */ diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile index f60de3b73b..b484c8bd1c 100644 --- a/libavfilter/x86/Makefile +++ b/libavfilter/x86/Makefile @@ -13,6 +13,7 @@ OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_tinterlace_init.o OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter_init.o OBJS-$(CONFIG_MASKEDMERGE_FILTER) += x86/vf_maskedmerge_init.o OBJS-$(CONFIG_NOISE_FILTER) += x86/vf_noise.o +OBJS-$(CONFIG_OVERLAY_FILTER) += x86/vf_overlay_init.o OBJS-$(CONFIG_PP7_FILTER) += x86/vf_pp7_init.o OBJS-$(CONFIG_PSNR_FILTER) += x86/vf_psnr_init.o OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup_init.o @@ -41,6 +42,7 @@ X86ASM-OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet.o X86ASM-OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_interlace.o X86ASM-OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter.o X86ASM-OBJS-$(CONFIG_MASKEDMERGE_FILTER) += x86/vf_maskedmerge.o +X86ASM-OBJS-$(CONFIG_OVERLAY_FILTER) += x86/vf_overlay.o X86ASM-OBJS-$(CONFIG_PP7_FILTER) += x86/vf_pp7.o X86ASM-OBJS-$(CONFIG_PSNR_FILTER) += x86/vf_psnr.o X86ASM-OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup.o diff --git a/libavfilter/x86/vf_overlay.asm b/libavfilter/x86/vf_overlay.asm new file mode 100644 index 0000000000..41f74fe946 --- /dev/null +++ b/libavfilter/x86/vf_overlay.asm @@ -0,0 +1,94 @@ +;***************************************************************************** +;* x86-optimized functions for overlay filter +;* +;* Copyright (C) 2018 Paul B Mahol +;* +;* 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_RODATA + +pd_128: times 4 dd 128 +pd_255: times 4 dd 255 +pd_257: times 4 dd 257 +pb_b2dw: db 0,-1,-1,-1, 1,-1,-1,-1, 2,-1,-1,-1, 3,-1,-1,-1 +pb_dw2b: db 0, 4, 8,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + +SECTION .text + +INIT_XMM sse4 +cglobal overlay_row_yuv444, 9, 14, 5, 0, d, da, s, a, w, x, y, src_w, src_h, r, x, t, u, v + xor xq, xq + movsxdifnidn wq, wd + mov rq, wq + and rq, mmsize/4 - 1 + cmp wq, mmsize/4 + jl .loop1 + pxor m0, m0 + sub wq, rq + .loop0: + movu m1, [dq + xq] + movu m2, [aq + xq] + movu m3, [sq + xq] + + pshufb m1, [pb_b2dw] + pshufb m2, [pb_b2dw] + pshufb m3, [pb_b2dw] + mova m4, [pd_255] + psubd m4, m2 + pmulld m1, m4 + pmulld m3, m2 + paddd m1, m3 + paddd m1, [pd_128] + pmulld m1, [pd_257] + psrad m1, 16 + pshufb m1, [pb_dw2b] + movd [dq+xq], m1 + + add xq, mmsize / 4 + cmp xq, wq + jl .loop0 + + cmp rq, 0 + je .end + add wq, rq + + .loop1: + xor tq, tq + xor uq, uq + xor vq, vq + mov rd, 255 + mov tb, [aq + xq] + neg tb + add rb, tb + mov ub, [sq + xq] + neg tb + imul ud, td + mov vb, [dq + xq] + imul rd, vd + add rd, ud + add rd, 128 + imul rd, 257 + sar rd, 16 + mov [dq + xq], rb + add xq, 1 + cmp xq, wq + jl .loop1 + .end: + RET diff --git a/libavfilter/x86/vf_overlay_init.c b/libavfilter/x86/vf_overlay_init.c new file mode 100644 index 0000000000..f57c850a30 --- /dev/null +++ b/libavfilter/x86/vf_overlay_init.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 Paul B Mahol + * + * 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/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/x86/cpu.h" +#include "libavfilter/vf_overlay.h" + +void ff_overlay_row_yuv444_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a, + int w, int x, int y, int src_w, int src_h); + +av_cold void ff_overlay_init_x86(OverlayContext *s, int format, int alpha_format, int main_has_alpha) +{ + int cpu_flags = av_get_cpu_flags(); + + if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && + (format == OVERLAY_FORMAT_YUV444 || + format == OVERLAY_FORMAT_GBRP) && + alpha_format == 0 && main_has_alpha == 0) { + s->blend_row = ff_overlay_row_yuv444_sse4; + } +}