From: Zhao Zhili <quinkblack@foxmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Zhao Zhili <zhilizhao@tencent.com> Subject: [FFmpeg-devel] [PATCH 1/2] swscale/aarch64: Add bgr24 to yuv Date: Sat, 15 Jun 2024 17:57:17 +0800 Message-ID: <tencent_CAA62D729A6C40E69AC29F10ABDA4E0A7008@qq.com> (raw) From: Zhao Zhili <zhilizhao@tencent.com> Test on Apple M1 with kperf bgr24_to_uv_8_c: 41.5 bgr24_to_uv_8_neon: 41.8 bgr24_to_uv_128_c: 133.5 bgr24_to_uv_128_neon: 94.3 bgr24_to_uv_1080_c: 960.5 bgr24_to_uv_1080_neon: 751.0 bgr24_to_uv_1920_c: 1695.3 bgr24_to_uv_1920_neon: 1357.3 bgr24_to_uv_half_8_c: 45.0 bgr24_to_uv_half_8_neon: 11.0 bgr24_to_uv_half_128_c: 130.5 bgr24_to_uv_half_128_neon: 51.8 bgr24_to_uv_half_1080_c: 877.3 bgr24_to_uv_half_1080_neon: 414.0 bgr24_to_uv_half_1920_c: 1540.0 bgr24_to_uv_half_1920_neon: 695.0 bgr24_to_y_8_c: 24.3 bgr24_to_y_8_neon: 12.8 bgr24_to_y_128_c: 94.3 bgr24_to_y_128_neon: 47.5 bgr24_to_y_1080_c: 611.5 bgr24_to_y_1080_neon: 437.5 bgr24_to_y_1920_c: 1077.3 bgr24_to_y_1920_neon: 765.3 --- libswscale/aarch64/input.S | 79 ++++++++++++++++++++++++++++-------- libswscale/aarch64/swscale.c | 32 +++++++++------ 2 files changed, 80 insertions(+), 31 deletions(-) diff --git a/libswscale/aarch64/input.S b/libswscale/aarch64/input.S index 33afa34111..2b956fe5c2 100644 --- a/libswscale/aarch64/input.S +++ b/libswscale/aarch64/input.S @@ -20,7 +20,7 @@ #include "libavutil/aarch64/asm.S" -.macro rgb24_to_yuv_load_rgb, src +.macro rgb_to_yuv_load_rgb src ld3 { v16.16b, v17.16b, v18.16b }, [\src] uxtl v19.8h, v16.8b // v19: r uxtl v20.8h, v17.8b // v20: g @@ -30,7 +30,7 @@ uxtl2 v24.8h, v18.16b // v24: b .endm -.macro rgb24_to_yuv_product, r, g, b, dst1, dst2, dst, coef0, coef1, coef2, right_shift +.macro rgb_to_yuv_product r, g, b, dst1, dst2, dst, coef0, coef1, coef2, right_shift mov \dst1\().16b, v6.16b // dst1 = const_offset mov \dst2\().16b, v6.16b // dst2 = const_offset smlal \dst1\().4s, \coef0\().4h, \r\().4h // dst1 += rx * r @@ -43,12 +43,20 @@ sqshrn2 \dst\().8h, \dst2\().4s, \right_shift // dst_higher_half = dst2 >> right_shift .endm -function ff_rgb24ToY_neon, export=1 +.macro rgbToY bgr cmp w4, #0 // check width > 0 + .if \bgr + ldr w12, [x5] // w12: ry + ldr w11, [x5, #4] // w11: gy + ldr w10, [x5, #8] // w10: by + .else ldp w10, w11, [x5] // w10: ry, w11: gy ldr w12, [x5, #8] // w12: by + .endif b.le 3f + // The following comments assume RGB order. The logic for RGB and BGR is the same. + mov w9, #256 // w9 = 1 << (RGB2YUV_SHIFT - 7) movk w9, #8, lsl #16 // w9 += 32 << (RGB2YUV_SHIFT - 1) dup v6.4s, w9 // w9: const_offset @@ -59,9 +67,9 @@ function ff_rgb24ToY_neon, export=1 dup v2.8h, w12 b.lt 2f 1: - rgb24_to_yuv_load_rgb x1 - rgb24_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9 - rgb24_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9 + rgb_to_yuv_load_rgb x1 + rgb_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9 + rgb_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9 sub w4, w4, #16 // width -= 16 add x1, x1, #48 // src += 48 cmp w4, #16 // width >= 16 ? @@ -83,12 +91,29 @@ function ff_rgb24ToY_neon, export=1 cbnz w4, 2b 3: ret +.endm + +function ff_rgb24ToY_neon, export=1 + rgbToY bgr=0 +endfunc + +function ff_bgr24ToY_neon, export=1 + rgbToY bgr=1 endfunc -.macro rgb24_load_uv_coeff half +.macro rgb_load_uv_coeff half, bgr + .if \bgr + ldr w12, [x6, #12] + ldr w11, [x6, #16] + ldr w10, [x6, #20] + ldr w15, [x6, #24] + ldr w14, [x6, #28] + ldr w13, [x6, #32] + .else ldp w10, w11, [x6, #12] // w10: ru, w11: gu ldp w12, w13, [x6, #20] // w12: bu, w13: rv ldp w14, w15, [x6, #28] // w14: gv, w15: bv + .endif .if \half mov w9, #512 movk w9, #128, lsl #16 // w9: const_offset @@ -105,21 +130,22 @@ endfunc dup v6.4s, w9 .endm -function ff_rgb24ToUV_half_neon, export=1 +.macro rgbToUV_half bgr cmp w5, #0 // check width > 0 b.le 3f cmp w5, #8 - rgb24_load_uv_coeff half=1 + rgb_load_uv_coeff half=1, bgr=\bgr b.lt 2f + // The following comments assume RGB order. The logic for RGB and BGR is the same. 1: ld3 { v16.16b, v17.16b, v18.16b }, [x3] uaddlp v19.8h, v16.16b // v19: r uaddlp v20.8h, v17.16b // v20: g uaddlp v21.8h, v18.16b // v21: b - rgb24_to_yuv_product v19, v20, v21, v22, v23, v16, v0, v1, v2, #10 - rgb24_to_yuv_product v19, v20, v21, v24, v25, v17, v3, v4, v5, #10 + rgb_to_yuv_product v19, v20, v21, v22, v23, v16, v0, v1, v2, #10 + rgb_to_yuv_product v19, v20, v21, v24, v25, v17, v3, v4, v5, #10 sub w5, w5, #8 // width -= 8 add x3, x3, #48 // src += 48 cmp w5, #8 // width >= 8 ? @@ -156,21 +182,30 @@ function ff_rgb24ToUV_half_neon, export=1 cbnz w5, 2b 3: ret +.endm + +function ff_rgb24ToUV_half_neon, export=1 + rgbToUV_half bgr=0 endfunc -function ff_rgb24ToUV_neon, export=1 +function ff_bgr24ToUV_half_neon, export=1 + rgbToUV_half bgr=1 +endfunc + +.macro rgbToUV bgr cmp w5, #0 // check width > 0 b.le 3f cmp w5, #16 - rgb24_load_uv_coeff half=0 + rgb_load_uv_coeff half=0, bgr=\bgr b.lt 2f + // The following comments assume RGB order. The logic for RGB and BGR is the same. 1: - rgb24_to_yuv_load_rgb x3 - rgb24_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9 - rgb24_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9 - rgb24_to_yuv_product v19, v20, v21, v25, v26, v18, v3, v4, v5, #9 - rgb24_to_yuv_product v22, v23, v24, v27, v28, v19, v3, v4, v5, #9 + rgb_to_yuv_load_rgb x3 + rgb_to_yuv_product v19, v20, v21, v25, v26, v16, v0, v1, v2, #9 + rgb_to_yuv_product v22, v23, v24, v27, v28, v17, v0, v1, v2, #9 + rgb_to_yuv_product v19, v20, v21, v25, v26, v18, v3, v4, v5, #9 + rgb_to_yuv_product v22, v23, v24, v27, v28, v19, v3, v4, v5, #9 sub w5, w5, #16 add x3, x3, #48 // src += 48 cmp w5, #16 @@ -199,4 +234,12 @@ function ff_rgb24ToUV_neon, export=1 cbnz w5, 2b 3: ret +.endm + +function ff_rgb24ToUV_neon, export=1 + rgbToUV bgr=0 +endfunc + +function ff_bgr24ToUV_neon, export=1 + rgbToUV bgr=1 endfunc diff --git a/libswscale/aarch64/swscale.c b/libswscale/aarch64/swscale.c index 4c4ea39dc1..ce70dbedcc 100644 --- a/libswscale/aarch64/swscale.c +++ b/libswscale/aarch64/swscale.c @@ -201,19 +201,18 @@ void ff_yuv2plane1_8_neon( default: break; \ } -void ff_rgb24ToY_neon(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, - const uint8_t *unused2, int width, - uint32_t *rgb2yuv, void *opq); - -void ff_rgb24ToUV_neon(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, - const uint8_t *src1, - const uint8_t *src2, int width, uint32_t *rgb2yuv, - void *opq); - -void ff_rgb24ToUV_half_neon(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, - const uint8_t *src1, - const uint8_t *src2, int width, uint32_t *rgb2yuv, - void *opq); +#define NEON_INPUT(name) \ +void ff_##name##ToY_neon(uint8_t *dst, const uint8_t *src, const uint8_t *, \ + const uint8_t *, int w, uint32_t *coeffs, void *); \ +void ff_##name##ToUV_neon(uint8_t *, uint8_t *, const uint8_t *, \ + const uint8_t *, const uint8_t *, int w, \ + uint32_t *coeffs, void *); \ +void ff_##name##ToUV_half_neon(uint8_t *, uint8_t *, const uint8_t *, \ + const uint8_t *, const uint8_t *, int w, \ + uint32_t *coeffs, void *) + +NEON_INPUT(bgr24); +NEON_INPUT(rgb24); av_cold void ff_sws_init_swscale_aarch64(SwsContext *c) { @@ -227,6 +226,13 @@ av_cold void ff_sws_init_swscale_aarch64(SwsContext *c) c->yuv2planeX = ff_yuv2planeX_8_neon; } switch (c->srcFormat) { + case AV_PIX_FMT_BGR24: + c->lumToYV12 = ff_bgr24ToY_neon; + if (c->chrSrcHSubSample) + c->chrToYV12 = ff_bgr24ToUV_half_neon; + else + c->chrToYV12 = ff_bgr24ToUV_neon; + break; case AV_PIX_FMT_RGB24: c->lumToYV12 = ff_rgb24ToY_neon; if (c->chrSrcHSubSample) -- 2.42.0 _______________________________________________ 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 reply other threads:[~2024-06-15 9:57 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-06-15 9:57 Zhao Zhili [this message] 2024-06-18 20:32 ` Martin Storsjö
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=tencent_CAA62D729A6C40E69AC29F10ABDA4E0A7008@qq.com \ --to=quinkblack@foxmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=zhilizhao@tencent.com \ /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