1 /**************************************************************************
3 * Copyright 2017 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "pipe/p_video_codec.h"
33 #include "util/u_memory.h"
34 #include "util/u_video.h"
36 #include "vl/vl_mpeg12_decoder.h"
38 #include "radeonsi/si_pipe.h"
39 #include "radeon_video.h"
40 #include "radeon_vcn_dec.h"
41 #include "vl/vl_probs_table.h"
43 #define FB_BUFFER_OFFSET 0x1000
44 #define FB_BUFFER_SIZE 2048
45 #define IT_SCALING_TABLE_SIZE 992
46 #define VP9_PROBS_TABLE_SIZE (RDECODE_VP9_PROBS_DATA_SIZE + 256)
47 #define RDECODE_SESSION_CONTEXT_SIZE (128 * 1024)
49 #define RDECODE_GPCOM_VCPU_CMD 0x2070c
50 #define RDECODE_GPCOM_VCPU_DATA0 0x20710
51 #define RDECODE_GPCOM_VCPU_DATA1 0x20714
52 #define RDECODE_ENGINE_CNTL 0x20718
55 #define NUM_MPEG2_REFS 6
56 #define NUM_H264_REFS 17
57 #define NUM_VC1_REFS 5
58 #define NUM_VP9_REFS 8
60 struct radeon_decoder
{
61 struct pipe_video_codec base
;
63 unsigned stream_handle
;
65 unsigned frame_number
;
67 struct pipe_screen
*screen
;
68 struct radeon_winsys
*ws
;
69 struct radeon_winsys_cs
*cs
;
77 struct rvid_buffer msg_fb_it_probs_buffers
[NUM_BUFFERS
];
78 struct rvid_buffer bs_buffers
[NUM_BUFFERS
];
79 struct rvid_buffer dpb
;
80 struct rvid_buffer ctx
;
81 struct rvid_buffer sessionctx
;
85 void *render_pic_list
[16];
90 static rvcn_dec_message_avc_t
get_h264_msg(struct radeon_decoder
*dec
,
91 struct pipe_h264_picture_desc
*pic
)
93 rvcn_dec_message_avc_t result
;
95 memset(&result
, 0, sizeof(result
));
96 switch (pic
->base
.profile
) {
97 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE
:
98 result
.profile
= RDECODE_H264_PROFILE_BASELINE
;
101 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN
:
102 result
.profile
= RDECODE_H264_PROFILE_MAIN
;
105 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
:
106 result
.profile
= RDECODE_H264_PROFILE_HIGH
;
114 result
.level
= dec
->base
.level
;
116 result
.sps_info_flags
= 0;
117 result
.sps_info_flags
|= pic
->pps
->sps
->direct_8x8_inference_flag
<< 0;
118 result
.sps_info_flags
|= pic
->pps
->sps
->mb_adaptive_frame_field_flag
<< 1;
119 result
.sps_info_flags
|= pic
->pps
->sps
->frame_mbs_only_flag
<< 2;
120 result
.sps_info_flags
|= pic
->pps
->sps
->delta_pic_order_always_zero_flag
<< 3;
121 result
.sps_info_flags
|= 1 << RDECODE_SPS_INFO_H264_EXTENSION_SUPPORT_FLAG_SHIFT
;
123 result
.bit_depth_luma_minus8
= pic
->pps
->sps
->bit_depth_luma_minus8
;
124 result
.bit_depth_chroma_minus8
= pic
->pps
->sps
->bit_depth_chroma_minus8
;
125 result
.log2_max_frame_num_minus4
= pic
->pps
->sps
->log2_max_frame_num_minus4
;
126 result
.pic_order_cnt_type
= pic
->pps
->sps
->pic_order_cnt_type
;
127 result
.log2_max_pic_order_cnt_lsb_minus4
=
128 pic
->pps
->sps
->log2_max_pic_order_cnt_lsb_minus4
;
130 switch (dec
->base
.chroma_format
) {
131 case PIPE_VIDEO_CHROMA_FORMAT_NONE
:
133 case PIPE_VIDEO_CHROMA_FORMAT_400
:
134 result
.chroma_format
= 0;
136 case PIPE_VIDEO_CHROMA_FORMAT_420
:
137 result
.chroma_format
= 1;
139 case PIPE_VIDEO_CHROMA_FORMAT_422
:
140 result
.chroma_format
= 2;
142 case PIPE_VIDEO_CHROMA_FORMAT_444
:
143 result
.chroma_format
= 3;
147 result
.pps_info_flags
= 0;
148 result
.pps_info_flags
|= pic
->pps
->transform_8x8_mode_flag
<< 0;
149 result
.pps_info_flags
|= pic
->pps
->redundant_pic_cnt_present_flag
<< 1;
150 result
.pps_info_flags
|= pic
->pps
->constrained_intra_pred_flag
<< 2;
151 result
.pps_info_flags
|= pic
->pps
->deblocking_filter_control_present_flag
<< 3;
152 result
.pps_info_flags
|= pic
->pps
->weighted_bipred_idc
<< 4;
153 result
.pps_info_flags
|= pic
->pps
->weighted_pred_flag
<< 6;
154 result
.pps_info_flags
|= pic
->pps
->bottom_field_pic_order_in_frame_present_flag
<< 7;
155 result
.pps_info_flags
|= pic
->pps
->entropy_coding_mode_flag
<< 8;
157 result
.num_slice_groups_minus1
= pic
->pps
->num_slice_groups_minus1
;
158 result
.slice_group_map_type
= pic
->pps
->slice_group_map_type
;
159 result
.slice_group_change_rate_minus1
= pic
->pps
->slice_group_change_rate_minus1
;
160 result
.pic_init_qp_minus26
= pic
->pps
->pic_init_qp_minus26
;
161 result
.chroma_qp_index_offset
= pic
->pps
->chroma_qp_index_offset
;
162 result
.second_chroma_qp_index_offset
= pic
->pps
->second_chroma_qp_index_offset
;
164 memcpy(result
.scaling_list_4x4
, pic
->pps
->ScalingList4x4
, 6*16);
165 memcpy(result
.scaling_list_8x8
, pic
->pps
->ScalingList8x8
, 2*64);
167 memcpy(dec
->it
, result
.scaling_list_4x4
, 6*16);
168 memcpy((dec
->it
+ 96), result
.scaling_list_8x8
, 2*64);
170 result
.num_ref_frames
= pic
->num_ref_frames
;
172 result
.num_ref_idx_l0_active_minus1
= pic
->num_ref_idx_l0_active_minus1
;
173 result
.num_ref_idx_l1_active_minus1
= pic
->num_ref_idx_l1_active_minus1
;
175 result
.frame_num
= pic
->frame_num
;
176 memcpy(result
.frame_num_list
, pic
->frame_num_list
, 4*16);
177 result
.curr_field_order_cnt_list
[0] = pic
->field_order_cnt
[0];
178 result
.curr_field_order_cnt_list
[1] = pic
->field_order_cnt
[1];
179 memcpy(result
.field_order_cnt_list
, pic
->field_order_cnt_list
, 4*16*2);
181 result
.decoded_pic_idx
= pic
->frame_num
;
186 static void radeon_dec_destroy_associated_data(void *data
)
188 /* NOOP, since we only use an intptr */
191 static rvcn_dec_message_hevc_t
get_h265_msg(struct radeon_decoder
*dec
,
192 struct pipe_video_buffer
*target
,
193 struct pipe_h265_picture_desc
*pic
)
195 rvcn_dec_message_hevc_t result
;
198 memset(&result
, 0, sizeof(result
));
199 result
.sps_info_flags
= 0;
200 result
.sps_info_flags
|= pic
->pps
->sps
->scaling_list_enabled_flag
<< 0;
201 result
.sps_info_flags
|= pic
->pps
->sps
->amp_enabled_flag
<< 1;
202 result
.sps_info_flags
|= pic
->pps
->sps
->sample_adaptive_offset_enabled_flag
<< 2;
203 result
.sps_info_flags
|= pic
->pps
->sps
->pcm_enabled_flag
<< 3;
204 result
.sps_info_flags
|= pic
->pps
->sps
->pcm_loop_filter_disabled_flag
<< 4;
205 result
.sps_info_flags
|= pic
->pps
->sps
->long_term_ref_pics_present_flag
<< 5;
206 result
.sps_info_flags
|= pic
->pps
->sps
->sps_temporal_mvp_enabled_flag
<< 6;
207 result
.sps_info_flags
|= pic
->pps
->sps
->strong_intra_smoothing_enabled_flag
<< 7;
208 result
.sps_info_flags
|= pic
->pps
->sps
->separate_colour_plane_flag
<< 8;
209 if (((struct si_screen
*)dec
->screen
)->info
.family
== CHIP_CARRIZO
)
210 result
.sps_info_flags
|= 1 << 9;
211 if (pic
->UseRefPicList
== true)
212 result
.sps_info_flags
|= 1 << 10;
214 result
.chroma_format
= pic
->pps
->sps
->chroma_format_idc
;
215 result
.bit_depth_luma_minus8
= pic
->pps
->sps
->bit_depth_luma_minus8
;
216 result
.bit_depth_chroma_minus8
= pic
->pps
->sps
->bit_depth_chroma_minus8
;
217 result
.log2_max_pic_order_cnt_lsb_minus4
= pic
->pps
->sps
->log2_max_pic_order_cnt_lsb_minus4
;
218 result
.sps_max_dec_pic_buffering_minus1
= pic
->pps
->sps
->sps_max_dec_pic_buffering_minus1
;
219 result
.log2_min_luma_coding_block_size_minus3
=
220 pic
->pps
->sps
->log2_min_luma_coding_block_size_minus3
;
221 result
.log2_diff_max_min_luma_coding_block_size
=
222 pic
->pps
->sps
->log2_diff_max_min_luma_coding_block_size
;
223 result
.log2_min_transform_block_size_minus2
=
224 pic
->pps
->sps
->log2_min_transform_block_size_minus2
;
225 result
.log2_diff_max_min_transform_block_size
=
226 pic
->pps
->sps
->log2_diff_max_min_transform_block_size
;
227 result
.max_transform_hierarchy_depth_inter
=
228 pic
->pps
->sps
->max_transform_hierarchy_depth_inter
;
229 result
.max_transform_hierarchy_depth_intra
=
230 pic
->pps
->sps
->max_transform_hierarchy_depth_intra
;
231 result
.pcm_sample_bit_depth_luma_minus1
= pic
->pps
->sps
->pcm_sample_bit_depth_luma_minus1
;
232 result
.pcm_sample_bit_depth_chroma_minus1
=
233 pic
->pps
->sps
->pcm_sample_bit_depth_chroma_minus1
;
234 result
.log2_min_pcm_luma_coding_block_size_minus3
=
235 pic
->pps
->sps
->log2_min_pcm_luma_coding_block_size_minus3
;
236 result
.log2_diff_max_min_pcm_luma_coding_block_size
=
237 pic
->pps
->sps
->log2_diff_max_min_pcm_luma_coding_block_size
;
238 result
.num_short_term_ref_pic_sets
= pic
->pps
->sps
->num_short_term_ref_pic_sets
;
240 result
.pps_info_flags
= 0;
241 result
.pps_info_flags
|= pic
->pps
->dependent_slice_segments_enabled_flag
<< 0;
242 result
.pps_info_flags
|= pic
->pps
->output_flag_present_flag
<< 1;
243 result
.pps_info_flags
|= pic
->pps
->sign_data_hiding_enabled_flag
<< 2;
244 result
.pps_info_flags
|= pic
->pps
->cabac_init_present_flag
<< 3;
245 result
.pps_info_flags
|= pic
->pps
->constrained_intra_pred_flag
<< 4;
246 result
.pps_info_flags
|= pic
->pps
->transform_skip_enabled_flag
<< 5;
247 result
.pps_info_flags
|= pic
->pps
->cu_qp_delta_enabled_flag
<< 6;
248 result
.pps_info_flags
|= pic
->pps
->pps_slice_chroma_qp_offsets_present_flag
<< 7;
249 result
.pps_info_flags
|= pic
->pps
->weighted_pred_flag
<< 8;
250 result
.pps_info_flags
|= pic
->pps
->weighted_bipred_flag
<< 9;
251 result
.pps_info_flags
|= pic
->pps
->transquant_bypass_enabled_flag
<< 10;
252 result
.pps_info_flags
|= pic
->pps
->tiles_enabled_flag
<< 11;
253 result
.pps_info_flags
|= pic
->pps
->entropy_coding_sync_enabled_flag
<< 12;
254 result
.pps_info_flags
|= pic
->pps
->uniform_spacing_flag
<< 13;
255 result
.pps_info_flags
|= pic
->pps
->loop_filter_across_tiles_enabled_flag
<< 14;
256 result
.pps_info_flags
|= pic
->pps
->pps_loop_filter_across_slices_enabled_flag
<< 15;
257 result
.pps_info_flags
|= pic
->pps
->deblocking_filter_override_enabled_flag
<< 16;
258 result
.pps_info_flags
|= pic
->pps
->pps_deblocking_filter_disabled_flag
<< 17;
259 result
.pps_info_flags
|= pic
->pps
->lists_modification_present_flag
<< 18;
260 result
.pps_info_flags
|= pic
->pps
->slice_segment_header_extension_present_flag
<< 19;
262 result
.num_extra_slice_header_bits
= pic
->pps
->num_extra_slice_header_bits
;
263 result
.num_long_term_ref_pic_sps
= pic
->pps
->sps
->num_long_term_ref_pics_sps
;
264 result
.num_ref_idx_l0_default_active_minus1
= pic
->pps
->num_ref_idx_l0_default_active_minus1
;
265 result
.num_ref_idx_l1_default_active_minus1
= pic
->pps
->num_ref_idx_l1_default_active_minus1
;
266 result
.pps_cb_qp_offset
= pic
->pps
->pps_cb_qp_offset
;
267 result
.pps_cr_qp_offset
= pic
->pps
->pps_cr_qp_offset
;
268 result
.pps_beta_offset_div2
= pic
->pps
->pps_beta_offset_div2
;
269 result
.pps_tc_offset_div2
= pic
->pps
->pps_tc_offset_div2
;
270 result
.diff_cu_qp_delta_depth
= pic
->pps
->diff_cu_qp_delta_depth
;
271 result
.num_tile_columns_minus1
= pic
->pps
->num_tile_columns_minus1
;
272 result
.num_tile_rows_minus1
= pic
->pps
->num_tile_rows_minus1
;
273 result
.log2_parallel_merge_level_minus2
= pic
->pps
->log2_parallel_merge_level_minus2
;
274 result
.init_qp_minus26
= pic
->pps
->init_qp_minus26
;
276 for (i
= 0; i
< 19; ++i
)
277 result
.column_width_minus1
[i
] = pic
->pps
->column_width_minus1
[i
];
279 for (i
= 0; i
< 21; ++i
)
280 result
.row_height_minus1
[i
] = pic
->pps
->row_height_minus1
[i
];
282 result
.num_delta_pocs_ref_rps_idx
= pic
->NumDeltaPocsOfRefRpsIdx
;
283 result
.curr_poc
= pic
->CurrPicOrderCntVal
;
285 for (i
= 0 ; i
< 16 ; i
++) {
286 for (j
= 0; (pic
->ref
[j
] != NULL
) && (j
< 16) ; j
++) {
287 if (dec
->render_pic_list
[i
] == pic
->ref
[j
])
290 dec
->render_pic_list
[i
] = NULL
;
291 else if (pic
->ref
[j
+1] == NULL
)
292 dec
->render_pic_list
[i
] = NULL
;
295 for (i
= 0 ; i
< 16 ; i
++) {
296 if (dec
->render_pic_list
[i
] == NULL
) {
297 dec
->render_pic_list
[i
] = target
;
303 vl_video_buffer_set_associated_data(target
, &dec
->base
,
304 (void *)(uintptr_t)result
.curr_idx
,
305 &radeon_dec_destroy_associated_data
);
307 for (i
= 0; i
< 16; ++i
) {
308 struct pipe_video_buffer
*ref
= pic
->ref
[i
];
309 uintptr_t ref_pic
= 0;
311 result
.poc_list
[i
] = pic
->PicOrderCntVal
[i
];
314 ref_pic
= (uintptr_t)vl_video_buffer_get_associated_data(ref
, &dec
->base
);
317 result
.ref_pic_list
[i
] = ref_pic
;
320 for (i
= 0; i
< 8; ++i
) {
321 result
.ref_pic_set_st_curr_before
[i
] = 0xFF;
322 result
.ref_pic_set_st_curr_after
[i
] = 0xFF;
323 result
.ref_pic_set_lt_curr
[i
] = 0xFF;
326 for (i
= 0; i
< pic
->NumPocStCurrBefore
; ++i
)
327 result
.ref_pic_set_st_curr_before
[i
] = pic
->RefPicSetStCurrBefore
[i
];
329 for (i
= 0; i
< pic
->NumPocStCurrAfter
; ++i
)
330 result
.ref_pic_set_st_curr_after
[i
] = pic
->RefPicSetStCurrAfter
[i
];
332 for (i
= 0; i
< pic
->NumPocLtCurr
; ++i
)
333 result
.ref_pic_set_lt_curr
[i
] = pic
->RefPicSetLtCurr
[i
];
335 for (i
= 0; i
< 6; ++i
)
336 result
.ucScalingListDCCoefSizeID2
[i
] = pic
->pps
->sps
->ScalingListDCCoeff16x16
[i
];
338 for (i
= 0; i
< 2; ++i
)
339 result
.ucScalingListDCCoefSizeID3
[i
] = pic
->pps
->sps
->ScalingListDCCoeff32x32
[i
];
341 memcpy(dec
->it
, pic
->pps
->sps
->ScalingList4x4
, 6 * 16);
342 memcpy(dec
->it
+ 96, pic
->pps
->sps
->ScalingList8x8
, 6 * 64);
343 memcpy(dec
->it
+ 480, pic
->pps
->sps
->ScalingList16x16
, 6 * 64);
344 memcpy(dec
->it
+ 864, pic
->pps
->sps
->ScalingList32x32
, 2 * 64);
346 for (i
= 0 ; i
< 2 ; i
++) {
347 for (j
= 0 ; j
< 15 ; j
++)
348 result
.direct_reflist
[i
][j
] = pic
->RefPicList
[i
][j
];
351 if (pic
->base
.profile
== PIPE_VIDEO_PROFILE_HEVC_MAIN_10
) {
352 if (target
->buffer_format
== PIPE_FORMAT_P016
) {
353 result
.p010_mode
= 1;
356 result
.p010_mode
= 0;
357 result
.luma_10to8
= 5;
358 result
.chroma_10to8
= 5;
359 result
.hevc_reserved
[0] = 4; /* sclr_luma10to8 */
360 result
.hevc_reserved
[1] = 4; /* sclr_chroma10to8 */
367 static void fill_probs_table(void *ptr
)
369 rvcn_dec_vp9_probs_t
*probs
= (rvcn_dec_vp9_probs_t
*)ptr
;
371 memcpy(&probs
->coef_probs
[0], default_coef_probs_4x4
, sizeof(default_coef_probs_4x4
));
372 memcpy(&probs
->coef_probs
[1], default_coef_probs_8x8
, sizeof(default_coef_probs_8x8
));
373 memcpy(&probs
->coef_probs
[2], default_coef_probs_16x16
, sizeof(default_coef_probs_16x16
));
374 memcpy(&probs
->coef_probs
[3], default_coef_probs_32x32
, sizeof(default_coef_probs_32x32
));
375 memcpy(probs
->y_mode_prob
, default_if_y_probs
, sizeof(default_if_y_probs
));
376 memcpy(probs
->uv_mode_prob
, default_if_uv_probs
, sizeof(default_if_uv_probs
));
377 memcpy(probs
->single_ref_prob
, default_single_ref_p
, sizeof(default_single_ref_p
));
378 memcpy(probs
->switchable_interp_prob
, default_switchable_interp_prob
, sizeof(default_switchable_interp_prob
));
379 memcpy(probs
->partition_prob
, default_partition_probs
, sizeof(default_partition_probs
));
380 memcpy(probs
->inter_mode_probs
, default_inter_mode_probs
, sizeof(default_inter_mode_probs
));
381 memcpy(probs
->mbskip_probs
, default_skip_probs
, sizeof(default_skip_probs
));
382 memcpy(probs
->intra_inter_prob
, default_intra_inter_p
, sizeof(default_intra_inter_p
));
383 memcpy(probs
->comp_inter_prob
, default_comp_inter_p
, sizeof(default_comp_inter_p
));
384 memcpy(probs
->comp_ref_prob
, default_comp_ref_p
, sizeof(default_comp_ref_p
));
385 memcpy(probs
->tx_probs_32x32
, default_tx_probs_32x32
, sizeof(default_tx_probs_32x32
));
386 memcpy(probs
->tx_probs_16x16
, default_tx_probs_16x16
, sizeof(default_tx_probs_16x16
));
387 memcpy(probs
->tx_probs_8x8
, default_tx_probs_8x8
, sizeof(default_tx_probs_8x8
));
388 memcpy(probs
->mv_joints
, default_nmv_joints
, sizeof(default_nmv_joints
));
389 memcpy(&probs
->mv_comps
[0], default_nmv_components
, sizeof(default_nmv_components
));
390 memset(&probs
->nmvc_mask
, 0, sizeof(rvcn_dec_vp9_nmv_ctx_mask_t
));
393 static rvcn_dec_message_vp9_t
get_vp9_msg(struct radeon_decoder
*dec
,
394 struct pipe_video_buffer
*target
,
395 struct pipe_vp9_picture_desc
*pic
)
397 rvcn_dec_message_vp9_t result
;
400 memset(&result
, 0, sizeof(result
));
403 rvcn_dec_vp9_probs_segment_t
*prbs
= (rvcn_dec_vp9_probs_segment_t
*)(dec
->probs
);
405 if (pic
->picture_parameter
.pic_fields
.segmentation_enabled
) {
406 for (i
= 0; i
< 8; ++i
) {
407 prbs
->seg
.feature_data
[i
] =
408 (pic
->slice_parameter
.seg_param
[i
].alt_quant
& 0xffff) |
409 ((pic
->slice_parameter
.seg_param
[i
].alt_lf
& 0xff) << 16) |
410 ((pic
->slice_parameter
.seg_param
[i
].segment_flags
.segment_reference
& 0xf) << 24);
411 prbs
->seg
.feature_mask
[i
] =
412 (pic
->slice_parameter
.seg_param
[i
].alt_quant_enabled
<< 0) |
413 (pic
->slice_parameter
.seg_param
[i
].alt_lf_enabled
<< 1) |
414 (pic
->slice_parameter
.seg_param
[i
].segment_flags
.segment_reference_enabled
<< 2) |
415 (pic
->slice_parameter
.seg_param
[i
].segment_flags
.segment_reference_skipped
<< 3);
418 for (i
= 0; i
< 7; ++i
)
419 prbs
->seg
.tree_probs
[i
] = pic
->picture_parameter
.mb_segment_tree_probs
[i
];
421 for (i
= 0; i
< 3; ++i
)
422 prbs
->seg
.pred_probs
[i
] = pic
->picture_parameter
.segment_pred_probs
[i
];
424 prbs
->seg
.abs_delta
= 0;
426 memset(&prbs
->seg
, 0, 256);
428 result
.frame_header_flags
=
429 (pic
->picture_parameter
.pic_fields
.frame_type
<<
430 RDECODE_FRAME_HDR_INFO_VP9_FRAME_TYPE_SHIFT
) &
431 RDECODE_FRAME_HDR_INFO_VP9_FRAME_TYPE_MASK
;
433 result
.frame_header_flags
|=
434 (pic
->picture_parameter
.pic_fields
.error_resilient_mode
<<
435 RDECODE_FRAME_HDR_INFO_VP9_ERROR_RESILIENT_MODE_SHIFT
) &
436 RDECODE_FRAME_HDR_INFO_VP9_ERROR_RESILIENT_MODE_MASK
;
438 result
.frame_header_flags
|=
439 (pic
->picture_parameter
.pic_fields
.intra_only
<<
440 RDECODE_FRAME_HDR_INFO_VP9_INTRA_ONLY_SHIFT
) &
441 RDECODE_FRAME_HDR_INFO_VP9_INTRA_ONLY_MASK
;
443 result
.frame_header_flags
|=
444 (pic
->picture_parameter
.pic_fields
.allow_high_precision_mv
<<
445 RDECODE_FRAME_HDR_INFO_VP9_ALLOW_HIGH_PRECISION_MV_SHIFT
) &
446 RDECODE_FRAME_HDR_INFO_VP9_ALLOW_HIGH_PRECISION_MV_MASK
;
448 result
.frame_header_flags
|=
449 (pic
->picture_parameter
.pic_fields
.frame_parallel_decoding_mode
<<
450 RDECODE_FRAME_HDR_INFO_VP9_FRAME_PARALLEL_DECODING_MODE_SHIFT
) &
451 RDECODE_FRAME_HDR_INFO_VP9_FRAME_PARALLEL_DECODING_MODE_MASK
;
453 result
.frame_header_flags
|=
454 (pic
->picture_parameter
.pic_fields
.refresh_frame_context
<<
455 RDECODE_FRAME_HDR_INFO_VP9_REFRESH_FRAME_CONTEXT_SHIFT
) &
456 RDECODE_FRAME_HDR_INFO_VP9_REFRESH_FRAME_CONTEXT_MASK
;
458 result
.frame_header_flags
|=
459 (pic
->picture_parameter
.pic_fields
.segmentation_enabled
<<
460 RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_ENABLED_SHIFT
) &
461 RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_ENABLED_MASK
;
463 result
.frame_header_flags
|=
464 (pic
->picture_parameter
.pic_fields
.segmentation_update_map
<<
465 RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_UPDATE_MAP_SHIFT
) &
466 RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_UPDATE_MAP_MASK
;
468 result
.frame_header_flags
|=
469 (pic
->picture_parameter
.pic_fields
.segmentation_temporal_update
<<
470 RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_TEMPORAL_UPDATE_SHIFT
) &
471 RDECODE_FRAME_HDR_INFO_VP9_SEGMENTATION_TEMPORAL_UPDATE_MASK
;
473 result
.frame_header_flags
|=
474 (pic
->picture_parameter
.mode_ref_delta_enabled
<<
475 RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_ENABLED_SHIFT
) &
476 RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_ENABLED_MASK
;
478 result
.frame_header_flags
|=
479 (pic
->picture_parameter
.mode_ref_delta_update
<<
480 RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_UPDATE_SHIFT
) &
481 RDECODE_FRAME_HDR_INFO_VP9_MODE_REF_DELTA_UPDATE_MASK
;
483 result
.frame_header_flags
|= ((dec
->show_frame
&&
484 !pic
->picture_parameter
.pic_fields
.error_resilient_mode
)
485 << RDECODE_FRAME_HDR_INFO_VP9_USE_PREV_IN_FIND_MV_REFS_SHIFT
) &
486 RDECODE_FRAME_HDR_INFO_VP9_USE_PREV_IN_FIND_MV_REFS_MASK
;
487 dec
->show_frame
= pic
->picture_parameter
.pic_fields
.show_frame
;
489 result
.interp_filter
= pic
->picture_parameter
.pic_fields
.mcomp_filter_type
;
491 result
.frame_context_idx
= pic
->picture_parameter
.pic_fields
.frame_context_idx
;
492 result
.reset_frame_context
= pic
->picture_parameter
.pic_fields
.reset_frame_context
;
494 result
.filter_level
= pic
->picture_parameter
.filter_level
;
495 result
.sharpness_level
= pic
->picture_parameter
.sharpness_level
;
497 for (i
= 0; i
< 8; ++i
)
498 memcpy(result
.lf_adj_level
[i
], pic
->slice_parameter
.seg_param
[i
].filter_level
, 4 * 2);
500 if (pic
->picture_parameter
.pic_fields
.lossless_flag
) {
501 result
.base_qindex
= 0;
502 result
.y_dc_delta_q
= 0;
503 result
.uv_ac_delta_q
= 0;
504 result
.uv_dc_delta_q
= 0;
506 result
.base_qindex
= pic
->picture_parameter
.base_qindex
;
507 result
.y_dc_delta_q
= pic
->picture_parameter
.y_dc_delta_q
;
508 result
.uv_ac_delta_q
= pic
->picture_parameter
.uv_ac_delta_q
;
509 result
.uv_dc_delta_q
= pic
->picture_parameter
.uv_dc_delta_q
;
512 result
.log2_tile_cols
= pic
->picture_parameter
.log2_tile_columns
;
513 result
.log2_tile_rows
= pic
->picture_parameter
.log2_tile_rows
;
514 result
.chroma_format
= 1;
515 result
.bit_depth_luma_minus8
= result
.bit_depth_chroma_minus8
516 = (pic
->picture_parameter
.bit_depth
- 8);
518 result
.vp9_frame_size
= align(dec
->bs_size
, 128);
519 result
.uncompressed_header_size
= pic
->picture_parameter
.frame_header_length_in_bytes
;
520 result
.compressed_header_size
= pic
->picture_parameter
.first_partition_size
;
522 assert(dec
->base
.max_references
+ 1 <= 16);
524 for (i
= 0 ; i
< dec
->base
.max_references
+ 1 ; ++i
) {
525 if (dec
->render_pic_list
[i
] && dec
->render_pic_list
[i
] == target
) {
526 result
.curr_pic_idx
=
527 (uintptr_t)vl_video_buffer_get_associated_data(target
, &dec
->base
);
529 } else if (!dec
->render_pic_list
[i
]) {
530 dec
->render_pic_list
[i
] = target
;
531 result
.curr_pic_idx
= dec
->ref_idx
;
532 vl_video_buffer_set_associated_data(target
, &dec
->base
,
533 (void *)(uintptr_t)dec
->ref_idx
++,
534 &radeon_dec_destroy_associated_data
);
539 for (i
= 0 ; i
< 8; i
++) {
540 result
.ref_frame_map
[i
] = (pic
->ref
[i
]) ?
541 (uintptr_t)vl_video_buffer_get_associated_data(pic
->ref
[i
], &dec
->base
) :
545 result
.frame_refs
[0] = result
.ref_frame_map
[pic
->picture_parameter
.pic_fields
.last_ref_frame
];
546 result
.ref_frame_sign_bias
[0] = pic
->picture_parameter
.pic_fields
.last_ref_frame_sign_bias
;
547 result
.frame_refs
[1] = result
.ref_frame_map
[pic
->picture_parameter
.pic_fields
.golden_ref_frame
];
548 result
.ref_frame_sign_bias
[1] = pic
->picture_parameter
.pic_fields
.golden_ref_frame_sign_bias
;
549 result
.frame_refs
[2] = result
.ref_frame_map
[pic
->picture_parameter
.pic_fields
.alt_ref_frame
];
550 result
.ref_frame_sign_bias
[2] = pic
->picture_parameter
.pic_fields
.alt_ref_frame_sign_bias
;
552 if (pic
->base
.profile
== PIPE_VIDEO_PROFILE_VP9_PROFILE2
) {
553 if (target
->buffer_format
== PIPE_FORMAT_P016
) {
554 result
.p010_mode
= 1;
557 result
.p010_mode
= 0;
558 result
.luma_10to8
= 1;
559 result
.chroma_10to8
= 1;
566 static unsigned calc_ctx_size_h265_main(struct radeon_decoder
*dec
)
568 unsigned width
= align(dec
->base
.width
, VL_MACROBLOCK_WIDTH
);
569 unsigned height
= align(dec
->base
.height
, VL_MACROBLOCK_HEIGHT
);
571 unsigned max_references
= dec
->base
.max_references
+ 1;
573 if (dec
->base
.width
* dec
->base
.height
>= 4096*2000)
574 max_references
= MAX2(max_references
, 8);
576 max_references
= MAX2(max_references
, 17);
578 width
= align (width
, 16);
579 height
= align (height
, 16);
580 return ((width
+ 255) / 16) * ((height
+ 255) / 16) * 16 * max_references
+ 52 * 1024;
583 static unsigned calc_ctx_size_h265_main10(struct radeon_decoder
*dec
, struct pipe_h265_picture_desc
*pic
)
585 unsigned block_size
, log2_ctb_size
, width_in_ctb
, height_in_ctb
, num_16x16_block_per_ctb
;
586 unsigned context_buffer_size_per_ctb_row
, cm_buffer_size
, max_mb_address
, db_left_tile_pxl_size
;
587 unsigned db_left_tile_ctx_size
= 4096 / 16 * (32 + 16 * 4);
589 unsigned width
= align(dec
->base
.width
, VL_MACROBLOCK_WIDTH
);
590 unsigned height
= align(dec
->base
.height
, VL_MACROBLOCK_HEIGHT
);
591 unsigned coeff_10bit
= (pic
->pps
->sps
->bit_depth_luma_minus8
||
592 pic
->pps
->sps
->bit_depth_chroma_minus8
) ? 2 : 1;
594 unsigned max_references
= dec
->base
.max_references
+ 1;
596 if (dec
->base
.width
* dec
->base
.height
>= 4096*2000)
597 max_references
= MAX2(max_references
, 8);
599 max_references
= MAX2(max_references
, 17);
601 block_size
= (1 << (pic
->pps
->sps
->log2_min_luma_coding_block_size_minus3
+ 3));
602 log2_ctb_size
= block_size
+ pic
->pps
->sps
->log2_diff_max_min_luma_coding_block_size
;
604 width_in_ctb
= (width
+ ((1 << log2_ctb_size
) - 1)) >> log2_ctb_size
;
605 height_in_ctb
= (height
+ ((1 << log2_ctb_size
) - 1)) >> log2_ctb_size
;
607 num_16x16_block_per_ctb
= ((1 << log2_ctb_size
) >> 4) * ((1 << log2_ctb_size
) >> 4);
608 context_buffer_size_per_ctb_row
= align(width_in_ctb
* num_16x16_block_per_ctb
* 16, 256);
609 max_mb_address
= (unsigned) ceil(height
* 8 / 2048.0);
611 cm_buffer_size
= max_references
* context_buffer_size_per_ctb_row
* height_in_ctb
;
612 db_left_tile_pxl_size
= coeff_10bit
* (max_mb_address
* 2 * 2048 + 1024);
614 return cm_buffer_size
+ db_left_tile_ctx_size
+ db_left_tile_pxl_size
;
617 static rvcn_dec_message_vc1_t
get_vc1_msg(struct pipe_vc1_picture_desc
*pic
)
619 rvcn_dec_message_vc1_t result
;
621 memset(&result
, 0, sizeof(result
));
622 switch(pic
->base
.profile
) {
623 case PIPE_VIDEO_PROFILE_VC1_SIMPLE
:
624 result
.profile
= RDECODE_VC1_PROFILE_SIMPLE
;
628 case PIPE_VIDEO_PROFILE_VC1_MAIN
:
629 result
.profile
= RDECODE_VC1_PROFILE_MAIN
;
633 case PIPE_VIDEO_PROFILE_VC1_ADVANCED
:
634 result
.profile
= RDECODE_VC1_PROFILE_ADVANCED
;
642 result
.sps_info_flags
|= pic
->postprocflag
<< 7;
643 result
.sps_info_flags
|= pic
->pulldown
<< 6;
644 result
.sps_info_flags
|= pic
->interlace
<< 5;
645 result
.sps_info_flags
|= pic
->tfcntrflag
<< 4;
646 result
.sps_info_flags
|= pic
->finterpflag
<< 3;
647 result
.sps_info_flags
|= pic
->psf
<< 1;
649 result
.pps_info_flags
|= pic
->range_mapy_flag
<< 31;
650 result
.pps_info_flags
|= pic
->range_mapy
<< 28;
651 result
.pps_info_flags
|= pic
->range_mapuv_flag
<< 27;
652 result
.pps_info_flags
|= pic
->range_mapuv
<< 24;
653 result
.pps_info_flags
|= pic
->multires
<< 21;
654 result
.pps_info_flags
|= pic
->maxbframes
<< 16;
655 result
.pps_info_flags
|= pic
->overlap
<< 11;
656 result
.pps_info_flags
|= pic
->quantizer
<< 9;
657 result
.pps_info_flags
|= pic
->panscan_flag
<< 7;
658 result
.pps_info_flags
|= pic
->refdist_flag
<< 6;
659 result
.pps_info_flags
|= pic
->vstransform
<< 0;
661 if (pic
->base
.profile
!= PIPE_VIDEO_PROFILE_VC1_SIMPLE
) {
662 result
.pps_info_flags
|= pic
->syncmarker
<< 20;
663 result
.pps_info_flags
|= pic
->rangered
<< 19;
664 result
.pps_info_flags
|= pic
->loopfilter
<< 5;
665 result
.pps_info_flags
|= pic
->fastuvmc
<< 4;
666 result
.pps_info_flags
|= pic
->extended_mv
<< 3;
667 result
.pps_info_flags
|= pic
->extended_dmv
<< 8;
668 result
.pps_info_flags
|= pic
->dquant
<< 1;
671 result
.chroma_format
= 1;
676 static uint32_t get_ref_pic_idx(struct radeon_decoder
*dec
, struct pipe_video_buffer
*ref
)
678 uint32_t min
= MAX2(dec
->frame_number
, NUM_MPEG2_REFS
) - NUM_MPEG2_REFS
;
679 uint32_t max
= MAX2(dec
->frame_number
, 1) - 1;
682 /* seems to be the most sane fallback */
686 /* get the frame number from the associated data */
687 frame
= (uintptr_t)vl_video_buffer_get_associated_data(ref
, &dec
->base
);
689 /* limit the frame number to a valid range */
690 return MAX2(MIN2(frame
, max
), min
);
693 static rvcn_dec_message_mpeg2_vld_t
get_mpeg2_msg(struct radeon_decoder
*dec
,
694 struct pipe_mpeg12_picture_desc
*pic
)
696 const int *zscan
= pic
->alternate_scan
? vl_zscan_alternate
: vl_zscan_normal
;
697 rvcn_dec_message_mpeg2_vld_t result
;
700 memset(&result
, 0, sizeof(result
));
701 result
.decoded_pic_idx
= dec
->frame_number
;
703 result
.forward_ref_pic_idx
= get_ref_pic_idx(dec
, pic
->ref
[0]);
704 result
.backward_ref_pic_idx
= get_ref_pic_idx(dec
, pic
->ref
[1]);
706 if(pic
->intra_matrix
) {
707 result
.load_intra_quantiser_matrix
= 1;
708 for (i
= 0; i
< 64; ++i
) {
709 result
.intra_quantiser_matrix
[i
] = pic
->intra_matrix
[zscan
[i
]];
712 if(pic
->non_intra_matrix
) {
713 result
.load_nonintra_quantiser_matrix
= 1;
714 for (i
= 0; i
< 64; ++i
) {
715 result
.nonintra_quantiser_matrix
[i
] = pic
->non_intra_matrix
[zscan
[i
]];
719 result
.profile_and_level_indication
= 0;
720 result
.chroma_format
= 0x1;
722 result
.picture_coding_type
= pic
->picture_coding_type
;
723 result
.f_code
[0][0] = pic
->f_code
[0][0] + 1;
724 result
.f_code
[0][1] = pic
->f_code
[0][1] + 1;
725 result
.f_code
[1][0] = pic
->f_code
[1][0] + 1;
726 result
.f_code
[1][1] = pic
->f_code
[1][1] + 1;
727 result
.intra_dc_precision
= pic
->intra_dc_precision
;
728 result
.pic_structure
= pic
->picture_structure
;
729 result
.top_field_first
= pic
->top_field_first
;
730 result
.frame_pred_frame_dct
= pic
->frame_pred_frame_dct
;
731 result
.concealment_motion_vectors
= pic
->concealment_motion_vectors
;
732 result
.q_scale_type
= pic
->q_scale_type
;
733 result
.intra_vlc_format
= pic
->intra_vlc_format
;
734 result
.alternate_scan
= pic
->alternate_scan
;
739 static rvcn_dec_message_mpeg4_asp_vld_t
get_mpeg4_msg(struct radeon_decoder
*dec
,
740 struct pipe_mpeg4_picture_desc
*pic
)
742 rvcn_dec_message_mpeg4_asp_vld_t result
;
745 memset(&result
, 0, sizeof(result
));
746 result
.decoded_pic_idx
= dec
->frame_number
;
748 result
.forward_ref_pic_idx
= get_ref_pic_idx(dec
, pic
->ref
[0]);
749 result
.backward_ref_pic_idx
= get_ref_pic_idx(dec
, pic
->ref
[1]);
751 result
.variant_type
= 0;
752 result
.profile_and_level_indication
= 0xF0;
754 result
.video_object_layer_verid
= 0x5;
755 result
.video_object_layer_shape
= 0x0;
757 result
.video_object_layer_width
= dec
->base
.width
;
758 result
.video_object_layer_height
= dec
->base
.height
;
760 result
.vop_time_increment_resolution
= pic
->vop_time_increment_resolution
;
762 result
.short_video_header
= pic
->short_video_header
;
763 result
.interlaced
= pic
->interlaced
;
764 result
.load_intra_quant_mat
= 1;
765 result
.load_nonintra_quant_mat
= 1;
766 result
.quarter_sample
= pic
->quarter_sample
;
767 result
.complexity_estimation_disable
= 1;
768 result
.resync_marker_disable
= pic
->resync_marker_disable
;
769 result
.newpred_enable
= 0;
770 result
.reduced_resolution_vop_enable
= 0;
772 result
.quant_type
= pic
->quant_type
;
774 for (i
= 0; i
< 64; ++i
) {
775 result
.intra_quant_mat
[i
] = pic
->intra_matrix
[vl_zscan_normal
[i
]];
776 result
.nonintra_quant_mat
[i
] = pic
->non_intra_matrix
[vl_zscan_normal
[i
]];
782 static void rvcn_dec_message_create(struct radeon_decoder
*dec
)
784 rvcn_dec_message_header_t
*header
= dec
->msg
;
785 rvcn_dec_message_create_t
*create
= dec
->msg
+ sizeof(rvcn_dec_message_header_t
);
786 unsigned sizes
= sizeof(rvcn_dec_message_header_t
) + sizeof(rvcn_dec_message_create_t
);
788 memset(dec
->msg
, 0, sizes
);
789 header
->header_size
= sizeof(rvcn_dec_message_header_t
);
790 header
->total_size
= sizes
;
791 header
->num_buffers
= 1;
792 header
->msg_type
= RDECODE_MSG_CREATE
;
793 header
->stream_handle
= dec
->stream_handle
;
794 header
->status_report_feedback_number
= 0;
796 header
->index
[0].message_id
= RDECODE_MESSAGE_CREATE
;
797 header
->index
[0].offset
= sizeof(rvcn_dec_message_header_t
);
798 header
->index
[0].size
= sizeof(rvcn_dec_message_create_t
);
799 header
->index
[0].filled
= 0;
801 create
->stream_type
= dec
->stream_type
;
802 create
->session_flags
= 0;
803 create
->width_in_samples
= dec
->base
.width
;
804 create
->height_in_samples
= dec
->base
.height
;
807 static struct pb_buffer
*rvcn_dec_message_decode(struct radeon_decoder
*dec
,
808 struct pipe_video_buffer
*target
,
809 struct pipe_picture_desc
*picture
)
811 struct r600_texture
*luma
= (struct r600_texture
*)
812 ((struct vl_video_buffer
*)target
)->resources
[0];
813 struct r600_texture
*chroma
= (struct r600_texture
*)
814 ((struct vl_video_buffer
*)target
)->resources
[1];
815 rvcn_dec_message_header_t
*header
;
816 rvcn_dec_message_index_t
*index
;
817 rvcn_dec_message_decode_t
*decode
;
818 unsigned sizes
= 0, offset_decode
, offset_codec
;
822 sizes
+= sizeof(rvcn_dec_message_header_t
);
823 index
= (void*)header
+ sizeof(rvcn_dec_message_header_t
);
824 sizes
+= sizeof(rvcn_dec_message_index_t
);
825 offset_decode
= sizes
;
826 decode
= (void*)index
+ sizeof(rvcn_dec_message_index_t
);
827 sizes
+= sizeof(rvcn_dec_message_decode_t
);
828 offset_codec
= sizes
;
829 codec
= (void*)decode
+ sizeof(rvcn_dec_message_decode_t
);
831 memset(dec
->msg
, 0, sizes
);
832 header
->header_size
= sizeof(rvcn_dec_message_header_t
);
833 header
->total_size
= sizes
;
834 header
->num_buffers
= 2;
835 header
->msg_type
= RDECODE_MSG_DECODE
;
836 header
->stream_handle
= dec
->stream_handle
;
837 header
->status_report_feedback_number
= dec
->frame_number
;
839 header
->index
[0].message_id
= RDECODE_MESSAGE_DECODE
;
840 header
->index
[0].offset
= offset_decode
;
841 header
->index
[0].size
= sizeof(rvcn_dec_message_decode_t
);
842 header
->index
[0].filled
= 0;
844 index
->offset
= offset_codec
;
845 index
->size
= sizeof(rvcn_dec_message_avc_t
);
848 decode
->stream_type
= dec
->stream_type
;
849 decode
->decode_flags
= 0x1;
850 decode
->width_in_samples
= dec
->base
.width
;
851 decode
->height_in_samples
= dec
->base
.height
;
853 decode
->bsd_size
= align(dec
->bs_size
, 128);
854 decode
->dpb_size
= dec
->dpb
.res
->buf
->size
;
856 r600_resource(((struct vl_video_buffer
*)target
)->resources
[0])->buf
->size
+
857 r600_resource(((struct vl_video_buffer
*)target
)->resources
[1])->buf
->size
;
859 decode
->sct_size
= 0;
860 decode
->sc_coeff_size
= 0;
862 decode
->sw_ctxt_size
= RDECODE_SESSION_CONTEXT_SIZE
;
863 decode
->db_pitch
= align(dec
->base
.width
, 32);
864 decode
->db_surf_tile_config
= 0;
866 decode
->dt_pitch
= luma
->surface
.u
.gfx9
.surf_pitch
* luma
->surface
.blk_w
;
867 decode
->dt_uv_pitch
= decode
->dt_pitch
/ 2;
869 decode
->dt_tiling_mode
= 0;
870 decode
->dt_swizzle_mode
= RDECODE_SW_MODE_LINEAR
;
871 decode
->dt_array_mode
= RDECODE_ARRAY_MODE_LINEAR
;
872 decode
->dt_field_mode
= ((struct vl_video_buffer
*)target
)->base
.interlaced
;
873 decode
->dt_surf_tile_config
= 0;
874 decode
->dt_uv_surf_tile_config
= 0;
876 decode
->dt_luma_top_offset
= luma
->surface
.u
.gfx9
.surf_offset
;
877 decode
->dt_chroma_top_offset
= chroma
->surface
.u
.gfx9
.surf_offset
;
878 if (decode
->dt_field_mode
) {
879 decode
->dt_luma_bottom_offset
= luma
->surface
.u
.gfx9
.surf_offset
+
880 luma
->surface
.u
.gfx9
.surf_slice_size
;
881 decode
->dt_chroma_bottom_offset
= chroma
->surface
.u
.gfx9
.surf_offset
+
882 chroma
->surface
.u
.gfx9
.surf_slice_size
;
884 decode
->dt_luma_bottom_offset
= decode
->dt_luma_top_offset
;
885 decode
->dt_chroma_bottom_offset
= decode
->dt_chroma_top_offset
;
888 switch (u_reduce_video_profile(picture
->profile
)) {
889 case PIPE_VIDEO_FORMAT_MPEG4_AVC
: {
890 rvcn_dec_message_avc_t avc
=
891 get_h264_msg(dec
, (struct pipe_h264_picture_desc
*)picture
);
892 memcpy(codec
, (void*)&avc
, sizeof(rvcn_dec_message_avc_t
));
893 index
->message_id
= RDECODE_MESSAGE_AVC
;
896 case PIPE_VIDEO_FORMAT_HEVC
: {
897 rvcn_dec_message_hevc_t hevc
=
898 get_h265_msg(dec
, target
, (struct pipe_h265_picture_desc
*)picture
);
900 memcpy(codec
, (void*)&hevc
, sizeof(rvcn_dec_message_hevc_t
));
901 index
->message_id
= RDECODE_MESSAGE_HEVC
;
902 if (dec
->ctx
.res
== NULL
) {
904 if (dec
->base
.profile
== PIPE_VIDEO_PROFILE_HEVC_MAIN_10
)
905 ctx_size
= calc_ctx_size_h265_main10(dec
,
906 (struct pipe_h265_picture_desc
*)picture
);
908 ctx_size
= calc_ctx_size_h265_main(dec
);
909 if (!si_vid_create_buffer(dec
->screen
, &dec
->ctx
, ctx_size
, PIPE_USAGE_DEFAULT
))
910 RVID_ERR("Can't allocated context buffer.\n");
911 si_vid_clear_buffer(dec
->base
.context
, &dec
->ctx
);
915 case PIPE_VIDEO_FORMAT_VC1
: {
916 rvcn_dec_message_vc1_t vc1
= get_vc1_msg((struct pipe_vc1_picture_desc
*)picture
);
918 memcpy(codec
, (void*)&vc1
, sizeof(rvcn_dec_message_vc1_t
));
919 if ((picture
->profile
== PIPE_VIDEO_PROFILE_VC1_SIMPLE
) ||
920 (picture
->profile
== PIPE_VIDEO_PROFILE_VC1_MAIN
)) {
921 decode
->width_in_samples
= align(decode
->width_in_samples
, 16) / 16;
922 decode
->height_in_samples
= align(decode
->height_in_samples
, 16) / 16;
924 index
->message_id
= RDECODE_MESSAGE_VC1
;
928 case PIPE_VIDEO_FORMAT_MPEG12
: {
929 rvcn_dec_message_mpeg2_vld_t mpeg2
=
930 get_mpeg2_msg(dec
, (struct pipe_mpeg12_picture_desc
*)picture
);
932 memcpy(codec
, (void*)&mpeg2
, sizeof(rvcn_dec_message_mpeg2_vld_t
));
933 index
->message_id
= RDECODE_MESSAGE_MPEG2_VLD
;
936 case PIPE_VIDEO_FORMAT_MPEG4
: {
937 rvcn_dec_message_mpeg4_asp_vld_t mpeg4
=
938 get_mpeg4_msg(dec
, (struct pipe_mpeg4_picture_desc
*)picture
);
940 memcpy(codec
, (void*)&mpeg4
, sizeof(rvcn_dec_message_mpeg4_asp_vld_t
));
941 index
->message_id
= RDECODE_MESSAGE_MPEG4_ASP_VLD
;
944 case PIPE_VIDEO_FORMAT_VP9
: {
945 rvcn_dec_message_vp9_t vp9
=
946 get_vp9_msg(dec
, target
, (struct pipe_vp9_picture_desc
*)picture
);
948 memcpy(codec
, (void*)&vp9
, sizeof(rvcn_dec_message_vp9_t
));
949 index
->message_id
= RDECODE_MESSAGE_VP9
;
951 if (dec
->ctx
.res
== NULL
) {
955 /* default probability + probability data */
958 /* SRE collocated context data */
959 ctx_size
+= 32 * 2 * 64 * 64;
961 /* SMP collocated context data */
962 ctx_size
+= 9 * 64 * 2 * 64 * 64;
964 /* SDB left tile pixel */
965 ctx_size
+= 8 * 2 * 4096;
967 if (dec
->base
.profile
== PIPE_VIDEO_PROFILE_VP9_PROFILE2
)
968 ctx_size
+= 8 * 2 * 4096;
970 if (!si_vid_create_buffer(dec
->screen
, &dec
->ctx
, ctx_size
, PIPE_USAGE_DEFAULT
))
971 RVID_ERR("Can't allocated context buffer.\n");
972 si_vid_clear_buffer(dec
->base
.context
, &dec
->ctx
);
974 /* ctx needs probs table */
975 ptr
= dec
->ws
->buffer_map(dec
->ctx
.res
->buf
, dec
->cs
, PIPE_TRANSFER_WRITE
);
976 fill_probs_table(ptr
);
977 dec
->ws
->buffer_unmap(dec
->ctx
.res
->buf
);
987 decode
->hw_ctxt_size
= dec
->ctx
.res
->buf
->size
;
989 return luma
->resource
.buf
;
992 static void rvcn_dec_message_destroy(struct radeon_decoder
*dec
)
994 rvcn_dec_message_header_t
*header
= dec
->msg
;
996 memset(dec
->msg
, 0, sizeof(rvcn_dec_message_header_t
));
997 header
->header_size
= sizeof(rvcn_dec_message_header_t
);
998 header
->total_size
= sizeof(rvcn_dec_message_header_t
) -
999 sizeof(rvcn_dec_message_index_t
);
1000 header
->num_buffers
= 0;
1001 header
->msg_type
= RDECODE_MSG_DESTROY
;
1002 header
->stream_handle
= dec
->stream_handle
;
1003 header
->status_report_feedback_number
= 0;
1006 static void rvcn_dec_message_feedback(struct radeon_decoder
*dec
)
1008 rvcn_dec_feedback_header_t
*header
= (void*)dec
->fb
;
1010 header
->header_size
= sizeof(rvcn_dec_feedback_header_t
);
1011 header
->total_size
= sizeof(rvcn_dec_feedback_header_t
);
1012 header
->num_buffers
= 0;
1015 /* flush IB to the hardware */
1016 static int flush(struct radeon_decoder
*dec
, unsigned flags
)
1018 return dec
->ws
->cs_flush(dec
->cs
, flags
, NULL
);
1021 /* add a new set register command to the IB */
1022 static void set_reg(struct radeon_decoder
*dec
, unsigned reg
, uint32_t val
)
1024 radeon_emit(dec
->cs
, RDECODE_PKT0(reg
>> 2, 0));
1025 radeon_emit(dec
->cs
, val
);
1028 /* send a command to the VCPU through the GPCOM registers */
1029 static void send_cmd(struct radeon_decoder
*dec
, unsigned cmd
,
1030 struct pb_buffer
* buf
, uint32_t off
,
1031 enum radeon_bo_usage usage
, enum radeon_bo_domain domain
)
1035 dec
->ws
->cs_add_buffer(dec
->cs
, buf
, usage
| RADEON_USAGE_SYNCHRONIZED
,
1036 domain
, RADEON_PRIO_UVD
);
1037 addr
= dec
->ws
->buffer_get_virtual_address(buf
);
1040 set_reg(dec
, RDECODE_GPCOM_VCPU_DATA0
, addr
);
1041 set_reg(dec
, RDECODE_GPCOM_VCPU_DATA1
, addr
>> 32);
1042 set_reg(dec
, RDECODE_GPCOM_VCPU_CMD
, cmd
<< 1);
1045 /* do the codec needs an IT buffer ?*/
1046 static bool have_it(struct radeon_decoder
*dec
)
1048 return dec
->stream_type
== RDECODE_CODEC_H264_PERF
||
1049 dec
->stream_type
== RDECODE_CODEC_H265
;
1052 /* do the codec needs an probs buffer? */
1053 static bool have_probs(struct radeon_decoder
*dec
)
1055 return dec
->stream_type
== RDECODE_CODEC_VP9
;
1058 /* map the next available message/feedback/itscaling buffer */
1059 static void map_msg_fb_it_probs_buf(struct radeon_decoder
*dec
)
1061 struct rvid_buffer
* buf
;
1064 /* grab the current message/feedback buffer */
1065 buf
= &dec
->msg_fb_it_probs_buffers
[dec
->cur_buffer
];
1067 /* and map it for CPU access */
1068 ptr
= dec
->ws
->buffer_map(buf
->res
->buf
, dec
->cs
, PIPE_TRANSFER_WRITE
);
1070 /* calc buffer offsets */
1073 dec
->fb
= (uint32_t *)(ptr
+ FB_BUFFER_OFFSET
);
1075 dec
->it
= (uint8_t *)(ptr
+ FB_BUFFER_OFFSET
+ FB_BUFFER_SIZE
);
1076 else if (have_probs(dec
))
1077 dec
->probs
= (uint8_t *)(ptr
+ FB_BUFFER_OFFSET
+ FB_BUFFER_SIZE
);
1080 /* unmap and send a message command to the VCPU */
1081 static void send_msg_buf(struct radeon_decoder
*dec
)
1083 struct rvid_buffer
* buf
;
1085 /* ignore the request if message/feedback buffer isn't mapped */
1086 if (!dec
->msg
|| !dec
->fb
)
1089 /* grab the current message buffer */
1090 buf
= &dec
->msg_fb_it_probs_buffers
[dec
->cur_buffer
];
1092 /* unmap the buffer */
1093 dec
->ws
->buffer_unmap(buf
->res
->buf
);
1099 if (dec
->sessionctx
.res
)
1100 send_cmd(dec
, RDECODE_CMD_SESSION_CONTEXT_BUFFER
,
1101 dec
->sessionctx
.res
->buf
, 0, RADEON_USAGE_READWRITE
,
1102 RADEON_DOMAIN_VRAM
);
1104 /* and send it to the hardware */
1105 send_cmd(dec
, RDECODE_CMD_MSG_BUFFER
, buf
->res
->buf
, 0,
1106 RADEON_USAGE_READ
, RADEON_DOMAIN_GTT
);
1109 /* cycle to the next set of buffers */
1110 static void next_buffer(struct radeon_decoder
*dec
)
1113 dec
->cur_buffer
%= NUM_BUFFERS
;
1116 static unsigned calc_ctx_size_h264_perf(struct radeon_decoder
*dec
)
1118 unsigned width_in_mb
, height_in_mb
, ctx_size
;
1119 unsigned width
= align(dec
->base
.width
, VL_MACROBLOCK_WIDTH
);
1120 unsigned height
= align(dec
->base
.height
, VL_MACROBLOCK_HEIGHT
);
1122 unsigned max_references
= dec
->base
.max_references
+ 1;
1124 // picture width & height in 16 pixel units
1125 width_in_mb
= width
/ VL_MACROBLOCK_WIDTH
;
1126 height_in_mb
= align(height
/ VL_MACROBLOCK_HEIGHT
, 2);
1128 unsigned fs_in_mb
= width_in_mb
* height_in_mb
;
1129 unsigned num_dpb_buffer
;
1130 switch(dec
->base
.level
) {
1132 num_dpb_buffer
= 8100 / fs_in_mb
;
1135 num_dpb_buffer
= 18000 / fs_in_mb
;
1138 num_dpb_buffer
= 20480 / fs_in_mb
;
1141 num_dpb_buffer
= 32768 / fs_in_mb
;
1144 num_dpb_buffer
= 34816 / fs_in_mb
;
1147 num_dpb_buffer
= 110400 / fs_in_mb
;
1150 num_dpb_buffer
= 184320 / fs_in_mb
;
1153 num_dpb_buffer
= 184320 / fs_in_mb
;
1157 max_references
= MAX2(MIN2(NUM_H264_REFS
, num_dpb_buffer
), max_references
);
1158 ctx_size
= max_references
* align(width_in_mb
* height_in_mb
* 192, 256);
1163 /* calculate size of reference picture buffer */
1164 static unsigned calc_dpb_size(struct radeon_decoder
*dec
)
1166 unsigned width_in_mb
, height_in_mb
, image_size
, dpb_size
;
1168 // always align them to MB size for dpb calculation
1169 unsigned width
= align(dec
->base
.width
, VL_MACROBLOCK_WIDTH
);
1170 unsigned height
= align(dec
->base
.height
, VL_MACROBLOCK_HEIGHT
);
1172 // always one more for currently decoded picture
1173 unsigned max_references
= dec
->base
.max_references
+ 1;
1175 // aligned size of a single frame
1176 image_size
= align(width
, 32) * height
;
1177 image_size
+= image_size
/ 2;
1178 image_size
= align(image_size
, 1024);
1180 // picture width & height in 16 pixel units
1181 width_in_mb
= width
/ VL_MACROBLOCK_WIDTH
;
1182 height_in_mb
= align(height
/ VL_MACROBLOCK_HEIGHT
, 2);
1184 switch (u_reduce_video_profile(dec
->base
.profile
)) {
1185 case PIPE_VIDEO_FORMAT_MPEG4_AVC
: {
1186 unsigned fs_in_mb
= width_in_mb
* height_in_mb
;
1187 unsigned num_dpb_buffer
;
1189 switch(dec
->base
.level
) {
1191 num_dpb_buffer
= 8100 / fs_in_mb
;
1194 num_dpb_buffer
= 18000 / fs_in_mb
;
1197 num_dpb_buffer
= 20480 / fs_in_mb
;
1200 num_dpb_buffer
= 32768 / fs_in_mb
;
1203 num_dpb_buffer
= 34816 / fs_in_mb
;
1206 num_dpb_buffer
= 110400 / fs_in_mb
;
1209 num_dpb_buffer
= 184320 / fs_in_mb
;
1212 num_dpb_buffer
= 184320 / fs_in_mb
;
1216 max_references
= MAX2(MIN2(NUM_H264_REFS
, num_dpb_buffer
), max_references
);
1217 dpb_size
= image_size
* max_references
;
1221 case PIPE_VIDEO_FORMAT_HEVC
:
1222 if (dec
->base
.width
* dec
->base
.height
>= 4096*2000)
1223 max_references
= MAX2(max_references
, 8);
1225 max_references
= MAX2(max_references
, 17);
1227 width
= align (width
, 16);
1228 height
= align (height
, 16);
1229 if (dec
->base
.profile
== PIPE_VIDEO_PROFILE_HEVC_MAIN_10
)
1230 dpb_size
= align((align(width
, 32) * height
* 9) / 4, 256) * max_references
;
1232 dpb_size
= align((align(width
, 32) * height
* 3) / 2, 256) * max_references
;
1235 case PIPE_VIDEO_FORMAT_VC1
:
1236 // the firmware seems to allways assume a minimum of ref frames
1237 max_references
= MAX2(NUM_VC1_REFS
, max_references
);
1239 // reference picture buffer
1240 dpb_size
= image_size
* max_references
;
1243 dpb_size
+= width_in_mb
* height_in_mb
* 128;
1245 // IT surface buffer
1246 dpb_size
+= width_in_mb
* 64;
1248 // DB surface buffer
1249 dpb_size
+= width_in_mb
* 128;
1252 dpb_size
+= align(MAX2(width_in_mb
, height_in_mb
) * 7 * 16, 64);
1255 case PIPE_VIDEO_FORMAT_MPEG12
:
1256 // reference picture buffer, must be big enough for all frames
1257 dpb_size
= image_size
* NUM_MPEG2_REFS
;
1260 case PIPE_VIDEO_FORMAT_MPEG4
:
1261 // reference picture buffer
1262 dpb_size
= image_size
* max_references
;
1265 dpb_size
+= width_in_mb
* height_in_mb
* 64;
1267 // IT surface buffer
1268 dpb_size
+= align(width_in_mb
* height_in_mb
* 32, 64);
1270 dpb_size
= MAX2(dpb_size
, 30 * 1024 * 1024);
1273 case PIPE_VIDEO_FORMAT_VP9
:
1274 max_references
= MAX2(max_references
, 9);
1276 dpb_size
= (4096 * 3000 * 3 / 2) * max_references
;
1277 if (dec
->base
.profile
== PIPE_VIDEO_PROFILE_VP9_PROFILE2
)
1278 dpb_size
*= (3 / 2);
1282 // something is missing here
1285 // at least use a sane default value
1286 dpb_size
= 32 * 1024 * 1024;
1293 * destroy this video decoder
1295 static void radeon_dec_destroy(struct pipe_video_codec
*decoder
)
1297 struct radeon_decoder
*dec
= (struct radeon_decoder
*)decoder
;
1302 map_msg_fb_it_probs_buf(dec
);
1303 rvcn_dec_message_destroy(dec
);
1308 dec
->ws
->cs_destroy(dec
->cs
);
1310 for (i
= 0; i
< NUM_BUFFERS
; ++i
) {
1311 si_vid_destroy_buffer(&dec
->msg_fb_it_probs_buffers
[i
]);
1312 si_vid_destroy_buffer(&dec
->bs_buffers
[i
]);
1315 si_vid_destroy_buffer(&dec
->dpb
);
1316 si_vid_destroy_buffer(&dec
->ctx
);
1317 si_vid_destroy_buffer(&dec
->sessionctx
);
1323 * start decoding of a new frame
1325 static void radeon_dec_begin_frame(struct pipe_video_codec
*decoder
,
1326 struct pipe_video_buffer
*target
,
1327 struct pipe_picture_desc
*picture
)
1329 struct radeon_decoder
*dec
= (struct radeon_decoder
*)decoder
;
1334 frame
= ++dec
->frame_number
;
1335 if (dec
->stream_type
!= RDECODE_CODEC_VP9
)
1336 vl_video_buffer_set_associated_data(target
, decoder
, (void *)frame
,
1337 &radeon_dec_destroy_associated_data
);
1340 dec
->bs_ptr
= dec
->ws
->buffer_map(
1341 dec
->bs_buffers
[dec
->cur_buffer
].res
->buf
,
1342 dec
->cs
, PIPE_TRANSFER_WRITE
);
1346 * decode a macroblock
1348 static void radeon_dec_decode_macroblock(struct pipe_video_codec
*decoder
,
1349 struct pipe_video_buffer
*target
,
1350 struct pipe_picture_desc
*picture
,
1351 const struct pipe_macroblock
*macroblocks
,
1352 unsigned num_macroblocks
)
1354 /* not supported (yet) */
1359 * decode a bitstream
1361 static void radeon_dec_decode_bitstream(struct pipe_video_codec
*decoder
,
1362 struct pipe_video_buffer
*target
,
1363 struct pipe_picture_desc
*picture
,
1364 unsigned num_buffers
,
1365 const void * const *buffers
,
1366 const unsigned *sizes
)
1368 struct radeon_decoder
*dec
= (struct radeon_decoder
*)decoder
;
1376 for (i
= 0; i
< num_buffers
; ++i
) {
1377 struct rvid_buffer
*buf
= &dec
->bs_buffers
[dec
->cur_buffer
];
1378 unsigned new_size
= dec
->bs_size
+ sizes
[i
];
1380 if (new_size
> buf
->res
->buf
->size
) {
1381 dec
->ws
->buffer_unmap(buf
->res
->buf
);
1382 if (!si_vid_resize_buffer(dec
->screen
, dec
->cs
, buf
, new_size
)) {
1383 RVID_ERR("Can't resize bitstream buffer!");
1387 dec
->bs_ptr
= dec
->ws
->buffer_map(buf
->res
->buf
, dec
->cs
,
1388 PIPE_TRANSFER_WRITE
);
1392 dec
->bs_ptr
+= dec
->bs_size
;
1395 memcpy(dec
->bs_ptr
, buffers
[i
], sizes
[i
]);
1396 dec
->bs_size
+= sizes
[i
];
1397 dec
->bs_ptr
+= sizes
[i
];
1402 * end decoding of the current frame
1404 static void radeon_dec_end_frame(struct pipe_video_codec
*decoder
,
1405 struct pipe_video_buffer
*target
,
1406 struct pipe_picture_desc
*picture
)
1408 struct radeon_decoder
*dec
= (struct radeon_decoder
*)decoder
;
1409 struct pb_buffer
*dt
;
1410 struct rvid_buffer
*msg_fb_it_probs_buf
, *bs_buf
;
1417 msg_fb_it_probs_buf
= &dec
->msg_fb_it_probs_buffers
[dec
->cur_buffer
];
1418 bs_buf
= &dec
->bs_buffers
[dec
->cur_buffer
];
1420 memset(dec
->bs_ptr
, 0, align(dec
->bs_size
, 128) - dec
->bs_size
);
1421 dec
->ws
->buffer_unmap(bs_buf
->res
->buf
);
1423 map_msg_fb_it_probs_buf(dec
);
1424 dt
= rvcn_dec_message_decode(dec
, target
, picture
);
1425 rvcn_dec_message_feedback(dec
);
1428 send_cmd(dec
, RDECODE_CMD_DPB_BUFFER
, dec
->dpb
.res
->buf
, 0,
1429 RADEON_USAGE_READWRITE
, RADEON_DOMAIN_VRAM
);
1431 send_cmd(dec
, RDECODE_CMD_CONTEXT_BUFFER
, dec
->ctx
.res
->buf
, 0,
1432 RADEON_USAGE_READWRITE
, RADEON_DOMAIN_VRAM
);
1433 send_cmd(dec
, RDECODE_CMD_BITSTREAM_BUFFER
, bs_buf
->res
->buf
,
1434 0, RADEON_USAGE_READ
, RADEON_DOMAIN_GTT
);
1435 send_cmd(dec
, RDECODE_CMD_DECODING_TARGET_BUFFER
, dt
, 0,
1436 RADEON_USAGE_WRITE
, RADEON_DOMAIN_VRAM
);
1437 send_cmd(dec
, RDECODE_CMD_FEEDBACK_BUFFER
, msg_fb_it_probs_buf
->res
->buf
,
1438 FB_BUFFER_OFFSET
, RADEON_USAGE_WRITE
, RADEON_DOMAIN_GTT
);
1440 send_cmd(dec
, RDECODE_CMD_IT_SCALING_TABLE_BUFFER
, msg_fb_it_probs_buf
->res
->buf
,
1441 FB_BUFFER_OFFSET
+ FB_BUFFER_SIZE
, RADEON_USAGE_READ
, RADEON_DOMAIN_GTT
);
1442 else if (have_probs(dec
))
1443 send_cmd(dec
, RDECODE_CMD_PROB_TBL_BUFFER
, msg_fb_it_probs_buf
->res
->buf
,
1444 FB_BUFFER_OFFSET
+ FB_BUFFER_SIZE
, RADEON_USAGE_READ
, RADEON_DOMAIN_GTT
);
1445 set_reg(dec
, RDECODE_ENGINE_CNTL
, 1);
1447 flush(dec
, PIPE_FLUSH_ASYNC
);
1452 * flush any outstanding command buffers to the hardware
1454 static void radeon_dec_flush(struct pipe_video_codec
*decoder
)
1459 * create and HW decoder
1461 struct pipe_video_codec
*radeon_create_decoder(struct pipe_context
*context
,
1462 const struct pipe_video_codec
*templ
)
1464 struct si_context
*sctx
= (struct si_context
*)context
;
1465 struct radeon_winsys
*ws
= sctx
->ws
;
1466 unsigned width
= templ
->width
, height
= templ
->height
;
1467 unsigned dpb_size
, bs_buf_size
, stream_type
= 0;
1468 struct radeon_decoder
*dec
;
1471 switch(u_reduce_video_profile(templ
->profile
)) {
1472 case PIPE_VIDEO_FORMAT_MPEG12
:
1473 if (templ
->entrypoint
> PIPE_VIDEO_ENTRYPOINT_BITSTREAM
)
1474 return vl_create_mpeg12_decoder(context
, templ
);
1475 stream_type
= RDECODE_CODEC_MPEG2_VLD
;
1477 case PIPE_VIDEO_FORMAT_MPEG4
:
1478 width
= align(width
, VL_MACROBLOCK_WIDTH
);
1479 height
= align(height
, VL_MACROBLOCK_HEIGHT
);
1480 stream_type
= RDECODE_CODEC_MPEG4
;
1482 case PIPE_VIDEO_FORMAT_VC1
:
1483 stream_type
= RDECODE_CODEC_VC1
;
1485 case PIPE_VIDEO_FORMAT_MPEG4_AVC
:
1486 width
= align(width
, VL_MACROBLOCK_WIDTH
);
1487 height
= align(height
, VL_MACROBLOCK_HEIGHT
);
1488 stream_type
= RDECODE_CODEC_H264_PERF
;
1490 case PIPE_VIDEO_FORMAT_HEVC
:
1491 stream_type
= RDECODE_CODEC_H265
;
1493 case PIPE_VIDEO_FORMAT_VP9
:
1494 stream_type
= RDECODE_CODEC_VP9
;
1501 dec
= CALLOC_STRUCT(radeon_decoder
);
1507 dec
->base
.context
= context
;
1508 dec
->base
.width
= width
;
1509 dec
->base
.height
= height
;
1511 dec
->base
.destroy
= radeon_dec_destroy
;
1512 dec
->base
.begin_frame
= radeon_dec_begin_frame
;
1513 dec
->base
.decode_macroblock
= radeon_dec_decode_macroblock
;
1514 dec
->base
.decode_bitstream
= radeon_dec_decode_bitstream
;
1515 dec
->base
.end_frame
= radeon_dec_end_frame
;
1516 dec
->base
.flush
= radeon_dec_flush
;
1518 dec
->stream_type
= stream_type
;
1519 dec
->stream_handle
= si_vid_alloc_stream_handle();
1520 dec
->screen
= context
->screen
;
1522 dec
->cs
= ws
->cs_create(sctx
->ctx
, RING_VCN_DEC
, NULL
, NULL
);
1524 RVID_ERR("Can't get command submission context.\n");
1528 for (i
= 0; i
< 16; i
++)
1529 dec
->render_pic_list
[i
] = NULL
;
1530 bs_buf_size
= width
* height
* (512 / (16 * 16));
1531 for (i
= 0; i
< NUM_BUFFERS
; ++i
) {
1532 unsigned msg_fb_it_probs_size
= FB_BUFFER_OFFSET
+ FB_BUFFER_SIZE
;
1534 msg_fb_it_probs_size
+= IT_SCALING_TABLE_SIZE
;
1535 else if (have_probs(dec
))
1536 msg_fb_it_probs_size
+= VP9_PROBS_TABLE_SIZE
;
1537 /* use vram to improve performance, workaround an unknown bug */
1538 if (!si_vid_create_buffer(dec
->screen
, &dec
->msg_fb_it_probs_buffers
[i
],
1539 msg_fb_it_probs_size
, PIPE_USAGE_DEFAULT
)) {
1540 RVID_ERR("Can't allocated message buffers.\n");
1544 if (!si_vid_create_buffer(dec
->screen
, &dec
->bs_buffers
[i
],
1545 bs_buf_size
, PIPE_USAGE_STAGING
)) {
1546 RVID_ERR("Can't allocated bitstream buffers.\n");
1550 si_vid_clear_buffer(context
, &dec
->msg_fb_it_probs_buffers
[i
]);
1551 si_vid_clear_buffer(context
, &dec
->bs_buffers
[i
]);
1553 if (have_probs(dec
)) {
1554 struct rvid_buffer
* buf
;
1557 buf
= &dec
->msg_fb_it_probs_buffers
[i
];
1558 ptr
= dec
->ws
->buffer_map(buf
->res
->buf
, dec
->cs
, PIPE_TRANSFER_WRITE
);
1559 ptr
+= FB_BUFFER_OFFSET
+ FB_BUFFER_SIZE
;
1560 fill_probs_table(ptr
);
1561 dec
->ws
->buffer_unmap(buf
->res
->buf
);
1565 dpb_size
= calc_dpb_size(dec
);
1567 if (!si_vid_create_buffer(dec
->screen
, &dec
->dpb
, dpb_size
, PIPE_USAGE_DEFAULT
)) {
1568 RVID_ERR("Can't allocated dpb.\n");
1572 si_vid_clear_buffer(context
, &dec
->dpb
);
1574 if (dec
->stream_type
== RDECODE_CODEC_H264_PERF
) {
1575 unsigned ctx_size
= calc_ctx_size_h264_perf(dec
);
1576 if (!si_vid_create_buffer(dec
->screen
, &dec
->ctx
, ctx_size
, PIPE_USAGE_DEFAULT
)) {
1577 RVID_ERR("Can't allocated context buffer.\n");
1580 si_vid_clear_buffer(context
, &dec
->ctx
);
1583 if (!si_vid_create_buffer(dec
->screen
, &dec
->sessionctx
,
1584 RDECODE_SESSION_CONTEXT_SIZE
,
1585 PIPE_USAGE_DEFAULT
)) {
1586 RVID_ERR("Can't allocated session ctx.\n");
1589 si_vid_clear_buffer(context
, &dec
->sessionctx
);
1591 map_msg_fb_it_probs_buf(dec
);
1592 rvcn_dec_message_create(dec
);
1603 if (dec
->cs
) dec
->ws
->cs_destroy(dec
->cs
);
1605 for (i
= 0; i
< NUM_BUFFERS
; ++i
) {
1606 si_vid_destroy_buffer(&dec
->msg_fb_it_probs_buffers
[i
]);
1607 si_vid_destroy_buffer(&dec
->bs_buffers
[i
]);
1610 si_vid_destroy_buffer(&dec
->dpb
);
1611 si_vid_destroy_buffer(&dec
->ctx
);
1612 si_vid_destroy_buffer(&dec
->sessionctx
);