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/convolution.h (1 of 9 files). Show all
Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | #ifndef AVFILTER_CONVOLUTION_H | 21 | #ifndef AVFILTER_CONVOLUTION_H |
| 22 | #define AVFILTER_CONVOLUTION_H | 22 | #define AVFILTER_CONVOLUTION_H |
| 23 | #include "avfilter.h" | 23 | #include "avfilter.h" |
| 24 | #include "libavutil/intreadwrite.h" | ||
| 24 | 25 | ||
| 25 | enum MatrixMode { | 26 | enum MatrixMode { |
| 26 | MATRIX_SQUARE, | 27 | MATRIX_SQUARE, |
| @@ -61,4 +62,77 @@ typedef struct ConvolutionContext { · 34 unmodified lines | |||
| 61 | } ConvolutionContext; | 62 | } ConvolutionContext; |
| 62 | 63 | ||
| 63 | void ff_convolution_init_x86(ConvolutionContext *s); | 64 | void ff_convolution_init_x86(ConvolutionContext *s); |
| 65 | void ff_sobel_init_x86(ConvolutionContext *s, int depth, int nb_planes); | ||
| 66 | |||
| 67 | static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride, | ||
| 68 | int x, int w, int y, int h, int bpc) | ||
| 69 | { | ||
| 70 | int i; | ||
| 71 | |||
| 72 | for (i = 0; i < 9; i++) { | ||
| 73 | int xoff = FFABS(x + ((i % 3) - 1)); | ||
| 74 | int yoff = FFABS(y + (i / 3) - 1); | ||
| 75 | |||
| 76 | xoff = xoff >= w ? 2 * w - 1 - xoff : xoff; | ||
| 77 | yoff = yoff >= h ? 2 * h - 1 - yoff : yoff; | ||
| 78 | |||
| 79 | c[i] = src + xoff * bpc + yoff * stride; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | static void filter_sobel(uint8_t *dst, int width, | ||
| 84 | float scale, float delta, const int *const matrix, | ||
| 85 | const uint8_t *c[], int peak, int radius, | ||
| 86 | int dstride, int stride, int size) | ||
| 87 | { | ||
| 88 | const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2]; | ||
| 89 | const uint8_t *c3 = c[3], *c5 = c[5]; | ||
| 90 | const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8]; | ||
| 91 | int x; | ||
| 92 | |||
| 93 | for (x = 0; x < width; x++) { | ||
| 94 | float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 + | ||
| 95 | c6[x] * 1 + c7[x] * 2 + c8[x] * 1; | ||
| 96 | float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 + | ||
| 97 | c5[x] * 2 + c6[x] * -1 + c8[x] * 1; | ||
| 98 | |||
| 99 | dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | static void filter16_sobel(uint8_t *dstp, int width, | ||
| 104 | float scale, float delta, const int *const matrix, | ||
| 105 | const uint8_t *c[], int peak, int radius, | ||
| 106 | int dstride, int stride, int size) | ||
| 107 | { | ||
| 108 | uint16_t *dst = (uint16_t *)dstp; | ||
| 109 | int x; | ||
| 110 | |||
| 111 | for (x = 0; x < width; x++) { | ||
| 112 | float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 + | ||
| 113 | AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1; | ||
| 114 | float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 + | ||
| 115 | AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1; | ||
| 116 | |||
| 117 | dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | static av_unused void ff_sobel_init(ConvolutionContext *s, int depth, int nb_planes) | ||
| 122 | { | ||
| 123 | for (int i = 0; i < 4; i++) { | ||
| 124 | s->filter[i] = filter_sobel; | ||
| 125 | s->copy[i] = !((1 << i) & s->planes); | ||
| 126 | s->size[i] = 3; | ||
| 127 | s->setup[i] = setup_3x3; | ||
| 128 | s->rdiv[i] = s->scale; | ||
| 129 | s->bias[i] = s->delta; | ||
| 130 | } | ||
| 131 | if (s->depth > 8) | ||
| 132 | for (int i = 0; i < 4; i++) | ||
| 133 | s->filter[i] = filter16_sobel; | ||
| 134 | #if ARCH_X86_64 | ||
| 135 | ff_sobel_init_x86(s, depth, nb_planes); | ||
| 136 | #endif | ||
| 137 | } | ||
| 64 | #endif | 138 | #endif |