Path: blob/21.2-virgl/src/gallium/drivers/radeon/radeon_vcn_enc_2_0.c
4570 views
/**************************************************************************1*2* Copyright 2017 Advanced Micro Devices, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "pipe/p_video_codec.h"28#include "radeon_vcn_enc.h"29#include "radeon_video.h"30#include "si_pipe.h"31#include "util/u_video.h"3233#include <stdio.h>3435#define RENCODE_FW_INTERFACE_MAJOR_VERSION 136#define RENCODE_FW_INTERFACE_MINOR_VERSION 13738#define RENCODE_IB_PARAM_SESSION_INFO 0x0000000139#define RENCODE_IB_PARAM_TASK_INFO 0x0000000240#define RENCODE_IB_PARAM_SESSION_INIT 0x0000000341#define RENCODE_IB_PARAM_LAYER_CONTROL 0x0000000442#define RENCODE_IB_PARAM_LAYER_SELECT 0x0000000543#define RENCODE_IB_PARAM_RATE_CONTROL_SESSION_INIT 0x0000000644#define RENCODE_IB_PARAM_RATE_CONTROL_LAYER_INIT 0x0000000745#define RENCODE_IB_PARAM_RATE_CONTROL_PER_PICTURE 0x0000000846#define RENCODE_IB_PARAM_QUALITY_PARAMS 0x0000000947#define RENCODE_IB_PARAM_DIRECT_OUTPUT_NALU 0x0000000a48#define RENCODE_IB_PARAM_SLICE_HEADER 0x0000000b49#define RENCODE_IB_PARAM_INPUT_FORMAT 0x0000000c50#define RENCODE_IB_PARAM_OUTPUT_FORMAT 0x0000000d51#define RENCODE_IB_PARAM_ENCODE_PARAMS 0x0000000f52#define RENCODE_IB_PARAM_INTRA_REFRESH 0x0000001053#define RENCODE_IB_PARAM_ENCODE_CONTEXT_BUFFER 0x0000001154#define RENCODE_IB_PARAM_VIDEO_BITSTREAM_BUFFER 0x0000001255#define RENCODE_IB_PARAM_FEEDBACK_BUFFER 0x000000155657#define RENCODE_HEVC_IB_PARAM_SLICE_CONTROL 0x0010000158#define RENCODE_HEVC_IB_PARAM_SPEC_MISC 0x0010000259#define RENCODE_HEVC_IB_PARAM_LOOP_FILTER 0x001000036061#define RENCODE_H264_IB_PARAM_SLICE_CONTROL 0x0020000162#define RENCODE_H264_IB_PARAM_SPEC_MISC 0x0020000263#define RENCODE_H264_IB_PARAM_ENCODE_PARAMS 0x0020000364#define RENCODE_H264_IB_PARAM_DEBLOCKING_FILTER 0x002000046566#define RENCODE_COLOR_VOLUME_G22_BT709 067#define RENCODE_COLOR_VOLUME_G10_BT2020 36869#define RENCODE_COLOR_BIT_DEPTH_8_BIT 070#define RENCODE_COLOR_BIT_DEPTH_10_BIT 17172#define RENCODE_COLOR_PACKING_FORMAT_NV12 073#define RENCODE_COLOR_PACKING_FORMAT_P010 17475static void radeon_enc_op_balance(struct radeon_encoder *enc)76{77RADEON_ENC_BEGIN(RENCODE_IB_OP_SET_BALANCE_ENCODING_MODE);78RADEON_ENC_END();79}8081static void radeon_enc_slice_header_hevc(struct radeon_encoder *enc)82{83uint32_t instruction[RENCODE_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS] = {0};84uint32_t num_bits[RENCODE_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS] = {0};85unsigned int inst_index = 0;86unsigned int cdw_start = 0;87unsigned int cdw_filled = 0;88unsigned int bits_copied = 0;89RADEON_ENC_BEGIN(enc->cmd.slice_header);90radeon_enc_reset(enc);91radeon_enc_set_emulation_prevention(enc, false);9293cdw_start = enc->cs.current.cdw;94radeon_enc_code_fixed_bits(enc, 0x0, 1);95radeon_enc_code_fixed_bits(enc, enc->enc_pic.nal_unit_type, 6);96radeon_enc_code_fixed_bits(enc, 0x0, 6);97radeon_enc_code_fixed_bits(enc, 0x1, 3);9899radeon_enc_flush_headers(enc);100instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_COPY;101num_bits[inst_index] = enc->bits_output - bits_copied;102bits_copied = enc->bits_output;103inst_index++;104105instruction[inst_index] = RENCODE_HEVC_HEADER_INSTRUCTION_FIRST_SLICE;106inst_index++;107108if ((enc->enc_pic.nal_unit_type >= 16) && (enc->enc_pic.nal_unit_type <= 23))109radeon_enc_code_fixed_bits(enc, 0x0, 1);110111radeon_enc_code_ue(enc, 0x0);112113radeon_enc_flush_headers(enc);114instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_COPY;115num_bits[inst_index] = enc->bits_output - bits_copied;116bits_copied = enc->bits_output;117inst_index++;118119instruction[inst_index] = RENCODE_HEVC_HEADER_INSTRUCTION_SLICE_SEGMENT;120inst_index++;121122instruction[inst_index] = RENCODE_HEVC_HEADER_INSTRUCTION_DEPENDENT_SLICE_END;123inst_index++;124125switch (enc->enc_pic.picture_type) {126case PIPE_H2645_ENC_PICTURE_TYPE_I:127case PIPE_H2645_ENC_PICTURE_TYPE_IDR:128radeon_enc_code_ue(enc, 0x2);129break;130case PIPE_H2645_ENC_PICTURE_TYPE_P:131case PIPE_H2645_ENC_PICTURE_TYPE_SKIP:132radeon_enc_code_ue(enc, 0x1);133break;134case PIPE_H2645_ENC_PICTURE_TYPE_B:135radeon_enc_code_ue(enc, 0x0);136break;137default:138radeon_enc_code_ue(enc, 0x1);139}140141if ((enc->enc_pic.nal_unit_type != 19) && (enc->enc_pic.nal_unit_type != 20)) {142radeon_enc_code_fixed_bits(enc, enc->enc_pic.pic_order_cnt, enc->enc_pic.log2_max_poc);143if (enc->enc_pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_P)144radeon_enc_code_fixed_bits(enc, 0x1, 1);145else {146radeon_enc_code_fixed_bits(enc, 0x0, 1);147radeon_enc_code_fixed_bits(enc, 0x0, 1);148radeon_enc_code_ue(enc, 0x0);149radeon_enc_code_ue(enc, 0x0);150}151}152153if (enc->enc_pic.sample_adaptive_offset_enabled_flag) {154radeon_enc_flush_headers(enc);155instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_COPY;156num_bits[inst_index] = enc->bits_output - bits_copied;157bits_copied = enc->bits_output;158inst_index++;159160instruction[inst_index] = RENCODE_HEVC_HEADER_INSTRUCTION_SAO_ENABLE;161inst_index++;162}163164if ((enc->enc_pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_P) ||165(enc->enc_pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B)) {166radeon_enc_code_fixed_bits(enc, 0x0, 1);167radeon_enc_code_fixed_bits(enc, enc->enc_pic.hevc_spec_misc.cabac_init_flag, 1);168radeon_enc_code_ue(enc, 5 - enc->enc_pic.max_num_merge_cand);169}170171radeon_enc_flush_headers(enc);172instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_COPY;173num_bits[inst_index] = enc->bits_output - bits_copied;174bits_copied = enc->bits_output;175inst_index++;176177instruction[inst_index] = RENCODE_HEVC_HEADER_INSTRUCTION_SLICE_QP_DELTA;178inst_index++;179180if ((enc->enc_pic.hevc_deblock.loop_filter_across_slices_enabled) &&181(!enc->enc_pic.hevc_deblock.deblocking_filter_disabled ||182enc->enc_pic.sample_adaptive_offset_enabled_flag)) {183if (enc->enc_pic.sample_adaptive_offset_enabled_flag) {184radeon_enc_flush_headers(enc);185instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_COPY;186num_bits[inst_index] = enc->bits_output - bits_copied;187bits_copied = enc->bits_output;188inst_index++;189190instruction[inst_index] = RENCODE_HEVC_HEADER_INSTRUCTION_LOOP_FILTER_ACROSS_SLICES_ENABLE;191inst_index++;192}193else194radeon_enc_code_fixed_bits(enc, enc->enc_pic.hevc_deblock.loop_filter_across_slices_enabled, 1);195}196197radeon_enc_flush_headers(enc);198instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_COPY;199num_bits[inst_index] = enc->bits_output - bits_copied;200bits_copied = enc->bits_output;201inst_index++;202instruction[inst_index] = RENCODE_HEADER_INSTRUCTION_END;203204cdw_filled = enc->cs.current.cdw - cdw_start;205for (int i = 0; i < RENCODE_SLICE_HEADER_TEMPLATE_MAX_TEMPLATE_SIZE_IN_DWORDS - cdw_filled; i++)206RADEON_ENC_CS(0x00000000);207208for (int j = 0; j < RENCODE_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS; j++) {209RADEON_ENC_CS(instruction[j]);210RADEON_ENC_CS(num_bits[j]);211}212213RADEON_ENC_END();214}215216static void radeon_enc_quality_params(struct radeon_encoder *enc)217{218enc->enc_pic.quality_params.vbaq_mode = 0;219enc->enc_pic.quality_params.scene_change_sensitivity = 0;220enc->enc_pic.quality_params.scene_change_min_idr_interval = 0;221enc->enc_pic.quality_params.two_pass_search_center_map_mode = 0;222223RADEON_ENC_BEGIN(enc->cmd.quality_params);224RADEON_ENC_CS(enc->enc_pic.quality_params.vbaq_mode);225RADEON_ENC_CS(enc->enc_pic.quality_params.scene_change_sensitivity);226RADEON_ENC_CS(enc->enc_pic.quality_params.scene_change_min_idr_interval);227RADEON_ENC_CS(enc->enc_pic.quality_params.two_pass_search_center_map_mode);228RADEON_ENC_END();229}230231static void radeon_enc_loop_filter_hevc(struct radeon_encoder *enc)232{233RADEON_ENC_BEGIN(enc->cmd.deblocking_filter_hevc);234RADEON_ENC_CS(enc->enc_pic.hevc_deblock.loop_filter_across_slices_enabled);235RADEON_ENC_CS(enc->enc_pic.hevc_deblock.deblocking_filter_disabled);236RADEON_ENC_CS(enc->enc_pic.hevc_deblock.beta_offset_div2);237RADEON_ENC_CS(enc->enc_pic.hevc_deblock.tc_offset_div2);238RADEON_ENC_CS(enc->enc_pic.hevc_deblock.cb_qp_offset);239RADEON_ENC_CS(enc->enc_pic.hevc_deblock.cr_qp_offset);240RADEON_ENC_CS(!enc->enc_pic.sample_adaptive_offset_enabled_flag);241RADEON_ENC_END();242}243244static void radeon_enc_nalu_sps_hevc(struct radeon_encoder *enc)245{246RADEON_ENC_BEGIN(enc->cmd.nalu);247RADEON_ENC_CS(RENCODE_DIRECT_OUTPUT_NALU_TYPE_SPS);248uint32_t *size_in_bytes = &enc->cs.current.buf[enc->cs.current.cdw++];249int i;250251radeon_enc_reset(enc);252radeon_enc_set_emulation_prevention(enc, false);253radeon_enc_code_fixed_bits(enc, 0x00000001, 32);254radeon_enc_code_fixed_bits(enc, 0x4201, 16);255radeon_enc_byte_align(enc);256radeon_enc_set_emulation_prevention(enc, true);257radeon_enc_code_fixed_bits(enc, 0x0, 4);258radeon_enc_code_fixed_bits(enc, enc->enc_pic.layer_ctrl.max_num_temporal_layers - 1, 3);259radeon_enc_code_fixed_bits(enc, 0x1, 1);260radeon_enc_code_fixed_bits(enc, 0x0, 2);261radeon_enc_code_fixed_bits(enc, enc->enc_pic.general_tier_flag, 1);262radeon_enc_code_fixed_bits(enc, enc->enc_pic.general_profile_idc, 5);263264if (enc->enc_pic.general_profile_idc == 2)265radeon_enc_code_fixed_bits(enc, 0x20000000, 32);266else267radeon_enc_code_fixed_bits(enc, 0x60000000, 32);268269radeon_enc_code_fixed_bits(enc, 0xb0000000, 32);270radeon_enc_code_fixed_bits(enc, 0x0, 16);271radeon_enc_code_fixed_bits(enc, enc->enc_pic.general_level_idc, 8);272273for (i = 0; i < (enc->enc_pic.layer_ctrl.max_num_temporal_layers - 1); i++)274radeon_enc_code_fixed_bits(enc, 0x0, 2);275276if ((enc->enc_pic.layer_ctrl.max_num_temporal_layers - 1) > 0) {277for (i = (enc->enc_pic.layer_ctrl.max_num_temporal_layers - 1); i < 8; i++)278radeon_enc_code_fixed_bits(enc, 0x0, 2);279}280281radeon_enc_code_ue(enc, 0x0);282radeon_enc_code_ue(enc, enc->enc_pic.chroma_format_idc);283radeon_enc_code_ue(enc, enc->enc_pic.session_init.aligned_picture_width);284radeon_enc_code_ue(enc, enc->enc_pic.session_init.aligned_picture_height);285286if ((enc->enc_pic.crop_left != 0) || (enc->enc_pic.crop_right != 0) ||287(enc->enc_pic.crop_top != 0) || (enc->enc_pic.crop_bottom != 0)) {288radeon_enc_code_fixed_bits(enc, 0x1, 1);289radeon_enc_code_ue(enc, enc->enc_pic.crop_left);290radeon_enc_code_ue(enc, enc->enc_pic.crop_right);291radeon_enc_code_ue(enc, enc->enc_pic.crop_top);292radeon_enc_code_ue(enc, enc->enc_pic.crop_bottom);293} else if (enc->enc_pic.session_init.padding_width != 0 ||294enc->enc_pic.session_init.padding_height != 0) {295radeon_enc_code_fixed_bits(enc, 0x1, 1);296radeon_enc_code_ue(enc, enc->enc_pic.session_init.padding_width / 2);297radeon_enc_code_ue(enc, enc->enc_pic.session_init.padding_width / 2);298radeon_enc_code_ue(enc, enc->enc_pic.session_init.padding_height / 2);299radeon_enc_code_ue(enc, enc->enc_pic.session_init.padding_height / 2);300} else301radeon_enc_code_fixed_bits(enc, 0x0, 1);302303radeon_enc_code_ue(enc, enc->enc_pic.bit_depth_luma_minus8);304radeon_enc_code_ue(enc, enc->enc_pic.bit_depth_chroma_minus8);305radeon_enc_code_ue(enc, enc->enc_pic.log2_max_poc - 4);306radeon_enc_code_fixed_bits(enc, 0x0, 1);307radeon_enc_code_ue(enc, 1);308radeon_enc_code_ue(enc, 0x0);309radeon_enc_code_ue(enc, 0x0);310radeon_enc_code_ue(enc, enc->enc_pic.hevc_spec_misc.log2_min_luma_coding_block_size_minus3);311// Only support CTBSize 64312radeon_enc_code_ue(enc,3136 - (enc->enc_pic.hevc_spec_misc.log2_min_luma_coding_block_size_minus3 + 3));314radeon_enc_code_ue(enc, enc->enc_pic.log2_min_transform_block_size_minus2);315radeon_enc_code_ue(enc, enc->enc_pic.log2_diff_max_min_transform_block_size);316radeon_enc_code_ue(enc, enc->enc_pic.max_transform_hierarchy_depth_inter);317radeon_enc_code_ue(enc, enc->enc_pic.max_transform_hierarchy_depth_intra);318319radeon_enc_code_fixed_bits(enc, 0x0, 1);320radeon_enc_code_fixed_bits(enc, !enc->enc_pic.hevc_spec_misc.amp_disabled, 1);321radeon_enc_code_fixed_bits(enc, enc->enc_pic.sample_adaptive_offset_enabled_flag, 1);322radeon_enc_code_fixed_bits(enc, enc->enc_pic.pcm_enabled_flag, 1);323324radeon_enc_code_ue(enc, 1);325radeon_enc_code_ue(enc, 1);326radeon_enc_code_ue(enc, 0);327radeon_enc_code_ue(enc, 0);328radeon_enc_code_fixed_bits(enc, 0x1, 1);329330radeon_enc_code_fixed_bits(enc, 0x0, 1);331332radeon_enc_code_fixed_bits(enc, 0, 1);333radeon_enc_code_fixed_bits(enc, enc->enc_pic.hevc_spec_misc.strong_intra_smoothing_enabled, 1);334335radeon_enc_code_fixed_bits(enc, 0x0, 1);336337radeon_enc_code_fixed_bits(enc, 0x0, 1);338339radeon_enc_code_fixed_bits(enc, 0x1, 1);340341radeon_enc_byte_align(enc);342radeon_enc_flush_headers(enc);343*size_in_bytes = (enc->bits_output + 7) / 8;344RADEON_ENC_END();345}346347static void radeon_enc_nalu_pps_hevc(struct radeon_encoder *enc)348{349RADEON_ENC_BEGIN(enc->cmd.nalu);350RADEON_ENC_CS(RENCODE_DIRECT_OUTPUT_NALU_TYPE_PPS);351uint32_t *size_in_bytes = &enc->cs.current.buf[enc->cs.current.cdw++];352radeon_enc_reset(enc);353radeon_enc_set_emulation_prevention(enc, false);354radeon_enc_code_fixed_bits(enc, 0x00000001, 32);355radeon_enc_code_fixed_bits(enc, 0x4401, 16);356radeon_enc_byte_align(enc);357radeon_enc_set_emulation_prevention(enc, true);358radeon_enc_code_ue(enc, 0x0);359radeon_enc_code_ue(enc, 0x0);360radeon_enc_code_fixed_bits(enc, 0x1, 1);361radeon_enc_code_fixed_bits(enc, 0x0, 4);362radeon_enc_code_fixed_bits(enc, 0x0, 1);363radeon_enc_code_fixed_bits(enc, 0x1, 1);364radeon_enc_code_ue(enc, 0x0);365radeon_enc_code_ue(enc, 0x0);366radeon_enc_code_se(enc, 0x0);367radeon_enc_code_fixed_bits(enc, enc->enc_pic.hevc_spec_misc.constrained_intra_pred_flag, 1);368radeon_enc_code_fixed_bits(enc, 0x0, 1);369if (enc->enc_pic.rc_session_init.rate_control_method == RENCODE_RATE_CONTROL_METHOD_NONE)370radeon_enc_code_fixed_bits(enc, 0x0, 1);371else {372radeon_enc_code_fixed_bits(enc, 0x1, 1);373radeon_enc_code_ue(enc, 0x0);374}375radeon_enc_code_se(enc, enc->enc_pic.hevc_deblock.cb_qp_offset);376radeon_enc_code_se(enc, enc->enc_pic.hevc_deblock.cr_qp_offset);377radeon_enc_code_fixed_bits(enc, 0x0, 1);378radeon_enc_code_fixed_bits(enc, 0x0, 2);379radeon_enc_code_fixed_bits(enc, 0x0, 1);380radeon_enc_code_fixed_bits(enc, 0x0, 1);381radeon_enc_code_fixed_bits(enc, 0x0, 1);382radeon_enc_code_fixed_bits(enc, enc->enc_pic.hevc_deblock.loop_filter_across_slices_enabled, 1);383radeon_enc_code_fixed_bits(enc, 0x1, 1);384radeon_enc_code_fixed_bits(enc, 0x0, 1);385radeon_enc_code_fixed_bits(enc, enc->enc_pic.hevc_deblock.deblocking_filter_disabled, 1);386387if (!enc->enc_pic.hevc_deblock.deblocking_filter_disabled) {388radeon_enc_code_se(enc, enc->enc_pic.hevc_deblock.beta_offset_div2);389radeon_enc_code_se(enc, enc->enc_pic.hevc_deblock.tc_offset_div2);390}391392radeon_enc_code_fixed_bits(enc, 0x0, 1);393radeon_enc_code_fixed_bits(enc, 0x0, 1);394radeon_enc_code_ue(enc, enc->enc_pic.log2_parallel_merge_level_minus2);395radeon_enc_code_fixed_bits(enc, 0x0, 2);396397radeon_enc_code_fixed_bits(enc, 0x1, 1);398399radeon_enc_byte_align(enc);400radeon_enc_flush_headers(enc);401*size_in_bytes = (enc->bits_output + 7) / 8;402RADEON_ENC_END();403}404405static void radeon_enc_input_format(struct radeon_encoder *enc)406{407RADEON_ENC_BEGIN(enc->cmd.input_format);408if (enc->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) {409RADEON_ENC_CS(RENCODE_COLOR_VOLUME_G10_BT2020);410RADEON_ENC_CS(0);411RADEON_ENC_CS(0);412RADEON_ENC_CS(0);413RADEON_ENC_CS(0);414RADEON_ENC_CS(RENCODE_COLOR_BIT_DEPTH_10_BIT);415RADEON_ENC_CS(RENCODE_COLOR_PACKING_FORMAT_P010);416} else {417RADEON_ENC_CS(RENCODE_COLOR_VOLUME_G22_BT709);418RADEON_ENC_CS(0);419RADEON_ENC_CS(0);420RADEON_ENC_CS(0);421RADEON_ENC_CS(0);422RADEON_ENC_CS(RENCODE_COLOR_BIT_DEPTH_8_BIT);423RADEON_ENC_CS(RENCODE_COLOR_PACKING_FORMAT_NV12);424}425RADEON_ENC_END();426}427428static void radeon_enc_output_format(struct radeon_encoder *enc)429{430RADEON_ENC_BEGIN(enc->cmd.output_format);431if (enc->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) {432RADEON_ENC_CS(RENCODE_COLOR_VOLUME_G10_BT2020);433RADEON_ENC_CS(0);434RADEON_ENC_CS(0);435RADEON_ENC_CS(RENCODE_COLOR_BIT_DEPTH_10_BIT);436} else {437RADEON_ENC_CS(RENCODE_COLOR_VOLUME_G22_BT709);438RADEON_ENC_CS(0);439RADEON_ENC_CS(0);440RADEON_ENC_CS(RENCODE_COLOR_BIT_DEPTH_8_BIT);441}442RADEON_ENC_END();443}444445static void radeon_enc_ctx(struct radeon_encoder *enc)446{447enc->enc_pic.ctx_buf.swizzle_mode = 0;448449uint32_t aligned_width = enc->enc_pic.session_init.aligned_picture_width;450uint32_t aligned_height = enc->enc_pic.session_init.aligned_picture_height;451452enc->enc_pic.ctx_buf.rec_luma_pitch = align(aligned_width, enc->alignment);453enc->enc_pic.ctx_buf.rec_chroma_pitch = align(aligned_width, enc->alignment);454455int luma_size = enc->enc_pic.ctx_buf.rec_luma_pitch * align(aligned_height, enc->alignment);456if (enc->enc_pic.bit_depth_luma_minus8 == 2)457luma_size *= 2;458int chroma_size = align(luma_size / 2, enc->alignment);459int offset = 0;460461enc->enc_pic.ctx_buf.num_reconstructed_pictures = 2;462for (int i = 0; i < enc->enc_pic.ctx_buf.num_reconstructed_pictures; i++) {463enc->enc_pic.ctx_buf.reconstructed_pictures[i].luma_offset = offset;464offset += luma_size;465enc->enc_pic.ctx_buf.reconstructed_pictures[i].chroma_offset = offset;466offset += chroma_size;467}468469RADEON_ENC_BEGIN(enc->cmd.ctx);470RADEON_ENC_READWRITE(enc->cpb.res->buf, enc->cpb.res->domains, 0);471RADEON_ENC_CS(enc->enc_pic.ctx_buf.swizzle_mode);472RADEON_ENC_CS(enc->enc_pic.ctx_buf.rec_luma_pitch);473RADEON_ENC_CS(enc->enc_pic.ctx_buf.rec_chroma_pitch);474RADEON_ENC_CS(enc->enc_pic.ctx_buf.num_reconstructed_pictures);475476for (int i = 0; i < enc->enc_pic.ctx_buf.num_reconstructed_pictures; i++) {477RADEON_ENC_CS(enc->enc_pic.ctx_buf.reconstructed_pictures[i].luma_offset);478RADEON_ENC_CS(enc->enc_pic.ctx_buf.reconstructed_pictures[i].chroma_offset);479}480481for (int i = 0; i < 136; i++)482RADEON_ENC_CS(0x00000000);483484RADEON_ENC_END();485}486487static void encode(struct radeon_encoder *enc)488{489enc->session_info(enc);490enc->total_task_size = 0;491enc->task_info(enc, enc->need_feedback);492493enc->encode_headers(enc);494enc->ctx(enc);495enc->bitstream(enc);496enc->feedback(enc);497enc->intra_refresh(enc);498enc->input_format(enc);499enc->output_format(enc);500501enc->op_preset(enc);502enc->op_enc(enc);503*enc->p_task_size = (enc->total_task_size);504}505506void radeon_enc_2_0_init(struct radeon_encoder *enc)507{508radeon_enc_1_2_init(enc);509enc->encode = encode;510enc->ctx = radeon_enc_ctx;511enc->quality_params = radeon_enc_quality_params;512enc->input_format = radeon_enc_input_format;513enc->output_format = radeon_enc_output_format;514515if (u_reduce_video_profile(enc->base.profile) == PIPE_VIDEO_FORMAT_HEVC) {516enc->deblocking_filter = radeon_enc_loop_filter_hevc;517enc->nalu_sps = radeon_enc_nalu_sps_hevc;518enc->nalu_pps = radeon_enc_nalu_pps_hevc;519enc->slice_header = radeon_enc_slice_header_hevc;520enc->op_preset = radeon_enc_op_balance;521}522523enc->cmd.session_info = RENCODE_IB_PARAM_SESSION_INFO;524enc->cmd.task_info = RENCODE_IB_PARAM_TASK_INFO;525enc->cmd.session_init = RENCODE_IB_PARAM_SESSION_INIT;526enc->cmd.layer_control = RENCODE_IB_PARAM_LAYER_CONTROL;527enc->cmd.layer_select = RENCODE_IB_PARAM_LAYER_SELECT;528enc->cmd.rc_session_init = RENCODE_IB_PARAM_RATE_CONTROL_SESSION_INIT;529enc->cmd.rc_layer_init = RENCODE_IB_PARAM_RATE_CONTROL_LAYER_INIT;530enc->cmd.rc_per_pic = RENCODE_IB_PARAM_RATE_CONTROL_PER_PICTURE;531enc->cmd.quality_params = RENCODE_IB_PARAM_QUALITY_PARAMS;532enc->cmd.nalu = RENCODE_IB_PARAM_DIRECT_OUTPUT_NALU;533enc->cmd.slice_header = RENCODE_IB_PARAM_SLICE_HEADER;534enc->cmd.input_format = RENCODE_IB_PARAM_INPUT_FORMAT;535enc->cmd.output_format = RENCODE_IB_PARAM_OUTPUT_FORMAT;536enc->cmd.enc_params = RENCODE_IB_PARAM_ENCODE_PARAMS;537enc->cmd.intra_refresh = RENCODE_IB_PARAM_INTRA_REFRESH;538enc->cmd.ctx = RENCODE_IB_PARAM_ENCODE_CONTEXT_BUFFER;539enc->cmd.bitstream = RENCODE_IB_PARAM_VIDEO_BITSTREAM_BUFFER;540enc->cmd.feedback = RENCODE_IB_PARAM_FEEDBACK_BUFFER;541enc->cmd.slice_control_hevc = RENCODE_HEVC_IB_PARAM_SLICE_CONTROL;542enc->cmd.spec_misc_hevc = RENCODE_HEVC_IB_PARAM_SPEC_MISC;543enc->cmd.deblocking_filter_hevc = RENCODE_HEVC_IB_PARAM_LOOP_FILTER;544enc->cmd.slice_control_h264 = RENCODE_H264_IB_PARAM_SLICE_CONTROL;545enc->cmd.spec_misc_h264 = RENCODE_H264_IB_PARAM_SPEC_MISC;546enc->cmd.enc_params_h264 = RENCODE_H264_IB_PARAM_ENCODE_PARAMS;547enc->cmd.deblocking_filter_h264 = RENCODE_H264_IB_PARAM_DEBLOCKING_FILTER;548549enc->enc_pic.session_info.interface_version =550((RENCODE_FW_INTERFACE_MAJOR_VERSION << RENCODE_IF_MAJOR_VERSION_SHIFT) |551(RENCODE_FW_INTERFACE_MINOR_VERSION << RENCODE_IF_MINOR_VERSION_SHIFT));552}553554555