1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2017 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 "radeon_vcn_dec.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "pipe/p_video_codec.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_mpeg12_decoder.h" 35bf215546Sopenharmony_ci#include "vl/vl_probs_table.h" 36bf215546Sopenharmony_ci#include "pspdecryptionparam.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci#include <assert.h> 39bf215546Sopenharmony_ci#include <stdio.h> 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#include "radeon_vcn_av1_default.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci#define FB_BUFFER_OFFSET 0x1000 44bf215546Sopenharmony_ci#define FB_BUFFER_SIZE 2048 45bf215546Sopenharmony_ci#define IT_SCALING_TABLE_SIZE 992 46bf215546Sopenharmony_ci#define VP9_PROBS_TABLE_SIZE (RDECODE_VP9_PROBS_DATA_SIZE + 256) 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci#define NUM_MPEG2_REFS 6 49bf215546Sopenharmony_ci#define NUM_H264_REFS 17 50bf215546Sopenharmony_ci#define NUM_VC1_REFS 5 51bf215546Sopenharmony_ci#define NUM_VP9_REFS 8 52bf215546Sopenharmony_ci#define NUM_AV1_REFS 8 53bf215546Sopenharmony_ci#define NUM_AV1_REFS_PER_FRAME 7 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_cistatic unsigned calc_dpb_size(struct radeon_decoder *dec); 56bf215546Sopenharmony_cistatic unsigned calc_ctx_size_h264_perf(struct radeon_decoder *dec); 57bf215546Sopenharmony_cistatic unsigned calc_ctx_size_h265_main(struct radeon_decoder *dec); 58bf215546Sopenharmony_cistatic unsigned calc_ctx_size_h265_main10(struct radeon_decoder *dec, 59bf215546Sopenharmony_ci struct pipe_h265_picture_desc *pic); 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_cistatic void radeon_dec_destroy_associated_data(void *data) 62bf215546Sopenharmony_ci{ 63bf215546Sopenharmony_ci /* NOOP, since we only use an intptr */ 64bf215546Sopenharmony_ci} 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_cistatic rvcn_dec_message_avc_t get_h264_msg(struct radeon_decoder *dec, 67bf215546Sopenharmony_ci struct pipe_video_buffer *target, 68bf215546Sopenharmony_ci struct pipe_h264_picture_desc *pic) 69bf215546Sopenharmony_ci{ 70bf215546Sopenharmony_ci rvcn_dec_message_avc_t result; 71bf215546Sopenharmony_ci struct h264_private *private; 72bf215546Sopenharmony_ci unsigned i, j, k; 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 75bf215546Sopenharmony_ci switch (pic->base.profile) { 76bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE: 77bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE: 78bf215546Sopenharmony_ci result.profile = RDECODE_H264_PROFILE_BASELINE; 79bf215546Sopenharmony_ci break; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: 82bf215546Sopenharmony_ci result.profile = RDECODE_H264_PROFILE_MAIN; 83bf215546Sopenharmony_ci break; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH: 86bf215546Sopenharmony_ci result.profile = RDECODE_H264_PROFILE_HIGH; 87bf215546Sopenharmony_ci break; 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci default: 90bf215546Sopenharmony_ci assert(0); 91bf215546Sopenharmony_ci break; 92bf215546Sopenharmony_ci } 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci result.level = dec->base.level; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci result.sps_info_flags = 0; 97bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->direct_8x8_inference_flag << 0; 98bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->mb_adaptive_frame_field_flag << 1; 99bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->frame_mbs_only_flag << 2; 100bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->delta_pic_order_always_zero_flag << 3; 101bf215546Sopenharmony_ci result.sps_info_flags |= ((dec->dpb_type == DPB_DYNAMIC_TIER_2) ? 0 : 1) 102bf215546Sopenharmony_ci << RDECODE_SPS_INFO_H264_EXTENSION_SUPPORT_FLAG_SHIFT; 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci result.bit_depth_luma_minus8 = pic->pps->sps->bit_depth_luma_minus8; 105bf215546Sopenharmony_ci result.bit_depth_chroma_minus8 = pic->pps->sps->bit_depth_chroma_minus8; 106bf215546Sopenharmony_ci result.log2_max_frame_num_minus4 = pic->pps->sps->log2_max_frame_num_minus4; 107bf215546Sopenharmony_ci result.pic_order_cnt_type = pic->pps->sps->pic_order_cnt_type; 108bf215546Sopenharmony_ci result.log2_max_pic_order_cnt_lsb_minus4 = pic->pps->sps->log2_max_pic_order_cnt_lsb_minus4; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci switch (dec->base.chroma_format) { 111bf215546Sopenharmony_ci case PIPE_VIDEO_CHROMA_FORMAT_NONE: 112bf215546Sopenharmony_ci break; 113bf215546Sopenharmony_ci case PIPE_VIDEO_CHROMA_FORMAT_400: 114bf215546Sopenharmony_ci result.chroma_format = 0; 115bf215546Sopenharmony_ci break; 116bf215546Sopenharmony_ci case PIPE_VIDEO_CHROMA_FORMAT_420: 117bf215546Sopenharmony_ci result.chroma_format = 1; 118bf215546Sopenharmony_ci break; 119bf215546Sopenharmony_ci case PIPE_VIDEO_CHROMA_FORMAT_422: 120bf215546Sopenharmony_ci result.chroma_format = 2; 121bf215546Sopenharmony_ci break; 122bf215546Sopenharmony_ci case PIPE_VIDEO_CHROMA_FORMAT_444: 123bf215546Sopenharmony_ci result.chroma_format = 3; 124bf215546Sopenharmony_ci break; 125bf215546Sopenharmony_ci } 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci result.pps_info_flags = 0; 128bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->transform_8x8_mode_flag << 0; 129bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->redundant_pic_cnt_present_flag << 1; 130bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->constrained_intra_pred_flag << 2; 131bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->deblocking_filter_control_present_flag << 3; 132bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->weighted_bipred_idc << 4; 133bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->weighted_pred_flag << 6; 134bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->bottom_field_pic_order_in_frame_present_flag << 7; 135bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->entropy_coding_mode_flag << 8; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci result.num_slice_groups_minus1 = pic->pps->num_slice_groups_minus1; 138bf215546Sopenharmony_ci result.slice_group_map_type = pic->pps->slice_group_map_type; 139bf215546Sopenharmony_ci result.slice_group_change_rate_minus1 = pic->pps->slice_group_change_rate_minus1; 140bf215546Sopenharmony_ci result.pic_init_qp_minus26 = pic->pps->pic_init_qp_minus26; 141bf215546Sopenharmony_ci result.chroma_qp_index_offset = pic->pps->chroma_qp_index_offset; 142bf215546Sopenharmony_ci result.second_chroma_qp_index_offset = pic->pps->second_chroma_qp_index_offset; 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci memcpy(result.scaling_list_4x4, pic->pps->ScalingList4x4, 6 * 16); 145bf215546Sopenharmony_ci memcpy(result.scaling_list_8x8, pic->pps->ScalingList8x8, 2 * 64); 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci memcpy(dec->it, result.scaling_list_4x4, 6 * 16); 148bf215546Sopenharmony_ci memcpy((dec->it + 96), result.scaling_list_8x8, 2 * 64); 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci result.num_ref_frames = pic->num_ref_frames; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci result.num_ref_idx_l0_active_minus1 = pic->num_ref_idx_l0_active_minus1; 153bf215546Sopenharmony_ci result.num_ref_idx_l1_active_minus1 = pic->num_ref_idx_l1_active_minus1; 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci result.frame_num = pic->frame_num; 156bf215546Sopenharmony_ci memcpy(result.frame_num_list, pic->frame_num_list, 4 * 16); 157bf215546Sopenharmony_ci result.curr_field_order_cnt_list[0] = pic->field_order_cnt[0]; 158bf215546Sopenharmony_ci result.curr_field_order_cnt_list[1] = pic->field_order_cnt[1]; 159bf215546Sopenharmony_ci memcpy(result.field_order_cnt_list, pic->field_order_cnt_list, 4 * 16 * 2); 160bf215546Sopenharmony_ci result.non_existing_frame_flags = 0; 161bf215546Sopenharmony_ci result.used_for_reference_flags = 0; 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci if (dec->dpb_type != DPB_DYNAMIC_TIER_2) { 164bf215546Sopenharmony_ci result.decoded_pic_idx = pic->frame_num; 165bf215546Sopenharmony_ci goto end; 166bf215546Sopenharmony_ci } 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci private = pic->priv; 169bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(private->past_ref); i++) { 170bf215546Sopenharmony_ci for (k = 0; private->past_ref[i] && (k < ARRAY_SIZE(pic->ref)); k++) 171bf215546Sopenharmony_ci if (pic->ref[k] && (private->past_ref[i] == pic->ref[k])) 172bf215546Sopenharmony_ci break; 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci for (j = 0; private->past_ref[i] 175bf215546Sopenharmony_ci && (k == ARRAY_SIZE(pic->ref)) 176bf215546Sopenharmony_ci && (j < ARRAY_SIZE(dec->render_pic_list)); j++) { 177bf215546Sopenharmony_ci if (dec->render_pic_list[j] 178bf215546Sopenharmony_ci && (dec->render_pic_list[j] == private->past_ref[i])) { 179bf215546Sopenharmony_ci dec->render_pic_list[j] = pic->ref[i]; 180bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(pic->ref[i], &dec->base, 181bf215546Sopenharmony_ci (void *)(uintptr_t)j, &radeon_dec_destroy_associated_data); 182bf215546Sopenharmony_ci break; 183bf215546Sopenharmony_ci } 184bf215546Sopenharmony_ci } 185bf215546Sopenharmony_ci } 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); i++) { 188bf215546Sopenharmony_ci for (j = 0; (pic->ref[j] != NULL) && (j < ARRAY_SIZE(dec->render_pic_list)); j++) { 189bf215546Sopenharmony_ci if (dec->render_pic_list[i] == pic->ref[j]) 190bf215546Sopenharmony_ci break; 191bf215546Sopenharmony_ci if (j == ARRAY_SIZE(dec->render_pic_list) - 1) 192bf215546Sopenharmony_ci dec->render_pic_list[i] = NULL; 193bf215546Sopenharmony_ci else if (pic->ref[j + 1] == NULL) 194bf215546Sopenharmony_ci dec->render_pic_list[i] = NULL; 195bf215546Sopenharmony_ci } 196bf215546Sopenharmony_ci } 197bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); ++i) { 198bf215546Sopenharmony_ci if (dec->render_pic_list[i] && dec->render_pic_list[i] == target) { 199bf215546Sopenharmony_ci if (target->codec != NULL){ 200bf215546Sopenharmony_ci result.decoded_pic_idx = 201bf215546Sopenharmony_ci (uintptr_t)vl_video_buffer_get_associated_data(target, &dec->base); 202bf215546Sopenharmony_ci } else { 203bf215546Sopenharmony_ci result.decoded_pic_idx = i; 204bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, &dec->base, (void *)(uintptr_t)i, 205bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 206bf215546Sopenharmony_ci } 207bf215546Sopenharmony_ci break; 208bf215546Sopenharmony_ci } 209bf215546Sopenharmony_ci } 210bf215546Sopenharmony_ci if (i == ARRAY_SIZE(dec->render_pic_list)) { 211bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); ++i) { 212bf215546Sopenharmony_ci if (!dec->render_pic_list[i]) { 213bf215546Sopenharmony_ci dec->render_pic_list[i] = target; 214bf215546Sopenharmony_ci result.decoded_pic_idx = i; 215bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, &dec->base, (void *)(uintptr_t)i, 216bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 217bf215546Sopenharmony_ci break; 218bf215546Sopenharmony_ci } 219bf215546Sopenharmony_ci } 220bf215546Sopenharmony_ci } 221bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(result.ref_frame_list); i++) { 222bf215546Sopenharmony_ci result.ref_frame_list[i] = pic->ref[i] ? 223bf215546Sopenharmony_ci (uintptr_t)vl_video_buffer_get_associated_data(pic->ref[i], &dec->base) : 0xff; 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_ci if (result.ref_frame_list[i] != 0xff) { 226bf215546Sopenharmony_ci if (pic->top_is_reference[i]) 227bf215546Sopenharmony_ci result.used_for_reference_flags |= (1 << (2 * i)); 228bf215546Sopenharmony_ci if (pic->bottom_is_reference[i]) 229bf215546Sopenharmony_ci result.used_for_reference_flags |= (1 << (2 * i + 1)); 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci if (pic->is_long_term[i]) 232bf215546Sopenharmony_ci result.ref_frame_list[i] |= 0x80; 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci result.curr_pic_ref_frame_num++; 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci for (j = 0; j < ARRAY_SIZE(dec->h264_valid_ref_num); j++) { 237bf215546Sopenharmony_ci if ((dec->h264_valid_ref_num[j] != (unsigned)-1) 238bf215546Sopenharmony_ci && (dec->h264_valid_ref_num[j] == result.frame_num_list[i])) 239bf215546Sopenharmony_ci break; 240bf215546Sopenharmony_ci } 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_ci for (k = 0; k < ARRAY_SIZE(dec->h264_valid_poc_num); k++) { 243bf215546Sopenharmony_ci if ((dec->h264_valid_poc_num[k] != (unsigned)-1) 244bf215546Sopenharmony_ci && ((dec->h264_valid_poc_num[k] == result.field_order_cnt_list[i][0]) 245bf215546Sopenharmony_ci || dec->h264_valid_poc_num[k] == result.field_order_cnt_list[i][1])) 246bf215546Sopenharmony_ci break; 247bf215546Sopenharmony_ci } 248bf215546Sopenharmony_ci } 249bf215546Sopenharmony_ci if (result.ref_frame_list[i] != 0xff && (j == ARRAY_SIZE(dec->h264_valid_ref_num)) 250bf215546Sopenharmony_ci && (k == ARRAY_SIZE(dec->h264_valid_poc_num))) { 251bf215546Sopenharmony_ci result.non_existing_frame_flags |= 1 << i; 252bf215546Sopenharmony_ci result.curr_pic_ref_frame_num--; 253bf215546Sopenharmony_ci result.ref_frame_list[i] = 0xff; 254bf215546Sopenharmony_ci } 255bf215546Sopenharmony_ci } 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(result.ref_frame_list); i++) { 258bf215546Sopenharmony_ci if (result.ref_frame_list[i] != 0xff) { 259bf215546Sopenharmony_ci dec->h264_valid_ref_num[i] = result.frame_num_list[i]; 260bf215546Sopenharmony_ci dec->h264_valid_poc_num[2 * i] = pic->top_is_reference[i] ? 261bf215546Sopenharmony_ci result.field_order_cnt_list[i][0] : (unsigned) -1; 262bf215546Sopenharmony_ci dec->h264_valid_poc_num[2 * i + 1] = pic->bottom_is_reference[i] ? 263bf215546Sopenharmony_ci result.field_order_cnt_list[i][1] : (unsigned) -1; 264bf215546Sopenharmony_ci } else { 265bf215546Sopenharmony_ci dec->h264_valid_ref_num[i] = 266bf215546Sopenharmony_ci dec->h264_valid_poc_num[2 * i] = 267bf215546Sopenharmony_ci dec->h264_valid_poc_num[2 * i + 1] = (unsigned) -1; 268bf215546Sopenharmony_ci } 269bf215546Sopenharmony_ci } 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_ci dec->h264_valid_ref_num[ARRAY_SIZE(dec->h264_valid_ref_num) - 1] = result.frame_num; 272bf215546Sopenharmony_ci dec->h264_valid_poc_num[ARRAY_SIZE(dec->h264_valid_poc_num) - 2] = 273bf215546Sopenharmony_ci pic->field_pic_flag && pic->bottom_field_flag ? 274bf215546Sopenharmony_ci (unsigned) -1 : result.curr_field_order_cnt_list[0]; 275bf215546Sopenharmony_ci dec->h264_valid_poc_num[ARRAY_SIZE(dec->h264_valid_poc_num) - 1] = 276bf215546Sopenharmony_ci pic->field_pic_flag && !pic->bottom_field_flag ? 277bf215546Sopenharmony_ci (unsigned) -1 : result.curr_field_order_cnt_list[1]; 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_2) { 280bf215546Sopenharmony_ci dec->ref_codec.bts = CODEC_8_BITS; 281bf215546Sopenharmony_ci dec->ref_codec.index = result.decoded_pic_idx; 282bf215546Sopenharmony_ci dec->ref_codec.ref_size = 16; 283bf215546Sopenharmony_ci memset(dec->ref_codec.ref_list, 0xff, sizeof(dec->ref_codec.ref_list)); 284bf215546Sopenharmony_ci memcpy(dec->ref_codec.ref_list, result.ref_frame_list, sizeof(result.ref_frame_list)); 285bf215546Sopenharmony_ci } 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ciend: 288bf215546Sopenharmony_ci return result; 289bf215546Sopenharmony_ci} 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_cistatic rvcn_dec_message_hevc_t get_h265_msg(struct radeon_decoder *dec, 292bf215546Sopenharmony_ci struct pipe_video_buffer *target, 293bf215546Sopenharmony_ci struct pipe_h265_picture_desc *pic) 294bf215546Sopenharmony_ci{ 295bf215546Sopenharmony_ci rvcn_dec_message_hevc_t result; 296bf215546Sopenharmony_ci unsigned i, j; 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 299bf215546Sopenharmony_ci result.sps_info_flags = 0; 300bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->scaling_list_enabled_flag << 0; 301bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->amp_enabled_flag << 1; 302bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->sample_adaptive_offset_enabled_flag << 2; 303bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->pcm_enabled_flag << 3; 304bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->pcm_loop_filter_disabled_flag << 4; 305bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->long_term_ref_pics_present_flag << 5; 306bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->sps_temporal_mvp_enabled_flag << 6; 307bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->strong_intra_smoothing_enabled_flag << 7; 308bf215546Sopenharmony_ci result.sps_info_flags |= pic->pps->sps->separate_colour_plane_flag << 8; 309bf215546Sopenharmony_ci if (((struct si_screen *)dec->screen)->info.family == CHIP_CARRIZO) 310bf215546Sopenharmony_ci result.sps_info_flags |= 1 << 9; 311bf215546Sopenharmony_ci if (pic->UseRefPicList == true) 312bf215546Sopenharmony_ci result.sps_info_flags |= 1 << 10; 313bf215546Sopenharmony_ci if (pic->UseStRpsBits == true && pic->pps->st_rps_bits != 0) { 314bf215546Sopenharmony_ci result.sps_info_flags |= 1 << 11; 315bf215546Sopenharmony_ci result.st_rps_bits = pic->pps->st_rps_bits; 316bf215546Sopenharmony_ci } 317bf215546Sopenharmony_ci 318bf215546Sopenharmony_ci result.chroma_format = pic->pps->sps->chroma_format_idc; 319bf215546Sopenharmony_ci result.bit_depth_luma_minus8 = pic->pps->sps->bit_depth_luma_minus8; 320bf215546Sopenharmony_ci result.bit_depth_chroma_minus8 = pic->pps->sps->bit_depth_chroma_minus8; 321bf215546Sopenharmony_ci result.log2_max_pic_order_cnt_lsb_minus4 = pic->pps->sps->log2_max_pic_order_cnt_lsb_minus4; 322bf215546Sopenharmony_ci result.sps_max_dec_pic_buffering_minus1 = pic->pps->sps->sps_max_dec_pic_buffering_minus1; 323bf215546Sopenharmony_ci result.log2_min_luma_coding_block_size_minus3 = 324bf215546Sopenharmony_ci pic->pps->sps->log2_min_luma_coding_block_size_minus3; 325bf215546Sopenharmony_ci result.log2_diff_max_min_luma_coding_block_size = 326bf215546Sopenharmony_ci pic->pps->sps->log2_diff_max_min_luma_coding_block_size; 327bf215546Sopenharmony_ci result.log2_min_transform_block_size_minus2 = 328bf215546Sopenharmony_ci pic->pps->sps->log2_min_transform_block_size_minus2; 329bf215546Sopenharmony_ci result.log2_diff_max_min_transform_block_size = 330bf215546Sopenharmony_ci pic->pps->sps->log2_diff_max_min_transform_block_size; 331bf215546Sopenharmony_ci result.max_transform_hierarchy_depth_inter = pic->pps->sps->max_transform_hierarchy_depth_inter; 332bf215546Sopenharmony_ci result.max_transform_hierarchy_depth_intra = pic->pps->sps->max_transform_hierarchy_depth_intra; 333bf215546Sopenharmony_ci result.pcm_sample_bit_depth_luma_minus1 = pic->pps->sps->pcm_sample_bit_depth_luma_minus1; 334bf215546Sopenharmony_ci result.pcm_sample_bit_depth_chroma_minus1 = pic->pps->sps->pcm_sample_bit_depth_chroma_minus1; 335bf215546Sopenharmony_ci result.log2_min_pcm_luma_coding_block_size_minus3 = 336bf215546Sopenharmony_ci pic->pps->sps->log2_min_pcm_luma_coding_block_size_minus3; 337bf215546Sopenharmony_ci result.log2_diff_max_min_pcm_luma_coding_block_size = 338bf215546Sopenharmony_ci pic->pps->sps->log2_diff_max_min_pcm_luma_coding_block_size; 339bf215546Sopenharmony_ci result.num_short_term_ref_pic_sets = pic->pps->sps->num_short_term_ref_pic_sets; 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ci result.pps_info_flags = 0; 342bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->dependent_slice_segments_enabled_flag << 0; 343bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->output_flag_present_flag << 1; 344bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->sign_data_hiding_enabled_flag << 2; 345bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->cabac_init_present_flag << 3; 346bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->constrained_intra_pred_flag << 4; 347bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->transform_skip_enabled_flag << 5; 348bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->cu_qp_delta_enabled_flag << 6; 349bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->pps_slice_chroma_qp_offsets_present_flag << 7; 350bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->weighted_pred_flag << 8; 351bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->weighted_bipred_flag << 9; 352bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->transquant_bypass_enabled_flag << 10; 353bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->tiles_enabled_flag << 11; 354bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->entropy_coding_sync_enabled_flag << 12; 355bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->uniform_spacing_flag << 13; 356bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->loop_filter_across_tiles_enabled_flag << 14; 357bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->pps_loop_filter_across_slices_enabled_flag << 15; 358bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->deblocking_filter_override_enabled_flag << 16; 359bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->pps_deblocking_filter_disabled_flag << 17; 360bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->lists_modification_present_flag << 18; 361bf215546Sopenharmony_ci result.pps_info_flags |= pic->pps->slice_segment_header_extension_present_flag << 19; 362bf215546Sopenharmony_ci 363bf215546Sopenharmony_ci result.num_extra_slice_header_bits = pic->pps->num_extra_slice_header_bits; 364bf215546Sopenharmony_ci result.num_long_term_ref_pic_sps = pic->pps->sps->num_long_term_ref_pics_sps; 365bf215546Sopenharmony_ci result.num_ref_idx_l0_default_active_minus1 = pic->pps->num_ref_idx_l0_default_active_minus1; 366bf215546Sopenharmony_ci result.num_ref_idx_l1_default_active_minus1 = pic->pps->num_ref_idx_l1_default_active_minus1; 367bf215546Sopenharmony_ci result.pps_cb_qp_offset = pic->pps->pps_cb_qp_offset; 368bf215546Sopenharmony_ci result.pps_cr_qp_offset = pic->pps->pps_cr_qp_offset; 369bf215546Sopenharmony_ci result.pps_beta_offset_div2 = pic->pps->pps_beta_offset_div2; 370bf215546Sopenharmony_ci result.pps_tc_offset_div2 = pic->pps->pps_tc_offset_div2; 371bf215546Sopenharmony_ci result.diff_cu_qp_delta_depth = pic->pps->diff_cu_qp_delta_depth; 372bf215546Sopenharmony_ci result.num_tile_columns_minus1 = pic->pps->num_tile_columns_minus1; 373bf215546Sopenharmony_ci result.num_tile_rows_minus1 = pic->pps->num_tile_rows_minus1; 374bf215546Sopenharmony_ci result.log2_parallel_merge_level_minus2 = pic->pps->log2_parallel_merge_level_minus2; 375bf215546Sopenharmony_ci result.init_qp_minus26 = pic->pps->init_qp_minus26; 376bf215546Sopenharmony_ci 377bf215546Sopenharmony_ci for (i = 0; i < 19; ++i) 378bf215546Sopenharmony_ci result.column_width_minus1[i] = pic->pps->column_width_minus1[i]; 379bf215546Sopenharmony_ci 380bf215546Sopenharmony_ci for (i = 0; i < 21; ++i) 381bf215546Sopenharmony_ci result.row_height_minus1[i] = pic->pps->row_height_minus1[i]; 382bf215546Sopenharmony_ci 383bf215546Sopenharmony_ci result.num_delta_pocs_ref_rps_idx = pic->NumDeltaPocsOfRefRpsIdx; 384bf215546Sopenharmony_ci result.curr_poc = pic->CurrPicOrderCntVal; 385bf215546Sopenharmony_ci 386bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); i++) { 387bf215546Sopenharmony_ci for (j = 0; 388bf215546Sopenharmony_ci (pic->ref[j] != NULL) && (j < ARRAY_SIZE(dec->render_pic_list)); 389bf215546Sopenharmony_ci j++) { 390bf215546Sopenharmony_ci if (dec->render_pic_list[i] == pic->ref[j]) 391bf215546Sopenharmony_ci break; 392bf215546Sopenharmony_ci if (j == ARRAY_SIZE(dec->render_pic_list) - 1) 393bf215546Sopenharmony_ci dec->render_pic_list[i] = NULL; 394bf215546Sopenharmony_ci else if (pic->ref[j + 1] == NULL) 395bf215546Sopenharmony_ci dec->render_pic_list[i] = NULL; 396bf215546Sopenharmony_ci } 397bf215546Sopenharmony_ci } 398bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); i++) { 399bf215546Sopenharmony_ci if (dec->render_pic_list[i] == NULL) { 400bf215546Sopenharmony_ci dec->render_pic_list[i] = target; 401bf215546Sopenharmony_ci result.curr_idx = i; 402bf215546Sopenharmony_ci break; 403bf215546Sopenharmony_ci } 404bf215546Sopenharmony_ci } 405bf215546Sopenharmony_ci 406bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, &dec->base, (void *)(uintptr_t)result.curr_idx, 407bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 408bf215546Sopenharmony_ci 409bf215546Sopenharmony_ci for (i = 0; i < 16; ++i) { 410bf215546Sopenharmony_ci struct pipe_video_buffer *ref = pic->ref[i]; 411bf215546Sopenharmony_ci uintptr_t ref_pic = 0; 412bf215546Sopenharmony_ci 413bf215546Sopenharmony_ci result.poc_list[i] = pic->PicOrderCntVal[i]; 414bf215546Sopenharmony_ci 415bf215546Sopenharmony_ci if (ref) 416bf215546Sopenharmony_ci ref_pic = (uintptr_t)vl_video_buffer_get_associated_data(ref, &dec->base); 417bf215546Sopenharmony_ci else 418bf215546Sopenharmony_ci ref_pic = 0x7F; 419bf215546Sopenharmony_ci result.ref_pic_list[i] = ref_pic; 420bf215546Sopenharmony_ci } 421bf215546Sopenharmony_ci 422bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) { 423bf215546Sopenharmony_ci result.ref_pic_set_st_curr_before[i] = 0xFF; 424bf215546Sopenharmony_ci result.ref_pic_set_st_curr_after[i] = 0xFF; 425bf215546Sopenharmony_ci result.ref_pic_set_lt_curr[i] = 0xFF; 426bf215546Sopenharmony_ci } 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_ci for (i = 0; i < pic->NumPocStCurrBefore; ++i) 429bf215546Sopenharmony_ci result.ref_pic_set_st_curr_before[i] = pic->RefPicSetStCurrBefore[i]; 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_ci for (i = 0; i < pic->NumPocStCurrAfter; ++i) 432bf215546Sopenharmony_ci result.ref_pic_set_st_curr_after[i] = pic->RefPicSetStCurrAfter[i]; 433bf215546Sopenharmony_ci 434bf215546Sopenharmony_ci for (i = 0; i < pic->NumPocLtCurr; ++i) 435bf215546Sopenharmony_ci result.ref_pic_set_lt_curr[i] = pic->RefPicSetLtCurr[i]; 436bf215546Sopenharmony_ci 437bf215546Sopenharmony_ci for (i = 0; i < 6; ++i) 438bf215546Sopenharmony_ci result.ucScalingListDCCoefSizeID2[i] = pic->pps->sps->ScalingListDCCoeff16x16[i]; 439bf215546Sopenharmony_ci 440bf215546Sopenharmony_ci for (i = 0; i < 2; ++i) 441bf215546Sopenharmony_ci result.ucScalingListDCCoefSizeID3[i] = pic->pps->sps->ScalingListDCCoeff32x32[i]; 442bf215546Sopenharmony_ci 443bf215546Sopenharmony_ci memcpy(dec->it, pic->pps->sps->ScalingList4x4, 6 * 16); 444bf215546Sopenharmony_ci memcpy(dec->it + 96, pic->pps->sps->ScalingList8x8, 6 * 64); 445bf215546Sopenharmony_ci memcpy(dec->it + 480, pic->pps->sps->ScalingList16x16, 6 * 64); 446bf215546Sopenharmony_ci memcpy(dec->it + 864, pic->pps->sps->ScalingList32x32, 2 * 64); 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci for (i = 0; i < 2; i++) { 449bf215546Sopenharmony_ci for (j = 0; j < 15; j++) 450bf215546Sopenharmony_ci result.direct_reflist[i][j] = pic->RefPicList[i][j]; 451bf215546Sopenharmony_ci } 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_ci if (pic->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) { 454bf215546Sopenharmony_ci if (target->buffer_format == PIPE_FORMAT_P010 || target->buffer_format == PIPE_FORMAT_P016) { 455bf215546Sopenharmony_ci result.p010_mode = 1; 456bf215546Sopenharmony_ci result.msb_mode = 1; 457bf215546Sopenharmony_ci } else { 458bf215546Sopenharmony_ci result.p010_mode = 0; 459bf215546Sopenharmony_ci result.luma_10to8 = 5; 460bf215546Sopenharmony_ci result.chroma_10to8 = 5; 461bf215546Sopenharmony_ci result.hevc_reserved[0] = 4; /* sclr_luma10to8 */ 462bf215546Sopenharmony_ci result.hevc_reserved[1] = 4; /* sclr_chroma10to8 */ 463bf215546Sopenharmony_ci } 464bf215546Sopenharmony_ci } 465bf215546Sopenharmony_ci 466bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_2) { 467bf215546Sopenharmony_ci dec->ref_codec.bts = (pic->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) ? 468bf215546Sopenharmony_ci CODEC_10_BITS : CODEC_8_BITS; 469bf215546Sopenharmony_ci dec->ref_codec.index = result.curr_idx; 470bf215546Sopenharmony_ci dec->ref_codec.ref_size = 15; 471bf215546Sopenharmony_ci memset(dec->ref_codec.ref_list, 0x7f, sizeof(dec->ref_codec.ref_list)); 472bf215546Sopenharmony_ci memcpy(dec->ref_codec.ref_list, result.ref_pic_list, sizeof(result.ref_pic_list)); 473bf215546Sopenharmony_ci } 474bf215546Sopenharmony_ci return result; 475bf215546Sopenharmony_ci} 476bf215546Sopenharmony_ci 477bf215546Sopenharmony_cistatic void fill_probs_table(void *ptr) 478bf215546Sopenharmony_ci{ 479bf215546Sopenharmony_ci rvcn_dec_vp9_probs_t *probs = (rvcn_dec_vp9_probs_t *)ptr; 480bf215546Sopenharmony_ci 481bf215546Sopenharmony_ci memcpy(&probs->coef_probs[0], default_coef_probs_4x4, sizeof(default_coef_probs_4x4)); 482bf215546Sopenharmony_ci memcpy(&probs->coef_probs[1], default_coef_probs_8x8, sizeof(default_coef_probs_8x8)); 483bf215546Sopenharmony_ci memcpy(&probs->coef_probs[2], default_coef_probs_16x16, sizeof(default_coef_probs_16x16)); 484bf215546Sopenharmony_ci memcpy(&probs->coef_probs[3], default_coef_probs_32x32, sizeof(default_coef_probs_32x32)); 485bf215546Sopenharmony_ci memcpy(probs->y_mode_prob, default_if_y_probs, sizeof(default_if_y_probs)); 486bf215546Sopenharmony_ci memcpy(probs->uv_mode_prob, default_if_uv_probs, sizeof(default_if_uv_probs)); 487bf215546Sopenharmony_ci memcpy(probs->single_ref_prob, default_single_ref_p, sizeof(default_single_ref_p)); 488bf215546Sopenharmony_ci memcpy(probs->switchable_interp_prob, default_switchable_interp_prob, 489bf215546Sopenharmony_ci sizeof(default_switchable_interp_prob)); 490bf215546Sopenharmony_ci memcpy(probs->partition_prob, default_partition_probs, sizeof(default_partition_probs)); 491bf215546Sopenharmony_ci memcpy(probs->inter_mode_probs, default_inter_mode_probs, sizeof(default_inter_mode_probs)); 492bf215546Sopenharmony_ci memcpy(probs->mbskip_probs, default_skip_probs, sizeof(default_skip_probs)); 493bf215546Sopenharmony_ci memcpy(probs->intra_inter_prob, default_intra_inter_p, sizeof(default_intra_inter_p)); 494bf215546Sopenharmony_ci memcpy(probs->comp_inter_prob, default_comp_inter_p, sizeof(default_comp_inter_p)); 495bf215546Sopenharmony_ci memcpy(probs->comp_ref_prob, default_comp_ref_p, sizeof(default_comp_ref_p)); 496bf215546Sopenharmony_ci memcpy(probs->tx_probs_32x32, default_tx_probs_32x32, sizeof(default_tx_probs_32x32)); 497bf215546Sopenharmony_ci memcpy(probs->tx_probs_16x16, default_tx_probs_16x16, sizeof(default_tx_probs_16x16)); 498bf215546Sopenharmony_ci memcpy(probs->tx_probs_8x8, default_tx_probs_8x8, sizeof(default_tx_probs_8x8)); 499bf215546Sopenharmony_ci memcpy(probs->mv_joints, default_nmv_joints, sizeof(default_nmv_joints)); 500bf215546Sopenharmony_ci memcpy(&probs->mv_comps[0], default_nmv_components, sizeof(default_nmv_components)); 501bf215546Sopenharmony_ci memset(&probs->nmvc_mask, 0, sizeof(rvcn_dec_vp9_nmv_ctx_mask_t)); 502bf215546Sopenharmony_ci} 503bf215546Sopenharmony_ci 504bf215546Sopenharmony_cistatic rvcn_dec_message_vp9_t get_vp9_msg(struct radeon_decoder *dec, 505bf215546Sopenharmony_ci struct pipe_video_buffer *target, 506bf215546Sopenharmony_ci struct pipe_vp9_picture_desc *pic) 507bf215546Sopenharmony_ci{ 508bf215546Sopenharmony_ci rvcn_dec_message_vp9_t result; 509bf215546Sopenharmony_ci unsigned i ,j; 510bf215546Sopenharmony_ci 511bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 512bf215546Sopenharmony_ci 513bf215546Sopenharmony_ci /* segment table */ 514bf215546Sopenharmony_ci rvcn_dec_vp9_probs_segment_t *prbs = (rvcn_dec_vp9_probs_segment_t *)(dec->probs); 515bf215546Sopenharmony_ci 516bf215546Sopenharmony_ci if (pic->picture_parameter.pic_fields.segmentation_enabled) { 517bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) { 518bf215546Sopenharmony_ci prbs->seg.feature_data[i] = 519bf215546Sopenharmony_ci (pic->slice_parameter.seg_param[i].alt_quant & 0xffff) | 520bf215546Sopenharmony_ci ((pic->slice_parameter.seg_param[i].alt_lf & 0xff) << 16) | 521bf215546Sopenharmony_ci ((pic->slice_parameter.seg_param[i].segment_flags.segment_reference & 0xf) << 24); 522bf215546Sopenharmony_ci prbs->seg.feature_mask[i] = 523bf215546Sopenharmony_ci (pic->slice_parameter.seg_param[i].alt_quant_enabled << 0) | 524bf215546Sopenharmony_ci (pic->slice_parameter.seg_param[i].alt_lf_enabled << 1) | 525bf215546Sopenharmony_ci (pic->slice_parameter.seg_param[i].segment_flags.segment_reference_enabled << 2) | 526bf215546Sopenharmony_ci (pic->slice_parameter.seg_param[i].segment_flags.segment_reference_skipped << 3); 527bf215546Sopenharmony_ci } 528bf215546Sopenharmony_ci 529bf215546Sopenharmony_ci for (i = 0; i < 7; ++i) 530bf215546Sopenharmony_ci prbs->seg.tree_probs[i] = pic->picture_parameter.mb_segment_tree_probs[i]; 531bf215546Sopenharmony_ci 532bf215546Sopenharmony_ci for (i = 0; i < 3; ++i) 533bf215546Sopenharmony_ci prbs->seg.pred_probs[i] = pic->picture_parameter.segment_pred_probs[i]; 534bf215546Sopenharmony_ci 535bf215546Sopenharmony_ci prbs->seg.abs_delta = pic->picture_parameter.abs_delta; 536bf215546Sopenharmony_ci } else 537bf215546Sopenharmony_ci memset(&prbs->seg, 0, 256); 538bf215546Sopenharmony_ci 539bf215546Sopenharmony_ci result.frame_header_flags = (pic->picture_parameter.pic_fields.frame_type 540bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_FRAME_TYPE_SHIFT) & 541bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_FRAME_TYPE_MASK; 542bf215546Sopenharmony_ci 543bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.error_resilient_mode 544bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_ERROR_RESILIENT_MODE_SHIFT) & 545bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_ERROR_RESILIENT_MODE_MASK; 546bf215546Sopenharmony_ci 547bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.intra_only 548bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_INTRA_ONLY_SHIFT) & 549bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_INTRA_ONLY_MASK; 550bf215546Sopenharmony_ci 551bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.allow_high_precision_mv 552bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_ALLOW_HIGH_PRECISION_MV_SHIFT) & 553bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_ALLOW_HIGH_PRECISION_MV_MASK; 554bf215546Sopenharmony_ci 555bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.frame_parallel_decoding_mode 556bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_FRAME_PARALLEL_DECODING_MODE_SHIFT) & 557bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_FRAME_PARALLEL_DECODING_MODE_MASK; 558bf215546Sopenharmony_ci 559bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.refresh_frame_context 560bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_REFRESH_FRAME_CONTEXT_SHIFT) & 561bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_REFRESH_FRAME_CONTEXT_MASK; 562bf215546Sopenharmony_ci 563bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.segmentation_enabled 564bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_ENABLED_SHIFT) & 565bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_ENABLED_MASK; 566bf215546Sopenharmony_ci 567bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.segmentation_update_map 568bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_UPDATE_MAP_SHIFT) & 569bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_UPDATE_MAP_MASK; 570bf215546Sopenharmony_ci 571bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_fields.segmentation_temporal_update 572bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_TEMPORAL_UPDATE_SHIFT) & 573bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_TEMPORAL_UPDATE_MASK; 574bf215546Sopenharmony_ci 575bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_ref_delta_enabled 576bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_ENABLED_SHIFT) & 577bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_ENABLED_MASK; 578bf215546Sopenharmony_ci 579bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_ref_delta_update 580bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_UPDATE_SHIFT) & 581bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_UPDATE_MASK; 582bf215546Sopenharmony_ci 583bf215546Sopenharmony_ci result.frame_header_flags |= 584bf215546Sopenharmony_ci ((dec->show_frame && !pic->picture_parameter.pic_fields.error_resilient_mode && 585bf215546Sopenharmony_ci dec->last_width == dec->base.width && dec->last_height == dec->base.height) 586bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_VP9_USE_PREV_IN_FIND_MV_REFS_SHIFT) & 587bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_USE_PREV_IN_FIND_MV_REFS_MASK; 588bf215546Sopenharmony_ci dec->show_frame = pic->picture_parameter.pic_fields.show_frame; 589bf215546Sopenharmony_ci 590bf215546Sopenharmony_ci result.frame_header_flags |= (1 << RDECODE_FRAME_HDR_INFO_VP9_USE_UNCOMPRESSED_HEADER_SHIFT) & 591bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_VP9_USE_UNCOMPRESSED_HEADER_MASK; 592bf215546Sopenharmony_ci 593bf215546Sopenharmony_ci result.interp_filter = pic->picture_parameter.pic_fields.mcomp_filter_type; 594bf215546Sopenharmony_ci 595bf215546Sopenharmony_ci result.frame_context_idx = pic->picture_parameter.pic_fields.frame_context_idx; 596bf215546Sopenharmony_ci result.reset_frame_context = pic->picture_parameter.pic_fields.reset_frame_context; 597bf215546Sopenharmony_ci 598bf215546Sopenharmony_ci result.filter_level = pic->picture_parameter.filter_level; 599bf215546Sopenharmony_ci result.sharpness_level = pic->picture_parameter.sharpness_level; 600bf215546Sopenharmony_ci 601bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) 602bf215546Sopenharmony_ci memcpy(result.lf_adj_level[i], pic->slice_parameter.seg_param[i].filter_level, 4 * 2); 603bf215546Sopenharmony_ci 604bf215546Sopenharmony_ci if (pic->picture_parameter.pic_fields.lossless_flag) { 605bf215546Sopenharmony_ci result.base_qindex = 0; 606bf215546Sopenharmony_ci result.y_dc_delta_q = 0; 607bf215546Sopenharmony_ci result.uv_ac_delta_q = 0; 608bf215546Sopenharmony_ci result.uv_dc_delta_q = 0; 609bf215546Sopenharmony_ci } else { 610bf215546Sopenharmony_ci result.base_qindex = pic->picture_parameter.base_qindex; 611bf215546Sopenharmony_ci result.y_dc_delta_q = pic->picture_parameter.y_dc_delta_q; 612bf215546Sopenharmony_ci result.uv_ac_delta_q = pic->picture_parameter.uv_ac_delta_q; 613bf215546Sopenharmony_ci result.uv_dc_delta_q = pic->picture_parameter.uv_dc_delta_q; 614bf215546Sopenharmony_ci } 615bf215546Sopenharmony_ci 616bf215546Sopenharmony_ci result.log2_tile_cols = pic->picture_parameter.log2_tile_columns; 617bf215546Sopenharmony_ci result.log2_tile_rows = pic->picture_parameter.log2_tile_rows; 618bf215546Sopenharmony_ci result.chroma_format = 1; 619bf215546Sopenharmony_ci result.bit_depth_luma_minus8 = result.bit_depth_chroma_minus8 = 620bf215546Sopenharmony_ci (pic->picture_parameter.bit_depth - 8); 621bf215546Sopenharmony_ci 622bf215546Sopenharmony_ci result.vp9_frame_size = align(dec->bs_size, 128); 623bf215546Sopenharmony_ci result.uncompressed_header_size = pic->picture_parameter.frame_header_length_in_bytes; 624bf215546Sopenharmony_ci result.compressed_header_size = pic->picture_parameter.first_partition_size; 625bf215546Sopenharmony_ci 626bf215546Sopenharmony_ci assert(dec->base.max_references + 1 <= ARRAY_SIZE(dec->render_pic_list)); 627bf215546Sopenharmony_ci 628bf215546Sopenharmony_ci //clear the dec->render list if it is not used as a reference 629bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); i++) { 630bf215546Sopenharmony_ci if (dec->render_pic_list[i]) { 631bf215546Sopenharmony_ci for (j=0;j<8;j++) { 632bf215546Sopenharmony_ci if (dec->render_pic_list[i] == pic->ref[j]) 633bf215546Sopenharmony_ci break; 634bf215546Sopenharmony_ci } 635bf215546Sopenharmony_ci if (j == 8) 636bf215546Sopenharmony_ci dec->render_pic_list[i] = NULL; 637bf215546Sopenharmony_ci } 638bf215546Sopenharmony_ci } 639bf215546Sopenharmony_ci 640bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); ++i) { 641bf215546Sopenharmony_ci if (dec->render_pic_list[i] && dec->render_pic_list[i] == target) { 642bf215546Sopenharmony_ci if (target->codec != NULL) { 643bf215546Sopenharmony_ci result.curr_pic_idx =(uintptr_t)vl_video_buffer_get_associated_data(target, &dec->base); 644bf215546Sopenharmony_ci } else { 645bf215546Sopenharmony_ci result.curr_pic_idx = i; 646bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, &dec->base, (void *)(uintptr_t)i, 647bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 648bf215546Sopenharmony_ci } 649bf215546Sopenharmony_ci break; 650bf215546Sopenharmony_ci } else if (!dec->render_pic_list[i]) { 651bf215546Sopenharmony_ci dec->render_pic_list[i] = target; 652bf215546Sopenharmony_ci result.curr_pic_idx = i; 653bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, &dec->base, (void *)(uintptr_t)i, 654bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 655bf215546Sopenharmony_ci break; 656bf215546Sopenharmony_ci } 657bf215546Sopenharmony_ci } 658bf215546Sopenharmony_ci 659bf215546Sopenharmony_ci for (i = 0; i < 8; i++) { 660bf215546Sopenharmony_ci result.ref_frame_map[i] = 661bf215546Sopenharmony_ci (pic->ref[i]) ? (uintptr_t)vl_video_buffer_get_associated_data(pic->ref[i], &dec->base) 662bf215546Sopenharmony_ci : 0x7f; 663bf215546Sopenharmony_ci } 664bf215546Sopenharmony_ci 665bf215546Sopenharmony_ci result.frame_refs[0] = result.ref_frame_map[pic->picture_parameter.pic_fields.last_ref_frame]; 666bf215546Sopenharmony_ci result.ref_frame_sign_bias[0] = pic->picture_parameter.pic_fields.last_ref_frame_sign_bias; 667bf215546Sopenharmony_ci result.frame_refs[1] = result.ref_frame_map[pic->picture_parameter.pic_fields.golden_ref_frame]; 668bf215546Sopenharmony_ci result.ref_frame_sign_bias[1] = pic->picture_parameter.pic_fields.golden_ref_frame_sign_bias; 669bf215546Sopenharmony_ci result.frame_refs[2] = result.ref_frame_map[pic->picture_parameter.pic_fields.alt_ref_frame]; 670bf215546Sopenharmony_ci result.ref_frame_sign_bias[2] = pic->picture_parameter.pic_fields.alt_ref_frame_sign_bias; 671bf215546Sopenharmony_ci 672bf215546Sopenharmony_ci if (pic->base.profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2) { 673bf215546Sopenharmony_ci if (target->buffer_format == PIPE_FORMAT_P010 || target->buffer_format == PIPE_FORMAT_P016) { 674bf215546Sopenharmony_ci result.p010_mode = 1; 675bf215546Sopenharmony_ci result.msb_mode = 1; 676bf215546Sopenharmony_ci } else { 677bf215546Sopenharmony_ci result.p010_mode = 0; 678bf215546Sopenharmony_ci result.luma_10to8 = 1; 679bf215546Sopenharmony_ci result.chroma_10to8 = 1; 680bf215546Sopenharmony_ci } 681bf215546Sopenharmony_ci } 682bf215546Sopenharmony_ci 683bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_2) { 684bf215546Sopenharmony_ci dec->ref_codec.bts = (pic->base.profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2) ? 685bf215546Sopenharmony_ci CODEC_10_BITS : CODEC_8_BITS; 686bf215546Sopenharmony_ci dec->ref_codec.index = result.curr_pic_idx; 687bf215546Sopenharmony_ci dec->ref_codec.ref_size = 8; 688bf215546Sopenharmony_ci memset(dec->ref_codec.ref_list, 0x7f, sizeof(dec->ref_codec.ref_list)); 689bf215546Sopenharmony_ci memcpy(dec->ref_codec.ref_list, result.ref_frame_map, sizeof(result.ref_frame_map)); 690bf215546Sopenharmony_ci } 691bf215546Sopenharmony_ci 692bf215546Sopenharmony_ci dec->last_width = dec->base.width; 693bf215546Sopenharmony_ci dec->last_height = dec->base.height; 694bf215546Sopenharmony_ci 695bf215546Sopenharmony_ci return result; 696bf215546Sopenharmony_ci} 697bf215546Sopenharmony_ci 698bf215546Sopenharmony_cistatic void set_drm_keys(rvcn_dec_message_drm_t *drm, DECRYPT_PARAMETERS *decrypted) 699bf215546Sopenharmony_ci{ 700bf215546Sopenharmony_ci int cbc = decrypted->u.s.cbc; 701bf215546Sopenharmony_ci int ctr = decrypted->u.s.ctr; 702bf215546Sopenharmony_ci int id = decrypted->u.s.drm_id; 703bf215546Sopenharmony_ci int ekc = 1; 704bf215546Sopenharmony_ci int data1 = 1; 705bf215546Sopenharmony_ci int data2 = 1; 706bf215546Sopenharmony_ci 707bf215546Sopenharmony_ci drm->drm_cmd = 0; 708bf215546Sopenharmony_ci drm->drm_cntl = 0; 709bf215546Sopenharmony_ci 710bf215546Sopenharmony_ci drm->drm_cntl = 1 << DRM_CNTL_BYPASS_SHIFT; 711bf215546Sopenharmony_ci 712bf215546Sopenharmony_ci if (cbc || ctr) { 713bf215546Sopenharmony_ci drm->drm_cntl = 0 << DRM_CNTL_BYPASS_SHIFT; 714bf215546Sopenharmony_ci drm->drm_cmd |= 0xff << DRM_CMD_BYTE_MASK_SHIFT; 715bf215546Sopenharmony_ci 716bf215546Sopenharmony_ci if (ctr) 717bf215546Sopenharmony_ci drm->drm_cmd |= 0x00 << DRM_CMD_ALGORITHM_SHIFT; 718bf215546Sopenharmony_ci else if (cbc) 719bf215546Sopenharmony_ci drm->drm_cmd |= 0x02 << DRM_CMD_ALGORITHM_SHIFT; 720bf215546Sopenharmony_ci 721bf215546Sopenharmony_ci drm->drm_cmd |= 1 << DRM_CMD_GEN_MASK_SHIFT; 722bf215546Sopenharmony_ci drm->drm_cmd |= ekc << DRM_CMD_UNWRAP_KEY_SHIFT; 723bf215546Sopenharmony_ci drm->drm_cmd |= 0 << DRM_CMD_OFFSET_SHIFT; 724bf215546Sopenharmony_ci drm->drm_cmd |= data2 << DRM_CMD_CNT_DATA_SHIFT; 725bf215546Sopenharmony_ci drm->drm_cmd |= data1 << DRM_CMD_CNT_KEY_SHIFT; 726bf215546Sopenharmony_ci drm->drm_cmd |= ekc << DRM_CMD_KEY_SHIFT; 727bf215546Sopenharmony_ci drm->drm_cmd |= id << DRM_CMD_SESSION_SEL_SHIFT; 728bf215546Sopenharmony_ci 729bf215546Sopenharmony_ci if (ekc) 730bf215546Sopenharmony_ci memcpy(drm->drm_wrapped_key, decrypted->encrypted_key, 16); 731bf215546Sopenharmony_ci if (data1) 732bf215546Sopenharmony_ci memcpy(drm->drm_key, decrypted->session_iv, 16); 733bf215546Sopenharmony_ci if (data2) 734bf215546Sopenharmony_ci memcpy(drm->drm_counter, decrypted->encrypted_iv, 16); 735bf215546Sopenharmony_ci drm->drm_offset = 0; 736bf215546Sopenharmony_ci } 737bf215546Sopenharmony_ci} 738bf215546Sopenharmony_ci 739bf215546Sopenharmony_cistatic rvcn_dec_message_av1_t get_av1_msg(struct radeon_decoder *dec, 740bf215546Sopenharmony_ci struct pipe_video_buffer *target, 741bf215546Sopenharmony_ci struct pipe_av1_picture_desc *pic) 742bf215546Sopenharmony_ci{ 743bf215546Sopenharmony_ci rvcn_dec_message_av1_t result; 744bf215546Sopenharmony_ci unsigned i, j; 745bf215546Sopenharmony_ci 746bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 747bf215546Sopenharmony_ci 748bf215546Sopenharmony_ci result.frame_header_flags = (pic->picture_parameter.pic_info_fields.show_frame 749bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SHOW_FRAME_SHIFT) & 750bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SHOW_FRAME_MASK; 751bf215546Sopenharmony_ci 752bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.disable_cdf_update 753bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_DISABLE_CDF_UPDATE_SHIFT) & 754bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_DISABLE_CDF_UPDATE_MASK; 755bf215546Sopenharmony_ci 756bf215546Sopenharmony_ci result.frame_header_flags |= ((!pic->picture_parameter.pic_info_fields.disable_frame_end_update_cdf) 757bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_REFRESH_FRAME_CONTEXT_SHIFT) & 758bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_REFRESH_FRAME_CONTEXT_MASK; 759bf215546Sopenharmony_ci 760bf215546Sopenharmony_ci result.frame_header_flags |= ((pic->picture_parameter.pic_info_fields.frame_type == 761bf215546Sopenharmony_ci 2 /* INTRA_ONLY_FRAME */) << RDECODE_FRAME_HDR_INFO_AV1_INTRA_ONLY_SHIFT) & 762bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_INTRA_ONLY_MASK; 763bf215546Sopenharmony_ci 764bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.allow_intrabc 765bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ALLOW_INTRABC_SHIFT) & 766bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ALLOW_INTRABC_MASK; 767bf215546Sopenharmony_ci 768bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.allow_high_precision_mv 769bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ALLOW_HIGH_PRECISION_MV_SHIFT) & 770bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ALLOW_HIGH_PRECISION_MV_MASK; 771bf215546Sopenharmony_ci 772bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.mono_chrome 773bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_MONOCHROME_SHIFT) & 774bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_MONOCHROME_MASK; 775bf215546Sopenharmony_ci 776bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_control_fields.skip_mode_present 777bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SKIP_MODE_FLAG_SHIFT) & 778bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SKIP_MODE_FLAG_MASK; 779bf215546Sopenharmony_ci 780bf215546Sopenharmony_ci result.frame_header_flags |= (((pic->picture_parameter.qmatrix_fields.qm_y == 0xf) ? 0 : 1) 781bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_USING_QMATRIX_SHIFT) & 782bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_USING_QMATRIX_MASK; 783bf215546Sopenharmony_ci 784bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_filter_intra 785bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_FILTER_INTRA_SHIFT) & 786bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_FILTER_INTRA_MASK; 787bf215546Sopenharmony_ci 788bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_intra_edge_filter 789bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_INTRA_EDGE_FILTER_SHIFT) & 790bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_INTRA_EDGE_FILTER_MASK; 791bf215546Sopenharmony_ci 792bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_interintra_compound 793bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_INTERINTRA_COMPOUND_SHIFT) & 794bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_INTERINTRA_COMPOUND_MASK; 795bf215546Sopenharmony_ci 796bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_masked_compound 797bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_MASKED_COMPOUND_SHIFT) & 798bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_MASKED_COMPOUND_MASK; 799bf215546Sopenharmony_ci 800bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.allow_warped_motion 801bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ALLOW_WARPED_MOTION_SHIFT) & 802bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ALLOW_WARPED_MOTION_MASK; 803bf215546Sopenharmony_ci 804bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_dual_filter 805bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_DUAL_FILTER_SHIFT) & 806bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_DUAL_FILTER_MASK; 807bf215546Sopenharmony_ci 808bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_order_hint 809bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_ORDER_HINT_SHIFT) & 810bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_ORDER_HINT_MASK; 811bf215546Sopenharmony_ci 812bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seq_info_fields.enable_jnt_comp 813bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ENABLE_JNT_COMP_SHIFT) & 814bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ENABLE_JNT_COMP_MASK; 815bf215546Sopenharmony_ci 816bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.use_ref_frame_mvs 817bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ALLOW_REF_FRAME_MVS_SHIFT) & 818bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ALLOW_REF_FRAME_MVS_MASK; 819bf215546Sopenharmony_ci 820bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.allow_screen_content_tools 821bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_ALLOW_SCREEN_CONTENT_TOOLS_SHIFT) & 822bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_ALLOW_SCREEN_CONTENT_TOOLS_MASK; 823bf215546Sopenharmony_ci 824bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.force_integer_mv 825bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_CUR_FRAME_FORCE_INTEGER_MV_SHIFT) & 826bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_CUR_FRAME_FORCE_INTEGER_MV_MASK; 827bf215546Sopenharmony_ci 828bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.loop_filter_info_fields.mode_ref_delta_enabled 829bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_MODE_REF_DELTA_ENABLED_SHIFT) & 830bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_MODE_REF_DELTA_ENABLED_MASK; 831bf215546Sopenharmony_ci 832bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.loop_filter_info_fields.mode_ref_delta_update 833bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_MODE_REF_DELTA_UPDATE_SHIFT) & 834bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_MODE_REF_DELTA_UPDATE_MASK; 835bf215546Sopenharmony_ci 836bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_control_fields.delta_q_present_flag 837bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_DELTA_Q_PRESENT_FLAG_SHIFT) & 838bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_DELTA_Q_PRESENT_FLAG_MASK; 839bf215546Sopenharmony_ci 840bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_control_fields.delta_lf_present_flag 841bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_DELTA_LF_PRESENT_FLAG_SHIFT) & 842bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_DELTA_LF_PRESENT_FLAG_MASK; 843bf215546Sopenharmony_ci 844bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_control_fields.reduced_tx_set_used 845bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_REDUCED_TX_SET_USED_SHIFT) & 846bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_REDUCED_TX_SET_USED_MASK; 847bf215546Sopenharmony_ci 848bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seg_info.segment_info_fields.enabled 849bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SEGMENTATION_ENABLED_SHIFT) & 850bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SEGMENTATION_ENABLED_MASK; 851bf215546Sopenharmony_ci 852bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seg_info.segment_info_fields.update_map 853bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SEGMENTATION_UPDATE_MAP_SHIFT) & 854bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SEGMENTATION_UPDATE_MAP_MASK; 855bf215546Sopenharmony_ci 856bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.seg_info.segment_info_fields.temporal_update 857bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SEGMENTATION_TEMPORAL_UPDATE_SHIFT) & 858bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SEGMENTATION_TEMPORAL_UPDATE_MASK; 859bf215546Sopenharmony_ci 860bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.mode_control_fields.delta_lf_multi 861bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_DELTA_LF_MULTI_SHIFT) & 862bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_DELTA_LF_MULTI_MASK; 863bf215546Sopenharmony_ci 864bf215546Sopenharmony_ci result.frame_header_flags |= (pic->picture_parameter.pic_info_fields.is_motion_mode_switchable 865bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SWITCHABLE_SKIP_MODE_SHIFT) & 866bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SWITCHABLE_SKIP_MODE_MASK; 867bf215546Sopenharmony_ci 868bf215546Sopenharmony_ci result.frame_header_flags |= ((!pic->picture_parameter.refresh_frame_flags) 869bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_SKIP_REFERENCE_UPDATE_SHIFT) & 870bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_SKIP_REFERENCE_UPDATE_MASK; 871bf215546Sopenharmony_ci 872bf215546Sopenharmony_ci result.frame_header_flags |= ((!pic->picture_parameter.seq_info_fields.ref_frame_mvs) 873bf215546Sopenharmony_ci << RDECODE_FRAME_HDR_INFO_AV1_DISABLE_REF_FRAME_MVS_SHIFT) & 874bf215546Sopenharmony_ci RDECODE_FRAME_HDR_INFO_AV1_DISABLE_REF_FRAME_MVS_MASK; 875bf215546Sopenharmony_ci 876bf215546Sopenharmony_ci result.current_frame_id = pic->picture_parameter.current_frame_id; 877bf215546Sopenharmony_ci result.frame_offset = pic->picture_parameter.order_hint; 878bf215546Sopenharmony_ci 879bf215546Sopenharmony_ci result.profile = pic->picture_parameter.profile; 880bf215546Sopenharmony_ci result.is_annexb = 0; 881bf215546Sopenharmony_ci result.frame_type = pic->picture_parameter.pic_info_fields.frame_type; 882bf215546Sopenharmony_ci result.primary_ref_frame = pic->picture_parameter.primary_ref_frame; 883bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); ++i) { 884bf215546Sopenharmony_ci if (dec->render_pic_list[i] && dec->render_pic_list[i] == target) { 885bf215546Sopenharmony_ci result.curr_pic_idx = (uintptr_t)vl_video_buffer_get_associated_data(target, &dec->base); 886bf215546Sopenharmony_ci break; 887bf215546Sopenharmony_ci } else if (!dec->render_pic_list[i]) { 888bf215546Sopenharmony_ci dec->render_pic_list[i] = target; 889bf215546Sopenharmony_ci result.curr_pic_idx = dec->ref_idx; 890bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, &dec->base, (void *)(uintptr_t)dec->ref_idx++, 891bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 892bf215546Sopenharmony_ci break; 893bf215546Sopenharmony_ci } 894bf215546Sopenharmony_ci } 895bf215546Sopenharmony_ci 896bf215546Sopenharmony_ci result.sb_size = pic->picture_parameter.seq_info_fields.use_128x128_superblock; 897bf215546Sopenharmony_ci result.interp_filter = pic->picture_parameter.interp_filter; 898bf215546Sopenharmony_ci for (i = 0; i < 2; ++i) 899bf215546Sopenharmony_ci result.filter_level[i] = pic->picture_parameter.filter_level[i]; 900bf215546Sopenharmony_ci result.filter_level_u = pic->picture_parameter.filter_level_u; 901bf215546Sopenharmony_ci result.filter_level_v = pic->picture_parameter.filter_level_v; 902bf215546Sopenharmony_ci result.sharpness_level = pic->picture_parameter.loop_filter_info_fields.sharpness_level; 903bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) 904bf215546Sopenharmony_ci result.ref_deltas[i] = pic->picture_parameter.ref_deltas[i]; 905bf215546Sopenharmony_ci for (i = 0; i < 2; ++i) 906bf215546Sopenharmony_ci result.mode_deltas[i] = pic->picture_parameter.mode_deltas[i]; 907bf215546Sopenharmony_ci result.base_qindex = pic->picture_parameter.base_qindex; 908bf215546Sopenharmony_ci result.y_dc_delta_q = pic->picture_parameter.y_dc_delta_q; 909bf215546Sopenharmony_ci result.u_dc_delta_q = pic->picture_parameter.u_dc_delta_q; 910bf215546Sopenharmony_ci result.v_dc_delta_q = pic->picture_parameter.v_dc_delta_q; 911bf215546Sopenharmony_ci result.u_ac_delta_q = pic->picture_parameter.u_ac_delta_q; 912bf215546Sopenharmony_ci result.v_ac_delta_q = pic->picture_parameter.v_ac_delta_q; 913bf215546Sopenharmony_ci result.qm_y = pic->picture_parameter.qmatrix_fields.qm_y | 0xf0; 914bf215546Sopenharmony_ci result.qm_u = pic->picture_parameter.qmatrix_fields.qm_u | 0xf0; 915bf215546Sopenharmony_ci result.qm_v = pic->picture_parameter.qmatrix_fields.qm_v | 0xf0; 916bf215546Sopenharmony_ci result.delta_q_res = 1 << pic->picture_parameter.mode_control_fields.log2_delta_q_res; 917bf215546Sopenharmony_ci result.delta_lf_res = 1 << pic->picture_parameter.mode_control_fields.log2_delta_lf_res; 918bf215546Sopenharmony_ci 919bf215546Sopenharmony_ci result.tile_cols = pic->picture_parameter.tile_cols; 920bf215546Sopenharmony_ci result.tile_rows = pic->picture_parameter.tile_rows; 921bf215546Sopenharmony_ci result.tx_mode = pic->picture_parameter.mode_control_fields.tx_mode; 922bf215546Sopenharmony_ci result.reference_mode = (pic->picture_parameter.mode_control_fields.reference_select == 1) ? 2 : 0; 923bf215546Sopenharmony_ci result.chroma_format = pic->picture_parameter.seq_info_fields.mono_chrome ? 0 : 1; 924bf215546Sopenharmony_ci result.tile_size_bytes = 0xff; 925bf215546Sopenharmony_ci result.context_update_tile_id = pic->picture_parameter.context_update_tile_id; 926bf215546Sopenharmony_ci for (i = 0; i < 65; ++i) { 927bf215546Sopenharmony_ci result.tile_col_start_sb[i] = pic->picture_parameter.tile_col_start_sb[i]; 928bf215546Sopenharmony_ci result.tile_row_start_sb[i] = pic->picture_parameter.tile_row_start_sb[i]; 929bf215546Sopenharmony_ci } 930bf215546Sopenharmony_ci result.max_width = pic->picture_parameter.max_width; 931bf215546Sopenharmony_ci result.max_height = pic->picture_parameter.max_height; 932bf215546Sopenharmony_ci if (pic->picture_parameter.pic_info_fields.use_superres) { 933bf215546Sopenharmony_ci result.width = (pic->picture_parameter.frame_width * 8 + pic->picture_parameter.superres_scale_denominator / 2) / 934bf215546Sopenharmony_ci pic->picture_parameter.superres_scale_denominator; 935bf215546Sopenharmony_ci result.superres_scale_denominator = pic->picture_parameter.superres_scale_denominator; 936bf215546Sopenharmony_ci } else { 937bf215546Sopenharmony_ci result.width = pic->picture_parameter.frame_width; 938bf215546Sopenharmony_ci result.superres_scale_denominator = pic->picture_parameter.superres_scale_denominator; 939bf215546Sopenharmony_ci } 940bf215546Sopenharmony_ci result.height = pic->picture_parameter.frame_height; 941bf215546Sopenharmony_ci result.superres_upscaled_width = pic->picture_parameter.frame_width; 942bf215546Sopenharmony_ci result.order_hint_bits = pic->picture_parameter.order_hint_bits_minus_1 + 1; 943bf215546Sopenharmony_ci 944bf215546Sopenharmony_ci for (i = 0; i < NUM_AV1_REFS; ++i) { 945bf215546Sopenharmony_ci result.ref_frame_map[i] = 946bf215546Sopenharmony_ci (pic->ref[i]) ? (uintptr_t)vl_video_buffer_get_associated_data(pic->ref[i], &dec->base) 947bf215546Sopenharmony_ci : 0x7f; 948bf215546Sopenharmony_ci } 949bf215546Sopenharmony_ci for (i = 0; i < NUM_AV1_REFS_PER_FRAME; ++i) 950bf215546Sopenharmony_ci result.frame_refs[i] = result.ref_frame_map[pic->picture_parameter.ref_frame_idx[i]]; 951bf215546Sopenharmony_ci 952bf215546Sopenharmony_ci result.bit_depth_luma_minus8 = result.bit_depth_chroma_minus8 = pic->picture_parameter.bit_depth_idx << 1; 953bf215546Sopenharmony_ci 954bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) { 955bf215546Sopenharmony_ci for (j = 0; j < 8; ++j) 956bf215546Sopenharmony_ci result.feature_data[i][j] = pic->picture_parameter.seg_info.feature_data[i][j]; 957bf215546Sopenharmony_ci result.feature_mask[i] = pic->picture_parameter.seg_info.feature_mask[i]; 958bf215546Sopenharmony_ci } 959bf215546Sopenharmony_ci memcpy(dec->probs, &pic->picture_parameter.seg_info.feature_data, 128); 960bf215546Sopenharmony_ci memcpy((dec->probs + 128), &pic->picture_parameter.seg_info.feature_mask, 8); 961bf215546Sopenharmony_ci 962bf215546Sopenharmony_ci result.cdef_damping = pic->picture_parameter.cdef_damping_minus_3 + 3; 963bf215546Sopenharmony_ci result.cdef_bits = pic->picture_parameter.cdef_bits; 964bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) { 965bf215546Sopenharmony_ci result.cdef_strengths[i] = pic->picture_parameter.cdef_y_strengths[i]; 966bf215546Sopenharmony_ci result.cdef_uv_strengths[i] = pic->picture_parameter.cdef_uv_strengths[i]; 967bf215546Sopenharmony_ci } 968bf215546Sopenharmony_ci result.frame_restoration_type[0] = pic->picture_parameter.loop_restoration_fields.yframe_restoration_type; 969bf215546Sopenharmony_ci result.frame_restoration_type[1] = pic->picture_parameter.loop_restoration_fields.cbframe_restoration_type; 970bf215546Sopenharmony_ci result.frame_restoration_type[2] = pic->picture_parameter.loop_restoration_fields.crframe_restoration_type; 971bf215546Sopenharmony_ci for (i = 0; i < 3; ++i) { 972bf215546Sopenharmony_ci int log2_num = 0; 973bf215546Sopenharmony_ci int unit_size = pic->picture_parameter.lr_unit_size[i]; 974bf215546Sopenharmony_ci if (unit_size) { 975bf215546Sopenharmony_ci while (unit_size >>= 1) 976bf215546Sopenharmony_ci log2_num++; 977bf215546Sopenharmony_ci result.log2_restoration_unit_size_minus5[i] = log2_num - 5; 978bf215546Sopenharmony_ci } else { 979bf215546Sopenharmony_ci result.log2_restoration_unit_size_minus5[i] = 0; 980bf215546Sopenharmony_ci } 981bf215546Sopenharmony_ci } 982bf215546Sopenharmony_ci 983bf215546Sopenharmony_ci if (pic->picture_parameter.bit_depth_idx) { 984bf215546Sopenharmony_ci if (target->buffer_format == PIPE_FORMAT_P010 || target->buffer_format == PIPE_FORMAT_P016) { 985bf215546Sopenharmony_ci result.p010_mode = 1; 986bf215546Sopenharmony_ci result.msb_mode = 1; 987bf215546Sopenharmony_ci } else { 988bf215546Sopenharmony_ci result.luma_10to8 = 1; 989bf215546Sopenharmony_ci result.chroma_10to8 = 1; 990bf215546Sopenharmony_ci } 991bf215546Sopenharmony_ci } 992bf215546Sopenharmony_ci 993bf215546Sopenharmony_ci result.preskip_segid = 0; 994bf215546Sopenharmony_ci result.last_active_segid = 0; 995bf215546Sopenharmony_ci for (i = 0; i < 8; i++) { 996bf215546Sopenharmony_ci for (j = 0; j < 8; j++) { 997bf215546Sopenharmony_ci if (pic->picture_parameter.seg_info.feature_mask[i] & (1 << j)) { 998bf215546Sopenharmony_ci result.last_active_segid = i; 999bf215546Sopenharmony_ci if (j >= 5) 1000bf215546Sopenharmony_ci result.preskip_segid = 1; 1001bf215546Sopenharmony_ci } 1002bf215546Sopenharmony_ci } 1003bf215546Sopenharmony_ci } 1004bf215546Sopenharmony_ci 1005bf215546Sopenharmony_ci result.seg_lossless_flag = 0; 1006bf215546Sopenharmony_ci for (i = 0; i < 8; ++i) { 1007bf215546Sopenharmony_ci int av1_get_qindex, qindex; 1008bf215546Sopenharmony_ci int segfeature_active = pic->picture_parameter.seg_info.feature_mask[i] & (1 << 0); 1009bf215546Sopenharmony_ci if (segfeature_active) { 1010bf215546Sopenharmony_ci int seg_qindex = pic->picture_parameter.base_qindex + 1011bf215546Sopenharmony_ci pic->picture_parameter.seg_info.feature_data[i][0]; 1012bf215546Sopenharmony_ci av1_get_qindex = seg_qindex < 0 ? 0 : (seg_qindex > 255 ? 255 : seg_qindex); 1013bf215546Sopenharmony_ci } else { 1014bf215546Sopenharmony_ci av1_get_qindex = pic->picture_parameter.base_qindex; 1015bf215546Sopenharmony_ci } 1016bf215546Sopenharmony_ci qindex = pic->picture_parameter.seg_info.segment_info_fields.enabled ? 1017bf215546Sopenharmony_ci av1_get_qindex : 1018bf215546Sopenharmony_ci pic->picture_parameter.base_qindex; 1019bf215546Sopenharmony_ci result.seg_lossless_flag |= (((qindex == 0) && result.y_dc_delta_q == 0 && 1020bf215546Sopenharmony_ci result.u_dc_delta_q == 0 && result.v_dc_delta_q == 0 && 1021bf215546Sopenharmony_ci result.u_ac_delta_q == 0 && result.v_ac_delta_q == 0) << i); 1022bf215546Sopenharmony_ci } 1023bf215546Sopenharmony_ci 1024bf215546Sopenharmony_ci rvcn_dec_film_grain_params_t* fg_params = &result.film_grain; 1025bf215546Sopenharmony_ci fg_params->apply_grain = pic->picture_parameter.film_grain_info.film_grain_info_fields.apply_grain; 1026bf215546Sopenharmony_ci if (fg_params->apply_grain) { 1027bf215546Sopenharmony_ci fg_params->random_seed = pic->picture_parameter.film_grain_info.grain_seed; 1028bf215546Sopenharmony_ci fg_params->grain_scale_shift = 1029bf215546Sopenharmony_ci pic->picture_parameter.film_grain_info.film_grain_info_fields.grain_scale_shift; 1030bf215546Sopenharmony_ci fg_params->scaling_shift = 1031bf215546Sopenharmony_ci pic->picture_parameter.film_grain_info.film_grain_info_fields.grain_scaling_minus_8 + 8; 1032bf215546Sopenharmony_ci fg_params->chroma_scaling_from_luma = 1033bf215546Sopenharmony_ci pic->picture_parameter.film_grain_info.film_grain_info_fields.chroma_scaling_from_luma; 1034bf215546Sopenharmony_ci fg_params->num_y_points = pic->picture_parameter.film_grain_info.num_y_points; 1035bf215546Sopenharmony_ci fg_params->num_cb_points = pic->picture_parameter.film_grain_info.num_cb_points; 1036bf215546Sopenharmony_ci fg_params->num_cr_points = pic->picture_parameter.film_grain_info.num_cr_points; 1037bf215546Sopenharmony_ci fg_params->cb_mult = pic->picture_parameter.film_grain_info.cb_mult; 1038bf215546Sopenharmony_ci fg_params->cb_luma_mult = pic->picture_parameter.film_grain_info.cb_luma_mult; 1039bf215546Sopenharmony_ci fg_params->cb_offset = pic->picture_parameter.film_grain_info.cb_offset; 1040bf215546Sopenharmony_ci fg_params->cr_mult = pic->picture_parameter.film_grain_info.cr_mult; 1041bf215546Sopenharmony_ci fg_params->cr_luma_mult = pic->picture_parameter.film_grain_info.cr_luma_mult; 1042bf215546Sopenharmony_ci fg_params->cr_offset = pic->picture_parameter.film_grain_info.cr_offset; 1043bf215546Sopenharmony_ci fg_params->bit_depth_minus_8 = pic->picture_parameter.bit_depth_idx << 1; 1044bf215546Sopenharmony_ci 1045bf215546Sopenharmony_ci for (i = 0; i < fg_params->num_y_points; ++i) { 1046bf215546Sopenharmony_ci fg_params->scaling_points_y[i][0] = pic->picture_parameter.film_grain_info.point_y_value[i]; 1047bf215546Sopenharmony_ci fg_params->scaling_points_y[i][1] = pic->picture_parameter.film_grain_info.point_y_scaling[i]; 1048bf215546Sopenharmony_ci } 1049bf215546Sopenharmony_ci for (i = 0; i < fg_params->num_cb_points; ++i) { 1050bf215546Sopenharmony_ci fg_params->scaling_points_cb[i][0] = pic->picture_parameter.film_grain_info.point_cb_value[i]; 1051bf215546Sopenharmony_ci fg_params->scaling_points_cb[i][1] = pic->picture_parameter.film_grain_info.point_cb_scaling[i]; 1052bf215546Sopenharmony_ci } 1053bf215546Sopenharmony_ci for (i = 0; i < fg_params->num_cr_points; ++i) { 1054bf215546Sopenharmony_ci fg_params->scaling_points_cr[i][0] = pic->picture_parameter.film_grain_info.point_cr_value[i]; 1055bf215546Sopenharmony_ci fg_params->scaling_points_cr[i][1] = pic->picture_parameter.film_grain_info.point_cr_scaling[i]; 1056bf215546Sopenharmony_ci } 1057bf215546Sopenharmony_ci 1058bf215546Sopenharmony_ci fg_params->ar_coeff_lag = pic->picture_parameter.film_grain_info.film_grain_info_fields.ar_coeff_lag; 1059bf215546Sopenharmony_ci fg_params->ar_coeff_shift = 1060bf215546Sopenharmony_ci pic->picture_parameter.film_grain_info.film_grain_info_fields.ar_coeff_shift_minus_6 + 6; 1061bf215546Sopenharmony_ci 1062bf215546Sopenharmony_ci for (i = 0; i < 24; ++i) 1063bf215546Sopenharmony_ci fg_params->ar_coeffs_y[i] = pic->picture_parameter.film_grain_info.ar_coeffs_y[i]; 1064bf215546Sopenharmony_ci 1065bf215546Sopenharmony_ci for (i = 0; i < 25; ++i) { 1066bf215546Sopenharmony_ci fg_params->ar_coeffs_cb[i] = pic->picture_parameter.film_grain_info.ar_coeffs_cb[i]; 1067bf215546Sopenharmony_ci fg_params->ar_coeffs_cr[i] = pic->picture_parameter.film_grain_info.ar_coeffs_cr[i]; 1068bf215546Sopenharmony_ci } 1069bf215546Sopenharmony_ci 1070bf215546Sopenharmony_ci fg_params->overlap_flag = pic->picture_parameter.film_grain_info.film_grain_info_fields.overlap_flag; 1071bf215546Sopenharmony_ci fg_params->clip_to_restricted_range = 1072bf215546Sopenharmony_ci pic->picture_parameter.film_grain_info.film_grain_info_fields.clip_to_restricted_range; 1073bf215546Sopenharmony_ci } 1074bf215546Sopenharmony_ci 1075bf215546Sopenharmony_ci result.uncompressed_header_size = 0; 1076bf215546Sopenharmony_ci for (i = 0; i < 7; ++i) { 1077bf215546Sopenharmony_ci result.global_motion[i + 1].wmtype = (rvcn_dec_transformation_type_e)pic->picture_parameter.wm[i].wmtype; 1078bf215546Sopenharmony_ci for (j = 0; j < 6; ++j) 1079bf215546Sopenharmony_ci result.global_motion[i + 1].wmmat[j] = pic->picture_parameter.wm[i].wmmat[j]; 1080bf215546Sopenharmony_ci } 1081bf215546Sopenharmony_ci for (i = 0; i < 256; ++i) { 1082bf215546Sopenharmony_ci result.tile_info[i].offset = pic->slice_parameter.slice_data_offset[i]; 1083bf215546Sopenharmony_ci result.tile_info[i].size = pic->slice_parameter.slice_data_size[i]; 1084bf215546Sopenharmony_ci } 1085bf215546Sopenharmony_ci 1086bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_2) { 1087bf215546Sopenharmony_ci dec->ref_codec.bts = pic->picture_parameter.bit_depth_idx ? CODEC_10_BITS : CODEC_8_BITS; 1088bf215546Sopenharmony_ci dec->ref_codec.index = result.curr_pic_idx; 1089bf215546Sopenharmony_ci dec->ref_codec.ref_size = 8; 1090bf215546Sopenharmony_ci memset(dec->ref_codec.ref_list, 0x7f, sizeof(dec->ref_codec.ref_list)); 1091bf215546Sopenharmony_ci memcpy(dec->ref_codec.ref_list, result.ref_frame_map, sizeof(result.ref_frame_map)); 1092bf215546Sopenharmony_ci } 1093bf215546Sopenharmony_ci 1094bf215546Sopenharmony_ci return result; 1095bf215546Sopenharmony_ci} 1096bf215546Sopenharmony_ci 1097bf215546Sopenharmony_cistatic void rvcn_init_mode_probs(void *prob) 1098bf215546Sopenharmony_ci{ 1099bf215546Sopenharmony_ci rvcn_av1_frame_context_t * fc = (rvcn_av1_frame_context_t*)prob; 1100bf215546Sopenharmony_ci int i; 1101bf215546Sopenharmony_ci 1102bf215546Sopenharmony_ci memcpy(fc->palette_y_size_cdf, default_palette_y_size_cdf, sizeof(default_palette_y_size_cdf)); 1103bf215546Sopenharmony_ci memcpy(fc->palette_uv_size_cdf, default_palette_uv_size_cdf, sizeof(default_palette_uv_size_cdf)); 1104bf215546Sopenharmony_ci memcpy(fc->palette_y_color_index_cdf, default_palette_y_color_index_cdf, sizeof(default_palette_y_color_index_cdf)); 1105bf215546Sopenharmony_ci memcpy(fc->palette_uv_color_index_cdf, default_palette_uv_color_index_cdf, sizeof(default_palette_uv_color_index_cdf)); 1106bf215546Sopenharmony_ci memcpy(fc->kf_y_cdf, default_kf_y_mode_cdf, sizeof(default_kf_y_mode_cdf)); 1107bf215546Sopenharmony_ci memcpy(fc->angle_delta_cdf, default_angle_delta_cdf, sizeof(default_angle_delta_cdf)); 1108bf215546Sopenharmony_ci memcpy(fc->comp_inter_cdf, default_comp_inter_cdf, sizeof(default_comp_inter_cdf)); 1109bf215546Sopenharmony_ci memcpy(fc->comp_ref_type_cdf, default_comp_ref_type_cdf,sizeof(default_comp_ref_type_cdf)); 1110bf215546Sopenharmony_ci memcpy(fc->uni_comp_ref_cdf, default_uni_comp_ref_cdf, sizeof(default_uni_comp_ref_cdf)); 1111bf215546Sopenharmony_ci memcpy(fc->palette_y_mode_cdf, default_palette_y_mode_cdf, sizeof(default_palette_y_mode_cdf)); 1112bf215546Sopenharmony_ci memcpy(fc->palette_uv_mode_cdf, default_palette_uv_mode_cdf, sizeof(default_palette_uv_mode_cdf)); 1113bf215546Sopenharmony_ci memcpy(fc->comp_ref_cdf, default_comp_ref_cdf, sizeof(default_comp_ref_cdf)); 1114bf215546Sopenharmony_ci memcpy(fc->comp_bwdref_cdf, default_comp_bwdref_cdf, sizeof(default_comp_bwdref_cdf)); 1115bf215546Sopenharmony_ci memcpy(fc->single_ref_cdf, default_single_ref_cdf, sizeof(default_single_ref_cdf)); 1116bf215546Sopenharmony_ci memcpy(fc->txfm_partition_cdf, default_txfm_partition_cdf, sizeof(default_txfm_partition_cdf)); 1117bf215546Sopenharmony_ci memcpy(fc->compound_index_cdf, default_compound_idx_cdfs, sizeof(default_compound_idx_cdfs)); 1118bf215546Sopenharmony_ci memcpy(fc->comp_group_idx_cdf, default_comp_group_idx_cdfs, sizeof(default_comp_group_idx_cdfs)); 1119bf215546Sopenharmony_ci memcpy(fc->newmv_cdf, default_newmv_cdf, sizeof(default_newmv_cdf)); 1120bf215546Sopenharmony_ci memcpy(fc->zeromv_cdf, default_zeromv_cdf, sizeof(default_zeromv_cdf)); 1121bf215546Sopenharmony_ci memcpy(fc->refmv_cdf, default_refmv_cdf, sizeof(default_refmv_cdf)); 1122bf215546Sopenharmony_ci memcpy(fc->drl_cdf, default_drl_cdf, sizeof(default_drl_cdf)); 1123bf215546Sopenharmony_ci memcpy(fc->motion_mode_cdf, default_motion_mode_cdf, sizeof(default_motion_mode_cdf)); 1124bf215546Sopenharmony_ci memcpy(fc->obmc_cdf, default_obmc_cdf, sizeof(default_obmc_cdf)); 1125bf215546Sopenharmony_ci memcpy(fc->inter_compound_mode_cdf, default_inter_compound_mode_cdf, sizeof(default_inter_compound_mode_cdf)); 1126bf215546Sopenharmony_ci memcpy(fc->compound_type_cdf, default_compound_type_cdf, sizeof(default_compound_type_cdf)); 1127bf215546Sopenharmony_ci memcpy(fc->wedge_idx_cdf, default_wedge_idx_cdf, sizeof(default_wedge_idx_cdf)); 1128bf215546Sopenharmony_ci memcpy(fc->interintra_cdf, default_interintra_cdf, sizeof(default_interintra_cdf)); 1129bf215546Sopenharmony_ci memcpy(fc->wedge_interintra_cdf, default_wedge_interintra_cdf, sizeof(default_wedge_interintra_cdf)); 1130bf215546Sopenharmony_ci memcpy(fc->interintra_mode_cdf, default_interintra_mode_cdf, sizeof(default_interintra_mode_cdf)); 1131bf215546Sopenharmony_ci memcpy(fc->pred_cdf, default_segment_pred_cdf, sizeof(default_segment_pred_cdf)); 1132bf215546Sopenharmony_ci memcpy(fc->switchable_restore_cdf, default_switchable_restore_cdf, sizeof(default_switchable_restore_cdf)); 1133bf215546Sopenharmony_ci memcpy(fc->wiener_restore_cdf, default_wiener_restore_cdf, sizeof(default_wiener_restore_cdf)); 1134bf215546Sopenharmony_ci memcpy(fc->sgrproj_restore_cdf, default_sgrproj_restore_cdf, sizeof(default_sgrproj_restore_cdf)); 1135bf215546Sopenharmony_ci memcpy(fc->y_mode_cdf, default_if_y_mode_cdf, sizeof(default_if_y_mode_cdf)); 1136bf215546Sopenharmony_ci memcpy(fc->uv_mode_cdf, default_uv_mode_cdf, sizeof(default_uv_mode_cdf)); 1137bf215546Sopenharmony_ci memcpy(fc->switchable_interp_cdf, default_switchable_interp_cdf, sizeof(default_switchable_interp_cdf)); 1138bf215546Sopenharmony_ci memcpy(fc->partition_cdf, default_partition_cdf, sizeof(default_partition_cdf)); 1139bf215546Sopenharmony_ci memcpy(fc->intra_ext_tx_cdf, default_intra_ext_tx_cdf, sizeof(default_intra_ext_tx_cdf)); 1140bf215546Sopenharmony_ci memcpy(fc->inter_ext_tx_cdf, default_inter_ext_tx_cdf, sizeof(default_inter_ext_tx_cdf)); 1141bf215546Sopenharmony_ci memcpy(fc->skip_cdfs, default_skip_cdfs, sizeof(default_skip_cdfs)); 1142bf215546Sopenharmony_ci memcpy(fc->intra_inter_cdf, default_intra_inter_cdf, sizeof(default_intra_inter_cdf)); 1143bf215546Sopenharmony_ci memcpy(fc->tree_cdf, default_seg_tree_cdf, sizeof(default_seg_tree_cdf)); 1144bf215546Sopenharmony_ci for (i = 0; i < SPATIAL_PREDICTION_PROBS; ++i) 1145bf215546Sopenharmony_ci memcpy(fc->spatial_pred_seg_cdf[i], default_spatial_pred_seg_tree_cdf[i], sizeof(default_spatial_pred_seg_tree_cdf[i])); 1146bf215546Sopenharmony_ci memcpy(fc->tx_size_cdf, default_tx_size_cdf, sizeof(default_tx_size_cdf)); 1147bf215546Sopenharmony_ci memcpy(fc->delta_q_cdf, default_delta_q_cdf, sizeof(default_delta_q_cdf)); 1148bf215546Sopenharmony_ci memcpy(fc->skip_mode_cdfs, default_skip_mode_cdfs, sizeof(default_skip_mode_cdfs)); 1149bf215546Sopenharmony_ci memcpy(fc->delta_lf_cdf, default_delta_lf_cdf, sizeof(default_delta_lf_cdf)); 1150bf215546Sopenharmony_ci memcpy(fc->delta_lf_multi_cdf, default_delta_lf_multi_cdf, sizeof(default_delta_lf_multi_cdf)); 1151bf215546Sopenharmony_ci memcpy(fc->cfl_sign_cdf, default_cfl_sign_cdf, sizeof(default_cfl_sign_cdf)); 1152bf215546Sopenharmony_ci memcpy(fc->cfl_alpha_cdf, default_cfl_alpha_cdf, sizeof(default_cfl_alpha_cdf)); 1153bf215546Sopenharmony_ci memcpy(fc->filter_intra_cdfs, default_filter_intra_cdfs, sizeof(default_filter_intra_cdfs)); 1154bf215546Sopenharmony_ci memcpy(fc->filter_intra_mode_cdf, default_filter_intra_mode_cdf, sizeof(default_filter_intra_mode_cdf)); 1155bf215546Sopenharmony_ci memcpy(fc->intrabc_cdf, default_intrabc_cdf, sizeof(default_intrabc_cdf)); 1156bf215546Sopenharmony_ci} 1157bf215546Sopenharmony_ci 1158bf215546Sopenharmony_cistatic void rvcn_vcn4_init_mode_probs(void *prob) 1159bf215546Sopenharmony_ci{ 1160bf215546Sopenharmony_ci rvcn_av1_vcn4_frame_context_t * fc = (rvcn_av1_vcn4_frame_context_t*)prob; 1161bf215546Sopenharmony_ci int i; 1162bf215546Sopenharmony_ci 1163bf215546Sopenharmony_ci memcpy(fc->palette_y_size_cdf, default_palette_y_size_cdf, sizeof(default_palette_y_size_cdf)); 1164bf215546Sopenharmony_ci memcpy(fc->palette_uv_size_cdf, default_palette_uv_size_cdf, sizeof(default_palette_uv_size_cdf)); 1165bf215546Sopenharmony_ci memcpy(fc->palette_y_color_index_cdf, default_palette_y_color_index_cdf, sizeof(default_palette_y_color_index_cdf)); 1166bf215546Sopenharmony_ci memcpy(fc->palette_uv_color_index_cdf, default_palette_uv_color_index_cdf, sizeof(default_palette_uv_color_index_cdf)); 1167bf215546Sopenharmony_ci memcpy(fc->kf_y_cdf, default_kf_y_mode_cdf, sizeof(default_kf_y_mode_cdf)); 1168bf215546Sopenharmony_ci memcpy(fc->angle_delta_cdf, default_angle_delta_cdf, sizeof(default_angle_delta_cdf)); 1169bf215546Sopenharmony_ci memcpy(fc->comp_inter_cdf, default_comp_inter_cdf, sizeof(default_comp_inter_cdf)); 1170bf215546Sopenharmony_ci memcpy(fc->comp_ref_type_cdf, default_comp_ref_type_cdf,sizeof(default_comp_ref_type_cdf)); 1171bf215546Sopenharmony_ci memcpy(fc->uni_comp_ref_cdf, default_uni_comp_ref_cdf, sizeof(default_uni_comp_ref_cdf)); 1172bf215546Sopenharmony_ci memcpy(fc->palette_y_mode_cdf, default_palette_y_mode_cdf, sizeof(default_palette_y_mode_cdf)); 1173bf215546Sopenharmony_ci memcpy(fc->palette_uv_mode_cdf, default_palette_uv_mode_cdf, sizeof(default_palette_uv_mode_cdf)); 1174bf215546Sopenharmony_ci memcpy(fc->comp_ref_cdf, default_comp_ref_cdf, sizeof(default_comp_ref_cdf)); 1175bf215546Sopenharmony_ci memcpy(fc->comp_bwdref_cdf, default_comp_bwdref_cdf, sizeof(default_comp_bwdref_cdf)); 1176bf215546Sopenharmony_ci memcpy(fc->single_ref_cdf, default_single_ref_cdf, sizeof(default_single_ref_cdf)); 1177bf215546Sopenharmony_ci memcpy(fc->txfm_partition_cdf, default_txfm_partition_cdf, sizeof(default_txfm_partition_cdf)); 1178bf215546Sopenharmony_ci memcpy(fc->compound_index_cdf, default_compound_idx_cdfs, sizeof(default_compound_idx_cdfs)); 1179bf215546Sopenharmony_ci memcpy(fc->comp_group_idx_cdf, default_comp_group_idx_cdfs, sizeof(default_comp_group_idx_cdfs)); 1180bf215546Sopenharmony_ci memcpy(fc->newmv_cdf, default_newmv_cdf, sizeof(default_newmv_cdf)); 1181bf215546Sopenharmony_ci memcpy(fc->zeromv_cdf, default_zeromv_cdf, sizeof(default_zeromv_cdf)); 1182bf215546Sopenharmony_ci memcpy(fc->refmv_cdf, default_refmv_cdf, sizeof(default_refmv_cdf)); 1183bf215546Sopenharmony_ci memcpy(fc->drl_cdf, default_drl_cdf, sizeof(default_drl_cdf)); 1184bf215546Sopenharmony_ci memcpy(fc->motion_mode_cdf, default_motion_mode_cdf, sizeof(default_motion_mode_cdf)); 1185bf215546Sopenharmony_ci memcpy(fc->obmc_cdf, default_obmc_cdf, sizeof(default_obmc_cdf)); 1186bf215546Sopenharmony_ci memcpy(fc->inter_compound_mode_cdf, default_inter_compound_mode_cdf, sizeof(default_inter_compound_mode_cdf)); 1187bf215546Sopenharmony_ci memcpy(fc->compound_type_cdf, default_compound_type_cdf, sizeof(default_compound_type_cdf)); 1188bf215546Sopenharmony_ci memcpy(fc->wedge_idx_cdf, default_wedge_idx_cdf, sizeof(default_wedge_idx_cdf)); 1189bf215546Sopenharmony_ci memcpy(fc->interintra_cdf, default_interintra_cdf, sizeof(default_interintra_cdf)); 1190bf215546Sopenharmony_ci memcpy(fc->wedge_interintra_cdf, default_wedge_interintra_cdf, sizeof(default_wedge_interintra_cdf)); 1191bf215546Sopenharmony_ci memcpy(fc->interintra_mode_cdf, default_interintra_mode_cdf, sizeof(default_interintra_mode_cdf)); 1192bf215546Sopenharmony_ci memcpy(fc->pred_cdf, default_segment_pred_cdf, sizeof(default_segment_pred_cdf)); 1193bf215546Sopenharmony_ci memcpy(fc->switchable_restore_cdf, default_switchable_restore_cdf, sizeof(default_switchable_restore_cdf)); 1194bf215546Sopenharmony_ci memcpy(fc->wiener_restore_cdf, default_wiener_restore_cdf, sizeof(default_wiener_restore_cdf)); 1195bf215546Sopenharmony_ci memcpy(fc->sgrproj_restore_cdf, default_sgrproj_restore_cdf, sizeof(default_sgrproj_restore_cdf)); 1196bf215546Sopenharmony_ci memcpy(fc->y_mode_cdf, default_if_y_mode_cdf, sizeof(default_if_y_mode_cdf)); 1197bf215546Sopenharmony_ci memcpy(fc->uv_mode_cdf, default_uv_mode_cdf, sizeof(default_uv_mode_cdf)); 1198bf215546Sopenharmony_ci memcpy(fc->switchable_interp_cdf, default_switchable_interp_cdf, sizeof(default_switchable_interp_cdf)); 1199bf215546Sopenharmony_ci memcpy(fc->partition_cdf, default_partition_cdf, sizeof(default_partition_cdf)); 1200bf215546Sopenharmony_ci memcpy(fc->intra_ext_tx_cdf, &default_intra_ext_tx_cdf[1], sizeof(default_intra_ext_tx_cdf[1]) * 2); 1201bf215546Sopenharmony_ci memcpy(fc->inter_ext_tx_cdf, &default_inter_ext_tx_cdf[1], sizeof(default_inter_ext_tx_cdf[1]) * 3); 1202bf215546Sopenharmony_ci memcpy(fc->skip_cdfs, default_skip_cdfs, sizeof(default_skip_cdfs)); 1203bf215546Sopenharmony_ci memcpy(fc->intra_inter_cdf, default_intra_inter_cdf, sizeof(default_intra_inter_cdf)); 1204bf215546Sopenharmony_ci memcpy(fc->tree_cdf, default_seg_tree_cdf, sizeof(default_seg_tree_cdf)); 1205bf215546Sopenharmony_ci for (i = 0; i < SPATIAL_PREDICTION_PROBS; ++i) 1206bf215546Sopenharmony_ci memcpy(fc->spatial_pred_seg_cdf[i], default_spatial_pred_seg_tree_cdf[i], sizeof(default_spatial_pred_seg_tree_cdf[i])); 1207bf215546Sopenharmony_ci memcpy(fc->tx_size_cdf, default_tx_size_cdf, sizeof(default_tx_size_cdf)); 1208bf215546Sopenharmony_ci memcpy(fc->delta_q_cdf, default_delta_q_cdf, sizeof(default_delta_q_cdf)); 1209bf215546Sopenharmony_ci memcpy(fc->skip_mode_cdfs, default_skip_mode_cdfs, sizeof(default_skip_mode_cdfs)); 1210bf215546Sopenharmony_ci memcpy(fc->delta_lf_cdf, default_delta_lf_cdf, sizeof(default_delta_lf_cdf)); 1211bf215546Sopenharmony_ci memcpy(fc->delta_lf_multi_cdf, default_delta_lf_multi_cdf, sizeof(default_delta_lf_multi_cdf)); 1212bf215546Sopenharmony_ci memcpy(fc->cfl_sign_cdf, default_cfl_sign_cdf, sizeof(default_cfl_sign_cdf)); 1213bf215546Sopenharmony_ci memcpy(fc->cfl_alpha_cdf, default_cfl_alpha_cdf, sizeof(default_cfl_alpha_cdf)); 1214bf215546Sopenharmony_ci memcpy(fc->filter_intra_cdfs, default_filter_intra_cdfs, sizeof(default_filter_intra_cdfs)); 1215bf215546Sopenharmony_ci memcpy(fc->filter_intra_mode_cdf, default_filter_intra_mode_cdf, sizeof(default_filter_intra_mode_cdf)); 1216bf215546Sopenharmony_ci memcpy(fc->intrabc_cdf, default_intrabc_cdf, sizeof(default_intrabc_cdf)); 1217bf215546Sopenharmony_ci} 1218bf215546Sopenharmony_ci 1219bf215546Sopenharmony_cistatic void rvcn_av1_init_mv_probs(void *prob) 1220bf215546Sopenharmony_ci{ 1221bf215546Sopenharmony_ci rvcn_av1_frame_context_t * fc = (rvcn_av1_frame_context_t*)prob; 1222bf215546Sopenharmony_ci 1223bf215546Sopenharmony_ci memcpy(fc->nmvc_joints_cdf, default_nmv_context.joints_cdf, sizeof(default_nmv_context.joints_cdf)); 1224bf215546Sopenharmony_ci memcpy(fc->nmvc_0_bits_cdf, default_nmv_context.comps[0].bits_cdf, sizeof(default_nmv_context.comps[0].bits_cdf)); 1225bf215546Sopenharmony_ci memcpy(fc->nmvc_0_class0_cdf, default_nmv_context.comps[0].class0_cdf, sizeof(default_nmv_context.comps[0].class0_cdf)); 1226bf215546Sopenharmony_ci memcpy(fc->nmvc_0_class0_fp_cdf, default_nmv_context.comps[0].class0_fp_cdf, sizeof(default_nmv_context.comps[0].class0_fp_cdf)); 1227bf215546Sopenharmony_ci memcpy(fc->nmvc_0_class0_hp_cdf, default_nmv_context.comps[0].class0_hp_cdf, sizeof(default_nmv_context.comps[0].class0_hp_cdf)); 1228bf215546Sopenharmony_ci memcpy(fc->nmvc_0_classes_cdf, default_nmv_context.comps[0].classes_cdf, sizeof(default_nmv_context.comps[0].classes_cdf)); 1229bf215546Sopenharmony_ci memcpy(fc->nmvc_0_fp_cdf, default_nmv_context.comps[0].fp_cdf, sizeof(default_nmv_context.comps[0].fp_cdf)); 1230bf215546Sopenharmony_ci memcpy(fc->nmvc_0_hp_cdf, default_nmv_context.comps[0].hp_cdf, sizeof(default_nmv_context.comps[0].hp_cdf)); 1231bf215546Sopenharmony_ci memcpy(fc->nmvc_0_sign_cdf, default_nmv_context.comps[0].sign_cdf, sizeof(default_nmv_context.comps[0].sign_cdf)); 1232bf215546Sopenharmony_ci memcpy(fc->nmvc_1_bits_cdf, default_nmv_context.comps[1].bits_cdf, sizeof(default_nmv_context.comps[1].bits_cdf)); 1233bf215546Sopenharmony_ci memcpy(fc->nmvc_1_class0_cdf, default_nmv_context.comps[1].class0_cdf, sizeof(default_nmv_context.comps[1].class0_cdf)); 1234bf215546Sopenharmony_ci memcpy(fc->nmvc_1_class0_fp_cdf, default_nmv_context.comps[1].class0_fp_cdf, sizeof(default_nmv_context.comps[1].class0_fp_cdf)); 1235bf215546Sopenharmony_ci memcpy(fc->nmvc_1_class0_hp_cdf, default_nmv_context.comps[1].class0_hp_cdf, sizeof(default_nmv_context.comps[1].class0_hp_cdf)); 1236bf215546Sopenharmony_ci memcpy(fc->nmvc_1_classes_cdf, default_nmv_context.comps[1].classes_cdf, sizeof(default_nmv_context.comps[1].classes_cdf)); 1237bf215546Sopenharmony_ci memcpy(fc->nmvc_1_fp_cdf, default_nmv_context.comps[1].fp_cdf, sizeof(default_nmv_context.comps[1].fp_cdf)); 1238bf215546Sopenharmony_ci memcpy(fc->nmvc_1_hp_cdf, default_nmv_context.comps[1].hp_cdf, sizeof(default_nmv_context.comps[1].hp_cdf)); 1239bf215546Sopenharmony_ci memcpy(fc->nmvc_1_sign_cdf, default_nmv_context.comps[1].sign_cdf, sizeof(default_nmv_context.comps[1].sign_cdf)); 1240bf215546Sopenharmony_ci memcpy(fc->ndvc_joints_cdf, default_nmv_context.joints_cdf, sizeof(default_nmv_context.joints_cdf)); 1241bf215546Sopenharmony_ci memcpy(fc->ndvc_0_bits_cdf, default_nmv_context.comps[0].bits_cdf, sizeof(default_nmv_context.comps[0].bits_cdf)); 1242bf215546Sopenharmony_ci memcpy(fc->ndvc_0_class0_cdf, default_nmv_context.comps[0].class0_cdf, sizeof(default_nmv_context.comps[0].class0_cdf)); 1243bf215546Sopenharmony_ci memcpy(fc->ndvc_0_class0_fp_cdf, default_nmv_context.comps[0].class0_fp_cdf, sizeof(default_nmv_context.comps[0].class0_fp_cdf)); 1244bf215546Sopenharmony_ci memcpy(fc->ndvc_0_class0_hp_cdf, default_nmv_context.comps[0].class0_hp_cdf, sizeof(default_nmv_context.comps[0].class0_hp_cdf)); 1245bf215546Sopenharmony_ci memcpy(fc->ndvc_0_classes_cdf, default_nmv_context.comps[0].classes_cdf, sizeof(default_nmv_context.comps[0].classes_cdf)); 1246bf215546Sopenharmony_ci memcpy(fc->ndvc_0_fp_cdf, default_nmv_context.comps[0].fp_cdf, sizeof(default_nmv_context.comps[0].fp_cdf)); 1247bf215546Sopenharmony_ci memcpy(fc->ndvc_0_hp_cdf, default_nmv_context.comps[0].hp_cdf, sizeof(default_nmv_context.comps[0].hp_cdf)); 1248bf215546Sopenharmony_ci memcpy(fc->ndvc_0_sign_cdf, default_nmv_context.comps[0].sign_cdf, sizeof(default_nmv_context.comps[0].sign_cdf)); 1249bf215546Sopenharmony_ci memcpy(fc->ndvc_1_bits_cdf, default_nmv_context.comps[1].bits_cdf, sizeof(default_nmv_context.comps[1].bits_cdf)); 1250bf215546Sopenharmony_ci memcpy(fc->ndvc_1_class0_cdf, default_nmv_context.comps[1].class0_cdf, sizeof(default_nmv_context.comps[1].class0_cdf)); 1251bf215546Sopenharmony_ci memcpy(fc->ndvc_1_class0_fp_cdf, default_nmv_context.comps[1].class0_fp_cdf, sizeof(default_nmv_context.comps[1].class0_fp_cdf)); 1252bf215546Sopenharmony_ci memcpy(fc->ndvc_1_class0_hp_cdf, default_nmv_context.comps[1].class0_hp_cdf, sizeof(default_nmv_context.comps[1].class0_hp_cdf)); 1253bf215546Sopenharmony_ci memcpy(fc->ndvc_1_classes_cdf, default_nmv_context.comps[1].classes_cdf, sizeof(default_nmv_context.comps[1].classes_cdf)); 1254bf215546Sopenharmony_ci memcpy(fc->ndvc_1_fp_cdf, default_nmv_context.comps[1].fp_cdf, sizeof(default_nmv_context.comps[1].fp_cdf)); 1255bf215546Sopenharmony_ci memcpy(fc->ndvc_1_hp_cdf, default_nmv_context.comps[1].hp_cdf, sizeof(default_nmv_context.comps[1].hp_cdf)); 1256bf215546Sopenharmony_ci memcpy(fc->ndvc_1_sign_cdf, default_nmv_context.comps[1].sign_cdf, sizeof(default_nmv_context.comps[1].sign_cdf)); 1257bf215546Sopenharmony_ci} 1258bf215546Sopenharmony_ci 1259bf215546Sopenharmony_cistatic void rvcn_vcn4_av1_init_mv_probs(void *prob) 1260bf215546Sopenharmony_ci{ 1261bf215546Sopenharmony_ci rvcn_av1_vcn4_frame_context_t * fc = (rvcn_av1_vcn4_frame_context_t*)prob; 1262bf215546Sopenharmony_ci 1263bf215546Sopenharmony_ci memcpy(fc->nmvc_joints_cdf, default_nmv_context.joints_cdf, sizeof(default_nmv_context.joints_cdf)); 1264bf215546Sopenharmony_ci memcpy(fc->nmvc_0_bits_cdf, default_nmv_context.comps[0].bits_cdf, sizeof(default_nmv_context.comps[0].bits_cdf)); 1265bf215546Sopenharmony_ci memcpy(fc->nmvc_0_class0_cdf, default_nmv_context.comps[0].class0_cdf, sizeof(default_nmv_context.comps[0].class0_cdf)); 1266bf215546Sopenharmony_ci memcpy(fc->nmvc_0_class0_fp_cdf, default_nmv_context.comps[0].class0_fp_cdf, sizeof(default_nmv_context.comps[0].class0_fp_cdf)); 1267bf215546Sopenharmony_ci memcpy(fc->nmvc_0_class0_hp_cdf, default_nmv_context.comps[0].class0_hp_cdf, sizeof(default_nmv_context.comps[0].class0_hp_cdf)); 1268bf215546Sopenharmony_ci memcpy(fc->nmvc_0_classes_cdf, default_nmv_context.comps[0].classes_cdf, sizeof(default_nmv_context.comps[0].classes_cdf)); 1269bf215546Sopenharmony_ci memcpy(fc->nmvc_0_fp_cdf, default_nmv_context.comps[0].fp_cdf, sizeof(default_nmv_context.comps[0].fp_cdf)); 1270bf215546Sopenharmony_ci memcpy(fc->nmvc_0_hp_cdf, default_nmv_context.comps[0].hp_cdf, sizeof(default_nmv_context.comps[0].hp_cdf)); 1271bf215546Sopenharmony_ci memcpy(fc->nmvc_0_sign_cdf, default_nmv_context.comps[0].sign_cdf, sizeof(default_nmv_context.comps[0].sign_cdf)); 1272bf215546Sopenharmony_ci memcpy(fc->nmvc_1_bits_cdf, default_nmv_context.comps[1].bits_cdf, sizeof(default_nmv_context.comps[1].bits_cdf)); 1273bf215546Sopenharmony_ci memcpy(fc->nmvc_1_class0_cdf, default_nmv_context.comps[1].class0_cdf, sizeof(default_nmv_context.comps[1].class0_cdf)); 1274bf215546Sopenharmony_ci memcpy(fc->nmvc_1_class0_fp_cdf, default_nmv_context.comps[1].class0_fp_cdf, sizeof(default_nmv_context.comps[1].class0_fp_cdf)); 1275bf215546Sopenharmony_ci memcpy(fc->nmvc_1_class0_hp_cdf, default_nmv_context.comps[1].class0_hp_cdf, sizeof(default_nmv_context.comps[1].class0_hp_cdf)); 1276bf215546Sopenharmony_ci memcpy(fc->nmvc_1_classes_cdf, default_nmv_context.comps[1].classes_cdf, sizeof(default_nmv_context.comps[1].classes_cdf)); 1277bf215546Sopenharmony_ci memcpy(fc->nmvc_1_fp_cdf, default_nmv_context.comps[1].fp_cdf, sizeof(default_nmv_context.comps[1].fp_cdf)); 1278bf215546Sopenharmony_ci memcpy(fc->nmvc_1_hp_cdf, default_nmv_context.comps[1].hp_cdf, sizeof(default_nmv_context.comps[1].hp_cdf)); 1279bf215546Sopenharmony_ci memcpy(fc->nmvc_1_sign_cdf, default_nmv_context.comps[1].sign_cdf, sizeof(default_nmv_context.comps[1].sign_cdf)); 1280bf215546Sopenharmony_ci memcpy(fc->ndvc_joints_cdf, default_nmv_context.joints_cdf, sizeof(default_nmv_context.joints_cdf)); 1281bf215546Sopenharmony_ci memcpy(fc->ndvc_0_bits_cdf, default_nmv_context.comps[0].bits_cdf, sizeof(default_nmv_context.comps[0].bits_cdf)); 1282bf215546Sopenharmony_ci memcpy(fc->ndvc_0_class0_cdf, default_nmv_context.comps[0].class0_cdf, sizeof(default_nmv_context.comps[0].class0_cdf)); 1283bf215546Sopenharmony_ci memcpy(fc->ndvc_0_class0_fp_cdf, default_nmv_context.comps[0].class0_fp_cdf, sizeof(default_nmv_context.comps[0].class0_fp_cdf)); 1284bf215546Sopenharmony_ci memcpy(fc->ndvc_0_class0_hp_cdf, default_nmv_context.comps[0].class0_hp_cdf, sizeof(default_nmv_context.comps[0].class0_hp_cdf)); 1285bf215546Sopenharmony_ci memcpy(fc->ndvc_0_classes_cdf, default_nmv_context.comps[0].classes_cdf, sizeof(default_nmv_context.comps[0].classes_cdf)); 1286bf215546Sopenharmony_ci memcpy(fc->ndvc_0_fp_cdf, default_nmv_context.comps[0].fp_cdf, sizeof(default_nmv_context.comps[0].fp_cdf)); 1287bf215546Sopenharmony_ci memcpy(fc->ndvc_0_hp_cdf, default_nmv_context.comps[0].hp_cdf, sizeof(default_nmv_context.comps[0].hp_cdf)); 1288bf215546Sopenharmony_ci memcpy(fc->ndvc_0_sign_cdf, default_nmv_context.comps[0].sign_cdf, sizeof(default_nmv_context.comps[0].sign_cdf)); 1289bf215546Sopenharmony_ci memcpy(fc->ndvc_1_bits_cdf, default_nmv_context.comps[1].bits_cdf, sizeof(default_nmv_context.comps[1].bits_cdf)); 1290bf215546Sopenharmony_ci memcpy(fc->ndvc_1_class0_cdf, default_nmv_context.comps[1].class0_cdf, sizeof(default_nmv_context.comps[1].class0_cdf)); 1291bf215546Sopenharmony_ci memcpy(fc->ndvc_1_class0_fp_cdf, default_nmv_context.comps[1].class0_fp_cdf, sizeof(default_nmv_context.comps[1].class0_fp_cdf)); 1292bf215546Sopenharmony_ci memcpy(fc->ndvc_1_class0_hp_cdf, default_nmv_context.comps[1].class0_hp_cdf, sizeof(default_nmv_context.comps[1].class0_hp_cdf)); 1293bf215546Sopenharmony_ci memcpy(fc->ndvc_1_classes_cdf, default_nmv_context.comps[1].classes_cdf, sizeof(default_nmv_context.comps[1].classes_cdf)); 1294bf215546Sopenharmony_ci memcpy(fc->ndvc_1_fp_cdf, default_nmv_context.comps[1].fp_cdf, sizeof(default_nmv_context.comps[1].fp_cdf)); 1295bf215546Sopenharmony_ci memcpy(fc->ndvc_1_hp_cdf, default_nmv_context.comps[1].hp_cdf, sizeof(default_nmv_context.comps[1].hp_cdf)); 1296bf215546Sopenharmony_ci memcpy(fc->ndvc_1_sign_cdf, default_nmv_context.comps[1].sign_cdf, sizeof(default_nmv_context.comps[1].sign_cdf)); 1297bf215546Sopenharmony_ci} 1298bf215546Sopenharmony_ci 1299bf215546Sopenharmony_cistatic void rvcn_av1_default_coef_probs(void *prob, int index) 1300bf215546Sopenharmony_ci{ 1301bf215546Sopenharmony_ci rvcn_av1_frame_context_t * fc = (rvcn_av1_frame_context_t*)prob; 1302bf215546Sopenharmony_ci 1303bf215546Sopenharmony_ci memcpy(fc->txb_skip_cdf, av1_default_txb_skip_cdfs[index], sizeof(av1_default_txb_skip_cdfs[index])); 1304bf215546Sopenharmony_ci memcpy(fc->eob_extra_cdf, av1_default_eob_extra_cdfs[index], sizeof(av1_default_eob_extra_cdfs[index])); 1305bf215546Sopenharmony_ci memcpy(fc->dc_sign_cdf, av1_default_dc_sign_cdfs[index], sizeof(av1_default_dc_sign_cdfs[index])); 1306bf215546Sopenharmony_ci memcpy(fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index], sizeof(av1_default_coeff_lps_multi_cdfs[index])); 1307bf215546Sopenharmony_ci memcpy(fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index], sizeof(av1_default_coeff_base_multi_cdfs[index])); 1308bf215546Sopenharmony_ci memcpy(fc->coeff_base_eob_cdf, av1_default_coeff_base_eob_multi_cdfs[index], sizeof(av1_default_coeff_base_eob_multi_cdfs[index])); 1309bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf16, av1_default_eob_multi16_cdfs[index], sizeof(av1_default_eob_multi16_cdfs[index])); 1310bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf32, av1_default_eob_multi32_cdfs[index], sizeof(av1_default_eob_multi32_cdfs[index])); 1311bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf64, av1_default_eob_multi64_cdfs[index], sizeof(av1_default_eob_multi64_cdfs[index])); 1312bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf128, av1_default_eob_multi128_cdfs[index], sizeof(av1_default_eob_multi128_cdfs[index])); 1313bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf256, av1_default_eob_multi256_cdfs[index], sizeof(av1_default_eob_multi256_cdfs[index])); 1314bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf512, av1_default_eob_multi512_cdfs[index], sizeof(av1_default_eob_multi512_cdfs[index])); 1315bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf1024, av1_default_eob_multi1024_cdfs[index], sizeof(av1_default_eob_multi1024_cdfs[index])); 1316bf215546Sopenharmony_ci} 1317bf215546Sopenharmony_ci 1318bf215546Sopenharmony_cistatic void rvcn_vcn4_av1_default_coef_probs(void *prob, int index) 1319bf215546Sopenharmony_ci{ 1320bf215546Sopenharmony_ci rvcn_av1_vcn4_frame_context_t *fc = (rvcn_av1_vcn4_frame_context_t*)prob; 1321bf215546Sopenharmony_ci void *p; 1322bf215546Sopenharmony_ci int i, j; 1323bf215546Sopenharmony_ci unsigned size; 1324bf215546Sopenharmony_ci 1325bf215546Sopenharmony_ci memcpy(fc->txb_skip_cdf, av1_default_txb_skip_cdfs[index], sizeof(av1_default_txb_skip_cdfs[index])); 1326bf215546Sopenharmony_ci 1327bf215546Sopenharmony_ci p = (void *)fc->eob_extra_cdf; 1328bf215546Sopenharmony_ci size = sizeof(av1_default_eob_extra_cdfs[0][0][0][0]) * EOB_COEF_CONTEXTS_VCN4; 1329bf215546Sopenharmony_ci for (i = 0; i < AV1_TX_SIZES; i++) { 1330bf215546Sopenharmony_ci for ( j = 0; j < AV1_PLANE_TYPES; j++) { 1331bf215546Sopenharmony_ci memcpy(p, &av1_default_eob_extra_cdfs[index][i][j][3], size); 1332bf215546Sopenharmony_ci p += size; 1333bf215546Sopenharmony_ci } 1334bf215546Sopenharmony_ci } 1335bf215546Sopenharmony_ci 1336bf215546Sopenharmony_ci memcpy(fc->dc_sign_cdf, av1_default_dc_sign_cdfs[index], sizeof(av1_default_dc_sign_cdfs[index])); 1337bf215546Sopenharmony_ci memcpy(fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index], sizeof(av1_default_coeff_lps_multi_cdfs[index])); 1338bf215546Sopenharmony_ci memcpy(fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index], sizeof(av1_default_coeff_base_multi_cdfs[index])); 1339bf215546Sopenharmony_ci memcpy(fc->coeff_base_eob_cdf, av1_default_coeff_base_eob_multi_cdfs[index], sizeof(av1_default_coeff_base_eob_multi_cdfs[index])); 1340bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf16, av1_default_eob_multi16_cdfs[index], sizeof(av1_default_eob_multi16_cdfs[index])); 1341bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf32, av1_default_eob_multi32_cdfs[index], sizeof(av1_default_eob_multi32_cdfs[index])); 1342bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf64, av1_default_eob_multi64_cdfs[index], sizeof(av1_default_eob_multi64_cdfs[index])); 1343bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf128, av1_default_eob_multi128_cdfs[index], sizeof(av1_default_eob_multi128_cdfs[index])); 1344bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf256, av1_default_eob_multi256_cdfs[index], sizeof(av1_default_eob_multi256_cdfs[index])); 1345bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf512, av1_default_eob_multi512_cdfs[index], sizeof(av1_default_eob_multi512_cdfs[index])); 1346bf215546Sopenharmony_ci memcpy(fc->eob_flag_cdf1024, av1_default_eob_multi1024_cdfs[index], sizeof(av1_default_eob_multi1024_cdfs[index])); 1347bf215546Sopenharmony_ci} 1348bf215546Sopenharmony_ci 1349bf215546Sopenharmony_cistatic unsigned calc_ctx_size_h265_main(struct radeon_decoder *dec) 1350bf215546Sopenharmony_ci{ 1351bf215546Sopenharmony_ci unsigned width = align(dec->base.width, VL_MACROBLOCK_WIDTH); 1352bf215546Sopenharmony_ci unsigned height = align(dec->base.height, VL_MACROBLOCK_HEIGHT); 1353bf215546Sopenharmony_ci 1354bf215546Sopenharmony_ci unsigned max_references = dec->base.max_references + 1; 1355bf215546Sopenharmony_ci 1356bf215546Sopenharmony_ci if (dec->base.width * dec->base.height >= 4096 * 2000) 1357bf215546Sopenharmony_ci max_references = MAX2(max_references, 8); 1358bf215546Sopenharmony_ci else 1359bf215546Sopenharmony_ci max_references = MAX2(max_references, 17); 1360bf215546Sopenharmony_ci 1361bf215546Sopenharmony_ci width = align(width, 16); 1362bf215546Sopenharmony_ci height = align(height, 16); 1363bf215546Sopenharmony_ci return ((width + 255) / 16) * ((height + 255) / 16) * 16 * max_references + 52 * 1024; 1364bf215546Sopenharmony_ci} 1365bf215546Sopenharmony_ci 1366bf215546Sopenharmony_cistatic unsigned calc_ctx_size_h265_main10(struct radeon_decoder *dec, 1367bf215546Sopenharmony_ci struct pipe_h265_picture_desc *pic) 1368bf215546Sopenharmony_ci{ 1369bf215546Sopenharmony_ci unsigned log2_ctb_size, width_in_ctb, height_in_ctb, num_16x16_block_per_ctb; 1370bf215546Sopenharmony_ci unsigned context_buffer_size_per_ctb_row, cm_buffer_size, max_mb_address, db_left_tile_pxl_size; 1371bf215546Sopenharmony_ci unsigned db_left_tile_ctx_size = 4096 / 16 * (32 + 16 * 4); 1372bf215546Sopenharmony_ci 1373bf215546Sopenharmony_ci unsigned width = align(dec->base.width, VL_MACROBLOCK_WIDTH); 1374bf215546Sopenharmony_ci unsigned height = align(dec->base.height, VL_MACROBLOCK_HEIGHT); 1375bf215546Sopenharmony_ci unsigned coeff_10bit = 1376bf215546Sopenharmony_ci (pic->pps->sps->bit_depth_luma_minus8 || pic->pps->sps->bit_depth_chroma_minus8) ? 2 : 1; 1377bf215546Sopenharmony_ci 1378bf215546Sopenharmony_ci unsigned max_references = dec->base.max_references + 1; 1379bf215546Sopenharmony_ci 1380bf215546Sopenharmony_ci if (dec->base.width * dec->base.height >= 4096 * 2000) 1381bf215546Sopenharmony_ci max_references = MAX2(max_references, 8); 1382bf215546Sopenharmony_ci else 1383bf215546Sopenharmony_ci max_references = MAX2(max_references, 17); 1384bf215546Sopenharmony_ci 1385bf215546Sopenharmony_ci log2_ctb_size = pic->pps->sps->log2_min_luma_coding_block_size_minus3 + 3 + 1386bf215546Sopenharmony_ci pic->pps->sps->log2_diff_max_min_luma_coding_block_size; 1387bf215546Sopenharmony_ci 1388bf215546Sopenharmony_ci width_in_ctb = (width + ((1 << log2_ctb_size) - 1)) >> log2_ctb_size; 1389bf215546Sopenharmony_ci height_in_ctb = (height + ((1 << log2_ctb_size) - 1)) >> log2_ctb_size; 1390bf215546Sopenharmony_ci 1391bf215546Sopenharmony_ci num_16x16_block_per_ctb = ((1 << log2_ctb_size) >> 4) * ((1 << log2_ctb_size) >> 4); 1392bf215546Sopenharmony_ci context_buffer_size_per_ctb_row = align(width_in_ctb * num_16x16_block_per_ctb * 16, 256); 1393bf215546Sopenharmony_ci max_mb_address = (unsigned)ceil(height * 8 / 2048.0); 1394bf215546Sopenharmony_ci 1395bf215546Sopenharmony_ci cm_buffer_size = max_references * context_buffer_size_per_ctb_row * height_in_ctb; 1396bf215546Sopenharmony_ci db_left_tile_pxl_size = coeff_10bit * (max_mb_address * 2 * 2048 + 1024); 1397bf215546Sopenharmony_ci 1398bf215546Sopenharmony_ci return cm_buffer_size + db_left_tile_ctx_size + db_left_tile_pxl_size; 1399bf215546Sopenharmony_ci} 1400bf215546Sopenharmony_ci 1401bf215546Sopenharmony_cistatic rvcn_dec_message_vc1_t get_vc1_msg(struct pipe_vc1_picture_desc *pic) 1402bf215546Sopenharmony_ci{ 1403bf215546Sopenharmony_ci rvcn_dec_message_vc1_t result; 1404bf215546Sopenharmony_ci 1405bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 1406bf215546Sopenharmony_ci switch (pic->base.profile) { 1407bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_VC1_SIMPLE: 1408bf215546Sopenharmony_ci result.profile = RDECODE_VC1_PROFILE_SIMPLE; 1409bf215546Sopenharmony_ci result.level = 1; 1410bf215546Sopenharmony_ci break; 1411bf215546Sopenharmony_ci 1412bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_VC1_MAIN: 1413bf215546Sopenharmony_ci result.profile = RDECODE_VC1_PROFILE_MAIN; 1414bf215546Sopenharmony_ci result.level = 2; 1415bf215546Sopenharmony_ci break; 1416bf215546Sopenharmony_ci 1417bf215546Sopenharmony_ci case PIPE_VIDEO_PROFILE_VC1_ADVANCED: 1418bf215546Sopenharmony_ci result.profile = RDECODE_VC1_PROFILE_ADVANCED; 1419bf215546Sopenharmony_ci result.level = 4; 1420bf215546Sopenharmony_ci break; 1421bf215546Sopenharmony_ci 1422bf215546Sopenharmony_ci default: 1423bf215546Sopenharmony_ci assert(0); 1424bf215546Sopenharmony_ci } 1425bf215546Sopenharmony_ci 1426bf215546Sopenharmony_ci result.sps_info_flags |= pic->postprocflag << 7; 1427bf215546Sopenharmony_ci result.sps_info_flags |= pic->pulldown << 6; 1428bf215546Sopenharmony_ci result.sps_info_flags |= pic->interlace << 5; 1429bf215546Sopenharmony_ci result.sps_info_flags |= pic->tfcntrflag << 4; 1430bf215546Sopenharmony_ci result.sps_info_flags |= pic->finterpflag << 3; 1431bf215546Sopenharmony_ci result.sps_info_flags |= pic->psf << 1; 1432bf215546Sopenharmony_ci 1433bf215546Sopenharmony_ci result.pps_info_flags |= pic->range_mapy_flag << 31; 1434bf215546Sopenharmony_ci result.pps_info_flags |= pic->range_mapy << 28; 1435bf215546Sopenharmony_ci result.pps_info_flags |= pic->range_mapuv_flag << 27; 1436bf215546Sopenharmony_ci result.pps_info_flags |= pic->range_mapuv << 24; 1437bf215546Sopenharmony_ci result.pps_info_flags |= pic->multires << 21; 1438bf215546Sopenharmony_ci result.pps_info_flags |= pic->maxbframes << 16; 1439bf215546Sopenharmony_ci result.pps_info_flags |= pic->overlap << 11; 1440bf215546Sopenharmony_ci result.pps_info_flags |= pic->quantizer << 9; 1441bf215546Sopenharmony_ci result.pps_info_flags |= pic->panscan_flag << 7; 1442bf215546Sopenharmony_ci result.pps_info_flags |= pic->refdist_flag << 6; 1443bf215546Sopenharmony_ci result.pps_info_flags |= pic->vstransform << 0; 1444bf215546Sopenharmony_ci 1445bf215546Sopenharmony_ci if (pic->base.profile != PIPE_VIDEO_PROFILE_VC1_SIMPLE) { 1446bf215546Sopenharmony_ci result.pps_info_flags |= pic->syncmarker << 20; 1447bf215546Sopenharmony_ci result.pps_info_flags |= pic->rangered << 19; 1448bf215546Sopenharmony_ci result.pps_info_flags |= pic->loopfilter << 5; 1449bf215546Sopenharmony_ci result.pps_info_flags |= pic->fastuvmc << 4; 1450bf215546Sopenharmony_ci result.pps_info_flags |= pic->extended_mv << 3; 1451bf215546Sopenharmony_ci result.pps_info_flags |= pic->extended_dmv << 8; 1452bf215546Sopenharmony_ci result.pps_info_flags |= pic->dquant << 1; 1453bf215546Sopenharmony_ci } 1454bf215546Sopenharmony_ci 1455bf215546Sopenharmony_ci result.chroma_format = 1; 1456bf215546Sopenharmony_ci 1457bf215546Sopenharmony_ci return result; 1458bf215546Sopenharmony_ci} 1459bf215546Sopenharmony_ci 1460bf215546Sopenharmony_cistatic uint32_t get_ref_pic_idx(struct radeon_decoder *dec, struct pipe_video_buffer *ref) 1461bf215546Sopenharmony_ci{ 1462bf215546Sopenharmony_ci uint32_t min = MAX2(dec->frame_number, NUM_MPEG2_REFS) - NUM_MPEG2_REFS; 1463bf215546Sopenharmony_ci uint32_t max = MAX2(dec->frame_number, 1) - 1; 1464bf215546Sopenharmony_ci uintptr_t frame; 1465bf215546Sopenharmony_ci 1466bf215546Sopenharmony_ci /* seems to be the most sane fallback */ 1467bf215546Sopenharmony_ci if (!ref) 1468bf215546Sopenharmony_ci return max; 1469bf215546Sopenharmony_ci 1470bf215546Sopenharmony_ci /* get the frame number from the associated data */ 1471bf215546Sopenharmony_ci frame = (uintptr_t)vl_video_buffer_get_associated_data(ref, &dec->base); 1472bf215546Sopenharmony_ci 1473bf215546Sopenharmony_ci /* limit the frame number to a valid range */ 1474bf215546Sopenharmony_ci return MAX2(MIN2(frame, max), min); 1475bf215546Sopenharmony_ci} 1476bf215546Sopenharmony_ci 1477bf215546Sopenharmony_cistatic rvcn_dec_message_mpeg2_vld_t get_mpeg2_msg(struct radeon_decoder *dec, 1478bf215546Sopenharmony_ci struct pipe_mpeg12_picture_desc *pic) 1479bf215546Sopenharmony_ci{ 1480bf215546Sopenharmony_ci const int *zscan = pic->alternate_scan ? vl_zscan_alternate : vl_zscan_normal; 1481bf215546Sopenharmony_ci rvcn_dec_message_mpeg2_vld_t result; 1482bf215546Sopenharmony_ci unsigned i; 1483bf215546Sopenharmony_ci 1484bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 1485bf215546Sopenharmony_ci result.decoded_pic_idx = dec->frame_number; 1486bf215546Sopenharmony_ci 1487bf215546Sopenharmony_ci result.forward_ref_pic_idx = get_ref_pic_idx(dec, pic->ref[0]); 1488bf215546Sopenharmony_ci result.backward_ref_pic_idx = get_ref_pic_idx(dec, pic->ref[1]); 1489bf215546Sopenharmony_ci 1490bf215546Sopenharmony_ci if (pic->intra_matrix) { 1491bf215546Sopenharmony_ci result.load_intra_quantiser_matrix = 1; 1492bf215546Sopenharmony_ci for (i = 0; i < 64; ++i) { 1493bf215546Sopenharmony_ci result.intra_quantiser_matrix[i] = pic->intra_matrix[zscan[i]]; 1494bf215546Sopenharmony_ci } 1495bf215546Sopenharmony_ci } 1496bf215546Sopenharmony_ci if (pic->non_intra_matrix) { 1497bf215546Sopenharmony_ci result.load_nonintra_quantiser_matrix = 1; 1498bf215546Sopenharmony_ci for (i = 0; i < 64; ++i) { 1499bf215546Sopenharmony_ci result.nonintra_quantiser_matrix[i] = pic->non_intra_matrix[zscan[i]]; 1500bf215546Sopenharmony_ci } 1501bf215546Sopenharmony_ci } 1502bf215546Sopenharmony_ci 1503bf215546Sopenharmony_ci result.profile_and_level_indication = 0; 1504bf215546Sopenharmony_ci result.chroma_format = 0x1; 1505bf215546Sopenharmony_ci 1506bf215546Sopenharmony_ci result.picture_coding_type = pic->picture_coding_type; 1507bf215546Sopenharmony_ci result.f_code[0][0] = pic->f_code[0][0] + 1; 1508bf215546Sopenharmony_ci result.f_code[0][1] = pic->f_code[0][1] + 1; 1509bf215546Sopenharmony_ci result.f_code[1][0] = pic->f_code[1][0] + 1; 1510bf215546Sopenharmony_ci result.f_code[1][1] = pic->f_code[1][1] + 1; 1511bf215546Sopenharmony_ci result.intra_dc_precision = pic->intra_dc_precision; 1512bf215546Sopenharmony_ci result.pic_structure = pic->picture_structure; 1513bf215546Sopenharmony_ci result.top_field_first = pic->top_field_first; 1514bf215546Sopenharmony_ci result.frame_pred_frame_dct = pic->frame_pred_frame_dct; 1515bf215546Sopenharmony_ci result.concealment_motion_vectors = pic->concealment_motion_vectors; 1516bf215546Sopenharmony_ci result.q_scale_type = pic->q_scale_type; 1517bf215546Sopenharmony_ci result.intra_vlc_format = pic->intra_vlc_format; 1518bf215546Sopenharmony_ci result.alternate_scan = pic->alternate_scan; 1519bf215546Sopenharmony_ci 1520bf215546Sopenharmony_ci return result; 1521bf215546Sopenharmony_ci} 1522bf215546Sopenharmony_ci 1523bf215546Sopenharmony_cistatic rvcn_dec_message_mpeg4_asp_vld_t get_mpeg4_msg(struct radeon_decoder *dec, 1524bf215546Sopenharmony_ci struct pipe_mpeg4_picture_desc *pic) 1525bf215546Sopenharmony_ci{ 1526bf215546Sopenharmony_ci rvcn_dec_message_mpeg4_asp_vld_t result; 1527bf215546Sopenharmony_ci unsigned i; 1528bf215546Sopenharmony_ci 1529bf215546Sopenharmony_ci memset(&result, 0, sizeof(result)); 1530bf215546Sopenharmony_ci result.decoded_pic_idx = dec->frame_number; 1531bf215546Sopenharmony_ci 1532bf215546Sopenharmony_ci result.forward_ref_pic_idx = get_ref_pic_idx(dec, pic->ref[0]); 1533bf215546Sopenharmony_ci result.backward_ref_pic_idx = get_ref_pic_idx(dec, pic->ref[1]); 1534bf215546Sopenharmony_ci 1535bf215546Sopenharmony_ci result.variant_type = 0; 1536bf215546Sopenharmony_ci result.profile_and_level_indication = 0xF0; 1537bf215546Sopenharmony_ci 1538bf215546Sopenharmony_ci result.video_object_layer_verid = 0x5; 1539bf215546Sopenharmony_ci result.video_object_layer_shape = 0x0; 1540bf215546Sopenharmony_ci 1541bf215546Sopenharmony_ci result.video_object_layer_width = dec->base.width; 1542bf215546Sopenharmony_ci result.video_object_layer_height = dec->base.height; 1543bf215546Sopenharmony_ci 1544bf215546Sopenharmony_ci result.vop_time_increment_resolution = pic->vop_time_increment_resolution; 1545bf215546Sopenharmony_ci 1546bf215546Sopenharmony_ci result.short_video_header = pic->short_video_header; 1547bf215546Sopenharmony_ci result.interlaced = pic->interlaced; 1548bf215546Sopenharmony_ci result.load_intra_quant_mat = 1; 1549bf215546Sopenharmony_ci result.load_nonintra_quant_mat = 1; 1550bf215546Sopenharmony_ci result.quarter_sample = pic->quarter_sample; 1551bf215546Sopenharmony_ci result.complexity_estimation_disable = 1; 1552bf215546Sopenharmony_ci result.resync_marker_disable = pic->resync_marker_disable; 1553bf215546Sopenharmony_ci result.newpred_enable = 0; 1554bf215546Sopenharmony_ci result.reduced_resolution_vop_enable = 0; 1555bf215546Sopenharmony_ci 1556bf215546Sopenharmony_ci result.quant_type = pic->quant_type; 1557bf215546Sopenharmony_ci 1558bf215546Sopenharmony_ci for (i = 0; i < 64; ++i) { 1559bf215546Sopenharmony_ci result.intra_quant_mat[i] = pic->intra_matrix[vl_zscan_normal[i]]; 1560bf215546Sopenharmony_ci result.nonintra_quant_mat[i] = pic->non_intra_matrix[vl_zscan_normal[i]]; 1561bf215546Sopenharmony_ci } 1562bf215546Sopenharmony_ci 1563bf215546Sopenharmony_ci return result; 1564bf215546Sopenharmony_ci} 1565bf215546Sopenharmony_ci 1566bf215546Sopenharmony_cistatic void rvcn_dec_message_create(struct radeon_decoder *dec) 1567bf215546Sopenharmony_ci{ 1568bf215546Sopenharmony_ci rvcn_dec_message_header_t *header = dec->msg; 1569bf215546Sopenharmony_ci rvcn_dec_message_create_t *create = dec->msg + sizeof(rvcn_dec_message_header_t); 1570bf215546Sopenharmony_ci unsigned sizes = sizeof(rvcn_dec_message_header_t) + sizeof(rvcn_dec_message_create_t); 1571bf215546Sopenharmony_ci 1572bf215546Sopenharmony_ci memset(dec->msg, 0, sizes); 1573bf215546Sopenharmony_ci header->header_size = sizeof(rvcn_dec_message_header_t); 1574bf215546Sopenharmony_ci header->total_size = sizes; 1575bf215546Sopenharmony_ci header->num_buffers = 1; 1576bf215546Sopenharmony_ci header->msg_type = RDECODE_MSG_CREATE; 1577bf215546Sopenharmony_ci header->stream_handle = dec->stream_handle; 1578bf215546Sopenharmony_ci header->status_report_feedback_number = 0; 1579bf215546Sopenharmony_ci 1580bf215546Sopenharmony_ci header->index[0].message_id = RDECODE_MESSAGE_CREATE; 1581bf215546Sopenharmony_ci header->index[0].offset = sizeof(rvcn_dec_message_header_t); 1582bf215546Sopenharmony_ci header->index[0].size = sizeof(rvcn_dec_message_create_t); 1583bf215546Sopenharmony_ci header->index[0].filled = 0; 1584bf215546Sopenharmony_ci 1585bf215546Sopenharmony_ci create->stream_type = dec->stream_type; 1586bf215546Sopenharmony_ci create->session_flags = 0; 1587bf215546Sopenharmony_ci create->width_in_samples = dec->base.width; 1588bf215546Sopenharmony_ci create->height_in_samples = dec->base.height; 1589bf215546Sopenharmony_ci} 1590bf215546Sopenharmony_ci 1591bf215546Sopenharmony_cistatic unsigned rvcn_dec_dynamic_dpb_t2_message(struct radeon_decoder *dec, rvcn_dec_message_decode_t *decode, 1592bf215546Sopenharmony_ci rvcn_dec_message_dynamic_dpb_t2_t *dynamic_dpb_t2, bool encrypted) 1593bf215546Sopenharmony_ci{ 1594bf215546Sopenharmony_ci struct rvcn_dec_dynamic_dpb_t2 *dpb = NULL, *dummy = NULL; 1595bf215546Sopenharmony_ci unsigned width, height, size; 1596bf215546Sopenharmony_ci uint64_t addr; 1597bf215546Sopenharmony_ci int i; 1598bf215546Sopenharmony_ci 1599bf215546Sopenharmony_ci width = align(decode->width_in_samples, dec->db_alignment); 1600bf215546Sopenharmony_ci height = align(decode->height_in_samples, dec->db_alignment); 1601bf215546Sopenharmony_ci size = align((width * height * 3) / 2, 256); 1602bf215546Sopenharmony_ci if (dec->ref_codec.bts == CODEC_10_BITS) 1603bf215546Sopenharmony_ci size = size * 3 / 2; 1604bf215546Sopenharmony_ci 1605bf215546Sopenharmony_ci list_for_each_entry_safe(struct rvcn_dec_dynamic_dpb_t2, d, &dec->dpb_ref_list, list) { 1606bf215546Sopenharmony_ci for (i = 0; i < dec->ref_codec.ref_size; ++i) { 1607bf215546Sopenharmony_ci if (((dec->ref_codec.ref_list[i] & 0x7f) != 0x7f) && (d->index == (dec->ref_codec.ref_list[i] & 0x7f))) { 1608bf215546Sopenharmony_ci if (!dummy) 1609bf215546Sopenharmony_ci dummy = d; 1610bf215546Sopenharmony_ci 1611bf215546Sopenharmony_ci addr = dec->ws->buffer_get_virtual_address(d->dpb.res->buf); 1612bf215546Sopenharmony_ci if (!addr && dummy) { 1613bf215546Sopenharmony_ci RVID_ERR("Ref list from application is incorrect, using dummy buffer instead.\n"); 1614bf215546Sopenharmony_ci addr = dec->ws->buffer_get_virtual_address(dummy->dpb.res->buf); 1615bf215546Sopenharmony_ci } 1616bf215546Sopenharmony_ci dynamic_dpb_t2->dpbAddrLo[i] = addr; 1617bf215546Sopenharmony_ci dynamic_dpb_t2->dpbAddrHi[i] = addr >> 32; 1618bf215546Sopenharmony_ci ++dynamic_dpb_t2->dpbArraySize; 1619bf215546Sopenharmony_ci break; 1620bf215546Sopenharmony_ci } 1621bf215546Sopenharmony_ci } 1622bf215546Sopenharmony_ci if (i == dec->ref_codec.ref_size) { 1623bf215546Sopenharmony_ci if (d->dpb.res->b.b.width0 * d->dpb.res->b.b.height0 != size) { 1624bf215546Sopenharmony_ci list_del(&d->list); 1625bf215546Sopenharmony_ci list_addtail(&d->list, &dec->dpb_unref_list); 1626bf215546Sopenharmony_ci } else { 1627bf215546Sopenharmony_ci d->index = 0x7f; 1628bf215546Sopenharmony_ci } 1629bf215546Sopenharmony_ci } 1630bf215546Sopenharmony_ci } 1631bf215546Sopenharmony_ci 1632bf215546Sopenharmony_ci list_for_each_entry_safe(struct rvcn_dec_dynamic_dpb_t2, d, &dec->dpb_ref_list, list) { 1633bf215546Sopenharmony_ci if (d->dpb.res->b.b.width0 * d->dpb.res->b.b.height0 == size && d->index == dec->ref_codec.index) { 1634bf215546Sopenharmony_ci dpb = d; 1635bf215546Sopenharmony_ci break; 1636bf215546Sopenharmony_ci } 1637bf215546Sopenharmony_ci } 1638bf215546Sopenharmony_ci 1639bf215546Sopenharmony_ci if (!dpb) { 1640bf215546Sopenharmony_ci list_for_each_entry_safe(struct rvcn_dec_dynamic_dpb_t2, d, &dec->dpb_ref_list, list) { 1641bf215546Sopenharmony_ci if (d->index == 0x7f) { 1642bf215546Sopenharmony_ci d->index = dec->ref_codec.index; 1643bf215546Sopenharmony_ci dpb = d; 1644bf215546Sopenharmony_ci break; 1645bf215546Sopenharmony_ci } 1646bf215546Sopenharmony_ci } 1647bf215546Sopenharmony_ci } 1648bf215546Sopenharmony_ci 1649bf215546Sopenharmony_ci list_for_each_entry_safe(struct rvcn_dec_dynamic_dpb_t2, d, &dec->dpb_unref_list, list) { 1650bf215546Sopenharmony_ci list_del(&d->list); 1651bf215546Sopenharmony_ci si_vid_destroy_buffer(&d->dpb); 1652bf215546Sopenharmony_ci FREE(d); 1653bf215546Sopenharmony_ci } 1654bf215546Sopenharmony_ci 1655bf215546Sopenharmony_ci if (!dpb) { 1656bf215546Sopenharmony_ci bool r; 1657bf215546Sopenharmony_ci dpb = CALLOC_STRUCT(rvcn_dec_dynamic_dpb_t2); 1658bf215546Sopenharmony_ci if (!dpb) 1659bf215546Sopenharmony_ci return 1; 1660bf215546Sopenharmony_ci dpb->index = dec->ref_codec.index; 1661bf215546Sopenharmony_ci if (encrypted) 1662bf215546Sopenharmony_ci r = si_vid_create_tmz_buffer(dec->screen, &dpb->dpb, size, PIPE_USAGE_DEFAULT); 1663bf215546Sopenharmony_ci else 1664bf215546Sopenharmony_ci r = si_vid_create_buffer(dec->screen, &dpb->dpb, size, PIPE_USAGE_DEFAULT); 1665bf215546Sopenharmony_ci assert(encrypted == (bool)(dpb->dpb.res->flags & RADEON_FLAG_ENCRYPTED)); 1666bf215546Sopenharmony_ci 1667bf215546Sopenharmony_ci if (!r) { 1668bf215546Sopenharmony_ci RVID_ERR("Can't allocated dpb buffer.\n"); 1669bf215546Sopenharmony_ci FREE(dpb); 1670bf215546Sopenharmony_ci return 1; 1671bf215546Sopenharmony_ci } 1672bf215546Sopenharmony_ci list_addtail(&dpb->list, &dec->dpb_ref_list); 1673bf215546Sopenharmony_ci } 1674bf215546Sopenharmony_ci 1675bf215546Sopenharmony_ci dec->ws->cs_add_buffer(&dec->cs, dpb->dpb.res->buf, 1676bf215546Sopenharmony_ci RADEON_USAGE_READWRITE | RADEON_USAGE_SYNCHRONIZED, RADEON_DOMAIN_VRAM); 1677bf215546Sopenharmony_ci addr = dec->ws->buffer_get_virtual_address(dpb->dpb.res->buf); 1678bf215546Sopenharmony_ci dynamic_dpb_t2->dpbCurrLo = addr; 1679bf215546Sopenharmony_ci dynamic_dpb_t2->dpbCurrHi = addr >> 32; 1680bf215546Sopenharmony_ci 1681bf215546Sopenharmony_ci decode->decode_flags = 1; 1682bf215546Sopenharmony_ci dynamic_dpb_t2->dpbConfigFlags = 0; 1683bf215546Sopenharmony_ci dynamic_dpb_t2->dpbLumaPitch = align(decode->width_in_samples, dec->db_alignment); 1684bf215546Sopenharmony_ci dynamic_dpb_t2->dpbLumaAlignedHeight = align(decode->height_in_samples, dec->db_alignment); 1685bf215546Sopenharmony_ci dynamic_dpb_t2->dpbLumaAlignedSize = dynamic_dpb_t2->dpbLumaPitch * 1686bf215546Sopenharmony_ci dynamic_dpb_t2->dpbLumaAlignedHeight; 1687bf215546Sopenharmony_ci dynamic_dpb_t2->dpbChromaPitch = dynamic_dpb_t2->dpbLumaPitch >> 1; 1688bf215546Sopenharmony_ci dynamic_dpb_t2->dpbChromaAlignedHeight = dynamic_dpb_t2->dpbLumaAlignedHeight >> 1; 1689bf215546Sopenharmony_ci dynamic_dpb_t2->dpbChromaAlignedSize = dynamic_dpb_t2->dpbChromaPitch * 1690bf215546Sopenharmony_ci dynamic_dpb_t2->dpbChromaAlignedHeight * 2; 1691bf215546Sopenharmony_ci 1692bf215546Sopenharmony_ci if (dec->ref_codec.bts == CODEC_10_BITS) { 1693bf215546Sopenharmony_ci dynamic_dpb_t2->dpbLumaAlignedSize = dynamic_dpb_t2->dpbLumaAlignedSize * 3 / 2; 1694bf215546Sopenharmony_ci dynamic_dpb_t2->dpbChromaAlignedSize = dynamic_dpb_t2->dpbChromaAlignedSize * 3 / 2; 1695bf215546Sopenharmony_ci } 1696bf215546Sopenharmony_ci 1697bf215546Sopenharmony_ci return 0; 1698bf215546Sopenharmony_ci} 1699bf215546Sopenharmony_ci 1700bf215546Sopenharmony_cistatic struct pb_buffer *rvcn_dec_message_decode(struct radeon_decoder *dec, 1701bf215546Sopenharmony_ci struct pipe_video_buffer *target, 1702bf215546Sopenharmony_ci struct pipe_picture_desc *picture) 1703bf215546Sopenharmony_ci{ 1704bf215546Sopenharmony_ci DECRYPT_PARAMETERS *decrypt = (DECRYPT_PARAMETERS *)picture->decrypt_key; 1705bf215546Sopenharmony_ci bool encrypted = (DECRYPT_PARAMETERS *)picture->protected_playback; 1706bf215546Sopenharmony_ci struct si_texture *luma = (struct si_texture *)((struct vl_video_buffer *)target)->resources[0]; 1707bf215546Sopenharmony_ci struct si_texture *chroma = 1708bf215546Sopenharmony_ci (struct si_texture *)((struct vl_video_buffer *)target)->resources[1]; 1709bf215546Sopenharmony_ci ASSERTED struct si_screen *sscreen = (struct si_screen *)dec->screen; 1710bf215546Sopenharmony_ci rvcn_dec_message_header_t *header; 1711bf215546Sopenharmony_ci rvcn_dec_message_index_t *index_codec; 1712bf215546Sopenharmony_ci rvcn_dec_message_index_t *index_drm = NULL; 1713bf215546Sopenharmony_ci rvcn_dec_message_index_t *index_dynamic_dpb = NULL; 1714bf215546Sopenharmony_ci rvcn_dec_message_decode_t *decode; 1715bf215546Sopenharmony_ci unsigned sizes = 0, offset_decode, offset_codec; 1716bf215546Sopenharmony_ci unsigned offset_drm = 0, offset_dynamic_dpb = 0; 1717bf215546Sopenharmony_ci void *codec; 1718bf215546Sopenharmony_ci rvcn_dec_message_drm_t *drm = NULL; 1719bf215546Sopenharmony_ci rvcn_dec_message_dynamic_dpb_t *dynamic_dpb = NULL; 1720bf215546Sopenharmony_ci rvcn_dec_message_dynamic_dpb_t2_t *dynamic_dpb_t2 = NULL; 1721bf215546Sopenharmony_ci 1722bf215546Sopenharmony_ci header = dec->msg; 1723bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_header_t); 1724bf215546Sopenharmony_ci 1725bf215546Sopenharmony_ci index_codec = (void*)header + sizes; 1726bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_index_t); 1727bf215546Sopenharmony_ci 1728bf215546Sopenharmony_ci if (encrypted) { 1729bf215546Sopenharmony_ci index_drm = (void*)header + sizes; 1730bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_index_t); 1731bf215546Sopenharmony_ci } 1732bf215546Sopenharmony_ci 1733bf215546Sopenharmony_ci if (dec->dpb_type >= DPB_DYNAMIC_TIER_1) { 1734bf215546Sopenharmony_ci index_dynamic_dpb = (void*)header + sizes; 1735bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_index_t); 1736bf215546Sopenharmony_ci } 1737bf215546Sopenharmony_ci 1738bf215546Sopenharmony_ci offset_decode = sizes; 1739bf215546Sopenharmony_ci decode = (void*)header + sizes; 1740bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_decode_t); 1741bf215546Sopenharmony_ci 1742bf215546Sopenharmony_ci if (encrypted) { 1743bf215546Sopenharmony_ci offset_drm = sizes; 1744bf215546Sopenharmony_ci drm = (void*)header + sizes; 1745bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_drm_t); 1746bf215546Sopenharmony_ci } 1747bf215546Sopenharmony_ci 1748bf215546Sopenharmony_ci if (dec->dpb_type >= DPB_DYNAMIC_TIER_1) { 1749bf215546Sopenharmony_ci offset_dynamic_dpb = sizes; 1750bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_1) { 1751bf215546Sopenharmony_ci dynamic_dpb = (void*)header + sizes; 1752bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_dynamic_dpb_t); 1753bf215546Sopenharmony_ci } 1754bf215546Sopenharmony_ci else if (dec->dpb_type == DPB_DYNAMIC_TIER_2) { 1755bf215546Sopenharmony_ci dynamic_dpb_t2 = (void*)header + sizes; 1756bf215546Sopenharmony_ci sizes += sizeof(rvcn_dec_message_dynamic_dpb_t2_t); 1757bf215546Sopenharmony_ci } 1758bf215546Sopenharmony_ci } 1759bf215546Sopenharmony_ci 1760bf215546Sopenharmony_ci offset_codec = sizes; 1761bf215546Sopenharmony_ci codec = (void*)header + sizes; 1762bf215546Sopenharmony_ci 1763bf215546Sopenharmony_ci memset(dec->msg, 0, sizes); 1764bf215546Sopenharmony_ci header->header_size = sizeof(rvcn_dec_message_header_t); 1765bf215546Sopenharmony_ci header->total_size = sizes; 1766bf215546Sopenharmony_ci header->msg_type = RDECODE_MSG_DECODE; 1767bf215546Sopenharmony_ci header->stream_handle = dec->stream_handle; 1768bf215546Sopenharmony_ci header->status_report_feedback_number = dec->frame_number; 1769bf215546Sopenharmony_ci 1770bf215546Sopenharmony_ci header->index[0].message_id = RDECODE_MESSAGE_DECODE; 1771bf215546Sopenharmony_ci header->index[0].offset = offset_decode; 1772bf215546Sopenharmony_ci header->index[0].size = sizeof(rvcn_dec_message_decode_t); 1773bf215546Sopenharmony_ci header->index[0].filled = 0; 1774bf215546Sopenharmony_ci header->num_buffers = 1; 1775bf215546Sopenharmony_ci 1776bf215546Sopenharmony_ci index_codec->offset = offset_codec; 1777bf215546Sopenharmony_ci index_codec->size = sizeof(rvcn_dec_message_avc_t); 1778bf215546Sopenharmony_ci index_codec->filled = 0; 1779bf215546Sopenharmony_ci ++header->num_buffers; 1780bf215546Sopenharmony_ci 1781bf215546Sopenharmony_ci if (encrypted) { 1782bf215546Sopenharmony_ci index_drm->message_id = RDECODE_MESSAGE_DRM; 1783bf215546Sopenharmony_ci index_drm->offset = offset_drm; 1784bf215546Sopenharmony_ci index_drm->size = sizeof(rvcn_dec_message_drm_t); 1785bf215546Sopenharmony_ci index_drm->filled = 0; 1786bf215546Sopenharmony_ci ++header->num_buffers; 1787bf215546Sopenharmony_ci } 1788bf215546Sopenharmony_ci 1789bf215546Sopenharmony_ci if (dec->dpb_type >= DPB_DYNAMIC_TIER_1) { 1790bf215546Sopenharmony_ci index_dynamic_dpb->message_id = RDECODE_MESSAGE_DYNAMIC_DPB; 1791bf215546Sopenharmony_ci index_dynamic_dpb->offset = offset_dynamic_dpb; 1792bf215546Sopenharmony_ci index_dynamic_dpb->filled = 0; 1793bf215546Sopenharmony_ci ++header->num_buffers; 1794bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_1) 1795bf215546Sopenharmony_ci index_dynamic_dpb->size = sizeof(rvcn_dec_message_dynamic_dpb_t); 1796bf215546Sopenharmony_ci else if (dec->dpb_type == DPB_DYNAMIC_TIER_2) 1797bf215546Sopenharmony_ci index_dynamic_dpb->size = sizeof(rvcn_dec_message_dynamic_dpb_t2_t); 1798bf215546Sopenharmony_ci } 1799bf215546Sopenharmony_ci 1800bf215546Sopenharmony_ci decode->stream_type = dec->stream_type; 1801bf215546Sopenharmony_ci decode->decode_flags = 0; 1802bf215546Sopenharmony_ci decode->width_in_samples = dec->base.width; 1803bf215546Sopenharmony_ci decode->height_in_samples = dec->base.height; 1804bf215546Sopenharmony_ci 1805bf215546Sopenharmony_ci decode->bsd_size = align(dec->bs_size, 128); 1806bf215546Sopenharmony_ci 1807bf215546Sopenharmony_ci if (!dec->dpb.res && dec->dpb_type != DPB_DYNAMIC_TIER_2) { 1808bf215546Sopenharmony_ci bool r; 1809bf215546Sopenharmony_ci if (dec->dpb_size) { 1810bf215546Sopenharmony_ci if (encrypted) { 1811bf215546Sopenharmony_ci r = si_vid_create_tmz_buffer(dec->screen, &dec->dpb, dec->dpb_size, PIPE_USAGE_DEFAULT); 1812bf215546Sopenharmony_ci } else { 1813bf215546Sopenharmony_ci r = si_vid_create_buffer(dec->screen, &dec->dpb, dec->dpb_size, PIPE_USAGE_DEFAULT); 1814bf215546Sopenharmony_ci } 1815bf215546Sopenharmony_ci assert(encrypted == (bool)(dec->dpb.res->flags & RADEON_FLAG_ENCRYPTED)); 1816bf215546Sopenharmony_ci if (!r) { 1817bf215546Sopenharmony_ci RVID_ERR("Can't allocated dpb.\n"); 1818bf215546Sopenharmony_ci return NULL; 1819bf215546Sopenharmony_ci } 1820bf215546Sopenharmony_ci si_vid_clear_buffer(dec->base.context, &dec->dpb); 1821bf215546Sopenharmony_ci } 1822bf215546Sopenharmony_ci } 1823bf215546Sopenharmony_ci 1824bf215546Sopenharmony_ci if (!dec->ctx.res) { 1825bf215546Sopenharmony_ci enum pipe_video_format fmt = u_reduce_video_profile(picture->profile); 1826bf215546Sopenharmony_ci if (dec->stream_type == RDECODE_CODEC_H264_PERF) { 1827bf215546Sopenharmony_ci unsigned ctx_size = calc_ctx_size_h264_perf(dec); 1828bf215546Sopenharmony_ci bool r; 1829bf215546Sopenharmony_ci if (encrypted && dec->tmz_ctx) { 1830bf215546Sopenharmony_ci r = si_vid_create_tmz_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT); 1831bf215546Sopenharmony_ci } else { 1832bf215546Sopenharmony_ci r = si_vid_create_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT); 1833bf215546Sopenharmony_ci } 1834bf215546Sopenharmony_ci assert((encrypted && dec->tmz_ctx) == (bool)(dec->ctx.res->flags & RADEON_FLAG_ENCRYPTED)); 1835bf215546Sopenharmony_ci 1836bf215546Sopenharmony_ci if (!r) { 1837bf215546Sopenharmony_ci RVID_ERR("Can't allocated context buffer.\n"); 1838bf215546Sopenharmony_ci return NULL; 1839bf215546Sopenharmony_ci } 1840bf215546Sopenharmony_ci si_vid_clear_buffer(dec->base.context, &dec->ctx); 1841bf215546Sopenharmony_ci } else if (fmt == PIPE_VIDEO_FORMAT_VP9) { 1842bf215546Sopenharmony_ci unsigned ctx_size; 1843bf215546Sopenharmony_ci uint8_t *ptr; 1844bf215546Sopenharmony_ci bool r; 1845bf215546Sopenharmony_ci 1846bf215546Sopenharmony_ci /* default probability + probability data */ 1847bf215546Sopenharmony_ci ctx_size = 2304 * 5; 1848bf215546Sopenharmony_ci 1849bf215546Sopenharmony_ci if (((struct si_screen *)dec->screen)->info.family >= CHIP_RENOIR) { 1850bf215546Sopenharmony_ci /* SRE collocated context data */ 1851bf215546Sopenharmony_ci ctx_size += 32 * 2 * 128 * 68; 1852bf215546Sopenharmony_ci /* SMP collocated context data */ 1853bf215546Sopenharmony_ci ctx_size += 9 * 64 * 2 * 128 * 68; 1854bf215546Sopenharmony_ci /* SDB left tile pixel */ 1855bf215546Sopenharmony_ci ctx_size += 8 * 2 * 2 * 8192; 1856bf215546Sopenharmony_ci } else { 1857bf215546Sopenharmony_ci ctx_size += 32 * 2 * 64 * 64; 1858bf215546Sopenharmony_ci ctx_size += 9 * 64 * 2 * 64 * 64; 1859bf215546Sopenharmony_ci ctx_size += 8 * 2 * 4096; 1860bf215546Sopenharmony_ci } 1861bf215546Sopenharmony_ci 1862bf215546Sopenharmony_ci if (dec->base.profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2) 1863bf215546Sopenharmony_ci ctx_size += 8 * 2 * 4096; 1864bf215546Sopenharmony_ci 1865bf215546Sopenharmony_ci if (encrypted && dec->tmz_ctx) { 1866bf215546Sopenharmony_ci r = si_vid_create_tmz_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT); 1867bf215546Sopenharmony_ci } else { 1868bf215546Sopenharmony_ci r = si_vid_create_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT); 1869bf215546Sopenharmony_ci } 1870bf215546Sopenharmony_ci if (!r) { 1871bf215546Sopenharmony_ci RVID_ERR("Can't allocated context buffer.\n"); 1872bf215546Sopenharmony_ci return NULL; 1873bf215546Sopenharmony_ci } 1874bf215546Sopenharmony_ci si_vid_clear_buffer(dec->base.context, &dec->ctx); 1875bf215546Sopenharmony_ci 1876bf215546Sopenharmony_ci /* ctx needs probs table */ 1877bf215546Sopenharmony_ci ptr = dec->ws->buffer_map(dec->ws, dec->ctx.res->buf, &dec->cs, 1878bf215546Sopenharmony_ci PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY); 1879bf215546Sopenharmony_ci fill_probs_table(ptr); 1880bf215546Sopenharmony_ci dec->ws->buffer_unmap(dec->ws, dec->ctx.res->buf); 1881bf215546Sopenharmony_ci dec->bs_ptr = NULL; 1882bf215546Sopenharmony_ci } else if (fmt == PIPE_VIDEO_FORMAT_HEVC) { 1883bf215546Sopenharmony_ci unsigned ctx_size; 1884bf215546Sopenharmony_ci bool r; 1885bf215546Sopenharmony_ci if (dec->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) 1886bf215546Sopenharmony_ci ctx_size = calc_ctx_size_h265_main10(dec, (struct pipe_h265_picture_desc *)picture); 1887bf215546Sopenharmony_ci else 1888bf215546Sopenharmony_ci ctx_size = calc_ctx_size_h265_main(dec); 1889bf215546Sopenharmony_ci 1890bf215546Sopenharmony_ci if (encrypted && dec->tmz_ctx) { 1891bf215546Sopenharmony_ci r = si_vid_create_tmz_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT); 1892bf215546Sopenharmony_ci } else { 1893bf215546Sopenharmony_ci r = si_vid_create_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT); 1894bf215546Sopenharmony_ci } 1895bf215546Sopenharmony_ci if (!r) { 1896bf215546Sopenharmony_ci RVID_ERR("Can't allocated context buffer.\n"); 1897bf215546Sopenharmony_ci return NULL; 1898bf215546Sopenharmony_ci } 1899bf215546Sopenharmony_ci si_vid_clear_buffer(dec->base.context, &dec->ctx); 1900bf215546Sopenharmony_ci } 1901bf215546Sopenharmony_ci } 1902bf215546Sopenharmony_ci if (encrypted != dec->ws->cs_is_secure(&dec->cs)) { 1903bf215546Sopenharmony_ci dec->ws->cs_flush(&dec->cs, RADEON_FLUSH_TOGGLE_SECURE_SUBMISSION, NULL); 1904bf215546Sopenharmony_ci } 1905bf215546Sopenharmony_ci 1906bf215546Sopenharmony_ci decode->dpb_size = (dec->dpb_type != DPB_DYNAMIC_TIER_2) ? dec->dpb.res->buf->size : 0; 1907bf215546Sopenharmony_ci decode->dt_size = si_resource(((struct vl_video_buffer *)target)->resources[0])->buf->size + 1908bf215546Sopenharmony_ci si_resource(((struct vl_video_buffer *)target)->resources[1])->buf->size; 1909bf215546Sopenharmony_ci 1910bf215546Sopenharmony_ci decode->sct_size = 0; 1911bf215546Sopenharmony_ci decode->sc_coeff_size = 0; 1912bf215546Sopenharmony_ci 1913bf215546Sopenharmony_ci decode->sw_ctxt_size = RDECODE_SESSION_CONTEXT_SIZE; 1914bf215546Sopenharmony_ci decode->db_pitch = align(dec->base.width, dec->db_alignment); 1915bf215546Sopenharmony_ci 1916bf215546Sopenharmony_ci if (((struct si_screen*)dec->screen)->info.family >= CHIP_NAVI21 && 1917bf215546Sopenharmony_ci (dec->stream_type == RDECODE_CODEC_VP9 || dec->stream_type == RDECODE_CODEC_AV1 || 1918bf215546Sopenharmony_ci dec->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10)) 1919bf215546Sopenharmony_ci decode->db_aligned_height = align(dec->base.height, 64); 1920bf215546Sopenharmony_ci 1921bf215546Sopenharmony_ci decode->db_surf_tile_config = 0; 1922bf215546Sopenharmony_ci decode->db_array_mode = dec->addr_gfx_mode; 1923bf215546Sopenharmony_ci 1924bf215546Sopenharmony_ci decode->dt_pitch = luma->surface.u.gfx9.surf_pitch * luma->surface.blk_w; 1925bf215546Sopenharmony_ci decode->dt_uv_pitch = chroma->surface.u.gfx9.surf_pitch * chroma->surface.blk_w; 1926bf215546Sopenharmony_ci 1927bf215546Sopenharmony_ci if (luma->surface.meta_offset) { 1928bf215546Sopenharmony_ci RVID_ERR("DCC surfaces not supported.\n"); 1929bf215546Sopenharmony_ci return NULL; 1930bf215546Sopenharmony_ci } 1931bf215546Sopenharmony_ci 1932bf215546Sopenharmony_ci decode->dt_tiling_mode = 0; 1933bf215546Sopenharmony_ci decode->dt_swizzle_mode = luma->surface.u.gfx9.swizzle_mode; 1934bf215546Sopenharmony_ci decode->dt_array_mode = dec->addr_gfx_mode; 1935bf215546Sopenharmony_ci decode->dt_field_mode = ((struct vl_video_buffer *)target)->base.interlaced; 1936bf215546Sopenharmony_ci decode->dt_surf_tile_config = 0; 1937bf215546Sopenharmony_ci decode->dt_uv_surf_tile_config = 0; 1938bf215546Sopenharmony_ci 1939bf215546Sopenharmony_ci decode->dt_luma_top_offset = luma->surface.u.gfx9.surf_offset; 1940bf215546Sopenharmony_ci decode->dt_chroma_top_offset = chroma->surface.u.gfx9.surf_offset; 1941bf215546Sopenharmony_ci if (decode->dt_field_mode) { 1942bf215546Sopenharmony_ci decode->dt_luma_bottom_offset = 1943bf215546Sopenharmony_ci luma->surface.u.gfx9.surf_offset + luma->surface.u.gfx9.surf_slice_size; 1944bf215546Sopenharmony_ci decode->dt_chroma_bottom_offset = 1945bf215546Sopenharmony_ci chroma->surface.u.gfx9.surf_offset + chroma->surface.u.gfx9.surf_slice_size; 1946bf215546Sopenharmony_ci } else { 1947bf215546Sopenharmony_ci decode->dt_luma_bottom_offset = decode->dt_luma_top_offset; 1948bf215546Sopenharmony_ci decode->dt_chroma_bottom_offset = decode->dt_chroma_top_offset; 1949bf215546Sopenharmony_ci } 1950bf215546Sopenharmony_ci if (dec->stream_type == RDECODE_CODEC_AV1) 1951bf215546Sopenharmony_ci decode->db_pitch_uv = chroma->surface.u.gfx9.surf_pitch * chroma->surface.blk_w; 1952bf215546Sopenharmony_ci 1953bf215546Sopenharmony_ci if (encrypted) { 1954bf215546Sopenharmony_ci assert(sscreen->info.has_tmz_support); 1955bf215546Sopenharmony_ci set_drm_keys(drm, decrypt); 1956bf215546Sopenharmony_ci } 1957bf215546Sopenharmony_ci 1958bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_1) { 1959bf215546Sopenharmony_ci decode->decode_flags = 1; 1960bf215546Sopenharmony_ci dynamic_dpb->dpbArraySize = NUM_VP9_REFS + 1; 1961bf215546Sopenharmony_ci dynamic_dpb->dpbLumaPitch = align(decode->width_in_samples, dec->db_alignment); 1962bf215546Sopenharmony_ci dynamic_dpb->dpbLumaAlignedHeight = align(decode->height_in_samples, dec->db_alignment); 1963bf215546Sopenharmony_ci dynamic_dpb->dpbLumaAlignedSize = 1964bf215546Sopenharmony_ci dynamic_dpb->dpbLumaPitch * dynamic_dpb->dpbLumaAlignedHeight; 1965bf215546Sopenharmony_ci dynamic_dpb->dpbChromaPitch = dynamic_dpb->dpbLumaPitch >> 1; 1966bf215546Sopenharmony_ci dynamic_dpb->dpbChromaAlignedHeight = dynamic_dpb->dpbLumaAlignedHeight >> 1; 1967bf215546Sopenharmony_ci dynamic_dpb->dpbChromaAlignedSize = 1968bf215546Sopenharmony_ci dynamic_dpb->dpbChromaPitch * dynamic_dpb->dpbChromaAlignedHeight * 2; 1969bf215546Sopenharmony_ci dynamic_dpb->dpbReserved0[0] = dec->db_alignment; 1970bf215546Sopenharmony_ci 1971bf215546Sopenharmony_ci if (dec->base.profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2) { 1972bf215546Sopenharmony_ci dynamic_dpb->dpbLumaAlignedSize = dynamic_dpb->dpbLumaAlignedSize * 3 / 2; 1973bf215546Sopenharmony_ci dynamic_dpb->dpbChromaAlignedSize = dynamic_dpb->dpbChromaAlignedSize * 3 / 2; 1974bf215546Sopenharmony_ci } 1975bf215546Sopenharmony_ci } 1976bf215546Sopenharmony_ci 1977bf215546Sopenharmony_ci switch (u_reduce_video_profile(picture->profile)) { 1978bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG4_AVC: { 1979bf215546Sopenharmony_ci rvcn_dec_message_avc_t avc = get_h264_msg(dec, target, (struct pipe_h264_picture_desc *)picture); 1980bf215546Sopenharmony_ci memcpy(codec, (void *)&avc, sizeof(rvcn_dec_message_avc_t)); 1981bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_AVC; 1982bf215546Sopenharmony_ci break; 1983bf215546Sopenharmony_ci } 1984bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_HEVC: { 1985bf215546Sopenharmony_ci rvcn_dec_message_hevc_t hevc = 1986bf215546Sopenharmony_ci get_h265_msg(dec, target, (struct pipe_h265_picture_desc *)picture); 1987bf215546Sopenharmony_ci 1988bf215546Sopenharmony_ci memcpy(codec, (void *)&hevc, sizeof(rvcn_dec_message_hevc_t)); 1989bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_HEVC; 1990bf215546Sopenharmony_ci break; 1991bf215546Sopenharmony_ci } 1992bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_VC1: { 1993bf215546Sopenharmony_ci rvcn_dec_message_vc1_t vc1 = get_vc1_msg((struct pipe_vc1_picture_desc *)picture); 1994bf215546Sopenharmony_ci 1995bf215546Sopenharmony_ci memcpy(codec, (void *)&vc1, sizeof(rvcn_dec_message_vc1_t)); 1996bf215546Sopenharmony_ci if ((picture->profile == PIPE_VIDEO_PROFILE_VC1_SIMPLE) || 1997bf215546Sopenharmony_ci (picture->profile == PIPE_VIDEO_PROFILE_VC1_MAIN)) { 1998bf215546Sopenharmony_ci decode->width_in_samples = align(decode->width_in_samples, 16) / 16; 1999bf215546Sopenharmony_ci decode->height_in_samples = align(decode->height_in_samples, 16) / 16; 2000bf215546Sopenharmony_ci } 2001bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_VC1; 2002bf215546Sopenharmony_ci break; 2003bf215546Sopenharmony_ci } 2004bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG12: { 2005bf215546Sopenharmony_ci rvcn_dec_message_mpeg2_vld_t mpeg2 = 2006bf215546Sopenharmony_ci get_mpeg2_msg(dec, (struct pipe_mpeg12_picture_desc *)picture); 2007bf215546Sopenharmony_ci 2008bf215546Sopenharmony_ci memcpy(codec, (void *)&mpeg2, sizeof(rvcn_dec_message_mpeg2_vld_t)); 2009bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_MPEG2_VLD; 2010bf215546Sopenharmony_ci break; 2011bf215546Sopenharmony_ci } 2012bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG4: { 2013bf215546Sopenharmony_ci rvcn_dec_message_mpeg4_asp_vld_t mpeg4 = 2014bf215546Sopenharmony_ci get_mpeg4_msg(dec, (struct pipe_mpeg4_picture_desc *)picture); 2015bf215546Sopenharmony_ci 2016bf215546Sopenharmony_ci memcpy(codec, (void *)&mpeg4, sizeof(rvcn_dec_message_mpeg4_asp_vld_t)); 2017bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_MPEG4_ASP_VLD; 2018bf215546Sopenharmony_ci break; 2019bf215546Sopenharmony_ci } 2020bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_VP9: { 2021bf215546Sopenharmony_ci rvcn_dec_message_vp9_t vp9 = 2022bf215546Sopenharmony_ci get_vp9_msg(dec, target, (struct pipe_vp9_picture_desc *)picture); 2023bf215546Sopenharmony_ci 2024bf215546Sopenharmony_ci memcpy(codec, (void *)&vp9, sizeof(rvcn_dec_message_vp9_t)); 2025bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_VP9; 2026bf215546Sopenharmony_ci break; 2027bf215546Sopenharmony_ci } 2028bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_AV1: { 2029bf215546Sopenharmony_ci rvcn_dec_message_av1_t av1 = 2030bf215546Sopenharmony_ci get_av1_msg(dec, target, (struct pipe_av1_picture_desc *)picture); 2031bf215546Sopenharmony_ci 2032bf215546Sopenharmony_ci memcpy(codec, (void *)&av1, sizeof(rvcn_dec_message_av1_t)); 2033bf215546Sopenharmony_ci index_codec->message_id = RDECODE_MESSAGE_AV1; 2034bf215546Sopenharmony_ci 2035bf215546Sopenharmony_ci if (dec->ctx.res == NULL) { 2036bf215546Sopenharmony_ci unsigned frame_ctxt_size = dec->av1_version == RDECODE_AV1_VER_0 2037bf215546Sopenharmony_ci ? align(sizeof(rvcn_av1_frame_context_t), 2048) 2038bf215546Sopenharmony_ci : align(sizeof(rvcn_av1_vcn4_frame_context_t), 2048); 2039bf215546Sopenharmony_ci 2040bf215546Sopenharmony_ci unsigned ctx_size = (9 + 4) * frame_ctxt_size + 9 * 64 * 34 * 512 + 9 * 64 * 34 * 256 * 5; 2041bf215546Sopenharmony_ci int num_64x64_CTB_8k = 68; 2042bf215546Sopenharmony_ci int num_128x128_CTB_8k = 34; 2043bf215546Sopenharmony_ci int sdb_pitch_64x64 = align(32 * num_64x64_CTB_8k, 256) * 2; 2044bf215546Sopenharmony_ci int sdb_pitch_128x128 = align(32 * num_128x128_CTB_8k, 256) * 2; 2045bf215546Sopenharmony_ci int sdb_lf_size_ctb_64x64 = sdb_pitch_64x64 * (align(1728, 64) / 64); 2046bf215546Sopenharmony_ci int sdb_lf_size_ctb_128x128 = sdb_pitch_128x128 * (align(3008, 64) / 64); 2047bf215546Sopenharmony_ci int sdb_superres_size_ctb_64x64 = sdb_pitch_64x64 * (align(3232, 64) / 64); 2048bf215546Sopenharmony_ci int sdb_superres_size_ctb_128x128 = sdb_pitch_128x128 * (align(6208, 64) / 64); 2049bf215546Sopenharmony_ci int sdb_output_size_ctb_64x64 = sdb_pitch_64x64 * (align(1312, 64) / 64); 2050bf215546Sopenharmony_ci int sdb_output_size_ctb_128x128 = sdb_pitch_128x128 * (align(2336, 64) / 64); 2051bf215546Sopenharmony_ci int sdb_fg_avg_luma_size_ctb_64x64 = sdb_pitch_64x64 * (align(384, 64) / 64); 2052bf215546Sopenharmony_ci int sdb_fg_avg_luma_size_ctb_128x128 = sdb_pitch_128x128 * (align(640, 64) / 64); 2053bf215546Sopenharmony_ci uint8_t *ptr; 2054bf215546Sopenharmony_ci int i; 2055bf215546Sopenharmony_ci struct rvcn_av1_prob_funcs prob; 2056bf215546Sopenharmony_ci 2057bf215546Sopenharmony_ci if (dec->av1_version == RDECODE_AV1_VER_0) { 2058bf215546Sopenharmony_ci prob.init_mode_probs = rvcn_init_mode_probs; 2059bf215546Sopenharmony_ci prob.init_mv_probs = rvcn_av1_init_mv_probs; 2060bf215546Sopenharmony_ci prob.default_coef_probs = rvcn_av1_default_coef_probs; 2061bf215546Sopenharmony_ci } else { 2062bf215546Sopenharmony_ci prob.init_mode_probs = rvcn_vcn4_init_mode_probs; 2063bf215546Sopenharmony_ci prob.init_mv_probs = rvcn_vcn4_av1_init_mv_probs; 2064bf215546Sopenharmony_ci prob.default_coef_probs = rvcn_vcn4_av1_default_coef_probs; 2065bf215546Sopenharmony_ci } 2066bf215546Sopenharmony_ci 2067bf215546Sopenharmony_ci ctx_size += (MAX2(sdb_lf_size_ctb_64x64, sdb_lf_size_ctb_128x128) + 2068bf215546Sopenharmony_ci MAX2(sdb_superres_size_ctb_64x64, sdb_superres_size_ctb_128x128) + 2069bf215546Sopenharmony_ci MAX2(sdb_output_size_ctb_64x64, sdb_output_size_ctb_128x128) + 2070bf215546Sopenharmony_ci MAX2(sdb_fg_avg_luma_size_ctb_64x64, sdb_fg_avg_luma_size_ctb_128x128)) * 2 + 68 * 512; 2071bf215546Sopenharmony_ci 2072bf215546Sopenharmony_ci if (!si_vid_create_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT)) 2073bf215546Sopenharmony_ci RVID_ERR("Can't allocated context buffer.\n"); 2074bf215546Sopenharmony_ci si_vid_clear_buffer(dec->base.context, &dec->ctx); 2075bf215546Sopenharmony_ci 2076bf215546Sopenharmony_ci ptr = dec->ws->buffer_map(dec->ws, dec->ctx.res->buf, &dec->cs, PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY); 2077bf215546Sopenharmony_ci 2078bf215546Sopenharmony_ci for (i = 0; i < 4; ++i) { 2079bf215546Sopenharmony_ci prob.init_mode_probs((void*)(ptr + i * frame_ctxt_size)); 2080bf215546Sopenharmony_ci prob.init_mv_probs((void*)(ptr + i * frame_ctxt_size)); 2081bf215546Sopenharmony_ci prob.default_coef_probs((void*)(ptr + i * frame_ctxt_size), i); 2082bf215546Sopenharmony_ci } 2083bf215546Sopenharmony_ci dec->ws->buffer_unmap(dec->ws, dec->ctx.res->buf); 2084bf215546Sopenharmony_ci } 2085bf215546Sopenharmony_ci 2086bf215546Sopenharmony_ci break; 2087bf215546Sopenharmony_ci } 2088bf215546Sopenharmony_ci default: 2089bf215546Sopenharmony_ci assert(0); 2090bf215546Sopenharmony_ci return NULL; 2091bf215546Sopenharmony_ci } 2092bf215546Sopenharmony_ci 2093bf215546Sopenharmony_ci if (dec->ctx.res) 2094bf215546Sopenharmony_ci decode->hw_ctxt_size = dec->ctx.res->buf->size; 2095bf215546Sopenharmony_ci 2096bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_2) 2097bf215546Sopenharmony_ci if (rvcn_dec_dynamic_dpb_t2_message(dec, decode, dynamic_dpb_t2, encrypted)) 2098bf215546Sopenharmony_ci return NULL; 2099bf215546Sopenharmony_ci 2100bf215546Sopenharmony_ci return luma->buffer.buf; 2101bf215546Sopenharmony_ci} 2102bf215546Sopenharmony_ci 2103bf215546Sopenharmony_cistatic void rvcn_dec_message_destroy(struct radeon_decoder *dec) 2104bf215546Sopenharmony_ci{ 2105bf215546Sopenharmony_ci rvcn_dec_message_header_t *header = dec->msg; 2106bf215546Sopenharmony_ci 2107bf215546Sopenharmony_ci memset(dec->msg, 0, sizeof(rvcn_dec_message_header_t)); 2108bf215546Sopenharmony_ci header->header_size = sizeof(rvcn_dec_message_header_t); 2109bf215546Sopenharmony_ci header->total_size = sizeof(rvcn_dec_message_header_t) - sizeof(rvcn_dec_message_index_t); 2110bf215546Sopenharmony_ci header->num_buffers = 0; 2111bf215546Sopenharmony_ci header->msg_type = RDECODE_MSG_DESTROY; 2112bf215546Sopenharmony_ci header->stream_handle = dec->stream_handle; 2113bf215546Sopenharmony_ci header->status_report_feedback_number = 0; 2114bf215546Sopenharmony_ci} 2115bf215546Sopenharmony_ci 2116bf215546Sopenharmony_cistatic void rvcn_dec_message_feedback(struct radeon_decoder *dec) 2117bf215546Sopenharmony_ci{ 2118bf215546Sopenharmony_ci rvcn_dec_feedback_header_t *header = (void *)dec->fb; 2119bf215546Sopenharmony_ci 2120bf215546Sopenharmony_ci header->header_size = sizeof(rvcn_dec_feedback_header_t); 2121bf215546Sopenharmony_ci header->total_size = sizeof(rvcn_dec_feedback_header_t); 2122bf215546Sopenharmony_ci header->num_buffers = 0; 2123bf215546Sopenharmony_ci} 2124bf215546Sopenharmony_ci 2125bf215546Sopenharmony_cistatic void rvcn_dec_sq_tail(struct radeon_decoder *dec) 2126bf215546Sopenharmony_ci{ 2127bf215546Sopenharmony_ci if (dec->vcn_dec_sw_ring == false) 2128bf215546Sopenharmony_ci return; 2129bf215546Sopenharmony_ci 2130bf215546Sopenharmony_ci rvcn_sq_tail(&dec->cs, &dec->sq); 2131bf215546Sopenharmony_ci} 2132bf215546Sopenharmony_ci/* flush IB to the hardware */ 2133bf215546Sopenharmony_cistatic int flush(struct radeon_decoder *dec, unsigned flags) 2134bf215546Sopenharmony_ci{ 2135bf215546Sopenharmony_ci rvcn_dec_sq_tail(dec); 2136bf215546Sopenharmony_ci 2137bf215546Sopenharmony_ci return dec->ws->cs_flush(&dec->cs, flags, NULL); 2138bf215546Sopenharmony_ci} 2139bf215546Sopenharmony_ci 2140bf215546Sopenharmony_ci/* add a new set register command to the IB */ 2141bf215546Sopenharmony_cistatic void set_reg(struct radeon_decoder *dec, unsigned reg, uint32_t val) 2142bf215546Sopenharmony_ci{ 2143bf215546Sopenharmony_ci radeon_emit(&dec->cs, RDECODE_PKT0(reg >> 2, 0)); 2144bf215546Sopenharmony_ci radeon_emit(&dec->cs, val); 2145bf215546Sopenharmony_ci} 2146bf215546Sopenharmony_ci 2147bf215546Sopenharmony_ci/* send a command to the VCPU through the GPCOM registers */ 2148bf215546Sopenharmony_cistatic void send_cmd(struct radeon_decoder *dec, unsigned cmd, struct pb_buffer *buf, uint32_t off, 2149bf215546Sopenharmony_ci unsigned usage, enum radeon_bo_domain domain) 2150bf215546Sopenharmony_ci{ 2151bf215546Sopenharmony_ci uint64_t addr; 2152bf215546Sopenharmony_ci 2153bf215546Sopenharmony_ci dec->ws->cs_add_buffer(&dec->cs, buf, usage | RADEON_USAGE_SYNCHRONIZED, domain); 2154bf215546Sopenharmony_ci addr = dec->ws->buffer_get_virtual_address(buf); 2155bf215546Sopenharmony_ci addr = addr + off; 2156bf215546Sopenharmony_ci 2157bf215546Sopenharmony_ci if (dec->vcn_dec_sw_ring == false) { 2158bf215546Sopenharmony_ci set_reg(dec, dec->reg.data0, addr); 2159bf215546Sopenharmony_ci set_reg(dec, dec->reg.data1, addr >> 32); 2160bf215546Sopenharmony_ci set_reg(dec, dec->reg.cmd, cmd << 1); 2161bf215546Sopenharmony_ci return; 2162bf215546Sopenharmony_ci } 2163bf215546Sopenharmony_ci 2164bf215546Sopenharmony_ci if (!dec->cs.current.cdw) { 2165bf215546Sopenharmony_ci rvcn_sq_header(&dec->cs, &dec->sq, false); 2166bf215546Sopenharmony_ci rvcn_decode_ib_package_t *ib_header = 2167bf215546Sopenharmony_ci (rvcn_decode_ib_package_t *)&(dec->cs.current.buf[dec->cs.current.cdw]); 2168bf215546Sopenharmony_ci 2169bf215546Sopenharmony_ci ib_header->package_size = sizeof(struct rvcn_decode_buffer_s) + 2170bf215546Sopenharmony_ci sizeof(struct rvcn_decode_ib_package_s); 2171bf215546Sopenharmony_ci dec->cs.current.cdw++; 2172bf215546Sopenharmony_ci ib_header->package_type = (RDECODE_IB_PARAM_DECODE_BUFFER); 2173bf215546Sopenharmony_ci dec->cs.current.cdw++; 2174bf215546Sopenharmony_ci 2175bf215546Sopenharmony_ci dec->decode_buffer = 2176bf215546Sopenharmony_ci (rvcn_decode_buffer_t *)&(dec->cs.current.buf[dec->cs.current.cdw]); 2177bf215546Sopenharmony_ci 2178bf215546Sopenharmony_ci dec->cs.current.cdw += sizeof(struct rvcn_decode_buffer_s) / 4; 2179bf215546Sopenharmony_ci memset(dec->decode_buffer, 0, sizeof(struct rvcn_decode_buffer_s)); 2180bf215546Sopenharmony_ci } 2181bf215546Sopenharmony_ci 2182bf215546Sopenharmony_ci switch(cmd) { 2183bf215546Sopenharmony_ci case RDECODE_CMD_MSG_BUFFER: 2184bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= RDECODE_CMDBUF_FLAGS_MSG_BUFFER; 2185bf215546Sopenharmony_ci dec->decode_buffer->msg_buffer_address_hi = (addr >> 32); 2186bf215546Sopenharmony_ci dec->decode_buffer->msg_buffer_address_lo = (addr); 2187bf215546Sopenharmony_ci break; 2188bf215546Sopenharmony_ci case RDECODE_CMD_DPB_BUFFER: 2189bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_DPB_BUFFER); 2190bf215546Sopenharmony_ci dec->decode_buffer->dpb_buffer_address_hi = (addr >> 32); 2191bf215546Sopenharmony_ci dec->decode_buffer->dpb_buffer_address_lo = (addr); 2192bf215546Sopenharmony_ci break; 2193bf215546Sopenharmony_ci case RDECODE_CMD_DECODING_TARGET_BUFFER: 2194bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_DECODING_TARGET_BUFFER); 2195bf215546Sopenharmony_ci dec->decode_buffer->target_buffer_address_hi = (addr >> 32); 2196bf215546Sopenharmony_ci dec->decode_buffer->target_buffer_address_lo = (addr); 2197bf215546Sopenharmony_ci break; 2198bf215546Sopenharmony_ci case RDECODE_CMD_FEEDBACK_BUFFER: 2199bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_FEEDBACK_BUFFER); 2200bf215546Sopenharmony_ci dec->decode_buffer->feedback_buffer_address_hi = (addr >> 32); 2201bf215546Sopenharmony_ci dec->decode_buffer->feedback_buffer_address_lo = (addr); 2202bf215546Sopenharmony_ci break; 2203bf215546Sopenharmony_ci case RDECODE_CMD_PROB_TBL_BUFFER: 2204bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_PROB_TBL_BUFFER); 2205bf215546Sopenharmony_ci dec->decode_buffer->prob_tbl_buffer_address_hi = (addr >> 32); 2206bf215546Sopenharmony_ci dec->decode_buffer->prob_tbl_buffer_address_lo = (addr); 2207bf215546Sopenharmony_ci break; 2208bf215546Sopenharmony_ci case RDECODE_CMD_SESSION_CONTEXT_BUFFER: 2209bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_SESSION_CONTEXT_BUFFER); 2210bf215546Sopenharmony_ci dec->decode_buffer->session_contex_buffer_address_hi = (addr >> 32); 2211bf215546Sopenharmony_ci dec->decode_buffer->session_contex_buffer_address_lo = (addr); 2212bf215546Sopenharmony_ci break; 2213bf215546Sopenharmony_ci case RDECODE_CMD_BITSTREAM_BUFFER: 2214bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_BITSTREAM_BUFFER); 2215bf215546Sopenharmony_ci dec->decode_buffer->bitstream_buffer_address_hi = (addr >> 32); 2216bf215546Sopenharmony_ci dec->decode_buffer->bitstream_buffer_address_lo = (addr); 2217bf215546Sopenharmony_ci break; 2218bf215546Sopenharmony_ci case RDECODE_CMD_IT_SCALING_TABLE_BUFFER: 2219bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_IT_SCALING_BUFFER); 2220bf215546Sopenharmony_ci dec->decode_buffer->it_sclr_table_buffer_address_hi = (addr >> 32); 2221bf215546Sopenharmony_ci dec->decode_buffer->it_sclr_table_buffer_address_lo = (addr); 2222bf215546Sopenharmony_ci break; 2223bf215546Sopenharmony_ci case RDECODE_CMD_CONTEXT_BUFFER: 2224bf215546Sopenharmony_ci dec->decode_buffer->valid_buf_flag |= (RDECODE_CMDBUF_FLAGS_CONTEXT_BUFFER); 2225bf215546Sopenharmony_ci dec->decode_buffer->context_buffer_address_hi = (addr >> 32); 2226bf215546Sopenharmony_ci dec->decode_buffer->context_buffer_address_lo = (addr); 2227bf215546Sopenharmony_ci break; 2228bf215546Sopenharmony_ci default: 2229bf215546Sopenharmony_ci printf("Not Support!"); 2230bf215546Sopenharmony_ci } 2231bf215546Sopenharmony_ci} 2232bf215546Sopenharmony_ci 2233bf215546Sopenharmony_ci/* do the codec needs an IT buffer ?*/ 2234bf215546Sopenharmony_cistatic bool have_it(struct radeon_decoder *dec) 2235bf215546Sopenharmony_ci{ 2236bf215546Sopenharmony_ci return dec->stream_type == RDECODE_CODEC_H264_PERF || dec->stream_type == RDECODE_CODEC_H265; 2237bf215546Sopenharmony_ci} 2238bf215546Sopenharmony_ci 2239bf215546Sopenharmony_ci/* do the codec needs an probs buffer? */ 2240bf215546Sopenharmony_cistatic bool have_probs(struct radeon_decoder *dec) 2241bf215546Sopenharmony_ci{ 2242bf215546Sopenharmony_ci return (dec->stream_type == RDECODE_CODEC_VP9 || dec->stream_type == RDECODE_CODEC_AV1); 2243bf215546Sopenharmony_ci} 2244bf215546Sopenharmony_ci 2245bf215546Sopenharmony_ci/* map the next available message/feedback/itscaling buffer */ 2246bf215546Sopenharmony_cistatic void map_msg_fb_it_probs_buf(struct radeon_decoder *dec) 2247bf215546Sopenharmony_ci{ 2248bf215546Sopenharmony_ci struct rvid_buffer *buf; 2249bf215546Sopenharmony_ci uint8_t *ptr; 2250bf215546Sopenharmony_ci 2251bf215546Sopenharmony_ci /* grab the current message/feedback buffer */ 2252bf215546Sopenharmony_ci buf = &dec->msg_fb_it_probs_buffers[dec->cur_buffer]; 2253bf215546Sopenharmony_ci 2254bf215546Sopenharmony_ci /* and map it for CPU access */ 2255bf215546Sopenharmony_ci ptr = 2256bf215546Sopenharmony_ci dec->ws->buffer_map(dec->ws, buf->res->buf, &dec->cs, PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY); 2257bf215546Sopenharmony_ci 2258bf215546Sopenharmony_ci /* calc buffer offsets */ 2259bf215546Sopenharmony_ci dec->msg = ptr; 2260bf215546Sopenharmony_ci 2261bf215546Sopenharmony_ci dec->fb = (uint32_t *)(ptr + FB_BUFFER_OFFSET); 2262bf215546Sopenharmony_ci if (have_it(dec)) 2263bf215546Sopenharmony_ci dec->it = (uint8_t *)(ptr + FB_BUFFER_OFFSET + FB_BUFFER_SIZE); 2264bf215546Sopenharmony_ci else if (have_probs(dec)) 2265bf215546Sopenharmony_ci dec->probs = (uint8_t *)(ptr + FB_BUFFER_OFFSET + FB_BUFFER_SIZE); 2266bf215546Sopenharmony_ci} 2267bf215546Sopenharmony_ci 2268bf215546Sopenharmony_ci/* unmap and send a message command to the VCPU */ 2269bf215546Sopenharmony_cistatic void send_msg_buf(struct radeon_decoder *dec) 2270bf215546Sopenharmony_ci{ 2271bf215546Sopenharmony_ci struct rvid_buffer *buf; 2272bf215546Sopenharmony_ci 2273bf215546Sopenharmony_ci /* ignore the request if message/feedback buffer isn't mapped */ 2274bf215546Sopenharmony_ci if (!dec->msg || !dec->fb) 2275bf215546Sopenharmony_ci return; 2276bf215546Sopenharmony_ci 2277bf215546Sopenharmony_ci /* grab the current message buffer */ 2278bf215546Sopenharmony_ci buf = &dec->msg_fb_it_probs_buffers[dec->cur_buffer]; 2279bf215546Sopenharmony_ci 2280bf215546Sopenharmony_ci /* unmap the buffer */ 2281bf215546Sopenharmony_ci dec->ws->buffer_unmap(dec->ws, buf->res->buf); 2282bf215546Sopenharmony_ci dec->bs_ptr = NULL; 2283bf215546Sopenharmony_ci dec->msg = NULL; 2284bf215546Sopenharmony_ci dec->fb = NULL; 2285bf215546Sopenharmony_ci dec->it = NULL; 2286bf215546Sopenharmony_ci dec->probs = NULL; 2287bf215546Sopenharmony_ci 2288bf215546Sopenharmony_ci if (dec->sessionctx.res) 2289bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_SESSION_CONTEXT_BUFFER, dec->sessionctx.res->buf, 0, 2290bf215546Sopenharmony_ci RADEON_USAGE_READWRITE, RADEON_DOMAIN_VRAM); 2291bf215546Sopenharmony_ci 2292bf215546Sopenharmony_ci /* and send it to the hardware */ 2293bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_MSG_BUFFER, buf->res->buf, 0, RADEON_USAGE_READ, RADEON_DOMAIN_GTT); 2294bf215546Sopenharmony_ci} 2295bf215546Sopenharmony_ci 2296bf215546Sopenharmony_ci/* cycle to the next set of buffers */ 2297bf215546Sopenharmony_cistatic void next_buffer(struct radeon_decoder *dec) 2298bf215546Sopenharmony_ci{ 2299bf215546Sopenharmony_ci ++dec->cur_buffer; 2300bf215546Sopenharmony_ci dec->cur_buffer %= NUM_BUFFERS; 2301bf215546Sopenharmony_ci} 2302bf215546Sopenharmony_ci 2303bf215546Sopenharmony_cistatic unsigned calc_ctx_size_h264_perf(struct radeon_decoder *dec) 2304bf215546Sopenharmony_ci{ 2305bf215546Sopenharmony_ci unsigned width_in_mb, height_in_mb, ctx_size; 2306bf215546Sopenharmony_ci unsigned width = align(dec->base.width, VL_MACROBLOCK_WIDTH); 2307bf215546Sopenharmony_ci unsigned height = align(dec->base.height, VL_MACROBLOCK_HEIGHT); 2308bf215546Sopenharmony_ci 2309bf215546Sopenharmony_ci unsigned max_references = dec->base.max_references + 1; 2310bf215546Sopenharmony_ci 2311bf215546Sopenharmony_ci // picture width & height in 16 pixel units 2312bf215546Sopenharmony_ci width_in_mb = width / VL_MACROBLOCK_WIDTH; 2313bf215546Sopenharmony_ci height_in_mb = align(height / VL_MACROBLOCK_HEIGHT, 2); 2314bf215546Sopenharmony_ci 2315bf215546Sopenharmony_ci unsigned fs_in_mb = width_in_mb * height_in_mb; 2316bf215546Sopenharmony_ci unsigned num_dpb_buffer; 2317bf215546Sopenharmony_ci switch (dec->base.level) { 2318bf215546Sopenharmony_ci case 30: 2319bf215546Sopenharmony_ci num_dpb_buffer = 8100 / fs_in_mb; 2320bf215546Sopenharmony_ci break; 2321bf215546Sopenharmony_ci case 31: 2322bf215546Sopenharmony_ci num_dpb_buffer = 18000 / fs_in_mb; 2323bf215546Sopenharmony_ci break; 2324bf215546Sopenharmony_ci case 32: 2325bf215546Sopenharmony_ci num_dpb_buffer = 20480 / fs_in_mb; 2326bf215546Sopenharmony_ci break; 2327bf215546Sopenharmony_ci case 41: 2328bf215546Sopenharmony_ci num_dpb_buffer = 32768 / fs_in_mb; 2329bf215546Sopenharmony_ci break; 2330bf215546Sopenharmony_ci case 42: 2331bf215546Sopenharmony_ci num_dpb_buffer = 34816 / fs_in_mb; 2332bf215546Sopenharmony_ci break; 2333bf215546Sopenharmony_ci case 50: 2334bf215546Sopenharmony_ci num_dpb_buffer = 110400 / fs_in_mb; 2335bf215546Sopenharmony_ci break; 2336bf215546Sopenharmony_ci case 51: 2337bf215546Sopenharmony_ci num_dpb_buffer = 184320 / fs_in_mb; 2338bf215546Sopenharmony_ci break; 2339bf215546Sopenharmony_ci default: 2340bf215546Sopenharmony_ci num_dpb_buffer = 184320 / fs_in_mb; 2341bf215546Sopenharmony_ci break; 2342bf215546Sopenharmony_ci } 2343bf215546Sopenharmony_ci num_dpb_buffer++; 2344bf215546Sopenharmony_ci max_references = MAX2(MIN2(NUM_H264_REFS, num_dpb_buffer), max_references); 2345bf215546Sopenharmony_ci ctx_size = max_references * align(width_in_mb * height_in_mb * 192, 256); 2346bf215546Sopenharmony_ci 2347bf215546Sopenharmony_ci return ctx_size; 2348bf215546Sopenharmony_ci} 2349bf215546Sopenharmony_ci 2350bf215546Sopenharmony_ci/* calculate size of reference picture buffer */ 2351bf215546Sopenharmony_cistatic unsigned calc_dpb_size(struct radeon_decoder *dec) 2352bf215546Sopenharmony_ci{ 2353bf215546Sopenharmony_ci unsigned width_in_mb, height_in_mb, image_size, dpb_size; 2354bf215546Sopenharmony_ci 2355bf215546Sopenharmony_ci // always align them to MB size for dpb calculation 2356bf215546Sopenharmony_ci unsigned width = align(dec->base.width, VL_MACROBLOCK_WIDTH); 2357bf215546Sopenharmony_ci unsigned height = align(dec->base.height, VL_MACROBLOCK_HEIGHT); 2358bf215546Sopenharmony_ci 2359bf215546Sopenharmony_ci // always one more for currently decoded picture 2360bf215546Sopenharmony_ci unsigned max_references = dec->base.max_references + 1; 2361bf215546Sopenharmony_ci 2362bf215546Sopenharmony_ci // aligned size of a single frame 2363bf215546Sopenharmony_ci image_size = align(width, 32) * height; 2364bf215546Sopenharmony_ci image_size += image_size / 2; 2365bf215546Sopenharmony_ci image_size = align(image_size, 1024); 2366bf215546Sopenharmony_ci 2367bf215546Sopenharmony_ci // picture width & height in 16 pixel units 2368bf215546Sopenharmony_ci width_in_mb = width / VL_MACROBLOCK_WIDTH; 2369bf215546Sopenharmony_ci height_in_mb = align(height / VL_MACROBLOCK_HEIGHT, 2); 2370bf215546Sopenharmony_ci 2371bf215546Sopenharmony_ci switch (u_reduce_video_profile(dec->base.profile)) { 2372bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG4_AVC: { 2373bf215546Sopenharmony_ci unsigned fs_in_mb = width_in_mb * height_in_mb; 2374bf215546Sopenharmony_ci unsigned num_dpb_buffer; 2375bf215546Sopenharmony_ci 2376bf215546Sopenharmony_ci switch (dec->base.level) { 2377bf215546Sopenharmony_ci case 30: 2378bf215546Sopenharmony_ci num_dpb_buffer = 8100 / fs_in_mb; 2379bf215546Sopenharmony_ci break; 2380bf215546Sopenharmony_ci case 31: 2381bf215546Sopenharmony_ci num_dpb_buffer = 18000 / fs_in_mb; 2382bf215546Sopenharmony_ci break; 2383bf215546Sopenharmony_ci case 32: 2384bf215546Sopenharmony_ci num_dpb_buffer = 20480 / fs_in_mb; 2385bf215546Sopenharmony_ci break; 2386bf215546Sopenharmony_ci case 41: 2387bf215546Sopenharmony_ci num_dpb_buffer = 32768 / fs_in_mb; 2388bf215546Sopenharmony_ci break; 2389bf215546Sopenharmony_ci case 42: 2390bf215546Sopenharmony_ci num_dpb_buffer = 34816 / fs_in_mb; 2391bf215546Sopenharmony_ci break; 2392bf215546Sopenharmony_ci case 50: 2393bf215546Sopenharmony_ci num_dpb_buffer = 110400 / fs_in_mb; 2394bf215546Sopenharmony_ci break; 2395bf215546Sopenharmony_ci case 51: 2396bf215546Sopenharmony_ci num_dpb_buffer = 184320 / fs_in_mb; 2397bf215546Sopenharmony_ci break; 2398bf215546Sopenharmony_ci default: 2399bf215546Sopenharmony_ci num_dpb_buffer = 184320 / fs_in_mb; 2400bf215546Sopenharmony_ci break; 2401bf215546Sopenharmony_ci } 2402bf215546Sopenharmony_ci num_dpb_buffer++; 2403bf215546Sopenharmony_ci max_references = MAX2(MIN2(NUM_H264_REFS, num_dpb_buffer), max_references); 2404bf215546Sopenharmony_ci dpb_size = image_size * max_references; 2405bf215546Sopenharmony_ci break; 2406bf215546Sopenharmony_ci } 2407bf215546Sopenharmony_ci 2408bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_HEVC: 2409bf215546Sopenharmony_ci if (dec->base.width * dec->base.height >= 4096 * 2000) 2410bf215546Sopenharmony_ci max_references = MAX2(max_references, 8); 2411bf215546Sopenharmony_ci else 2412bf215546Sopenharmony_ci max_references = MAX2(max_references, 17); 2413bf215546Sopenharmony_ci 2414bf215546Sopenharmony_ci width = align(width, 16); 2415bf215546Sopenharmony_ci height = align(height, 16); 2416bf215546Sopenharmony_ci if (dec->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) 2417bf215546Sopenharmony_ci dpb_size = align((align(width, 64) * align(height, 64) * 9) / 4, 256) * max_references; 2418bf215546Sopenharmony_ci else 2419bf215546Sopenharmony_ci dpb_size = align((align(width, 32) * height * 3) / 2, 256) * max_references; 2420bf215546Sopenharmony_ci break; 2421bf215546Sopenharmony_ci 2422bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_VC1: 2423bf215546Sopenharmony_ci // the firmware seems to allways assume a minimum of ref frames 2424bf215546Sopenharmony_ci max_references = MAX2(NUM_VC1_REFS, max_references); 2425bf215546Sopenharmony_ci 2426bf215546Sopenharmony_ci // reference picture buffer 2427bf215546Sopenharmony_ci dpb_size = image_size * max_references; 2428bf215546Sopenharmony_ci 2429bf215546Sopenharmony_ci // CONTEXT_BUFFER 2430bf215546Sopenharmony_ci dpb_size += width_in_mb * height_in_mb * 128; 2431bf215546Sopenharmony_ci 2432bf215546Sopenharmony_ci // IT surface buffer 2433bf215546Sopenharmony_ci dpb_size += width_in_mb * 64; 2434bf215546Sopenharmony_ci 2435bf215546Sopenharmony_ci // DB surface buffer 2436bf215546Sopenharmony_ci dpb_size += width_in_mb * 128; 2437bf215546Sopenharmony_ci 2438bf215546Sopenharmony_ci // BP 2439bf215546Sopenharmony_ci dpb_size += align(MAX2(width_in_mb, height_in_mb) * 7 * 16, 64); 2440bf215546Sopenharmony_ci break; 2441bf215546Sopenharmony_ci 2442bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG12: 2443bf215546Sopenharmony_ci // reference picture buffer, must be big enough for all frames 2444bf215546Sopenharmony_ci dpb_size = image_size * NUM_MPEG2_REFS; 2445bf215546Sopenharmony_ci break; 2446bf215546Sopenharmony_ci 2447bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG4: 2448bf215546Sopenharmony_ci // reference picture buffer 2449bf215546Sopenharmony_ci dpb_size = image_size * max_references; 2450bf215546Sopenharmony_ci 2451bf215546Sopenharmony_ci // CM 2452bf215546Sopenharmony_ci dpb_size += width_in_mb * height_in_mb * 64; 2453bf215546Sopenharmony_ci 2454bf215546Sopenharmony_ci // IT surface buffer 2455bf215546Sopenharmony_ci dpb_size += align(width_in_mb * height_in_mb * 32, 64); 2456bf215546Sopenharmony_ci 2457bf215546Sopenharmony_ci dpb_size = MAX2(dpb_size, 30 * 1024 * 1024); 2458bf215546Sopenharmony_ci break; 2459bf215546Sopenharmony_ci 2460bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_VP9: 2461bf215546Sopenharmony_ci max_references = MAX2(max_references, 9); 2462bf215546Sopenharmony_ci 2463bf215546Sopenharmony_ci if (dec->dpb_type == DPB_MAX_RES) 2464bf215546Sopenharmony_ci dpb_size = (((struct si_screen *)dec->screen)->info.family >= CHIP_RENOIR) 2465bf215546Sopenharmony_ci ? (8192 * 4320 * 3 / 2) * max_references 2466bf215546Sopenharmony_ci : (4096 * 3000 * 3 / 2) * max_references; 2467bf215546Sopenharmony_ci else 2468bf215546Sopenharmony_ci dpb_size = (align(dec->base.width, dec->db_alignment) * 2469bf215546Sopenharmony_ci align(dec->base.height, dec->db_alignment) * 3 / 2) * max_references; 2470bf215546Sopenharmony_ci 2471bf215546Sopenharmony_ci if (dec->base.profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2) 2472bf215546Sopenharmony_ci dpb_size = dpb_size * 3 / 2; 2473bf215546Sopenharmony_ci break; 2474bf215546Sopenharmony_ci 2475bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_AV1: 2476bf215546Sopenharmony_ci max_references = MAX2(max_references, 9); 2477bf215546Sopenharmony_ci dpb_size = 8192 * 4320 * 3 / 2 * max_references * 3 / 2; 2478bf215546Sopenharmony_ci break; 2479bf215546Sopenharmony_ci 2480bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_JPEG: 2481bf215546Sopenharmony_ci dpb_size = 0; 2482bf215546Sopenharmony_ci break; 2483bf215546Sopenharmony_ci 2484bf215546Sopenharmony_ci default: 2485bf215546Sopenharmony_ci // something is missing here 2486bf215546Sopenharmony_ci assert(0); 2487bf215546Sopenharmony_ci 2488bf215546Sopenharmony_ci // at least use a sane default value 2489bf215546Sopenharmony_ci dpb_size = 32 * 1024 * 1024; 2490bf215546Sopenharmony_ci break; 2491bf215546Sopenharmony_ci } 2492bf215546Sopenharmony_ci return dpb_size; 2493bf215546Sopenharmony_ci} 2494bf215546Sopenharmony_ci 2495bf215546Sopenharmony_ci/** 2496bf215546Sopenharmony_ci * destroy this video decoder 2497bf215546Sopenharmony_ci */ 2498bf215546Sopenharmony_cistatic void radeon_dec_destroy(struct pipe_video_codec *decoder) 2499bf215546Sopenharmony_ci{ 2500bf215546Sopenharmony_ci struct radeon_decoder *dec = (struct radeon_decoder *)decoder; 2501bf215546Sopenharmony_ci unsigned i; 2502bf215546Sopenharmony_ci 2503bf215546Sopenharmony_ci assert(decoder); 2504bf215546Sopenharmony_ci 2505bf215546Sopenharmony_ci if (dec->stream_type != RDECODE_CODEC_JPEG) { 2506bf215546Sopenharmony_ci map_msg_fb_it_probs_buf(dec); 2507bf215546Sopenharmony_ci rvcn_dec_message_destroy(dec); 2508bf215546Sopenharmony_ci send_msg_buf(dec); 2509bf215546Sopenharmony_ci flush(dec, 0); 2510bf215546Sopenharmony_ci } 2511bf215546Sopenharmony_ci 2512bf215546Sopenharmony_ci dec->ws->cs_destroy(&dec->cs); 2513bf215546Sopenharmony_ci 2514bf215546Sopenharmony_ci if (dec->stream_type == RDECODE_CODEC_JPEG) { 2515bf215546Sopenharmony_ci for (i = 0; i < dec->njctx; i++) { 2516bf215546Sopenharmony_ci dec->ws->cs_destroy(&dec->jcs[i]); 2517bf215546Sopenharmony_ci dec->ws->ctx_destroy(dec->jctx[i]); 2518bf215546Sopenharmony_ci } 2519bf215546Sopenharmony_ci } 2520bf215546Sopenharmony_ci 2521bf215546Sopenharmony_ci for (i = 0; i < NUM_BUFFERS; ++i) { 2522bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->msg_fb_it_probs_buffers[i]); 2523bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->bs_buffers[i]); 2524bf215546Sopenharmony_ci } 2525bf215546Sopenharmony_ci 2526bf215546Sopenharmony_ci if (dec->dpb_type != DPB_DYNAMIC_TIER_2) { 2527bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->dpb); 2528bf215546Sopenharmony_ci } else { 2529bf215546Sopenharmony_ci list_for_each_entry_safe(struct rvcn_dec_dynamic_dpb_t2, d, &dec->dpb_ref_list, list) { 2530bf215546Sopenharmony_ci list_del(&d->list); 2531bf215546Sopenharmony_ci si_vid_destroy_buffer(&d->dpb); 2532bf215546Sopenharmony_ci FREE(d); 2533bf215546Sopenharmony_ci } 2534bf215546Sopenharmony_ci } 2535bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->ctx); 2536bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->sessionctx); 2537bf215546Sopenharmony_ci 2538bf215546Sopenharmony_ci FREE(dec->jcs); 2539bf215546Sopenharmony_ci FREE(dec->jctx); 2540bf215546Sopenharmony_ci FREE(dec); 2541bf215546Sopenharmony_ci} 2542bf215546Sopenharmony_ci 2543bf215546Sopenharmony_ci/** 2544bf215546Sopenharmony_ci * start decoding of a new frame 2545bf215546Sopenharmony_ci */ 2546bf215546Sopenharmony_cistatic void radeon_dec_begin_frame(struct pipe_video_codec *decoder, 2547bf215546Sopenharmony_ci struct pipe_video_buffer *target, 2548bf215546Sopenharmony_ci struct pipe_picture_desc *picture) 2549bf215546Sopenharmony_ci{ 2550bf215546Sopenharmony_ci struct radeon_decoder *dec = (struct radeon_decoder *)decoder; 2551bf215546Sopenharmony_ci uintptr_t frame; 2552bf215546Sopenharmony_ci 2553bf215546Sopenharmony_ci assert(decoder); 2554bf215546Sopenharmony_ci 2555bf215546Sopenharmony_ci frame = ++dec->frame_number; 2556bf215546Sopenharmony_ci if (dec->stream_type != RDECODE_CODEC_VP9 && dec->stream_type != RDECODE_CODEC_AV1 2557bf215546Sopenharmony_ci && dec->stream_type != RDECODE_CODEC_H264_PERF) 2558bf215546Sopenharmony_ci vl_video_buffer_set_associated_data(target, decoder, (void *)frame, 2559bf215546Sopenharmony_ci &radeon_dec_destroy_associated_data); 2560bf215546Sopenharmony_ci 2561bf215546Sopenharmony_ci dec->bs_size = 0; 2562bf215546Sopenharmony_ci dec->bs_ptr = dec->ws->buffer_map(dec->ws, dec->bs_buffers[dec->cur_buffer].res->buf, &dec->cs, 2563bf215546Sopenharmony_ci PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY); 2564bf215546Sopenharmony_ci} 2565bf215546Sopenharmony_ci 2566bf215546Sopenharmony_ci/** 2567bf215546Sopenharmony_ci * decode a macroblock 2568bf215546Sopenharmony_ci */ 2569bf215546Sopenharmony_cistatic void radeon_dec_decode_macroblock(struct pipe_video_codec *decoder, 2570bf215546Sopenharmony_ci struct pipe_video_buffer *target, 2571bf215546Sopenharmony_ci struct pipe_picture_desc *picture, 2572bf215546Sopenharmony_ci const struct pipe_macroblock *macroblocks, 2573bf215546Sopenharmony_ci unsigned num_macroblocks) 2574bf215546Sopenharmony_ci{ 2575bf215546Sopenharmony_ci /* not supported (yet) */ 2576bf215546Sopenharmony_ci assert(0); 2577bf215546Sopenharmony_ci} 2578bf215546Sopenharmony_ci 2579bf215546Sopenharmony_ci/** 2580bf215546Sopenharmony_ci * decode a bitstream 2581bf215546Sopenharmony_ci */ 2582bf215546Sopenharmony_cistatic void radeon_dec_decode_bitstream(struct pipe_video_codec *decoder, 2583bf215546Sopenharmony_ci struct pipe_video_buffer *target, 2584bf215546Sopenharmony_ci struct pipe_picture_desc *picture, unsigned num_buffers, 2585bf215546Sopenharmony_ci const void *const *buffers, const unsigned *sizes) 2586bf215546Sopenharmony_ci{ 2587bf215546Sopenharmony_ci struct radeon_decoder *dec = (struct radeon_decoder *)decoder; 2588bf215546Sopenharmony_ci unsigned i; 2589bf215546Sopenharmony_ci 2590bf215546Sopenharmony_ci assert(decoder); 2591bf215546Sopenharmony_ci 2592bf215546Sopenharmony_ci if (!dec->bs_ptr) 2593bf215546Sopenharmony_ci return; 2594bf215546Sopenharmony_ci 2595bf215546Sopenharmony_ci for (i = 0; i < num_buffers; ++i) { 2596bf215546Sopenharmony_ci struct rvid_buffer *buf = &dec->bs_buffers[dec->cur_buffer]; 2597bf215546Sopenharmony_ci unsigned new_size = dec->bs_size + sizes[i]; 2598bf215546Sopenharmony_ci 2599bf215546Sopenharmony_ci if (new_size > buf->res->buf->size) { 2600bf215546Sopenharmony_ci dec->ws->buffer_unmap(dec->ws, buf->res->buf); 2601bf215546Sopenharmony_ci dec->bs_ptr = NULL; 2602bf215546Sopenharmony_ci if (!si_vid_resize_buffer(dec->screen, &dec->cs, buf, new_size)) { 2603bf215546Sopenharmony_ci RVID_ERR("Can't resize bitstream buffer!"); 2604bf215546Sopenharmony_ci return; 2605bf215546Sopenharmony_ci } 2606bf215546Sopenharmony_ci 2607bf215546Sopenharmony_ci dec->bs_ptr = dec->ws->buffer_map(dec->ws, buf->res->buf, &dec->cs, 2608bf215546Sopenharmony_ci PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY); 2609bf215546Sopenharmony_ci if (!dec->bs_ptr) 2610bf215546Sopenharmony_ci return; 2611bf215546Sopenharmony_ci 2612bf215546Sopenharmony_ci dec->bs_ptr += dec->bs_size; 2613bf215546Sopenharmony_ci } 2614bf215546Sopenharmony_ci 2615bf215546Sopenharmony_ci memcpy(dec->bs_ptr, buffers[i], sizes[i]); 2616bf215546Sopenharmony_ci dec->bs_size += sizes[i]; 2617bf215546Sopenharmony_ci dec->bs_ptr += sizes[i]; 2618bf215546Sopenharmony_ci } 2619bf215546Sopenharmony_ci} 2620bf215546Sopenharmony_ci 2621bf215546Sopenharmony_ci/** 2622bf215546Sopenharmony_ci * send cmd for vcn dec 2623bf215546Sopenharmony_ci */ 2624bf215546Sopenharmony_civoid send_cmd_dec(struct radeon_decoder *dec, struct pipe_video_buffer *target, 2625bf215546Sopenharmony_ci struct pipe_picture_desc *picture) 2626bf215546Sopenharmony_ci{ 2627bf215546Sopenharmony_ci struct pb_buffer *dt; 2628bf215546Sopenharmony_ci struct rvid_buffer *msg_fb_it_probs_buf, *bs_buf; 2629bf215546Sopenharmony_ci 2630bf215546Sopenharmony_ci msg_fb_it_probs_buf = &dec->msg_fb_it_probs_buffers[dec->cur_buffer]; 2631bf215546Sopenharmony_ci bs_buf = &dec->bs_buffers[dec->cur_buffer]; 2632bf215546Sopenharmony_ci 2633bf215546Sopenharmony_ci memset(dec->bs_ptr, 0, align(dec->bs_size, 128) - dec->bs_size); 2634bf215546Sopenharmony_ci dec->ws->buffer_unmap(dec->ws, bs_buf->res->buf); 2635bf215546Sopenharmony_ci dec->bs_ptr = NULL; 2636bf215546Sopenharmony_ci 2637bf215546Sopenharmony_ci map_msg_fb_it_probs_buf(dec); 2638bf215546Sopenharmony_ci dt = rvcn_dec_message_decode(dec, target, picture); 2639bf215546Sopenharmony_ci rvcn_dec_message_feedback(dec); 2640bf215546Sopenharmony_ci send_msg_buf(dec); 2641bf215546Sopenharmony_ci 2642bf215546Sopenharmony_ci if (dec->dpb_type != DPB_DYNAMIC_TIER_2) 2643bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_DPB_BUFFER, dec->dpb.res->buf, 0, RADEON_USAGE_READWRITE, 2644bf215546Sopenharmony_ci RADEON_DOMAIN_VRAM); 2645bf215546Sopenharmony_ci if (dec->ctx.res) 2646bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_CONTEXT_BUFFER, dec->ctx.res->buf, 0, RADEON_USAGE_READWRITE, 2647bf215546Sopenharmony_ci RADEON_DOMAIN_VRAM); 2648bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_BITSTREAM_BUFFER, bs_buf->res->buf, 0, RADEON_USAGE_READ, 2649bf215546Sopenharmony_ci RADEON_DOMAIN_GTT); 2650bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_DECODING_TARGET_BUFFER, dt, 0, RADEON_USAGE_WRITE, RADEON_DOMAIN_VRAM); 2651bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_FEEDBACK_BUFFER, msg_fb_it_probs_buf->res->buf, FB_BUFFER_OFFSET, 2652bf215546Sopenharmony_ci RADEON_USAGE_WRITE, RADEON_DOMAIN_GTT); 2653bf215546Sopenharmony_ci if (have_it(dec)) 2654bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_IT_SCALING_TABLE_BUFFER, msg_fb_it_probs_buf->res->buf, 2655bf215546Sopenharmony_ci FB_BUFFER_OFFSET + FB_BUFFER_SIZE, RADEON_USAGE_READ, RADEON_DOMAIN_GTT); 2656bf215546Sopenharmony_ci else if (have_probs(dec)) 2657bf215546Sopenharmony_ci send_cmd(dec, RDECODE_CMD_PROB_TBL_BUFFER, msg_fb_it_probs_buf->res->buf, 2658bf215546Sopenharmony_ci FB_BUFFER_OFFSET + FB_BUFFER_SIZE, RADEON_USAGE_READ, RADEON_DOMAIN_GTT); 2659bf215546Sopenharmony_ci 2660bf215546Sopenharmony_ci if (dec->vcn_dec_sw_ring == false) 2661bf215546Sopenharmony_ci set_reg(dec, dec->reg.cntl, 1); 2662bf215546Sopenharmony_ci} 2663bf215546Sopenharmony_ci 2664bf215546Sopenharmony_ci/** 2665bf215546Sopenharmony_ci * end decoding of the current frame 2666bf215546Sopenharmony_ci */ 2667bf215546Sopenharmony_cistatic void radeon_dec_end_frame(struct pipe_video_codec *decoder, struct pipe_video_buffer *target, 2668bf215546Sopenharmony_ci struct pipe_picture_desc *picture) 2669bf215546Sopenharmony_ci{ 2670bf215546Sopenharmony_ci struct radeon_decoder *dec = (struct radeon_decoder *)decoder; 2671bf215546Sopenharmony_ci 2672bf215546Sopenharmony_ci assert(decoder); 2673bf215546Sopenharmony_ci 2674bf215546Sopenharmony_ci if (!dec->bs_ptr) 2675bf215546Sopenharmony_ci return; 2676bf215546Sopenharmony_ci 2677bf215546Sopenharmony_ci dec->send_cmd(dec, target, picture); 2678bf215546Sopenharmony_ci flush(dec, PIPE_FLUSH_ASYNC); 2679bf215546Sopenharmony_ci next_buffer(dec); 2680bf215546Sopenharmony_ci} 2681bf215546Sopenharmony_ci 2682bf215546Sopenharmony_ci/** 2683bf215546Sopenharmony_ci * end decoding of the current jpeg frame 2684bf215546Sopenharmony_ci */ 2685bf215546Sopenharmony_cistatic void radeon_dec_jpeg_end_frame(struct pipe_video_codec *decoder, struct pipe_video_buffer *target, 2686bf215546Sopenharmony_ci struct pipe_picture_desc *picture) 2687bf215546Sopenharmony_ci{ 2688bf215546Sopenharmony_ci struct radeon_decoder *dec = (struct radeon_decoder *)decoder; 2689bf215546Sopenharmony_ci 2690bf215546Sopenharmony_ci assert(decoder); 2691bf215546Sopenharmony_ci 2692bf215546Sopenharmony_ci if (!dec->bs_ptr) 2693bf215546Sopenharmony_ci return; 2694bf215546Sopenharmony_ci 2695bf215546Sopenharmony_ci dec->send_cmd(dec, target, picture); 2696bf215546Sopenharmony_ci dec->ws->cs_flush(&dec->jcs[dec->cb_idx], PIPE_FLUSH_ASYNC, NULL); 2697bf215546Sopenharmony_ci next_buffer(dec); 2698bf215546Sopenharmony_ci dec->cb_idx = (dec->cb_idx+1) % dec->njctx; 2699bf215546Sopenharmony_ci} 2700bf215546Sopenharmony_ci 2701bf215546Sopenharmony_ci/** 2702bf215546Sopenharmony_ci * flush any outstanding command buffers to the hardware 2703bf215546Sopenharmony_ci */ 2704bf215546Sopenharmony_cistatic void radeon_dec_flush(struct pipe_video_codec *decoder) 2705bf215546Sopenharmony_ci{ 2706bf215546Sopenharmony_ci} 2707bf215546Sopenharmony_ci 2708bf215546Sopenharmony_ci/** 2709bf215546Sopenharmony_ci * create and HW decoder 2710bf215546Sopenharmony_ci */ 2711bf215546Sopenharmony_cistruct pipe_video_codec *radeon_create_decoder(struct pipe_context *context, 2712bf215546Sopenharmony_ci const struct pipe_video_codec *templ) 2713bf215546Sopenharmony_ci{ 2714bf215546Sopenharmony_ci struct si_context *sctx = (struct si_context *)context; 2715bf215546Sopenharmony_ci struct radeon_winsys *ws = sctx->ws; 2716bf215546Sopenharmony_ci unsigned width = templ->width, height = templ->height; 2717bf215546Sopenharmony_ci unsigned bs_buf_size, stream_type = 0, ring = AMD_IP_VCN_DEC; 2718bf215546Sopenharmony_ci struct radeon_decoder *dec; 2719bf215546Sopenharmony_ci int r, i; 2720bf215546Sopenharmony_ci 2721bf215546Sopenharmony_ci switch (u_reduce_video_profile(templ->profile)) { 2722bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG12: 2723bf215546Sopenharmony_ci if (templ->entrypoint > PIPE_VIDEO_ENTRYPOINT_BITSTREAM) 2724bf215546Sopenharmony_ci return vl_create_mpeg12_decoder(context, templ); 2725bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_MPEG2_VLD; 2726bf215546Sopenharmony_ci break; 2727bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG4: 2728bf215546Sopenharmony_ci width = align(width, VL_MACROBLOCK_WIDTH); 2729bf215546Sopenharmony_ci height = align(height, VL_MACROBLOCK_HEIGHT); 2730bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_MPEG4; 2731bf215546Sopenharmony_ci break; 2732bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_VC1: 2733bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_VC1; 2734bf215546Sopenharmony_ci break; 2735bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_MPEG4_AVC: 2736bf215546Sopenharmony_ci width = align(width, VL_MACROBLOCK_WIDTH); 2737bf215546Sopenharmony_ci height = align(height, VL_MACROBLOCK_HEIGHT); 2738bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_H264_PERF; 2739bf215546Sopenharmony_ci break; 2740bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_HEVC: 2741bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_H265; 2742bf215546Sopenharmony_ci break; 2743bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_VP9: 2744bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_VP9; 2745bf215546Sopenharmony_ci break; 2746bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_AV1: 2747bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_AV1; 2748bf215546Sopenharmony_ci break; 2749bf215546Sopenharmony_ci case PIPE_VIDEO_FORMAT_JPEG: 2750bf215546Sopenharmony_ci stream_type = RDECODE_CODEC_JPEG; 2751bf215546Sopenharmony_ci ring = AMD_IP_VCN_JPEG; 2752bf215546Sopenharmony_ci break; 2753bf215546Sopenharmony_ci default: 2754bf215546Sopenharmony_ci assert(0); 2755bf215546Sopenharmony_ci break; 2756bf215546Sopenharmony_ci } 2757bf215546Sopenharmony_ci 2758bf215546Sopenharmony_ci dec = CALLOC_STRUCT(radeon_decoder); 2759bf215546Sopenharmony_ci 2760bf215546Sopenharmony_ci if (!dec) 2761bf215546Sopenharmony_ci return NULL; 2762bf215546Sopenharmony_ci 2763bf215546Sopenharmony_ci dec->base = *templ; 2764bf215546Sopenharmony_ci dec->base.context = context; 2765bf215546Sopenharmony_ci dec->base.width = width; 2766bf215546Sopenharmony_ci dec->base.height = height; 2767bf215546Sopenharmony_ci 2768bf215546Sopenharmony_ci dec->base.destroy = radeon_dec_destroy; 2769bf215546Sopenharmony_ci dec->base.begin_frame = radeon_dec_begin_frame; 2770bf215546Sopenharmony_ci dec->base.decode_macroblock = radeon_dec_decode_macroblock; 2771bf215546Sopenharmony_ci dec->base.decode_bitstream = radeon_dec_decode_bitstream; 2772bf215546Sopenharmony_ci dec->base.end_frame = radeon_dec_end_frame; 2773bf215546Sopenharmony_ci dec->base.flush = radeon_dec_flush; 2774bf215546Sopenharmony_ci 2775bf215546Sopenharmony_ci dec->stream_type = stream_type; 2776bf215546Sopenharmony_ci dec->stream_handle = si_vid_alloc_stream_handle(); 2777bf215546Sopenharmony_ci dec->screen = context->screen; 2778bf215546Sopenharmony_ci dec->ws = ws; 2779bf215546Sopenharmony_ci 2780bf215546Sopenharmony_ci if (u_reduce_video_profile(templ->profile) != PIPE_VIDEO_FORMAT_JPEG && 2781bf215546Sopenharmony_ci sctx->gfx_level >= GFX11) { 2782bf215546Sopenharmony_ci dec->vcn_dec_sw_ring = true; 2783bf215546Sopenharmony_ci ring = AMD_IP_VCN_UNIFIED; 2784bf215546Sopenharmony_ci } 2785bf215546Sopenharmony_ci 2786bf215546Sopenharmony_ci dec->sq.ib_total_size_in_dw = NULL; 2787bf215546Sopenharmony_ci dec->sq.ib_checksum = NULL; 2788bf215546Sopenharmony_ci 2789bf215546Sopenharmony_ci if (!ws->cs_create(&dec->cs, sctx->ctx, ring, NULL, NULL, false)) { 2790bf215546Sopenharmony_ci RVID_ERR("Can't get command submission context.\n"); 2791bf215546Sopenharmony_ci goto error; 2792bf215546Sopenharmony_ci } 2793bf215546Sopenharmony_ci 2794bf215546Sopenharmony_ci if (dec->stream_type == RDECODE_CODEC_JPEG) { 2795bf215546Sopenharmony_ci 2796bf215546Sopenharmony_ci if (sctx->family == CHIP_ARCTURUS || sctx->family == CHIP_ALDEBARAN) 2797bf215546Sopenharmony_ci dec->njctx = 2; 2798bf215546Sopenharmony_ci else 2799bf215546Sopenharmony_ci dec->njctx = 1; 2800bf215546Sopenharmony_ci 2801bf215546Sopenharmony_ci dec->jctx = (struct radeon_winsys_ctx **) CALLOC(dec->njctx, 2802bf215546Sopenharmony_ci sizeof(struct radeon_winsys_ctx *)); 2803bf215546Sopenharmony_ci dec->jcs = (struct radeon_cmdbuf *) CALLOC(dec->njctx, sizeof(struct radeon_cmdbuf)); 2804bf215546Sopenharmony_ci if(!dec->jctx || !dec->jcs) 2805bf215546Sopenharmony_ci goto err; 2806bf215546Sopenharmony_ci for (i = 0; i < dec->njctx; i++) { 2807bf215546Sopenharmony_ci /* Initialize the context handle and the command stream. */ 2808bf215546Sopenharmony_ci dec->jctx[i] = dec->ws->ctx_create(dec->ws, RADEON_CTX_PRIORITY_MEDIUM); 2809bf215546Sopenharmony_ci if (!sctx->ctx) 2810bf215546Sopenharmony_ci goto error; 2811bf215546Sopenharmony_ci if (!dec->ws->cs_create(&dec->jcs[i], dec->jctx[i], ring, NULL, NULL, false)) { 2812bf215546Sopenharmony_ci RVID_ERR("Can't get additional command submission context for mJPEG.\n"); 2813bf215546Sopenharmony_ci goto error; 2814bf215546Sopenharmony_ci } 2815bf215546Sopenharmony_ci } 2816bf215546Sopenharmony_ci dec->base.end_frame = radeon_dec_jpeg_end_frame; 2817bf215546Sopenharmony_ci dec->cb_idx = 0; 2818bf215546Sopenharmony_ci } 2819bf215546Sopenharmony_ci 2820bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->render_pic_list); i++) 2821bf215546Sopenharmony_ci dec->render_pic_list[i] = NULL; 2822bf215546Sopenharmony_ci 2823bf215546Sopenharmony_ci if (sctx->family >= CHIP_NAVI21 && (stream_type == RDECODE_CODEC_H264_PERF)) { 2824bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->h264_valid_ref_num); i++) 2825bf215546Sopenharmony_ci dec->h264_valid_ref_num[i] = (unsigned) -1; 2826bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dec->h264_valid_poc_num); i++) 2827bf215546Sopenharmony_ci dec->h264_valid_poc_num[i] = (unsigned) -1; 2828bf215546Sopenharmony_ci } 2829bf215546Sopenharmony_ci 2830bf215546Sopenharmony_ci bs_buf_size = width * height * (512 / (16 * 16)); 2831bf215546Sopenharmony_ci for (i = 0; i < NUM_BUFFERS; ++i) { 2832bf215546Sopenharmony_ci unsigned msg_fb_it_probs_size = FB_BUFFER_OFFSET + FB_BUFFER_SIZE; 2833bf215546Sopenharmony_ci if (have_it(dec)) 2834bf215546Sopenharmony_ci msg_fb_it_probs_size += IT_SCALING_TABLE_SIZE; 2835bf215546Sopenharmony_ci else if (have_probs(dec)) 2836bf215546Sopenharmony_ci msg_fb_it_probs_size += (dec->stream_type == RDECODE_CODEC_VP9) ? 2837bf215546Sopenharmony_ci VP9_PROBS_TABLE_SIZE : 2838bf215546Sopenharmony_ci sizeof(rvcn_dec_av1_segment_fg_t); 2839bf215546Sopenharmony_ci /* use vram to improve performance, workaround an unknown bug */ 2840bf215546Sopenharmony_ci if (!si_vid_create_buffer(dec->screen, &dec->msg_fb_it_probs_buffers[i], msg_fb_it_probs_size, 2841bf215546Sopenharmony_ci PIPE_USAGE_DEFAULT)) { 2842bf215546Sopenharmony_ci RVID_ERR("Can't allocated message buffers.\n"); 2843bf215546Sopenharmony_ci goto error; 2844bf215546Sopenharmony_ci } 2845bf215546Sopenharmony_ci 2846bf215546Sopenharmony_ci if (!si_vid_create_buffer(dec->screen, &dec->bs_buffers[i], bs_buf_size, 2847bf215546Sopenharmony_ci PIPE_USAGE_STAGING)) { 2848bf215546Sopenharmony_ci RVID_ERR("Can't allocated bitstream buffers.\n"); 2849bf215546Sopenharmony_ci goto error; 2850bf215546Sopenharmony_ci } 2851bf215546Sopenharmony_ci 2852bf215546Sopenharmony_ci si_vid_clear_buffer(context, &dec->msg_fb_it_probs_buffers[i]); 2853bf215546Sopenharmony_ci si_vid_clear_buffer(context, &dec->bs_buffers[i]); 2854bf215546Sopenharmony_ci 2855bf215546Sopenharmony_ci if (have_probs(dec) && dec->stream_type == RDECODE_CODEC_VP9) { 2856bf215546Sopenharmony_ci struct rvid_buffer *buf; 2857bf215546Sopenharmony_ci void *ptr; 2858bf215546Sopenharmony_ci 2859bf215546Sopenharmony_ci buf = &dec->msg_fb_it_probs_buffers[i]; 2860bf215546Sopenharmony_ci ptr = dec->ws->buffer_map(dec->ws, buf->res->buf, &dec->cs, 2861bf215546Sopenharmony_ci PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY); 2862bf215546Sopenharmony_ci ptr += FB_BUFFER_OFFSET + FB_BUFFER_SIZE; 2863bf215546Sopenharmony_ci fill_probs_table(ptr); 2864bf215546Sopenharmony_ci dec->ws->buffer_unmap(dec->ws, buf->res->buf); 2865bf215546Sopenharmony_ci dec->bs_ptr = NULL; 2866bf215546Sopenharmony_ci } 2867bf215546Sopenharmony_ci } 2868bf215546Sopenharmony_ci 2869bf215546Sopenharmony_ci if (sctx->family >= CHIP_NAVI21 && 2870bf215546Sopenharmony_ci (stream_type == RDECODE_CODEC_VP9 || 2871bf215546Sopenharmony_ci stream_type == RDECODE_CODEC_AV1 || 2872bf215546Sopenharmony_ci ((stream_type == RDECODE_CODEC_H265) && templ->expect_chunked_decode) || 2873bf215546Sopenharmony_ci ((stream_type == RDECODE_CODEC_H264_PERF) && templ->expect_chunked_decode))) 2874bf215546Sopenharmony_ci dec->dpb_type = DPB_DYNAMIC_TIER_2; 2875bf215546Sopenharmony_ci else if (sctx->family <= CHIP_NAVI14 && stream_type == RDECODE_CODEC_VP9) 2876bf215546Sopenharmony_ci dec->dpb_type = DPB_DYNAMIC_TIER_1; 2877bf215546Sopenharmony_ci else 2878bf215546Sopenharmony_ci dec->dpb_type = DPB_MAX_RES; 2879bf215546Sopenharmony_ci 2880bf215546Sopenharmony_ci dec->db_alignment = (((struct si_screen *)dec->screen)->info.family >= CHIP_RENOIR && 2881bf215546Sopenharmony_ci dec->base.width > 32 && (dec->stream_type == RDECODE_CODEC_VP9 || 2882bf215546Sopenharmony_ci dec->stream_type == RDECODE_CODEC_AV1 || 2883bf215546Sopenharmony_ci dec->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10)) ? 64 : 32; 2884bf215546Sopenharmony_ci 2885bf215546Sopenharmony_ci dec->dpb_size = calc_dpb_size(dec); 2886bf215546Sopenharmony_ci 2887bf215546Sopenharmony_ci if (!si_vid_create_buffer(dec->screen, &dec->sessionctx, RDECODE_SESSION_CONTEXT_SIZE, 2888bf215546Sopenharmony_ci PIPE_USAGE_DEFAULT)) { 2889bf215546Sopenharmony_ci RVID_ERR("Can't allocated session ctx.\n"); 2890bf215546Sopenharmony_ci goto error; 2891bf215546Sopenharmony_ci } 2892bf215546Sopenharmony_ci si_vid_clear_buffer(context, &dec->sessionctx); 2893bf215546Sopenharmony_ci 2894bf215546Sopenharmony_ci dec->addr_gfx_mode = RDECODE_ARRAY_MODE_LINEAR; 2895bf215546Sopenharmony_ci dec->av1_version = RDECODE_AV1_VER_0; 2896bf215546Sopenharmony_ci 2897bf215546Sopenharmony_ci switch (sctx->family) { 2898bf215546Sopenharmony_ci case CHIP_RAVEN: 2899bf215546Sopenharmony_ci case CHIP_RAVEN2: 2900bf215546Sopenharmony_ci dec->reg.data0 = RDECODE_VCN1_GPCOM_VCPU_DATA0; 2901bf215546Sopenharmony_ci dec->reg.data1 = RDECODE_VCN1_GPCOM_VCPU_DATA1; 2902bf215546Sopenharmony_ci dec->reg.cmd = RDECODE_VCN1_GPCOM_VCPU_CMD; 2903bf215546Sopenharmony_ci dec->reg.cntl = RDECODE_VCN1_ENGINE_CNTL; 2904bf215546Sopenharmony_ci dec->jpg.direct_reg = false; 2905bf215546Sopenharmony_ci break; 2906bf215546Sopenharmony_ci case CHIP_NAVI10: 2907bf215546Sopenharmony_ci case CHIP_NAVI12: 2908bf215546Sopenharmony_ci case CHIP_NAVI14: 2909bf215546Sopenharmony_ci case CHIP_RENOIR: 2910bf215546Sopenharmony_ci dec->reg.data0 = RDECODE_VCN2_GPCOM_VCPU_DATA0; 2911bf215546Sopenharmony_ci dec->reg.data1 = RDECODE_VCN2_GPCOM_VCPU_DATA1; 2912bf215546Sopenharmony_ci dec->reg.cmd = RDECODE_VCN2_GPCOM_VCPU_CMD; 2913bf215546Sopenharmony_ci dec->reg.cntl = RDECODE_VCN2_ENGINE_CNTL; 2914bf215546Sopenharmony_ci dec->jpg.direct_reg = true; 2915bf215546Sopenharmony_ci break; 2916bf215546Sopenharmony_ci case CHIP_ARCTURUS: 2917bf215546Sopenharmony_ci case CHIP_ALDEBARAN: 2918bf215546Sopenharmony_ci case CHIP_NAVI21: 2919bf215546Sopenharmony_ci case CHIP_NAVI22: 2920bf215546Sopenharmony_ci case CHIP_NAVI23: 2921bf215546Sopenharmony_ci case CHIP_NAVI24: 2922bf215546Sopenharmony_ci case CHIP_VANGOGH: 2923bf215546Sopenharmony_ci case CHIP_REMBRANDT: 2924bf215546Sopenharmony_ci case CHIP_GFX1036: 2925bf215546Sopenharmony_ci dec->reg.data0 = RDECODE_VCN2_5_GPCOM_VCPU_DATA0; 2926bf215546Sopenharmony_ci dec->reg.data1 = RDECODE_VCN2_5_GPCOM_VCPU_DATA1; 2927bf215546Sopenharmony_ci dec->reg.cmd = RDECODE_VCN2_5_GPCOM_VCPU_CMD; 2928bf215546Sopenharmony_ci dec->reg.cntl = RDECODE_VCN2_5_ENGINE_CNTL; 2929bf215546Sopenharmony_ci dec->jpg.direct_reg = true; 2930bf215546Sopenharmony_ci break; 2931bf215546Sopenharmony_ci case CHIP_GFX1100: 2932bf215546Sopenharmony_ci case CHIP_GFX1102: 2933bf215546Sopenharmony_ci dec->jpg.direct_reg = true; 2934bf215546Sopenharmony_ci dec->addr_gfx_mode = RDECODE_ARRAY_MODE_ADDRLIB_SEL_GFX11; 2935bf215546Sopenharmony_ci dec->av1_version = RDECODE_AV1_VER_1; 2936bf215546Sopenharmony_ci break; 2937bf215546Sopenharmony_ci default: 2938bf215546Sopenharmony_ci RVID_ERR("VCN is not supported.\n"); 2939bf215546Sopenharmony_ci goto error; 2940bf215546Sopenharmony_ci } 2941bf215546Sopenharmony_ci 2942bf215546Sopenharmony_ci if (dec->stream_type != RDECODE_CODEC_JPEG) { 2943bf215546Sopenharmony_ci map_msg_fb_it_probs_buf(dec); 2944bf215546Sopenharmony_ci rvcn_dec_message_create(dec); 2945bf215546Sopenharmony_ci send_msg_buf(dec); 2946bf215546Sopenharmony_ci r = flush(dec, 0); 2947bf215546Sopenharmony_ci if (r) 2948bf215546Sopenharmony_ci goto error; 2949bf215546Sopenharmony_ci } 2950bf215546Sopenharmony_ci 2951bf215546Sopenharmony_ci next_buffer(dec); 2952bf215546Sopenharmony_ci 2953bf215546Sopenharmony_ci if (stream_type == RDECODE_CODEC_JPEG) 2954bf215546Sopenharmony_ci dec->send_cmd = send_cmd_jpeg; 2955bf215546Sopenharmony_ci else 2956bf215546Sopenharmony_ci dec->send_cmd = send_cmd_dec; 2957bf215546Sopenharmony_ci 2958bf215546Sopenharmony_ci 2959bf215546Sopenharmony_ci if (dec->dpb_type == DPB_DYNAMIC_TIER_2) { 2960bf215546Sopenharmony_ci list_inithead(&dec->dpb_ref_list); 2961bf215546Sopenharmony_ci list_inithead(&dec->dpb_unref_list); 2962bf215546Sopenharmony_ci } 2963bf215546Sopenharmony_ci 2964bf215546Sopenharmony_ci dec->tmz_ctx = sctx->family < CHIP_RENOIR; 2965bf215546Sopenharmony_ci 2966bf215546Sopenharmony_ci return &dec->base; 2967bf215546Sopenharmony_ci 2968bf215546Sopenharmony_cierror: 2969bf215546Sopenharmony_ci dec->ws->cs_destroy(&dec->cs); 2970bf215546Sopenharmony_ci 2971bf215546Sopenharmony_ci if (dec->stream_type == RDECODE_CODEC_JPEG) { 2972bf215546Sopenharmony_ci for (i = 0; i < dec->njctx; i++) { 2973bf215546Sopenharmony_ci dec->ws->cs_destroy(&dec->jcs[i]); 2974bf215546Sopenharmony_ci dec->ws->ctx_destroy(dec->jctx[i]); 2975bf215546Sopenharmony_ci } 2976bf215546Sopenharmony_ci } 2977bf215546Sopenharmony_ci 2978bf215546Sopenharmony_ci for (i = 0; i < NUM_BUFFERS; ++i) { 2979bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->msg_fb_it_probs_buffers[i]); 2980bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->bs_buffers[i]); 2981bf215546Sopenharmony_ci } 2982bf215546Sopenharmony_ci 2983bf215546Sopenharmony_ci if (dec->dpb_type != DPB_DYNAMIC_TIER_2) 2984bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->dpb); 2985bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->ctx); 2986bf215546Sopenharmony_ci si_vid_destroy_buffer(&dec->sessionctx); 2987bf215546Sopenharmony_ci 2988bf215546Sopenharmony_cierr: 2989bf215546Sopenharmony_ci if (dec->jcs) 2990bf215546Sopenharmony_ci FREE(dec->jcs); 2991bf215546Sopenharmony_ci if (dec->jctx) 2992bf215546Sopenharmony_ci FREE(dec->jctx); 2993bf215546Sopenharmony_ci FREE(dec); 2994bf215546Sopenharmony_ci 2995bf215546Sopenharmony_ci return NULL; 2996bf215546Sopenharmony_ci} 2997