Add an optional filter_line3 to the available optimisations. filter_line3 is equivalent to filter_line, memcpy, filter_line filter_line shares quite a number of loads and some calculations in common with its next iteration and testing shows that using aarch64 neon filter_line3s performance is 30% better than two filter_lines and a memcpy. Adds a test for vf_bwdif filter_line3 to checkasm Rounds job start lines down to a multiple of 4. This means that if filter_line3 exists then filter_line will not sometimes be called once at the end of a slice depending on thread count. The final slice may do up to 3 extra lines but filter_edge is faster than filter_line so it is unlikely to create any noticable thread load variation.
Showing the changes to libavfilter (2 of 3 files). Show all
Unified · Split
| @@ -35,6 +35,9 @@ typedef struct BWDIFContext { · 34 unmodified lines | ||
| 35 | 35 | void (*filter_edge)(void *dst, void *prev, void *cur, void *next, |
| 36 | 36 | int w, int prefs, int mrefs, int prefs2, int mrefs2, |
| 37 | 37 | int parity, int clip_max, int spat); |
| 38 | + void (*filter_line3)(void *dst, int dstride, | |
| 39 | + const void *prev, const void *cur, const void *next, int prefs, | |
| 40 | + int w, int parity, int clip_max); | |
| 38 | 41 | } BWDIFContext; |
| 39 | 42 | |
| 40 | 43 | void ff_bwdif_init_filter_line(BWDIFContext *bwdif, int bit_depth); |
| @@ -53,4 +56,8 @@ void ff_bwdif_filter_line_c(void *dst1, void *prev1, void *cur1, void *next1, · 12 unmodified lines | ||
| 53 | 56 | int prefs3, int mrefs3, int prefs4, int mrefs4, |
| 54 | 57 | int parity, int clip_max); |
| 55 | 58 | |
| 59 | +void ff_bwdif_filter_line3_c(void * dst1, int d_stride, | |
| 60 | + const void * prev1, const void * cur1, const void * next1, int s_stride, | |
| 61 | + int w, int parity, int clip_max); | |
| 62 | + | |
| 56 | 63 | #endif /* AVFILTER_BWDIF_H */ |
| @@ -150,6 +150,31 @@ void ff_bwdif_filter_line_c(void *dst1, void *prev1, void *cur1, void *next1, · 149 unmodified lines | ||
| 150 | 150 | FILTER2() |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | +#define NEXT_LINE()\ | |
| 154 | + dst += d_stride; \ | |
| 155 | + prev += prefs; \ | |
| 156 | + cur += prefs; \ | |
| 157 | + next += prefs; | |
| 158 | + | |
| 159 | +void ff_bwdif_filter_line3_c(void * dst1, int d_stride, | |
| 160 | + const void * prev1, const void * cur1, const void * next1, int s_stride, | |
| 161 | + int w, int parity, int clip_max) | |
| 162 | +{ | |
| 163 | + const int prefs = s_stride; | |
| 164 | + uint8_t * dst = dst1; | |
| 165 | + const uint8_t * prev = prev1; | |
| 166 | + const uint8_t * cur = cur1; | |
| 167 | + const uint8_t * next = next1; | |
| 168 | + | |
| 169 | + ff_bwdif_filter_line_c(dst, (void*)prev, (void*)cur, (void*)next, w, | |
| 170 | + prefs, -prefs, prefs * 2, - prefs * 2, prefs * 3, -prefs * 3, prefs * 4, -prefs * 4, parity, clip_max); | |
| 171 | + NEXT_LINE(); | |
| 172 | + memcpy(dst, cur, w); | |
| 173 | + NEXT_LINE(); | |
| 174 | + ff_bwdif_filter_line_c(dst, (void*)prev, (void*)cur, (void*)next, w, | |
| 175 | + prefs, -prefs, prefs * 2, - prefs * 2, prefs * 3, -prefs * 3, prefs * 4, -prefs * 4, parity, clip_max); | |
| 176 | +} | |
| 177 | + | |
| 153 | 178 | void ff_bwdif_filter_edge_c(void *dst1, void *prev1, void *cur1, void *next1, |
| 154 | 179 | int w, int prefs, int mrefs, int prefs2, int mrefs2, |
| 155 | 180 | int parity, int clip_max, int spat) |
| @@ -212,6 +237,13 @@ static void filter_edge_16bit(void *dst1, void *prev1, void *cur1, void *next1, · 56 unmodified lines | ||
| 212 | 237 | FILTER2() |
| 213 | 238 | } |
| 214 | 239 | |
| 240 | +// Round job start line down to multiple of 4 so that if filter_line3 exists | |
| 241 | +// and the frame is a multiple of 4 high then filter_line will never be called | |
| 242 | +static inline int job_start(const int jobnr, const int nb_jobs, const int h) | |
| 243 | +{ | |
| 244 | + return jobnr >= nb_jobs ? h : ((h * jobnr) / nb_jobs) & ~3; | |
| 245 | +} | |
| 246 | + | |
| 215 | 247 | static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| 216 | 248 | { |
| 217 | 249 | BWDIFContext *s = ctx->priv; |
| @@ -221,8 +253,8 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 3 unmodified lines | ||
| 221 | 253 | int clip_max = (1 << (yadif->csp->comp[td->plane].depth)) - 1; |
| 222 | 254 | int df = (yadif->csp->comp[td->plane].depth + 7) / 8; |
| 223 | 255 | int refs = linesize / df; |
| 224 | − int slice_start = (td->h * jobnr ) / nb_jobs; | |
| 225 | − int slice_end = (td->h * (jobnr+1)) / nb_jobs; | |
| 256 | + int slice_start = job_start(jobnr, nb_jobs, td->h); | |
| 257 | + int slice_end = job_start(jobnr + 1, nb_jobs, td->h); | |
| 226 | 258 | int y; |
| 227 | 259 | |
| 228 | 260 | for (y = slice_start; y < slice_end; y++) { |
| @@ -244,6 +276,11 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 15 unmodified lines | ||
| 244 | 276 | refs << 1, -(refs << 1), |
| 245 | 277 | td->parity ^ td->tff, clip_max, |
| 246 | 278 | (y < 2) || ((y + 3) > td->h) ? 0 : 1); |
| 279 | + } else if (s->filter_line3 && y + 2 < slice_end && y + 6 < td->h) { | |
| 280 | + s->filter_line3(dst, td->frame->linesize[td->plane], | |
| 281 | + prev, cur, next, linesize, td->w, | |
| 282 | + td->parity ^ td->tff, clip_max); | |
| 283 | + y += 2; | |
| 247 | 284 | } else { |
| 248 | 285 | s->filter_line(dst, prev, cur, next, td->w, |
| 249 | 286 | refs, -refs, refs << 1, -(refs << 1), |
| @@ -280,7 +317,7 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, · 30 unmodified lines | ||
| 280 | 317 | td.plane = i; |
| 281 | 318 | |
| 282 | 319 | ff_filter_execute(ctx, filter_slice, &td, NULL, |
| 283 | − FFMIN(h, ff_filter_get_nb_threads(ctx))); | |
| 320 | + FFMIN((h+3)/4, ff_filter_get_nb_threads(ctx))); | |
| 284 | 321 | } |
| 285 | 322 | if (yadif->current_field == YADIF_FIELD_END) { |
| 286 | 323 | yadif->current_field = YADIF_FIELD_NORMAL; |
| @@ -357,6 +394,7 @@ static int config_props(AVFilterLink *link) · 70 unmodified lines | ||
| 357 | 394 | |
| 358 | 395 | av_cold void ff_bwdif_init_filter_line(BWDIFContext *s, int bit_depth) |
| 359 | 396 | { |
| 397 | + s->filter_line3 = 0; | |
| 360 | 398 | if (bit_depth > 8) { |
| 361 | 399 | s->filter_intra = filter_intra_16bit; |
| 362 | 400 | s->filter_line = filter_line_c_16bit; |