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>
26 * Zhao Yakui <yakui.zhao@intel.com>
34 #include <va/va_dec_jpeg.h>
36 #include "intel_batchbuffer.h"
37 #include "intel_driver.h"
39 #include "i965_defines.h"
40 #include "i965_drv_video.h"
41 #include "i965_decoder_utils.h"
45 static const uint32_t zigzag_direct[64] = {
46 0, 1, 8, 16, 9, 2, 3, 10,
47 17, 24, 32, 25, 18, 11, 4, 5,
48 12, 19, 26, 33, 40, 48, 41, 34,
49 27, 20, 13, 6, 7, 14, 21, 28,
50 35, 42, 49, 56, 57, 50, 43, 36,
51 29, 22, 15, 23, 30, 37, 44, 51,
52 58, 59, 52, 45, 38, 31, 39, 46,
53 53, 60, 61, 54, 47, 55, 62, 63
57 gen75_mfd_avc_frame_store_index(VADriverContextP ctx,
58 VAPictureParameterBufferH264 *pic_param,
59 struct gen7_mfd_context *gen7_mfd_context)
61 struct i965_driver_data *i965 = i965_driver_data(ctx);
64 assert(ARRAY_ELEMS(gen7_mfd_context->reference_surface) == ARRAY_ELEMS(pic_param->ReferenceFrames));
66 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
69 if (gen7_mfd_context->reference_surface[i].surface_id == VA_INVALID_ID)
72 for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
73 VAPictureH264 *ref_pic = &pic_param->ReferenceFrames[j];
74 if (ref_pic->flags & VA_PICTURE_H264_INVALID)
77 if (gen7_mfd_context->reference_surface[i].surface_id == ref_pic->picture_id) {
84 struct object_surface *obj_surface = SURFACE(gen7_mfd_context->reference_surface[i].surface_id);
85 obj_surface->flags &= ~SURFACE_REFERENCED;
87 if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
88 dri_bo_unreference(obj_surface->bo);
89 obj_surface->bo = NULL;
90 obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
93 if (obj_surface->free_private_data)
94 obj_surface->free_private_data(&obj_surface->private_data);
96 gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
97 gen7_mfd_context->reference_surface[i].frame_store_id = -1;
101 for (i = 0; i < ARRAY_ELEMS(pic_param->ReferenceFrames); i++) {
102 VAPictureH264 *ref_pic = &pic_param->ReferenceFrames[i];
105 if (ref_pic->flags & VA_PICTURE_H264_INVALID)
108 for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
109 if (gen7_mfd_context->reference_surface[j].surface_id == VA_INVALID_ID)
112 if (gen7_mfd_context->reference_surface[j].surface_id == ref_pic->picture_id) {
120 struct object_surface *obj_surface = SURFACE(ref_pic->picture_id);
123 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
125 for (frame_idx = 0; frame_idx < ARRAY_ELEMS(gen7_mfd_context->reference_surface); frame_idx++) {
126 for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
127 if (gen7_mfd_context->reference_surface[j].surface_id == VA_INVALID_ID)
130 if (gen7_mfd_context->reference_surface[j].frame_store_id == frame_idx)
134 if (j == ARRAY_ELEMS(gen7_mfd_context->reference_surface))
138 assert(frame_idx < ARRAY_ELEMS(gen7_mfd_context->reference_surface));
140 for (j = 0; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
141 if (gen7_mfd_context->reference_surface[j].surface_id == VA_INVALID_ID) {
142 gen7_mfd_context->reference_surface[j].surface_id = ref_pic->picture_id;
143 gen7_mfd_context->reference_surface[j].frame_store_id = frame_idx;
151 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface) - 1; i++) {
152 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
153 gen7_mfd_context->reference_surface[i].frame_store_id == i)
156 for (j = i + 1; j < ARRAY_ELEMS(gen7_mfd_context->reference_surface); j++) {
157 if (gen7_mfd_context->reference_surface[j].surface_id != VA_INVALID_ID &&
158 gen7_mfd_context->reference_surface[j].frame_store_id == i) {
159 VASurfaceID id = gen7_mfd_context->reference_surface[i].surface_id;
160 int frame_idx = gen7_mfd_context->reference_surface[i].frame_store_id;
162 gen7_mfd_context->reference_surface[i].surface_id = gen7_mfd_context->reference_surface[j].surface_id;
163 gen7_mfd_context->reference_surface[i].frame_store_id = gen7_mfd_context->reference_surface[j].frame_store_id;
164 gen7_mfd_context->reference_surface[j].surface_id = id;
165 gen7_mfd_context->reference_surface[j].frame_store_id = frame_idx;
173 gen75_mfd_free_avc_surface(void **data)
175 struct gen7_avc_surface *gen7_avc_surface = *data;
177 if (!gen7_avc_surface)
180 dri_bo_unreference(gen7_avc_surface->dmv_top);
181 gen7_avc_surface->dmv_top = NULL;
182 dri_bo_unreference(gen7_avc_surface->dmv_bottom);
183 gen7_avc_surface->dmv_bottom = NULL;
185 free(gen7_avc_surface);
190 gen75_mfd_init_avc_surface(VADriverContextP ctx,
191 VAPictureParameterBufferH264 *pic_param,
192 struct object_surface *obj_surface)
194 struct i965_driver_data *i965 = i965_driver_data(ctx);
195 struct gen7_avc_surface *gen7_avc_surface = obj_surface->private_data;
196 int width_in_mbs, height_in_mbs;
198 obj_surface->free_private_data = gen75_mfd_free_avc_surface;
199 width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
200 height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1; /* frame height */
202 if (!gen7_avc_surface) {
203 gen7_avc_surface = calloc(sizeof(struct gen7_avc_surface), 1);
204 assert((obj_surface->size & 0x3f) == 0);
205 obj_surface->private_data = gen7_avc_surface;
208 gen7_avc_surface->dmv_bottom_flag = (pic_param->pic_fields.bits.field_pic_flag &&
209 !pic_param->seq_fields.bits.direct_8x8_inference_flag);
211 if (gen7_avc_surface->dmv_top == NULL) {
212 gen7_avc_surface->dmv_top = dri_bo_alloc(i965->intel.bufmgr,
213 "direct mv w/r buffer",
214 width_in_mbs * height_in_mbs * 64,
216 assert(gen7_avc_surface->dmv_top);
219 if (gen7_avc_surface->dmv_bottom_flag &&
220 gen7_avc_surface->dmv_bottom == NULL) {
221 gen7_avc_surface->dmv_bottom = dri_bo_alloc(i965->intel.bufmgr,
222 "direct mv w/r buffer",
223 width_in_mbs * height_in_mbs * 64,
225 assert(gen7_avc_surface->dmv_bottom);
230 gen75_mfd_pipe_mode_select(VADriverContextP ctx,
231 struct decode_state *decode_state,
233 struct gen7_mfd_context *gen7_mfd_context)
235 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
237 assert(standard_select == MFX_FORMAT_MPEG2 ||
238 standard_select == MFX_FORMAT_AVC ||
239 standard_select == MFX_FORMAT_VC1 ||
240 standard_select == MFX_FORMAT_JPEG);
242 BEGIN_BCS_BATCH(batch, 5);
243 OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
245 (MFX_LONG_MODE << 17) | /* Currently only support long format */
246 (MFD_MODE_VLD << 15) | /* VLD mode */
247 (0 << 10) | /* disable Stream-Out */
248 (gen7_mfd_context->post_deblocking_output.valid << 9) | /* Post Deblocking Output */
249 (gen7_mfd_context->pre_deblocking_output.valid << 8) | /* Pre Deblocking Output */
250 (0 << 5) | /* not in stitch mode */
251 (MFX_CODEC_DECODE << 4) | /* decoding mode */
252 (standard_select << 0));
254 (0 << 4) | /* terminate if AVC motion and POC table error occurs */
255 (0 << 3) | /* terminate if AVC mbdata error occurs */
256 (0 << 2) | /* terminate if AVC CABAC/CAVLC decode error occurs */
259 OUT_BCS_BATCH(batch, 0); /* pic status/error report id */
260 OUT_BCS_BATCH(batch, 0); /* reserved */
261 ADVANCE_BCS_BATCH(batch);
265 gen75_mfd_surface_state(VADriverContextP ctx,
266 struct decode_state *decode_state,
268 struct gen7_mfd_context *gen7_mfd_context)
270 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
271 struct i965_driver_data *i965 = i965_driver_data(ctx);
272 struct object_surface *obj_surface = SURFACE(decode_state->current_render_target);
273 unsigned int y_cb_offset;
274 unsigned int y_cr_offset;
278 y_cb_offset = obj_surface->y_cb_offset;
279 y_cr_offset = obj_surface->y_cr_offset;
281 BEGIN_BCS_BATCH(batch, 6);
282 OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
283 OUT_BCS_BATCH(batch, 0);
285 ((obj_surface->orig_height - 1) << 18) |
286 ((obj_surface->orig_width - 1) << 4));
288 (MFX_SURFACE_PLANAR_420_8 << 28) | /* 420 planar YUV surface */
289 ((standard_select != MFX_FORMAT_JPEG) << 27) | /* interleave chroma, set to 0 for JPEG */
290 (0 << 22) | /* surface object control state, ignored */
291 ((obj_surface->width - 1) << 3) | /* pitch */
292 (0 << 2) | /* must be 0 */
293 (1 << 1) | /* must be tiled */
294 (I965_TILEWALK_YMAJOR << 0)); /* tile walk, must be 1 */
296 (0 << 16) | /* X offset for U(Cb), must be 0 */
297 (y_cb_offset << 0)); /* Y offset for U(Cb) */
299 (0 << 16) | /* X offset for V(Cr), must be 0 */
300 (y_cr_offset << 0)); /* Y offset for V(Cr), must be 0 for video codec, non-zoro for JPEG */
301 ADVANCE_BCS_BATCH(batch);
305 gen75_mfd_pipe_buf_addr_state(VADriverContextP ctx,
306 struct decode_state *decode_state,
308 struct gen7_mfd_context *gen7_mfd_context)
310 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
311 struct i965_driver_data *i965 = i965_driver_data(ctx);
314 BEGIN_BCS_BATCH(batch, 24);
315 OUT_BCS_BATCH(batch, MFX_PIPE_BUF_ADDR_STATE | (24 - 2));
316 if (gen7_mfd_context->pre_deblocking_output.valid)
317 OUT_BCS_RELOC(batch, gen7_mfd_context->pre_deblocking_output.bo,
318 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
321 OUT_BCS_BATCH(batch, 0);
323 if (gen7_mfd_context->post_deblocking_output.valid)
324 OUT_BCS_RELOC(batch, gen7_mfd_context->post_deblocking_output.bo,
325 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
328 OUT_BCS_BATCH(batch, 0);
330 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
331 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
333 if (gen7_mfd_context->intra_row_store_scratch_buffer.valid)
334 OUT_BCS_RELOC(batch, gen7_mfd_context->intra_row_store_scratch_buffer.bo,
335 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
338 OUT_BCS_BATCH(batch, 0);
340 if (gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid)
341 OUT_BCS_RELOC(batch, gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo,
342 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
345 OUT_BCS_BATCH(batch, 0);
348 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
349 struct object_surface *obj_surface;
351 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
352 obj_surface = SURFACE(gen7_mfd_context->reference_surface[i].surface_id);
353 assert(obj_surface && obj_surface->bo);
355 OUT_BCS_RELOC(batch, obj_surface->bo,
356 I915_GEM_DOMAIN_INSTRUCTION, 0,
359 OUT_BCS_BATCH(batch, 0);
363 OUT_BCS_BATCH(batch, 0); /* ignore DW23 for decoding */
364 ADVANCE_BCS_BATCH(batch);
368 gen75_mfd_ind_obj_base_addr_state(VADriverContextP ctx,
369 dri_bo *slice_data_bo,
371 struct gen7_mfd_context *gen7_mfd_context)
373 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
375 BEGIN_BCS_BATCH(batch, 11);
376 OUT_BCS_BATCH(batch, MFX_IND_OBJ_BASE_ADDR_STATE | (11 - 2));
377 OUT_BCS_RELOC(batch, slice_data_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); /* MFX Indirect Bitstream Object Base Address */
378 OUT_BCS_BATCH(batch, 0x80000000); /* must set, up to 2G */
379 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
380 OUT_BCS_BATCH(batch, 0);
381 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
382 OUT_BCS_BATCH(batch, 0);
383 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
384 OUT_BCS_BATCH(batch, 0);
385 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
386 OUT_BCS_BATCH(batch, 0);
387 ADVANCE_BCS_BATCH(batch);
391 gen75_mfd_bsp_buf_base_addr_state(VADriverContextP ctx,
392 struct decode_state *decode_state,
394 struct gen7_mfd_context *gen7_mfd_context)
396 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
398 BEGIN_BCS_BATCH(batch, 4);
399 OUT_BCS_BATCH(batch, MFX_BSP_BUF_BASE_ADDR_STATE | (4 - 2));
401 if (gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid)
402 OUT_BCS_RELOC(batch, gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo,
403 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
406 OUT_BCS_BATCH(batch, 0);
408 if (gen7_mfd_context->mpr_row_store_scratch_buffer.valid)
409 OUT_BCS_RELOC(batch, gen7_mfd_context->mpr_row_store_scratch_buffer.bo,
410 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
413 OUT_BCS_BATCH(batch, 0);
415 if (gen7_mfd_context->bitplane_read_buffer.valid)
416 OUT_BCS_RELOC(batch, gen7_mfd_context->bitplane_read_buffer.bo,
417 I915_GEM_DOMAIN_INSTRUCTION, 0,
420 OUT_BCS_BATCH(batch, 0);
422 ADVANCE_BCS_BATCH(batch);
427 gen7_mfd_aes_state(VADriverContextP ctx,
428 struct decode_state *decode_state,
436 gen75_mfd_qm_state(VADriverContextP ctx,
440 struct gen7_mfd_context *gen7_mfd_context)
442 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
443 unsigned int qm_buffer[16];
445 assert(qm_length <= 16 * 4);
446 memcpy(qm_buffer, qm, qm_length);
448 BEGIN_BCS_BATCH(batch, 18);
449 OUT_BCS_BATCH(batch, MFX_QM_STATE | (18 - 2));
450 OUT_BCS_BATCH(batch, qm_type << 0);
451 intel_batchbuffer_data(batch, qm_buffer, 16 * 4);
452 ADVANCE_BCS_BATCH(batch);
457 gen7_mfd_wait(VADriverContextP ctx,
458 struct decode_state *decode_state,
460 struct gen7_mfd_context *gen7_mfd_context)
462 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
464 BEGIN_BCS_BATCH(batch, 1);
465 OUT_BCS_BATCH(batch, MFX_WAIT | (1 << 8));
466 ADVANCE_BCS_BATCH(batch);
471 gen75_mfd_avc_img_state(VADriverContextP ctx,
472 struct decode_state *decode_state,
473 struct gen7_mfd_context *gen7_mfd_context)
475 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
477 int mbaff_frame_flag;
478 unsigned int width_in_mbs, height_in_mbs;
479 VAPictureParameterBufferH264 *pic_param;
481 assert(decode_state->pic_param && decode_state->pic_param->buffer);
482 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
483 assert(!(pic_param->CurrPic.flags & VA_PICTURE_H264_INVALID));
485 if (pic_param->CurrPic.flags & VA_PICTURE_H264_TOP_FIELD)
487 else if (pic_param->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD)
492 if ((img_struct & 0x1) == 0x1) {
493 assert(pic_param->pic_fields.bits.field_pic_flag == 0x1);
495 assert(pic_param->pic_fields.bits.field_pic_flag == 0x0);
498 if (pic_param->seq_fields.bits.frame_mbs_only_flag) { /* a frame containing only frame macroblocks */
499 assert(pic_param->seq_fields.bits.mb_adaptive_frame_field_flag == 0);
500 assert(pic_param->pic_fields.bits.field_pic_flag == 0);
502 assert(pic_param->seq_fields.bits.direct_8x8_inference_flag == 1); /* see H.264 spec */
505 mbaff_frame_flag = (pic_param->seq_fields.bits.mb_adaptive_frame_field_flag &&
506 !pic_param->pic_fields.bits.field_pic_flag);
508 width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
509 height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1; /* frame height */
511 /* MFX unit doesn't support 4:2:2 and 4:4:4 picture */
512 assert(pic_param->seq_fields.bits.chroma_format_idc == 0 || /* monochrome picture */
513 pic_param->seq_fields.bits.chroma_format_idc == 1); /* 4:2:0 */
514 assert(pic_param->seq_fields.bits.residual_colour_transform_flag == 0); /* only available for 4:4:4 */
516 BEGIN_BCS_BATCH(batch, 16);
517 OUT_BCS_BATCH(batch, MFX_AVC_IMG_STATE | (16 - 2));
519 width_in_mbs * height_in_mbs);
521 ((height_in_mbs - 1) << 16) |
522 ((width_in_mbs - 1) << 0));
524 ((pic_param->second_chroma_qp_index_offset & 0x1f) << 24) |
525 ((pic_param->chroma_qp_index_offset & 0x1f) << 16) |
526 (0 << 14) | /* Max-bit conformance Intra flag ??? FIXME */
527 (0 << 13) | /* Max Macroblock size conformance Inter flag ??? FIXME */
528 (pic_param->pic_fields.bits.weighted_pred_flag << 12) | /* differ from GEN6 */
529 (pic_param->pic_fields.bits.weighted_bipred_idc << 10) |
532 (pic_param->seq_fields.bits.chroma_format_idc << 10) |
533 (pic_param->pic_fields.bits.entropy_coding_mode_flag << 7) |
534 ((!pic_param->pic_fields.bits.reference_pic_flag) << 6) |
535 (pic_param->pic_fields.bits.constrained_intra_pred_flag << 5) |
536 (pic_param->seq_fields.bits.direct_8x8_inference_flag << 4) |
537 (pic_param->pic_fields.bits.transform_8x8_mode_flag << 3) |
538 (pic_param->seq_fields.bits.frame_mbs_only_flag << 2) |
539 (mbaff_frame_flag << 1) |
540 (pic_param->pic_fields.bits.field_pic_flag << 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 OUT_BCS_BATCH(batch, 0);
550 OUT_BCS_BATCH(batch, 0);
551 OUT_BCS_BATCH(batch, 0);
552 ADVANCE_BCS_BATCH(batch);
556 gen75_mfd_avc_qm_state(VADriverContextP ctx,
557 struct decode_state *decode_state,
558 struct gen7_mfd_context *gen7_mfd_context)
560 VAIQMatrixBufferH264 *iq_matrix;
561 VAPictureParameterBufferH264 *pic_param;
563 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer)
564 iq_matrix = (VAIQMatrixBufferH264 *)decode_state->iq_matrix->buffer;
566 iq_matrix = &gen7_mfd_context->iq_matrix.h264;
568 assert(decode_state->pic_param && decode_state->pic_param->buffer);
569 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
571 gen75_mfd_qm_state(ctx, MFX_QM_AVC_4X4_INTRA_MATRIX, &iq_matrix->ScalingList4x4[0][0], 3 * 16, gen7_mfd_context);
572 gen75_mfd_qm_state(ctx, MFX_QM_AVC_4X4_INTER_MATRIX, &iq_matrix->ScalingList4x4[3][0], 3 * 16, gen7_mfd_context);
574 if (pic_param->pic_fields.bits.transform_8x8_mode_flag) {
575 gen75_mfd_qm_state(ctx, MFX_QM_AVC_8x8_INTRA_MATRIX, &iq_matrix->ScalingList8x8[0][0], 64, gen7_mfd_context);
576 gen75_mfd_qm_state(ctx, MFX_QM_AVC_8x8_INTER_MATRIX, &iq_matrix->ScalingList8x8[1][0], 64, gen7_mfd_context);
581 gen75_mfd_avc_directmode_state(VADriverContextP ctx,
582 VAPictureParameterBufferH264 *pic_param,
583 VASliceParameterBufferH264 *slice_param,
584 struct gen7_mfd_context *gen7_mfd_context)
586 struct i965_driver_data *i965 = i965_driver_data(ctx);
587 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
588 struct object_surface *obj_surface;
589 struct gen7_avc_surface *gen7_avc_surface;
590 VAPictureH264 *va_pic;
593 BEGIN_BCS_BATCH(batch, 69);
594 OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
596 /* reference surfaces 0..15 */
597 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
598 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
599 obj_surface = SURFACE(gen7_mfd_context->reference_surface[i].surface_id);
601 gen7_avc_surface = obj_surface->private_data;
603 if (gen7_avc_surface == NULL) {
604 OUT_BCS_BATCH(batch, 0);
605 OUT_BCS_BATCH(batch, 0);
607 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
608 I915_GEM_DOMAIN_INSTRUCTION, 0,
611 if (gen7_avc_surface->dmv_bottom_flag == 1)
612 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_bottom,
613 I915_GEM_DOMAIN_INSTRUCTION, 0,
616 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
617 I915_GEM_DOMAIN_INSTRUCTION, 0,
621 OUT_BCS_BATCH(batch, 0);
622 OUT_BCS_BATCH(batch, 0);
626 /* the current decoding frame/field */
627 va_pic = &pic_param->CurrPic;
628 assert(!(va_pic->flags & VA_PICTURE_H264_INVALID));
629 obj_surface = SURFACE(va_pic->picture_id);
630 assert(obj_surface && obj_surface->bo && obj_surface->private_data);
631 gen7_avc_surface = obj_surface->private_data;
633 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
634 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
637 if (gen7_avc_surface->dmv_bottom_flag == 1)
638 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_bottom,
639 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
642 OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
643 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
647 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
648 if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
650 for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
651 va_pic = &pic_param->ReferenceFrames[j];
653 if (va_pic->flags & VA_PICTURE_H264_INVALID)
656 if (va_pic->picture_id == gen7_mfd_context->reference_surface[i].surface_id) {
663 assert(!(va_pic->flags & VA_PICTURE_H264_INVALID));
665 OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt);
666 OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt);
668 OUT_BCS_BATCH(batch, 0);
669 OUT_BCS_BATCH(batch, 0);
673 va_pic = &pic_param->CurrPic;
674 OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt);
675 OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt);
677 ADVANCE_BCS_BATCH(batch);
681 gen75_mfd_avc_slice_state(VADriverContextP ctx,
682 VAPictureParameterBufferH264 *pic_param,
683 VASliceParameterBufferH264 *slice_param,
684 VASliceParameterBufferH264 *next_slice_param,
685 struct gen7_mfd_context *gen7_mfd_context)
687 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
688 int width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
689 int height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1;
690 int slice_hor_pos, slice_ver_pos, next_slice_hor_pos, next_slice_ver_pos;
691 int num_ref_idx_l0, num_ref_idx_l1;
692 int mbaff_picture = (!pic_param->pic_fields.bits.field_pic_flag &&
693 pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
694 int first_mb_in_slice = 0, first_mb_in_next_slice = 0;
697 if (slice_param->slice_type == SLICE_TYPE_I ||
698 slice_param->slice_type == SLICE_TYPE_SI) {
699 slice_type = SLICE_TYPE_I;
700 } else if (slice_param->slice_type == SLICE_TYPE_P ||
701 slice_param->slice_type == SLICE_TYPE_SP) {
702 slice_type = SLICE_TYPE_P;
704 assert(slice_param->slice_type == SLICE_TYPE_B);
705 slice_type = SLICE_TYPE_B;
708 if (slice_type == SLICE_TYPE_I) {
709 assert(slice_param->num_ref_idx_l0_active_minus1 == 0);
710 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
713 } else if (slice_type == SLICE_TYPE_P) {
714 assert(slice_param->num_ref_idx_l1_active_minus1 == 0);
715 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
718 num_ref_idx_l0 = slice_param->num_ref_idx_l0_active_minus1 + 1;
719 num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
722 first_mb_in_slice = slice_param->first_mb_in_slice << mbaff_picture;
723 slice_hor_pos = first_mb_in_slice % width_in_mbs;
724 slice_ver_pos = first_mb_in_slice / width_in_mbs;
726 if (next_slice_param) {
727 first_mb_in_next_slice = next_slice_param->first_mb_in_slice << mbaff_picture;
728 next_slice_hor_pos = first_mb_in_next_slice % width_in_mbs;
729 next_slice_ver_pos = first_mb_in_next_slice / width_in_mbs;
731 next_slice_hor_pos = 0;
732 next_slice_ver_pos = height_in_mbs / (1 + !!pic_param->pic_fields.bits.field_pic_flag);
735 BEGIN_BCS_BATCH(batch, 11); /* FIXME: is it 10??? */
736 OUT_BCS_BATCH(batch, MFX_AVC_SLICE_STATE | (11 - 2));
737 OUT_BCS_BATCH(batch, slice_type);
739 (num_ref_idx_l1 << 24) |
740 (num_ref_idx_l0 << 16) |
741 (slice_param->chroma_log2_weight_denom << 8) |
742 (slice_param->luma_log2_weight_denom << 0));
744 (slice_param->direct_spatial_mv_pred_flag << 29) |
745 (slice_param->disable_deblocking_filter_idc << 27) |
746 (slice_param->cabac_init_idc << 24) |
747 ((pic_param->pic_init_qp_minus26 + 26 + slice_param->slice_qp_delta) << 16) |
748 ((slice_param->slice_beta_offset_div2 & 0xf) << 8) |
749 ((slice_param->slice_alpha_c0_offset_div2 & 0xf) << 0));
751 (slice_ver_pos << 24) |
752 (slice_hor_pos << 16) |
753 (first_mb_in_slice << 0));
755 (next_slice_ver_pos << 16) |
756 (next_slice_hor_pos << 0));
758 (next_slice_param == NULL) << 19); /* last slice flag */
759 OUT_BCS_BATCH(batch, 0);
760 OUT_BCS_BATCH(batch, 0);
761 OUT_BCS_BATCH(batch, 0);
762 OUT_BCS_BATCH(batch, 0);
763 ADVANCE_BCS_BATCH(batch);
767 gen75_mfd_avc_ref_idx_state(VADriverContextP ctx,
768 VAPictureParameterBufferH264 *pic_param,
769 VASliceParameterBufferH264 *slice_param,
770 struct gen7_mfd_context *gen7_mfd_context)
772 gen6_send_avc_ref_idx_state(
773 gen7_mfd_context->base.batch,
775 gen7_mfd_context->reference_surface
780 gen75_mfd_avc_weightoffset_state(VADriverContextP ctx,
781 VAPictureParameterBufferH264 *pic_param,
782 VASliceParameterBufferH264 *slice_param,
783 struct gen7_mfd_context *gen7_mfd_context)
785 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
786 int i, j, num_weight_offset_table = 0;
787 short weightoffsets[32 * 6];
789 if ((slice_param->slice_type == SLICE_TYPE_P ||
790 slice_param->slice_type == SLICE_TYPE_SP) &&
791 (pic_param->pic_fields.bits.weighted_pred_flag == 1)) {
792 num_weight_offset_table = 1;
795 if ((slice_param->slice_type == SLICE_TYPE_B) &&
796 (pic_param->pic_fields.bits.weighted_bipred_idc == 1)) {
797 num_weight_offset_table = 2;
800 for (i = 0; i < num_weight_offset_table; i++) {
801 BEGIN_BCS_BATCH(batch, 98);
802 OUT_BCS_BATCH(batch, MFX_AVC_WEIGHTOFFSET_STATE | (98 - 2));
803 OUT_BCS_BATCH(batch, i);
806 for (j = 0; j < 32; j++) {
807 weightoffsets[j * 6 + 0] = slice_param->luma_weight_l0[j];
808 weightoffsets[j * 6 + 1] = slice_param->luma_offset_l0[j];
809 weightoffsets[j * 6 + 2] = slice_param->chroma_weight_l0[j][0];
810 weightoffsets[j * 6 + 3] = slice_param->chroma_offset_l0[j][0];
811 weightoffsets[j * 6 + 4] = slice_param->chroma_weight_l0[j][1];
812 weightoffsets[j * 6 + 5] = slice_param->chroma_offset_l0[j][1];
815 for (j = 0; j < 32; j++) {
816 weightoffsets[j * 6 + 0] = slice_param->luma_weight_l1[j];
817 weightoffsets[j * 6 + 1] = slice_param->luma_offset_l1[j];
818 weightoffsets[j * 6 + 2] = slice_param->chroma_weight_l1[j][0];
819 weightoffsets[j * 6 + 3] = slice_param->chroma_offset_l1[j][0];
820 weightoffsets[j * 6 + 4] = slice_param->chroma_weight_l1[j][1];
821 weightoffsets[j * 6 + 5] = slice_param->chroma_offset_l1[j][1];
825 intel_batchbuffer_data(batch, weightoffsets, sizeof(weightoffsets));
826 ADVANCE_BCS_BATCH(batch);
831 gen75_mfd_avc_get_slice_bit_offset(uint8_t *buf, int mode_flag, int in_slice_data_bit_offset)
833 int out_slice_data_bit_offset;
834 int slice_header_size = in_slice_data_bit_offset / 8;
837 for (i = 0, j = 0; i < slice_header_size; i++, j++) {
838 if (!buf[j] && !buf[j + 1] && buf[j + 2] == 3) {
843 out_slice_data_bit_offset = 8 * j + in_slice_data_bit_offset % 8;
845 if (mode_flag == ENTROPY_CABAC)
846 out_slice_data_bit_offset = ALIGN(out_slice_data_bit_offset, 0x8);
848 return out_slice_data_bit_offset;
852 gen75_mfd_avc_bsd_object(VADriverContextP ctx,
853 VAPictureParameterBufferH264 *pic_param,
854 VASliceParameterBufferH264 *slice_param,
855 dri_bo *slice_data_bo,
856 VASliceParameterBufferH264 *next_slice_param,
857 struct gen7_mfd_context *gen7_mfd_context)
859 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
860 int slice_data_bit_offset;
861 uint8_t *slice_data = NULL;
863 dri_bo_map(slice_data_bo, 0);
864 slice_data = (uint8_t *)(slice_data_bo->virtual + slice_param->slice_data_offset);
865 slice_data_bit_offset = gen75_mfd_avc_get_slice_bit_offset(slice_data,
866 pic_param->pic_fields.bits.entropy_coding_mode_flag,
867 slice_param->slice_data_bit_offset);
868 dri_bo_unmap(slice_data_bo);
870 /* the input bitsteam format on GEN7 differs from GEN6 */
871 BEGIN_BCS_BATCH(batch, 6);
872 OUT_BCS_BATCH(batch, MFD_AVC_BSD_OBJECT | (6 - 2));
874 (slice_param->slice_data_size));
875 OUT_BCS_BATCH(batch, slice_param->slice_data_offset);
883 ((slice_data_bit_offset >> 3) << 16) |
886 ((next_slice_param == NULL) << 3) | /* LastSlice Flag */
887 (slice_data_bit_offset & 0x7));
888 OUT_BCS_BATCH(batch, 0);
889 ADVANCE_BCS_BATCH(batch);
893 gen75_mfd_avc_context_init(
894 VADriverContextP ctx,
895 struct gen7_mfd_context *gen7_mfd_context
898 /* Initialize flat scaling lists */
899 avc_gen_default_iq_matrix(&gen7_mfd_context->iq_matrix.h264);
903 gen75_mfd_avc_decode_init(VADriverContextP ctx,
904 struct decode_state *decode_state,
905 struct gen7_mfd_context *gen7_mfd_context)
907 VAPictureParameterBufferH264 *pic_param;
908 VASliceParameterBufferH264 *slice_param;
909 VAPictureH264 *va_pic;
910 struct i965_driver_data *i965 = i965_driver_data(ctx);
911 struct object_surface *obj_surface;
913 int i, j, enable_avc_ildb = 0;
914 unsigned int width_in_mbs, height_in_mbs;
916 for (j = 0; j < decode_state->num_slice_params && enable_avc_ildb == 0; j++) {
917 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
918 slice_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j]->buffer;
920 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
921 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
922 assert((slice_param->slice_type == SLICE_TYPE_I) ||
923 (slice_param->slice_type == SLICE_TYPE_SI) ||
924 (slice_param->slice_type == SLICE_TYPE_P) ||
925 (slice_param->slice_type == SLICE_TYPE_SP) ||
926 (slice_param->slice_type == SLICE_TYPE_B));
928 if (slice_param->disable_deblocking_filter_idc != 1) {
937 assert(decode_state->pic_param && decode_state->pic_param->buffer);
938 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
939 gen75_mfd_avc_frame_store_index(ctx, pic_param, gen7_mfd_context);
940 width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
941 height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1;
942 assert(width_in_mbs > 0 && width_in_mbs <= 256); /* 4K */
943 assert(height_in_mbs > 0 && height_in_mbs <= 256);
945 /* Current decoded picture */
946 va_pic = &pic_param->CurrPic;
947 assert(!(va_pic->flags & VA_PICTURE_H264_INVALID));
948 obj_surface = SURFACE(va_pic->picture_id);
950 obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
951 obj_surface->flags |= (pic_param->pic_fields.bits.reference_pic_flag ? SURFACE_REFERENCED : 0);
952 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
953 gen75_mfd_init_avc_surface(ctx, pic_param, obj_surface);
955 dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
956 gen7_mfd_context->post_deblocking_output.bo = obj_surface->bo;
957 dri_bo_reference(gen7_mfd_context->post_deblocking_output.bo);
958 gen7_mfd_context->post_deblocking_output.valid = enable_avc_ildb;
960 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
961 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
962 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
963 gen7_mfd_context->pre_deblocking_output.valid = !enable_avc_ildb;
965 dri_bo_unreference(gen7_mfd_context->intra_row_store_scratch_buffer.bo);
966 bo = dri_bo_alloc(i965->intel.bufmgr,
971 gen7_mfd_context->intra_row_store_scratch_buffer.bo = bo;
972 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 1;
974 dri_bo_unreference(gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo);
975 bo = dri_bo_alloc(i965->intel.bufmgr,
976 "deblocking filter row store",
977 width_in_mbs * 64 * 4,
980 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = bo;
981 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 1;
983 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
984 bo = dri_bo_alloc(i965->intel.bufmgr,
986 width_in_mbs * 64 * 2,
989 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = bo;
990 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 1;
992 dri_bo_unreference(gen7_mfd_context->mpr_row_store_scratch_buffer.bo);
993 bo = dri_bo_alloc(i965->intel.bufmgr,
995 width_in_mbs * 64 * 2,
998 gen7_mfd_context->mpr_row_store_scratch_buffer.bo = bo;
999 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 1;
1001 gen7_mfd_context->bitplane_read_buffer.valid = 0;
1005 gen75_mfd_avc_decode_picture(VADriverContextP ctx,
1006 struct decode_state *decode_state,
1007 struct gen7_mfd_context *gen7_mfd_context)
1009 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1010 VAPictureParameterBufferH264 *pic_param;
1011 VASliceParameterBufferH264 *slice_param, *next_slice_param, *next_slice_group_param;
1012 dri_bo *slice_data_bo;
1015 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1016 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
1017 gen75_mfd_avc_decode_init(ctx, decode_state, gen7_mfd_context);
1019 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
1020 intel_batchbuffer_emit_mi_flush(batch);
1021 gen75_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1022 gen75_mfd_surface_state(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1023 gen75_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1024 gen75_mfd_bsp_buf_base_addr_state(ctx, decode_state, MFX_FORMAT_AVC, gen7_mfd_context);
1025 gen75_mfd_avc_qm_state(ctx, decode_state, gen7_mfd_context);
1026 gen75_mfd_avc_img_state(ctx, decode_state, gen7_mfd_context);
1028 for (j = 0; j < decode_state->num_slice_params; j++) {
1029 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
1030 slice_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j]->buffer;
1031 slice_data_bo = decode_state->slice_datas[j]->bo;
1032 gen75_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_AVC, gen7_mfd_context);
1034 if (j == decode_state->num_slice_params - 1)
1035 next_slice_group_param = NULL;
1037 next_slice_group_param = (VASliceParameterBufferH264 *)decode_state->slice_params[j + 1]->buffer;
1039 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
1040 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
1041 assert((slice_param->slice_type == SLICE_TYPE_I) ||
1042 (slice_param->slice_type == SLICE_TYPE_SI) ||
1043 (slice_param->slice_type == SLICE_TYPE_P) ||
1044 (slice_param->slice_type == SLICE_TYPE_SP) ||
1045 (slice_param->slice_type == SLICE_TYPE_B));
1047 if (i < decode_state->slice_params[j]->num_elements - 1)
1048 next_slice_param = slice_param + 1;
1050 next_slice_param = next_slice_group_param;
1052 gen75_mfd_avc_directmode_state(ctx, pic_param, slice_param, gen7_mfd_context);
1053 gen75_mfd_avc_ref_idx_state(ctx, pic_param, slice_param, gen7_mfd_context);
1054 gen75_mfd_avc_weightoffset_state(ctx, pic_param, slice_param, gen7_mfd_context);
1055 gen75_mfd_avc_slice_state(ctx, pic_param, slice_param, next_slice_param, gen7_mfd_context);
1056 gen75_mfd_avc_bsd_object(ctx, pic_param, slice_param, slice_data_bo, next_slice_param, gen7_mfd_context);
1061 intel_batchbuffer_end_atomic(batch);
1062 intel_batchbuffer_flush(batch);
1066 gen75_mfd_mpeg2_decode_init(VADriverContextP ctx,
1067 struct decode_state *decode_state,
1068 struct gen7_mfd_context *gen7_mfd_context)
1070 VAPictureParameterBufferMPEG2 *pic_param;
1071 struct i965_driver_data *i965 = i965_driver_data(ctx);
1072 struct object_surface *obj_surface;
1074 unsigned int width_in_mbs;
1076 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1077 pic_param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
1078 width_in_mbs = ALIGN(pic_param->horizontal_size, 16) / 16;
1080 mpeg2_set_reference_surfaces(
1082 gen7_mfd_context->reference_surface,
1087 /* Current decoded picture */
1088 obj_surface = SURFACE(decode_state->current_render_target);
1089 assert(obj_surface);
1090 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
1092 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
1093 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
1094 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
1095 gen7_mfd_context->pre_deblocking_output.valid = 1;
1097 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
1098 bo = dri_bo_alloc(i965->intel.bufmgr,
1099 "bsd mpc row store",
1103 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = bo;
1104 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 1;
1106 gen7_mfd_context->post_deblocking_output.valid = 0;
1107 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 0;
1108 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 0;
1109 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 0;
1110 gen7_mfd_context->bitplane_read_buffer.valid = 0;
1114 gen75_mfd_mpeg2_pic_state(VADriverContextP ctx,
1115 struct decode_state *decode_state,
1116 struct gen7_mfd_context *gen7_mfd_context)
1118 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1119 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1120 VAPictureParameterBufferMPEG2 *pic_param;
1121 unsigned int slice_concealment_disable_bit = 0;
1123 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1124 pic_param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
1126 slice_concealment_disable_bit = 1;
1128 BEGIN_BCS_BATCH(batch, 13);
1129 OUT_BCS_BATCH(batch, MFX_MPEG2_PIC_STATE | (13 - 2));
1130 OUT_BCS_BATCH(batch,
1131 (pic_param->f_code & 0xf) << 28 | /* f_code[1][1] */
1132 ((pic_param->f_code >> 4) & 0xf) << 24 | /* f_code[1][0] */
1133 ((pic_param->f_code >> 8) & 0xf) << 20 | /* f_code[0][1] */
1134 ((pic_param->f_code >> 12) & 0xf) << 16 | /* f_code[0][0] */
1135 pic_param->picture_coding_extension.bits.intra_dc_precision << 14 |
1136 pic_param->picture_coding_extension.bits.picture_structure << 12 |
1137 pic_param->picture_coding_extension.bits.top_field_first << 11 |
1138 pic_param->picture_coding_extension.bits.frame_pred_frame_dct << 10 |
1139 pic_param->picture_coding_extension.bits.concealment_motion_vectors << 9 |
1140 pic_param->picture_coding_extension.bits.q_scale_type << 8 |
1141 pic_param->picture_coding_extension.bits.intra_vlc_format << 7 |
1142 pic_param->picture_coding_extension.bits.alternate_scan << 6);
1143 OUT_BCS_BATCH(batch,
1144 pic_param->picture_coding_type << 9);
1145 OUT_BCS_BATCH(batch,
1146 (slice_concealment_disable_bit << 31) |
1147 ((ALIGN(pic_param->vertical_size, 16) / 16) - 1) << 16 |
1148 ((ALIGN(pic_param->horizontal_size, 16) / 16) - 1));
1149 OUT_BCS_BATCH(batch, 0);
1150 OUT_BCS_BATCH(batch, 0);
1151 OUT_BCS_BATCH(batch, 0);
1152 OUT_BCS_BATCH(batch, 0);
1153 OUT_BCS_BATCH(batch, 0);
1154 OUT_BCS_BATCH(batch, 0);
1155 OUT_BCS_BATCH(batch, 0);
1156 OUT_BCS_BATCH(batch, 0);
1157 OUT_BCS_BATCH(batch, 0);
1158 ADVANCE_BCS_BATCH(batch);
1162 gen75_mfd_mpeg2_qm_state(VADriverContextP ctx,
1163 struct decode_state *decode_state,
1164 struct gen7_mfd_context *gen7_mfd_context)
1166 VAIQMatrixBufferMPEG2 * const gen_iq_matrix = &gen7_mfd_context->iq_matrix.mpeg2;
1169 /* Update internal QM state */
1170 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer) {
1171 VAIQMatrixBufferMPEG2 * const iq_matrix =
1172 (VAIQMatrixBufferMPEG2 *)decode_state->iq_matrix->buffer;
1174 if (gen_iq_matrix->load_intra_quantiser_matrix == -1 ||
1175 iq_matrix->load_intra_quantiser_matrix) {
1176 gen_iq_matrix->load_intra_quantiser_matrix =
1177 iq_matrix->load_intra_quantiser_matrix;
1178 if (iq_matrix->load_intra_quantiser_matrix) {
1179 for (j = 0; j < 64; j++)
1180 gen_iq_matrix->intra_quantiser_matrix[zigzag_direct[j]] =
1181 iq_matrix->intra_quantiser_matrix[j];
1185 if (gen_iq_matrix->load_non_intra_quantiser_matrix == -1 ||
1186 iq_matrix->load_non_intra_quantiser_matrix) {
1187 gen_iq_matrix->load_non_intra_quantiser_matrix =
1188 iq_matrix->load_non_intra_quantiser_matrix;
1189 if (iq_matrix->load_non_intra_quantiser_matrix) {
1190 for (j = 0; j < 64; j++)
1191 gen_iq_matrix->non_intra_quantiser_matrix[zigzag_direct[j]] =
1192 iq_matrix->non_intra_quantiser_matrix[j];
1197 /* Commit QM state to HW */
1198 for (i = 0; i < 2; i++) {
1199 unsigned char *qm = NULL;
1203 if (gen_iq_matrix->load_intra_quantiser_matrix) {
1204 qm = gen_iq_matrix->intra_quantiser_matrix;
1205 qm_type = MFX_QM_MPEG_INTRA_QUANTIZER_MATRIX;
1208 if (gen_iq_matrix->load_non_intra_quantiser_matrix) {
1209 qm = gen_iq_matrix->non_intra_quantiser_matrix;
1210 qm_type = MFX_QM_MPEG_NON_INTRA_QUANTIZER_MATRIX;
1217 gen75_mfd_qm_state(ctx, qm_type, qm, 64, gen7_mfd_context);
1222 gen75_mfd_mpeg2_bsd_object(VADriverContextP ctx,
1223 VAPictureParameterBufferMPEG2 *pic_param,
1224 VASliceParameterBufferMPEG2 *slice_param,
1225 VASliceParameterBufferMPEG2 *next_slice_param,
1226 struct gen7_mfd_context *gen7_mfd_context)
1228 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1229 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1230 unsigned int width_in_mbs = ALIGN(pic_param->horizontal_size, 16) / 16;
1231 int mb_count, vpos0, hpos0, vpos1, hpos1, is_field_pic_wa, is_field_pic = 0;
1233 if (pic_param->picture_coding_extension.bits.picture_structure == MPEG_TOP_FIELD ||
1234 pic_param->picture_coding_extension.bits.picture_structure == MPEG_BOTTOM_FIELD)
1236 is_field_pic_wa = is_field_pic &&
1237 gen7_mfd_context->wa_mpeg2_slice_vertical_position > 0;
1239 vpos0 = slice_param->slice_vertical_position / (1 + is_field_pic_wa);
1240 hpos0 = slice_param->slice_horizontal_position;
1242 if (next_slice_param == NULL) {
1243 vpos1 = ALIGN(pic_param->vertical_size, 16) / 16 / (1 + is_field_pic);
1246 vpos1 = next_slice_param->slice_vertical_position / (1 + is_field_pic_wa);
1247 hpos1 = next_slice_param->slice_horizontal_position;
1250 mb_count = (vpos1 * width_in_mbs + hpos1) - (vpos0 * width_in_mbs + hpos0);
1252 BEGIN_BCS_BATCH(batch, 5);
1253 OUT_BCS_BATCH(batch, MFD_MPEG2_BSD_OBJECT | (5 - 2));
1254 OUT_BCS_BATCH(batch,
1255 slice_param->slice_data_size - (slice_param->macroblock_offset >> 3));
1256 OUT_BCS_BATCH(batch,
1257 slice_param->slice_data_offset + (slice_param->macroblock_offset >> 3));
1258 OUT_BCS_BATCH(batch,
1262 (next_slice_param == NULL) << 5 |
1263 (next_slice_param == NULL) << 3 |
1264 (slice_param->macroblock_offset & 0x7));
1265 OUT_BCS_BATCH(batch,
1266 (slice_param->quantiser_scale_code << 24) |
1267 (vpos1 << 8 | hpos1));
1268 ADVANCE_BCS_BATCH(batch);
1272 gen75_mfd_mpeg2_decode_picture(VADriverContextP ctx,
1273 struct decode_state *decode_state,
1274 struct gen7_mfd_context *gen7_mfd_context)
1276 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1277 VAPictureParameterBufferMPEG2 *pic_param;
1278 VASliceParameterBufferMPEG2 *slice_param, *next_slice_param, *next_slice_group_param;
1279 dri_bo *slice_data_bo;
1282 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1283 pic_param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
1285 gen75_mfd_mpeg2_decode_init(ctx, decode_state, gen7_mfd_context);
1286 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
1287 intel_batchbuffer_emit_mi_flush(batch);
1288 gen75_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1289 gen75_mfd_surface_state(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1290 gen75_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1291 gen75_mfd_bsp_buf_base_addr_state(ctx, decode_state, MFX_FORMAT_MPEG2, gen7_mfd_context);
1292 gen75_mfd_mpeg2_pic_state(ctx, decode_state, gen7_mfd_context);
1293 gen75_mfd_mpeg2_qm_state(ctx, decode_state, gen7_mfd_context);
1295 if (gen7_mfd_context->wa_mpeg2_slice_vertical_position < 0)
1296 gen7_mfd_context->wa_mpeg2_slice_vertical_position =
1297 mpeg2_wa_slice_vertical_position(decode_state, pic_param);
1299 for (j = 0; j < decode_state->num_slice_params; j++) {
1300 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
1301 slice_param = (VASliceParameterBufferMPEG2 *)decode_state->slice_params[j]->buffer;
1302 slice_data_bo = decode_state->slice_datas[j]->bo;
1303 gen75_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_MPEG2, gen7_mfd_context);
1305 if (j == decode_state->num_slice_params - 1)
1306 next_slice_group_param = NULL;
1308 next_slice_group_param = (VASliceParameterBufferMPEG2 *)decode_state->slice_params[j + 1]->buffer;
1310 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
1311 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
1313 if (i < decode_state->slice_params[j]->num_elements - 1)
1314 next_slice_param = slice_param + 1;
1316 next_slice_param = next_slice_group_param;
1318 gen75_mfd_mpeg2_bsd_object(ctx, pic_param, slice_param, next_slice_param, gen7_mfd_context);
1323 intel_batchbuffer_end_atomic(batch);
1324 intel_batchbuffer_flush(batch);
1327 static const int va_to_gen7_vc1_pic_type[5] = {
1331 GEN7_VC1_BI_PICTURE,
1335 static const int va_to_gen7_vc1_mv[4] = {
1337 2, /* 1-MV half-pel */
1338 3, /* 1-MV half-pef bilinear */
1342 static const int b_picture_scale_factor[21] = {
1343 128, 85, 170, 64, 192,
1344 51, 102, 153, 204, 43,
1345 215, 37, 74, 111, 148,
1346 185, 222, 32, 96, 160,
1350 static const int va_to_gen7_vc1_condover[3] = {
1356 static const int va_to_gen7_vc1_profile[4] = {
1357 GEN7_VC1_SIMPLE_PROFILE,
1358 GEN7_VC1_MAIN_PROFILE,
1359 GEN7_VC1_RESERVED_PROFILE,
1360 GEN7_VC1_ADVANCED_PROFILE
1364 gen75_mfd_free_vc1_surface(void **data)
1366 struct gen7_vc1_surface *gen7_vc1_surface = *data;
1368 if (!gen7_vc1_surface)
1371 dri_bo_unreference(gen7_vc1_surface->dmv);
1372 free(gen7_vc1_surface);
1377 gen75_mfd_init_vc1_surface(VADriverContextP ctx,
1378 VAPictureParameterBufferVC1 *pic_param,
1379 struct object_surface *obj_surface)
1381 struct i965_driver_data *i965 = i965_driver_data(ctx);
1382 struct gen7_vc1_surface *gen7_vc1_surface = obj_surface->private_data;
1383 int width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
1384 int height_in_mbs = ALIGN(pic_param->coded_height, 16) / 16;
1386 obj_surface->free_private_data = gen75_mfd_free_vc1_surface;
1388 if (!gen7_vc1_surface) {
1389 gen7_vc1_surface = calloc(sizeof(struct gen7_vc1_surface), 1);
1390 assert((obj_surface->size & 0x3f) == 0);
1391 obj_surface->private_data = gen7_vc1_surface;
1394 gen7_vc1_surface->picture_type = pic_param->picture_fields.bits.picture_type;
1396 if (gen7_vc1_surface->dmv == NULL) {
1397 gen7_vc1_surface->dmv = dri_bo_alloc(i965->intel.bufmgr,
1398 "direct mv w/r buffer",
1399 width_in_mbs * height_in_mbs * 64,
1405 gen75_mfd_vc1_decode_init(VADriverContextP ctx,
1406 struct decode_state *decode_state,
1407 struct gen7_mfd_context *gen7_mfd_context)
1409 VAPictureParameterBufferVC1 *pic_param;
1410 struct i965_driver_data *i965 = i965_driver_data(ctx);
1411 struct object_surface *obj_surface;
1416 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1417 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1418 width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
1420 /* reference picture */
1421 obj_surface = SURFACE(pic_param->forward_reference_picture);
1423 if (obj_surface && obj_surface->bo)
1424 gen7_mfd_context->reference_surface[0].surface_id = pic_param->forward_reference_picture;
1426 gen7_mfd_context->reference_surface[0].surface_id = VA_INVALID_ID;
1428 obj_surface = SURFACE(pic_param->backward_reference_picture);
1430 if (obj_surface && obj_surface->bo)
1431 gen7_mfd_context->reference_surface[1].surface_id = pic_param->backward_reference_picture;
1433 gen7_mfd_context->reference_surface[1].surface_id = pic_param->forward_reference_picture;
1435 /* must do so !!! */
1436 for (i = 2; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++)
1437 gen7_mfd_context->reference_surface[i].surface_id = gen7_mfd_context->reference_surface[i % 2].surface_id;
1439 /* Current decoded picture */
1440 obj_surface = SURFACE(decode_state->current_render_target);
1441 assert(obj_surface);
1442 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
1443 gen75_mfd_init_vc1_surface(ctx, pic_param, obj_surface);
1445 dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
1446 gen7_mfd_context->post_deblocking_output.bo = obj_surface->bo;
1447 dri_bo_reference(gen7_mfd_context->post_deblocking_output.bo);
1448 gen7_mfd_context->post_deblocking_output.valid = pic_param->entrypoint_fields.bits.loopfilter;
1450 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
1451 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
1452 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
1453 gen7_mfd_context->pre_deblocking_output.valid = !pic_param->entrypoint_fields.bits.loopfilter;
1455 dri_bo_unreference(gen7_mfd_context->intra_row_store_scratch_buffer.bo);
1456 bo = dri_bo_alloc(i965->intel.bufmgr,
1461 gen7_mfd_context->intra_row_store_scratch_buffer.bo = bo;
1462 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 1;
1464 dri_bo_unreference(gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo);
1465 bo = dri_bo_alloc(i965->intel.bufmgr,
1466 "deblocking filter row store",
1467 width_in_mbs * 6 * 64,
1470 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = bo;
1471 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 1;
1473 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
1474 bo = dri_bo_alloc(i965->intel.bufmgr,
1475 "bsd mpc row store",
1479 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = bo;
1480 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 1;
1482 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 0;
1484 gen7_mfd_context->bitplane_read_buffer.valid = !!pic_param->bitplane_present.value;
1485 dri_bo_unreference(gen7_mfd_context->bitplane_read_buffer.bo);
1487 if (gen7_mfd_context->bitplane_read_buffer.valid) {
1488 int width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
1489 int height_in_mbs = ALIGN(pic_param->coded_height, 16) / 16;
1490 int bitplane_width = ALIGN(width_in_mbs, 2) / 2;
1492 uint8_t *src = NULL, *dst = NULL;
1494 assert(decode_state->bit_plane->buffer);
1495 src = decode_state->bit_plane->buffer;
1497 bo = dri_bo_alloc(i965->intel.bufmgr,
1499 bitplane_width * bitplane_width,
1502 gen7_mfd_context->bitplane_read_buffer.bo = bo;
1504 dri_bo_map(bo, True);
1505 assert(bo->virtual);
1508 for (src_h = 0; src_h < height_in_mbs; src_h++) {
1509 for(src_w = 0; src_w < width_in_mbs; src_w++) {
1510 int src_index, dst_index;
1514 src_index = (src_h * width_in_mbs + src_w) / 2;
1515 src_shift = !((src_h * width_in_mbs + src_w) & 1) * 4;
1516 src_value = ((src[src_index] >> src_shift) & 0xf);
1518 dst_index = src_w / 2;
1519 dst[dst_index] = ((dst[dst_index] >> 4) | (src_value << 4));
1523 dst[src_w / 2] >>= 4;
1525 dst += bitplane_width;
1530 gen7_mfd_context->bitplane_read_buffer.bo = NULL;
1534 gen75_mfd_vc1_pic_state(VADriverContextP ctx,
1535 struct decode_state *decode_state,
1536 struct gen7_mfd_context *gen7_mfd_context)
1538 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1539 VAPictureParameterBufferVC1 *pic_param;
1540 struct i965_driver_data *i965 = i965_driver_data(ctx);
1541 struct object_surface *obj_surface;
1542 int alt_pquant_config = 0, alt_pquant_edge_mask = 0, alt_pq;
1543 int dquant, dquantfrm, dqprofile, dqdbedge, dqsbedge, dqbilevel;
1544 int unified_mv_mode;
1545 int ref_field_pic_polarity = 0;
1546 int scale_factor = 0;
1548 int dmv_surface_valid = 0;
1554 int interpolation_mode = 0;
1556 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1557 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1559 profile = va_to_gen7_vc1_profile[pic_param->sequence_fields.bits.profile];
1560 dquant = pic_param->pic_quantizer_fields.bits.dquant;
1561 dquantfrm = pic_param->pic_quantizer_fields.bits.dq_frame;
1562 dqprofile = pic_param->pic_quantizer_fields.bits.dq_profile;
1563 dqdbedge = pic_param->pic_quantizer_fields.bits.dq_db_edge;
1564 dqsbedge = pic_param->pic_quantizer_fields.bits.dq_sb_edge;
1565 dqbilevel = pic_param->pic_quantizer_fields.bits.dq_binary_level;
1566 alt_pq = pic_param->pic_quantizer_fields.bits.alt_pic_quantizer;
1569 alt_pquant_config = 0;
1570 alt_pquant_edge_mask = 0;
1571 } else if (dquant == 2) {
1572 alt_pquant_config = 1;
1573 alt_pquant_edge_mask = 0xf;
1575 assert(dquant == 1);
1576 if (dquantfrm == 0) {
1577 alt_pquant_config = 0;
1578 alt_pquant_edge_mask = 0;
1581 assert(dquantfrm == 1);
1582 alt_pquant_config = 1;
1584 switch (dqprofile) {
1586 if (dqbilevel == 0) {
1587 alt_pquant_config = 2;
1588 alt_pquant_edge_mask = 0;
1590 assert(dqbilevel == 1);
1591 alt_pquant_config = 3;
1592 alt_pquant_edge_mask = 0;
1597 alt_pquant_edge_mask = 0xf;
1602 alt_pquant_edge_mask = 0x9;
1604 alt_pquant_edge_mask = (0x3 << dqdbedge);
1609 alt_pquant_edge_mask = (0x1 << dqsbedge);
1618 if (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation) {
1619 assert(pic_param->mv_fields.bits.mv_mode2 < 4);
1620 unified_mv_mode = va_to_gen7_vc1_mv[pic_param->mv_fields.bits.mv_mode2];
1622 assert(pic_param->mv_fields.bits.mv_mode < 4);
1623 unified_mv_mode = va_to_gen7_vc1_mv[pic_param->mv_fields.bits.mv_mode];
1626 if (pic_param->sequence_fields.bits.interlace == 1 &&
1627 pic_param->picture_fields.bits.frame_coding_mode != 0) { /* frame-interlace or field-interlace */
1628 /* FIXME: calculate reference field picture polarity */
1630 ref_field_pic_polarity = 0;
1633 if (pic_param->b_picture_fraction < 21)
1634 scale_factor = b_picture_scale_factor[pic_param->b_picture_fraction];
1636 picture_type = va_to_gen7_vc1_pic_type[pic_param->picture_fields.bits.picture_type];
1638 if (profile == GEN7_VC1_ADVANCED_PROFILE &&
1639 picture_type == GEN7_VC1_I_PICTURE)
1640 picture_type = GEN7_VC1_BI_PICTURE;
1642 if (picture_type == GEN7_VC1_I_PICTURE || picture_type == GEN7_VC1_BI_PICTURE) /* I picture */
1643 trans_ac_y = pic_param->transform_fields.bits.transform_ac_codingset_idx2;
1645 trans_ac_y = pic_param->transform_fields.bits.transform_ac_codingset_idx1;
1648 if (picture_type == GEN7_VC1_B_PICTURE) {
1649 struct gen7_vc1_surface *gen7_vc1_surface = NULL;
1651 obj_surface = SURFACE(pic_param->backward_reference_picture);
1652 assert(obj_surface);
1653 gen7_vc1_surface = obj_surface->private_data;
1655 if (!gen7_vc1_surface ||
1656 (va_to_gen7_vc1_pic_type[gen7_vc1_surface->picture_type] == GEN7_VC1_I_PICTURE ||
1657 va_to_gen7_vc1_pic_type[gen7_vc1_surface->picture_type] == GEN7_VC1_BI_PICTURE))
1658 dmv_surface_valid = 0;
1660 dmv_surface_valid = 1;
1663 assert(pic_param->picture_fields.bits.frame_coding_mode < 3);
1665 if (pic_param->picture_fields.bits.frame_coding_mode < 2)
1666 fcm = pic_param->picture_fields.bits.frame_coding_mode;
1668 if (pic_param->picture_fields.bits.top_field_first)
1674 if (pic_param->picture_fields.bits.picture_type == GEN7_VC1_B_PICTURE) { /* B picture */
1675 brfd = pic_param->reference_fields.bits.reference_distance;
1676 brfd = (scale_factor * brfd) >> 8;
1677 brfd = pic_param->reference_fields.bits.reference_distance - brfd - 1;
1683 overlap = pic_param->sequence_fields.bits.overlap;
1684 if (profile != GEN7_VC1_ADVANCED_PROFILE && pic_param->pic_quantizer_fields.bits.pic_quantizer_scale < 9)
1687 assert(pic_param->conditional_overlap_flag < 3);
1688 assert(pic_param->mv_fields.bits.mv_table < 4); /* FIXME: interlace mode */
1690 if (pic_param->mv_fields.bits.mv_mode == VAMvMode1MvHalfPelBilinear ||
1691 (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation &&
1692 pic_param->mv_fields.bits.mv_mode2 == VAMvMode1MvHalfPelBilinear))
1693 interpolation_mode = 9; /* Half-pel bilinear */
1694 else if (pic_param->mv_fields.bits.mv_mode == VAMvMode1MvHalfPel ||
1695 (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation &&
1696 pic_param->mv_fields.bits.mv_mode2 == VAMvMode1MvHalfPel))
1697 interpolation_mode = 1; /* Half-pel bicubic */
1699 interpolation_mode = 0; /* Quarter-pel bicubic */
1701 BEGIN_BCS_BATCH(batch, 6);
1702 OUT_BCS_BATCH(batch, MFD_VC1_LONG_PIC_STATE | (6 - 2));
1703 OUT_BCS_BATCH(batch,
1704 (((ALIGN(pic_param->coded_height, 16) / 16) - 1) << 16) |
1705 ((ALIGN(pic_param->coded_width, 16) / 16) - 1));
1706 OUT_BCS_BATCH(batch,
1707 ((ALIGN(pic_param->coded_width, 16) / 16 + 1) / 2 - 1) << 24 |
1708 dmv_surface_valid << 15 |
1709 (pic_param->pic_quantizer_fields.bits.quantizer == 0) << 14 | /* implicit quantizer */
1710 pic_param->rounding_control << 13 |
1711 pic_param->sequence_fields.bits.syncmarker << 12 |
1712 interpolation_mode << 8 |
1713 0 << 7 | /* FIXME: scale up or down ??? */
1714 pic_param->range_reduction_frame << 6 |
1715 pic_param->entrypoint_fields.bits.loopfilter << 5 |
1717 !pic_param->picture_fields.bits.is_first_field << 3 |
1718 (pic_param->sequence_fields.bits.profile == 3) << 0);
1719 OUT_BCS_BATCH(batch,
1720 va_to_gen7_vc1_condover[pic_param->conditional_overlap_flag] << 29 |
1721 picture_type << 26 |
1724 pic_param->pic_quantizer_fields.bits.pic_quantizer_scale << 8 |
1726 OUT_BCS_BATCH(batch,
1727 unified_mv_mode << 28 |
1728 pic_param->mv_fields.bits.four_mv_switch << 27 |
1729 pic_param->fast_uvmc_flag << 26 |
1730 ref_field_pic_polarity << 25 |
1731 pic_param->reference_fields.bits.num_reference_pictures << 24 |
1732 pic_param->reference_fields.bits.reference_distance << 20 |
1733 pic_param->reference_fields.bits.reference_distance << 16 | /* FIXME: ??? */
1734 pic_param->mv_fields.bits.extended_dmv_range << 10 |
1735 pic_param->mv_fields.bits.extended_mv_range << 8 |
1736 alt_pquant_edge_mask << 4 |
1737 alt_pquant_config << 2 |
1738 pic_param->pic_quantizer_fields.bits.half_qp << 1 |
1739 pic_param->pic_quantizer_fields.bits.pic_quantizer_type << 0);
1740 OUT_BCS_BATCH(batch,
1741 !!pic_param->bitplane_present.value << 31 |
1742 !pic_param->bitplane_present.flags.bp_forward_mb << 30 |
1743 !pic_param->bitplane_present.flags.bp_mv_type_mb << 29 |
1744 !pic_param->bitplane_present.flags.bp_skip_mb << 28 |
1745 !pic_param->bitplane_present.flags.bp_direct_mb << 27 |
1746 !pic_param->bitplane_present.flags.bp_overflags << 26 |
1747 !pic_param->bitplane_present.flags.bp_ac_pred << 25 |
1748 !pic_param->bitplane_present.flags.bp_field_tx << 24 |
1749 pic_param->mv_fields.bits.mv_table << 20 |
1750 pic_param->mv_fields.bits.four_mv_block_pattern_table << 18 |
1751 pic_param->mv_fields.bits.two_mv_block_pattern_table << 16 |
1752 pic_param->transform_fields.bits.frame_level_transform_type << 12 |
1753 pic_param->transform_fields.bits.mb_level_transform_type_flag << 11 |
1754 pic_param->mb_mode_table << 8 |
1756 pic_param->transform_fields.bits.transform_ac_codingset_idx1 << 4 |
1757 pic_param->transform_fields.bits.intra_transform_dc_table << 3 |
1758 pic_param->cbp_table << 0);
1759 ADVANCE_BCS_BATCH(batch);
1763 gen75_mfd_vc1_pred_pipe_state(VADriverContextP ctx,
1764 struct decode_state *decode_state,
1765 struct gen7_mfd_context *gen7_mfd_context)
1767 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1768 VAPictureParameterBufferVC1 *pic_param;
1769 int intensitycomp_single;
1771 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1772 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1774 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1775 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1776 intensitycomp_single = (pic_param->mv_fields.bits.mv_mode == VAMvModeIntensityCompensation);
1778 BEGIN_BCS_BATCH(batch, 6);
1779 OUT_BCS_BATCH(batch, MFX_VC1_PRED_PIPE_STATE | (6 - 2));
1780 OUT_BCS_BATCH(batch,
1781 0 << 14 | /* FIXME: double ??? */
1783 intensitycomp_single << 10 |
1784 intensitycomp_single << 8 |
1785 0 << 4 | /* FIXME: interlace mode */
1787 OUT_BCS_BATCH(batch,
1788 pic_param->luma_shift << 16 |
1789 pic_param->luma_scale << 0); /* FIXME: Luma Scaling */
1790 OUT_BCS_BATCH(batch, 0);
1791 OUT_BCS_BATCH(batch, 0);
1792 OUT_BCS_BATCH(batch, 0);
1793 ADVANCE_BCS_BATCH(batch);
1798 gen75_mfd_vc1_directmode_state(VADriverContextP ctx,
1799 struct decode_state *decode_state,
1800 struct gen7_mfd_context *gen7_mfd_context)
1802 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1803 VAPictureParameterBufferVC1 *pic_param;
1804 struct i965_driver_data *i965 = i965_driver_data(ctx);
1805 struct object_surface *obj_surface;
1806 dri_bo *dmv_read_buffer = NULL, *dmv_write_buffer = NULL;
1808 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1809 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1811 obj_surface = SURFACE(decode_state->current_render_target);
1813 if (obj_surface && obj_surface->private_data) {
1814 dmv_write_buffer = ((struct gen7_vc1_surface *)(obj_surface->private_data))->dmv;
1817 obj_surface = SURFACE(pic_param->backward_reference_picture);
1819 if (obj_surface && obj_surface->private_data) {
1820 dmv_read_buffer = ((struct gen7_vc1_surface *)(obj_surface->private_data))->dmv;
1823 BEGIN_BCS_BATCH(batch, 3);
1824 OUT_BCS_BATCH(batch, MFX_VC1_DIRECTMODE_STATE | (3 - 2));
1826 if (dmv_write_buffer)
1827 OUT_BCS_RELOC(batch, dmv_write_buffer,
1828 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
1831 OUT_BCS_BATCH(batch, 0);
1833 if (dmv_read_buffer)
1834 OUT_BCS_RELOC(batch, dmv_read_buffer,
1835 I915_GEM_DOMAIN_INSTRUCTION, 0,
1838 OUT_BCS_BATCH(batch, 0);
1840 ADVANCE_BCS_BATCH(batch);
1844 gen75_mfd_vc1_get_macroblock_bit_offset(uint8_t *buf, int in_slice_data_bit_offset, int profile)
1846 int out_slice_data_bit_offset;
1847 int slice_header_size = in_slice_data_bit_offset / 8;
1851 out_slice_data_bit_offset = in_slice_data_bit_offset;
1853 for (i = 0, j = 0; i < slice_header_size; i++, j++) {
1854 if (!buf[j] && !buf[j + 1] && buf[j + 2] == 3 && buf[j + 3] < 4) {
1859 out_slice_data_bit_offset = 8 * j + in_slice_data_bit_offset % 8;
1862 return out_slice_data_bit_offset;
1866 gen75_mfd_vc1_bsd_object(VADriverContextP ctx,
1867 VAPictureParameterBufferVC1 *pic_param,
1868 VASliceParameterBufferVC1 *slice_param,
1869 VASliceParameterBufferVC1 *next_slice_param,
1870 dri_bo *slice_data_bo,
1871 struct gen7_mfd_context *gen7_mfd_context)
1873 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1874 int next_slice_start_vert_pos;
1875 int macroblock_offset;
1876 uint8_t *slice_data = NULL;
1878 dri_bo_map(slice_data_bo, 0);
1879 slice_data = (uint8_t *)(slice_data_bo->virtual + slice_param->slice_data_offset);
1880 macroblock_offset = gen75_mfd_vc1_get_macroblock_bit_offset(slice_data,
1881 slice_param->macroblock_offset,
1882 pic_param->sequence_fields.bits.profile);
1883 dri_bo_unmap(slice_data_bo);
1885 if (next_slice_param)
1886 next_slice_start_vert_pos = next_slice_param->slice_vertical_position;
1888 next_slice_start_vert_pos = ALIGN(pic_param->coded_height, 16) / 16;
1890 BEGIN_BCS_BATCH(batch, 5);
1891 OUT_BCS_BATCH(batch, MFD_VC1_BSD_OBJECT | (5 - 2));
1892 OUT_BCS_BATCH(batch,
1893 slice_param->slice_data_size - (macroblock_offset >> 3));
1894 OUT_BCS_BATCH(batch,
1895 slice_param->slice_data_offset + (macroblock_offset >> 3));
1896 OUT_BCS_BATCH(batch,
1897 slice_param->slice_vertical_position << 16 |
1898 next_slice_start_vert_pos << 0);
1899 OUT_BCS_BATCH(batch,
1900 (macroblock_offset & 0x7));
1901 ADVANCE_BCS_BATCH(batch);
1905 gen75_mfd_vc1_decode_picture(VADriverContextP ctx,
1906 struct decode_state *decode_state,
1907 struct gen7_mfd_context *gen7_mfd_context)
1909 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
1910 VAPictureParameterBufferVC1 *pic_param;
1911 VASliceParameterBufferVC1 *slice_param, *next_slice_param, *next_slice_group_param;
1912 dri_bo *slice_data_bo;
1915 assert(decode_state->pic_param && decode_state->pic_param->buffer);
1916 pic_param = (VAPictureParameterBufferVC1 *)decode_state->pic_param->buffer;
1918 gen75_mfd_vc1_decode_init(ctx, decode_state, gen7_mfd_context);
1919 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
1920 intel_batchbuffer_emit_mi_flush(batch);
1921 gen75_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1922 gen75_mfd_surface_state(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1923 gen75_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1924 gen75_mfd_bsp_buf_base_addr_state(ctx, decode_state, MFX_FORMAT_VC1, gen7_mfd_context);
1925 gen75_mfd_vc1_pic_state(ctx, decode_state, gen7_mfd_context);
1926 gen75_mfd_vc1_pred_pipe_state(ctx, decode_state, gen7_mfd_context);
1927 gen75_mfd_vc1_directmode_state(ctx, decode_state, gen7_mfd_context);
1929 for (j = 0; j < decode_state->num_slice_params; j++) {
1930 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
1931 slice_param = (VASliceParameterBufferVC1 *)decode_state->slice_params[j]->buffer;
1932 slice_data_bo = decode_state->slice_datas[j]->bo;
1933 gen75_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_VC1, gen7_mfd_context);
1935 if (j == decode_state->num_slice_params - 1)
1936 next_slice_group_param = NULL;
1938 next_slice_group_param = (VASliceParameterBufferVC1 *)decode_state->slice_params[j + 1]->buffer;
1940 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
1941 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
1943 if (i < decode_state->slice_params[j]->num_elements - 1)
1944 next_slice_param = slice_param + 1;
1946 next_slice_param = next_slice_group_param;
1948 gen75_mfd_vc1_bsd_object(ctx, pic_param, slice_param, next_slice_param, slice_data_bo, gen7_mfd_context);
1953 intel_batchbuffer_end_atomic(batch);
1954 intel_batchbuffer_flush(batch);
1958 gen75_mfd_jpeg_decode_init(VADriverContextP ctx,
1959 struct decode_state *decode_state,
1960 struct gen7_mfd_context *gen7_mfd_context)
1962 struct i965_driver_data *i965 = i965_driver_data(ctx);
1963 struct object_surface *obj_surface;
1964 VAPictureParameterBufferJPEGBaseline *pic_param;
1965 int subsampling = SUBSAMPLE_YUV420;
1967 pic_param = (VAPictureParameterBufferJPEGBaseline *)decode_state->pic_param->buffer;
1969 if (pic_param->num_components == 1)
1970 subsampling = SUBSAMPLE_YUV400;
1971 else if (pic_param->num_components == 3) {
1972 int h1 = pic_param->components[0].h_sampling_factor;
1973 int h2 = pic_param->components[1].h_sampling_factor;
1974 int h3 = pic_param->components[2].h_sampling_factor;
1975 int v1 = pic_param->components[0].v_sampling_factor;
1976 int v2 = pic_param->components[1].v_sampling_factor;
1977 int v3 = pic_param->components[2].v_sampling_factor;
1979 if (h1 == 2 && h2 == 1 && h3 == 1 &&
1980 v1 == 2 && v2 == 1 && v3 == 1)
1981 subsampling = SUBSAMPLE_YUV420;
1982 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
1983 v1 == 1 && v2 == 1 && v3 == 1)
1984 subsampling = SUBSAMPLE_YUV422H;
1985 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
1986 v1 == 1 && v2 == 1 && v3 == 1)
1987 subsampling = SUBSAMPLE_YUV444;
1988 else if (h1 == 4 && h2 == 1 && h3 == 1 &&
1989 v1 == 1 && v2 == 1 && v3 == 1)
1990 subsampling = SUBSAMPLE_YUV411;
1991 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
1992 v1 == 2 && v2 == 1 && v3 == 1)
1993 subsampling = SUBSAMPLE_YUV422V;
1994 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
1995 v1 == 2 && v2 == 2 && v3 == 2)
1996 subsampling = SUBSAMPLE_YUV422H;
1997 else if (h2 == 2 && h2 == 2 && h3 == 2 &&
1998 v1 == 2 && v2 == 1 && v3 == 1)
1999 subsampling = SUBSAMPLE_YUV422V;
2006 /* Current decoded picture */
2007 obj_surface = SURFACE(decode_state->current_render_target);
2008 assert(obj_surface);
2009 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('I','M','C','1'), subsampling);
2011 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
2012 gen7_mfd_context->pre_deblocking_output.bo = obj_surface->bo;
2013 dri_bo_reference(gen7_mfd_context->pre_deblocking_output.bo);
2014 gen7_mfd_context->pre_deblocking_output.valid = 1;
2016 gen7_mfd_context->post_deblocking_output.bo = NULL;
2017 gen7_mfd_context->post_deblocking_output.valid = 0;
2019 gen7_mfd_context->intra_row_store_scratch_buffer.bo = NULL;
2020 gen7_mfd_context->intra_row_store_scratch_buffer.valid = 0;
2022 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = NULL;
2023 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.valid = 0;
2025 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = NULL;
2026 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.valid = 0;
2028 gen7_mfd_context->mpr_row_store_scratch_buffer.bo = NULL;
2029 gen7_mfd_context->mpr_row_store_scratch_buffer.valid = 0;
2031 gen7_mfd_context->bitplane_read_buffer.bo = NULL;
2032 gen7_mfd_context->bitplane_read_buffer.valid = 0;
2035 static const int va_to_gen7_jpeg_rotation[4] = {
2036 GEN7_JPEG_ROTATION_0,
2037 GEN7_JPEG_ROTATION_90,
2038 GEN7_JPEG_ROTATION_180,
2039 GEN7_JPEG_ROTATION_270
2043 gen75_mfd_jpeg_pic_state(VADriverContextP ctx,
2044 struct decode_state *decode_state,
2045 struct gen7_mfd_context *gen7_mfd_context)
2047 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2048 VAPictureParameterBufferJPEGBaseline *pic_param;
2049 int chroma_type = GEN7_YUV420;
2050 int frame_width_in_blks;
2051 int frame_height_in_blks;
2053 assert(decode_state->pic_param && decode_state->pic_param->buffer);
2054 pic_param = (VAPictureParameterBufferJPEGBaseline *)decode_state->pic_param->buffer;
2056 if (pic_param->num_components == 1)
2057 chroma_type = GEN7_YUV400;
2058 else if (pic_param->num_components == 3) {
2059 int h1 = pic_param->components[0].h_sampling_factor;
2060 int h2 = pic_param->components[1].h_sampling_factor;
2061 int h3 = pic_param->components[2].h_sampling_factor;
2062 int v1 = pic_param->components[0].v_sampling_factor;
2063 int v2 = pic_param->components[1].v_sampling_factor;
2064 int v3 = pic_param->components[2].v_sampling_factor;
2066 if (h1 == 2 && h2 == 1 && h3 == 1 &&
2067 v1 == 2 && v2 == 1 && v3 == 1)
2068 chroma_type = GEN7_YUV420;
2069 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
2070 v1 == 1 && v2 == 1 && v3 == 1)
2071 chroma_type = GEN7_YUV422H_2Y;
2072 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
2073 v1 == 1 && v2 == 1 && v3 == 1)
2074 chroma_type = GEN7_YUV444;
2075 else if (h1 == 4 && h2 == 1 && h3 == 1 &&
2076 v1 == 1 && v2 == 1 && v3 == 1)
2077 chroma_type = GEN7_YUV411;
2078 else if (h1 == 1 && h2 == 1 && h3 == 1 &&
2079 v1 == 2 && v2 == 1 && v3 == 1)
2080 chroma_type = GEN7_YUV422V_2Y;
2081 else if (h1 == 2 && h2 == 1 && h3 == 1 &&
2082 v1 == 2 && v2 == 2 && v3 == 2)
2083 chroma_type = GEN7_YUV422H_4Y;
2084 else if (h2 == 2 && h2 == 2 && h3 == 2 &&
2085 v1 == 2 && v2 == 1 && v3 == 1)
2086 chroma_type = GEN7_YUV422V_4Y;
2091 if (chroma_type == GEN7_YUV400 ||
2092 chroma_type == GEN7_YUV444 ||
2093 chroma_type == GEN7_YUV422V_2Y) {
2094 frame_width_in_blks = ((pic_param->picture_width + 7) / 8);
2095 frame_height_in_blks = ((pic_param->picture_height + 7) / 8);
2096 } else if (chroma_type == GEN7_YUV411) {
2097 frame_width_in_blks = ((pic_param->picture_width + 31) / 32) * 4;
2098 frame_height_in_blks = ((pic_param->picture_height + 31) / 32) * 4;
2100 frame_width_in_blks = ((pic_param->picture_width + 15) / 16) * 2;
2101 frame_height_in_blks = ((pic_param->picture_height + 15) / 16) * 2;
2104 BEGIN_BCS_BATCH(batch, 3);
2105 OUT_BCS_BATCH(batch, MFX_JPEG_PIC_STATE | (3 - 2));
2106 OUT_BCS_BATCH(batch,
2107 (va_to_gen7_jpeg_rotation[0] << 4) | /* without rotation */
2108 (chroma_type << 0));
2109 OUT_BCS_BATCH(batch,
2110 ((frame_height_in_blks - 1) << 16) | /* FrameHeightInBlks */
2111 ((frame_width_in_blks - 1) << 0)); /* FrameWidthInBlks */
2112 ADVANCE_BCS_BATCH(batch);
2115 static const int va_to_gen7_jpeg_hufftable[2] = {
2121 gen75_mfd_jpeg_huff_table_state(VADriverContextP ctx,
2122 struct decode_state *decode_state,
2123 struct gen7_mfd_context *gen7_mfd_context,
2126 VAHuffmanTableBufferJPEGBaseline *huffman_table;
2127 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2130 if (!decode_state->huffman_table || !decode_state->huffman_table->buffer)
2133 huffman_table = (VAHuffmanTableBufferJPEGBaseline *)decode_state->huffman_table->buffer;
2135 for (index = 0; index < num_tables; index++) {
2136 int id = va_to_gen7_jpeg_hufftable[index];
2137 if (!huffman_table->load_huffman_table[index])
2139 BEGIN_BCS_BATCH(batch, 53);
2140 OUT_BCS_BATCH(batch, MFX_JPEG_HUFF_TABLE_STATE | (53 - 2));
2141 OUT_BCS_BATCH(batch, id);
2142 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].num_dc_codes, 12);
2143 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].dc_values, 12);
2144 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].num_ac_codes, 16);
2145 intel_batchbuffer_data(batch, huffman_table->huffman_table[index].ac_values, 164);
2146 ADVANCE_BCS_BATCH(batch);
2150 static const int va_to_gen7_jpeg_qm[5] = {
2152 MFX_QM_JPEG_LUMA_Y_QUANTIZER_MATRIX,
2153 MFX_QM_JPEG_CHROMA_CB_QUANTIZER_MATRIX,
2154 MFX_QM_JPEG_CHROMA_CR_QUANTIZER_MATRIX,
2155 MFX_QM_JPEG_ALPHA_QUANTIZER_MATRIX
2159 gen75_mfd_jpeg_qm_state(VADriverContextP ctx,
2160 struct decode_state *decode_state,
2161 struct gen7_mfd_context *gen7_mfd_context)
2163 VAPictureParameterBufferJPEGBaseline *pic_param;
2164 VAIQMatrixBufferJPEGBaseline *iq_matrix;
2167 if (!decode_state->iq_matrix || !decode_state->iq_matrix->buffer)
2170 iq_matrix = (VAIQMatrixBufferJPEGBaseline *)decode_state->iq_matrix->buffer;
2171 pic_param = (VAPictureParameterBufferJPEGBaseline *)decode_state->pic_param->buffer;
2173 assert(pic_param->num_components <= 3);
2175 for (index = 0; index < pic_param->num_components; index++) {
2176 int qm_type = va_to_gen7_jpeg_qm[pic_param->components[index].component_id - pic_param->components[0].component_id + 1];
2177 unsigned char *qm = iq_matrix->quantiser_table[pic_param->components[index].quantiser_table_selector];
2178 unsigned char raster_qm[64];
2181 if (!iq_matrix->load_quantiser_table[pic_param->components[index].quantiser_table_selector])
2184 for (j = 0; j < 64; j++)
2185 raster_qm[zigzag_direct[j]] = qm[j];
2187 gen75_mfd_qm_state(ctx, qm_type, raster_qm, 64, gen7_mfd_context);
2192 gen75_mfd_jpeg_bsd_object(VADriverContextP ctx,
2193 VAPictureParameterBufferJPEGBaseline *pic_param,
2194 VASliceParameterBufferJPEGBaseline *slice_param,
2195 VASliceParameterBufferJPEGBaseline *next_slice_param,
2196 dri_bo *slice_data_bo,
2197 struct gen7_mfd_context *gen7_mfd_context)
2199 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2200 int scan_component_mask = 0;
2203 assert(slice_param->num_components > 0);
2204 assert(slice_param->num_components < 4);
2205 assert(slice_param->num_components <= pic_param->num_components);
2207 for (i = 0; i < slice_param->num_components; i++) {
2208 switch (slice_param->components[i].component_selector - pic_param->components[0].component_id + 1) {
2210 scan_component_mask |= (1 << 0);
2213 scan_component_mask |= (1 << 1);
2216 scan_component_mask |= (1 << 2);
2224 BEGIN_BCS_BATCH(batch, 6);
2225 OUT_BCS_BATCH(batch, MFD_JPEG_BSD_OBJECT | (6 - 2));
2226 OUT_BCS_BATCH(batch,
2227 slice_param->slice_data_size);
2228 OUT_BCS_BATCH(batch,
2229 slice_param->slice_data_offset);
2230 OUT_BCS_BATCH(batch,
2231 slice_param->slice_horizontal_position << 16 |
2232 slice_param->slice_vertical_position << 0);
2233 OUT_BCS_BATCH(batch,
2234 ((slice_param->num_components != 1) << 30) | /* interleaved */
2235 (scan_component_mask << 27) | /* scan components */
2236 (0 << 26) | /* disable interrupt allowed */
2237 (slice_param->num_mcus << 0)); /* MCU count */
2238 OUT_BCS_BATCH(batch,
2239 (slice_param->restart_interval << 0)); /* RestartInterval */
2240 ADVANCE_BCS_BATCH(batch);
2243 /* Workaround for JPEG decoding on Ivybridge */
2246 i965_DestroySurfaces(VADriverContextP ctx,
2247 VASurfaceID *surface_list,
2250 i965_CreateSurfaces(VADriverContextP ctx,
2255 VASurfaceID *surfaces);
2260 unsigned char data[32];
2262 int data_bit_offset;
2264 } gen7_jpeg_wa_clip = {
2268 0x65, 0xb8, 0x40, 0x32, 0x13, 0xfd, 0x06, 0x6c,
2269 0xfc, 0x0a, 0x50, 0x71, 0x5c, 0x00
2277 gen75_jpeg_wa_init(VADriverContextP ctx,
2278 struct gen7_mfd_context *gen7_mfd_context)
2280 struct i965_driver_data *i965 = i965_driver_data(ctx);
2282 struct object_surface *obj_surface;
2284 if (gen7_mfd_context->jpeg_wa_surface_id != VA_INVALID_SURFACE)
2285 i965_DestroySurfaces(ctx,
2286 &gen7_mfd_context->jpeg_wa_surface_id,
2289 status = i965_CreateSurfaces(ctx,
2290 gen7_jpeg_wa_clip.width,
2291 gen7_jpeg_wa_clip.height,
2292 VA_RT_FORMAT_YUV420,
2294 &gen7_mfd_context->jpeg_wa_surface_id);
2295 assert(status == VA_STATUS_SUCCESS);
2297 obj_surface = SURFACE(gen7_mfd_context->jpeg_wa_surface_id);
2298 assert(obj_surface);
2299 i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
2301 if (!gen7_mfd_context->jpeg_wa_slice_data_bo) {
2302 gen7_mfd_context->jpeg_wa_slice_data_bo = dri_bo_alloc(i965->intel.bufmgr,
2306 dri_bo_subdata(gen7_mfd_context->jpeg_wa_slice_data_bo,
2308 gen7_jpeg_wa_clip.data_size,
2309 gen7_jpeg_wa_clip.data);
2314 gen75_jpeg_wa_pipe_mode_select(VADriverContextP ctx,
2315 struct gen7_mfd_context *gen7_mfd_context)
2317 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2319 BEGIN_BCS_BATCH(batch, 5);
2320 OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
2321 OUT_BCS_BATCH(batch,
2322 (MFX_LONG_MODE << 17) | /* Currently only support long format */
2323 (MFD_MODE_VLD << 15) | /* VLD mode */
2324 (0 << 10) | /* disable Stream-Out */
2325 (0 << 9) | /* Post Deblocking Output */
2326 (1 << 8) | /* Pre Deblocking Output */
2327 (0 << 5) | /* not in stitch mode */
2328 (MFX_CODEC_DECODE << 4) | /* decoding mode */
2329 (MFX_FORMAT_AVC << 0));
2330 OUT_BCS_BATCH(batch,
2331 (0 << 4) | /* terminate if AVC motion and POC table error occurs */
2332 (0 << 3) | /* terminate if AVC mbdata error occurs */
2333 (0 << 2) | /* terminate if AVC CABAC/CAVLC decode error occurs */
2336 OUT_BCS_BATCH(batch, 0); /* pic status/error report id */
2337 OUT_BCS_BATCH(batch, 0); /* reserved */
2338 ADVANCE_BCS_BATCH(batch);
2342 gen75_jpeg_wa_surface_state(VADriverContextP ctx,
2343 struct gen7_mfd_context *gen7_mfd_context)
2345 struct i965_driver_data *i965 = i965_driver_data(ctx);
2346 struct object_surface *obj_surface = SURFACE(gen7_mfd_context->jpeg_wa_surface_id);
2347 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2349 BEGIN_BCS_BATCH(batch, 6);
2350 OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
2351 OUT_BCS_BATCH(batch, 0);
2352 OUT_BCS_BATCH(batch,
2353 ((obj_surface->orig_width - 1) << 18) |
2354 ((obj_surface->orig_height - 1) << 4));
2355 OUT_BCS_BATCH(batch,
2356 (MFX_SURFACE_PLANAR_420_8 << 28) | /* 420 planar YUV surface */
2357 (1 << 27) | /* interleave chroma, set to 0 for JPEG */
2358 (0 << 22) | /* surface object control state, ignored */
2359 ((obj_surface->width - 1) << 3) | /* pitch */
2360 (0 << 2) | /* must be 0 */
2361 (1 << 1) | /* must be tiled */
2362 (I965_TILEWALK_YMAJOR << 0)); /* tile walk, must be 1 */
2363 OUT_BCS_BATCH(batch,
2364 (0 << 16) | /* X offset for U(Cb), must be 0 */
2365 (obj_surface->y_cb_offset << 0)); /* Y offset for U(Cb) */
2366 OUT_BCS_BATCH(batch,
2367 (0 << 16) | /* X offset for V(Cr), must be 0 */
2368 (0 << 0)); /* Y offset for V(Cr), must be 0 for video codec, non-zoro for JPEG */
2369 ADVANCE_BCS_BATCH(batch);
2373 gen75_jpeg_wa_pipe_buf_addr_state(VADriverContextP ctx,
2374 struct gen7_mfd_context *gen7_mfd_context)
2376 struct i965_driver_data *i965 = i965_driver_data(ctx);
2377 struct object_surface *obj_surface = SURFACE(gen7_mfd_context->jpeg_wa_surface_id);
2378 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2382 intra_bo = dri_bo_alloc(i965->intel.bufmgr,
2387 BEGIN_BCS_BATCH(batch, 24);
2388 OUT_BCS_BATCH(batch, MFX_PIPE_BUF_ADDR_STATE | (24 - 2));
2389 OUT_BCS_RELOC(batch,
2391 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2394 OUT_BCS_BATCH(batch, 0); /* post deblocking */
2396 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
2397 OUT_BCS_BATCH(batch, 0); /* ignore for decoding */
2399 OUT_BCS_RELOC(batch,
2401 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2404 OUT_BCS_BATCH(batch, 0);
2407 for (i = 0; i < MAX_GEN_REFERENCE_FRAMES; i++) {
2408 OUT_BCS_BATCH(batch, 0);
2411 OUT_BCS_BATCH(batch, 0); /* ignore DW23 for decoding */
2412 ADVANCE_BCS_BATCH(batch);
2414 dri_bo_unreference(intra_bo);
2418 gen75_jpeg_wa_bsp_buf_base_addr_state(VADriverContextP ctx,
2419 struct gen7_mfd_context *gen7_mfd_context)
2421 struct i965_driver_data *i965 = i965_driver_data(ctx);
2422 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2423 dri_bo *bsd_mpc_bo, *mpr_bo;
2425 bsd_mpc_bo = dri_bo_alloc(i965->intel.bufmgr,
2426 "bsd mpc row store",
2427 11520, /* 1.5 * 120 * 64 */
2430 mpr_bo = dri_bo_alloc(i965->intel.bufmgr,
2432 7680, /* 1. 0 * 120 * 64 */
2435 BEGIN_BCS_BATCH(batch, 4);
2436 OUT_BCS_BATCH(batch, MFX_BSP_BUF_BASE_ADDR_STATE | (4 - 2));
2438 OUT_BCS_RELOC(batch,
2440 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2443 OUT_BCS_RELOC(batch,
2445 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,
2447 OUT_BCS_BATCH(batch, 0);
2449 ADVANCE_BCS_BATCH(batch);
2451 dri_bo_unreference(bsd_mpc_bo);
2452 dri_bo_unreference(mpr_bo);
2456 gen75_jpeg_wa_avc_qm_state(VADriverContextP ctx,
2457 struct gen7_mfd_context *gen7_mfd_context)
2463 gen75_jpeg_wa_avc_img_state(VADriverContextP ctx,
2464 struct gen7_mfd_context *gen7_mfd_context)
2466 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2468 int mbaff_frame_flag = 0;
2469 unsigned int width_in_mbs = 1, height_in_mbs = 1;
2471 BEGIN_BCS_BATCH(batch, 16);
2472 OUT_BCS_BATCH(batch, MFX_AVC_IMG_STATE | (16 - 2));
2473 OUT_BCS_BATCH(batch,
2474 width_in_mbs * height_in_mbs);
2475 OUT_BCS_BATCH(batch,
2476 ((height_in_mbs - 1) << 16) |
2477 ((width_in_mbs - 1) << 0));
2478 OUT_BCS_BATCH(batch,
2483 (0 << 12) | /* differ from GEN6 */
2486 OUT_BCS_BATCH(batch,
2487 (1 << 10) | /* 4:2:0 */
2488 (1 << 7) | /* CABAC */
2494 (mbaff_frame_flag << 1) |
2496 OUT_BCS_BATCH(batch, 0);
2497 OUT_BCS_BATCH(batch, 0);
2498 OUT_BCS_BATCH(batch, 0);
2499 OUT_BCS_BATCH(batch, 0);
2500 OUT_BCS_BATCH(batch, 0);
2501 OUT_BCS_BATCH(batch, 0);
2502 OUT_BCS_BATCH(batch, 0);
2503 OUT_BCS_BATCH(batch, 0);
2504 OUT_BCS_BATCH(batch, 0);
2505 OUT_BCS_BATCH(batch, 0);
2506 OUT_BCS_BATCH(batch, 0);
2507 ADVANCE_BCS_BATCH(batch);
2511 gen75_jpeg_wa_avc_directmode_state(VADriverContextP ctx,
2512 struct gen7_mfd_context *gen7_mfd_context)
2514 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2517 BEGIN_BCS_BATCH(batch, 69);
2518 OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
2520 /* reference surfaces 0..15 */
2521 for (i = 0; i < MAX_GEN_REFERENCE_FRAMES; i++) {
2522 OUT_BCS_BATCH(batch, 0); /* top */
2523 OUT_BCS_BATCH(batch, 0); /* bottom */
2526 /* the current decoding frame/field */
2527 OUT_BCS_BATCH(batch, 0); /* top */
2528 OUT_BCS_BATCH(batch, 0); /* bottom */
2531 for (i = 0; i < MAX_GEN_REFERENCE_FRAMES; i++) {
2532 OUT_BCS_BATCH(batch, 0);
2533 OUT_BCS_BATCH(batch, 0);
2536 OUT_BCS_BATCH(batch, 0);
2537 OUT_BCS_BATCH(batch, 0);
2539 ADVANCE_BCS_BATCH(batch);
2543 gen75_jpeg_wa_ind_obj_base_addr_state(VADriverContextP ctx,
2544 struct gen7_mfd_context *gen7_mfd_context)
2546 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2548 BEGIN_BCS_BATCH(batch, 11);
2549 OUT_BCS_BATCH(batch, MFX_IND_OBJ_BASE_ADDR_STATE | (11 - 2));
2550 OUT_BCS_RELOC(batch,
2551 gen7_mfd_context->jpeg_wa_slice_data_bo,
2552 I915_GEM_DOMAIN_INSTRUCTION, 0,
2554 OUT_BCS_BATCH(batch, 0x80000000); /* must set, up to 2G */
2555 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2556 OUT_BCS_BATCH(batch, 0);
2557 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2558 OUT_BCS_BATCH(batch, 0);
2559 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2560 OUT_BCS_BATCH(batch, 0);
2561 OUT_BCS_BATCH(batch, 0); /* ignore for VLD mode */
2562 OUT_BCS_BATCH(batch, 0);
2563 ADVANCE_BCS_BATCH(batch);
2567 gen75_jpeg_wa_avc_bsd_object(VADriverContextP ctx,
2568 struct gen7_mfd_context *gen7_mfd_context)
2570 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2572 /* the input bitsteam format on GEN7 differs from GEN6 */
2573 BEGIN_BCS_BATCH(batch, 6);
2574 OUT_BCS_BATCH(batch, MFD_AVC_BSD_OBJECT | (6 - 2));
2575 OUT_BCS_BATCH(batch, gen7_jpeg_wa_clip.data_size);
2576 OUT_BCS_BATCH(batch, 0);
2577 OUT_BCS_BATCH(batch,
2583 OUT_BCS_BATCH(batch,
2584 ((gen7_jpeg_wa_clip.data_bit_offset >> 3) << 16) |
2587 (1 << 3) | /* LastSlice Flag */
2588 (gen7_jpeg_wa_clip.data_bit_offset & 0x7));
2589 OUT_BCS_BATCH(batch, 0);
2590 ADVANCE_BCS_BATCH(batch);
2594 gen75_jpeg_wa_avc_slice_state(VADriverContextP ctx,
2595 struct gen7_mfd_context *gen7_mfd_context)
2597 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2598 int slice_hor_pos = 0, slice_ver_pos = 0, next_slice_hor_pos = 0, next_slice_ver_pos = 1;
2599 int num_ref_idx_l0 = 0, num_ref_idx_l1 = 0;
2600 int first_mb_in_slice = 0;
2601 int slice_type = SLICE_TYPE_I;
2603 BEGIN_BCS_BATCH(batch, 11);
2604 OUT_BCS_BATCH(batch, MFX_AVC_SLICE_STATE | (11 - 2));
2605 OUT_BCS_BATCH(batch, slice_type);
2606 OUT_BCS_BATCH(batch,
2607 (num_ref_idx_l1 << 24) |
2608 (num_ref_idx_l0 << 16) |
2611 OUT_BCS_BATCH(batch,
2613 (1 << 27) | /* disable Deblocking */
2615 (gen7_jpeg_wa_clip.qp << 16) |
2618 OUT_BCS_BATCH(batch,
2619 (slice_ver_pos << 24) |
2620 (slice_hor_pos << 16) |
2621 (first_mb_in_slice << 0));
2622 OUT_BCS_BATCH(batch,
2623 (next_slice_ver_pos << 16) |
2624 (next_slice_hor_pos << 0));
2625 OUT_BCS_BATCH(batch, (1 << 19)); /* last slice flag */
2626 OUT_BCS_BATCH(batch, 0);
2627 OUT_BCS_BATCH(batch, 0);
2628 OUT_BCS_BATCH(batch, 0);
2629 OUT_BCS_BATCH(batch, 0);
2630 ADVANCE_BCS_BATCH(batch);
2634 gen75_mfd_jpeg_wa(VADriverContextP ctx,
2635 struct gen7_mfd_context *gen7_mfd_context)
2637 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2638 gen75_jpeg_wa_init(ctx, gen7_mfd_context);
2639 intel_batchbuffer_emit_mi_flush(batch);
2640 gen75_jpeg_wa_pipe_mode_select(ctx, gen7_mfd_context);
2641 gen75_jpeg_wa_surface_state(ctx, gen7_mfd_context);
2642 gen75_jpeg_wa_pipe_buf_addr_state(ctx, gen7_mfd_context);
2643 gen75_jpeg_wa_bsp_buf_base_addr_state(ctx, gen7_mfd_context);
2644 gen75_jpeg_wa_avc_qm_state(ctx, gen7_mfd_context);
2645 gen75_jpeg_wa_avc_img_state(ctx, gen7_mfd_context);
2646 gen75_jpeg_wa_ind_obj_base_addr_state(ctx, gen7_mfd_context);
2648 gen75_jpeg_wa_avc_directmode_state(ctx, gen7_mfd_context);
2649 gen75_jpeg_wa_avc_slice_state(ctx, gen7_mfd_context);
2650 gen75_jpeg_wa_avc_bsd_object(ctx, gen7_mfd_context);
2654 gen75_mfd_jpeg_decode_picture(VADriverContextP ctx,
2655 struct decode_state *decode_state,
2656 struct gen7_mfd_context *gen7_mfd_context)
2658 struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
2659 VAPictureParameterBufferJPEGBaseline *pic_param;
2660 VASliceParameterBufferJPEGBaseline *slice_param, *next_slice_param, *next_slice_group_param;
2661 dri_bo *slice_data_bo;
2662 int i, j, max_selector = 0;
2664 assert(decode_state->pic_param && decode_state->pic_param->buffer);
2665 pic_param = (VAPictureParameterBufferJPEGBaseline *)decode_state->pic_param->buffer;
2667 /* Currently only support Baseline DCT */
2668 gen75_mfd_jpeg_decode_init(ctx, decode_state, gen7_mfd_context);
2669 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
2670 gen75_mfd_jpeg_wa(ctx, gen7_mfd_context);
2671 intel_batchbuffer_emit_mi_flush(batch);
2672 gen75_mfd_pipe_mode_select(ctx, decode_state, MFX_FORMAT_JPEG, gen7_mfd_context);
2673 gen75_mfd_surface_state(ctx, decode_state, MFX_FORMAT_JPEG, gen7_mfd_context);
2674 gen75_mfd_pipe_buf_addr_state(ctx, decode_state, MFX_FORMAT_JPEG, gen7_mfd_context);
2675 gen75_mfd_jpeg_pic_state(ctx, decode_state, gen7_mfd_context);
2676 gen75_mfd_jpeg_qm_state(ctx, decode_state, gen7_mfd_context);
2678 for (j = 0; j < decode_state->num_slice_params; j++) {
2679 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
2680 slice_param = (VASliceParameterBufferJPEGBaseline *)decode_state->slice_params[j]->buffer;
2681 slice_data_bo = decode_state->slice_datas[j]->bo;
2682 gen75_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_JPEG, gen7_mfd_context);
2684 if (j == decode_state->num_slice_params - 1)
2685 next_slice_group_param = NULL;
2687 next_slice_group_param = (VASliceParameterBufferJPEGBaseline *)decode_state->slice_params[j + 1]->buffer;
2689 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
2692 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
2694 if (i < decode_state->slice_params[j]->num_elements - 1)
2695 next_slice_param = slice_param + 1;
2697 next_slice_param = next_slice_group_param;
2699 for (component = 0; component < slice_param->num_components; component++) {
2700 if (max_selector < slice_param->components[component].dc_table_selector)
2701 max_selector = slice_param->components[component].dc_table_selector;
2703 if (max_selector < slice_param->components[component].ac_table_selector)
2704 max_selector = slice_param->components[component].ac_table_selector;
2711 assert(max_selector < 2);
2712 gen75_mfd_jpeg_huff_table_state(ctx, decode_state, gen7_mfd_context, max_selector + 1);
2714 for (j = 0; j < decode_state->num_slice_params; j++) {
2715 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
2716 slice_param = (VASliceParameterBufferJPEGBaseline *)decode_state->slice_params[j]->buffer;
2717 slice_data_bo = decode_state->slice_datas[j]->bo;
2718 gen75_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_JPEG, gen7_mfd_context);
2720 if (j == decode_state->num_slice_params - 1)
2721 next_slice_group_param = NULL;
2723 next_slice_group_param = (VASliceParameterBufferJPEGBaseline *)decode_state->slice_params[j + 1]->buffer;
2725 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
2726 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
2728 if (i < decode_state->slice_params[j]->num_elements - 1)
2729 next_slice_param = slice_param + 1;
2731 next_slice_param = next_slice_group_param;
2733 gen75_mfd_jpeg_bsd_object(ctx, pic_param, slice_param, next_slice_param, slice_data_bo, gen7_mfd_context);
2738 intel_batchbuffer_end_atomic(batch);
2739 intel_batchbuffer_flush(batch);
2743 gen75_mfd_decode_picture(VADriverContextP ctx,
2745 union codec_state *codec_state,
2746 struct hw_context *hw_context)
2749 struct gen7_mfd_context *gen7_mfd_context = (struct gen7_mfd_context *)hw_context;
2750 struct decode_state *decode_state = &codec_state->decode;
2752 assert(gen7_mfd_context);
2754 gen7_mfd_context->wa_mpeg2_slice_vertical_position = -1;
2757 case VAProfileMPEG2Simple:
2758 case VAProfileMPEG2Main:
2759 gen75_mfd_mpeg2_decode_picture(ctx, decode_state, gen7_mfd_context);
2762 case VAProfileH264Baseline:
2763 case VAProfileH264Main:
2764 case VAProfileH264High:
2765 gen75_mfd_avc_decode_picture(ctx, decode_state, gen7_mfd_context);
2768 case VAProfileVC1Simple:
2769 case VAProfileVC1Main:
2770 case VAProfileVC1Advanced:
2771 gen75_mfd_vc1_decode_picture(ctx, decode_state, gen7_mfd_context);
2774 case VAProfileJPEGBaseline:
2775 gen75_mfd_jpeg_decode_picture(ctx, decode_state, gen7_mfd_context);
2785 gen75_mfd_context_destroy(void *hw_context)
2787 struct gen7_mfd_context *gen7_mfd_context = (struct gen7_mfd_context *)hw_context;
2789 dri_bo_unreference(gen7_mfd_context->post_deblocking_output.bo);
2790 gen7_mfd_context->post_deblocking_output.bo = NULL;
2792 dri_bo_unreference(gen7_mfd_context->pre_deblocking_output.bo);
2793 gen7_mfd_context->pre_deblocking_output.bo = NULL;
2795 dri_bo_unreference(gen7_mfd_context->intra_row_store_scratch_buffer.bo);
2796 gen7_mfd_context->intra_row_store_scratch_buffer.bo = NULL;
2798 dri_bo_unreference(gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo);
2799 gen7_mfd_context->deblocking_filter_row_store_scratch_buffer.bo = NULL;
2801 dri_bo_unreference(gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo);
2802 gen7_mfd_context->bsd_mpc_row_store_scratch_buffer.bo = NULL;
2804 dri_bo_unreference(gen7_mfd_context->mpr_row_store_scratch_buffer.bo);
2805 gen7_mfd_context->mpr_row_store_scratch_buffer.bo = NULL;
2807 dri_bo_unreference(gen7_mfd_context->bitplane_read_buffer.bo);
2808 gen7_mfd_context->bitplane_read_buffer.bo = NULL;
2810 dri_bo_unreference(gen7_mfd_context->jpeg_wa_slice_data_bo);
2812 intel_batchbuffer_free(gen7_mfd_context->base.batch);
2813 free(gen7_mfd_context);
2816 static void gen75_mfd_mpeg2_context_init(VADriverContextP ctx,
2817 struct gen7_mfd_context *gen7_mfd_context)
2819 gen7_mfd_context->iq_matrix.mpeg2.load_intra_quantiser_matrix = -1;
2820 gen7_mfd_context->iq_matrix.mpeg2.load_non_intra_quantiser_matrix = -1;
2821 gen7_mfd_context->iq_matrix.mpeg2.load_chroma_intra_quantiser_matrix = -1;
2822 gen7_mfd_context->iq_matrix.mpeg2.load_chroma_non_intra_quantiser_matrix = -1;
2826 gen75_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
2828 struct intel_driver_data *intel = intel_driver_data(ctx);
2829 struct gen7_mfd_context *gen7_mfd_context = calloc(1, sizeof(struct gen7_mfd_context));
2832 gen7_mfd_context->base.destroy = gen75_mfd_context_destroy;
2833 gen7_mfd_context->base.run = gen75_mfd_decode_picture;
2834 gen7_mfd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER);
2836 for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
2837 gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
2838 gen7_mfd_context->reference_surface[i].frame_store_id = -1;
2841 gen7_mfd_context->jpeg_wa_surface_id = VA_INVALID_SURFACE;
2843 switch (obj_config->profile) {
2844 case VAProfileMPEG2Simple:
2845 case VAProfileMPEG2Main:
2846 gen75_mfd_mpeg2_context_init(ctx, gen7_mfd_context);
2849 case VAProfileH264Baseline:
2850 case VAProfileH264Main:
2851 case VAProfileH264High:
2852 gen75_mfd_avc_context_init(ctx, gen7_mfd_context);
2857 return (struct hw_context *)gen7_mfd_context;