1 /**************************************************************************
3 * Copyright 2015 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "pipe/p_video_codec.h"
32 #include "util/u_video.h"
33 #include "util/u_memory.h"
35 #include "vl/vl_video_buffer.h"
37 #include "radeonsi/si_pipe.h"
38 #include "radeon_video.h"
39 #include "radeon_vce.h"
41 static void get_rate_control_param(struct rvce_encoder
*enc
, struct pipe_h264_enc_picture_desc
*pic
)
43 enc
->enc_pic
.rc
.rc_method
= pic
->rate_ctrl
.rate_ctrl_method
;
44 enc
->enc_pic
.rc
.target_bitrate
= pic
->rate_ctrl
.target_bitrate
;
45 enc
->enc_pic
.rc
.peak_bitrate
= pic
->rate_ctrl
.peak_bitrate
;
46 enc
->enc_pic
.rc
.quant_i_frames
= pic
->quant_i_frames
;
47 enc
->enc_pic
.rc
.quant_p_frames
= pic
->quant_p_frames
;
48 enc
->enc_pic
.rc
.quant_b_frames
= pic
->quant_b_frames
;
49 enc
->enc_pic
.rc
.gop_size
= pic
->gop_size
;
50 enc
->enc_pic
.rc
.frame_rate_num
= pic
->rate_ctrl
.frame_rate_num
;
51 enc
->enc_pic
.rc
.frame_rate_den
= pic
->rate_ctrl
.frame_rate_den
;
52 enc
->enc_pic
.rc
.max_qp
= 51;
53 enc
->enc_pic
.rc
.vbv_buffer_size
= pic
->rate_ctrl
.vbv_buffer_size
;
54 enc
->enc_pic
.rc
.vbv_buf_lv
= pic
->rate_ctrl
.vbv_buf_lv
;
55 enc
->enc_pic
.rc
.fill_data_enable
= pic
->rate_ctrl
.fill_data_enable
;
56 enc
->enc_pic
.rc
.enforce_hrd
= pic
->rate_ctrl
.enforce_hrd
;
57 enc
->enc_pic
.rc
.target_bits_picture
= pic
->rate_ctrl
.target_bits_picture
;
58 enc
->enc_pic
.rc
.peak_bits_picture_integer
= pic
->rate_ctrl
.peak_bits_picture_integer
;
59 enc
->enc_pic
.rc
.peak_bits_picture_fraction
= pic
->rate_ctrl
.peak_bits_picture_fraction
;
62 static void get_motion_estimation_param(struct rvce_encoder
*enc
, struct pipe_h264_enc_picture_desc
*pic
)
64 enc
->enc_pic
.me
.motion_est_quarter_pixel
= pic
->motion_est
.motion_est_quarter_pixel
;
65 enc
->enc_pic
.me
.enc_disable_sub_mode
= pic
->motion_est
.enc_disable_sub_mode
;
66 enc
->enc_pic
.me
.lsmvert
= pic
->motion_est
.lsmvert
;
67 enc
->enc_pic
.me
.enc_en_ime_overw_dis_subm
= pic
->motion_est
.enc_en_ime_overw_dis_subm
;
68 enc
->enc_pic
.me
.enc_ime_overw_dis_subm_no
= pic
->motion_est
.enc_ime_overw_dis_subm_no
;
69 enc
->enc_pic
.me
.enc_ime2_search_range_x
= pic
->motion_est
.enc_ime2_search_range_x
;
70 enc
->enc_pic
.me
.enc_ime2_search_range_y
= pic
->motion_est
.enc_ime2_search_range_y
;
71 enc
->enc_pic
.me
.enc_ime_decimation_search
= 0x00000001;
72 enc
->enc_pic
.me
.motion_est_half_pixel
= 0x00000001;
73 enc
->enc_pic
.me
.enc_search_range_x
= 0x00000010;
74 enc
->enc_pic
.me
.enc_search_range_y
= 0x00000010;
75 enc
->enc_pic
.me
.enc_search1_range_x
= 0x00000010;
76 enc
->enc_pic
.me
.enc_search1_range_y
= 0x00000010;
79 static void get_pic_control_param(struct rvce_encoder
*enc
, struct pipe_h264_enc_picture_desc
*pic
)
81 unsigned encNumMBsPerSlice
;
82 encNumMBsPerSlice
= align(enc
->base
.width
, 16) / 16;
83 encNumMBsPerSlice
*= align(enc
->base
.height
, 16) / 16;
84 enc
->enc_pic
.pc
.enc_crop_right_offset
= (align(enc
->base
.width
, 16) - enc
->base
.width
) >> 1;
85 enc
->enc_pic
.pc
.enc_crop_bottom_offset
= (align(enc
->base
.height
, 16) - enc
->base
.height
) >> 1;
86 enc
->enc_pic
.pc
.enc_num_mbs_per_slice
= encNumMBsPerSlice
;
87 enc
->enc_pic
.pc
.enc_b_pic_pattern
= MAX2(enc
->base
.max_references
, 1) - 1;
88 enc
->enc_pic
.pc
.enc_number_of_reference_frames
= MIN2(enc
->base
.max_references
, 2);
89 enc
->enc_pic
.pc
.enc_max_num_ref_frames
= enc
->base
.max_references
+ 1;
90 enc
->enc_pic
.pc
.enc_num_default_active_ref_l0
= 0x00000001;
91 enc
->enc_pic
.pc
.enc_num_default_active_ref_l1
= 0x00000001;
92 enc
->enc_pic
.pc
.enc_cabac_enable
= pic
->pic_ctrl
.enc_cabac_enable
;
93 enc
->enc_pic
.pc
.enc_constraint_set_flags
= pic
->pic_ctrl
.enc_constraint_set_flags
;
94 enc
->enc_pic
.pc
.enc_num_default_active_ref_l0
= 0x00000001;
95 enc
->enc_pic
.pc
.enc_num_default_active_ref_l1
= 0x00000001;
98 static void get_task_info_param(struct rvce_encoder
*enc
)
100 enc
->enc_pic
.ti
.offset_of_next_task_info
= 0xffffffff;
103 static void get_feedback_buffer_param(struct rvce_encoder
*enc
)
105 enc
->enc_pic
.fb
.feedback_ring_size
= 0x00000001;
108 static void get_config_ext_param(struct rvce_encoder
*enc
)
110 enc
->enc_pic
.ce
.enc_enable_perf_logging
= 0x00000003;
113 static void get_vui_param(struct rvce_encoder
*enc
, struct pipe_h264_enc_picture_desc
*pic
)
115 enc
->enc_pic
.enable_vui
= pic
->enable_vui
;
116 enc
->enc_pic
.vui
.video_format
= 0x00000005;
117 enc
->enc_pic
.vui
.color_prim
= 0x00000002;
118 enc
->enc_pic
.vui
.transfer_char
= 0x00000002;
119 enc
->enc_pic
.vui
.matrix_coef
= 0x00000002;
120 enc
->enc_pic
.vui
.timing_info_present_flag
= 0x00000001;
121 enc
->enc_pic
.vui
.num_units_in_tick
= pic
->rate_ctrl
.frame_rate_den
;
122 enc
->enc_pic
.vui
.time_scale
= pic
->rate_ctrl
.frame_rate_num
* 2;
123 enc
->enc_pic
.vui
.fixed_frame_rate_flag
= 0x00000001;
124 enc
->enc_pic
.vui
.bit_rate_scale
= 0x00000004;
125 enc
->enc_pic
.vui
.cpb_size_scale
= 0x00000006;
126 enc
->enc_pic
.vui
.initial_cpb_removal_delay_length_minus1
= 0x00000017;
127 enc
->enc_pic
.vui
.cpb_removal_delay_length_minus1
= 0x00000017;
128 enc
->enc_pic
.vui
.dpb_output_delay_length_minus1
= 0x00000017;
129 enc
->enc_pic
.vui
.time_offset_length
= 0x00000018;
130 enc
->enc_pic
.vui
.motion_vectors_over_pic_boundaries_flag
= 0x00000001;
131 enc
->enc_pic
.vui
.max_bytes_per_pic_denom
= 0x00000002;
132 enc
->enc_pic
.vui
.max_bits_per_mb_denom
= 0x00000001;
133 enc
->enc_pic
.vui
.log2_max_mv_length_hori
= 0x00000010;
134 enc
->enc_pic
.vui
.log2_max_mv_length_vert
= 0x00000010;
135 enc
->enc_pic
.vui
.num_reorder_frames
= 0x00000003;
136 enc
->enc_pic
.vui
.max_dec_frame_buffering
= 0x00000003;
139 void si_vce_52_get_param(struct rvce_encoder
*enc
, struct pipe_h264_enc_picture_desc
*pic
)
141 get_rate_control_param(enc
, pic
);
142 get_motion_estimation_param(enc
, pic
);
143 get_pic_control_param(enc
, pic
);
144 get_task_info_param(enc
);
145 get_feedback_buffer_param(enc
);
146 get_vui_param(enc
, pic
);
147 get_config_ext_param(enc
);
149 enc
->enc_pic
.picture_type
= pic
->picture_type
;
150 enc
->enc_pic
.frame_num
= pic
->frame_num
;
151 enc
->enc_pic
.frame_num_cnt
= pic
->frame_num_cnt
;
152 enc
->enc_pic
.p_remain
= pic
->p_remain
;
153 enc
->enc_pic
.i_remain
= pic
->i_remain
;
154 enc
->enc_pic
.gop_cnt
= pic
->gop_cnt
;
155 enc
->enc_pic
.pic_order_cnt
= pic
->pic_order_cnt
;
156 enc
->enc_pic
.ref_idx_l0
= pic
->ref_idx_l0
;
157 enc
->enc_pic
.ref_idx_l1
= pic
->ref_idx_l1
;
158 enc
->enc_pic
.not_referenced
= pic
->not_referenced
;
160 enc
->enc_pic
.addrmode_arraymode_disrdo_distwoinstants
= 0x00000201;
162 enc
->enc_pic
.addrmode_arraymode_disrdo_distwoinstants
= 0x01000201;
163 enc
->enc_pic
.is_idr
= (pic
->picture_type
== PIPE_H264_ENC_PICTURE_TYPE_IDR
);
166 static void create(struct rvce_encoder
*enc
)
168 struct si_screen
*sscreen
= (struct si_screen
*)enc
->screen
;
169 enc
->task_info(enc
, 0x00000000, 0, 0, 0);
171 RVCE_BEGIN(0x01000001); // create cmd
172 RVCE_CS(enc
->enc_pic
.ec
.enc_use_circular_buffer
);
173 RVCE_CS(u_get_h264_profile_idc(enc
->base
.profile
)); // encProfile
174 RVCE_CS(enc
->base
.level
); // encLevel
175 RVCE_CS(enc
->enc_pic
.ec
.enc_pic_struct_restriction
);
176 RVCE_CS(enc
->base
.width
); // encImageWidth
177 RVCE_CS(enc
->base
.height
); // encImageHeight
179 if (sscreen
->info
.chip_class
< GFX9
) {
180 RVCE_CS(enc
->luma
->u
.legacy
.level
[0].nblk_x
* enc
->luma
->bpe
); // encRefPicLumaPitch
181 RVCE_CS(enc
->chroma
->u
.legacy
.level
[0].nblk_x
* enc
->chroma
->bpe
); // encRefPicChromaPitch
182 RVCE_CS(align(enc
->luma
->u
.legacy
.level
[0].nblk_y
, 16) / 8); // encRefYHeightInQw
184 RVCE_CS(enc
->luma
->u
.gfx9
.surf_pitch
* enc
->luma
->bpe
); // encRefPicLumaPitch
185 RVCE_CS(enc
->chroma
->u
.gfx9
.surf_pitch
* enc
->chroma
->bpe
); // encRefPicChromaPitch
186 RVCE_CS(align(enc
->luma
->u
.gfx9
.surf_height
, 16) / 8); // encRefYHeightInQw
189 RVCE_CS(enc
->enc_pic
.addrmode_arraymode_disrdo_distwoinstants
);
191 RVCE_CS(enc
->enc_pic
.ec
.enc_pre_encode_context_buffer_offset
);
192 RVCE_CS(enc
->enc_pic
.ec
.enc_pre_encode_input_luma_buffer_offset
);
193 RVCE_CS(enc
->enc_pic
.ec
.enc_pre_encode_input_chroma_buffer_offset
);
194 RVCE_CS(enc
->enc_pic
.ec
.enc_pre_encode_mode_chromaflag_vbaqmode_scenechangesensitivity
);
198 static void encode(struct rvce_encoder
*enc
)
200 struct si_screen
*sscreen
= (struct si_screen
*)enc
->screen
;
201 signed luma_offset
, chroma_offset
, bs_offset
;
202 unsigned dep
, bs_idx
= enc
->bs_idx
++;
205 if (enc
->dual_inst
) {
208 else if (enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_IDR
)
215 enc
->task_info(enc
, 0x00000003, dep
, 0, bs_idx
);
217 RVCE_BEGIN(0x05000001); // context buffer
218 RVCE_READWRITE(enc
->cpb
.res
->buf
, enc
->cpb
.res
->domains
, 0); // encodeContextAddressHi/Lo
221 bs_offset
= -(signed)(bs_idx
* enc
->bs_size
);
223 RVCE_BEGIN(0x05000004); // video bitstream buffer
224 RVCE_WRITE(enc
->bs_handle
, RADEON_DOMAIN_GTT
, bs_offset
); // videoBitstreamRingAddressHi/Lo
225 RVCE_CS(enc
->bs_size
); // videoBitstreamRingSize
228 if (enc
->dual_pipe
) {
229 unsigned aux_offset
= enc
->cpb
.res
->buf
->size
-
230 RVCE_MAX_AUX_BUFFER_NUM
* RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE
* 2;
231 RVCE_BEGIN(0x05000002); // auxiliary buffer
232 for (i
= 0; i
< 8; ++i
) {
234 aux_offset
+= RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE
;
236 for (i
= 0; i
< 8; ++i
)
237 RVCE_CS(RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE
);
241 RVCE_BEGIN(0x03000001); // encode
242 RVCE_CS(enc
->enc_pic
.frame_num
? 0x0 : 0x11); // insertHeaders
243 RVCE_CS(enc
->enc_pic
.eo
.picture_structure
);
244 RVCE_CS(enc
->bs_size
); // allowedMaxBitstreamSize
245 RVCE_CS(enc
->enc_pic
.eo
.force_refresh_map
);
246 RVCE_CS(enc
->enc_pic
.eo
.insert_aud
);
247 RVCE_CS(enc
->enc_pic
.eo
.end_of_sequence
);
248 RVCE_CS(enc
->enc_pic
.eo
.end_of_stream
);
250 if (sscreen
->info
.chip_class
< GFX9
) {
251 RVCE_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
252 enc
->luma
->u
.legacy
.level
[0].offset
); // inputPictureLumaAddressHi/Lo
253 RVCE_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
254 enc
->chroma
->u
.legacy
.level
[0].offset
); // inputPictureChromaAddressHi/Lo
255 RVCE_CS(align(enc
->luma
->u
.legacy
.level
[0].nblk_y
, 16)); // encInputFrameYPitch
256 RVCE_CS(enc
->luma
->u
.legacy
.level
[0].nblk_x
* enc
->luma
->bpe
); // encInputPicLumaPitch
257 RVCE_CS(enc
->chroma
->u
.legacy
.level
[0].nblk_x
* enc
->chroma
->bpe
); // encInputPicChromaPitch
259 RVCE_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
260 enc
->luma
->u
.gfx9
.surf_offset
); // inputPictureLumaAddressHi/Lo
261 RVCE_READ(enc
->handle
, RADEON_DOMAIN_VRAM
,
262 enc
->chroma
->u
.gfx9
.surf_offset
); // inputPictureChromaAddressHi/Lo
263 RVCE_CS(align(enc
->luma
->u
.gfx9
.surf_height
, 16)); // encInputFrameYPitch
264 RVCE_CS(enc
->luma
->u
.gfx9
.surf_pitch
* enc
->luma
->bpe
); // encInputPicLumaPitch
265 RVCE_CS(enc
->chroma
->u
.gfx9
.surf_pitch
* enc
->chroma
->bpe
); // encInputPicChromaPitch
269 enc
->enc_pic
.eo
.enc_input_pic_addr_array_disable2pipe_disablemboffload
= 0x00000000;
271 enc
->enc_pic
.eo
.enc_input_pic_addr_array_disable2pipe_disablemboffload
= 0x00010000;
272 RVCE_CS(enc
->enc_pic
.eo
.enc_input_pic_addr_array_disable2pipe_disablemboffload
);
273 RVCE_CS(enc
->enc_pic
.eo
.enc_input_pic_tile_config
);
274 RVCE_CS(enc
->enc_pic
.picture_type
); // encPicType
275 RVCE_CS(enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_IDR
); // encIdrFlag
276 if ((enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_IDR
) && (enc
->enc_pic
.eo
.enc_idr_pic_id
!=0))
277 enc
->enc_pic
.eo
.enc_idr_pic_id
= enc
->enc_pic
.idr_pic_id
- 1;
279 enc
->enc_pic
.eo
.enc_idr_pic_id
= 0x00000000;
280 RVCE_CS(enc
->enc_pic
.eo
.enc_idr_pic_id
);
281 RVCE_CS(enc
->enc_pic
.eo
.enc_mgs_key_pic
);
282 RVCE_CS(!enc
->enc_pic
.not_referenced
);
283 RVCE_CS(enc
->enc_pic
.eo
.enc_temporal_layer_index
);
284 RVCE_CS(enc
->enc_pic
.eo
.num_ref_idx_active_override_flag
);
285 RVCE_CS(enc
->enc_pic
.eo
.num_ref_idx_l0_active_minus1
);
286 RVCE_CS(enc
->enc_pic
.eo
.num_ref_idx_l1_active_minus1
);
288 i
= enc
->enc_pic
.frame_num
- enc
->enc_pic
.ref_idx_l0
;
289 if (i
> 1 && enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_P
) {
290 enc
->enc_pic
.eo
.enc_ref_list_modification_op
= 0x00000001;
291 enc
->enc_pic
.eo
.enc_ref_list_modification_num
= i
- 1;
292 RVCE_CS(enc
->enc_pic
.eo
.enc_ref_list_modification_op
);
293 RVCE_CS(enc
->enc_pic
.eo
.enc_ref_list_modification_num
);
295 enc
->enc_pic
.eo
.enc_ref_list_modification_op
= 0x00000000;
296 enc
->enc_pic
.eo
.enc_ref_list_modification_num
= 0x00000000;
297 RVCE_CS(enc
->enc_pic
.eo
.enc_ref_list_modification_op
);
298 RVCE_CS(enc
->enc_pic
.eo
.enc_ref_list_modification_num
);
301 for (i
= 0; i
< 3; ++i
) {
302 enc
->enc_pic
.eo
.enc_ref_list_modification_op
= 0x00000000;
303 enc
->enc_pic
.eo
.enc_ref_list_modification_num
= 0x00000000;
304 RVCE_CS(enc
->enc_pic
.eo
.enc_ref_list_modification_op
);
305 RVCE_CS(enc
->enc_pic
.eo
.enc_ref_list_modification_num
);
307 for (i
= 0; i
< 4; ++i
) {
308 RVCE_CS(enc
->enc_pic
.eo
.enc_decoded_picture_marking_op
);
309 RVCE_CS(enc
->enc_pic
.eo
.enc_decoded_picture_marking_num
);
310 RVCE_CS(enc
->enc_pic
.eo
.enc_decoded_picture_marking_idx
);
311 RVCE_CS(enc
->enc_pic
.eo
.enc_decoded_ref_base_picture_marking_op
);
312 RVCE_CS(enc
->enc_pic
.eo
.enc_decoded_ref_base_picture_marking_num
);
315 // encReferencePictureL0[0]
316 RVCE_CS(0x00000000); // pictureStructure
317 if(enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_P
||
318 enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_B
) {
319 struct rvce_cpb_slot
*l0
= si_l0_slot(enc
);
320 si_vce_frame_offset(enc
, l0
, &luma_offset
, &chroma_offset
);
321 RVCE_CS(l0
->picture_type
);
322 RVCE_CS(l0
->frame_num
);
323 RVCE_CS(l0
->pic_order_cnt
);
324 RVCE_CS(luma_offset
);
325 RVCE_CS(chroma_offset
);
327 enc
->enc_pic
.eo
.l0_enc_pic_type
= 0x00000000;
328 enc
->enc_pic
.eo
.l0_frame_number
= 0x00000000;
329 enc
->enc_pic
.eo
.l0_picture_order_count
= 0x00000000;
330 enc
->enc_pic
.eo
.l0_luma_offset
= 0xffffffff;
331 enc
->enc_pic
.eo
.l0_chroma_offset
= 0xffffffff;
332 RVCE_CS(enc
->enc_pic
.eo
.l0_enc_pic_type
);
333 RVCE_CS(enc
->enc_pic
.eo
.l0_frame_number
);
334 RVCE_CS(enc
->enc_pic
.eo
.l0_picture_order_count
);
335 RVCE_CS(enc
->enc_pic
.eo
.l0_luma_offset
);
336 RVCE_CS(enc
->enc_pic
.eo
.l0_chroma_offset
);
339 // encReferencePictureL0[1]
340 enc
->enc_pic
.eo
.l0_picture_structure
= 0x00000000;
341 enc
->enc_pic
.eo
.l0_enc_pic_type
= 0x00000000;
342 enc
->enc_pic
.eo
.l0_frame_number
= 0x00000000;
343 enc
->enc_pic
.eo
.l0_picture_order_count
= 0x00000000;
344 enc
->enc_pic
.eo
.l0_luma_offset
= 0xffffffff;
345 enc
->enc_pic
.eo
.l0_chroma_offset
= 0xffffffff;
346 RVCE_CS(enc
->enc_pic
.eo
.l0_picture_structure
);
347 RVCE_CS(enc
->enc_pic
.eo
.l0_enc_pic_type
);
348 RVCE_CS(enc
->enc_pic
.eo
.l0_frame_number
);
349 RVCE_CS(enc
->enc_pic
.eo
.l0_picture_order_count
);
350 RVCE_CS(enc
->enc_pic
.eo
.l0_luma_offset
);
351 RVCE_CS(enc
->enc_pic
.eo
.l0_chroma_offset
);
353 // encReferencePictureL1[0]
354 RVCE_CS(0x00000000); // pictureStructure
355 if(enc
->enc_pic
.picture_type
== PIPE_H264_ENC_PICTURE_TYPE_B
) {
356 struct rvce_cpb_slot
*l1
= si_l1_slot(enc
);
357 si_vce_frame_offset(enc
, l1
, &luma_offset
, &chroma_offset
);
358 RVCE_CS(l1
->picture_type
);
359 RVCE_CS(l1
->frame_num
);
360 RVCE_CS(l1
->pic_order_cnt
);
361 RVCE_CS(luma_offset
);
362 RVCE_CS(chroma_offset
);
364 enc
->enc_pic
.eo
.l1_enc_pic_type
= 0x00000000;
365 enc
->enc_pic
.eo
.l1_frame_number
= 0x00000000;
366 enc
->enc_pic
.eo
.l1_picture_order_count
= 0x00000000;
367 enc
->enc_pic
.eo
.l1_luma_offset
= 0xffffffff;
368 enc
->enc_pic
.eo
.l1_chroma_offset
= 0xffffffff;
369 RVCE_CS(enc
->enc_pic
.eo
.l1_enc_pic_type
);
370 RVCE_CS(enc
->enc_pic
.eo
.l1_frame_number
);
371 RVCE_CS(enc
->enc_pic
.eo
.l1_picture_order_count
);
372 RVCE_CS(enc
->enc_pic
.eo
.l1_luma_offset
);
373 RVCE_CS(enc
->enc_pic
.eo
.l1_chroma_offset
);
376 si_vce_frame_offset(enc
, si_current_slot(enc
), &luma_offset
, &chroma_offset
);
377 RVCE_CS(luma_offset
);
378 RVCE_CS(chroma_offset
);
379 RVCE_CS(enc
->enc_pic
.eo
.enc_coloc_buffer_offset
);
380 RVCE_CS(enc
->enc_pic
.eo
.enc_reconstructed_ref_base_picture_luma_offset
);
381 RVCE_CS(enc
->enc_pic
.eo
.enc_reconstructed_ref_base_picture_chroma_offset
);
382 RVCE_CS(enc
->enc_pic
.eo
.enc_reference_ref_base_picture_luma_offset
);
383 RVCE_CS(enc
->enc_pic
.eo
.enc_reference_ref_base_picture_chroma_offset
);
384 RVCE_CS(enc
->enc_pic
.frame_num_cnt
-1);
385 RVCE_CS(enc
->enc_pic
.frame_num
);
386 RVCE_CS(enc
->enc_pic
.pic_order_cnt
);
387 RVCE_CS(enc
->enc_pic
.i_remain
);
388 RVCE_CS(enc
->enc_pic
.p_remain
);
389 RVCE_CS(enc
->enc_pic
.eo
.num_b_pic_remain_in_rcgop
);
390 RVCE_CS(enc
->enc_pic
.eo
.num_ir_pic_remain_in_rcgop
);
391 RVCE_CS(enc
->enc_pic
.eo
.enable_intra_refresh
);
393 RVCE_CS(enc
->enc_pic
.eo
.aq_variance_en
);
394 RVCE_CS(enc
->enc_pic
.eo
.aq_block_size
);
395 RVCE_CS(enc
->enc_pic
.eo
.aq_mb_variance_sel
);
396 RVCE_CS(enc
->enc_pic
.eo
.aq_frame_variance_sel
);
397 RVCE_CS(enc
->enc_pic
.eo
.aq_param_a
);
398 RVCE_CS(enc
->enc_pic
.eo
.aq_param_b
);
399 RVCE_CS(enc
->enc_pic
.eo
.aq_param_c
);
400 RVCE_CS(enc
->enc_pic
.eo
.aq_param_d
);
401 RVCE_CS(enc
->enc_pic
.eo
.aq_param_e
);
403 RVCE_CS(enc
->enc_pic
.eo
.context_in_sfb
);
407 static void rate_control(struct rvce_encoder
*enc
)
409 RVCE_BEGIN(0x04000005); // rate control
410 RVCE_CS(enc
->enc_pic
.rc
.rc_method
);
411 RVCE_CS(enc
->enc_pic
.rc
.target_bitrate
);
412 RVCE_CS(enc
->enc_pic
.rc
.peak_bitrate
);
413 RVCE_CS(enc
->enc_pic
.rc
.frame_rate_num
);
414 RVCE_CS(enc
->enc_pic
.rc
.gop_size
);
415 RVCE_CS(enc
->enc_pic
.rc
.quant_i_frames
);
416 RVCE_CS(enc
->enc_pic
.rc
.quant_p_frames
);
417 RVCE_CS(enc
->enc_pic
.rc
.quant_b_frames
);
418 RVCE_CS(enc
->enc_pic
.rc
.vbv_buffer_size
);
419 RVCE_CS(enc
->enc_pic
.rc
.frame_rate_den
);
420 RVCE_CS(enc
->enc_pic
.rc
.vbv_buf_lv
);
421 RVCE_CS(enc
->enc_pic
.rc
.max_au_size
);
422 RVCE_CS(enc
->enc_pic
.rc
.qp_initial_mode
);
423 RVCE_CS(enc
->enc_pic
.rc
.target_bits_picture
);
424 RVCE_CS(enc
->enc_pic
.rc
.peak_bits_picture_integer
);
425 RVCE_CS(enc
->enc_pic
.rc
.peak_bits_picture_fraction
);
426 RVCE_CS(enc
->enc_pic
.rc
.min_qp
);
427 RVCE_CS(enc
->enc_pic
.rc
.max_qp
);
428 RVCE_CS(enc
->enc_pic
.rc
.skip_frame_enable
);
429 RVCE_CS(enc
->enc_pic
.rc
.fill_data_enable
);
430 RVCE_CS(enc
->enc_pic
.rc
.enforce_hrd
);
431 RVCE_CS(enc
->enc_pic
.rc
.b_pics_delta_qp
);
432 RVCE_CS(enc
->enc_pic
.rc
.ref_b_pics_delta_qp
);
433 RVCE_CS(enc
->enc_pic
.rc
.rc_reinit_disable
);
434 RVCE_CS(enc
->enc_pic
.rc
.enc_lcvbr_init_qp_flag
);
435 RVCE_CS(enc
->enc_pic
.rc
.lcvbrsatd_based_nonlinear_bit_budget_flag
);
439 static void config(struct rvce_encoder
*enc
)
441 enc
->task_info(enc
, 0x00000002, 0, 0xffffffff, 0);
442 enc
->rate_control(enc
);
443 enc
->config_extension(enc
);
444 enc
->motion_estimation(enc
);
448 enc
->pic_control(enc
);
451 static void config_extension(struct rvce_encoder
*enc
)
453 RVCE_BEGIN(0x04000001); // config extension
454 RVCE_CS(enc
->enc_pic
.ce
.enc_enable_perf_logging
);
458 static void feedback(struct rvce_encoder
*enc
)
460 RVCE_BEGIN(0x05000005); // feedback buffer
461 RVCE_WRITE(enc
->fb
->res
->buf
, enc
->fb
->res
->domains
, 0x0); // feedbackRingAddressHi/Lo
462 RVCE_CS(enc
->enc_pic
.fb
.feedback_ring_size
);
466 static void destroy(struct rvce_encoder
*enc
)
468 enc
->task_info(enc
, 0x00000001, 0, 0, 0);
472 RVCE_BEGIN(0x02000001); // destroy
476 static void motion_estimation(struct rvce_encoder
*enc
)
478 RVCE_BEGIN(0x04000007); // motion estimation
479 RVCE_CS(enc
->enc_pic
.me
.enc_ime_decimation_search
);
480 RVCE_CS(enc
->enc_pic
.me
.motion_est_half_pixel
);
481 RVCE_CS(enc
->enc_pic
.me
.motion_est_quarter_pixel
);
482 RVCE_CS(enc
->enc_pic
.me
.disable_favor_pmv_point
);
483 RVCE_CS(enc
->enc_pic
.me
.force_zero_point_center
);
484 RVCE_CS(enc
->enc_pic
.me
.lsmvert
);
485 RVCE_CS(enc
->enc_pic
.me
.enc_search_range_x
);
486 RVCE_CS(enc
->enc_pic
.me
.enc_search_range_y
);
487 RVCE_CS(enc
->enc_pic
.me
.enc_search1_range_x
);
488 RVCE_CS(enc
->enc_pic
.me
.enc_search1_range_y
);
489 RVCE_CS(enc
->enc_pic
.me
.disable_16x16_frame1
);
490 RVCE_CS(enc
->enc_pic
.me
.disable_satd
);
491 RVCE_CS(enc
->enc_pic
.me
.enable_amd
);
492 RVCE_CS(enc
->enc_pic
.me
.enc_disable_sub_mode
);
493 RVCE_CS(enc
->enc_pic
.me
.enc_ime_skip_x
);
494 RVCE_CS(enc
->enc_pic
.me
.enc_ime_skip_y
);
495 RVCE_CS(enc
->enc_pic
.me
.enc_en_ime_overw_dis_subm
);
496 RVCE_CS(enc
->enc_pic
.me
.enc_ime_overw_dis_subm_no
);
497 RVCE_CS(enc
->enc_pic
.me
.enc_ime2_search_range_x
);
498 RVCE_CS(enc
->enc_pic
.me
.enc_ime2_search_range_y
);
499 RVCE_CS(enc
->enc_pic
.me
.parallel_mode_speedup_enable
);
500 RVCE_CS(enc
->enc_pic
.me
.fme0_enc_disable_sub_mode
);
501 RVCE_CS(enc
->enc_pic
.me
.fme1_enc_disable_sub_mode
);
502 RVCE_CS(enc
->enc_pic
.me
.ime_sw_speedup_enable
);
506 static void pic_control(struct rvce_encoder
*enc
)
508 RVCE_BEGIN(0x04000002); // pic control
509 RVCE_CS(enc
->enc_pic
.pc
.enc_use_constrained_intra_pred
);
510 RVCE_CS(enc
->enc_pic
.pc
.enc_cabac_enable
);
511 RVCE_CS(enc
->enc_pic
.pc
.enc_cabac_idc
);
512 RVCE_CS(enc
->enc_pic
.pc
.enc_loop_filter_disable
);
513 RVCE_CS(enc
->enc_pic
.pc
.enc_lf_beta_offset
);
514 RVCE_CS(enc
->enc_pic
.pc
.enc_lf_alpha_c0_offset
);
515 RVCE_CS(enc
->enc_pic
.pc
.enc_crop_left_offset
);
516 RVCE_CS(enc
->enc_pic
.pc
.enc_crop_right_offset
);
517 RVCE_CS(enc
->enc_pic
.pc
.enc_crop_top_offset
);
518 RVCE_CS(enc
->enc_pic
.pc
.enc_crop_bottom_offset
);
519 RVCE_CS(enc
->enc_pic
.pc
.enc_num_mbs_per_slice
);
520 RVCE_CS(enc
->enc_pic
.pc
.enc_intra_refresh_num_mbs_per_slot
);
521 RVCE_CS(enc
->enc_pic
.pc
.enc_force_intra_refresh
);
522 RVCE_CS(enc
->enc_pic
.pc
.enc_force_imb_period
);
523 RVCE_CS(enc
->enc_pic
.pc
.enc_pic_order_cnt_type
);
524 RVCE_CS(enc
->enc_pic
.pc
.log2_max_pic_order_cnt_lsb_minus4
);
525 RVCE_CS(enc
->enc_pic
.pc
.enc_sps_id
);
526 RVCE_CS(enc
->enc_pic
.pc
.enc_pps_id
);
527 RVCE_CS(enc
->enc_pic
.pc
.enc_constraint_set_flags
);
528 RVCE_CS(enc
->enc_pic
.pc
.enc_b_pic_pattern
);
529 RVCE_CS(enc
->enc_pic
.pc
.weight_pred_mode_b_picture
);
530 RVCE_CS(enc
->enc_pic
.pc
.enc_number_of_reference_frames
);
531 RVCE_CS(enc
->enc_pic
.pc
.enc_max_num_ref_frames
);
532 RVCE_CS(enc
->enc_pic
.pc
.enc_num_default_active_ref_l0
);
533 RVCE_CS(enc
->enc_pic
.pc
.enc_num_default_active_ref_l1
);
534 RVCE_CS(enc
->enc_pic
.pc
.enc_slice_mode
);
535 RVCE_CS(enc
->enc_pic
.pc
.enc_max_slice_size
);
539 static void rdo(struct rvce_encoder
*enc
)
541 RVCE_BEGIN(0x04000008); // rdo
542 RVCE_CS(enc
->enc_pic
.rdo
.enc_disable_tbe_pred_i_frame
);
543 RVCE_CS(enc
->enc_pic
.rdo
.enc_disable_tbe_pred_p_frame
);
544 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_interpol_y
);
545 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_interpol_uv
);
546 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_intrapol_y
);
547 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_intrapol_uv
);
548 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_interpol_y_1
);
549 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_interpol_uv_1
);
550 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_intrapol_y_1
);
551 RVCE_CS(enc
->enc_pic
.rdo
.use_fme_intrapol_uv_1
);
552 RVCE_CS(enc
->enc_pic
.rdo
.enc_16x16_cost_adj
);
553 RVCE_CS(enc
->enc_pic
.rdo
.enc_skip_cost_adj
);
554 RVCE_CS(enc
->enc_pic
.rdo
.enc_force_16x16_skip
);
555 RVCE_CS(enc
->enc_pic
.rdo
.enc_disable_threshold_calc_a
);
556 RVCE_CS(enc
->enc_pic
.rdo
.enc_luma_coeff_cost
);
557 RVCE_CS(enc
->enc_pic
.rdo
.enc_luma_mb_coeff_cost
);
558 RVCE_CS(enc
->enc_pic
.rdo
.enc_chroma_coeff_cost
);
562 static void session(struct rvce_encoder
*enc
)
564 RVCE_BEGIN(0x00000001); // session cmd
565 RVCE_CS(enc
->stream_handle
);
569 static void task_info(struct rvce_encoder
*enc
, uint32_t op
,
570 uint32_t dep
, uint32_t fb_idx
, uint32_t ring_idx
)
572 RVCE_BEGIN(0x00000002); // task info
574 if (enc
->task_info_idx
) {
575 uint32_t offs
= enc
->cs
->current
.cdw
- enc
->task_info_idx
+ 3;
576 // Update offsetOfNextTaskInfo
577 enc
->cs
->current
.buf
[enc
->task_info_idx
] = offs
;
579 enc
->task_info_idx
= enc
->cs
->current
.cdw
;
581 enc
->enc_pic
.ti
.task_operation
= op
;
582 enc
->enc_pic
.ti
.reference_picture_dependency
= dep
;
583 enc
->enc_pic
.ti
.feedback_index
= fb_idx
;
584 enc
->enc_pic
.ti
.video_bitstream_ring_index
= ring_idx
;
585 RVCE_CS(enc
->enc_pic
.ti
.offset_of_next_task_info
);
586 RVCE_CS(enc
->enc_pic
.ti
.task_operation
);
587 RVCE_CS(enc
->enc_pic
.ti
.reference_picture_dependency
);
588 RVCE_CS(enc
->enc_pic
.ti
.collocate_flag_dependency
);
589 RVCE_CS(enc
->enc_pic
.ti
.feedback_index
);
590 RVCE_CS(enc
->enc_pic
.ti
.video_bitstream_ring_index
);
594 static void vui(struct rvce_encoder
*enc
)
598 if (!enc
->enc_pic
.enable_vui
)
601 RVCE_BEGIN(0x04000009); // vui
602 RVCE_CS(enc
->enc_pic
.vui
.aspect_ratio_info_present_flag
);
603 RVCE_CS(enc
->enc_pic
.vui
.aspect_ratio_idc
);
604 RVCE_CS(enc
->enc_pic
.vui
.sar_width
);
605 RVCE_CS(enc
->enc_pic
.vui
.sar_height
);
606 RVCE_CS(enc
->enc_pic
.vui
.overscan_info_present_flag
);
607 RVCE_CS(enc
->enc_pic
.vui
.overscan_Approp_flag
);
608 RVCE_CS(enc
->enc_pic
.vui
.video_signal_type_present_flag
);
609 RVCE_CS(enc
->enc_pic
.vui
.video_format
);
610 RVCE_CS(enc
->enc_pic
.vui
.video_full_range_flag
);
611 RVCE_CS(enc
->enc_pic
.vui
.color_description_present_flag
);
612 RVCE_CS(enc
->enc_pic
.vui
.color_prim
);
613 RVCE_CS(enc
->enc_pic
.vui
.transfer_char
);
614 RVCE_CS(enc
->enc_pic
.vui
.matrix_coef
);
615 RVCE_CS(enc
->enc_pic
.vui
.chroma_loc_info_present_flag
);
616 RVCE_CS(enc
->enc_pic
.vui
.chroma_loc_top
);
617 RVCE_CS(enc
->enc_pic
.vui
.chroma_loc_bottom
);
618 RVCE_CS(enc
->enc_pic
.vui
.timing_info_present_flag
);
619 RVCE_CS(enc
->enc_pic
.vui
.num_units_in_tick
);
620 RVCE_CS(enc
->enc_pic
.vui
.time_scale
);
621 RVCE_CS(enc
->enc_pic
.vui
.fixed_frame_rate_flag
);
622 RVCE_CS(enc
->enc_pic
.vui
.nal_hrd_parameters_present_flag
);
623 RVCE_CS(enc
->enc_pic
.vui
.cpb_cnt_minus1
);
624 RVCE_CS(enc
->enc_pic
.vui
.bit_rate_scale
);
625 RVCE_CS(enc
->enc_pic
.vui
.cpb_size_scale
);
626 for (i
= 0; i
< 32; i
++) {
627 RVCE_CS(enc
->enc_pic
.vui
.bit_rate_value_minus
);
628 RVCE_CS(enc
->enc_pic
.vui
.cpb_size_value_minus
);
629 RVCE_CS(enc
->enc_pic
.vui
.cbr_flag
);
631 RVCE_CS(enc
->enc_pic
.vui
.initial_cpb_removal_delay_length_minus1
);
632 RVCE_CS(enc
->enc_pic
.vui
.cpb_removal_delay_length_minus1
);
633 RVCE_CS(enc
->enc_pic
.vui
.dpb_output_delay_length_minus1
);
634 RVCE_CS(enc
->enc_pic
.vui
.time_offset_length
);
635 RVCE_CS(enc
->enc_pic
.vui
.low_delay_hrd_flag
);
636 RVCE_CS(enc
->enc_pic
.vui
.pic_struct_present_flag
);
637 RVCE_CS(enc
->enc_pic
.vui
.bitstream_restriction_present_flag
);
638 RVCE_CS(enc
->enc_pic
.vui
.motion_vectors_over_pic_boundaries_flag
);
639 RVCE_CS(enc
->enc_pic
.vui
.max_bytes_per_pic_denom
);
640 RVCE_CS(enc
->enc_pic
.vui
.max_bits_per_mb_denom
);
641 RVCE_CS(enc
->enc_pic
.vui
.log2_max_mv_length_hori
);
642 RVCE_CS(enc
->enc_pic
.vui
.log2_max_mv_length_vert
);
643 RVCE_CS(enc
->enc_pic
.vui
.num_reorder_frames
);
644 RVCE_CS(enc
->enc_pic
.vui
.max_dec_frame_buffering
);
648 void si_vce_52_init(struct rvce_encoder
*enc
)
650 enc
->session
= session
;
651 enc
->task_info
= task_info
;
652 enc
->create
= create
;
653 enc
->feedback
= feedback
;
654 enc
->rate_control
= rate_control
;
655 enc
->config_extension
= config_extension
;
656 enc
->pic_control
= pic_control
;
657 enc
->motion_estimation
= motion_estimation
;
660 enc
->config
= config
;
661 enc
->encode
= encode
;
662 enc
->destroy
= destroy
;