2 * Copyright © 2011 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>
33 #include <va/va_dec_jpeg.h>
35 #include "intel_batchbuffer.h"
36 #include "intel_driver.h"
38 #include "i965_defines.h"
39 #include "i965_drv_video.h"
40 #include "i965_decoder_utils.h"
44 static const uint32_t zigzag_direct[64] = {
45 0, 1, 8, 16, 9, 2, 3, 10,
46 17, 24, 32, 25, 18, 11, 4, 5,
47 12, 19, 26, 33, 40, 48, 41, 34,
48 27, 20, 13, 6, 7, 14, 21, 28,
49 35, 42, 49, 56, 57, 50, 43, 36,
50 29, 22, 15, 23, 30, 37, 44, 51,
51 58, 59, 52, 45, 38, 31, 39, 46,
52 53, 60, 61, 54, 47, 55, 62, 63
56 gen7_mfd_avc_frame_store_index(VADriverContextP ctx,
57 VAPictureParameterBufferH264 *pic_param,
58 struct gen7_mfd_context *gen7_mfd_context)
60 struct i965_driver_data *i965 = i965_driver_data(ctx);
63 assert(ARRAY_ELEMS(gen7_mfd_context->reference_surface) == ARRAY_ELEMS(pic_param->ReferenceFrames));
65 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
68 if (gen7_mfd_context->reference_surface[i].surface_id == VA_INVALID_ID)
71 for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
72 VAPictureH264 *ref_pic = &pic_param->ReferenceFrames[j];
73 if (ref_pic->flags & VA_PICTURE_H264_INVALID)
76 if (gen7_mfd_context->reference_surface[i].surface_id == ref_pic->picture_id) {
83 struct object_surface *obj_surface = SURFACE(gen7_mfd_context->reference_surface[i].surface_id);
84 obj_surface->flags &= ~SURFACE_REFERENCED;
86 if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
87 dri_bo_unreference(obj_surface->bo);
88 obj_surface->bo = NULL;
89 obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
92 if (obj_surface->free_private_data)
93 obj_surface->free_private_data(&obj_surface->private_data);
95 gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
96 gen7_mfd_context->reference_surface[i].frame_store_id = -1;
100 for (i = 0; i < ARRAY_ELEMS(pic_param->ReferenceFrames); i++) {
101 VAPictureH264 *ref_pic = &pic_param->ReferenceFrames[i];
104 if (ref_pic->flags & VA_PICTURE_H264_INVALID)
107 for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
108 if (gen7_mfd_context->reference_surface[j].surface_id == VA_INVALID_ID)
111 if (gen7_mfd_context->reference_surface[j].surface_id == ref_pic->picture_id) {
119 struct object_surface *obj_surface = SURFACE(ref_pic->picture_id);
122 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
124 for (frame_idx = 0; frame_idx < ARRAY_ELEMS(gen7_mfd_context->reference_surface); frame_idx++) {
125 for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
126 if (gen7_mfd_context->reference_surface[j].surface_id == VA_INVALID_ID)
129 if (gen7_mfd_context->reference_surface[j].frame_store_id == frame_idx)
133 if (j == ARRAY_ELEMS(gen7_mfd_context->reference_surface))
137 assert(frame_idx < ARRAY_ELEMS(gen7_mfd_context->reference_surface));
139 for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
140 if (gen7_mfd_context->reference_surface[j].surface_id == VA_INVALID_ID) {
141 gen7_mfd_context->reference_surface[j].surface_id = ref_pic->picture_id;
142 gen7_mfd_context->reference_surface[j].frame_store_id = frame_idx;
150 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface) - 1; i++) {
151 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
152 gen7_mfd_context->reference_surface[i].frame_store_id == i)
155 for (j = i + 1; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
156 if (gen7_mfd_context->reference_surface[j].surface_id != VA_INVALID_ID &&
157 gen7_mfd_context->reference_surface[j].frame_store_id == i) {
158 VASurfaceID id = gen7_mfd_context->reference_surface[i].surface_id;
159 int frame_idx = gen7_mfd_context->reference_surface[i].frame_store_id;
161 gen7_mfd_context->reference_surface[i].surface_id = gen7_mfd_context->reference_surface[j].surface_id;
162 gen7_mfd_context->reference_surface[i].frame_store_id = gen7_mfd_context->reference_surface[j].frame_store_id;
163 gen7_mfd_context->reference_surface[j].surface_id = id;
164 gen7_mfd_context->reference_surface[j].frame_store_id = frame_idx;
172 gen7_mfd_free_avc_surface(void **data)
174 struct gen7_avc_surface *gen7_avc_surface = *data;
176 if (!gen7_avc_surface)
179 dri_bo_unreference(gen7_avc_surface->dmv_top);
180 gen7_avc_surface->dmv_top = NULL;
181 dri_bo_unreference(gen7_avc_surface->dmv_bottom);
182 gen7_avc_surface->dmv_bottom = NULL;
184 free(gen7_avc_surface);
189 gen7_mfd_init_avc_surface(VADriverContextP ctx,
190 VAPictureParameterBufferH264 *pic_param,
191 struct object_surface *obj_surface)
193 struct i965_driver_data *i965 = i965_driver_data(ctx);
194 struct gen7_avc_surface *gen7_avc_surface = obj_surface->private_data;
195 int width_in_mbs, height_in_mbs;
197 obj_surface->free_private_data = gen7_mfd_free_avc_surface;
198 width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
199 height_in_mbs = ((pic_param->picture_height_in_mbs_minus1 + 1) & 0xff); /* frame height */
201 if (!gen7_avc_surface) {
202 gen7_avc_surface = calloc(sizeof(struct gen7_avc_surface), 1);
203 assert((obj_surface->size & 0x3f) == 0);
204 obj_surface->private_data = gen7_avc_surface;
207 gen7_avc_surface->dmv_bottom_flag = (pic_param->pic_fields.bits.field_pic_flag &&
208 !pic_param->seq_fields.bits.direct_8x8_inference_flag);
210 if (gen7_avc_surface->dmv_top == NULL) {
211 gen7_avc_surface->dmv_top = dri_bo_alloc(i965->intel.bufmgr,
212 "direct mv w/r buffer",
213 width_in_mbs * height_in_mbs * 64,
217 if (gen7_avc_surface->dmv_bottom_flag &&
218 gen7_avc_surface->dmv_bottom == NULL) {
219 gen7_avc_surface->dmv_bottom = dri_bo_alloc(i965->intel.bufmgr,
220 "direct mv w/r buffer",
221 width_in_mbs * height_in_mbs * 64,
227 gen7_mfd_pipe_mode_select(VADriverContextP ctx,
228 struct decode_state *decode_state,
230 struct gen7_mfd_context *gen7_mfd_context)
232 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
234 assert(standard_select == MFX_FORMAT_MPEG2 ||
235 standard_select == MFX_FORMAT_AVC ||
236 standard_select == MFX_FORMAT_VC1 ||
237 standard_select == MFX_FORMAT_JPEG);
239 BEGIN_BCS_BATCH(batch, 5);
240 OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
242 (MFX_LONG_MODE << 17) | /* Currently only support long format */
243 (MFD_MODE_VLD << 15) | /* VLD mode */
244 (0 << 10) | /* disable Stream-Out */
245 (gen7_mfd_context->post_deblocking_output.valid << 9) | /* Post Deblocking Output */
246 (gen7_mfd_context->pre_deblocking_output.valid << 8) | /* Pre Deblocking Output */
247 (0 << 5) | /* not in stitch mode */
248 (MFX_CODEC_DECODE << 4) | /* decoding mode */
249 (standard_select << 0));
251 (0 << 4) | /* terminate if AVC motion and POC table error occurs */
252 (0 << 3) | /* terminate if AVC mbdata error occurs */
253 (0 << 2) | /* terminate if AVC CABAC/CAVLC decode error occurs */
256 OUT_BCS_BATCH(batch, 0); /* pic status/error report id */
257 OUT_BCS_BATCH(batch, 0); /* reserved */
258 ADVANCE_BCS_BATCH(batch);
262 gen7_mfd_surface_state(VADriverContextP ctx,
263 struct decode_state *decode_state,
265 struct gen7_mfd_context *gen7_mfd_context)
267 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
268 struct i965_driver_data *i965 = i965_driver_data(ctx);
269 struct object_surface *obj_surface = SURFACE(decode_state->current_render_target);
270 unsigned int y_cb_offset;
271 unsigned int y_cr_offset;
275 y_cb_offset = obj_surface->y_cb_offset;
276 y_cr_offset = obj_surface->y_cr_offset;
278 BEGIN_BCS_BATCH(batch, 6);
279 OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
280 OUT_BCS_BATCH(batch, 0);
282 ((obj_surface->orig_height - 1) << 18) |
283 ((obj_surface->orig_width - 1) << 4));
285 (MFX_SURFACE_PLANAR_420_8 << 28) | /* 420 planar YUV surface */
286 ((standard_select != MFX_FORMAT_JPEG) << 27) | /* interleave chroma, set to 0 for JPEG */
287 (0 << 22) | /* surface object control state, ignored */
288 ((obj_surface->width - 1) << 3) | /* pitch */
289 (0 << 2) | /* must be 0 */
290 (1 << 1) | /* must be tiled */
291 (I965_TILEWALK_YMAJOR << 0)); /* tile walk, must be 1 */
293 (0 << 16) | /* X offset for U(Cb), must be 0 */
294 (y_cb_offset << 0)); /* Y offset for U(Cb) */
296 (0 << 16) | /* X offset for V(Cr), must be 0 */
297 (y_cr_offset << 0)); /* Y offset for V(Cr), must be 0 for video codec, non-zoro for JPEG */
298 ADVANCE_BCS_BATCH(batch);
302 gen7_mfd_pipe_buf_addr_state(VADriverContextP ctx,
303 struct decode_state *decode_state,
305 struct gen7_mfd_context *gen7_mfd_context)
307 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
308 struct i965_driver_data *i965 = i965_driver_data(ctx);
311 BEGIN_BCS_BATCH(batch, 24);
312 OUT_BCS_BATCH(batch, MFX_PIPE_BUF_ADDR_STATE | (24 - 2));
313 if (gen7_mfd_context->pre_deblocking_output.valid)
314 OUT_BCS_RELOC(batch, gen7_mfd_context->pre_deblocking_output.bo,
315 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
318 OUT_BCS_BATCH(batch, 0);
320 if (gen7_mfd_context->post_deblocking_output.valid)
321 OUT_BCS_RELOC(batch, gen7_mfd_context->post_deblocking_output.bo,
322 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
325 OUT_BCS_BATCH(batch, 0);
327 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
328 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
330 if (gen7_mfd_context->intra_row_store_scratch_buffer.valid)
331 OUT_BCS_RELOC(batch, gen7_mfd_context->intra_row_store_scratch_buffer.bo,
332 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
335 OUT_BCS_BATCH(batch, 0);
337 if (gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid)
338 OUT_BCS_RELOC(batch, gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo,
339 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
342 OUT_BCS_BATCH(batch, 0);
345 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
346 struct object_surface *obj_surface;
348 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
349 obj_surface = SURFACE(gen7_mfd_context->reference_surface[i].surface_id);
350 assert(obj_surface && obj_surface->bo);
352 OUT_BCS_RELOC(batch, obj_surface->bo,
353 I915_GEM_DOMAIN_INSTRUCTION, 0,
356 OUT_BCS_BATCH(batch, 0);
360 OUT_BCS_BATCH(batch, 0); /* ignore DW23 for decoding */
361 ADVANCE_BCS_BATCH(batch);
365 gen7_mfd_ind_obj_base_addr_state(VADriverContextP ctx,
366 dri_bo *slice_data_bo,
368 struct gen7_mfd_context *gen7_mfd_context)
370 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
372 BEGIN_BCS_BATCH(batch, 11);
373 OUT_BCS_BATCH(batch, MFX_IND_OBJ_BASE_ADDR_STATE | (11 - 2));
374 OUT_BCS_RELOC(batch, slice_data_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); /* MFX Indirect Bitstream Object Base Address */
375 OUT_BCS_BATCH(batch, 0x80000000); /* must set, up to 2G */
376 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
377 OUT_BCS_BATCH(batch, 0);
378 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
379 OUT_BCS_BATCH(batch, 0);
380 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
381 OUT_BCS_BATCH(batch, 0);
382 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
383 OUT_BCS_BATCH(batch, 0);
384 ADVANCE_BCS_BATCH(batch);
388 gen7_mfd_bsp_buf_base_addr_state(VADriverContextP ctx,
389 struct decode_state *decode_state,
391 struct gen7_mfd_context *gen7_mfd_context)
393 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
395 BEGIN_BCS_BATCH(batch, 4);
396 OUT_BCS_BATCH(batch, MFX_BSP_BUF_BASE_ADDR_STATE | (4 - 2));
398 if (gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid)
399 OUT_BCS_RELOC(batch, gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo,
400 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
403 OUT_BCS_BATCH(batch, 0);
405 if (gen7_mfd_context->mpr_row_store_scratch_buffer.valid)
406 OUT_BCS_RELOC(batch, gen7_mfd_context->mpr_row_store_scratch_buffer.bo,
407 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
410 OUT_BCS_BATCH(batch, 0);
412 if (gen7_mfd_context->bitplane_read_buffer.valid)
413 OUT_BCS_RELOC(batch, gen7_mfd_context->bitplane_read_buffer.bo,
414 I915_GEM_DOMAIN_INSTRUCTION, 0,
417 OUT_BCS_BATCH(batch, 0);
419 ADVANCE_BCS_BATCH(batch);
424 gen7_mfd_aes_state(VADriverContextP ctx,
425 struct decode_state *decode_state,
433 gen7_mfd_qm_state(VADriverContextP ctx,
437 struct gen7_mfd_context *gen7_mfd_context)
439 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
440 unsigned int qm_buffer[16];
442 assert(qm_length <= 16 * 4);
443 memcpy(qm_buffer, qm, qm_length);
445 BEGIN_BCS_BATCH(batch, 18);
446 OUT_BCS_BATCH(batch, MFX_QM_STATE | (18 - 2));
447 OUT_BCS_BATCH(batch, qm_type << 0);
448 intel_batchbuffer_data(batch, qm_buffer, 16 * 4);
449 ADVANCE_BCS_BATCH(batch);
454 gen7_mfd_wait(VADriverContextP ctx,
455 struct decode_state *decode_state,
457 struct gen7_mfd_context *gen7_mfd_context)
459 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
461 BEGIN_BCS_BATCH(batch, 1);
462 OUT_BCS_BATCH(batch, MFX_WAIT | (1 << 8));
463 ADVANCE_BCS_BATCH(batch);
468 gen7_mfd_avc_img_state(VADriverContextP ctx,
469 struct decode_state *decode_state,
470 struct gen7_mfd_context *gen7_mfd_context)
472 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
474 int mbaff_frame_flag;
475 unsigned int width_in_mbs, height_in_mbs;
476 VAPictureParameterBufferH264 *pic_param;
478 assert(decode_state->pic_param && decode_state->pic_param->buffer);
479 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
480 assert(!(pic_param->CurrPic.flags & VA_PICTURE_H264_INVALID));
482 if (pic_param->CurrPic.flags & VA_PICTURE_H264_TOP_FIELD)
484 else if (pic_param->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD)
489 if ((img_struct & 0x1) == 0x1) {
490 assert(pic_param->pic_fields.bits.field_pic_flag == 0x1);
492 assert(pic_param->pic_fields.bits.field_pic_flag == 0x0);
495 if (pic_param->seq_fields.bits.frame_mbs_only_flag) { /* a frame containing only frame macroblocks */
496 assert(pic_param->seq_fields.bits.mb_adaptive_frame_field_flag == 0);
497 assert(pic_param->pic_fields.bits.field_pic_flag == 0);
499 assert(pic_param->seq_fields.bits.direct_8x8_inference_flag == 1); /* see H.264 spec */
502 mbaff_frame_flag = (pic_param->seq_fields.bits.mb_adaptive_frame_field_flag &&
503 !pic_param->pic_fields.bits.field_pic_flag);
505 width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
506 height_in_mbs = ((pic_param->picture_height_in_mbs_minus1 + 1) & 0xff); /* frame height */
508 /* MFX unit doesn't support 4:2:2 and 4:4:4 picture */
509 assert(pic_param->seq_fields.bits.chroma_format_idc == 0 || /* monochrome picture */
510 pic_param->seq_fields.bits.chroma_format_idc == 1); /* 4:2:0 */
511 assert(pic_param->seq_fields.bits.residual_colour_transform_flag == 0); /* only available for 4:4:4 */
513 BEGIN_BCS_BATCH(batch, 16);
514 OUT_BCS_BATCH(batch, MFX_AVC_IMG_STATE | (16 - 2));
516 width_in_mbs * height_in_mbs);
518 ((height_in_mbs - 1) << 16) |
519 ((width_in_mbs - 1) << 0));
521 ((pic_param->second_chroma_qp_index_offset & 0x1f) << 24) |
522 ((pic_param->chroma_qp_index_offset & 0x1f) << 16) |
523 (0 << 14) | /* Max-bit conformance Intra flag ??? FIXME */
524 (0 << 13) | /* Max Macroblock size conformance Inter flag ??? FIXME */
525 (pic_param->pic_fields.bits.weighted_pred_flag << 12) | /* differ from GEN6 */
526 (pic_param->pic_fields.bits.weighted_bipred_idc << 10) |
529 (pic_param->seq_fields.bits.chroma_format_idc << 10) |
530 (pic_param->pic_fields.bits.entropy_coding_mode_flag << 7) |
531 ((!pic_param->pic_fields.bits.reference_pic_flag) << 6) |
532 (pic_param->pic_fields.bits.constrained_intra_pred_flag << 5) |
533 (pic_param->seq_fields.bits.direct_8x8_inference_flag << 4) |
534 (pic_param->pic_fields.bits.transform_8x8_mode_flag << 3) |
535 (pic_param->seq_fields.bits.frame_mbs_only_flag << 2) |
536 (mbaff_frame_flag << 1) |
537 (pic_param->pic_fields.bits.field_pic_flag << 0));
538 OUT_BCS_BATCH(batch, 0);
539 OUT_BCS_BATCH(batch, 0);
540 OUT_BCS_BATCH(batch, 0);
541 OUT_BCS_BATCH(batch, 0);
542 OUT_BCS_BATCH(batch, 0);
543 OUT_BCS_BATCH(batch, 0);
544 OUT_BCS_BATCH(batch, 0);
545 OUT_BCS_BATCH(batch, 0);
546 OUT_BCS_BATCH(batch, 0);
547 OUT_BCS_BATCH(batch, 0);
548 OUT_BCS_BATCH(batch, 0);
549 ADVANCE_BCS_BATCH(batch);
553 gen7_mfd_avc_qm_state(VADriverContextP ctx,
554 struct decode_state *decode_state,
555 struct gen7_mfd_context *gen7_mfd_context)
557 VAIQMatrixBufferH264 *iq_matrix;
558 VAPictureParameterBufferH264 *pic_param;
560 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer)
561 iq_matrix = (VAIQMatrixBufferH264 *)decode_state->iq_matrix->buffer;
563 iq_matrix = &gen7_mfd_context->iq_matrix.h264;
565 assert(decode_state->pic_param && decode_state->pic_param->buffer);
566 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
568 gen7_mfd_qm_state(ctx, MFX_QM_AVC_4X4_INTRA_MATRIX, &iq_matrix->ScalingList4x4[0][0], 3 * 16, gen7_mfd_context);
569 gen7_mfd_qm_state(ctx, MFX_QM_AVC_4X4_INTER_MATRIX, &iq_matrix->ScalingList4x4[3][0], 3 * 16, gen7_mfd_context);
571 if (pic_param->pic_fields.bits.transform_8x8_mode_flag) {
572 gen7_mfd_qm_state(ctx, MFX_QM_AVC_8x8_INTRA_MATRIX, &iq_matrix->ScalingList8x8[0][0], 64, gen7_mfd_context);
573 gen7_mfd_qm_state(ctx, MFX_QM_AVC_8x8_INTER_MATRIX, &iq_matrix->ScalingList8x8[1][0], 64, gen7_mfd_context);
578 gen7_mfd_avc_directmode_state(VADriverContextP ctx,
579 VAPictureParameterBufferH264 *pic_param,
580 VASliceParameterBufferH264 *slice_param,
581 struct gen7_mfd_context *gen7_mfd_context)
583 struct i965_driver_data *i965 = i965_driver_data(ctx);
584 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
585 struct object_surface *obj_surface;
586 struct gen7_avc_surface *gen7_avc_surface;
587 VAPictureH264 *va_pic;
590 BEGIN_BCS_BATCH(batch, 69);
591 OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
593 /* reference surfaces 0..15 */
594 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
595 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
596 obj_surface = SURFACE(gen7_mfd_context->reference_surface[i].surface_id);
598 gen7_avc_surface = obj_surface->private_data;
600 if (gen7_avc_surface == NULL) {
601 OUT_BCS_BATCH(batch, 0);
602 OUT_BCS_BATCH(batch, 0);
604 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
605 I915_GEM_DOMAIN_INSTRUCTION, 0,
608 if (gen7_avc_surface->dmv_bottom_flag == 1)
609 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_bottom,
610 I915_GEM_DOMAIN_INSTRUCTION, 0,
613 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
614 I915_GEM_DOMAIN_INSTRUCTION, 0,
618 OUT_BCS_BATCH(batch, 0);
619 OUT_BCS_BATCH(batch, 0);
623 /* the current decoding frame/field */
624 va_pic = &pic_param->CurrPic;
625 assert(!(va_pic->flags & VA_PICTURE_H264_INVALID));
626 obj_surface = SURFACE(va_pic->picture_id);
627 assert(obj_surface && obj_surface->bo && obj_surface->private_data);
628 gen7_avc_surface = obj_surface->private_data;
630 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
631 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
634 if (gen7_avc_surface->dmv_bottom_flag == 1)
635 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_bottom,
636 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
639 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
640 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
644 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
645 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
647 for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
648 va_pic = &pic_param->ReferenceFrames[j];
650 if (va_pic->flags & VA_PICTURE_H264_INVALID)
653 if (va_pic->picture_id == gen7_mfd_context->reference_surface[i].surface_id) {
660 assert(!(va_pic->flags & VA_PICTURE_H264_INVALID));
662 OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt);
663 OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt);
665 OUT_BCS_BATCH(batch, 0);
666 OUT_BCS_BATCH(batch, 0);
670 va_pic = &pic_param->CurrPic;
671 OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt);
672 OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt);
674 ADVANCE_BCS_BATCH(batch);
678 gen7_mfd_avc_slice_state(VADriverContextP ctx,
679 VAPictureParameterBufferH264 *pic_param,
680 VASliceParameterBufferH264 *slice_param,
681 VASliceParameterBufferH264 *next_slice_param,
682 struct gen7_mfd_context *gen7_mfd_context)
684 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
685 int width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
686 int height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1;
687 int slice_hor_pos, slice_ver_pos, next_slice_hor_pos, next_slice_ver_pos;
688 int num_ref_idx_l0, num_ref_idx_l1;
689 int mbaff_picture = (!pic_param->pic_fields.bits.field_pic_flag &&
690 pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
691 int first_mb_in_slice = 0, first_mb_in_next_slice = 0;
694 if (slice_param->slice_type == SLICE_TYPE_I ||
695 slice_param->slice_type == SLICE_TYPE_SI) {
696 slice_type = SLICE_TYPE_I;
697 } else if (slice_param->slice_type == SLICE_TYPE_P ||
698 slice_param->slice_type == SLICE_TYPE_SP) {
699 slice_type = SLICE_TYPE_P;
701 assert(slice_param->slice_type == SLICE_TYPE_B);
702 slice_type = SLICE_TYPE_B;
705 if (slice_type == SLICE_TYPE_I) {
706 assert(slice_param->num_ref_idx_l0_active_minus1 == 0);
707 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
710 } else if (slice_type == SLICE_TYPE_P) {
711 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
712 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
715 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
716 num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
719 first_mb_in_slice = slice_param->first_mb_in_slice << mbaff_picture;
720 slice_hor_pos = first_mb_in_slice % width_in_mbs;
721 slice_ver_pos = first_mb_in_slice / width_in_mbs;
723 if (next_slice_param) {
724 first_mb_in_next_slice = next_slice_param->first_mb_in_slice << mbaff_picture;
725 next_slice_hor_pos = first_mb_in_next_slice % width_in_mbs;
726 next_slice_ver_pos = first_mb_in_next_slice / width_in_mbs;
728 next_slice_hor_pos = 0;
729 next_slice_ver_pos = height_in_mbs / (1 + !!pic_param->pic_fields.bits.field_pic_flag);
732 BEGIN_BCS_BATCH(batch, 11); /* FIXME: is it 10??? */
733 OUT_BCS_BATCH(batch, MFX_AVC_SLICE_STATE | (11 - 2));
734 OUT_BCS_BATCH(batch, slice_type);
736 (num_ref_idx_l1 << 24) |
737 (num_ref_idx_l0 << 16) |
738 (slice_param->chroma_log2_weight_denom << 8) |
739 (slice_param->luma_log2_weight_denom << 0));
741 (slice_param->direct_spatial_mv_pred_flag << 29) |
742 (slice_param->disable_deblocking_filter_idc << 27) |
743 (slice_param->cabac_init_idc << 24) |
744 ((pic_param->pic_init_qp_minus26 + 26 + slice_param->slice_qp_delta) << 16) |
745 ((slice_param->slice_beta_offset_div2 & 0xf) << 8) |
746 ((slice_param->slice_alpha_c0_offset_div2 & 0xf) << 0));
748 (slice_ver_pos << 24) |
749 (slice_hor_pos << 16) |
750 (first_mb_in_slice << 0));
752 (next_slice_ver_pos << 16) |
753 (next_slice_hor_pos << 0));
755 (next_slice_param == NULL) << 19); /* last slice flag */
756 OUT_BCS_BATCH(batch, 0);
757 OUT_BCS_BATCH(batch, 0);
758 OUT_BCS_BATCH(batch, 0);
759 OUT_BCS_BATCH(batch, 0);
760 ADVANCE_BCS_BATCH(batch);
764 gen7_mfd_avc_ref_idx_state(VADriverContextP ctx,
765 VAPictureParameterBufferH264 *pic_param,
766 VASliceParameterBufferH264 *slice_param,
767 struct gen7_mfd_context *gen7_mfd_context)
769 gen6_send_avc_ref_idx_state(
770 gen7_mfd_context->base.batch,
772 gen7_mfd_context->reference_surface
777 gen7_mfd_avc_weightoffset_state(VADriverContextP ctx,
778 VAPictureParameterBufferH264 *pic_param,
779 VASliceParameterBufferH264 *slice_param,
780 struct gen7_mfd_context *gen7_mfd_context)
782 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
783 int i, j, num_weight_offset_table = 0;
784 short weightoffsets[32 * 6];
786 if ((slice_param->slice_type == SLICE_TYPE_P ||
787 slice_param->slice_type == SLICE_TYPE_SP) &&
788 (pic_param->pic_fields.bits.weighted_pred_flag == 1)) {
789 num_weight_offset_table = 1;
792 if ((slice_param->slice_type == SLICE_TYPE_B) &&
793 (pic_param->pic_fields.bits.weighted_bipred_idc == 1)) {
794 num_weight_offset_table = 2;
797 for (i = 0; i < num_weight_offset_table; i++) {
798 BEGIN_BCS_BATCH(batch, 98);
799 OUT_BCS_BATCH(batch, MFX_AVC_WEIGHTOFFSET_STATE | (98 - 2));
800 OUT_BCS_BATCH(batch, i);
803 for (j = 0; j < 32; j++) {
804 weightoffsets[j * 6 + 0] = slice_param->luma_weight_l0[j];
805 weightoffsets[j * 6 + 1] = slice_param->luma_offset_l0[j];
806 weightoffsets[j * 6 + 2] = slice_param->chroma_weight_l0[j][0];
807 weightoffsets[j * 6 + 3] = slice_param->chroma_offset_l0[j][0];
808 weightoffsets[j * 6 + 4] = slice_param->chroma_weight_l0[j][1];
809 weightoffsets[j * 6 + 5] = slice_param->chroma_offset_l0[j][1];
812 for (j = 0; j < 32; j++) {
813 weightoffsets[j * 6 + 0] = slice_param->luma_weight_l1[j];
814 weightoffsets[j * 6 + 1] = slice_param->luma_offset_l1[j];
815 weightoffsets[j * 6 + 2] = slice_param->chroma_weight_l1[j][0];
816 weightoffsets[j * 6 + 3] = slice_param->chroma_offset_l1[j][0];
817 weightoffsets[j * 6 + 4] = slice_param->chroma_weight_l1[j][1];
818 weightoffsets[j * 6 + 5] = slice_param->chroma_offset_l1[j][1];
822 intel_batchbuffer_data(batch, weightoffsets, sizeof(weightoffsets));
823 ADVANCE_BCS_BATCH(batch);
828 gen7_mfd_avc_get_slice_bit_offset(uint8_t *buf, int mode_flag, int in_slice_data_bit_offset)
830 int out_slice_data_bit_offset;
831 int slice_header_size = in_slice_data_bit_offset / 8;
834 for (i = 0, j = 0; i < slice_header_size; i++, j++) {
835 if (!buf[j] && !buf[j + 1] && buf[j + 2] == 3) {
840 out_slice_data_bit_offset = 8 * j + in_slice_data_bit_offset % 8;
842 if (mode_flag == ENTROPY_CABAC)
843 out_slice_data_bit_offset = ALIGN(out_slice_data_bit_offset, 0x8);
845 return out_slice_data_bit_offset;
849 gen7_mfd_avc_bsd_object(VADriverContextP ctx,
850 VAPictureParameterBufferH264 *pic_param,
851 VASliceParameterBufferH264 *slice_param,
852 dri_bo *slice_data_bo,
853 VASliceParameterBufferH264 *next_slice_param,
854 struct gen7_mfd_context *gen7_mfd_context)
856 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
857 int slice_data_bit_offset;
858 uint8_t *slice_data = NULL;
860 dri_bo_map(slice_data_bo, 0);
861 slice_data = (uint8_t *)(slice_data_bo->virtual + slice_param->slice_data_offset);
862 slice_data_bit_offset = gen7_mfd_avc_get_slice_bit_offset(slice_data,
863 pic_param->pic_fields.bits.entropy_coding_mode_flag,
864 slice_param->slice_data_bit_offset);
865 dri_bo_unmap(slice_data_bo);
867 /* the input bitsteam format on GEN7 differs from GEN6 */
868 BEGIN_BCS_BATCH(batch, 6);
869 OUT_BCS_BATCH(batch, MFD_AVC_BSD_OBJECT | (6 - 2));
871 (slice_param->slice_data_size));
872 OUT_BCS_BATCH(batch, slice_param->slice_data_offset);
880 ((slice_data_bit_offset >> 3) << 16) |
883 ((next_slice_param == NULL) << 3) | /* LastSlice Flag */
884 (slice_data_bit_offset & 0x7));
885 OUT_BCS_BATCH(batch, 0);
886 ADVANCE_BCS_BATCH(batch);
890 gen7_mfd_avc_context_init(
891 VADriverContextP ctx,
892 struct gen7_mfd_context *gen7_mfd_context
895 /* Initialize flat scaling lists */
896 avc_gen_default_iq_matrix(&gen7_mfd_context->iq_matrix.h264);
900 gen7_mfd_avc_decode_init(VADriverContextP ctx,
901 struct decode_state *decode_state,
902 struct gen7_mfd_context *gen7_mfd_context)
904 VAPictureParameterBufferH264 *pic_param;
905 VASliceParameterBufferH264 *slice_param;
906 VAPictureH264 *va_pic;
907 struct i965_driver_data *i965 = i965_driver_data(ctx);
908 struct object_surface *obj_surface;
910 int i, j, enable_avc_ildb = 0;
913 for (j = 0; j < decode_state->num_slice_params && enable_avc_ildb == 0; j++) {
914 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
915 slice_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j]->buffer;
917 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
918 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
919 assert((slice_param->slice_type == SLICE_TYPE_I) ||
920 (slice_param->slice_type == SLICE_TYPE_SI) ||
921 (slice_param->slice_type == SLICE_TYPE_P) ||
922 (slice_param->slice_type == SLICE_TYPE_SP) ||
923 (slice_param->slice_type == SLICE_TYPE_B));
925 if (slice_param->disable_deblocking_filter_idc != 1) {
934 assert(decode_state->pic_param && decode_state->pic_param->buffer);
935 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
936 gen7_mfd_avc_frame_store_index(ctx, pic_param, gen7_mfd_context);
937 width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
939 /* Current decoded picture */
940 va_pic = &pic_param->CurrPic;
941 assert(!(va_pic->flags & VA_PICTURE_H264_INVALID));
942 obj_surface = SURFACE(va_pic->picture_id);
944 obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
945 obj_surface->flags |= (pic_param->pic_fields.bits.reference_pic_flag ? SURFACE_REFERENCED : 0);
946 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
947 gen7_mfd_init_avc_surface(ctx, pic_param, obj_surface);
949 dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
950 gen7_mfd_context->post_deblocking_output.bo = obj_surface->bo;
951 dri_bo_reference(gen7_mfd_context->post_deblocking_output.bo);
952 gen7_mfd_context->post_deblocking_output.valid = enable_avc_ildb;
954 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
955 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
956 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
957 gen7_mfd_context->pre_deblocking_output.valid = !enable_avc_ildb;
959 dri_bo_unreference(gen7_mfd_context->intra_row_store_scratch_buffer.bo);
960 bo = dri_bo_alloc(i965->intel.bufmgr,
965 gen7_mfd_context->intra_row_store_scratch_buffer.bo = bo;
966 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 1;
968 dri_bo_unreference(gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo);
969 bo = dri_bo_alloc(i965->intel.bufmgr,
970 "deblocking filter row store",
971 width_in_mbs * 64 * 4,
974 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = bo;
975 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 1;
977 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
978 bo = dri_bo_alloc(i965->intel.bufmgr,
980 width_in_mbs * 64 * 2,
983 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = bo;
984 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 1;
986 dri_bo_unreference(gen7_mfd_context->mpr_row_store_scratch_buffer.bo);
987 bo = dri_bo_alloc(i965->intel.bufmgr,
989 width_in_mbs * 64 * 2,
992 gen7_mfd_context->mpr_row_store_scratch_buffer.bo = bo;
993 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 1;
995 gen7_mfd_context->bitplane_read_buffer.valid = 0;
999 gen7_mfd_avc_decode_picture(VADriverContextP ctx,
1000 struct decode_state *decode_state,
1001 struct gen7_mfd_context *gen7_mfd_context)
1003 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1004 VAPictureParameterBufferH264 *pic_param;
1005 VASliceParameterBufferH264 *slice_param, *next_slice_param, *next_slice_group_param;
1006 dri_bo *slice_data_bo;
1009 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1010 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
1011 gen7_mfd_avc_decode_init(ctx, decode_state, gen7_mfd_context);
1013 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
1014 intel_batchbuffer_emit_mi_flush(batch);
1015 gen7_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1016 gen7_mfd_surface_state(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1017 gen7_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1018 gen7_mfd_bsp_buf_base_addr_state(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1019 gen7_mfd_avc_qm_state(ctx, decode_state, gen7_mfd_context);
1020 gen7_mfd_avc_img_state(ctx, decode_state, gen7_mfd_context);
1022 for (j = 0; j < decode_state->num_slice_params; j++) {
1023 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
1024 slice_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j]->buffer;
1025 slice_data_bo = decode_state->slice_datas[j]->bo;
1026 gen7_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_AVC, gen7_mfd_context);
1028 if (j == decode_state->num_slice_params - 1)
1029 next_slice_group_param = NULL;
1031 next_slice_group_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j + 1]->buffer;
1033 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
1034 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
1035 assert((slice_param->slice_type == SLICE_TYPE_I) ||
1036 (slice_param->slice_type == SLICE_TYPE_SI) ||
1037 (slice_param->slice_type == SLICE_TYPE_P) ||
1038 (slice_param->slice_type == SLICE_TYPE_SP) ||
1039 (slice_param->slice_type == SLICE_TYPE_B));
1041 if (i < decode_state->slice_params[j]->num_elements - 1)
1042 next_slice_param = slice_param + 1;
1044 next_slice_param = next_slice_group_param;
1046 gen7_mfd_avc_directmode_state(ctx, pic_param, slice_param, gen7_mfd_context);
1047 gen7_mfd_avc_ref_idx_state(ctx, pic_param, slice_param, gen7_mfd_context);
1048 gen7_mfd_avc_weightoffset_state(ctx, pic_param, slice_param, gen7_mfd_context);
1049 gen7_mfd_avc_slice_state(ctx, pic_param, slice_param, next_slice_param, gen7_mfd_context);
1050 gen7_mfd_avc_bsd_object(ctx, pic_param, slice_param, slice_data_bo, next_slice_param, gen7_mfd_context);
1055 intel_batchbuffer_end_atomic(batch);
1056 intel_batchbuffer_flush(batch);
1060 gen7_mfd_mpeg2_decode_init(VADriverContextP ctx,
1061 struct decode_state *decode_state,
1062 struct gen7_mfd_context *gen7_mfd_context)
1064 VAPictureParameterBufferMPEG2 *pic_param;
1065 struct i965_driver_data *i965 = i965_driver_data(ctx);
1066 struct object_surface *obj_surface;
1068 unsigned int width_in_mbs;
1070 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1071 pic_param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
1072 width_in_mbs = ALIGN(pic_param->horizontal_size, 16) / 16;
1074 mpeg2_set_reference_surfaces(
1076 gen7_mfd_context->reference_surface,
1081 /* Current decoded picture */
1082 obj_surface = SURFACE(decode_state->current_render_target);
1083 assert(obj_surface);
1084 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
1086 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
1087 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
1088 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
1089 gen7_mfd_context->pre_deblocking_output.valid = 1;
1091 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
1092 bo = dri_bo_alloc(i965->intel.bufmgr,
1093 "bsd mpc row store",
1097 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = bo;
1098 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 1;
1100 gen7_mfd_context->post_deblocking_output.valid = 0;
1101 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 0;
1102 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 0;
1103 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 0;
1104 gen7_mfd_context->bitplane_read_buffer.valid = 0;
1108 gen7_mfd_mpeg2_pic_state(VADriverContextP ctx,
1109 struct decode_state *decode_state,
1110 struct gen7_mfd_context *gen7_mfd_context)
1112 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1113 VAPictureParameterBufferMPEG2 *pic_param;
1115 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1116 pic_param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
1118 BEGIN_BCS_BATCH(batch, 13);
1119 OUT_BCS_BATCH(batch, MFX_MPEG2_PIC_STATE | (13 - 2));
1120 OUT_BCS_BATCH(batch,
1121 (pic_param->f_code & 0xf) << 28 | /* f_code[1][1] */
1122 ((pic_param->f_code >> 4) & 0xf) << 24 | /* f_code[1][0] */
1123 ((pic_param->f_code >> 8) & 0xf) << 20 | /* f_code[0][1] */
1124 ((pic_param->f_code >> 12) & 0xf) << 16 | /* f_code[0][0] */
1125 pic_param->picture_coding_extension.bits.intra_dc_precision << 14 |
1126 pic_param->picture_coding_extension.bits.picture_structure << 12 |
1127 pic_param->picture_coding_extension.bits.top_field_first << 11 |
1128 pic_param->picture_coding_extension.bits.frame_pred_frame_dct << 10 |
1129 pic_param->picture_coding_extension.bits.concealment_motion_vectors << 9 |
1130 pic_param->picture_coding_extension.bits.q_scale_type << 8 |
1131 pic_param->picture_coding_extension.bits.intra_vlc_format << 7 |
1132 pic_param->picture_coding_extension.bits.alternate_scan << 6);
1133 OUT_BCS_BATCH(batch,
1134 pic_param->picture_coding_type << 9);
1135 OUT_BCS_BATCH(batch,
1136 ((ALIGN(pic_param->vertical_size, 16) / 16) - 1) << 16 |
1137 ((ALIGN(pic_param->horizontal_size, 16) / 16) - 1));
1138 OUT_BCS_BATCH(batch, 0);
1139 OUT_BCS_BATCH(batch, 0);
1140 OUT_BCS_BATCH(batch, 0);
1141 OUT_BCS_BATCH(batch, 0);
1142 OUT_BCS_BATCH(batch, 0);
1143 OUT_BCS_BATCH(batch, 0);
1144 OUT_BCS_BATCH(batch, 0);
1145 OUT_BCS_BATCH(batch, 0);
1146 OUT_BCS_BATCH(batch, 0);
1147 ADVANCE_BCS_BATCH(batch);
1151 gen7_mfd_mpeg2_qm_state(VADriverContextP ctx,
1152 struct decode_state *decode_state,
1153 struct gen7_mfd_context *gen7_mfd_context)
1155 VAIQMatrixBufferMPEG2 * const gen_iq_matrix = &gen7_mfd_context->iq_matrix.mpeg2;
1158 /* Update internal QM state */
1159 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer) {
1160 VAIQMatrixBufferMPEG2 * const iq_matrix =
1161 (VAIQMatrixBufferMPEG2 *)decode_state->iq_matrix->buffer;
1163 if (gen_iq_matrix->load_intra_quantiser_matrix == -1 ||
1164 iq_matrix->load_intra_quantiser_matrix) {
1165 gen_iq_matrix->load_intra_quantiser_matrix =
1166 iq_matrix->load_intra_quantiser_matrix;
1167 if (iq_matrix->load_intra_quantiser_matrix) {
1168 for (j = 0; j < 64; j++)
1169 gen_iq_matrix->intra_quantiser_matrix[zigzag_direct[j]] =
1170 iq_matrix->intra_quantiser_matrix[j];
1174 if (gen_iq_matrix->load_non_intra_quantiser_matrix == -1 ||
1175 iq_matrix->load_non_intra_quantiser_matrix) {
1176 gen_iq_matrix->load_non_intra_quantiser_matrix =
1177 iq_matrix->load_non_intra_quantiser_matrix;
1178 if (iq_matrix->load_non_intra_quantiser_matrix) {
1179 for (j = 0; j < 64; j++)
1180 gen_iq_matrix->non_intra_quantiser_matrix[zigzag_direct[j]] =
1181 iq_matrix->non_intra_quantiser_matrix[j];
1186 /* Commit QM state to HW */
1187 for (i = 0; i < 2; i++) {
1188 unsigned char *qm = NULL;
1192 if (gen_iq_matrix->load_intra_quantiser_matrix) {
1193 qm = gen_iq_matrix->intra_quantiser_matrix;
1194 qm_type = MFX_QM_MPEG_INTRA_QUANTIZER_MATRIX;
1197 if (gen_iq_matrix->load_non_intra_quantiser_matrix) {
1198 qm = gen_iq_matrix->non_intra_quantiser_matrix;
1199 qm_type = MFX_QM_MPEG_NON_INTRA_QUANTIZER_MATRIX;
1206 gen7_mfd_qm_state(ctx, qm_type, qm, 64, gen7_mfd_context);
1211 gen7_mfd_mpeg2_bsd_object(VADriverContextP ctx,
1212 VAPictureParameterBufferMPEG2 *pic_param,
1213 VASliceParameterBufferMPEG2 *slice_param,
1214 VASliceParameterBufferMPEG2 *next_slice_param,
1215 struct gen7_mfd_context *gen7_mfd_context)
1217 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1218 unsigned int width_in_mbs = ALIGN(pic_param->horizontal_size, 16) / 16;
1219 int mb_count, vpos0, hpos0, vpos1, hpos1, is_field_pic_wa, is_field_pic = 0;
1221 if (pic_param->picture_coding_extension.bits.picture_structure == MPEG_TOP_FIELD ||
1222 pic_param->picture_coding_extension.bits.picture_structure == MPEG_BOTTOM_FIELD)
1224 is_field_pic_wa = is_field_pic &&
1225 gen7_mfd_context->wa_mpeg2_slice_vertical_position > 0;
1227 vpos0 = slice_param->slice_vertical_position / (1 + is_field_pic_wa);
1228 hpos0 = slice_param->slice_horizontal_position;
1230 if (next_slice_param == NULL) {
1231 vpos1 = ALIGN(pic_param->vertical_size, 16) / 16 / (1 + is_field_pic);
1234 vpos1 = next_slice_param->slice_vertical_position / (1 + is_field_pic_wa);
1235 hpos1 = next_slice_param->slice_horizontal_position;
1238 mb_count = (vpos1 * width_in_mbs + hpos1) - (vpos0 * width_in_mbs + hpos0);
1240 BEGIN_BCS_BATCH(batch, 5);
1241 OUT_BCS_BATCH(batch, MFD_MPEG2_BSD_OBJECT | (5 - 2));
1242 OUT_BCS_BATCH(batch,
1243 slice_param->slice_data_size - (slice_param->macroblock_offset >> 3));
1244 OUT_BCS_BATCH(batch,
1245 slice_param->slice_data_offset + (slice_param->macroblock_offset >> 3));
1246 OUT_BCS_BATCH(batch,
1250 (next_slice_param == NULL) << 5 |
1251 (next_slice_param == NULL) << 3 |
1252 (slice_param->macroblock_offset & 0x7));
1253 OUT_BCS_BATCH(batch,
1254 slice_param->quantiser_scale_code << 24);
1255 ADVANCE_BCS_BATCH(batch);
1259 gen7_mfd_mpeg2_decode_picture(VADriverContextP ctx,
1260 struct decode_state *decode_state,
1261 struct gen7_mfd_context *gen7_mfd_context)
1263 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1264 VAPictureParameterBufferMPEG2 *pic_param;
1265 VASliceParameterBufferMPEG2 *slice_param, *next_slice_param, *next_slice_group_param;
1266 dri_bo *slice_data_bo;
1269 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1270 pic_param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
1272 gen7_mfd_mpeg2_decode_init(ctx, decode_state, gen7_mfd_context);
1273 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
1274 intel_batchbuffer_emit_mi_flush(batch);
1275 gen7_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1276 gen7_mfd_surface_state(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1277 gen7_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1278 gen7_mfd_bsp_buf_base_addr_state(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1279 gen7_mfd_mpeg2_pic_state(ctx, decode_state, gen7_mfd_context);
1280 gen7_mfd_mpeg2_qm_state(ctx, decode_state, gen7_mfd_context);
1282 if (gen7_mfd_context->wa_mpeg2_slice_vertical_position < 0)
1283 gen7_mfd_context->wa_mpeg2_slice_vertical_position =
1284 mpeg2_wa_slice_vertical_position(decode_state, pic_param);
1286 for (j = 0; j < decode_state->num_slice_params; j++) {
1287 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
1288 slice_param = (VASliceParameterBufferMPEG2 *)decode_state->slice_params[j]->buffer;
1289 slice_data_bo = decode_state->slice_datas[j]->bo;
1290 gen7_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_MPEG2, gen7_mfd_context);
1292 if (j == decode_state->num_slice_params - 1)
1293 next_slice_group_param = NULL;
1295 next_slice_group_param = (VASliceParameterBufferMPEG2 *)decode_state->slice_params[j + 1]->buffer;
1297 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
1298 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
1300 if (i < decode_state->slice_params[j]->num_elements - 1)
1301 next_slice_param = slice_param + 1;
1303 next_slice_param = next_slice_group_param;
1305 gen7_mfd_mpeg2_bsd_object(ctx, pic_param, slice_param, next_slice_param, gen7_mfd_context);
1310 intel_batchbuffer_end_atomic(batch);
1311 intel_batchbuffer_flush(batch);
1314 static const int va_to_gen7_vc1_pic_type[5] = {
1318 GEN7_VC1_BI_PICTURE,
1322 static const int va_to_gen7_vc1_mv[4] = {
1324 2, /* 1-MV half-pel */
1325 3, /* 1-MV half-pef bilinear */
1329 static const int b_picture_scale_factor[21] = {
1330 128, 85, 170, 64, 192,
1331 51, 102, 153, 204, 43,
1332 215, 37, 74, 111, 148,
1333 185, 222, 32, 96, 160,
1337 static const int va_to_gen7_vc1_condover[3] = {
1343 static const int va_to_gen7_vc1_profile[4] = {
1344 GEN7_VC1_SIMPLE_PROFILE,
1345 GEN7_VC1_MAIN_PROFILE,
1346 GEN7_VC1_RESERVED_PROFILE,
1347 GEN7_VC1_ADVANCED_PROFILE
1351 gen7_mfd_free_vc1_surface(void **data)
1353 struct gen7_vc1_surface *gen7_vc1_surface = *data;
1355 if (!gen7_vc1_surface)
1358 dri_bo_unreference(gen7_vc1_surface->dmv);
1359 free(gen7_vc1_surface);
1364 gen7_mfd_init_vc1_surface(VADriverContextP ctx,
1365 VAPictureParameterBufferVC1 *pic_param,
1366 struct object_surface *obj_surface)
1368 struct i965_driver_data *i965 = i965_driver_data(ctx);
1369 struct gen7_vc1_surface *gen7_vc1_surface = obj_surface->private_data;
1370 int width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
1371 int height_in_mbs = ALIGN(pic_param->coded_height, 16) / 16;
1373 obj_surface->free_private_data = gen7_mfd_free_vc1_surface;
1375 if (!gen7_vc1_surface) {
1376 gen7_vc1_surface = calloc(sizeof(struct gen7_vc1_surface), 1);
1377 assert((obj_surface->size & 0x3f) == 0);
1378 obj_surface->private_data = gen7_vc1_surface;
1381 gen7_vc1_surface->picture_type = pic_param->picture_fields.bits.picture_type;
1383 if (gen7_vc1_surface->dmv == NULL) {
1384 gen7_vc1_surface->dmv = dri_bo_alloc(i965->intel.bufmgr,
1385 "direct mv w/r buffer",
1386 width_in_mbs * height_in_mbs * 64,
1392 gen7_mfd_vc1_decode_init(VADriverContextP ctx,
1393 struct decode_state *decode_state,
1394 struct gen7_mfd_context *gen7_mfd_context)
1396 VAPictureParameterBufferVC1 *pic_param;
1397 struct i965_driver_data *i965 = i965_driver_data(ctx);
1398 struct object_surface *obj_surface;
1403 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1404 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1405 width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
1407 /* reference picture */
1408 obj_surface = SURFACE(pic_param->forward_reference_picture);
1410 if (obj_surface && obj_surface->bo)
1411 gen7_mfd_context->reference_surface[0].surface_id = pic_param->forward_reference_picture;
1413 gen7_mfd_context->reference_surface[0].surface_id = VA_INVALID_ID;
1415 obj_surface = SURFACE(pic_param->backward_reference_picture);
1417 if (obj_surface && obj_surface->bo)
1418 gen7_mfd_context->reference_surface[1].surface_id = pic_param->backward_reference_picture;
1420 gen7_mfd_context->reference_surface[1].surface_id = pic_param->forward_reference_picture;
1422 /* must do so !!! */
1423 for (i = 2; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++)
1424 gen7_mfd_context->reference_surface[i].surface_id = gen7_mfd_context->reference_surface[i % 2].surface_id;
1426 /* Current decoded picture */
1427 obj_surface = SURFACE(decode_state->current_render_target);
1428 assert(obj_surface);
1429 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
1430 gen7_mfd_init_vc1_surface(ctx, pic_param, obj_surface);
1432 dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
1433 gen7_mfd_context->post_deblocking_output.bo = obj_surface->bo;
1434 dri_bo_reference(gen7_mfd_context->post_deblocking_output.bo);
1435 gen7_mfd_context->post_deblocking_output.valid = pic_param->entrypoint_fields.bits.loopfilter;
1437 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
1438 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
1439 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
1440 gen7_mfd_context->pre_deblocking_output.valid = !pic_param->entrypoint_fields.bits.loopfilter;
1442 dri_bo_unreference(gen7_mfd_context->intra_row_store_scratch_buffer.bo);
1443 bo = dri_bo_alloc(i965->intel.bufmgr,
1448 gen7_mfd_context->intra_row_store_scratch_buffer.bo = bo;
1449 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 1;
1451 dri_bo_unreference(gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo);
1452 bo = dri_bo_alloc(i965->intel.bufmgr,
1453 "deblocking filter row store",
1454 width_in_mbs * 6 * 64,
1457 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = bo;
1458 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 1;
1460 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
1461 bo = dri_bo_alloc(i965->intel.bufmgr,
1462 "bsd mpc row store",
1466 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = bo;
1467 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 1;
1469 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 0;
1471 gen7_mfd_context->bitplane_read_buffer.valid = !!pic_param->bitplane_present.value;
1472 dri_bo_unreference(gen7_mfd_context->bitplane_read_buffer.bo);
1474 if (gen7_mfd_context->bitplane_read_buffer.valid) {
1475 int width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
1476 int height_in_mbs = ALIGN(pic_param->coded_height, 16) / 16;
1477 int bitplane_width = ALIGN(width_in_mbs, 2) / 2;
1479 uint8_t *src = NULL, *dst = NULL;
1481 assert(decode_state->bit_plane->buffer);
1482 src = decode_state->bit_plane->buffer;
1484 bo = dri_bo_alloc(i965->intel.bufmgr,
1486 bitplane_width * bitplane_width,
1489 gen7_mfd_context->bitplane_read_buffer.bo = bo;
1491 dri_bo_map(bo, True);
1492 assert(bo->virtual);
1495 for (src_h = 0; src_h < height_in_mbs; src_h++) {
1496 for(src_w = 0; src_w < width_in_mbs; src_w++) {
1497 int src_index, dst_index;
1501 src_index = (src_h * width_in_mbs + src_w) / 2;
1502 src_shift = !((src_h * width_in_mbs + src_w) & 1) * 4;
1503 src_value = ((src[src_index] >> src_shift) & 0xf);
1505 dst_index = src_w / 2;
1506 dst[dst_index] = ((dst[dst_index] >> 4) | (src_value << 4));
1510 dst[src_w / 2] >>= 4;
1512 dst += bitplane_width;
1517 gen7_mfd_context->bitplane_read_buffer.bo = NULL;
1521 gen7_mfd_vc1_pic_state(VADriverContextP ctx,
1522 struct decode_state *decode_state,
1523 struct gen7_mfd_context *gen7_mfd_context)
1525 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1526 VAPictureParameterBufferVC1 *pic_param;
1527 struct i965_driver_data *i965 = i965_driver_data(ctx);
1528 struct object_surface *obj_surface;
1529 int alt_pquant_config = 0, alt_pquant_edge_mask = 0, alt_pq;
1530 int dquant, dquantfrm, dqprofile, dqdbedge, dqsbedge, dqbilevel;
1531 int unified_mv_mode;
1532 int ref_field_pic_polarity = 0;
1533 int scale_factor = 0;
1535 int dmv_surface_valid = 0;
1541 int interpolation_mode = 0;
1543 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1544 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1546 profile = va_to_gen7_vc1_profile[pic_param->sequence_fields.bits.profile];
1547 dquant = pic_param->pic_quantizer_fields.bits.dquant;
1548 dquantfrm = pic_param->pic_quantizer_fields.bits.dq_frame;
1549 dqprofile = pic_param->pic_quantizer_fields.bits.dq_profile;
1550 dqdbedge = pic_param->pic_quantizer_fields.bits.dq_db_edge;
1551 dqsbedge = pic_param->pic_quantizer_fields.bits.dq_sb_edge;
1552 dqbilevel = pic_param->pic_quantizer_fields.bits.dq_binary_level;
1553 alt_pq = pic_param->pic_quantizer_fields.bits.alt_pic_quantizer;
1556 alt_pquant_config = 0;
1557 alt_pquant_edge_mask = 0;
1558 } else if (dquant == 2) {
1559 alt_pquant_config = 1;
1560 alt_pquant_edge_mask = 0xf;
1562 assert(dquant == 1);
1563 if (dquantfrm == 0) {
1564 alt_pquant_config = 0;
1565 alt_pquant_edge_mask = 0;
1568 assert(dquantfrm == 1);
1569 alt_pquant_config = 1;
1571 switch (dqprofile) {
1573 if (dqbilevel == 0) {
1574 alt_pquant_config = 2;
1575 alt_pquant_edge_mask = 0;
1577 assert(dqbilevel == 1);
1578 alt_pquant_config = 3;
1579 alt_pquant_edge_mask = 0;
1584 alt_pquant_edge_mask = 0xf;
1589 alt_pquant_edge_mask = 0x9;
1591 alt_pquant_edge_mask = (0x3 << dqdbedge);
1596 alt_pquant_edge_mask = (0x1 << dqsbedge);
1605 if (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation) {
1606 assert(pic_param->mv_fields.bits.mv_mode2 < 4);
1607 unified_mv_mode = va_to_gen7_vc1_mv[pic_param->mv_fields.bits.mv_mode2];
1609 assert(pic_param->mv_fields.bits.mv_mode < 4);
1610 unified_mv_mode = va_to_gen7_vc1_mv[pic_param->mv_fields.bits.mv_mode];
1613 if (pic_param->sequence_fields.bits.interlace == 1 &&
1614 pic_param->picture_fields.bits.frame_coding_mode != 0) { /* frame-interlace or field-interlace */
1615 /* FIXME: calculate reference field picture polarity */
1617 ref_field_pic_polarity = 0;
1620 if (pic_param->b_picture_fraction < 21)
1621 scale_factor = b_picture_scale_factor[pic_param->b_picture_fraction];
1623 picture_type = va_to_gen7_vc1_pic_type[pic_param->picture_fields.bits.picture_type];
1625 if (profile == GEN7_VC1_ADVANCED_PROFILE &&
1626 picture_type == GEN7_VC1_I_PICTURE)
1627 picture_type = GEN7_VC1_BI_PICTURE;
1629 if (picture_type == GEN7_VC1_I_PICTURE || picture_type == GEN7_VC1_BI_PICTURE) /* I picture */
1630 trans_ac_y = pic_param->transform_fields.bits.transform_ac_codingset_idx2;
1632 trans_ac_y = pic_param->transform_fields.bits.transform_ac_codingset_idx1;
1635 if (picture_type == GEN7_VC1_B_PICTURE) {
1636 struct gen7_vc1_surface *gen7_vc1_surface = NULL;
1638 obj_surface = SURFACE(pic_param->backward_reference_picture);
1639 assert(obj_surface);
1640 gen7_vc1_surface = obj_surface->private_data;
1642 if (!gen7_vc1_surface ||
1643 (va_to_gen7_vc1_pic_type[gen7_vc1_surface->picture_type] == GEN7_VC1_I_PICTURE ||
1644 va_to_gen7_vc1_pic_type[gen7_vc1_surface->picture_type] == GEN7_VC1_BI_PICTURE))
1645 dmv_surface_valid = 0;
1647 dmv_surface_valid = 1;
1650 assert(pic_param->picture_fields.bits.frame_coding_mode < 3);
1652 if (pic_param->picture_fields.bits.frame_coding_mode < 2)
1653 fcm = pic_param->picture_fields.bits.frame_coding_mode;
1655 if (pic_param->picture_fields.bits.top_field_first)
1661 if (pic_param->picture_fields.bits.picture_type == GEN7_VC1_B_PICTURE) { /* B picture */
1662 brfd = pic_param->reference_fields.bits.reference_distance;
1663 brfd = (scale_factor * brfd) >> 8;
1664 brfd = pic_param->reference_fields.bits.reference_distance - brfd - 1;
1670 overlap = pic_param->sequence_fields.bits.overlap;
1671 if (profile != GEN7_VC1_ADVANCED_PROFILE && pic_param->pic_quantizer_fields.bits.pic_quantizer_scale < 9)
1674 assert(pic_param->conditional_overlap_flag < 3);
1675 assert(pic_param->mv_fields.bits.mv_table < 4); /* FIXME: interlace mode */
1677 if (pic_param->mv_fields.bits.mv_mode == VAMvMode1MvHalfPelBilinear ||
1678 (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation &&
1679 pic_param->mv_fields.bits.mv_mode2 == VAMvMode1MvHalfPelBilinear))
1680 interpolation_mode = 9; /* Half-pel bilinear */
1681 else if (pic_param->mv_fields.bits.mv_mode == VAMvMode1MvHalfPel ||
1682 (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation &&
1683 pic_param->mv_fields.bits.mv_mode2 == VAMvMode1MvHalfPel))
1684 interpolation_mode = 1; /* Half-pel bicubic */
1686 interpolation_mode = 0; /* Quarter-pel bicubic */
1688 BEGIN_BCS_BATCH(batch, 6);
1689 OUT_BCS_BATCH(batch, MFD_VC1_LONG_PIC_STATE | (6 - 2));
1690 OUT_BCS_BATCH(batch,
1691 (((ALIGN(pic_param->coded_height, 16) / 16) - 1) << 16) |
1692 ((ALIGN(pic_param->coded_width, 16) / 16) - 1));
1693 OUT_BCS_BATCH(batch,
1694 ((ALIGN(pic_param->coded_width, 16) / 16 + 1) / 2 - 1) << 24 |
1695 dmv_surface_valid << 15 |
1696 (pic_param->pic_quantizer_fields.bits.quantizer == 0) << 14 | /* implicit quantizer */
1697 pic_param->rounding_control << 13 |
1698 pic_param->sequence_fields.bits.syncmarker << 12 |
1699 interpolation_mode << 8 |
1700 0 << 7 | /* FIXME: scale up or down ??? */
1701 pic_param->range_reduction_frame << 6 |
1702 pic_param->entrypoint_fields.bits.loopfilter << 5 |
1704 !pic_param->picture_fields.bits.is_first_field << 3 |
1705 (pic_param->sequence_fields.bits.profile == 3) << 0);
1706 OUT_BCS_BATCH(batch,
1707 va_to_gen7_vc1_condover[pic_param->conditional_overlap_flag] << 29 |
1708 picture_type << 26 |
1711 pic_param->pic_quantizer_fields.bits.pic_quantizer_scale << 8 |
1713 OUT_BCS_BATCH(batch,
1714 unified_mv_mode << 28 |
1715 pic_param->mv_fields.bits.four_mv_switch << 27 |
1716 pic_param->fast_uvmc_flag << 26 |
1717 ref_field_pic_polarity << 25 |
1718 pic_param->reference_fields.bits.num_reference_pictures << 24 |
1719 pic_param->reference_fields.bits.reference_distance << 20 |
1720 pic_param->reference_fields.bits.reference_distance << 16 | /* FIXME: ??? */
1721 pic_param->mv_fields.bits.extended_dmv_range << 10 |
1722 pic_param->mv_fields.bits.extended_mv_range << 8 |
1723 alt_pquant_edge_mask << 4 |
1724 alt_pquant_config << 2 |
1725 pic_param->pic_quantizer_fields.bits.half_qp << 1 |
1726 pic_param->pic_quantizer_fields.bits.pic_quantizer_type << 0);
1727 OUT_BCS_BATCH(batch,
1728 !!pic_param->bitplane_present.value << 31 |
1729 !pic_param->bitplane_present.flags.bp_forward_mb << 30 |
1730 !pic_param->bitplane_present.flags.bp_mv_type_mb << 29 |
1731 !pic_param->bitplane_present.flags.bp_skip_mb << 28 |
1732 !pic_param->bitplane_present.flags.bp_direct_mb << 27 |
1733 !pic_param->bitplane_present.flags.bp_overflags << 26 |
1734 !pic_param->bitplane_present.flags.bp_ac_pred << 25 |
1735 !pic_param->bitplane_present.flags.bp_field_tx << 24 |
1736 pic_param->mv_fields.bits.mv_table << 20 |
1737 pic_param->mv_fields.bits.four_mv_block_pattern_table << 18 |
1738 pic_param->mv_fields.bits.two_mv_block_pattern_table << 16 |
1739 pic_param->transform_fields.bits.frame_level_transform_type << 12 |
1740 pic_param->transform_fields.bits.mb_level_transform_type_flag << 11 |
1741 pic_param->mb_mode_table << 8 |
1743 pic_param->transform_fields.bits.transform_ac_codingset_idx1 << 4 |
1744 pic_param->transform_fields.bits.intra_transform_dc_table << 3 |
1745 pic_param->cbp_table << 0);
1746 ADVANCE_BCS_BATCH(batch);
1750 gen7_mfd_vc1_pred_pipe_state(VADriverContextP ctx,
1751 struct decode_state *decode_state,
1752 struct gen7_mfd_context *gen7_mfd_context)
1754 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1755 VAPictureParameterBufferVC1 *pic_param;
1756 int intensitycomp_single;
1758 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1759 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1761 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1762 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1763 intensitycomp_single = (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation);
1765 BEGIN_BCS_BATCH(batch, 6);
1766 OUT_BCS_BATCH(batch, MFX_VC1_PRED_PIPE_STATE | (6 - 2));
1767 OUT_BCS_BATCH(batch,
1768 0 << 14 | /* FIXME: double ??? */
1770 intensitycomp_single << 10 |
1771 intensitycomp_single << 8 |
1772 0 << 4 | /* FIXME: interlace mode */
1774 OUT_BCS_BATCH(batch,
1775 pic_param->luma_shift << 16 |
1776 pic_param->luma_scale << 0); /* FIXME: Luma Scaling */
1777 OUT_BCS_BATCH(batch, 0);
1778 OUT_BCS_BATCH(batch, 0);
1779 OUT_BCS_BATCH(batch, 0);
1780 ADVANCE_BCS_BATCH(batch);
1785 gen7_mfd_vc1_directmode_state(VADriverContextP ctx,
1786 struct decode_state *decode_state,
1787 struct gen7_mfd_context *gen7_mfd_context)
1789 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1790 VAPictureParameterBufferVC1 *pic_param;
1791 struct i965_driver_data *i965 = i965_driver_data(ctx);
1792 struct object_surface *obj_surface;
1793 dri_bo *dmv_read_buffer = NULL, *dmv_write_buffer = NULL;
1795 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1796 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1798 obj_surface = SURFACE(decode_state->current_render_target);
1800 if (obj_surface && obj_surface->private_data) {
1801 dmv_write_buffer = ((struct gen7_vc1_surface *)(obj_surface->private_data))->dmv;
1804 obj_surface = SURFACE(pic_param->backward_reference_picture);
1806 if (obj_surface && obj_surface->private_data) {
1807 dmv_read_buffer = ((struct gen7_vc1_surface *)(obj_surface->private_data))->dmv;
1810 BEGIN_BCS_BATCH(batch, 3);
1811 OUT_BCS_BATCH(batch, MFX_VC1_DIRECTMODE_STATE | (3 - 2));
1813 if (dmv_write_buffer)
1814 OUT_BCS_RELOC(batch, dmv_write_buffer,
1815 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
1818 OUT_BCS_BATCH(batch, 0);
1820 if (dmv_read_buffer)
1821 OUT_BCS_RELOC(batch, dmv_read_buffer,
1822 I915_GEM_DOMAIN_INSTRUCTION, 0,
1825 OUT_BCS_BATCH(batch, 0);
1827 ADVANCE_BCS_BATCH(batch);
1831 gen7_mfd_vc1_get_macroblock_bit_offset(uint8_t *buf, int in_slice_data_bit_offset, int profile)
1833 int out_slice_data_bit_offset;
1834 int slice_header_size = in_slice_data_bit_offset / 8;
1838 out_slice_data_bit_offset = in_slice_data_bit_offset;
1840 for (i = 0, j = 0; i < slice_header_size; i++, j++) {
1841 if (!buf[j] && !buf[j + 1] && buf[j + 2] == 3 && buf[j + 3] < 4) {
1846 out_slice_data_bit_offset = 8 * j + in_slice_data_bit_offset % 8;
1849 return out_slice_data_bit_offset;
1853 gen7_mfd_vc1_bsd_object(VADriverContextP ctx,
1854 VAPictureParameterBufferVC1 *pic_param,
1855 VASliceParameterBufferVC1 *slice_param,
1856 VASliceParameterBufferVC1 *next_slice_param,
1857 dri_bo *slice_data_bo,
1858 struct gen7_mfd_context *gen7_mfd_context)
1860 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1861 int next_slice_start_vert_pos;
1862 int macroblock_offset;
1863 uint8_t *slice_data = NULL;
1865 dri_bo_map(slice_data_bo, 0);
1866 slice_data = (uint8_t *)(slice_data_bo->virtual + slice_param->slice_data_offset);
1867 macroblock_offset = gen7_mfd_vc1_get_macroblock_bit_offset(slice_data,
1868 slice_param->macroblock_offset,
1869 pic_param->sequence_fields.bits.profile);
1870 dri_bo_unmap(slice_data_bo);
1872 if (next_slice_param)
1873 next_slice_start_vert_pos = next_slice_param->slice_vertical_position;
1875 next_slice_start_vert_pos = ALIGN(pic_param->coded_height, 16) / 16;
1877 BEGIN_BCS_BATCH(batch, 5);
1878 OUT_BCS_BATCH(batch, MFD_VC1_BSD_OBJECT | (5 - 2));
1879 OUT_BCS_BATCH(batch,
1880 slice_param->slice_data_size - (macroblock_offset >> 3));
1881 OUT_BCS_BATCH(batch,
1882 slice_param->slice_data_offset + (macroblock_offset >> 3));
1883 OUT_BCS_BATCH(batch,
1884 slice_param->slice_vertical_position << 16 |
1885 next_slice_start_vert_pos << 0);
1886 OUT_BCS_BATCH(batch,
1887 (macroblock_offset & 0x7));
1888 ADVANCE_BCS_BATCH(batch);
1892 gen7_mfd_vc1_decode_picture(VADriverContextP ctx,
1893 struct decode_state *decode_state,
1894 struct gen7_mfd_context *gen7_mfd_context)
1896 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1897 VAPictureParameterBufferVC1 *pic_param;
1898 VASliceParameterBufferVC1 *slice_param, *next_slice_param, *next_slice_group_param;
1899 dri_bo *slice_data_bo;
1902 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1903 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1905 gen7_mfd_vc1_decode_init(ctx, decode_state, gen7_mfd_context);
1906 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
1907 intel_batchbuffer_emit_mi_flush(batch);
1908 gen7_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1909 gen7_mfd_surface_state(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1910 gen7_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1911 gen7_mfd_bsp_buf_base_addr_state(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1912 gen7_mfd_vc1_pic_state(ctx, decode_state, gen7_mfd_context);
1913 gen7_mfd_vc1_pred_pipe_state(ctx, decode_state, gen7_mfd_context);
1914 gen7_mfd_vc1_directmode_state(ctx, decode_state, gen7_mfd_context);
1916 for (j = 0; j < decode_state->num_slice_params; j++) {
1917 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
1918 slice_param = (VASliceParameterBufferVC1 *)decode_state->slice_params[j]->buffer;
1919 slice_data_bo = decode_state->slice_datas[j]->bo;
1920 gen7_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_VC1, gen7_mfd_context);
1922 if (j == decode_state->num_slice_params - 1)
1923 next_slice_group_param = NULL;
1925 next_slice_group_param = (VASliceParameterBufferVC1 *)decode_state->slice_params[j + 1]->buffer;
1927 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
1928 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
1930 if (i < decode_state->slice_params[j]->num_elements - 1)
1931 next_slice_param = slice_param + 1;
1933 next_slice_param = next_slice_group_param;
1935 gen7_mfd_vc1_bsd_object(ctx, pic_param, slice_param, next_slice_param, slice_data_bo, gen7_mfd_context);
1940 intel_batchbuffer_end_atomic(batch);
1941 intel_batchbuffer_flush(batch);
1945 gen7_mfd_jpeg_decode_init(VADriverContextP ctx,
1946 struct decode_state *decode_state,
1947 struct gen7_mfd_context *gen7_mfd_context)
1949 struct i965_driver_data *i965 = i965_driver_data(ctx);
1950 struct object_surface *obj_surface;
1951 VAPictureParameterBufferJPEG *pic_param;
1952 int subsampling = SUBSAMPLE_YUV420;
1954 pic_param = (VAPictureParameterBufferJPEG *)decode_state->pic_param->buffer;
1956 if (pic_param->num_components == 1)
1957 subsampling = SUBSAMPLE_YUV400;
1958 else if (pic_param->num_components == 3) {
1959 int h1 = pic_param->components[0].h_sampling_factor;
1960 int h2 = pic_param->components[1].h_sampling_factor;
1961 int h3 = pic_param->components[2].h_sampling_factor;
1962 int v1 = pic_param->components[0].v_sampling_factor;
1963 int v2 = pic_param->components[1].v_sampling_factor;
1964 int v3 = pic_param->components[2].v_sampling_factor;
1966 if (h1 == 2 && h2 == 1 && h3 == 1 &&
1967 v1 == 2 && v2 == 1 && v3 == 1)
1968 subsampling = SUBSAMPLE_YUV420;
1969 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
1970 v1 == 1 && v2 == 1 && v3 == 1)
1971 subsampling = SUBSAMPLE_YUV422H;
1972 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
1973 v1 == 1 && v2 == 1 && v3 == 1)
1974 subsampling = SUBSAMPLE_YUV444;
1975 else if (h1 == 4 && h2 == 1 && h3 == 1 &&
1976 v1 == 1 && v2 == 1 && v3 == 1)
1977 subsampling = SUBSAMPLE_YUV411;
1978 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
1979 v1 == 2 && v2 == 1 && v3 == 1)
1980 subsampling = SUBSAMPLE_YUV422V;
1981 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
1982 v1 == 2 && v2 == 2 && v3 == 2)
1983 subsampling = SUBSAMPLE_YUV422H;
1984 else if (h2 == 2 && h2 == 2 && h3 == 2 &&
1985 v1 == 2 && v2 == 1 && v3 == 1)
1986 subsampling = SUBSAMPLE_YUV422V;
1993 /* Current decoded picture */
1994 obj_surface = SURFACE(decode_state->current_render_target);
1995 assert(obj_surface);
1996 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('I','M','C','1'), subsampling);
1998 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
1999 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
2000 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
2001 gen7_mfd_context->pre_deblocking_output.valid = 1;
2003 gen7_mfd_context->post_deblocking_output.bo = NULL;
2004 gen7_mfd_context->post_deblocking_output.valid = 0;
2006 gen7_mfd_context->intra_row_store_scratch_buffer.bo = NULL;
2007 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 0;
2009 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = NULL;
2010 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 0;
2012 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = NULL;
2013 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 0;
2015 gen7_mfd_context->mpr_row_store_scratch_buffer.bo = NULL;
2016 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 0;
2018 gen7_mfd_context->bitplane_read_buffer.bo = NULL;
2019 gen7_mfd_context->bitplane_read_buffer.valid = 0;
2022 static const int va_to_gen7_jpeg_rotation[4] = {
2023 GEN7_JPEG_ROTATION_0,
2024 GEN7_JPEG_ROTATION_90,
2025 GEN7_JPEG_ROTATION_180,
2026 GEN7_JPEG_ROTATION_270
2030 gen7_mfd_jpeg_pic_state(VADriverContextP ctx,
2031 struct decode_state *decode_state,
2032 struct gen7_mfd_context *gen7_mfd_context)
2034 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2035 VAPictureParameterBufferJPEG *pic_param;
2036 int chroma_type = GEN7_YUV420;
2037 int frame_width_in_blks;
2038 int frame_height_in_blks;
2040 assert(decode_state->pic_param && decode_state->pic_param->buffer);
2041 pic_param = (VAPictureParameterBufferJPEG *)decode_state->pic_param->buffer;
2043 if (pic_param->num_components == 1)
2044 chroma_type = GEN7_YUV400;
2045 else if (pic_param->num_components == 3) {
2046 int h1 = pic_param->components[0].h_sampling_factor;
2047 int h2 = pic_param->components[1].h_sampling_factor;
2048 int h3 = pic_param->components[2].h_sampling_factor;
2049 int v1 = pic_param->components[0].v_sampling_factor;
2050 int v2 = pic_param->components[1].v_sampling_factor;
2051 int v3 = pic_param->components[2].v_sampling_factor;
2053 if (h1 == 2 && h2 == 1 && h3 == 1 &&
2054 v1 == 2 && v2 == 1 && v3 == 1)
2055 chroma_type = GEN7_YUV420;
2056 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
2057 v1 == 1 && v2 == 1 && v3 == 1)
2058 chroma_type = GEN7_YUV422H_2Y;
2059 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
2060 v1 == 1 && v2 == 1 && v3 == 1)
2061 chroma_type = GEN7_YUV444;
2062 else if (h1 == 4 && h2 == 1 && h3 == 1 &&
2063 v1 == 1 && v2 == 1 && v3 == 1)
2064 chroma_type = GEN7_YUV411;
2065 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
2066 v1 == 2 && v2 == 1 && v3 == 1)
2067 chroma_type = GEN7_YUV422V_2Y;
2068 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
2069 v1 == 2 && v2 == 2 && v3 == 2)
2070 chroma_type = GEN7_YUV422H_4Y;
2071 else if (h2 == 2 && h2 == 2 && h3 == 2 &&
2072 v1 == 2 && v2 == 1 && v3 == 1)
2073 chroma_type = GEN7_YUV422V_4Y;
2078 if (chroma_type == GEN7_YUV400 ||
2079 chroma_type == GEN7_YUV444 ||
2080 chroma_type == GEN7_YUV422V_2Y) {
2081 frame_width_in_blks = ((pic_param->picture_width + 7) / 8);
2082 frame_height_in_blks = ((pic_param->picture_height + 7) / 8);
2083 } else if (chroma_type == GEN7_YUV411) {
2084 frame_width_in_blks = ((pic_param->picture_width + 31) / 32) * 4;
2085 frame_height_in_blks = ((pic_param->picture_height + 31) / 32) * 4;
2087 frame_width_in_blks = ((pic_param->picture_width + 15) / 16) * 2;
2088 frame_height_in_blks = ((pic_param->picture_height + 15) / 16) * 2;
2091 BEGIN_BCS_BATCH(batch, 3);
2092 OUT_BCS_BATCH(batch, MFX_JPEG_PIC_STATE | (3 - 2));
2093 OUT_BCS_BATCH(batch,
2094 (va_to_gen7_jpeg_rotation[pic_param->rotation] << 4) | /* rotation */
2095 (chroma_type << 0));
2096 OUT_BCS_BATCH(batch,
2097 ((frame_height_in_blks - 1) << 16) | /* FrameHeightInBlks */
2098 ((frame_width_in_blks - 1) << 0)); /* FrameWidthInBlks */
2099 ADVANCE_BCS_BATCH(batch);
2102 static const int va_to_gen7_jpeg_hufftable[2] = {
2108 gen7_mfd_jpeg_huff_table_state(VADriverContextP ctx,
2109 struct decode_state *decode_state,
2110 struct gen7_mfd_context *gen7_mfd_context,
2113 VAHuffmanTableBufferJPEG *huffman_table;
2114 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2117 if (!decode_state->huffman_table || !decode_state->huffman_table->buffer)
2120 huffman_table = (VAHuffmanTableBufferJPEG *)decode_state->huffman_table->buffer;
2122 for (index = 0; index < num_tables; index++) {
2123 int id = va_to_gen7_jpeg_hufftable[index];
2124 BEGIN_BCS_BATCH(batch, 53);
2125 OUT_BCS_BATCH(batch, MFX_JPEG_HUFF_TABLE_STATE | (53 - 2));
2126 OUT_BCS_BATCH(batch, id);
2127 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].num_dc_codes, 12);
2128 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].dc_values, 12);
2129 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].num_ac_codes, 16);
2130 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].ac_values, 164);
2131 ADVANCE_BCS_BATCH(batch);
2135 static const int va_to_gen7_jpeg_qm[5] = {
2137 MFX_QM_JPEG_LUMA_Y_QUANTIZER_MATRIX,
2138 MFX_QM_JPEG_CHROMA_CB_QUANTIZER_MATRIX,
2139 MFX_QM_JPEG_CHROMA_CR_QUANTIZER_MATRIX,
2140 MFX_QM_JPEG_ALPHA_QUANTIZER_MATRIX
2144 gen7_mfd_jpeg_qm_state(VADriverContextP ctx,
2145 struct decode_state *decode_state,
2146 struct gen7_mfd_context *gen7_mfd_context)
2148 VAPictureParameterBufferJPEG *pic_param;
2149 VAIQMatrixBufferJPEG *iq_matrix;
2152 if (!decode_state->iq_matrix || !decode_state->iq_matrix->buffer)
2155 iq_matrix = (VAIQMatrixBufferJPEG *)decode_state->iq_matrix->buffer;
2156 pic_param = (VAPictureParameterBufferJPEG *)decode_state->pic_param->buffer;
2158 assert(pic_param->num_components <= 3);
2160 for (index = 0; index < pic_param->num_components; index++) {
2161 int qm_type = va_to_gen7_jpeg_qm[pic_param->components[index].component_id - pic_param->components[0].component_id + 1];
2162 unsigned char *qm = iq_matrix->quantiser_table[pic_param->components[index].quantiser_table_selector];
2163 unsigned char precision = pic_param->sample_precision;
2164 unsigned char raster_qm[64];
2167 assert(precision == 8);
2169 for (j = 0; j < 64; j++)
2170 raster_qm[zigzag_direct[j]] = qm[j];
2172 gen7_mfd_qm_state(ctx, qm_type, raster_qm, 64, gen7_mfd_context);
2177 gen7_mfd_jpeg_bsd_object(VADriverContextP ctx,
2178 VAPictureParameterBufferJPEG *pic_param,
2179 VASliceParameterBufferJPEG *slice_param,
2180 VASliceParameterBufferJPEG *next_slice_param,
2181 dri_bo *slice_data_bo,
2182 struct gen7_mfd_context *gen7_mfd_context)
2184 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2185 int scan_component_mask = 0;
2188 assert(slice_param->num_components > 0);
2189 assert(slice_param->num_components < 4);
2190 assert(slice_param->num_components <= pic_param->num_components);
2192 for (i = 0; i < slice_param->num_components; i++) {
2193 switch (slice_param->components[i].component_selector - pic_param->components[0].component_id + 1) {
2195 scan_component_mask |= (1 << 0);
2198 scan_component_mask |= (1 << 1);
2201 scan_component_mask |= (1 << 2);
2209 BEGIN_BCS_BATCH(batch, 6);
2210 OUT_BCS_BATCH(batch, MFD_JPEG_BSD_OBJECT | (6 - 2));
2211 OUT_BCS_BATCH(batch,
2212 slice_param->slice_data_size);
2213 OUT_BCS_BATCH(batch,
2214 slice_param->slice_data_offset);
2215 OUT_BCS_BATCH(batch,
2216 slice_param->slice_horizontal_position << 16 |
2217 slice_param->slice_vertical_position << 0);
2218 OUT_BCS_BATCH(batch,
2219 ((slice_param->num_components != 1) << 30) | /* interleaved */
2220 (scan_component_mask << 27) | /* scan components */
2221 (0 << 26) | /* disable interrupt allowed */
2222 (slice_param->num_mcus << 0)); /* MCU count */
2223 OUT_BCS_BATCH(batch,
2224 (slice_param->restart_interval << 0)); /* RestartInterval */
2225 ADVANCE_BCS_BATCH(batch);
2228 /* Workaround for JPEG decoding on Ivybridge */
2231 i965_DestroySurfaces(VADriverContextP ctx,
2232 VASurfaceID *surface_list,
2235 i965_CreateSurfaces(VADriverContextP ctx,
2240 VASurfaceID *surfaces);
2245 unsigned char data[32];
2247 int data_bit_offset;
2249 } gen7_jpeg_wa_clip = {
2253 0x65, 0xb8, 0x40, 0x32, 0x13, 0xfd, 0x06, 0x6c,
2254 0xfc, 0x0a, 0x50, 0x71, 0x5c, 0x00
2262 gen7_jpeg_wa_init(VADriverContextP ctx,
2263 struct gen7_mfd_context *gen7_mfd_context)
2265 struct i965_driver_data *i965 = i965_driver_data(ctx);
2267 struct object_surface *obj_surface;
2269 if (gen7_mfd_context->jpeg_wa_surface_id != VA_INVALID_SURFACE)
2270 i965_DestroySurfaces(ctx,
2271 &gen7_mfd_context->jpeg_wa_surface_id,
2274 status = i965_CreateSurfaces(ctx,
2275 gen7_jpeg_wa_clip.width,
2276 gen7_jpeg_wa_clip.height,
2277 VA_RT_FORMAT_YUV420,
2279 &gen7_mfd_context->jpeg_wa_surface_id);
2280 assert(status == VA_STATUS_SUCCESS);
2282 obj_surface = SURFACE(gen7_mfd_context->jpeg_wa_surface_id);
2283 assert(obj_surface);
2284 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
2286 if (!gen7_mfd_context->jpeg_wa_slice_data_bo) {
2287 gen7_mfd_context->jpeg_wa_slice_data_bo = dri_bo_alloc(i965->intel.bufmgr,
2291 dri_bo_subdata(gen7_mfd_context->jpeg_wa_slice_data_bo,
2293 gen7_jpeg_wa_clip.data_size,
2294 gen7_jpeg_wa_clip.data);
2299 gen7_jpeg_wa_pipe_mode_select(VADriverContextP ctx,
2300 struct gen7_mfd_context *gen7_mfd_context)
2302 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2304 BEGIN_BCS_BATCH(batch, 5);
2305 OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
2306 OUT_BCS_BATCH(batch,
2307 (MFX_LONG_MODE << 17) | /* Currently only support long format */
2308 (MFD_MODE_VLD << 15) | /* VLD mode */
2309 (0 << 10) | /* disable Stream-Out */
2310 (0 << 9) | /* Post Deblocking Output */
2311 (1 << 8) | /* Pre Deblocking Output */
2312 (0 << 5) | /* not in stitch mode */
2313 (MFX_CODEC_DECODE << 4) | /* decoding mode */
2314 (MFX_FORMAT_AVC << 0));
2315 OUT_BCS_BATCH(batch,
2316 (0 << 4) | /* terminate if AVC motion and POC table error occurs */
2317 (0 << 3) | /* terminate if AVC mbdata error occurs */
2318 (0 << 2) | /* terminate if AVC CABAC/CAVLC decode error occurs */
2321 OUT_BCS_BATCH(batch, 0); /* pic status/error report id */
2322 OUT_BCS_BATCH(batch, 0); /* reserved */
2323 ADVANCE_BCS_BATCH(batch);
2327 gen7_jpeg_wa_surface_state(VADriverContextP ctx,
2328 struct gen7_mfd_context *gen7_mfd_context)
2330 struct i965_driver_data *i965 = i965_driver_data(ctx);
2331 struct object_surface *obj_surface = SURFACE(gen7_mfd_context->jpeg_wa_surface_id);
2332 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2334 BEGIN_BCS_BATCH(batch, 6);
2335 OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
2336 OUT_BCS_BATCH(batch, 0);
2337 OUT_BCS_BATCH(batch,
2338 ((obj_surface->orig_width - 1) << 18) |
2339 ((obj_surface->orig_height - 1) << 4));
2340 OUT_BCS_BATCH(batch,
2341 (MFX_SURFACE_PLANAR_420_8 << 28) | /* 420 planar YUV surface */
2342 (1 << 27) | /* interleave chroma, set to 0 for JPEG */
2343 (0 << 22) | /* surface object control state, ignored */
2344 ((obj_surface->width - 1) << 3) | /* pitch */
2345 (0 << 2) | /* must be 0 */
2346 (1 << 1) | /* must be tiled */
2347 (I965_TILEWALK_YMAJOR << 0)); /* tile walk, must be 1 */
2348 OUT_BCS_BATCH(batch,
2349 (0 << 16) | /* X offset for U(Cb), must be 0 */
2350 (obj_surface->y_cb_offset << 0)); /* Y offset for U(Cb) */
2351 OUT_BCS_BATCH(batch,
2352 (0 << 16) | /* X offset for V(Cr), must be 0 */
2353 (0 << 0)); /* Y offset for V(Cr), must be 0 for video codec, non-zoro for JPEG */
2354 ADVANCE_BCS_BATCH(batch);
2358 gen7_jpeg_wa_pipe_buf_addr_state(VADriverContextP ctx,
2359 struct gen7_mfd_context *gen7_mfd_context)
2361 struct i965_driver_data *i965 = i965_driver_data(ctx);
2362 struct object_surface *obj_surface = SURFACE(gen7_mfd_context->jpeg_wa_surface_id);
2363 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2367 intra_bo = dri_bo_alloc(i965->intel.bufmgr,
2372 BEGIN_BCS_BATCH(batch, 24);
2373 OUT_BCS_BATCH(batch, MFX_PIPE_BUF_ADDR_STATE | (24 - 2));
2374 OUT_BCS_RELOC(batch,
2376 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2379 OUT_BCS_BATCH(batch, 0); /* post deblocking */
2381 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
2382 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
2384 OUT_BCS_RELOC(batch,
2386 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2389 OUT_BCS_BATCH(batch, 0);
2392 for (i = 0; i < MAX_GEN_REFERENCE_FRAMES; i++) {
2393 OUT_BCS_BATCH(batch, 0);
2396 OUT_BCS_BATCH(batch, 0); /* ignore DW23 for decoding */
2397 ADVANCE_BCS_BATCH(batch);
2399 dri_bo_unreference(intra_bo);
2403 gen7_jpeg_wa_bsp_buf_base_addr_state(VADriverContextP ctx,
2404 struct gen7_mfd_context *gen7_mfd_context)
2406 struct i965_driver_data *i965 = i965_driver_data(ctx);
2407 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2408 dri_bo *bsd_mpc_bo, *mpr_bo;
2410 bsd_mpc_bo = dri_bo_alloc(i965->intel.bufmgr,
2411 "bsd mpc row store",
2412 11520, /* 1.5 * 120 * 64 */
2415 mpr_bo = dri_bo_alloc(i965->intel.bufmgr,
2417 7680, /* 1. 0 * 120 * 64 */
2420 BEGIN_BCS_BATCH(batch, 4);
2421 OUT_BCS_BATCH(batch, MFX_BSP_BUF_BASE_ADDR_STATE | (4 - 2));
2423 OUT_BCS_RELOC(batch,
2425 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2428 OUT_BCS_RELOC(batch,
2430 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2432 OUT_BCS_BATCH(batch, 0);
2434 ADVANCE_BCS_BATCH(batch);
2436 dri_bo_unreference(bsd_mpc_bo);
2437 dri_bo_unreference(mpr_bo);
2441 gen7_jpeg_wa_avc_qm_state(VADriverContextP ctx,
2442 struct gen7_mfd_context *gen7_mfd_context)
2448 gen7_jpeg_wa_avc_img_state(VADriverContextP ctx,
2449 struct gen7_mfd_context *gen7_mfd_context)
2451 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2453 int mbaff_frame_flag = 0;
2454 unsigned int width_in_mbs = 1, height_in_mbs = 1;
2456 BEGIN_BCS_BATCH(batch, 16);
2457 OUT_BCS_BATCH(batch, MFX_AVC_IMG_STATE | (16 - 2));
2458 OUT_BCS_BATCH(batch,
2459 width_in_mbs * height_in_mbs);
2460 OUT_BCS_BATCH(batch,
2461 ((height_in_mbs - 1) << 16) |
2462 ((width_in_mbs - 1) << 0));
2463 OUT_BCS_BATCH(batch,
2468 (0 << 12) | /* differ from GEN6 */
2471 OUT_BCS_BATCH(batch,
2472 (1 << 10) | /* 4:2:0 */
2473 (1 << 7) | /* CABAC */
2479 (mbaff_frame_flag << 1) |
2481 OUT_BCS_BATCH(batch, 0);
2482 OUT_BCS_BATCH(batch, 0);
2483 OUT_BCS_BATCH(batch, 0);
2484 OUT_BCS_BATCH(batch, 0);
2485 OUT_BCS_BATCH(batch, 0);
2486 OUT_BCS_BATCH(batch, 0);
2487 OUT_BCS_BATCH(batch, 0);
2488 OUT_BCS_BATCH(batch, 0);
2489 OUT_BCS_BATCH(batch, 0);
2490 OUT_BCS_BATCH(batch, 0);
2491 OUT_BCS_BATCH(batch, 0);
2492 ADVANCE_BCS_BATCH(batch);
2496 gen7_jpeg_wa_avc_directmode_state(VADriverContextP ctx,
2497 struct gen7_mfd_context *gen7_mfd_context)
2499 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2502 BEGIN_BCS_BATCH(batch, 69);
2503 OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
2505 /* reference surfaces 0..15 */
2506 for (i = 0; i < MAX_GEN_REFERENCE_FRAMES; i++) {
2507 OUT_BCS_BATCH(batch, 0); /* top */
2508 OUT_BCS_BATCH(batch, 0); /* bottom */
2511 /* the current decoding frame/field */
2512 OUT_BCS_BATCH(batch, 0); /* top */
2513 OUT_BCS_BATCH(batch, 0); /* bottom */
2516 for (i = 0; i < MAX_GEN_REFERENCE_FRAMES; i++) {
2517 OUT_BCS_BATCH(batch, 0);
2518 OUT_BCS_BATCH(batch, 0);
2521 OUT_BCS_BATCH(batch, 0);
2522 OUT_BCS_BATCH(batch, 0);
2524 ADVANCE_BCS_BATCH(batch);
2528 gen7_jpeg_wa_ind_obj_base_addr_state(VADriverContextP ctx,
2529 struct gen7_mfd_context *gen7_mfd_context)
2531 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2533 BEGIN_BCS_BATCH(batch, 11);
2534 OUT_BCS_BATCH(batch, MFX_IND_OBJ_BASE_ADDR_STATE | (11 - 2));
2535 OUT_BCS_RELOC(batch,
2536 gen7_mfd_context->jpeg_wa_slice_data_bo,
2537 I915_GEM_DOMAIN_INSTRUCTION, 0,
2539 OUT_BCS_BATCH(batch, 0x80000000); /* must set, up to 2G */
2540 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2541 OUT_BCS_BATCH(batch, 0);
2542 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2543 OUT_BCS_BATCH(batch, 0);
2544 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2545 OUT_BCS_BATCH(batch, 0);
2546 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2547 OUT_BCS_BATCH(batch, 0);
2548 ADVANCE_BCS_BATCH(batch);
2552 gen7_jpeg_wa_avc_bsd_object(VADriverContextP ctx,
2553 struct gen7_mfd_context *gen7_mfd_context)
2555 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2557 /* the input bitsteam format on GEN7 differs from GEN6 */
2558 BEGIN_BCS_BATCH(batch, 6);
2559 OUT_BCS_BATCH(batch, MFD_AVC_BSD_OBJECT | (6 - 2));
2560 OUT_BCS_BATCH(batch, gen7_jpeg_wa_clip.data_size);
2561 OUT_BCS_BATCH(batch, 0);
2562 OUT_BCS_BATCH(batch,
2568 OUT_BCS_BATCH(batch,
2569 ((gen7_jpeg_wa_clip.data_bit_offset >> 3) << 16) |
2572 (1 << 3) | /* LastSlice Flag */
2573 (gen7_jpeg_wa_clip.data_bit_offset & 0x7));
2574 OUT_BCS_BATCH(batch, 0);
2575 ADVANCE_BCS_BATCH(batch);
2579 gen7_jpeg_wa_avc_slice_state(VADriverContextP ctx,
2580 struct gen7_mfd_context *gen7_mfd_context)
2582 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2583 int slice_hor_pos = 0, slice_ver_pos = 0, next_slice_hor_pos = 0, next_slice_ver_pos = 1;
2584 int num_ref_idx_l0 = 0, num_ref_idx_l1 = 0;
2585 int first_mb_in_slice = 0;
2586 int slice_type = SLICE_TYPE_I;
2588 BEGIN_BCS_BATCH(batch, 11);
2589 OUT_BCS_BATCH(batch, MFX_AVC_SLICE_STATE | (11 - 2));
2590 OUT_BCS_BATCH(batch, slice_type);
2591 OUT_BCS_BATCH(batch,
2592 (num_ref_idx_l1 << 24) |
2593 (num_ref_idx_l0 << 16) |
2596 OUT_BCS_BATCH(batch,
2598 (1 << 27) | /* disable Deblocking */
2600 (gen7_jpeg_wa_clip.qp << 16) |
2603 OUT_BCS_BATCH(batch,
2604 (slice_ver_pos << 24) |
2605 (slice_hor_pos << 16) |
2606 (first_mb_in_slice << 0));
2607 OUT_BCS_BATCH(batch,
2608 (next_slice_ver_pos << 16) |
2609 (next_slice_hor_pos << 0));
2610 OUT_BCS_BATCH(batch, (1 << 19)); /* last slice flag */
2611 OUT_BCS_BATCH(batch, 0);
2612 OUT_BCS_BATCH(batch, 0);
2613 OUT_BCS_BATCH(batch, 0);
2614 OUT_BCS_BATCH(batch, 0);
2615 ADVANCE_BCS_BATCH(batch);
2619 gen7_mfd_jpeg_wa(VADriverContextP ctx,
2620 struct gen7_mfd_context *gen7_mfd_context)
2622 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2623 gen7_jpeg_wa_init(ctx, gen7_mfd_context);
2624 intel_batchbuffer_emit_mi_flush(batch);
2625 gen7_jpeg_wa_pipe_mode_select(ctx, gen7_mfd_context);
2626 gen7_jpeg_wa_surface_state(ctx, gen7_mfd_context);
2627 gen7_jpeg_wa_pipe_buf_addr_state(ctx, gen7_mfd_context);
2628 gen7_jpeg_wa_bsp_buf_base_addr_state(ctx, gen7_mfd_context);
2629 gen7_jpeg_wa_avc_qm_state(ctx, gen7_mfd_context);
2630 gen7_jpeg_wa_avc_img_state(ctx, gen7_mfd_context);
2631 gen7_jpeg_wa_ind_obj_base_addr_state(ctx, gen7_mfd_context);
2633 gen7_jpeg_wa_avc_directmode_state(ctx, gen7_mfd_context);
2634 gen7_jpeg_wa_avc_slice_state(ctx, gen7_mfd_context);
2635 gen7_jpeg_wa_avc_bsd_object(ctx, gen7_mfd_context);
2639 gen7_mfd_jpeg_decode_picture(VADriverContextP ctx,
2640 struct decode_state *decode_state,
2641 struct gen7_mfd_context *gen7_mfd_context)
2643 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2644 VAPictureParameterBufferJPEG *pic_param;
2645 VASliceParameterBufferJPEG *slice_param, *next_slice_param, *next_slice_group_param;
2646 dri_bo *slice_data_bo;
2647 int i, j, max_selector = 0;
2649 assert(decode_state->pic_param && decode_state->pic_param->buffer);
2650 pic_param = (VAPictureParameterBufferJPEG *)decode_state->pic_param->buffer;
2652 /* Currently only support Baseline DCT */
2653 assert(pic_param->sample_precision == 8);
2654 gen7_mfd_jpeg_decode_init(ctx, decode_state, gen7_mfd_context);
2655 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
2656 gen7_mfd_jpeg_wa(ctx, gen7_mfd_context);
2657 intel_batchbuffer_emit_mi_flush(batch);
2658 gen7_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_JPEG, gen7_mfd_context);
2659 gen7_mfd_surface_state(ctx, decode_state, MFX_FORMAT_JPEG, gen7_mfd_context);
2660 gen7_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_JPEG, gen7_mfd_context);
2661 gen7_mfd_jpeg_pic_state(ctx, decode_state, gen7_mfd_context);
2662 gen7_mfd_jpeg_qm_state(ctx, decode_state, gen7_mfd_context);
2664 for (j = 0; j < decode_state->num_slice_params; j++) {
2665 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
2666 slice_param = (VASliceParameterBufferJPEG *)decode_state->slice_params[j]->buffer;
2667 slice_data_bo = decode_state->slice_datas[j]->bo;
2668 gen7_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_JPEG, gen7_mfd_context);
2670 if (j == decode_state->num_slice_params - 1)
2671 next_slice_group_param = NULL;
2673 next_slice_group_param = (VASliceParameterBufferJPEG *)decode_state->slice_params[j + 1]->buffer;
2675 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
2678 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
2680 if (i < decode_state->slice_params[j]->num_elements - 1)
2681 next_slice_param = slice_param + 1;
2683 next_slice_param = next_slice_group_param;
2685 for (component = 0; component < slice_param->num_components; component++) {
2686 if (max_selector < slice_param->components[component].dc_table_selector)
2687 max_selector = slice_param->components[component].dc_table_selector;
2689 if (max_selector < slice_param->components[component].ac_table_selector)
2690 max_selector = slice_param->components[component].ac_table_selector;
2697 assert(max_selector < 2);
2698 gen7_mfd_jpeg_huff_table_state(ctx, decode_state, gen7_mfd_context, max_selector + 1);
2700 for (j = 0; j < decode_state->num_slice_params; j++) {
2701 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
2702 slice_param = (VASliceParameterBufferJPEG *)decode_state->slice_params[j]->buffer;
2703 slice_data_bo = decode_state->slice_datas[j]->bo;
2704 gen7_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_JPEG, gen7_mfd_context);
2706 if (j == decode_state->num_slice_params - 1)
2707 next_slice_group_param = NULL;
2709 next_slice_group_param = (VASliceParameterBufferJPEG *)decode_state->slice_params[j + 1]->buffer;
2711 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
2712 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
2714 if (i < decode_state->slice_params[j]->num_elements - 1)
2715 next_slice_param = slice_param + 1;
2717 next_slice_param = next_slice_group_param;
2719 gen7_mfd_jpeg_bsd_object(ctx, pic_param, slice_param, next_slice_param, slice_data_bo, gen7_mfd_context);
2724 intel_batchbuffer_end_atomic(batch);
2725 intel_batchbuffer_flush(batch);
2729 gen7_mfd_decode_picture(VADriverContextP ctx,
2731 union codec_state *codec_state,
2732 struct hw_context *hw_context)
2735 struct gen7_mfd_context *gen7_mfd_context = (struct gen7_mfd_context *)hw_context;
2736 struct decode_state *decode_state = &codec_state->decode;
2738 assert(gen7_mfd_context);
2740 gen7_mfd_context->wa_mpeg2_slice_vertical_position = -1;
2743 case VAProfileMPEG2Simple:
2744 case VAProfileMPEG2Main:
2745 gen7_mfd_mpeg2_decode_picture(ctx, decode_state, gen7_mfd_context);
2748 case VAProfileH264Baseline:
2749 case VAProfileH264Main:
2750 case VAProfileH264High:
2751 gen7_mfd_avc_decode_picture(ctx, decode_state, gen7_mfd_context);
2754 case VAProfileVC1Simple:
2755 case VAProfileVC1Main:
2756 case VAProfileVC1Advanced:
2757 gen7_mfd_vc1_decode_picture(ctx, decode_state, gen7_mfd_context);
2760 case VAProfileJPEGBaseline:
2761 gen7_mfd_jpeg_decode_picture(ctx, decode_state, gen7_mfd_context);
2771 gen7_mfd_context_destroy(void *hw_context)
2773 struct gen7_mfd_context *gen7_mfd_context = (struct gen7_mfd_context *)hw_context;
2775 dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
2776 gen7_mfd_context->post_deblocking_output.bo = NULL;
2778 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
2779 gen7_mfd_context->pre_deblocking_output.bo = NULL;
2781 dri_bo_unreference(gen7_mfd_context->intra_row_store_scratch_buffer.bo);
2782 gen7_mfd_context->intra_row_store_scratch_buffer.bo = NULL;
2784 dri_bo_unreference(gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo);
2785 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = NULL;
2787 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
2788 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = NULL;
2790 dri_bo_unreference(gen7_mfd_context->mpr_row_store_scratch_buffer.bo);
2791 gen7_mfd_context->mpr_row_store_scratch_buffer.bo = NULL;
2793 dri_bo_unreference(gen7_mfd_context->bitplane_read_buffer.bo);
2794 gen7_mfd_context->bitplane_read_buffer.bo = NULL;
2796 dri_bo_unreference(gen7_mfd_context->jpeg_wa_slice_data_bo);
2798 intel_batchbuffer_free(gen7_mfd_context->base.batch);
2799 free(gen7_mfd_context);
2802 static void gen7_mfd_mpeg2_context_init(VADriverContextP ctx,
2803 struct gen7_mfd_context *gen7_mfd_context)
2805 gen7_mfd_context->iq_matrix.mpeg2.load_intra_quantiser_matrix = -1;
2806 gen7_mfd_context->iq_matrix.mpeg2.load_non_intra_quantiser_matrix = -1;
2807 gen7_mfd_context->iq_matrix.mpeg2.load_chroma_intra_quantiser_matrix = -1;
2808 gen7_mfd_context->iq_matrix.mpeg2.load_chroma_non_intra_quantiser_matrix = -1;
2812 gen7_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
2814 struct intel_driver_data *intel = intel_driver_data(ctx);
2815 struct gen7_mfd_context *gen7_mfd_context = calloc(1, sizeof(struct gen7_mfd_context));
2818 gen7_mfd_context->base.destroy = gen7_mfd_context_destroy;
2819 gen7_mfd_context->base.run = gen7_mfd_decode_picture;
2820 gen7_mfd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
2822 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
2823 gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
2824 gen7_mfd_context->reference_surface[i].frame_store_id = -1;
2827 gen7_mfd_context->jpeg_wa_surface_id = VA_INVALID_SURFACE;
2829 switch (obj_config->profile) {
2830 case VAProfileMPEG2Simple:
2831 case VAProfileMPEG2Main:
2832 gen7_mfd_mpeg2_context_init(ctx, gen7_mfd_context);
2835 case VAProfileH264Baseline:
2836 case VAProfileH264Main:
2837 case VAProfileH264High:
2838 gen7_mfd_avc_context_init(ctx, gen7_mfd_context);
2843 return (struct hw_context *)gen7_mfd_context;