Path: blob/21.2-virgl/src/gallium/drivers/radeon/radeon_vce.h
4570 views
/**************************************************************************1*2* Copyright 2013 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#ifndef RADEON_VCE_H28#define RADEON_VCE_H2930#include "radeon_video.h"31#include "util/list.h"3233#define RVCE_CS(value) (enc->cs.current.buf[enc->cs.current.cdw++] = (value))34#define RVCE_BEGIN(cmd) \35{ \36uint32_t *begin = &enc->cs.current.buf[enc->cs.current.cdw++]; \37RVCE_CS(cmd)38#define RVCE_READ(buf, domain, off) \39si_vce_add_buffer(enc, (buf), RADEON_USAGE_READ, (domain), (off))40#define RVCE_WRITE(buf, domain, off) \41si_vce_add_buffer(enc, (buf), RADEON_USAGE_WRITE, (domain), (off))42#define RVCE_READWRITE(buf, domain, off) \43si_vce_add_buffer(enc, (buf), RADEON_USAGE_READWRITE, (domain), (off))44#define RVCE_END() \45*begin = (&enc->cs.current.buf[enc->cs.current.cdw] - begin) * 4; \46}4748#define RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE (4096 * 16 * 2.5)49#define RVCE_MAX_AUX_BUFFER_NUM 45051struct si_screen;5253/* driver dependent callback */54typedef void (*rvce_get_buffer)(struct pipe_resource *resource, struct pb_buffer **handle,55struct radeon_surf **surface);5657/* Coded picture buffer slot */58struct rvce_cpb_slot {59struct list_head list;6061unsigned index;62enum pipe_h2645_enc_picture_type picture_type;63unsigned frame_num;64unsigned pic_order_cnt;65};6667struct rvce_rate_control {68uint32_t rc_method;69uint32_t target_bitrate;70uint32_t peak_bitrate;71uint32_t frame_rate_num;72uint32_t gop_size;73uint32_t quant_i_frames;74uint32_t quant_p_frames;75uint32_t quant_b_frames;76uint32_t vbv_buffer_size;77uint32_t frame_rate_den;78uint32_t vbv_buf_lv;79uint32_t max_au_size;80uint32_t qp_initial_mode;81uint32_t target_bits_picture;82uint32_t peak_bits_picture_integer;83uint32_t peak_bits_picture_fraction;84uint32_t min_qp;85uint32_t max_qp;86uint32_t skip_frame_enable;87uint32_t fill_data_enable;88uint32_t enforce_hrd;89uint32_t b_pics_delta_qp;90uint32_t ref_b_pics_delta_qp;91uint32_t rc_reinit_disable;92uint32_t enc_lcvbr_init_qp_flag;93uint32_t lcvbrsatd_based_nonlinear_bit_budget_flag;94};9596struct rvce_motion_estimation {97uint32_t enc_ime_decimation_search;98uint32_t motion_est_half_pixel;99uint32_t motion_est_quarter_pixel;100uint32_t disable_favor_pmv_point;101uint32_t force_zero_point_center;102uint32_t lsmvert;103uint32_t enc_search_range_x;104uint32_t enc_search_range_y;105uint32_t enc_search1_range_x;106uint32_t enc_search1_range_y;107uint32_t disable_16x16_frame1;108uint32_t disable_satd;109uint32_t enable_amd;110uint32_t enc_disable_sub_mode;111uint32_t enc_ime_skip_x;112uint32_t enc_ime_skip_y;113uint32_t enc_en_ime_overw_dis_subm;114uint32_t enc_ime_overw_dis_subm_no;115uint32_t enc_ime2_search_range_x;116uint32_t enc_ime2_search_range_y;117uint32_t parallel_mode_speedup_enable;118uint32_t fme0_enc_disable_sub_mode;119uint32_t fme1_enc_disable_sub_mode;120uint32_t ime_sw_speedup_enable;121};122123struct rvce_pic_control {124uint32_t enc_use_constrained_intra_pred;125uint32_t enc_cabac_enable;126uint32_t enc_cabac_idc;127uint32_t enc_loop_filter_disable;128int32_t enc_lf_beta_offset;129int32_t enc_lf_alpha_c0_offset;130uint32_t enc_crop_left_offset;131uint32_t enc_crop_right_offset;132uint32_t enc_crop_top_offset;133uint32_t enc_crop_bottom_offset;134uint32_t enc_num_mbs_per_slice;135uint32_t enc_intra_refresh_num_mbs_per_slot;136uint32_t enc_force_intra_refresh;137uint32_t enc_force_imb_period;138uint32_t enc_pic_order_cnt_type;139uint32_t log2_max_pic_order_cnt_lsb_minus4;140uint32_t enc_sps_id;141uint32_t enc_pps_id;142uint32_t enc_constraint_set_flags;143uint32_t enc_b_pic_pattern;144uint32_t weight_pred_mode_b_picture;145uint32_t enc_number_of_reference_frames;146uint32_t enc_max_num_ref_frames;147uint32_t enc_num_default_active_ref_l0;148uint32_t enc_num_default_active_ref_l1;149uint32_t enc_slice_mode;150uint32_t enc_max_slice_size;151};152153struct rvce_task_info {154uint32_t offset_of_next_task_info;155uint32_t task_operation;156uint32_t reference_picture_dependency;157uint32_t collocate_flag_dependency;158uint32_t feedback_index;159uint32_t video_bitstream_ring_index;160};161162struct rvce_feedback_buf_pkg {163uint32_t feedback_ring_address_hi;164uint32_t feedback_ring_address_lo;165uint32_t feedback_ring_size;166};167168struct rvce_rdo {169uint32_t enc_disable_tbe_pred_i_frame;170uint32_t enc_disable_tbe_pred_p_frame;171uint32_t use_fme_interpol_y;172uint32_t use_fme_interpol_uv;173uint32_t use_fme_intrapol_y;174uint32_t use_fme_intrapol_uv;175uint32_t use_fme_interpol_y_1;176uint32_t use_fme_interpol_uv_1;177uint32_t use_fme_intrapol_y_1;178uint32_t use_fme_intrapol_uv_1;179uint32_t enc_16x16_cost_adj;180uint32_t enc_skip_cost_adj;181uint32_t enc_force_16x16_skip;182uint32_t enc_disable_threshold_calc_a;183uint32_t enc_luma_coeff_cost;184uint32_t enc_luma_mb_coeff_cost;185uint32_t enc_chroma_coeff_cost;186};187188struct rvce_vui {189uint32_t aspect_ratio_info_present_flag;190uint32_t aspect_ratio_idc;191uint32_t sar_width;192uint32_t sar_height;193uint32_t overscan_info_present_flag;194uint32_t overscan_Approp_flag;195uint32_t video_signal_type_present_flag;196uint32_t video_format;197uint32_t video_full_range_flag;198uint32_t color_description_present_flag;199uint32_t color_prim;200uint32_t transfer_char;201uint32_t matrix_coef;202uint32_t chroma_loc_info_present_flag;203uint32_t chroma_loc_top;204uint32_t chroma_loc_bottom;205uint32_t timing_info_present_flag;206uint32_t num_units_in_tick;207uint32_t time_scale;208uint32_t fixed_frame_rate_flag;209uint32_t nal_hrd_parameters_present_flag;210uint32_t cpb_cnt_minus1;211uint32_t bit_rate_scale;212uint32_t cpb_size_scale;213uint32_t bit_rate_value_minus;214uint32_t cpb_size_value_minus;215uint32_t cbr_flag;216uint32_t initial_cpb_removal_delay_length_minus1;217uint32_t cpb_removal_delay_length_minus1;218uint32_t dpb_output_delay_length_minus1;219uint32_t time_offset_length;220uint32_t low_delay_hrd_flag;221uint32_t pic_struct_present_flag;222uint32_t bitstream_restriction_present_flag;223uint32_t motion_vectors_over_pic_boundaries_flag;224uint32_t max_bytes_per_pic_denom;225uint32_t max_bits_per_mb_denom;226uint32_t log2_max_mv_length_hori;227uint32_t log2_max_mv_length_vert;228uint32_t num_reorder_frames;229uint32_t max_dec_frame_buffering;230};231232struct rvce_enc_operation {233uint32_t insert_headers;234uint32_t picture_structure;235uint32_t allowed_max_bitstream_size;236uint32_t force_refresh_map;237uint32_t insert_aud;238uint32_t end_of_sequence;239uint32_t end_of_stream;240uint32_t input_picture_luma_address_hi;241uint32_t input_picture_luma_address_lo;242uint32_t input_picture_chroma_address_hi;243uint32_t input_picture_chroma_address_lo;244uint32_t enc_input_frame_y_pitch;245uint32_t enc_input_pic_luma_pitch;246uint32_t enc_input_pic_chroma_pitch;247;248uint32_t enc_input_pic_addr_array;249uint32_t enc_input_pic_addr_array_disable2pipe_disablemboffload;250uint32_t enc_input_pic_tile_config;251uint32_t enc_pic_type;252uint32_t enc_idr_flag;253uint32_t enc_idr_pic_id;254uint32_t enc_mgs_key_pic;255uint32_t enc_reference_flag;256uint32_t enc_temporal_layer_index;257uint32_t num_ref_idx_active_override_flag;258uint32_t num_ref_idx_l0_active_minus1;259uint32_t num_ref_idx_l1_active_minus1;260uint32_t enc_ref_list_modification_op;261uint32_t enc_ref_list_modification_num;262uint32_t enc_decoded_picture_marking_op;263uint32_t enc_decoded_picture_marking_num;264uint32_t enc_decoded_picture_marking_idx;265uint32_t enc_decoded_ref_base_picture_marking_op;266uint32_t enc_decoded_ref_base_picture_marking_num;267uint32_t l0_picture_structure;268uint32_t l0_enc_pic_type;269uint32_t l0_frame_number;270uint32_t l0_picture_order_count;271uint32_t l0_luma_offset;272uint32_t l0_chroma_offset;273uint32_t l1_picture_structure;274uint32_t l1_enc_pic_type;275uint32_t l1_frame_number;276uint32_t l1_picture_order_count;277uint32_t l1_luma_offset;278uint32_t l1_chroma_offset;279uint32_t enc_reconstructed_luma_offset;280uint32_t enc_reconstructed_chroma_offset;281;282uint32_t enc_coloc_buffer_offset;283uint32_t enc_reconstructed_ref_base_picture_luma_offset;284uint32_t enc_reconstructed_ref_base_picture_chroma_offset;285uint32_t enc_reference_ref_base_picture_luma_offset;286uint32_t enc_reference_ref_base_picture_chroma_offset;287uint32_t picture_count;288uint32_t frame_number;289uint32_t picture_order_count;290uint32_t num_i_pic_remain_in_rcgop;291uint32_t num_p_pic_remain_in_rcgop;292uint32_t num_b_pic_remain_in_rcgop;293uint32_t num_ir_pic_remain_in_rcgop;294uint32_t enable_intra_refresh;295uint32_t aq_variance_en;296uint32_t aq_block_size;297uint32_t aq_mb_variance_sel;298uint32_t aq_frame_variance_sel;299uint32_t aq_param_a;300uint32_t aq_param_b;301uint32_t aq_param_c;302uint32_t aq_param_d;303uint32_t aq_param_e;304uint32_t context_in_sfb;305};306307struct rvce_enc_create {308uint32_t enc_use_circular_buffer;309uint32_t enc_profile;310uint32_t enc_level;311uint32_t enc_pic_struct_restriction;312uint32_t enc_image_width;313uint32_t enc_image_height;314uint32_t enc_ref_pic_luma_pitch;315uint32_t enc_ref_pic_chroma_pitch;316uint32_t enc_ref_y_height_in_qw;317uint32_t enc_ref_pic_addr_array_enc_pic_struct_restriction_disable_rdo;318uint32_t enc_pre_encode_context_buffer_offset;319uint32_t enc_pre_encode_input_luma_buffer_offset;320uint32_t enc_pre_encode_input_chroma_buffer_offset;321uint32_t enc_pre_encode_mode_chromaflag_vbaqmode_scenechangesensitivity;322};323324struct rvce_config_ext {325uint32_t enc_enable_perf_logging;326};327328struct rvce_h264_enc_pic {329struct rvce_rate_control rc;330struct rvce_motion_estimation me;331struct rvce_pic_control pc;332struct rvce_task_info ti;333struct rvce_feedback_buf_pkg fb;334struct rvce_rdo rdo;335struct rvce_vui vui;336struct rvce_enc_operation eo;337struct rvce_enc_create ec;338struct rvce_config_ext ce;339340unsigned quant_i_frames;341unsigned quant_p_frames;342unsigned quant_b_frames;343344enum pipe_h2645_enc_picture_type picture_type;345unsigned frame_num;346unsigned frame_num_cnt;347unsigned p_remain;348unsigned i_remain;349unsigned idr_pic_id;350unsigned gop_cnt;351unsigned gop_size;352unsigned pic_order_cnt;353unsigned ref_idx_l0;354unsigned ref_idx_l1;355unsigned addrmode_arraymode_disrdo_distwoinstants;356357bool not_referenced;358bool is_idr;359bool has_ref_pic_list;360bool enable_vui;361unsigned int ref_pic_list_0[32];362unsigned int ref_pic_list_1[32];363unsigned int frame_idx[32];364};365366/* VCE encoder representation */367struct rvce_encoder {368struct pipe_video_codec base;369370/* version specific packets */371void (*session)(struct rvce_encoder *enc);372void (*create)(struct rvce_encoder *enc);373void (*feedback)(struct rvce_encoder *enc);374void (*rate_control)(struct rvce_encoder *enc);375void (*config_extension)(struct rvce_encoder *enc);376void (*pic_control)(struct rvce_encoder *enc);377void (*motion_estimation)(struct rvce_encoder *enc);378void (*rdo)(struct rvce_encoder *enc);379void (*vui)(struct rvce_encoder *enc);380void (*config)(struct rvce_encoder *enc);381void (*encode)(struct rvce_encoder *enc);382void (*destroy)(struct rvce_encoder *enc);383void (*task_info)(struct rvce_encoder *enc, uint32_t op, uint32_t dep, uint32_t fb_idx,384uint32_t ring_idx);385void (*si_get_pic_param)(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic);386387unsigned stream_handle;388389struct pipe_screen *screen;390struct radeon_winsys *ws;391struct radeon_cmdbuf cs;392393rvce_get_buffer get_buffer;394395struct pb_buffer *handle;396struct radeon_surf *luma;397struct radeon_surf *chroma;398399struct pb_buffer *bs_handle;400unsigned bs_size;401402struct rvce_cpb_slot *cpb_array;403struct list_head cpb_slots;404unsigned cpb_num;405406struct rvid_buffer *fb;407struct rvid_buffer cpb;408struct pipe_h264_enc_picture_desc pic;409struct rvce_h264_enc_pic enc_pic;410411unsigned task_info_idx;412unsigned bs_idx;413414bool use_vm;415bool use_vui;416bool dual_pipe;417bool dual_inst;418};419420/* CPB handling functions */421struct rvce_cpb_slot *si_current_slot(struct rvce_encoder *enc);422struct rvce_cpb_slot *si_l0_slot(struct rvce_encoder *enc);423struct rvce_cpb_slot *si_l1_slot(struct rvce_encoder *enc);424void si_vce_frame_offset(struct rvce_encoder *enc, struct rvce_cpb_slot *slot, signed *luma_offset,425signed *chroma_offset);426427struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,428const struct pipe_video_codec *templat,429struct radeon_winsys *ws,430rvce_get_buffer get_buffer);431432bool si_vce_is_fw_version_supported(struct si_screen *sscreen);433434void si_vce_add_buffer(struct rvce_encoder *enc, struct pb_buffer *buf, enum radeon_bo_usage usage,435enum radeon_bo_domain domain, signed offset);436437/* init vce fw 40.2.2 specific callbacks */438void si_vce_40_2_2_init(struct rvce_encoder *enc);439440/* init vce fw 50 specific callbacks */441void si_vce_50_init(struct rvce_encoder *enc);442443/* init vce fw 52 specific callbacks */444void si_vce_52_init(struct rvce_encoder *enc);445446/* get parameters for vce 40.2.2 */447void si_vce_40_2_2_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic);448449/* get parameters for vce 50 */450void si_vce_50_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic);451452/* get parameters for vce 52 */453void si_vce_52_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic);454455#endif456457458