From patchwork Mon Jun 24 13:02:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 50122 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ae71:0:b0:482:c625:d099 with SMTP id w17csp1993037vqz; Mon, 24 Jun 2024 06:02:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVWFbqwVlUlcQEoWAM8NZmuM12jV9ZNg0VLOrP6mZ6HIo6N5LeazD42hTftyzwVqDhQZifIl83xnSPZ0A84rv0BJ1sew4p53IJpmg== X-Google-Smtp-Source: AGHT+IE5HGkG8Sqmq/MeB8Mw5siwiIurvOdqC+jPMC5oAHc4oiuaNyBAjVBeO69P/QfB78ToZMuM X-Received: by 2002:a50:a6d9:0:b0:57c:571f:e52d with SMTP id 4fb4d7f45d1cf-57d4a2e9bfamr3857034a12.36.1719234170893; Mon, 24 Jun 2024 06:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719234170; cv=none; d=google.com; s=arc-20160816; b=dt4Q/fJvJUypoiwdxdRQtGiekY9jWpJzhTXX5RpHRycgKdOnl4d7NVoFw7vQdJzc8O /gsoGRTD86fCEhwDBV6tgSEwA5tTczFPXujpRHVvdBYNo0OGiUTOvNhnWj+bgYRb4l0m 2+HytJoLRdE7z5PqesFHwVwx1L4YSPnn4hIwOlPgwJPwKCch22/l/C48HIiQTvERV7lh xRiOFuSRMIgR8HenHAILAvjmUzjDFB1XSqPneBcsZwL/ueuPBb1XFrsB+PTaqstE5WgF BLXAfTdahmAWbkv8ieS55/CfKbSE67vgXsmR7GOU9CYRRljo7Oftq/2zcZ8+ufrU9EaK gXbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=ouEp7hUAXA0SlC/Cmg9BVCtk0eIYANhb9cdNHO06Pcw=; fh=HnHYuZ9XgUo86ZRXTLWWmQxhslYEI9B9taZ5X1DLFfc=; b=qQqrVNxPnFWEj7CslqP5PB+N5to4mTJJhUBVWDrS8hyW5jyTZDSK2oKD2n7kcRW2g9 Gy4MCDfiiC07NoV4d8nMpkU9uJQmYY3Or6A9fIpU6du1oAHMdv+X0iEe371MUbmsYPmp oqKF/BGpWC33AlW0E338wuNiL68x8BdX6Y9ADlxkikFl7KRe4NfF2R/Ip3M67aJoc0UZ TNRfYkpev0f84jBulXDk3tpaIEJ3DFPPud003UywaluYT8OYDlzsgbeC6CP1aJmwfKOj yQKSDuDJa3KK/bXuFVVGk4UHusRpxql0YgYnfK99Poh4M+EBnamHh6l+ixF67kGdU5I4 mHUg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=mj+MjrGL; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-57d434e3836si2610691a12.379.2024.06.24.06.02.50; Mon, 24 Jun 2024 06:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=mj+MjrGL; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8D6F268D641; Mon, 24 Jun 2024 16:02:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2043468D0E4 for ; Mon, 24 Jun 2024 16:02:28 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1719234139; bh=SB48REO2xZOpLudWpwnGscOxaMpzCDFZ5LtB/U4iGMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mj+MjrGL5jTlDwE2Sj0G3Ldng6PZjCIbt7dyq83Now5JSMpzoDtZnnnMKrVVBoIUq 4kquZqjlMgE4SbOrxhf5jtcdu3MXBHNSbcFXgP81CeCHj3i1BNhsmeQvYxicO6HnbS Gww5qGGXUwuUOtvt2MbLEbxJZh7QBQqIo7zJL4xg= Received: from ZHILIZHAO-MB1.tencent.com ([119.147.10.191]) by newxmesmtplogicsvrszb9-1.qq.com (NewEsmtp) with SMTP id 903582A; Mon, 24 Jun 2024 21:02:16 +0800 X-QQ-mid: xmsmtpt1719234137tncjpc36l Message-ID: X-QQ-XMAILINFO: OQhZ3T0tjf0aFdI8CfCcq2tRPlbrGRTy6rZc0SBBnC9XicVLxsr7doq6KLDWAG G+ZFY4S+31iV2ftHBDFPGoxFFFWhbOC9cBh/5z4zV5VWR9HZziFrNBufpyj1lrfxf0vnhSqDA3nl AvsSyNYCWUvWsrAXvc8Z/o7yMRyM4ZlwlAU/TosGIe7UeRq6718YL007cX5frSz7BDC4ucv+7GnN u7AafSrwfMmEVQKxswwE4LSbxNRHo6k1j5/yPCI30Mut0D2fl4iC7FjDwFbkRbeduTSxNHhGkvyF ZDuqARl10CssZm6z3DwQfCD05zKM2UHYZqRz7yNKr+lLIAw4+G6AiMBdWvyAgFn+nc6TfCSAdxuj +AVfsTzNHWqpYTaRID4hHEY+1qlSYEzfPOsZLdHqusdqB0r/dbMwmM3awg9hqI1tuDNrIW1VE5pF jmC5eXp1MYaPhvBxuWt+JODy6DGXXjvlVVMmxEvdXmz1N24ul2fpvQEo54cbIWrQ2Nd63lN/n3UO aovgBQJO59TF45o+/Cls5QSZOFK1qioVw6YiLrONU8hlqilLU9yiVUXHR4UxBYcBtgYfSGaXP8UQ UWG5SuGzdLAQ4ibcBrs+Hvhzon6mNbhPK1kEK0ZI0QI5sIzCi6SDxM50GC8xdooFOqHCAMhalLzb oB1wjw/0Upo+Kozr+lHWW5/xeaqYKXOGswwn0B6K+fSYFb3aEToTgVFwv67jJQkfzVjfqa/oVYqx SDsxj+fYDMiAznmliysl2SouK/Phg3jZQV/WejATgm3o5N3RVVf6K3pnG8eGSBr7wHVkSfMEWVt2 itrL76puQak0clv0hhx1fmuR0klwerpbxeQmRLK0fWjrcqzeHcwo8+FACuUKHkinTXZSyPj5vs1Y b+Ag3dOmh1qrkYjUB5yFuYQRdzF2IoBe8krYMRDRx5qwiMh6GyJW0QnM/t5I2EbXyggP3t73eN3G 9/+yR+sFTYrQnd3ThJW3PmLeVmn6RK2a9Hy8m98PEd1MYC2gjSuHr1NVweXEaKsv2U4HWUY4T6hQ zEiOnj0SEQaq8apMFrT1dTyoHyGZg= X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Jun 2024 21:02:12 +0800 X-OQ-MSGID: <20240624130213.71634-2-quinkblack@foxmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240624130213.71634-1-quinkblack@foxmail.com> References: <20240624130213.71634-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 2/3] swscale/aarch64: Add bgra/rgba to yuv X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: V6x+v4eDI/13 From: Zhao Zhili Test on Apple M1 with kperf : -O3 : -O3 -fno-vectorize bgra_to_uv_8_c : 13.4 : 27.5 bgra_to_uv_8_neon : 37.4 : 41.7 bgra_to_uv_128_c : 155.9 : 550.2 bgra_to_uv_128_neon : 91.7 : 92.7 bgra_to_uv_1080_c : 1173.2 : 4558.2 bgra_to_uv_1080_neon : 822.7 : 809.5 bgra_to_uv_1920_c : 2078.2 : 8115.2 bgra_to_uv_1920_neon : 1437.7 : 1438.7 bgra_to_uv_half_8_c : 17.9 : 14.2 bgra_to_uv_half_8_neon : 37.4 : 10.5 bgra_to_uv_half_128_c : 103.9 : 326.0 bgra_to_uv_half_128_neon : 73.9 : 68.7 bgra_to_uv_half_1080_c : 850.2 : 3732.0 bgra_to_uv_half_1080_neon : 484.2 : 490.0 bgra_to_uv_half_1920_c : 1479.2 : 4942.7 bgra_to_uv_half_1920_neon : 824.2 : 824.7 bgra_to_y_8_c : 8.2 : 29.5 bgra_to_y_8_neon : 18.2 : 32.7 bgra_to_y_128_c : 101.4 : 361.5 bgra_to_y_128_neon : 74.9 : 73.7 bgra_to_y_1080_c : 739.4 : 3018.0 bgra_to_y_1080_neon : 613.4 : 544.2 bgra_to_y_1920_c : 1298.7 : 5326.0 bgra_to_y_1920_neon : 918.7 : 934.2 --- libswscale/aarch64/input.S | 68 +++++++++++++++++++++++++++--------- libswscale/aarch64/swscale.c | 16 +++++++++ 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/libswscale/aarch64/input.S b/libswscale/aarch64/input.S index 2cfec4cb6a..ce5b042371 100644 --- a/libswscale/aarch64/input.S +++ b/libswscale/aarch64/input.S @@ -20,8 +20,12 @@ #include "libavutil/aarch64/asm.S" -.macro rgb_to_yuv_load_rgb src +.macro rgb_to_yuv_load_rgb src, element=3 + .if \element == 3 ld3 { v16.16b, v17.16b, v18.16b }, [\src] + .else + ld4 { v16.16b, v17.16b, v18.16b, v19.16b }, [\src] + .endif uxtl v19.8h, v16.8b // v19: r uxtl v20.8h, v17.8b // v20: g uxtl v21.8h, v18.8b // v21: b @@ -43,7 +47,8 @@ sqshrn2 \dst\().8h, \dst2\().4s, \right_shift // dst_higher_half = dst2 >> right_shift .endm -function ff_bgr24ToY_neon, export=1 +.macro rgbToY_neon fmt_bgr, fmt_rgb, element +function ff_\fmt_bgr\()ToY_neon, export=1 cmp w4, #0 // check width > 0 ldp w12, w11, [x5] // w12: ry, w11: gy ldr w10, [x5, #8] // w10: by @@ -51,7 +56,7 @@ function ff_bgr24ToY_neon, export=1 ret endfunc -function ff_rgb24ToY_neon, export=1 +function ff_\fmt_rgb\()ToY_neon, export=1 cmp w4, #0 // check width > 0 ldp w10, w11, [x5] // w10: ry, w11: gy ldr w12, [x5, #8] // w12: by @@ -67,11 +72,11 @@ function ff_rgb24ToY_neon, export=1 dup v2.8h, w12 b.lt 2f 1: - rgb_to_yuv_load_rgb x1 + rgb_to_yuv_load_rgb x1, \element 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 + add x1, x1, #(16*\element) cmp w4, #16 // width >= 16 ? stp q16, q17, [x0], #32 // store to dst b.ge 1b @@ -86,12 +91,17 @@ function ff_rgb24ToY_neon, export=1 smaddl x13, w15, w12, x13 // x13 += by * b asr w13, w13, #9 // x13 >>= 9 sub w4, w4, #1 // width-- - add x1, x1, #3 // src += 3 + add x1, x1, #\element strh w13, [x0], #2 // store to dst cbnz w4, 2b 3: ret endfunc +.endm + +rgbToY_neon bgr24, rgb24, element=3 + +rgbToY_neon bgra32, rgba32, element=4 .macro rgb_set_uv_coeff half .if \half @@ -110,7 +120,8 @@ endfunc dup v6.4s, w9 .endm -function ff_bgr24ToUV_half_neon, export=1 +.macro rgbToUV_half_neon fmt_bgr, fmt_rgb, element +function ff_\fmt_bgr\()ToUV_half_neon, export=1 cmp w5, #0 // check width > 0 b.le 3f @@ -120,7 +131,7 @@ function ff_bgr24ToUV_half_neon, export=1 b 4f endfunc -function ff_rgb24ToUV_half_neon, export=1 +function ff_\fmt_rgb\()ToUV_half_neon, export=1 cmp w5, #0 // check width > 0 b.le 3f @@ -132,7 +143,11 @@ function ff_rgb24ToUV_half_neon, export=1 rgb_set_uv_coeff half=1 b.lt 2f 1: + .if \element == 3 ld3 { v16.16b, v17.16b, v18.16b }, [x3] + .else + ld4 { v16.16b, v17.16b, v18.16b, v19.16b }, [x3] + .endif uaddlp v19.8h, v16.16b // v19: r uaddlp v20.8h, v17.16b // v20: g uaddlp v21.8h, v18.16b // v21: b @@ -140,7 +155,7 @@ function ff_rgb24ToUV_half_neon, export=1 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 + add x3, x3, #(16*\element) cmp w5, #8 // width >= 8 ? str q16, [x0], #16 // store dst_u str q17, [x1], #16 // store dst_v @@ -148,9 +163,10 @@ function ff_rgb24ToUV_half_neon, export=1 cbz w5, 3f 2: ldrb w2, [x3] // w2: r1 - ldrb w4, [x3, #3] // w4: r2 + ldrb w4, [x3, #\element] // w4: r2 add w2, w2, w4 // w2 = r1 + r2 + .if \element == 3 ldrb w4, [x3, #1] // w4: g1 ldrb w7, [x3, #4] // w7: g2 add w4, w4, w7 // w4 = g1 + g2 @@ -158,6 +174,15 @@ function ff_rgb24ToUV_half_neon, export=1 ldrb w7, [x3, #2] // w7: b1 ldrb w8, [x3, #5] // w8: b2 add w7, w7, w8 // w7 = b1 + b2 + .else + ldrb w4, [x3, #1] // w4: g1 + ldrb w7, [x3, #5] // w7: g2 + add w4, w4, w7 // w4 = g1 + g2 + + ldrb w7, [x3, #2] // w7: b1 + ldrb w8, [x3, #6] // w8: b2 + add w7, w7, w8 // w7 = b1 + b2 + .endif smaddl x8, w2, w10, x9 // dst_u = ru * r + const_offset smaddl x8, w4, w11, x8 // dst_u += gu * g @@ -170,14 +195,20 @@ function ff_rgb24ToUV_half_neon, export=1 smaddl x8, w7, w15, x8 // dst_v += bv * b asr x8, x8, #10 // dst_v >>= 10 sub w5, w5, #1 - add x3, x3, #6 // src += 6 + add x3, x3, #(2*\element) strh w8, [x1], #2 // store dst_v cbnz w5, 2b 3: ret endfunc +.endm -function ff_bgr24ToUV_neon, export=1 +rgbToUV_half_neon bgr24, rgb24, element=3 + +rgbToUV_half_neon bgra32, rgba32, element=4 + +.macro rgbToUV_neon fmt_bgr, fmt_rgb, element +function ff_\fmt_bgr\()ToUV_neon, export=1 cmp w5, #0 // check width > 0 b.le 3f @@ -187,7 +218,7 @@ function ff_bgr24ToUV_neon, export=1 b 4f endfunc -function ff_rgb24ToUV_neon, export=1 +function ff_\fmt_rgb\()ToUV_neon, export=1 cmp w5, #0 // check width > 0 b.le 3f @@ -199,13 +230,13 @@ function ff_rgb24ToUV_neon, export=1 rgb_set_uv_coeff half=0 b.lt 2f 1: - rgb_to_yuv_load_rgb x3 + rgb_to_yuv_load_rgb x3, \element 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 + add x3, x3, #(16*\element) cmp w5, #16 stp q16, q17, [x0], #32 // store to dst_u stp q18, q19, [x1], #32 // store to dst_v @@ -227,9 +258,14 @@ function ff_rgb24ToUV_neon, export=1 smaddl x8, w4, w15, x8 // x8 += bv * b asr w8, w8, #9 // x8 >>= 9 sub w5, w5, #1 // width-- - add x3, x3, #3 // src += 3 + add x3, x3, #\element strh w8, [x1], #2 // store to dst_v cbnz w5, 2b 3: ret endfunc +.endm + +rgbToUV_neon bgr24, rgb24, element=3 + +rgbToUV_neon bgra32, rgba32, element=4 diff --git a/libswscale/aarch64/swscale.c b/libswscale/aarch64/swscale.c index c6594944c3..92af662014 100644 --- a/libswscale/aarch64/swscale.c +++ b/libswscale/aarch64/swscale.c @@ -212,7 +212,9 @@ void ff_##name##ToUV_half_neon(uint8_t *, uint8_t *, const uint8_t *, \ uint32_t *coeffs, void *) NEON_INPUT(bgr24); +NEON_INPUT(bgra32); NEON_INPUT(rgb24); +NEON_INPUT(rgba32); void ff_lumRangeFromJpeg_neon(int16_t *dst, int width); void ff_chrRangeFromJpeg_neon(int16_t *dstU, int16_t *dstV, int width); @@ -253,6 +255,13 @@ av_cold void ff_sws_init_swscale_aarch64(SwsContext *c) else c->chrToYV12 = ff_bgr24ToUV_neon; break; + case AV_PIX_FMT_BGRA: + c->lumToYV12 = ff_bgra32ToY_neon; + if (c->chrSrcHSubSample) + c->chrToYV12 = ff_bgra32ToUV_half_neon; + else + c->chrToYV12 = ff_bgra32ToUV_neon; + break; case AV_PIX_FMT_RGB24: c->lumToYV12 = ff_rgb24ToY_neon; if (c->chrSrcHSubSample) @@ -260,6 +269,13 @@ av_cold void ff_sws_init_swscale_aarch64(SwsContext *c) else c->chrToYV12 = ff_rgb24ToUV_neon; break; + case AV_PIX_FMT_RGBA: + c->lumToYV12 = ff_rgba32ToY_neon; + if (c->chrSrcHSubSample) + c->chrToYV12 = ff_rgba32ToUV_half_neon; + else + c->chrToYV12 = ff_rgba32ToUV_neon; + break; default: break; }