History

wasm/hevc: Add sao_band_filter

hevc_sao_band_8_8_c: 63.0 ( 1.00x) hevc_sao_band_8_8_simd128: 10.4 ( 6.06x) hevc_sao_band_16_8_c: 230.4 ( 1.00x) hevc_sao_band_16_8_simd128: 22.9 (10.07x) hevc_sao_band_32_8_c: 900.4 ( 1.00x) hevc_sao_band_32_8_simd128: 81.5 (11.05x) hevc_sao_band_48_8_c: 2009.1 ( 1.00x) hevc_sao_band_48_8_simd128: 170.2 (11.80x) hevc_sao_band_64_8_c: 3535.0 ( 1.00x) hevc_sao_band_64_8_simd128: 297.5 (11.88x)

Zhao Zhili committed 1 year ago

Commit fe45f551 parent 9c7b0194 files · +165 −1Browse files

Unified · Split

4 files
  1. libavcodec/wasm/hevc/Makefile +2 −1
  2. libavcodec/wasm/hevc/dsp_init.c +7 −0
  3. libavcodec/wasm/hevc/sao.c +114 −0
  4. libavcodec/wasm/hevc/sao.h +42 −0
libavcodec/wasm/hevc/Makefile+2−1
@@ -1,3 +1,4 @@
11 OBJS-$(CONFIG_HEVC_DECODER) += wasm/hevc/dsp_init.o
22
3−SIMD128-OBJS-$(CONFIG_HEVC_DECODER) += wasm/hevc/idct.o
3+SIMD128-OBJS-$(CONFIG_HEVC_DECODER) += wasm/hevc/idct.o \
4+ wasm/hevc/sao.o
libavcodec/wasm/hevc/dsp_init.c+7−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include "libavutil/cpu_internal.h"
2222 #include "libavcodec/hevc/dsp.h"
2323 #include "libavcodec/wasm/hevc/idct.h"
24+#include "libavcodec/wasm/hevc/sao.h"
2425
2526 av_cold void ff_hevc_dsp_init_wasm(HEVCDSPContext *c, const int bit_depth)
2627 {
@@ -35,6 +36,12 @@ av_cold void ff_hevc_dsp_init_wasm(HEVCDSPContext *c, const int bit_depth) · 8 unmodified lines
3536 c->idct[1] = ff_hevc_idct_8x8_8_simd128;
3637 c->idct[2] = ff_hevc_idct_16x16_8_simd128;
3738 c->idct[3] = ff_hevc_idct_32x32_8_simd128;
39+
40+ c->sao_band_filter[0] = ff_hevc_sao_band_filter_8x8_8_simd128;
41+ c->sao_band_filter[1] =
42+ c->sao_band_filter[2] =
43+ c->sao_band_filter[3] =
44+ c->sao_band_filter[4] = ff_hevc_sao_band_filter_16x16_8_simd128;
3845 } else if (bit_depth == 10) {
3946 c->idct[0] = ff_hevc_idct_4x4_10_simd128;
4047 c->idct[1] = ff_hevc_idct_8x8_10_simd128;
libavcodec/wasm/hevc/sao.c+114−0
@@ -0,0 +1,114 @@
1+/*
2+ * Copyright (c) 2025 Zhao Zhili
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include "sao.h"
22+
23+#include <wasm_simd128.h>
24+
25+void ff_hevc_sao_band_filter_8x8_8_simd128(uint8_t *dst, const uint8_t *src,
26+ ptrdiff_t stride_dst,
27+ ptrdiff_t stride_src,
28+ const int16_t *sao_offset_val,
29+ int sao_left_class, int width,
30+ int height)
31+{
32+ int8_t offset_table[32] = {0};
33+ v128_t offset_low, offset_high;
34+
35+ for (int k = 0; k < 4; k++)
36+ offset_table[(k + sao_left_class) & 31] = (int8_t)sao_offset_val[k + 1];
37+
38+ offset_low = wasm_v128_load(offset_table);
39+ offset_high = wasm_v128_load(&offset_table[16]);
40+
41+ for (int y = height; y > 0; y -= 2) {
42+ v128_t src_v, src_high;
43+ v128_t v0, v1;
44+
45+ src_v = wasm_v128_load64_zero(src);
46+ src += stride_src;
47+ src_v = wasm_v128_load64_lane(src, src_v, 1);
48+ src += stride_src;
49+
50+ v0 = wasm_u8x16_shr(src_v, 3);
51+ v1 = wasm_i8x16_sub(v0, wasm_i8x16_const_splat(16));
52+ v0 = wasm_i8x16_swizzle(offset_low, v0);
53+ v1 = wasm_i8x16_swizzle(offset_high, v1);
54+ v0 = wasm_v128_or(v0, v1);
55+ src_high = wasm_u16x8_extend_high_u8x16(src_v);
56+ v1 = wasm_i16x8_extend_high_i8x16(v0);
57+ src_v = wasm_u16x8_extend_low_u8x16(src_v);
58+ v0 = wasm_i16x8_extend_low_i8x16(v0);
59+
60+ v0 = wasm_i16x8_add_sat(src_v, v0);
61+ v1 = wasm_i16x8_add_sat(src_high, v1);
62+ v0 = wasm_u8x16_narrow_i16x8(v0, v1);
63+
64+ wasm_v128_store64_lane(dst, v0, 0);
65+ dst += stride_dst;
66+ wasm_v128_store64_lane(dst, v0, 1);
67+ dst += stride_dst;
68+ }
69+}
70+
71+void ff_hevc_sao_band_filter_16x16_8_simd128(uint8_t *dst, const uint8_t *src,
72+ ptrdiff_t stride_dst,
73+ ptrdiff_t stride_src,
74+ const int16_t *sao_offset_val,
75+ int sao_left_class, int width,
76+ int height)
77+{
78+ int8_t offset_table[32] = {0};
79+ v128_t offset_low, offset_high;
80+
81+ for (int k = 0; k < 4; k++)
82+ offset_table[(k + sao_left_class) & 31] = (int8_t)sao_offset_val[k + 1];
83+
84+ offset_low = wasm_v128_load(offset_table);
85+ offset_high = wasm_v128_load(&offset_table[16]);
86+
87+ for (int y = height; y > 0; y--) {
88+ for (int x = 0; x < width; x += 16) {
89+ v128_t src_v, src_high;
90+ v128_t v0, v1;
91+
92+ src_v = wasm_v128_load(&src[x]);
93+
94+ v0 = wasm_u8x16_shr(src_v, 3);
95+ v1 = wasm_i8x16_sub(v0, wasm_i8x16_const_splat(16));
96+ v0 = wasm_i8x16_swizzle(offset_low, v0);
97+ v1 = wasm_i8x16_swizzle(offset_high, v1);
98+ v0 = wasm_v128_or(v0, v1);
99+ src_high = wasm_u16x8_extend_high_u8x16(src_v);
100+ v1 = wasm_i16x8_extend_high_i8x16(v0);
101+ src_v = wasm_u16x8_extend_low_u8x16(src_v);
102+ v0 = wasm_i16x8_extend_low_i8x16(v0);
103+
104+ v0 = wasm_i16x8_add_sat(src_v, v0);
105+ v1 = wasm_i16x8_add_sat(src_high, v1);
106+ v0 = wasm_u8x16_narrow_i16x8(v0, v1);
107+ wasm_v128_store(&dst[x], v0);
108+ }
109+
110+ dst += stride_dst;
111+ src += stride_src;
112+ }
113+}
114+
libavcodec/wasm/hevc/sao.h+42−0
@@ -0,0 +1,42 @@
1+/*
2+ * Copyright (c) 2025 Zhao Zhili
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#ifndef AVCODEC_WASM_HEVC_SAO_H
22+#define AVCODEC_WASM_HEVC_SAO_H
23+
24+#include <stddef.h>
25+#include <stdint.h>
26+
27+void ff_hevc_sao_band_filter_8x8_8_simd128(uint8_t *_dst, const uint8_t *_src,
28+ ptrdiff_t _stride_dst,
29+ ptrdiff_t _stride_src,
30+ const int16_t *sao_offset_val,
31+ int sao_left_class, int width,
32+ int height);
33+
34+void ff_hevc_sao_band_filter_16x16_8_simd128(uint8_t *_dst, const uint8_t *_src,
35+ ptrdiff_t _stride_dst,
36+ ptrdiff_t _stride_src,
37+ const int16_t *sao_offset_val,
38+ int sao_left_class, int width,
39+ int height);
40+
41+#endif
42+

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