From patchwork Thu Jul 21 02:25:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Phlipot X-Patchwork-Id: 36879 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp2771123pzb; Wed, 20 Jul 2022 19:26:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vmHXpcF5dUpTC1JGNA666Q/1HtEvZyVY6eT5ZpeaooAhy9j+NSaodGrwT4ztMqjLIdsEf/ X-Received: by 2002:a05:6402:3511:b0:43a:caf7:6fce with SMTP id b17-20020a056402351100b0043acaf76fcemr55219151edd.349.1658370383269; Wed, 20 Jul 2022 19:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658370383; cv=none; d=google.com; s=arc-20160816; b=09RXR9nAtcbKvXwbFtmK6kNffmQo2MJUyA/fsdDe5sg0Xz6OaWHeIJGCB/LvxAevP+ YHDrnN0BZYhJBB+6KATn+JP/EQDrJUm4VtJs5/BBNVoxb5p/vWR0qvOmiAX8Uvwe9wx3 K3UmKt7rphwOPoEyfgbrtmJAcxDI1+qHrpYduTWu/AhA45ZZZAXw0cNijJdmtFIL/dew GQrpiXheaydCBJpMBImJwBcXytCincB8809ibgq5UysA9gBbtDAjG35jbJ+h4IINYW+X EmDfNvAM02N/2c8RxH93IbeTNTU+kZDmuRVujup0czHd3Wwf++RZa1LmHYEtDRggA6U6 le4w== 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=6lfXK8KYO5o9/eywNyRRuV67x63Ct/NJWROFJpmSnMo=; b=0TLfP1IN1LhzoC+dYtOWyQVO1EqK0vcIpptRGUbAtkAjnXjyHsQTarfYd5tdiwh/GF zS+ceCnr6lukdP6GrRYwxoTuSEbMf4pmnONdx7xGjMe6wnmK+M+E7yl5vVVs+0wsgVCr NevLaQ7mVv0IgRygCnfVwGHgfBPAgfacvWnZ047ym9+1ZOvHnFHGpihPHcLowqMK5FJa em5a4/ajkU8+G75xtVjgE4plOEC2W+aZ9wE4xgd+6/GdtiaYVBsn9gFBJjD46kUT5Oay twJRxuK8IZKYeeTwnM46KUrlOEvQRgOfN0dtusumVpCCM1VRjTY8/1eG7avfLRPn1YpN qaqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=IAwFasTQ; 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 t24-20020aa7d4d8000000b0043b79180f22si813956edr.83.2022.07.20.19.26.22; Wed, 20 Jul 2022 19:26:23 -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=20210112 header.b=IAwFasTQ; 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 880A768B5E6; Thu, 21 Jul 2022 05:25:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D135C68818E for ; Thu, 21 Jul 2022 05:25:44 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id b9so460177pfp.10 for ; Wed, 20 Jul 2022 19:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c4xeuuzjgkCyJeehhi155/UaxzBBbcPC2HabThBId/I=; b=IAwFasTQS73tdZ5BYyPHvB03WyreTogzaIrASTOmaJdQHYiBRqOOBVczhjdOLkp0iY oSfrrlLSiAJjsJ+SQ8tE6ALqdLfYDRWfq6A/FmSatGkNvQbfEc7+L+G31lGWvGff0KNw 4XQF4b5ySck/j6A6EWrn0g0DGMrvahca25jxjOKXa9efSffqpSABkKXulpmYBcAHvVdJ rUT3W3RUaVGjL3QLr/YRjwGGcQV0RBXlP+GBhJ39nZDsrehNjwxhSHO0Zo/Hjcd6o/UO FFZJNRLwpX+S4SgLEeMpLrCHxu0aMgB1rdvN654cvy5I4w2lg9wfcsxrjF7YvWLASLl8 dYKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c4xeuuzjgkCyJeehhi155/UaxzBBbcPC2HabThBId/I=; b=kScwrKsN3A2opHRRc4FMLtVKekquO03VLJm5f73W4HvwbAUrLVAOLADihTsjR6fOm5 4i5nBgjVijEbxcpSJ+TNAbiZtMYBQ2vyt/OTL+gtmDWtdPA3RPp1ocaYNsxb+HmjBABq U5jV2jQxHFoAsFFHgxS+1rmHXaI66fakiHm15z2xEewpA2pjmRcuuU9nDHOJRYdlBHuH kx+V36PM3BZBxfcOIeO8VS1Y7zZmQqj7wHRAsmyHiImmv6+KZ5IDQH2U0lml8e9ho3Ou TgSkh/a8dF7R0/08UDVzyKOgj3n1xJouV/SoDeB1u42A2fRfh0ECQvkwMb6tloqkE6G+ Tlrw== X-Gm-Message-State: AJIora9rKTbGh9szIT3wu489IKTiNpGXJYhJVujy3k7/vbfxhYNOgLc7 1jflFN6XhWqu0NBs+JZ8icUe9Isor/XCnw== X-Received: by 2002:a63:79c8:0:b0:41a:7b78:9ed2 with SMTP id u191-20020a6379c8000000b0041a7b789ed2mr2104061pgc.306.1658370342838; Wed, 20 Jul 2022 19:25:42 -0700 (PDT) Received: from localhost.localdomain (23-121-159-29.lightspeed.sntcca.sbcglobal.net. [23.121.159.29]) by smtp.googlemail.com with ESMTPSA id j3-20020a62c503000000b005251c6fbd0csm340079pfg.29.2022.07.20.19.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 19:25:42 -0700 (PDT) From: Chris Phlipot To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Jul 2022 19:25:13 -0700 Message-Id: <20220721022514.1466331-4-cphlipot0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721022514.1466331-1-cphlipot0@gmail.com> References: <20220721022514.1466331-1-cphlipot0@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/5] avfilter/vf_yadif: Process more pixels using filter_line 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: Chris Phlipot Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bFedlfgmMeTD filter_line is generally vectorized, wheras filter_edge is implemented in C. Currently we rely on filter_edge to process non-edges in cases where the width doesn't match the alignment. This causes us to process non-edge pixels with the slow C implementation vs the faster SSE implementation. It is generally faster to process 8 pixels with the slowest SSE2 vectorized implementation than it is to process 2 pixels with the C implementation. Therefore, if filter_edge needs to process 2 or more non-edge pixels, it would be faster to process these non-edge pixels with filter_line instead even if it processes more pixels than necessary. To address this, we use filter_line so long as we know that at least 2 pixels will be used in the final output even if the rest of the computed pixels are invalid. Any incorrect output pixels generated by filter_line will be overwritten by the following call to filter_edge. In addtion we avoid running filter_line if it would read or write pixels outside the current slice. Signed-off-by: Chris Phlipot --- libavfilter/vf_yadif.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 54109566be..394c04a985 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -201,6 +201,8 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) int slice_end = (td->h * (jobnr+1)) / nb_jobs; int y; int edge = 3 + s->req_align / df - 1; + int filter_width_target = td->w - 3; + int filter_width_rounded_up = (filter_width_target & ~(s->req_align-1)) + s->req_align; /* filtering reads 3 pixels to the left/right; to avoid invalid reads, * we need to call the c variant which avoids this for border pixels @@ -215,11 +217,28 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) int mrefs = y ? -refs : refs; int parity = td->parity ^ td->tff; int mode = y == 1 || y + 2 == td->h ? 2 : s->mode; + + /* Adjust width and alignment to process extra pixels in filter_line + * using potentially vectorized code so long as it doesn't cause + * reads or writes outside of the current slice. filter_edge will + * correct any incorrect pixels written by filter_line in this + * scenario. + */ + int filter_width; + int edge_alignment; + if (filter_width_rounded_up - filter_width_target >= 2 + && y*refs + filter_width_rounded_up < slice_end * refs + refs - 3) { + filter_width = filter_width_rounded_up; + edge_alignment = 1; + } else { + filter_width = td->w - edge; + edge_alignment = s->req_align; + } s->filter_line(dst + pix_3, prev + pix_3, cur + pix_3, - next + pix_3, td->w - edge, + next + pix_3, filter_width, prefs, mrefs, parity, mode); s->filter_edges(dst, prev, cur, next, td->w, - prefs, mrefs, parity, mode, s->req_align); + prefs, mrefs, parity, mode, edge_alignment); } else { memcpy(&td->frame->data[td->plane][y * td->frame->linesize[td->plane]], &s->cur->data[td->plane][y * refs], td->w * df);