diff mbox series

[FFmpeg-devel,v2,4/5] swscale/x86/yuv2rgb: add ssse3 yuv42{0, 2}p -> gbrp unscaled colorspace converters

Message ID 20240806105106.59866-5-ramiro.polla@gmail.com
State New
Headers show
Series swscale/yuv2rgb: add yuv42{0, 2}p -> gbrp unscaled colorspace converters | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Ramiro Polla Aug. 6, 2024, 10:51 a.m. UTC
Note: this implementation is limited to x86_64 due to general purpose
      register pressure.

checkasm --bench on an Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz:
yuv420p_gbrp_8_c: 118.5
yuv420p_gbrp_8_ssse3: 93.3
yuv420p_gbrp_128_c: 1068.3
yuv420p_gbrp_128_ssse3: 319.3
yuv420p_gbrp_1080_c: 8841.8
yuv420p_gbrp_1080_ssse3: 2211.8
yuv420p_gbrp_1920_c: 15903.8
yuv420p_gbrp_1920_ssse3: 3814.3
yuv422p_gbrp_8_c: 144.8
yuv422p_gbrp_8_ssse3: 93.8
yuv422p_gbrp_128_c: 1395.8
yuv422p_gbrp_128_ssse3: 313.0
yuv422p_gbrp_1080_c: 11551.5
yuv422p_gbrp_1080_ssse3: 2240.8
yuv422p_gbrp_1920_c: 20585.3
yuv422p_gbrp_1920_ssse3: 5249.5
yuva420p_gbrp_8_c: 117.5
yuva420p_gbrp_8_ssse3: 92.0
yuva420p_gbrp_128_c: 1593.0
yuva420p_gbrp_128_ssse3: 319.3
yuva420p_gbrp_1080_c: 8694.5
yuva420p_gbrp_1080_ssse3: 2186.0
yuva420p_gbrp_1920_c: 15946.5
yuva420p_gbrp_1920_ssse3: 3805.3
---
 libswscale/x86/yuv2rgb.c     | 39 ++++++++++++++++++++++++++++++++++++
 libswscale/x86/yuv_2_rgb.asm | 24 +++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c
index 68e903c6ad..2a4505fa90 100644
--- a/libswscale/x86/yuv2rgb.c
+++ b/libswscale/x86/yuv2rgb.c
@@ -79,6 +79,12 @@  extern void ff_yuva_420_rgb32_ssse3(x86_reg index, uint8_t *image, const uint8_t
 extern void ff_yuva_420_bgr32_ssse3(x86_reg index, uint8_t *image, const uint8_t *pu_index,
                                     const uint8_t *pv_index, const uint64_t *pointer_c_dither,
                                     const uint8_t *py_2index, const uint8_t *pa_2index);
+#if ARCH_X86_64
+extern void ff_yuv_420_gbrp24_ssse3(x86_reg index, uint8_t *image, uint8_t *dst_b, uint8_t *dst_r,
+                                    const uint8_t *pu_index, const uint8_t *pv_index,
+                                    const uint64_t *pointer_c_dither,
+                                    const uint8_t *py_2index);
+#endif
 
 static inline int yuv420_rgb15_ssse3(SwsContext *c, const uint8_t *src[],
                                      int srcStride[],
@@ -201,6 +207,35 @@  static inline int yuv420_bgr24_ssse3(SwsContext *c, const uint8_t *src[],
     return srcSliceH;
 }
 
+#if ARCH_X86_64
+static inline int yuv420_gbrp_ssse3(SwsContext *c, const uint8_t *src[],
+                                    int srcStride[],
+                                    int srcSliceY, int srcSliceH,
+                                    uint8_t *dst[], int dstStride[])
+{
+    int y, h_size, vshift;
+
+    h_size = (c->dstW + 7) & ~7;
+    if (h_size * 3 > FFABS(dstStride[0]))
+        h_size -= 8;
+
+    vshift = c->srcFormat != AV_PIX_FMT_YUV422P;
+
+    for (y = 0; y < srcSliceH; y++) {
+        uint8_t *dst_g    = dst[0] + (y + srcSliceY) * dstStride[0];
+        uint8_t *dst_b    = dst[1] + (y + srcSliceY) * dstStride[1];
+        uint8_t *dst_r    = dst[2] + (y + srcSliceY) * dstStride[2];
+        const uint8_t *py = src[0] +               y * srcStride[0];
+        const uint8_t *pu = src[1] +   (y >> vshift) * srcStride[1];
+        const uint8_t *pv = src[2] +   (y >> vshift) * srcStride[2];
+        x86_reg index = -h_size / 2;
+
+        ff_yuv_420_gbrp24_ssse3(index, dst_g, dst_b, dst_r, pu - index, pv - index, &(c->redDither), py - 2 * index);
+    }
+    return srcSliceH;
+}
+#endif
+
 #endif /* HAVE_X86ASM */
 
 av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
@@ -234,6 +269,10 @@  av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
             return yuv420_rgb16_ssse3;
         case AV_PIX_FMT_RGB555:
             return yuv420_rgb15_ssse3;
+#if ARCH_X86_64
+        case AV_PIX_FMT_GBRP:
+            return yuv420_gbrp_ssse3;
+#endif
         }
     }
 
