From: Chris Phlipot <cphlipot0@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Chris Phlipot <cphlipot0@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 4/5] avfilter/vf_yadif: Process more pixels using filter_line Date: Wed, 20 Jul 2022 19:25:13 -0700 Message-ID: <20220721022514.1466331-4-cphlipot0@gmail.com> (raw) In-Reply-To: <20220721022514.1466331-1-cphlipot0@gmail.com> 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 <cphlipot0@gmail.com> --- 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); -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-07-21 2:26 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-21 2:25 [FFmpeg-devel] [PATCH v2 1/5] avfilter/vf_yadif: Fix edge size when MAX_ALIGN is < 4 Chris Phlipot 2022-07-21 2:25 ` [FFmpeg-devel] [PATCH v2 2/5] avfilter/vf_yadif: Allow alignment to be configurable Chris Phlipot 2022-07-21 2:25 ` [FFmpeg-devel] [PATCH v2 3/5] avfilter/vf_yadif: reformat code to improve readability Chris Phlipot 2022-07-21 2:25 ` Chris Phlipot [this message] 2022-07-21 2:25 ` [FFmpeg-devel] [PATCH v2 5/5] avfilter/vf_yadif: Add x86_64 avx yadif asm Chris Phlipot
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220721022514.1466331-4-cphlipot0@gmail.com \ --to=cphlipot0@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git