This commit enabled assembly code with intel AVX512 VNNI and added unit test for sobel filter sobel_c: 4537 sobel_avx512icl 2136
Showing the changes to libavfilter/vf_convolution.c (1 of 9 files). Show all
Unified · Split
| @@ -139,24 +139,6 @@ static void filter16_roberts(uint8_t *dstp, int width, · 138 unmodified lines | ||
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | −static void filter16_sobel(uint8_t *dstp, int width, | |
| 143 | − float scale, float delta, const int *const matrix, | |
| 144 | − const uint8_t *c[], int peak, int radius, | |
| 145 | − int dstride, int stride, int size) | |
| 146 | −{ | |
| 147 | − uint16_t *dst = (uint16_t *)dstp; | |
| 148 | − int x; | |
| 149 | − | |
| 150 | − for (x = 0; x < width; x++) { | |
| 151 | − float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 + | |
| 152 | − AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1; | |
| 153 | − float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 + | |
| 154 | − AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1; | |
| 155 | − | |
| 156 | − dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak); | |
| 157 | − } | |
| 158 | −} | |
| 159 | − | |
| 160 | 142 | static void filter16_scharr(uint8_t *dstp, int width, |
| 161 | 143 | float scale, float delta, const int *const matrix, |
| 162 | 144 | const uint8_t *c[], int peak, int radius, |
| @@ -261,26 +243,6 @@ static void filter_roberts(uint8_t *dst, int width, · 98 unmodified lines | ||
| 261 | 243 | } |
| 262 | 244 | } |
| 263 | 245 | |
| 264 | −static void filter_sobel(uint8_t *dst, int width, | |
| 265 | − float scale, float delta, const int *const matrix, | |
| 266 | − const uint8_t *c[], int peak, int radius, | |
| 267 | − int dstride, int stride, int size) | |
| 268 | −{ | |
| 269 | − const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2]; | |
| 270 | − const uint8_t *c3 = c[3], *c5 = c[5]; | |
| 271 | − const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8]; | |
| 272 | − int x; | |
| 273 | − | |
| 274 | − for (x = 0; x < width; x++) { | |
| 275 | − float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 + | |
| 276 | − c6[x] * 1 + c7[x] * 2 + c8[x] * 1; | |
| 277 | − float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 + | |
| 278 | − c5[x] * 2 + c6[x] * -1 + c8[x] * 1; | |
| 279 | − | |
| 280 | − dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta); | |
| 281 | − } | |
| 282 | −} | |
| 283 | − | |
| 284 | 246 | static void filter_scharr(uint8_t *dst, int width, |
| 285 | 247 | float scale, float delta, const int *const matrix, |
| 286 | 248 | const uint8_t *c[], int peak, int radius, |
| @@ -552,22 +514,6 @@ static void filter_column(uint8_t *dst, int height, · 265 unmodified lines | ||
| 552 | 514 | } |
| 553 | 515 | } |
| 554 | 516 | |
| 555 | −static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride, | |
| 556 | − int x, int w, int y, int h, int bpc) | |
| 557 | −{ | |
| 558 | − int i; | |
| 559 | − | |
| 560 | − for (i = 0; i < 9; i++) { | |
| 561 | − int xoff = FFABS(x + ((i % 3) - 1)); | |
| 562 | − int yoff = FFABS(y + (i / 3) - 1); | |
| 563 | − | |
| 564 | − xoff = xoff >= w ? 2 * w - 1 - xoff : xoff; | |
| 565 | − yoff = yoff >= h ? 2 * h - 1 - yoff : yoff; | |
| 566 | − | |
| 567 | − c[i] = src + xoff * bpc + yoff * stride; | |
| 568 | − } | |
| 569 | −} | |
| 570 | − | |
| 571 | 517 | static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride, |
| 572 | 518 | int x, int w, int y, int h, int bpc) |
| 573 | 519 | { |
| @@ -708,6 +654,18 @@ static int param_init(AVFilterContext *ctx) · 134 unmodified lines | ||
| 708 | 654 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 709 | 655 | int p, i; |
| 710 | 656 | |
| 657 | + s->depth = desc->comp[0].depth; | |
| 658 | + s->max = (1 << s->depth) - 1; | |
| 659 | + | |
| 660 | + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
| 661 | + s->planewidth[0] = s->planewidth[3] = inlink->w; | |
| 662 | + s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
| 663 | + s->planeheight[0] = s->planeheight[3] = inlink->h; | |
| 664 | + | |
| 665 | + s->nb_planes = av_pix_fmt_count_planes(inlink->format); | |
| 666 | + s->nb_threads = ff_filter_get_nb_threads(ctx); | |
| 667 | + s->bpc = (s->depth + 7) / 8; | |
| 668 | + | |
| 711 | 669 | if (!strcmp(ctx->filter->name, "convolution")) { |
| 712 | 670 | for (i = 0; i < 4; i++) { |
| 713 | 671 | int *matrix = (int *)s->matrix[i]; |
| @@ -804,14 +762,7 @@ static int param_init(AVFilterContext *ctx) · 90 unmodified lines | ||
| 804 | 762 | s->bias[i] = s->delta; |
| 805 | 763 | } |
| 806 | 764 | } else if (!strcmp(ctx->filter->name, "sobel")) { |
| 807 | − for (i = 0; i < 4; i++) { | |
| 808 | − s->filter[i] = filter_sobel; | |
| 809 | − s->copy[i] = !((1 << i) & s->planes); | |
| 810 | − s->size[i] = 3; | |
| 811 | − s->setup[i] = setup_3x3; | |
| 812 | − s->rdiv[i] = s->scale; | |
| 813 | − s->bias[i] = s->delta; | |
| 814 | − } | |
| 765 | + ff_sobel_init(s, s->depth, s->nb_planes); | |
| 815 | 766 | } else if (!strcmp(ctx->filter->name, "kirsch")) { |
| 816 | 767 | for (i = 0; i < 4; i++) { |
| 817 | 768 | s->filter[i] = filter_kirsch; |
| @@ -832,18 +783,6 @@ static int param_init(AVFilterContext *ctx) · 14 unmodified lines | ||
| 832 | 783 | } |
| 833 | 784 | } |
| 834 | 785 | |
| 835 | − s->depth = desc->comp[0].depth; | |
| 836 | − s->max = (1 << s->depth) - 1; | |
| 837 | − | |
| 838 | − s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | |
| 839 | − s->planewidth[0] = s->planewidth[3] = inlink->w; | |
| 840 | − s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); | |
| 841 | − s->planeheight[0] = s->planeheight[3] = inlink->h; | |
| 842 | − | |
| 843 | − s->nb_planes = av_pix_fmt_count_planes(inlink->format); | |
| 844 | − s->nb_threads = ff_filter_get_nb_threads(ctx); | |
| 845 | − s->bpc = (s->depth + 7) / 8; | |
| 846 | − | |
| 847 | 786 | if (!strcmp(ctx->filter->name, "convolution")) { |
| 848 | 787 | if (s->depth > 8) { |
| 849 | 788 | for (p = 0; p < s->nb_planes; p++) { |
| @@ -870,10 +809,6 @@ static int param_init(AVFilterContext *ctx) · 20 unmodified lines | ||
| 870 | 809 | if (s->depth > 8) |
| 871 | 810 | for (p = 0; p < s->nb_planes; p++) |
| 872 | 811 | s->filter[p] = filter16_roberts; |
| 873 | − } else if (!strcmp(ctx->filter->name, "sobel")) { | |
| 874 | − if (s->depth > 8) | |
| 875 | − for (p = 0; p < s->nb_planes; p++) | |
| 876 | − s->filter[p] = filter16_sobel; | |
| 877 | 812 | } else if (!strcmp(ctx->filter->name, "kirsch")) { |
| 878 | 813 | if (s->depth > 8) |
| 879 | 814 | for (p = 0; p < s->nb_planes; p++) |