diff --git a/libswscale/x86/yuv_2_rgb.asm b/libswscale/x86/yuv_2_rgb.asm
index b67ab162d2..eeb1d25942 100644
--- a/libswscale/x86/yuv_2_rgb.asm
+++ b/libswscale/x86/yuv_2_rgb.asm
@@ -32,6 +32,7 @@  mask_dw25  : db  0,  0,  0,  0, -1, -1,  0,  0,  0,  0, -1, -1,  0,  0,  0,  0
 rgb24_shuf1: db  0,  1,  6,  7, 12, 13,  2,  3,  8,  9, 14, 15,  4,  5, 10, 11
 rgb24_shuf2: db 10, 11,  0,  1,  6,  7, 12, 13,  2,  3,  8,  9, 14, 15,  4,  5
 rgb24_shuf3: db  4,  5, 10, 11,  0,  1,  6,  7, 12, 13,  2,  3,  8,  9, 14, 15
+gbrp_shuf  : db  0,  8,  1,  9,  2, 10,  3, 11,  4, 12,  5, 13,  6, 14,  7, 15
 pw_00ff: times 8 dw 255
 pb_f8:   times 16 db 248
 pb_e0:   times 16 db 224
@@ -60,8 +61,13 @@  SECTION .text
     %define GPR_num 6
     %endif
 %else
+    %ifidn %2, gbrp
+    %define parameters index, image, dst_b, dst_r, pu_index, pv_index, pointer_c_dither, py_2index
+    %define GPR_num 8
+    %else
     %define parameters index, image, pu_index, pv_index, pointer_c_dither, py_2index
     %define GPR_num 6
+    %endif
 %endif
 
 %define m_green m2
@@ -172,10 +178,22 @@  cglobal %1_420_%2%3, GPR_num, GPR_num, reg_num, parameters
     paddsw m2, m6 ; G0 G2 G4 G6 ...
 
 %if %3 == 24 ; PACK RGB24
-%define depth 3
     packuswb m0, m3 ; B0 B2 B4 B6 ... B1 B3 B5 B7 ...
     packuswb m1, m5 ; R0 R2 R4 R6 ... R1 R3 R5 R7 ...
     packuswb m2, m7 ; G0 G2 G4 G6 ... G1 G3 G5 G7 ...
+%ifidn %2, gbrp ; PLANAR GBRP
+%define depth 1
+    mova   m4, [gbrp_shuf]
+    pshufb m0, m4
+    pshufb m1, m4
+    pshufb m2, m4
+    movu [imageq], m2
+    movu [dst_bq], m0
+    movu [dst_rq], m1
+    add dst_bq, 8 * depth * time_num
+    add dst_rq, 8 * depth * time_num
+%else
+%define depth 3
     mova m3, m_red
     mova m6, m_blue
     psrldq m_red, 8
@@ -206,6 +224,7 @@  cglobal %1_420_%2%3, GPR_num, GPR_num, reg_num, parameters
     movu [imageq], m0
     movu [imageq + 16], m1
     movu [imageq + 32], m2
+%endif ; PLANAR GBRP
 %else ; PACK RGB15/16/32
     packuswb m0, m1
     packuswb m3, m5
@@ -292,3 +311,6 @@  yuv2rgb_fn yuva, rgb, 32
 yuv2rgb_fn yuva, bgr, 32
 yuv2rgb_fn yuv,  rgb, 15
 yuv2rgb_fn yuv,  rgb, 16
+%if ARCH_X86_64
+yuv2rgb_fn yuv,  gbrp, 24
+%endif