FFmpeg
h264dsp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 J. Dekker <jdek@itanimul.li>
3  * Copyright © 2024 Rémi Denis-Courmont.
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 
24 #include <stdint.h>
25 #include <string.h>
26 
27 #include "libavutil/attributes.h"
28 #include "libavutil/cpu.h"
29 #include "libavutil/riscv/cpu.h"
30 #include "libavcodec/h264dsp.h"
31 
32 extern const struct {
36 
37 void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
38  int alpha, int beta, int8_t *tc0);
39 void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
40  int alpha, int beta, int8_t *tc0);
41 void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
42  int alpha, int beta, int8_t *tc0);
43 void ff_h264_v_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride,
44  int alpha, int beta, int8_t *tc0);
45 void ff_h264_h_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride,
46  int alpha, int beta, int8_t *tc0);
47 void ff_h264_h_loop_filter_chroma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
48  int alpha, int beta,
49  int8_t *tc0);
50 
51 #define IDCT_DEPTH(depth) \
52 void ff_h264_idct_add_##depth##_rvv(uint8_t *d, int16_t *s, int stride); \
53 void ff_h264_idct8_add_##depth##_rvv(uint8_t *d, int16_t *s, int stride); \
54 void ff_h264_idct4_dc_add_##depth##_rvv(uint8_t *, int16_t *, int); \
55 void ff_h264_idct8_dc_add_##depth##_rvv(uint8_t *, int16_t *, int); \
56 void ff_h264_idct_add16_##depth##_rvv(uint8_t *d, const int *soffset, \
57  int16_t *s, int stride, \
58  const uint8_t nnzc[5 * 8]); \
59 void ff_h264_idct_add16intra_##depth##_rvv(uint8_t *d, const int *soffset, \
60  int16_t *s, int stride, \
61  const uint8_t nnzc[5 * 8]); \
62 void ff_h264_idct8_add4_##depth##_rvv(uint8_t *d, const int *soffset, \
63  int16_t *s, int stride, \
64  const uint8_t nnzc[5 * 8]); \
65 void ff_h264_idct4_add8_##depth##_rvv(uint8_t **d, const int *soffset, \
66  int16_t *s, int stride, \
67  const uint8_t nnzc[5 * 8]); \
68 void ff_h264_idct4_add8_422_##depth##_rvv(uint8_t **d, const int *soffset, \
69  int16_t *s, int stride, \
70  const uint8_t nnzc[5 * 8]);
71 
72 IDCT_DEPTH(8)
73 IDCT_DEPTH(9)
74 IDCT_DEPTH(10)
75 IDCT_DEPTH(12)
76 IDCT_DEPTH(14)
77 #undef IDCT_DEPTH
78 
79 void ff_h264_add_pixels8_8_rvv(uint8_t *dst, int16_t *block, int stride);
80 void ff_h264_add_pixels4_8_rvv(uint8_t *dst, int16_t *block, int stride);
81 void ff_h264_add_pixels8_16_rvv(uint8_t *dst, int16_t *block, int stride);
82 void ff_h264_add_pixels4_16_rvv(uint8_t *dst, int16_t *block, int stride);
83 
84 extern int ff_startcode_find_candidate_rvb(const uint8_t *, int);
85 extern int ff_startcode_find_candidate_rvv(const uint8_t *, int);
86 
88  const int chroma_format_idc)
89 {
90 #if HAVE_RV
91  int flags = av_get_cpu_flags();
92 
95 # if HAVE_RVV
96  if (flags & AV_CPU_FLAG_RVV_I32) {
97  const bool zvl128b = ff_rv_vlen_least(128);
98 
99  if (bit_depth == 8) {
100  if (zvl128b) {
101  if (flags & AV_CPU_FLAG_RVB)
102  dsp->weight_h264_pixels_tab[0] =
103  ff_h264_weight_funcs_8_rvv[0].weight;
104  dsp->biweight_h264_pixels_tab[0] =
105  ff_h264_weight_funcs_8_rvv[0].biweight;
106  }
107  if (flags & AV_CPU_FLAG_RVV_I64) {
108  dsp->weight_h264_pixels_tab[1] =
109  ff_h264_weight_funcs_8_rvv[1].weight;
110  dsp->biweight_h264_pixels_tab[1] =
111  ff_h264_weight_funcs_8_rvv[1].biweight;
112  }
113  dsp->weight_h264_pixels_tab[2] =
114  ff_h264_weight_funcs_8_rvv[2].weight;
115  dsp->biweight_h264_pixels_tab[2] =
116  ff_h264_weight_funcs_8_rvv[2].biweight;
117  dsp->weight_h264_pixels_tab[3] =
118  ff_h264_weight_funcs_8_rvv[3].weight;
119  dsp->biweight_h264_pixels_tab[3] =
120  ff_h264_weight_funcs_8_rvv[3].biweight;
121  }
122 
123  if (bit_depth == 8 && zvl128b) {
130  if (chroma_format_idc <= 1) {
135  }
136 
137  dsp->h264_idct_add = ff_h264_idct_add_8_rvv;
138  dsp->h264_idct8_add = ff_h264_idct8_add_8_rvv;
139  if (flags & AV_CPU_FLAG_RVB) {
140  dsp->h264_idct_dc_add = ff_h264_idct4_dc_add_8_rvv;
141  dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
142  dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
143 # if __riscv_xlen == 64
144  dsp->h264_idct8_add4 = ff_h264_idct8_add4_8_rvv;
145  if (chroma_format_idc <= 1)
146  dsp->h264_idct_add8 = ff_h264_idct4_add8_8_rvv;
147  else
148  dsp->h264_idct_add8 = ff_h264_idct4_add8_422_8_rvv;
149 # endif
150  }
151  if (flags & AV_CPU_FLAG_RVV_I64) {
153  if (flags & AV_CPU_FLAG_RVB)
154  dsp->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_rvv;
155  }
157  }
158 
159 #define IDCT_DEPTH(depth) \
160  if (bit_depth == depth) { \
161  if (zvl128b) \
162  dsp->h264_idct_add = ff_h264_idct_add_##depth##_rvv; \
163  if (flags & AV_CPU_FLAG_RVB) \
164  dsp->h264_idct8_add = ff_h264_idct8_add_##depth##_rvv; \
165  if (zvl128b && (flags & AV_CPU_FLAG_RVB)) { \
166  dsp->h264_idct_dc_add = ff_h264_idct4_dc_add_##depth##_rvv; \
167  dsp->h264_idct8_dc_add = ff_h264_idct8_dc_add_##depth##_rvv; \
168  dsp->h264_idct_add16 = ff_h264_idct_add16_##depth##_rvv; \
169  dsp->h264_idct_add16intra = \
170  ff_h264_idct_add16intra_##depth##_rvv; \
171  if (__riscv_xlen == 64) { \
172  if (chroma_format_idc <= 1) \
173  dsp->h264_idct_add8 = \
174  ff_h264_idct4_add8_##depth##_rvv; \
175  else \
176  dsp->h264_idct_add8 = \
177  ff_h264_idct4_add8_422_##depth##_rvv; \
178  } \
179  } \
180  if (__riscv_xlen == 64 && (flags & AV_CPU_FLAG_RVB)) \
181  dsp->h264_idct8_add4 = ff_h264_idct8_add4_##depth##_rvv; \
182  }
183 
184  IDCT_DEPTH(9)
185  IDCT_DEPTH(10)
186  IDCT_DEPTH(12)
187  IDCT_DEPTH(14)
188 
189  if (bit_depth > 8 && zvl128b) {
193  }
194 
196  }
197 # endif
198 #endif
199 }
ff_h264_v_loop_filter_luma_8_rvv
void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
AV_CPU_FLAG_RVB_BASIC
#define AV_CPU_FLAG_RVB_BASIC
Basic bit-manipulations.
Definition: cpu.h:96
H264DSPContext::h264_idct_add8
void(* h264_idct_add8)(uint8_t **dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[15 *8])
Definition: h264dsp.h:96
ff_h264_add_pixels4_8_rvv
void ff_h264_add_pixels4_8_rvv(uint8_t *dst, int16_t *block, int stride)
h264_biweight_func
void(* h264_biweight_func)(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int height, int log2_denom, int weightd, int weights, int offset)
Definition: h264dsp.h:35
ff_h264dsp_init_riscv
av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth, const int chroma_format_idc)
Definition: h264dsp_init.c:87
ff_h264_v_loop_filter_chroma_8_rvv
void ff_h264_v_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
H264DSPContext::h264_add_pixels8_clear
void(* h264_add_pixels8_clear)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:107
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:107
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
AV_CPU_FLAG_RVB
#define AV_CPU_FLAG_RVB
B (bit manipulations)
Definition: cpu.h:102
H264DSPContext::h264_idct_add16
void(* h264_idct_add16)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 *8])
Definition: h264dsp.h:90
H264DSPContext::h264_v_loop_filter_chroma
void(* h264_v_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:61
weight
const h264_weight_func weight
Definition: h264dsp_init.c:33
av_cold
#define av_cold
Definition: attributes.h:90
ff_rv_vlen_least
static bool ff_rv_vlen_least(unsigned int bits)
Checks that the vector bit-size is at least the given value.
Definition: cpu.h:65
H264DSPContext::biweight_h264_pixels_tab
h264_biweight_func biweight_h264_pixels_tab[4]
Definition: h264dsp.h:45
cpu.h
ff_startcode_find_candidate_rvv
int ff_startcode_find_candidate_rvv(const uint8_t *, int)
ff_h264_h_loop_filter_luma_mbaff_8_rvv
void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
ff_h264_add_pixels4_16_rvv
void ff_h264_add_pixels4_16_rvv(uint8_t *dst, int16_t *block, int stride)
H264DSPContext::h264_h_loop_filter_chroma_mbaff
void(* h264_h_loop_filter_chroma_mbaff)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:65
H264DSPContext::startcode_find_candidate
int(* startcode_find_candidate)(const uint8_t *buf, int size)
Search buf from the start for up to size bytes.
Definition: h264dsp.h:117
H264DSPContext::h264_idct8_dc_add
void(* h264_idct8_dc_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:87
H264DSPContext::h264_h_loop_filter_luma
void(* h264_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:50
h264dsp.h
ff_h264_add_pixels8_16_rvv
void ff_h264_add_pixels8_16_rvv(uint8_t *dst, int16_t *block, int stride)
H264DSPContext
Context for storing H.264 DSP functions.
Definition: h264dsp.h:42
H264DSPContext::h264_h_loop_filter_luma_mbaff
void(* h264_h_loop_filter_luma_mbaff)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:52
h264_weight_func
void(* h264_weight_func)(uint8_t *block, ptrdiff_t stride, int height, int log2_denom, int weight, int offset)
Definition: h264dsp.h:33
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
cpu.h
H264DSPContext::weight_h264_pixels_tab
h264_weight_func weight_h264_pixels_tab[4]
Definition: h264dsp.h:44
attributes.h
AV_CPU_FLAG_RVV_I32
#define AV_CPU_FLAG_RVV_I32
Vectors of 8/16/32-bit int's *‍/.
Definition: cpu.h:92
H264DSPContext::h264_idct8_add
void(* h264_idct8_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:83
ff_h264_h_loop_filter_chroma_mbaff_8_rvv
void ff_h264_h_loop_filter_chroma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
biweight
const h264_biweight_func biweight
Definition: h264dsp_init.c:34
H264DSPContext::h264_h_loop_filter_chroma
void(* h264_h_loop_filter_chroma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:63
ff_h264_weight_funcs_8_rvv
const struct @213 ff_h264_weight_funcs_8_rvv[]
stride
#define stride
Definition: h264pred_template.c:537
H264DSPContext::h264_idct8_add4
void(* h264_idct8_add4)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 *8])
Definition: h264dsp.h:93
H264DSPContext::h264_idct_dc_add
void(* h264_idct_dc_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:85
H264DSPContext::h264_add_pixels4_clear
void(* h264_add_pixels4_clear)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:108
ff_h264_h_loop_filter_luma_8_rvv
void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
ff_h264_h_loop_filter_chroma_8_rvv
void ff_h264_h_loop_filter_chroma_8_rvv(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
H264DSPContext::h264_idct_add16intra
void(* h264_idct_add16intra)(uint8_t *dst, const int *blockoffset, int16_t *block, int stride, const uint8_t nnzc[5 *8])
Definition: h264dsp.h:99
H264DSPContext::h264_v_loop_filter_luma
void(* h264_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
Definition: h264dsp.h:48
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
ff_h264_add_pixels8_8_rvv
void ff_h264_add_pixels8_8_rvv(uint8_t *dst, int16_t *block, int stride)
ff_startcode_find_candidate_rvb
int ff_startcode_find_candidate_rvb(const uint8_t *, int)
IDCT_DEPTH
#define IDCT_DEPTH(depth)
Definition: h264dsp_init.c:51
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
AV_CPU_FLAG_RVV_I64
#define AV_CPU_FLAG_RVV_I64
Vectors of 64-bit int's *‍/.
Definition: cpu.h:94
H264DSPContext::h264_idct_add
void(* h264_idct_add)(uint8_t *dst, int16_t *block, int stride)
Definition: h264dsp.h:81