Skip to content

Commit e3b5b77

Browse files
cazouHans Verkuil
authored andcommitted
media: rkvdec: Add HEVC support for the VDPU383 variant
The VDPU383 decoder is used on the RK3576 SoC and has support for HEVC. This patch also moves some functions to a common rkvdec-hevc-common.c file and adds a specific scaling matrix flatten function. The fluster score for JCT-VC-HEVC_V1 is 146/147. Reviewed-by: Nicolas Dufresne <[email protected]> Signed-off-by: Detlev Casanova <[email protected]> Signed-off-by: Nicolas Dufresne <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent c9a59dc commit e3b5b77

8 files changed

Lines changed: 765 additions & 48 deletions

File tree

drivers/media/platform/rockchip/rkvdec/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ rockchip-vdec-y += \
1111
rkvdec-vdpu381-h264.o \
1212
rkvdec-vdpu381-hevc.o \
1313
rkvdec-vdpu383-h264.o \
14+
rkvdec-vdpu383-hevc.o \
1415
rkvdec-vp9.o

drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -140,56 +140,26 @@ static void set_ref_poc(struct rkvdec_rps_short_term_ref_set *set, int poc, int
140140
}
141141
}
142142

143-
/*
144-
* Flip one or more matrices along their main diagonal and flatten them
145-
* before writing it to the memory.
146-
* Convert:
147-
* ABCD AEIM
148-
* EFGH => BFJN => AEIMBFJNCGKODHLP
149-
* IJKL CGKO
150-
* MNOP DHLP
151-
*/
152-
static void transpose_and_flatten_matrices(u8 *output, const u8 *input,
153-
int matrices, int row_length)
154-
{
155-
int i, j, row, x_offset, matrix_offset, rot_index, y_offset, matrix_size, new_value;
156-
157-
matrix_size = row_length * row_length;
158-
for (i = 0; i < matrices; i++) {
159-
row = 0;
160-
x_offset = 0;
161-
matrix_offset = i * matrix_size;
162-
for (j = 0; j < matrix_size; j++) {
163-
y_offset = j - (row * row_length);
164-
rot_index = y_offset * row_length + x_offset;
165-
new_value = *(input + i * matrix_size + j);
166-
output[matrix_offset + rot_index] = new_value;
167-
if ((j + 1) % row_length == 0) {
168-
row += 1;
169-
x_offset += 1;
170-
}
171-
}
172-
}
173-
}
174-
175-
static void assemble_scalingfactor0(u8 *output, const struct v4l2_ctrl_hevc_scaling_matrix *input)
143+
static void assemble_scalingfactor0(struct rkvdec_ctx *ctx, u8 *output,
144+
const struct v4l2_ctrl_hevc_scaling_matrix *input)
176145
{
146+
const struct rkvdec_variant *variant = ctx->dev->variant;
177147
int offset = 0;
178148

179-
transpose_and_flatten_matrices(output, (const u8 *)input->scaling_list_4x4, 6, 4);
149+
variant->ops->flatten_matrices(output, (const u8 *)input->scaling_list_4x4, 6, 4);
180150
offset = 6 * 16 * sizeof(u8);
181-
transpose_and_flatten_matrices(output + offset, (const u8 *)input->scaling_list_8x8, 6, 8);
151+
variant->ops->flatten_matrices(output + offset, (const u8 *)input->scaling_list_8x8, 6, 8);
182152
offset += 6 * 64 * sizeof(u8);
183-
transpose_and_flatten_matrices(output + offset,
184-
(const u8 *)input->scaling_list_16x16, 6, 8);
153+
variant->ops->flatten_matrices(output + offset, (const u8 *)input->scaling_list_16x16,
154+
6, 8);
185155
offset += 6 * 64 * sizeof(u8);
186156
/* Add a 128 byte padding with 0s between the two 32x32 matrices */
187-
transpose_and_flatten_matrices(output + offset,
188-
(const u8 *)input->scaling_list_32x32, 1, 8);
157+
variant->ops->flatten_matrices(output + offset, (const u8 *)input->scaling_list_32x32,
158+
1, 8);
189159
offset += 64 * sizeof(u8);
190160
memset(output + offset, 0, 128);
191161
offset += 128 * sizeof(u8);
192-
transpose_and_flatten_matrices(output + offset,
162+
variant->ops->flatten_matrices(output + offset,
193163
(const u8 *)input->scaling_list_32x32 + (64 * sizeof(u8)),
194164
1, 8);
195165
offset += 64 * sizeof(u8);
@@ -214,16 +184,17 @@ static void assemble_scalingdc(u8 *output, const struct v4l2_ctrl_hevc_scaling_m
214184
memcpy(output + 6 * sizeof(u8), list_32x32, 6 * sizeof(u8));
215185
}
216186

217-
static void translate_scaling_list(struct scaling_factor *output,
187+
static void translate_scaling_list(struct rkvdec_ctx *ctx, struct scaling_factor *output,
218188
const struct v4l2_ctrl_hevc_scaling_matrix *input)
219189
{
220-
assemble_scalingfactor0(output->scalingfactor0, input);
190+
assemble_scalingfactor0(ctx, output->scalingfactor0, input);
221191
memcpy(output->scalingfactor1, (const u8 *)input->scaling_list_4x4, 96);
222192
assemble_scalingdc(output->scalingdc, input);
223193
memset(output->reserved, 0, 4 * sizeof(u8));
224194
}
225195

226-
void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run,
196+
void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
197+
struct rkvdec_hevc_run *run,
227198
struct scaling_factor *scaling_factor,
228199
struct v4l2_ctrl_hevc_scaling_matrix *cache)
229200
{
@@ -233,7 +204,7 @@ void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run,
233204
sizeof(struct v4l2_ctrl_hevc_scaling_matrix)))
234205
return;
235206

236-
translate_scaling_list(scaling_factor, scaling);
207+
translate_scaling_list(ctx, scaling_factor, scaling);
237208

238209
memcpy(cache, scaling,
239210
sizeof(struct v4l2_ctrl_hevc_scaling_matrix));

drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size
9595
s32 pic_in_cts_height, u16 *column_width, u16 *row_height);
9696
void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
9797
struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache);
98-
void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run,
98+
void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
99+
struct rkvdec_hevc_run *run,
99100
struct scaling_factor *scaling_factor,
100101
struct v4l2_ctrl_hevc_scaling_matrix *cache);
101102
struct vb2_buffer *get_ref_buf(struct rkvdec_ctx *ctx,

drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx)
568568

569569
rkvdec_hevc_run_preamble(ctx, &run);
570570

571-
rkvdec_hevc_assemble_hw_scaling_list(&run, &tbl->scaling_list,
571+
rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list,
572572
&hevc_ctx->scaling_matrix_cache);
573573
assemble_hw_pps(ctx, &run);
574574
assemble_sw_rps(ctx, &run);

drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx)
594594

595595
rkvdec_hevc_run_preamble(ctx, &run);
596596

597-
rkvdec_hevc_assemble_hw_scaling_list(&run,
598-
&tbl->scaling_list,
597+
rkvdec_hevc_assemble_hw_scaling_list(ctx, &run, &tbl->scaling_list,
599598
&hevc_ctx->scaling_matrix_cache);
600599
assemble_hw_pps(ctx, &run);
601600

0 commit comments

Comments
 (0)