History

swscale/aarch64/yuv2rgb: add neon yuv42{0,2}p -> gbrp unscaled colorspace converters

checkasm --bench on a Raspberry Pi 5 Model B Rev 1.0: yuv420p_gbrp_128_c: 1243.0 yuv420p_gbrp_128_neon: 453.5 yuv420p_gbrp_1920_c: 18165.5 yuv420p_gbrp_1920_neon: 6700.0 yuv422p_gbrp_128_c: 1463.5 yuv422p_gbrp_128_neon: 471.5 yuv422p_gbrp_1920_c: 21343.7 yuv422p_gbrp_1920_neon: 6743.5

Ramiro Polla committed 2 years ago

Commit 181cd261 parent 87447642 files · +118 −13Browse files

Showing the changes to libswscale (2 of 2 files). Show all

Unified · Split

2 files
  1. libswscale/aarch64/swscale_unscaled.c +58 −0
  2. libswscale/aarch64/yuv2rgb_neon.S +60 −13
libswscale/aarch64/swscale_unscaled.c+58−0
@@ -52,11 +52,41 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], · 51 unmodified lines
5252 c->yuv2rgb_y_coeff); \
5353 } \
5454
55+#define DECLARE_FF_YUVX_TO_GBRP_FUNCS(ifmt, ofmt) \
56+int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
57+ uint8_t *dst, int linesize, \
58+ const uint8_t *srcY, int linesizeY, \
59+ const uint8_t *srcU, int linesizeU, \
60+ const uint8_t *srcV, int linesizeV, \
61+ const int16_t *table, \
62+ int y_offset, \
63+ int y_coeff, \
64+ uint8_t *dst1, int linesize1, \
65+ uint8_t *dst2, int linesize2); \
66+ \
67+static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
68+ int srcStride[], int srcSliceY, int srcSliceH, \
69+ uint8_t *dst[], int dstStride[]) { \
70+ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
71+ \
72+ return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
73+ dst[0] + srcSliceY * dstStride[0], dstStride[0], \
74+ src[0], srcStride[0], \
75+ src[1], srcStride[1], \
76+ src[2], srcStride[2], \
77+ yuv2rgb_table, \
78+ c->yuv2rgb_y_offset >> 6, \
79+ c->yuv2rgb_y_coeff, \
80+ dst[1] + srcSliceY * dstStride[1], dstStride[1], \
81+ dst[2] + srcSliceY * dstStride[2], dstStride[2]); \
82+} \
83+
5584 #define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
5685 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
5786 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
5887 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
5988 DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
89+DECLARE_FF_YUVX_TO_GBRP_FUNCS(yuvx, gbrp) \
6090
6191 DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
6292 DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
@@ -83,11 +113,38 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], · 20 unmodified lines
83113 c->yuv2rgb_y_coeff); \
84114 } \
85115
116+#define DECLARE_FF_NVX_TO_GBRP_FUNCS(ifmt, ofmt) \
117+int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
118+ uint8_t *dst, int linesize, \
119+ const uint8_t *srcY, int linesizeY, \
120+ const uint8_t *srcC, int linesizeC, \
121+ const int16_t *table, \
122+ int y_offset, \
123+ int y_coeff, \
124+ uint8_t *dst1, int linesize1, \
125+ uint8_t *dst2, int linesize2); \
126+ \
127+static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
128+ int srcStride[], int srcSliceY, int srcSliceH, \
129+ uint8_t *dst[], int dstStride[]) { \
130+ const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
131+ \
132+ return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
133+ dst[0] + srcSliceY * dstStride[0], dstStride[0], \
134+ src[0], srcStride[0], src[1], srcStride[1], \
135+ yuv2rgb_table, \
136+ c->yuv2rgb_y_offset >> 6, \
137+ c->yuv2rgb_y_coeff, \
138+ dst[1] + srcSliceY * dstStride[1], dstStride[1], \
139+ dst[2] + srcSliceY * dstStride[2], dstStride[2]); \
140+} \
141+
86142 #define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
87143 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
88144 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
89145 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
90146 DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
147+DECLARE_FF_NVX_TO_GBRP_FUNCS(nvx, gbrp) \
91148
92149 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
93150 DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
@@ -110,6 +167,7 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) · 16 unmodified lines
110167 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
111168 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
112169 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
170+ SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, gbrp, GBRP, accurate_rnd); \
113171 } while (0)
114172
115173 static void get_unscaled_swscale_neon(SwsContext *c) {
libswscale/aarch64/yuv2rgb_neon.S+60−13
@@ -30,23 +30,43 @@ · 29 unmodified lines
3030 #endif
3131 .endm
3232
33−.macro load_args_nv12
33+.macro load_dst1_dst2 dst1 linesize1 dst2 linesize2
34+#if defined(__APPLE__)
35+#define DST_OFFSET 8
36+#else
37+#define DST_OFFSET 0
38+#endif
39+ ldr x10, [sp, #\dst1 - DST_OFFSET]
40+ ldr w12, [sp, #\linesize1 - DST_OFFSET]
41+ ldr x15, [sp, #\dst2 - DST_OFFSET]
42+ ldr w16, [sp, #\linesize2 - DST_OFFSET]
43+#undef DST_OFFSET
44+ sub w12, w12, w0 // w12 = linesize1 - width (padding1)
45+ sub w16, w16, w0 // w16 = linesize2 - width (padding2)
46+.endm
47+
48+.macro load_args_nv12 ofmt
3449 ldr x8, [sp] // table
3550 load_yoff_ycoeff 8, 16 // y_offset, y_coeff
3651 ld1 {v1.1d}, [x8]
3752 dup v0.8h, w10
3853 dup v3.8h, w9
54+.ifc \ofmt,gbrp
55+ load_dst1_dst2 24, 32, 40, 48
56+ sub w3, w3, w0 // w3 = linesize - width (padding)
57+.else
3958 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)
59+.endif
4060 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)
4161 sub w7, w7, w0 // w7 = linesizeC - width (paddingC)
4262 neg w11, w0
4363 .endm
4464
45−.macro load_args_nv21
46− load_args_nv12
65+.macro load_args_nv21 ofmt
66+ load_args_nv12 \ofmt
4767 .endm
4868
49−.macro load_args_yuv420p
69+.macro load_args_yuv420p ofmt
5070 ldr x13, [sp] // srcV
5171 ldr w14, [sp, #8] // linesizeV
5272 ldr x8, [sp, #16] // table
@@ -54,7 +74,12 @@ · 1 unmodified line
5474 ld1 {v1.1d}, [x8]
5575 dup v0.8h, w10
5676 dup v3.8h, w9
77+.ifc \ofmt,gbrp
78+ load_dst1_dst2 40, 48, 56, 64
79+ sub w3, w3, w0 // w3 = linesize - width (padding)
80+.else
5781 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)
82+.endif
5883 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)
5984 sub w7, w7, w0, lsr #1 // w7 = linesizeU - width / 2 (paddingU)
6085 sub w14, w14, w0, lsr #1 // w14 = linesizeV - width / 2 (paddingV)
@@ -62,7 +87,7 @@ · 1 unmodified line
6287 neg w11, w11
6388 .endm
6489
65−.macro load_args_yuv422p
90+.macro load_args_yuv422p ofmt
6691 ldr x13, [sp] // srcV
6792 ldr w14, [sp, #8] // linesizeV
6893 ldr x8, [sp, #16] // table
@@ -70,7 +95,12 @@ · 1 unmodified line
7095 ld1 {v1.1d}, [x8]
7196 dup v0.8h, w10
7297 dup v3.8h, w9
98+.ifc \ofmt,gbrp
99+ load_dst1_dst2 40, 48, 56, 64
100+ sub w3, w3, w0 // w3 = linesize - width (padding)
101+.else
73102 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)
103+.endif
74104 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)
75105 sub w7, w7, w0, lsr #1 // w7 = linesizeU - width / 2 (paddingU)
76106 sub w14, w14, w0, lsr #1 // w14 = linesizeV - width / 2 (paddingV)
@@ -100,9 +130,9 @@ · 23 unmodified lines
100130 .endm
101131
102132 .macro increment_nv12
103− ands w15, w1, #1
104− csel w16, w7, w11, ne // incC = (h & 1) ? paddincC : -width
105− add x6, x6, w16, sxtw // srcC += incC
133+ ands w17, w1, #1
134+ csel w17, w7, w11, ne // incC = (h & 1) ? paddincC : -width
135+ add x6, x6, w17, sxtw // srcC += incC
106136 .endm
107137
108138 .macro increment_nv21
@@ -110,10 +140,10 @@ · 1 unmodified line
110140 .endm
111141
112142 .macro increment_yuv420p
113− ands w15, w1, #1
114− csel w16, w7, w11, ne // incU = (h & 1) ? paddincU : -width/2
143+ ands w17, w1, #1
144+ csel w17, w7, w11, ne // incU = (h & 1) ? paddincU : -width/2
145+ add x6, x6, w17, sxtw // srcU += incU
115146 csel w17, w14, w11, ne // incV = (h & 1) ? paddincV : -width/2
116− add x6, x6, w16, sxtw // srcU += incU
117147 add x13, x13, w17, sxtw // srcV += incV
118148 .endm
119149
@@ -122,7 +152,7 @@ · 2 unmodified lines
122152 add x13, x13, w14, sxtw // srcV += incV
123153 .endm
124154
125−.macro compute_rgba r1 g1 b1 a1 r2 g2 b2 a2
155+.macro compute_rgb r1 g1 b1 r2 g2 b2
126156 add v20.8h, v26.8h, v20.8h // Y1 + R1
127157 add v21.8h, v27.8h, v21.8h // Y2 + R2
128158 add v22.8h, v26.8h, v22.8h // Y1 + G1
@@ -135,13 +165,18 @@ · 6 unmodified lines
135165 sqrshrun \g2, v23.8h, #1 // clip_u8((Y2 + G1) >> 1)
136166 sqrshrun \b1, v24.8h, #1 // clip_u8((Y1 + B1) >> 1)
137167 sqrshrun \b2, v25.8h, #1 // clip_u8((Y2 + B1) >> 1)
168+.endm
169+
170+.macro compute_rgba r1 g1 b1 a1 r2 g2 b2 a2
171+ compute_rgb \r1, \g1, \b1, \r2, \g2, \b2
138172 movi \a1, #255
139173 movi \a2, #255
140174 .endm
141175
142176 .macro declare_func ifmt ofmt
143177 function ff_\ifmt\()_to_\ofmt\()_neon, export=1
144− load_args_\ifmt
178+ load_args_\ifmt \ofmt
179+
145180 mov w9, w1
146181 1:
147182 mov w8, w0 // w8 = width
@@ -185,11 +220,22 @@ function ff_\ifmt\()_to_\ofmt\()_neon, export=1 · 37 unmodified lines
185220 compute_rgba v6.8b,v5.8b,v4.8b,v7.8b, v18.8b,v17.8b,v16.8b,v19.8b
186221 .endif
187222
223+.ifc \ofmt,gbrp
224+ compute_rgb v18.8b,v4.8b,v6.8b, v19.8b,v5.8b,v7.8b
225+ st1 { v4.8b, v5.8b }, [x2], #16
226+ st1 { v6.8b, v7.8b }, [x10], #16
227+ st1 { v18.8b, v19.8b }, [x15], #16
228+.else
188229 st4 { v4.8b, v5.8b, v6.8b, v7.8b}, [x2], #32
189230 st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [x2], #32
231+.endif
190232 subs w8, w8, #16 // width -= 16
191233 b.gt 2b
192234 add x2, x2, w3, sxtw // dst += padding
235+.ifc \ofmt,gbrp
236+ add x10, x10, w12, sxtw // dst1 += padding1
237+ add x15, x15, w16, sxtw // dst2 += padding2
238+.endif
193239 add x4, x4, w5, sxtw // srcY += paddingY
194240 increment_\ifmt
195241 subs w1, w1, #1 // height -= 1
@@ -204,6 +250,7 @@ endfunc · 8 unmodified lines
204250 declare_func \ifmt, rgba
205251 declare_func \ifmt, abgr
206252 declare_func \ifmt, bgra
253+ declare_func \ifmt, gbrp
207254 .endm
208255
209256 declare_rgb_funcs nv12

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t