2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
30 #include "intel_batchbuffer.h"
31 #include "intel_driver.h"
33 #include "i965_defines.h"
34 #include "i965_drv_video.h"
35 #include "i965_avc_bsd.h"
36 #include "i965_media_h264.h"
37 #include "i965_media.h"
38 #include "i965_decoder_utils.h"
39 #include "intel_media.h"
42 i965_avc_bsd_init_avc_bsd_surface(VADriverContextP ctx,
43 struct object_surface *obj_surface,
44 VAPictureParameterBufferH264 *pic_param,
45 struct i965_h264_context *i965_h264_context)
47 struct i965_driver_data *i965 = i965_driver_data(ctx);
48 GenAvcSurface *avc_bsd_surface = obj_surface->private_data;
50 obj_surface->free_private_data = gen_free_avc_surface;
52 if (!avc_bsd_surface) {
53 avc_bsd_surface = calloc(sizeof(GenAvcSurface), 1);
54 assert((obj_surface->size & 0x3f) == 0);
55 obj_surface->private_data = avc_bsd_surface;
58 avc_bsd_surface->dmv_bottom_flag = (pic_param->pic_fields.bits.field_pic_flag &&
59 !pic_param->seq_fields.bits.direct_8x8_inference_flag);
61 if (avc_bsd_surface->dmv_top == NULL) {
62 avc_bsd_surface->dmv_top = dri_bo_alloc(i965->intel.bufmgr,
63 "direct mv w/r buffer",
68 if (avc_bsd_surface->dmv_bottom_flag &&
69 avc_bsd_surface->dmv_bottom == NULL) {
70 avc_bsd_surface->dmv_bottom = dri_bo_alloc(i965->intel.bufmgr,
71 "direct mv w/r buffer",
78 i965_bsd_ind_obj_base_address(VADriverContextP ctx,
79 struct decode_state *decode_state,
81 struct i965_h264_context *i965_h264_context)
84 struct intel_batchbuffer *batch = i965_h264_context->batch;
86 dri_bo *ind_bo = decode_state->slice_datas[slice]->bo;
88 BEGIN_BCS_BATCH(batch, 3);
89 OUT_BCS_BATCH(batch, CMD_BSD_IND_OBJ_BASE_ADDR | (3 - 2));
90 OUT_BCS_RELOC(batch, ind_bo,
91 I915_GEM_DOMAIN_INSTRUCTION, 0,
93 OUT_BCS_BATCH(batch, 0);
94 ADVANCE_BCS_BATCH(batch);
98 i965_avc_bsd_img_state(VADriverContextP ctx,
99 struct decode_state *decode_state,
100 struct i965_h264_context *i965_h264_context)
102 struct intel_batchbuffer *batch = i965_h264_context->batch;
105 int mbaff_frame_flag;
106 unsigned int avc_it_command_header;
107 unsigned int width_in_mbs, height_in_mbs;
108 VAPictureParameterBufferH264 *pic_param;
110 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer)
113 qm_present_flag = 0; /* built-in QM matrices */
115 assert(decode_state->pic_param && decode_state->pic_param->buffer);
116 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
118 if (pic_param->CurrPic.flags & VA_PICTURE_H264_TOP_FIELD)
120 else if (pic_param->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD)
125 if ((img_struct & 0x1) == 0x1) {
126 assert(pic_param->pic_fields.bits.field_pic_flag == 0x1);
128 assert(pic_param->pic_fields.bits.field_pic_flag == 0x0);
131 if (pic_param->seq_fields.bits.frame_mbs_only_flag) { /* a frame containing only frame macroblocks */
132 assert(pic_param->seq_fields.bits.mb_adaptive_frame_field_flag == 0);
133 assert(pic_param->pic_fields.bits.field_pic_flag == 0);
135 assert(pic_param->seq_fields.bits.direct_8x8_inference_flag == 1); /* see H.264 spec */
138 mbaff_frame_flag = (pic_param->seq_fields.bits.mb_adaptive_frame_field_flag &&
139 !pic_param->pic_fields.bits.field_pic_flag);
141 width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
142 height_in_mbs = ((pic_param->picture_height_in_mbs_minus1 + 1) & 0xff); /* frame height */
144 assert(!((width_in_mbs * height_in_mbs) & 0x8000)); /* hardware requirement */
146 /* BSD unit doesn't support 4:2:2 and 4:4:4 picture */
147 assert(pic_param->seq_fields.bits.chroma_format_idc == 0 || /* monochrome picture */
148 pic_param->seq_fields.bits.chroma_format_idc == 1); /* 4:2:0 */
149 assert(pic_param->seq_fields.bits.residual_colour_transform_flag == 0); /* only available for 4:4:4 */
151 avc_it_command_header = (CMD_MEDIA_OBJECT_EX | (12 - 2));
153 BEGIN_BCS_BATCH(batch, 6);
154 OUT_BCS_BATCH(batch, CMD_AVC_BSD_IMG_STATE | (6 - 2));
156 ((width_in_mbs * height_in_mbs) & 0x7fff));
158 (height_in_mbs << 16) |
159 (width_in_mbs << 0));
161 ((pic_param->second_chroma_qp_index_offset & 0x1f) << 24) |
162 ((pic_param->chroma_qp_index_offset & 0x1f) << 16) |
163 (SCAN_RASTER_ORDER << 15) | /* AVC ILDB Data */
164 (SCAN_SPECIAL_ORDER << 14) | /* AVC IT Command */
165 (SCAN_RASTER_ORDER << 13) | /* AVC IT Data */
166 (1 << 12) | /* always 1, hardware requirement */
167 (qm_present_flag << 10) |
169 (16 << 0)); /* FIXME: always support 16 reference frames ??? */
171 (RESIDUAL_DATA_OFFSET << 24) | /* residual data offset */
172 (0 << 17) | /* don't overwrite SRT */
173 (0 << 16) | /* Un-SRT (Unsynchronized Root Thread) */
174 (0 << 12) | /* FIXME: no 16MV ??? */
175 (pic_param->seq_fields.bits.chroma_format_idc << 10) |
176 (i965_h264_context->enable_avc_ildb << 8) | /* Enable ILDB writing output */
177 (pic_param->pic_fields.bits.entropy_coding_mode_flag << 7) |
178 ((!pic_param->pic_fields.bits.reference_pic_flag) << 6) |
179 (pic_param->pic_fields.bits.constrained_intra_pred_flag << 5) |
180 (pic_param->seq_fields.bits.direct_8x8_inference_flag << 4) |
181 (pic_param->pic_fields.bits.transform_8x8_mode_flag << 3) |
182 (pic_param->seq_fields.bits.frame_mbs_only_flag << 2) |
183 (mbaff_frame_flag << 1) |
184 (pic_param->pic_fields.bits.field_pic_flag << 0));
185 OUT_BCS_BATCH(batch, avc_it_command_header);
186 ADVANCE_BCS_BATCH(batch);
190 i965_avc_bsd_qm_state(VADriverContextP ctx,
191 struct decode_state *decode_state,
192 struct i965_h264_context *i965_h264_context)
194 struct intel_batchbuffer *batch = i965_h264_context->batch;
196 VAIQMatrixBufferH264 *iq_matrix;
197 VAPictureParameterBufferH264 *pic_param;
199 if (!decode_state->iq_matrix || !decode_state->iq_matrix->buffer)
202 iq_matrix = (VAIQMatrixBufferH264 *)decode_state->iq_matrix->buffer;
204 assert(decode_state->pic_param && decode_state->pic_param->buffer);
205 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
207 cmd_len = 2 + 6 * 4; /* always load six 4x4 scaling matrices */
209 if (pic_param->pic_fields.bits.transform_8x8_mode_flag)
210 cmd_len += 2 * 16; /* load two 8x8 scaling matrices */
212 BEGIN_BCS_BATCH(batch, cmd_len);
213 OUT_BCS_BATCH(batch, CMD_AVC_BSD_QM_STATE | (cmd_len - 2));
215 if (pic_param->pic_fields.bits.transform_8x8_mode_flag)
217 (0x0 << 8) | /* don't use default built-in matrices */
218 (0xff << 0)); /* six 4x4 and two 8x8 scaling matrices */
221 (0x0 << 8) | /* don't use default built-in matrices */
222 (0x3f << 0)); /* six 4x4 scaling matrices */
224 intel_batchbuffer_data(batch, &iq_matrix->ScalingList4x4[0][0], 6 * 4 * 4);
226 if (pic_param->pic_fields.bits.transform_8x8_mode_flag)
227 intel_batchbuffer_data(batch, &iq_matrix->ScalingList8x8[0][0], 2 * 16 * 4);
229 ADVANCE_BCS_BATCH(batch);
233 i965_avc_bsd_slice_state(VADriverContextP ctx,
234 VAPictureParameterBufferH264 *pic_param,
235 VASliceParameterBufferH264 *slice_param,
236 struct i965_h264_context *i965_h264_context)
238 struct intel_batchbuffer *batch = i965_h264_context->batch;
239 int present_flag, cmd_len, list, j;
240 uint8_t ref_idx_state[32];
241 char weightoffsets[32 * 6];
243 /* don't issue SLICE_STATE for intra-prediction decoding */
244 if (slice_param->slice_type == SLICE_TYPE_I ||
245 slice_param->slice_type == SLICE_TYPE_SI)
250 if (slice_param->slice_type == SLICE_TYPE_P ||
251 slice_param->slice_type == SLICE_TYPE_SP) {
252 present_flag = PRESENT_REF_LIST0;
255 present_flag = PRESENT_REF_LIST0 | PRESENT_REF_LIST1;
259 if ((slice_param->slice_type == SLICE_TYPE_P ||
260 slice_param->slice_type == SLICE_TYPE_SP) &&
261 (pic_param->pic_fields.bits.weighted_pred_flag == 1)) {
262 present_flag |= PRESENT_WEIGHT_OFFSET_L0;
266 if ((slice_param->slice_type == SLICE_TYPE_B) &&
267 (pic_param->pic_fields.bits.weighted_bipred_idc == 1)) {
268 present_flag |= PRESENT_WEIGHT_OFFSET_L0 | PRESENT_WEIGHT_OFFSET_L1;
272 BEGIN_BCS_BATCH(batch, cmd_len);
273 OUT_BCS_BATCH(batch, CMD_AVC_BSD_SLICE_STATE | (cmd_len - 2));
274 OUT_BCS_BATCH(batch, present_flag);
276 for (list = 0; list < 2; list++) {
277 int flag, num_va_pics;
278 VAPictureH264 *va_pic;
281 flag = PRESENT_REF_LIST0;
282 va_pic = slice_param->RefPicList0;
283 num_va_pics = slice_param->num_ref_idx_l0_active_minus1 + 1;
285 flag = PRESENT_REF_LIST1;
286 va_pic = slice_param->RefPicList1;
287 num_va_pics = slice_param->num_ref_idx_l1_active_minus1 + 1;
290 if (!(present_flag & flag))
293 gen5_fill_avc_ref_idx_state(
296 i965_h264_context->fsid_list
298 intel_batchbuffer_data(batch, ref_idx_state, sizeof(ref_idx_state));
301 i965_h264_context->weight128_luma_l0 = 0;
302 i965_h264_context->weight128_luma_l1 = 0;
303 i965_h264_context->weight128_chroma_l0 = 0;
304 i965_h264_context->weight128_chroma_l1 = 0;
306 i965_h264_context->weight128_offset0_flag = 0;
307 i965_h264_context->weight128_offset0 = 0;
309 if (present_flag & PRESENT_WEIGHT_OFFSET_L0) {
310 for (j = 0; j < 32; j++) {
311 weightoffsets[j * 6 + 0] = slice_param->luma_offset_l0[j];
312 weightoffsets[j * 6 + 1] = slice_param->luma_weight_l0[j];
313 weightoffsets[j * 6 + 2] = slice_param->chroma_offset_l0[j][0];
314 weightoffsets[j * 6 + 3] = slice_param->chroma_weight_l0[j][0];
315 weightoffsets[j * 6 + 4] = slice_param->chroma_offset_l0[j][1];
316 weightoffsets[j * 6 + 5] = slice_param->chroma_weight_l0[j][1];
318 if (pic_param->pic_fields.bits.weighted_pred_flag == 1 ||
319 pic_param->pic_fields.bits.weighted_bipred_idc == 1) {
320 if (i965_h264_context->use_hw_w128) {
321 if (slice_param->luma_weight_l0[j] == 128)
322 i965_h264_context->weight128_luma_l0 |= (1 << j);
324 if (slice_param->chroma_weight_l0[j][0] == 128 ||
325 slice_param->chroma_weight_l0[j][1] == 128)
326 i965_h264_context->weight128_chroma_l0 |= (1 << j);
328 /* FIXME: workaround for weight 128 */
329 if (slice_param->luma_weight_l0[j] == 128 ||
330 slice_param->chroma_weight_l0[j][0] == 128 ||
331 slice_param->chroma_weight_l0[j][1] == 128)
332 i965_h264_context->weight128_offset0_flag = 1;
337 intel_batchbuffer_data(batch, weightoffsets, sizeof(weightoffsets));
340 if (present_flag & PRESENT_WEIGHT_OFFSET_L1) {
341 for (j = 0; j < 32; j++) {
342 weightoffsets[j * 6 + 0] = slice_param->luma_offset_l1[j];
343 weightoffsets[j * 6 + 1] = slice_param->luma_weight_l1[j];
344 weightoffsets[j * 6 + 2] = slice_param->chroma_offset_l1[j][0];
345 weightoffsets[j * 6 + 3] = slice_param->chroma_weight_l1[j][0];
346 weightoffsets[j * 6 + 4] = slice_param->chroma_offset_l1[j][1];
347 weightoffsets[j * 6 + 5] = slice_param->chroma_weight_l1[j][1];
349 if (pic_param->pic_fields.bits.weighted_bipred_idc == 1) {
350 if (i965_h264_context->use_hw_w128) {
351 if (slice_param->luma_weight_l1[j] == 128)
352 i965_h264_context->weight128_luma_l1 |= (1 << j);
354 if (slice_param->chroma_weight_l1[j][0] == 128 ||
355 slice_param->chroma_weight_l1[j][1] == 128)
356 i965_h264_context->weight128_chroma_l1 |= (1 << j);
358 if (slice_param->luma_weight_l0[j] == 128 ||
359 slice_param->chroma_weight_l0[j][0] == 128 ||
360 slice_param->chroma_weight_l0[j][1] == 128)
361 i965_h264_context->weight128_offset0_flag = 1;
366 intel_batchbuffer_data(batch, weightoffsets, sizeof(weightoffsets));
369 ADVANCE_BCS_BATCH(batch);
373 i965_avc_bsd_buf_base_state(VADriverContextP ctx,
374 struct decode_state *decode_state,
375 VAPictureParameterBufferH264 *pic_param,
376 VASliceParameterBufferH264 *slice_param,
377 struct i965_h264_context *i965_h264_context)
379 struct intel_batchbuffer *batch = i965_h264_context->batch;
380 struct i965_avc_bsd_context *i965_avc_bsd_context;
382 VAPictureH264 *va_pic;
383 struct object_surface *obj_surface;
384 GenAvcSurface *avc_bsd_surface;
386 i965_avc_bsd_context = &i965_h264_context->i965_avc_bsd_context;
388 BEGIN_BCS_BATCH(batch, 74);
389 OUT_BCS_BATCH(batch, CMD_AVC_BSD_BUF_BASE_STATE | (74 - 2));
390 OUT_BCS_RELOC(batch, i965_avc_bsd_context->bsd_raw_store.bo,
391 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
393 OUT_BCS_RELOC(batch, i965_avc_bsd_context->mpr_row_store.bo,
394 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
396 OUT_BCS_RELOC(batch, i965_h264_context->avc_it_command_mb_info.bo,
397 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
398 i965_h264_context->avc_it_command_mb_info.mbs * i965_h264_context->use_avc_hw_scoreboard * MB_CMD_IN_BYTES);
399 OUT_BCS_RELOC(batch, i965_h264_context->avc_it_data.bo,
400 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
401 (i965_h264_context->avc_it_data.write_offset << 6));
403 if (i965_h264_context->enable_avc_ildb)
404 OUT_BCS_RELOC(batch, i965_h264_context->avc_ildb_data.bo,
405 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
408 OUT_BCS_BATCH(batch, 0);
410 for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fsid_list); i++) {
411 if (i965_h264_context->fsid_list[i].surface_id != VA_INVALID_ID &&
412 i965_h264_context->fsid_list[i].obj_surface &&
413 i965_h264_context->fsid_list[i].obj_surface->private_data) {
415 for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
416 va_pic = &pic_param->ReferenceFrames[j];
418 if (va_pic->flags & VA_PICTURE_H264_INVALID)
421 if (va_pic->picture_id == i965_h264_context->fsid_list[i].surface_id) {
428 obj_surface = i965_h264_context->fsid_list[i].obj_surface;
429 avc_bsd_surface = obj_surface->private_data;
431 OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top,
432 I915_GEM_DOMAIN_INSTRUCTION, 0,
435 if (avc_bsd_surface->dmv_bottom_flag == 1)
436 OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_bottom,
437 I915_GEM_DOMAIN_INSTRUCTION, 0,
440 OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top,
441 I915_GEM_DOMAIN_INSTRUCTION, 0,
444 OUT_BCS_BATCH(batch, 0);
445 OUT_BCS_BATCH(batch, 0);
449 va_pic = &pic_param->CurrPic;
450 obj_surface = decode_state->render_object;
451 obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
452 obj_surface->flags |= (pic_param->pic_fields.bits.reference_pic_flag ? SURFACE_REFERENCED : 0);
453 i965_check_alloc_surface_bo(ctx, obj_surface, 0, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
455 /* initial uv component for YUV400 case */
456 if (pic_param->seq_fields.bits.chroma_format_idc == 0) {
457 unsigned int uv_offset = obj_surface->width * obj_surface->height;
458 unsigned int uv_size = obj_surface->width * obj_surface->height / 2;
460 dri_bo_map(obj_surface->bo, 1);
461 memset(obj_surface->bo->virtual + uv_offset, 0x80, uv_size);
462 dri_bo_unmap(obj_surface->bo);
465 i965_avc_bsd_init_avc_bsd_surface(ctx, obj_surface, pic_param, i965_h264_context);
466 avc_bsd_surface = obj_surface->private_data;
468 OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top,
469 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
472 if (avc_bsd_surface->dmv_bottom_flag == 1)
473 OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_bottom,
474 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
477 OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top,
478 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
482 for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fsid_list); i++) {
483 if (i965_h264_context->fsid_list[i].surface_id != VA_INVALID_ID) {
485 for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
486 va_pic = &pic_param->ReferenceFrames[j];
488 if (va_pic->flags & VA_PICTURE_H264_INVALID)
491 if (va_pic->picture_id == i965_h264_context->fsid_list[i].surface_id) {
499 if (!(va_pic->flags & VA_PICTURE_H264_INVALID)) {
500 OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt);
501 OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt);
504 OUT_BCS_BATCH(batch, 0);
505 OUT_BCS_BATCH(batch, 0);
509 va_pic = &pic_param->CurrPic;
510 OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt);
511 OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt);
513 ADVANCE_BCS_BATCH(batch);
517 g4x_avc_bsd_object(VADriverContextP ctx,
518 struct decode_state *decode_state,
519 VAPictureParameterBufferH264 *pic_param,
520 VASliceParameterBufferH264 *slice_param,
522 struct i965_h264_context *i965_h264_context)
524 struct intel_batchbuffer *batch = i965_h264_context->batch;
525 int width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
526 int height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1; /* frame height */
529 int encrypted, counter_value, cmd_len;
530 int slice_hor_pos, slice_ver_pos;
531 int num_ref_idx_l0, num_ref_idx_l1;
532 int mbaff_picture = (!pic_param->pic_fields.bits.field_pic_flag &&
533 pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
534 unsigned int slice_data_bit_offset;
535 int weighted_pred_idc = 0;
536 int first_mb_in_slice = 0;
539 encrypted = 0; /* FIXME: which flag in VAAPI is used for encryption? */
543 counter_value = 0; /* FIXME: ??? */
548 slice_data_bit_offset = avc_get_first_mb_bit_offset_with_epb(
549 decode_state->slice_datas[slice_index]->bo,
551 pic_param->pic_fields.bits.entropy_coding_mode_flag
554 if (slice_param->slice_type == SLICE_TYPE_I ||
555 slice_param->slice_type == SLICE_TYPE_SI)
556 slice_type = SLICE_TYPE_I;
557 else if (slice_param->slice_type == SLICE_TYPE_P ||
558 slice_param->slice_type == SLICE_TYPE_SP)
559 slice_type = SLICE_TYPE_P;
561 assert(slice_param->slice_type == SLICE_TYPE_B);
562 slice_type = SLICE_TYPE_B;
565 if (slice_type == SLICE_TYPE_I) {
566 assert(slice_param->num_ref_idx_l0_active_minus1 == 0);
567 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
570 } else if (slice_type == SLICE_TYPE_P) {
571 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
572 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
575 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
576 num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
579 if (slice_type == SLICE_TYPE_P)
580 weighted_pred_idc = pic_param->pic_fields.bits.weighted_pred_flag;
581 else if (slice_type == SLICE_TYPE_B)
582 weighted_pred_idc = pic_param->pic_fields.bits.weighted_bipred_idc;
584 first_mb_in_slice = slice_param->first_mb_in_slice << mbaff_picture;
585 slice_hor_pos = first_mb_in_slice % width_in_mbs;
586 slice_ver_pos = first_mb_in_slice / width_in_mbs;
588 BEGIN_BCS_BATCH(batch, cmd_len);
589 OUT_BCS_BATCH(batch, CMD_AVC_BSD_OBJECT | (cmd_len - 2));
592 ((slice_param->slice_data_size - (slice_data_bit_offset >> 3)) << 0));
594 (slice_param->slice_data_offset +
595 (slice_data_bit_offset >> 3)));
597 (0 << 31) | /* concealment mode: 0->intra 16x16 prediction, 1->inter P Copy */
598 (0 << 14) | /* ignore BSDPrematureComplete Error handling */
599 (0 << 13) | /* FIXME: ??? */
600 (0 << 12) | /* ignore MPR Error handling */
601 (0 << 10) | /* ignore Entropy Error handling */
602 (0 << 8) | /* ignore MB Header Error handling */
605 (num_ref_idx_l1 << 24) |
606 (num_ref_idx_l0 << 16) |
607 (slice_param->chroma_log2_weight_denom << 8) |
608 (slice_param->luma_log2_weight_denom << 0));
610 (weighted_pred_idc << 30) |
611 (slice_param->direct_spatial_mv_pred_flag << 29) |
612 (slice_param->disable_deblocking_filter_idc << 27) |
613 (slice_param->cabac_init_idc << 24) |
614 ((pic_param->pic_init_qp_minus26 + 26 + slice_param->slice_qp_delta) << 16) |
615 ((slice_param->slice_beta_offset_div2 & 0xf) << 8) |
616 ((slice_param->slice_alpha_c0_offset_div2 & 0xf) << 0));
618 (slice_ver_pos << 24) |
619 (slice_hor_pos << 16) |
620 (first_mb_in_slice << 0));
623 ((0x7 - (slice_data_bit_offset & 0x7)) << 0));
626 OUT_BCS_BATCH(batch, counter_value);
629 ADVANCE_BCS_BATCH(batch);
631 BEGIN_BCS_BATCH(batch, 8);
632 OUT_BCS_BATCH(batch, CMD_AVC_BSD_OBJECT | (8 - 2));
633 OUT_BCS_BATCH(batch, 0); /* indirect data length for phantom slice is 0 */
634 OUT_BCS_BATCH(batch, 0); /* indirect data start address for phantom slice is 0 */
635 OUT_BCS_BATCH(batch, 0);
636 OUT_BCS_BATCH(batch, 0);
637 OUT_BCS_BATCH(batch, 0);
638 OUT_BCS_BATCH(batch, width_in_mbs * height_in_mbs / (1 + !!pic_param->pic_fields.bits.field_pic_flag));
639 OUT_BCS_BATCH(batch, 0);
640 ADVANCE_BCS_BATCH(batch);
645 ironlake_avc_bsd_object(VADriverContextP ctx,
646 struct decode_state *decode_state,
647 VAPictureParameterBufferH264 *pic_param,
648 VASliceParameterBufferH264 *slice_param,
650 struct i965_h264_context *i965_h264_context)
652 struct intel_batchbuffer *batch = i965_h264_context->batch;
653 int width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
654 int height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1; /* frame height */
657 int encrypted, counter_value;
658 int slice_hor_pos, slice_ver_pos;
659 int num_ref_idx_l0, num_ref_idx_l1;
660 int mbaff_picture = (!pic_param->pic_fields.bits.field_pic_flag &&
661 pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
662 unsigned int slice_data_bit_offset;
663 int weighted_pred_idc = 0;
664 int first_mb_in_slice;
667 encrypted = 0; /* FIXME: which flag in VAAPI is used for encryption? */
670 counter_value = 0; /* FIXME: ??? */
674 slice_data_bit_offset = avc_get_first_mb_bit_offset_with_epb(
675 decode_state->slice_datas[slice_index]->bo,
677 pic_param->pic_fields.bits.entropy_coding_mode_flag
680 if (slice_param->slice_type == SLICE_TYPE_I ||
681 slice_param->slice_type == SLICE_TYPE_SI)
682 slice_type = SLICE_TYPE_I;
683 else if (slice_param->slice_type == SLICE_TYPE_P ||
684 slice_param->slice_type == SLICE_TYPE_SP)
685 slice_type = SLICE_TYPE_P;
687 assert(slice_param->slice_type == SLICE_TYPE_B);
688 slice_type = SLICE_TYPE_B;
691 if (slice_type == SLICE_TYPE_I) {
692 assert(slice_param->num_ref_idx_l0_active_minus1 == 0);
693 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
696 } else if (slice_type == SLICE_TYPE_P) {
697 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
698 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
701 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
702 num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
705 if (slice_type == SLICE_TYPE_P)
706 weighted_pred_idc = pic_param->pic_fields.bits.weighted_pred_flag;
707 else if (slice_type == SLICE_TYPE_B)
708 weighted_pred_idc = pic_param->pic_fields.bits.weighted_bipred_idc;
710 first_mb_in_slice = slice_param->first_mb_in_slice << mbaff_picture;
711 slice_hor_pos = first_mb_in_slice % width_in_mbs;
712 slice_ver_pos = first_mb_in_slice / width_in_mbs;
714 BEGIN_BCS_BATCH(batch, 16);
715 OUT_BCS_BATCH(batch, CMD_AVC_BSD_OBJECT | (16 - 2));
718 (0 << 30) | /* FIXME: packet based bit stream */
719 (0 << 29) | /* FIXME: packet format */
720 ((slice_param->slice_data_size - (slice_data_bit_offset >> 3)) << 0));
722 (slice_param->slice_data_offset +
723 (slice_data_bit_offset >> 3)));
725 (0 << 31) | /* concealment mode: 0->intra 16x16 prediction, 1->inter P Copy */
726 (0 << 14) | /* ignore BSDPrematureComplete Error handling */
727 (0 << 13) | /* FIXME: ??? */
728 (0 << 12) | /* ignore MPR Error handling */
729 (0 << 10) | /* ignore Entropy Error handling */
730 (0 << 8) | /* ignore MB Header Error handling */
733 (num_ref_idx_l1 << 24) |
734 (num_ref_idx_l0 << 16) |
735 (slice_param->chroma_log2_weight_denom << 8) |
736 (slice_param->luma_log2_weight_denom << 0));
738 (weighted_pred_idc << 30) |
739 (slice_param->direct_spatial_mv_pred_flag << 29) |
740 (slice_param->disable_deblocking_filter_idc << 27) |
741 (slice_param->cabac_init_idc << 24) |
742 ((pic_param->pic_init_qp_minus26 + 26 + slice_param->slice_qp_delta) << 16) |
743 ((slice_param->slice_beta_offset_div2 & 0xf) << 8) |
744 ((slice_param->slice_alpha_c0_offset_div2 & 0xf) << 0));
746 (slice_ver_pos << 24) |
747 (slice_hor_pos << 16) |
748 (first_mb_in_slice << 0));
751 ((0x7 - (slice_data_bit_offset & 0x7)) << 0));
752 OUT_BCS_BATCH(batch, counter_value);
754 /* FIXME: dw9-dw11 */
755 OUT_BCS_BATCH(batch, 0);
756 OUT_BCS_BATCH(batch, 0);
757 OUT_BCS_BATCH(batch, 0);
758 OUT_BCS_BATCH(batch, i965_h264_context->weight128_luma_l0);
759 OUT_BCS_BATCH(batch, i965_h264_context->weight128_luma_l1);
760 OUT_BCS_BATCH(batch, i965_h264_context->weight128_chroma_l0);
761 OUT_BCS_BATCH(batch, i965_h264_context->weight128_chroma_l1);
763 ADVANCE_BCS_BATCH(batch);
765 BEGIN_BCS_BATCH(batch, 16);
766 OUT_BCS_BATCH(batch, CMD_AVC_BSD_OBJECT | (16 - 2));
767 OUT_BCS_BATCH(batch, 0); /* indirect data length for phantom slice is 0 */
768 OUT_BCS_BATCH(batch, 0); /* indirect data start address for phantom slice is 0 */
769 OUT_BCS_BATCH(batch, 0);
770 OUT_BCS_BATCH(batch, 0);
771 OUT_BCS_BATCH(batch, 0);
772 OUT_BCS_BATCH(batch, width_in_mbs * height_in_mbs / (1 + !!pic_param->pic_fields.bits.field_pic_flag));
773 OUT_BCS_BATCH(batch, 0);
774 OUT_BCS_BATCH(batch, 0);
775 OUT_BCS_BATCH(batch, 0);
776 OUT_BCS_BATCH(batch, 0);
777 OUT_BCS_BATCH(batch, 0);
778 OUT_BCS_BATCH(batch, 0);
779 OUT_BCS_BATCH(batch, 0);
780 OUT_BCS_BATCH(batch, 0);
781 OUT_BCS_BATCH(batch, 0);
782 ADVANCE_BCS_BATCH(batch);
787 i965_avc_bsd_object(VADriverContextP ctx,
788 struct decode_state *decode_state,
789 VAPictureParameterBufferH264 *pic_param,
790 VASliceParameterBufferH264 *slice_param,
792 struct i965_h264_context *i965_h264_context)
794 struct i965_driver_data *i965 = i965_driver_data(ctx);
796 if (IS_IRONLAKE(i965->intel.device_id))
797 ironlake_avc_bsd_object(ctx, decode_state, pic_param, slice_param, slice_index, i965_h264_context);
799 g4x_avc_bsd_object(ctx, decode_state, pic_param, slice_param, slice_index, i965_h264_context);
803 i965_avc_bsd_phantom_slice(VADriverContextP ctx,
804 struct decode_state *decode_state,
805 VAPictureParameterBufferH264 *pic_param,
806 struct i965_h264_context *i965_h264_context)
808 i965_avc_bsd_object(ctx, decode_state, pic_param, NULL, 0, i965_h264_context);
812 i965_avc_bsd_pipeline(VADriverContextP ctx, struct decode_state *decode_state, void *h264_context)
814 struct i965_h264_context *i965_h264_context = (struct i965_h264_context *)h264_context;
815 struct intel_batchbuffer *batch = i965_h264_context->batch;
816 VAPictureParameterBufferH264 *pic_param;
817 VASliceParameterBufferH264 *slice_param;
820 assert(decode_state->pic_param && decode_state->pic_param->buffer);
821 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
822 intel_update_avc_frame_store_index(ctx, decode_state, pic_param, i965_h264_context->fsid_list);
824 i965_h264_context->enable_avc_ildb = 0;
825 i965_h264_context->picture.i_flag = 1;
827 for (j = 0; j < decode_state->num_slice_params && i965_h264_context->enable_avc_ildb == 0; j++) {
828 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
829 slice_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j]->buffer;
831 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
832 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
833 assert((slice_param->slice_type == SLICE_TYPE_I) ||
834 (slice_param->slice_type == SLICE_TYPE_SI) ||
835 (slice_param->slice_type == SLICE_TYPE_P) ||
836 (slice_param->slice_type == SLICE_TYPE_SP) ||
837 (slice_param->slice_type == SLICE_TYPE_B));
839 if (slice_param->disable_deblocking_filter_idc != 1) {
840 i965_h264_context->enable_avc_ildb = 1;
848 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
850 i965_avc_bsd_img_state(ctx, decode_state, i965_h264_context);
851 i965_avc_bsd_qm_state(ctx, decode_state, i965_h264_context);
853 for (j = 0; j < decode_state->num_slice_params; j++) {
854 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
855 slice_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j]->buffer;
857 i965_bsd_ind_obj_base_address(ctx, decode_state, j, i965_h264_context);
859 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
860 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
861 assert((slice_param->slice_type == SLICE_TYPE_I) ||
862 (slice_param->slice_type == SLICE_TYPE_SI) ||
863 (slice_param->slice_type == SLICE_TYPE_P) ||
864 (slice_param->slice_type == SLICE_TYPE_SP) ||
865 (slice_param->slice_type == SLICE_TYPE_B));
867 if (i965_h264_context->picture.i_flag &&
868 (slice_param->slice_type != SLICE_TYPE_I ||
869 slice_param->slice_type != SLICE_TYPE_SI))
870 i965_h264_context->picture.i_flag = 0;
872 i965_avc_bsd_slice_state(ctx, pic_param, slice_param, i965_h264_context);
873 i965_avc_bsd_buf_base_state(ctx, decode_state, pic_param, slice_param, i965_h264_context);
874 i965_avc_bsd_object(ctx, decode_state, pic_param, slice_param, j, i965_h264_context);
879 i965_avc_bsd_phantom_slice(ctx, decode_state, pic_param, i965_h264_context);
880 intel_batchbuffer_emit_mi_flush(batch);
881 intel_batchbuffer_end_atomic(batch);
882 intel_batchbuffer_flush(batch);
886 i965_avc_bsd_decode_init(VADriverContextP ctx, void *h264_context)
888 struct i965_driver_data *i965 = i965_driver_data(ctx);
889 struct i965_h264_context *i965_h264_context = (struct i965_h264_context *)h264_context;
890 struct i965_avc_bsd_context *i965_avc_bsd_context;
893 assert(i965_h264_context);
894 i965_avc_bsd_context = &i965_h264_context->i965_avc_bsd_context;
896 dri_bo_unreference(i965_avc_bsd_context->bsd_raw_store.bo);
897 bo = dri_bo_alloc(i965->intel.bufmgr,
899 0x3000, /* at least 11520 bytes to support 120 MBs per row */
902 i965_avc_bsd_context->bsd_raw_store.bo = bo;
904 dri_bo_unreference(i965_avc_bsd_context->mpr_row_store.bo);
905 bo = dri_bo_alloc(i965->intel.bufmgr,
907 0x2000, /* at least 7680 bytes to support 120 MBs per row */
910 i965_avc_bsd_context->mpr_row_store.bo = bo;
914 i965_avc_bsd_ternimate(struct i965_avc_bsd_context *i965_avc_bsd_context)
916 dri_bo_unreference(i965_avc_bsd_context->bsd_raw_store.bo);
917 dri_bo_unreference(i965_avc_bsd_context->mpr_row_store.bo);