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