2 * Copyright © 2009 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 * Zou Nan hai <nanhai.zou@intel.com>
34 #include <va/va_backend.h>
36 #include "intel_batchbuffer.h"
37 #include "intel_driver.h"
38 #include "i965_defines.h"
39 #include "i965_drv_video.h"
41 #include "i965_media.h"
42 #include "i965_media_mpeg2.h"
44 #define SURFACE_TARGET 0
45 #define SURFACE_FORWARD 1
46 #define SURFACE_BACKWARD 2
47 #define SURFACE_BIDIRECT 3
51 FRAME_FRAME_PRED_FORWARD,
52 FRAME_FRAME_PRED_BACKWARD,
53 FRAME_FRAME_PRED_BIDIRECT,
54 FRAME_FIELD_PRED_FORWARD,
55 FRAME_FIELD_PRED_BACKWARD,
56 FRAME_FIELD_PRED_BIDIRECT,
76 const uint32_t idct_table[] = {
77 C4, C1, C2, C3, C4, C5, C6, C7, //g5
78 C4, C1, C2, C3, C4, C5, C6, C7,
79 C4, C3, C6,-C7,-C4,-C1,-C2,-C5,
80 C4, C3, C6,-C7,-C4,-C1,-C2,-C5,
81 C4, C5,-C6,-C1,-C4, C7, C2, C3,
82 C4, C5,-C6,-C1,-C4, C7, C2, C3,
83 C4, C7,-C2,-C5, C4, C3,-C6,-C1,
84 C4, C7,-C2,-C5, C4, C3,-C6,-C1,
85 C4,-C7,-C2, C5, C4,-C3,-C6, C1,
86 C4,-C7,-C2, C5, C4,-C3,-C6, C1,
87 C4,-C5,-C6, C1,-C4,-C7, C2,-C3,
88 C4,-C5,-C6, C1,-C4,-C7, C2,-C3,
89 C4,-C3, C6, C7,-C4, C1,-C2, C5,
90 C4,-C3, C6, C7,-C4, C1,-C2, C5,
91 C4,-C1, C2,-C3, C4,-C5, C6,-C7,
92 C4,-C1, C2,-C3, C4,-C5, C6,-C7 //g20
103 const uint32_t zigzag_direct[64] = {
104 0, 1, 8, 16, 9, 2, 3, 10,
105 17, 24, 32, 25, 18, 11, 4, 5,
106 12, 19, 26, 33, 40, 48, 41, 34,
107 27, 20, 13, 6, 7, 14, 21, 28,
108 35, 42, 49, 56, 57, 50, 43, 36,
109 29, 22, 15, 23, 30, 37, 44, 51,
110 58, 59, 52, 45, 38, 31, 39, 46,
111 53, 60, 61, 54, 47, 55, 62, 63
114 static uint32_t frame_intra_kernel[][4] = {
115 #include "shaders/mpeg2/vld/frame_intra.g4b"
117 static uint32_t frame_frame_pred_forward_kernel[][4] = {
118 #include "shaders/mpeg2/vld/frame_frame_pred_forward.g4b"
120 static uint32_t frame_frame_pred_backward_kernel[][4] = {
121 #include "shaders/mpeg2/vld/frame_frame_pred_backward.g4b"
123 static uint32_t frame_frame_pred_bidirect_kernel[][4] = {
124 #include "shaders/mpeg2/vld/frame_frame_pred_bidirect.g4b"
126 static uint32_t frame_field_pred_forward_kernel[][4] = {
127 #include "shaders/mpeg2/vld/frame_field_pred_forward.g4b"
129 static uint32_t frame_field_pred_backward_kernel[][4] = {
130 #include "shaders/mpeg2/vld/frame_field_pred_backward.g4b"
132 static uint32_t frame_field_pred_bidirect_kernel[][4] = {
133 #include "shaders/mpeg2/vld/frame_field_pred_bidirect.g4b"
135 static uint32_t lib_kernel[][4] = {
136 #include "shaders/mpeg2/vld/lib.g4b"
139 static uint32_t field_intra_kernel[][4] = {
140 #include "shaders/mpeg2/vld/field_intra.g4b"
142 static uint32_t field_forward_kernel[][4] = {
143 #include "shaders/mpeg2/vld/field_forward.g4b"
145 static uint32_t field_forward_16x8_kernel[][4] = {
146 #include "shaders/mpeg2/vld/field_forward_16x8.g4b"
148 static uint32_t field_backward_kernel[][4] = {
149 #include "shaders/mpeg2/vld/field_backward.g4b"
151 static uint32_t field_backward_16x8_kernel[][4] = {
152 #include "shaders/mpeg2/vld/field_backward_16x8.g4b"
154 static uint32_t field_bidirect_kernel[][4] = {
155 #include "shaders/mpeg2/vld/field_bidirect.g4b"
157 static uint32_t field_bidirect_16x8_kernel[][4] = {
158 #include "shaders/mpeg2/vld/field_bidirect_16x8.g4b"
161 static struct media_kernel mpeg2_vld_kernels_gen4[] = {
166 sizeof(frame_intra_kernel),
171 "FRAME_FRAME_PRED_FORWARD",
172 FRAME_FRAME_PRED_FORWARD,
173 frame_frame_pred_forward_kernel,
174 sizeof(frame_frame_pred_forward_kernel),
179 "FRAME_FRAME_PRED_BACKWARD",
180 FRAME_FRAME_PRED_BACKWARD,
181 frame_frame_pred_backward_kernel,
182 sizeof(frame_frame_pred_backward_kernel),
187 "FRAME_FRAME_PRED_BIDIRECT",
188 FRAME_FRAME_PRED_BIDIRECT,
189 frame_frame_pred_bidirect_kernel,
190 sizeof(frame_frame_pred_bidirect_kernel),
195 "FRAME_FIELD_PRED_FORWARD",
196 FRAME_FIELD_PRED_FORWARD,
197 frame_field_pred_forward_kernel,
198 sizeof(frame_field_pred_forward_kernel),
203 "FRAME_FIELD_PRED_BACKWARD",
204 FRAME_FIELD_PRED_BACKWARD,
205 frame_field_pred_backward_kernel,
206 sizeof(frame_field_pred_backward_kernel),
211 "FRAME_FIELD_PRED_BIDIRECT",
212 FRAME_FIELD_PRED_BIDIRECT,
213 frame_field_pred_bidirect_kernel,
214 sizeof(frame_field_pred_bidirect_kernel),
230 sizeof(field_intra_kernel),
237 field_forward_kernel,
238 sizeof(field_forward_kernel),
243 "FIELD_FORWARD_16X8",
245 field_forward_16x8_kernel,
246 sizeof(field_forward_16x8_kernel),
253 field_backward_kernel,
254 sizeof(field_backward_kernel),
259 "FIELD_BACKWARD_16X8",
261 field_backward_16x8_kernel,
262 sizeof(field_backward_16x8_kernel),
269 field_bidirect_kernel,
270 sizeof(field_bidirect_kernel),
275 "FIELD_BIDIRECT_16X8",
277 field_bidirect_16x8_kernel,
278 sizeof(field_bidirect_16x8_kernel),
284 static uint32_t frame_intra_kernel_gen5[][4] = {
285 #include "shaders/mpeg2/vld/frame_intra.g4b.gen5"
287 static uint32_t frame_frame_pred_forward_kernel_gen5[][4] = {
288 #include "shaders/mpeg2/vld/frame_frame_pred_forward.g4b.gen5"
290 static uint32_t frame_frame_pred_backward_kernel_gen5[][4] = {
291 #include "shaders/mpeg2/vld/frame_frame_pred_backward.g4b.gen5"
293 static uint32_t frame_frame_pred_bidirect_kernel_gen5[][4] = {
294 #include "shaders/mpeg2/vld/frame_frame_pred_bidirect.g4b.gen5"
296 static uint32_t frame_field_pred_forward_kernel_gen5[][4] = {
297 #include "shaders/mpeg2/vld/frame_field_pred_forward.g4b.gen5"
299 static uint32_t frame_field_pred_backward_kernel_gen5[][4] = {
300 #include "shaders/mpeg2/vld/frame_field_pred_backward.g4b.gen5"
302 static uint32_t frame_field_pred_bidirect_kernel_gen5[][4] = {
303 #include "shaders/mpeg2/vld/frame_field_pred_bidirect.g4b.gen5"
305 static uint32_t lib_kernel_gen5[][4] = {
306 #include "shaders/mpeg2/vld/lib.g4b.gen5"
309 static uint32_t field_intra_kernel_gen5[][4] = {
310 #include "shaders/mpeg2/vld/field_intra.g4b.gen5"
312 static uint32_t field_forward_kernel_gen5[][4] = {
313 #include "shaders/mpeg2/vld/field_forward.g4b.gen5"
315 static uint32_t field_forward_16x8_kernel_gen5[][4] = {
316 #include "shaders/mpeg2/vld/field_forward_16x8.g4b.gen5"
318 static uint32_t field_backward_kernel_gen5[][4] = {
319 #include "shaders/mpeg2/vld/field_backward.g4b.gen5"
321 static uint32_t field_backward_16x8_kernel_gen5[][4] = {
322 #include "shaders/mpeg2/vld/field_backward_16x8.g4b.gen5"
324 static uint32_t field_bidirect_kernel_gen5[][4] = {
325 #include "shaders/mpeg2/vld/field_bidirect.g4b.gen5"
327 static uint32_t field_bidirect_16x8_kernel_gen5[][4] = {
328 #include "shaders/mpeg2/vld/field_bidirect_16x8.g4b.gen5"
331 static struct media_kernel mpeg2_vld_kernels_gen5[] = {
335 frame_intra_kernel_gen5,
336 sizeof(frame_intra_kernel_gen5),
341 "FRAME_FRAME_PRED_FORWARD",
342 FRAME_FRAME_PRED_FORWARD,
343 frame_frame_pred_forward_kernel_gen5,
344 sizeof(frame_frame_pred_forward_kernel_gen5),
349 "FRAME_FRAME_PRED_BACKWARD",
350 FRAME_FRAME_PRED_BACKWARD,
351 frame_frame_pred_backward_kernel_gen5,
352 sizeof(frame_frame_pred_backward_kernel_gen5),
357 "FRAME_FRAME_PRED_BIDIRECT",
358 FRAME_FRAME_PRED_BIDIRECT,
359 frame_frame_pred_bidirect_kernel_gen5,
360 sizeof(frame_frame_pred_bidirect_kernel_gen5),
365 "FRAME_FIELD_PRED_FORWARD",
366 FRAME_FIELD_PRED_FORWARD,
367 frame_field_pred_forward_kernel_gen5,
368 sizeof(frame_field_pred_forward_kernel_gen5),
373 "FRAME_FIELD_PRED_BACKWARD",
374 FRAME_FIELD_PRED_BACKWARD,
375 frame_field_pred_backward_kernel_gen5,
376 sizeof(frame_field_pred_backward_kernel_gen5),
381 "FRAME_FIELD_PRED_BIDIRECT",
382 FRAME_FIELD_PRED_BIDIRECT,
383 frame_field_pred_bidirect_kernel_gen5,
384 sizeof(frame_field_pred_bidirect_kernel_gen5),
392 sizeof(lib_kernel_gen5),
399 field_intra_kernel_gen5,
400 sizeof(field_intra_kernel_gen5),
407 field_forward_kernel_gen5,
408 sizeof(field_forward_kernel_gen5),
413 "FIELD_FORWARD_16X8",
415 field_forward_16x8_kernel_gen5,
416 sizeof(field_forward_16x8_kernel_gen5),
423 field_backward_kernel_gen5,
424 sizeof(field_backward_kernel_gen5),
429 "FIELD_BACKWARD_16X8",
431 field_backward_16x8_kernel_gen5,
432 sizeof(field_backward_16x8_kernel_gen5),
439 field_bidirect_kernel_gen5,
440 sizeof(field_bidirect_kernel_gen5),
445 "FIELD_BIDIRECT_16X8",
447 field_bidirect_16x8_kernel_gen5,
448 sizeof(field_bidirect_16x8_kernel_gen5),
453 static struct media_kernel *mpeg2_vld_kernels = NULL;
455 #define NUM_MPEG2_VLD_KERNELS (sizeof(mpeg2_vld_kernels_gen4)/sizeof(mpeg2_vld_kernels_gen4[0]))
458 i965_media_mpeg2_surface_state(VADriverContextP ctx,
460 struct object_surface *obj_surface,
461 unsigned long offset,
464 int vert_line_stride,
465 int vert_line_stride_ofs,
466 struct i965_media_context *media_context)
468 struct i965_driver_data *i965 = i965_driver_data(ctx);
469 struct i965_surface_state *ss;
471 uint32_t write_domain, read_domain;
473 bo = dri_bo_alloc(i965->intel.bufmgr,
475 sizeof(struct i965_surface_state), 32);
480 memset(ss, 0, sizeof(*ss));
481 ss->ss0.surface_type = I965_SURFACE_2D;
482 ss->ss0.surface_format = I965_SURFACEFORMAT_R8_SINT;
483 ss->ss0.vert_line_stride = vert_line_stride;
484 ss->ss0.vert_line_stride_ofs = vert_line_stride_ofs;
485 ss->ss1.base_addr = obj_surface->bo->offset + offset;
486 ss->ss2.width = w - 1;
487 ss->ss2.height = h - 1;
488 ss->ss3.pitch = w - 1;
491 write_domain = I915_GEM_DOMAIN_RENDER;
492 read_domain = I915_GEM_DOMAIN_RENDER;
495 read_domain = I915_GEM_DOMAIN_SAMPLER;
498 dri_bo_emit_reloc(bo,
499 read_domain, write_domain,
501 offsetof(struct i965_surface_state, ss1),
505 assert(index < MAX_MEDIA_SURFACES);
506 // assert(media_context->surface_state[index].bo == NULL);
507 media_context->surface_state[index].bo = bo;
511 i965_media_mpeg2_surface_setup(VADriverContextP ctx,
513 struct object_surface *obj_surface,
515 int picture_structure,
517 struct i965_media_context *media_context)
519 int w = obj_surface->width;
520 int h = obj_surface->height;
522 if (obj_surface->bo == NULL) {
523 struct i965_driver_data *i965 = i965_driver_data(ctx);
525 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
531 if (picture_structure == MPEG_FRAME) {
532 i965_media_mpeg2_surface_state(ctx, base_index + 0, obj_surface,
536 i965_media_mpeg2_surface_state(ctx, base_index + 1, obj_surface,
540 i965_media_mpeg2_surface_state(ctx, base_index + 2, obj_surface,
541 w * h + w * h / 4, w / 2, h / 2,
545 if (surface == SURFACE_TARGET) {
546 i965_media_mpeg2_surface_state(ctx, 3, obj_surface,
550 i965_media_mpeg2_surface_state(ctx, 10, obj_surface,
554 i965_media_mpeg2_surface_state(ctx, 11, obj_surface,
555 w * h + w * h / 4, w / 2, h / 2,
558 if (picture_structure == MPEG_TOP_FIELD) {
559 i965_media_mpeg2_surface_state(ctx, base_index + 0, obj_surface,
563 i965_media_mpeg2_surface_state(ctx, base_index + 1, obj_surface,
567 i965_media_mpeg2_surface_state(ctx, base_index + 2, obj_surface,
568 w * h + w * h / 4, w / 2, h / 2,
572 assert(picture_structure == MPEG_BOTTOM_FIELD);
573 i965_media_mpeg2_surface_state(ctx, base_index + 0, obj_surface,
577 i965_media_mpeg2_surface_state(ctx, base_index + 1, obj_surface,
581 i965_media_mpeg2_surface_state(ctx, base_index + 2, obj_surface,
582 w * h + w * h / 4, w / 2, h / 2,
587 i965_media_mpeg2_surface_state(ctx, base_index + 0, obj_surface,
591 i965_media_mpeg2_surface_state(ctx, base_index + 1, obj_surface,
595 i965_media_mpeg2_surface_state(ctx, base_index + 2, obj_surface,
596 w * h + w * h / 4, w / 2, h / 2,
604 i965_media_mpeg2_surfaces_setup(VADriverContextP ctx,
605 struct decode_state *decode_state,
606 struct i965_media_context *media_context)
608 struct i965_driver_data *i965 = i965_driver_data(ctx);
609 struct object_surface *obj_surface;
610 VAPictureParameterBufferMPEG2 *param;
612 assert(decode_state->pic_param && decode_state->pic_param->buffer);
613 param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
615 obj_surface = SURFACE(decode_state->current_render_target);
617 i965_media_mpeg2_surface_setup(ctx, 0, obj_surface, True,
618 param->picture_coding_extension.bits.picture_structure,
622 obj_surface = SURFACE(param->forward_reference_picture);
624 // assert(param->picture_coding_type == 1); /* I-picture */
626 i965_media_mpeg2_surface_setup(ctx, 4, obj_surface, False,
627 param->picture_coding_extension.bits.picture_structure,
630 obj_surface = SURFACE(param->backward_reference_picture);
632 assert(param->picture_coding_type == 2); /* P-picture */
634 obj_surface = SURFACE(param->forward_reference_picture);
635 i965_media_mpeg2_surface_setup(ctx, 7, obj_surface, False,
636 param->picture_coding_extension.bits.picture_structure,
640 assert(param->picture_coding_type == 3); /* B-picture */
641 i965_media_mpeg2_surface_setup(ctx, 7, obj_surface, False,
642 param->picture_coding_extension.bits.picture_structure,
650 i965_media_mpeg2_binding_table(VADriverContextP ctx, struct i965_media_context *media_context)
653 unsigned int *binding_table;
654 dri_bo *bo = media_context->binding_table.bo;
658 binding_table = bo->virtual;
659 memset(binding_table, 0, bo->size);
661 for (i = 0; i < MAX_MEDIA_SURFACES; i++) {
662 if (media_context->surface_state[i].bo) {
663 binding_table[i] = media_context->surface_state[i].bo->offset;
664 dri_bo_emit_reloc(bo,
665 I915_GEM_DOMAIN_INSTRUCTION, 0,
667 i * sizeof(*binding_table),
668 media_context->surface_state[i].bo);
672 dri_bo_unmap(media_context->binding_table.bo);
676 i965_media_mpeg2_vfe_state(VADriverContextP ctx, struct i965_media_context *media_context)
678 struct i965_vfe_state *vfe_state;
681 bo = media_context->vfe_state.bo;
684 vfe_state = bo->virtual;
685 memset(vfe_state, 0, sizeof(*vfe_state));
686 vfe_state->vfe0.extend_vfe_state_present = 1;
687 vfe_state->vfe1.vfe_mode = VFE_VLD_MODE;
688 vfe_state->vfe1.num_urb_entries = media_context->urb.num_vfe_entries;
689 vfe_state->vfe1.children_present = 0;
690 vfe_state->vfe1.urb_entry_alloc_size = media_context->urb.size_vfe_entry - 1;
691 vfe_state->vfe1.max_threads = media_context->urb.num_vfe_entries - 1;
692 vfe_state->vfe2.interface_descriptor_base =
693 media_context->idrt.bo->offset >> 4; /* reloc */
694 dri_bo_emit_reloc(bo,
695 I915_GEM_DOMAIN_INSTRUCTION, 0,
697 offsetof(struct i965_vfe_state, vfe2),
698 media_context->idrt.bo);
703 i965_media_mpeg2_interface_descriptor_remap_table(VADriverContextP ctx, struct i965_media_context *media_context)
705 struct i965_interface_descriptor *desc;
709 bo = media_context->idrt.bo;
714 for (i = 0; i < NUM_MPEG2_VLD_KERNELS; i++) {
715 memset(desc, 0, sizeof(*desc));
716 desc->desc0.grf_reg_blocks = 15;
717 desc->desc0.kernel_start_pointer = mpeg2_vld_kernels[i].bo->offset >> 6; /* reloc */
718 desc->desc1.const_urb_entry_read_offset = 0;
719 desc->desc1.const_urb_entry_read_len = 30;
720 desc->desc3.binding_table_entry_count = 0;
721 desc->desc3.binding_table_pointer =
722 media_context->binding_table.bo->offset >> 5; /*reloc */
724 dri_bo_emit_reloc(bo,
725 I915_GEM_DOMAIN_INSTRUCTION, 0,
726 desc->desc0.grf_reg_blocks,
727 i * sizeof(*desc) + offsetof(struct i965_interface_descriptor, desc0),
728 mpeg2_vld_kernels[i].bo);
730 dri_bo_emit_reloc(bo,
731 I915_GEM_DOMAIN_INSTRUCTION, 0,
732 desc->desc3.binding_table_entry_count,
733 i * sizeof(*desc) + offsetof(struct i965_interface_descriptor, desc3),
734 media_context->binding_table.bo);
742 i965_media_mpeg2_vld_state(VADriverContextP ctx,
743 struct decode_state *decode_state,
744 struct i965_media_context *media_context)
746 struct i965_vld_state *vld_state;
747 VAPictureParameterBufferMPEG2 *param;
749 assert(decode_state->pic_param && decode_state->pic_param->buffer);
750 param = (VAPictureParameterBufferMPEG2 *)decode_state->pic_param->buffer;
752 assert(media_context->extended_state.bo);
753 dri_bo_map(media_context->extended_state.bo, 1);
754 assert(media_context->extended_state.bo->virtual);
755 vld_state = media_context->extended_state.bo->virtual;
756 memset(vld_state, 0, sizeof(*vld_state));
758 vld_state->vld0.f_code_0_0 = ((param->f_code >> 12) & 0xf);
759 vld_state->vld0.f_code_0_1 = ((param->f_code >> 8) & 0xf);
760 vld_state->vld0.f_code_1_0 = ((param->f_code >> 4) & 0xf);
761 vld_state->vld0.f_code_1_1 = (param->f_code & 0xf);
762 vld_state->vld0.intra_dc_precision = param->picture_coding_extension.bits.intra_dc_precision;
763 vld_state->vld0.picture_structure = param->picture_coding_extension.bits.picture_structure;
764 vld_state->vld0.top_field_first = param->picture_coding_extension.bits.top_field_first;
765 vld_state->vld0.frame_predict_frame_dct = param->picture_coding_extension.bits.frame_pred_frame_dct;
766 vld_state->vld0.concealment_motion_vector = param->picture_coding_extension.bits.concealment_motion_vectors;
767 vld_state->vld0.quantizer_scale_type = param->picture_coding_extension.bits.q_scale_type;
768 vld_state->vld0.intra_vlc_format = param->picture_coding_extension.bits.intra_vlc_format;
769 vld_state->vld0.scan_order = param->picture_coding_extension.bits.alternate_scan;
771 vld_state->vld1.picture_coding_type = param->picture_coding_type;
773 if (vld_state->vld0.picture_structure == MPEG_FRAME) {
775 vld_state->desc_remap_table0.index_0 = FRAME_INTRA;
776 vld_state->desc_remap_table0.index_1 = FRAME_FRAME_PRED_FORWARD;
777 vld_state->desc_remap_table0.index_2 = FRAME_FIELD_PRED_FORWARD;
778 vld_state->desc_remap_table0.index_3 = FRAME_FIELD_PRED_BIDIRECT; /* dual prime */
779 vld_state->desc_remap_table0.index_4 = FRAME_FRAME_PRED_BACKWARD;
780 vld_state->desc_remap_table0.index_5 = FRAME_FIELD_PRED_BACKWARD;
781 vld_state->desc_remap_table0.index_6 = FRAME_FRAME_PRED_BIDIRECT;
782 vld_state->desc_remap_table0.index_7 = FRAME_FIELD_PRED_BIDIRECT;
784 vld_state->desc_remap_table1.index_8 = FRAME_INTRA;
785 vld_state->desc_remap_table1.index_9 = FRAME_FRAME_PRED_FORWARD;
786 vld_state->desc_remap_table1.index_10 = FRAME_FIELD_PRED_FORWARD;
787 vld_state->desc_remap_table1.index_11 = FRAME_FIELD_PRED_BIDIRECT;
788 vld_state->desc_remap_table1.index_12 = FRAME_FRAME_PRED_BACKWARD;
789 vld_state->desc_remap_table1.index_13 = FRAME_FIELD_PRED_BACKWARD;
790 vld_state->desc_remap_table1.index_14 = FRAME_FRAME_PRED_BIDIRECT;
791 vld_state->desc_remap_table1.index_15 = FRAME_FIELD_PRED_BIDIRECT;
794 vld_state->desc_remap_table0.index_0 = FIELD_INTRA;
795 vld_state->desc_remap_table0.index_1 = FIELD_FORWARD;
796 vld_state->desc_remap_table0.index_2 = FIELD_FORWARD_16X8;
797 vld_state->desc_remap_table0.index_3 = FIELD_BIDIRECT; /* dual prime */
798 vld_state->desc_remap_table0.index_4 = FIELD_BACKWARD;
799 vld_state->desc_remap_table0.index_5 = FIELD_BACKWARD_16X8;
800 vld_state->desc_remap_table0.index_6 = FIELD_BIDIRECT;
801 vld_state->desc_remap_table0.index_7 = FIELD_BIDIRECT_16X8;
804 dri_bo_unmap(media_context->extended_state.bo);
808 i965_media_mpeg2_upload_constants(VADriverContextP ctx,
809 struct decode_state *decode_state,
810 struct i965_media_context *media_context)
813 unsigned char *constant_buffer;
815 unsigned int *lib_reloc;
816 int lib_reloc_offset = 0;
818 dri_bo_map(media_context->curbe.bo, 1);
819 assert(media_context->curbe.bo->virtual);
820 constant_buffer = media_context->curbe.bo->virtual;
823 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer) {
824 VAIQMatrixBufferMPEG2 *iq_matrix = (VAIQMatrixBufferMPEG2 *)decode_state->iq_matrix->buffer;
826 /* Upload quantisation matrix in row-major order. The mplayer vaapi
827 * patch passes quantisation matrix in zig-zag order to va library.
828 * Do we need a flag in VAIQMatrixBufferMPEG2 to specify the order
829 * of the quantisation matrix?
831 qmx = constant_buffer;
832 if (iq_matrix->load_intra_quantiser_matrix) {
833 for (i = 0; i < 64; i++) {
834 j = zigzag_direct[i];
835 qmx[j] = iq_matrix->intra_quantiser_matrix[i];
839 qmx = constant_buffer + 64;
840 if (iq_matrix->load_non_intra_quantiser_matrix) {
841 for (i = 0; i < 64; i++) {
842 j = zigzag_direct[i];
843 qmx[j] = iq_matrix->non_intra_quantiser_matrix[i];
847 /* no chroma quantisation matrices for 4:2:0 data */
851 memcpy(constant_buffer + 128, idct_table, sizeof(idct_table));
854 lib_reloc_offset = 128 + sizeof(idct_table);
855 lib_reloc = (unsigned int *)(constant_buffer + lib_reloc_offset);
856 for (i = 0; i < 8; i++) {
857 lib_reloc[i] = mpeg2_vld_kernels[LIB_INTERFACE].bo->offset;
858 dri_bo_emit_reloc(media_context->curbe.bo,
859 I915_GEM_DOMAIN_INSTRUCTION, 0,
861 lib_reloc_offset + i * sizeof(unsigned int),
862 mpeg2_vld_kernels[LIB_INTERFACE].bo);
865 dri_bo_unmap(media_context->curbe.bo);
869 i965_media_mpeg2_states_setup(VADriverContextP ctx,
870 struct decode_state *decode_state,
871 struct i965_media_context *media_context)
873 i965_media_mpeg2_surfaces_setup(ctx, decode_state, media_context);
874 i965_media_mpeg2_binding_table(ctx, media_context);
875 i965_media_mpeg2_interface_descriptor_remap_table(ctx, media_context);
876 i965_media_mpeg2_vld_state(ctx, decode_state, media_context);
877 i965_media_mpeg2_vfe_state(ctx, media_context);
878 i965_media_mpeg2_upload_constants(ctx, decode_state, media_context);
882 i965_media_mpeg2_objects(VADriverContextP ctx,
883 struct decode_state *decode_state,
884 struct i965_media_context *media_context)
887 VASliceParameterBufferMPEG2 *slice_param;
889 for (j = 0; j < decode_state->num_slice_params; j++) {
890 assert(decode_state->slice_params[j] && decode_state->slice_params[j]->buffer);
891 assert(decode_state->slice_datas[j] && decode_state->slice_datas[j]->bo);
892 slice_param = (VASliceParameterBufferMPEG2 *)decode_state->slice_params[j]->buffer;
894 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
895 assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
898 OUT_BATCH(ctx, CMD_MEDIA_OBJECT | 4);
900 OUT_BATCH(ctx, slice_param->slice_data_size - (slice_param->macroblock_offset >> 3));
901 OUT_RELOC(ctx, decode_state->slice_datas[j]->bo,
902 I915_GEM_DOMAIN_SAMPLER, 0,
903 slice_param->slice_data_offset + (slice_param->macroblock_offset >> 3));
905 ((slice_param->slice_horizontal_position << 24) |
906 (slice_param->slice_vertical_position << 16) |
908 (slice_param->macroblock_offset & 0x7)));
909 OUT_BATCH(ctx, slice_param->quantiser_scale_code << 24);
917 i965_media_mpeg2_free_private_context(void **data)
921 for (i = 0; i < NUM_MPEG2_VLD_KERNELS; i++) {
922 struct media_kernel *kernel = &mpeg2_vld_kernels[i];
924 dri_bo_unreference(kernel->bo);
928 mpeg2_vld_kernels = NULL;
932 i965_media_mpeg2_decode_init(VADriverContextP ctx,
933 struct decode_state *decode_state,
934 struct i965_media_context *media_context)
936 struct i965_driver_data *i965 = i965_driver_data(ctx);
939 dri_bo_unreference(media_context->indirect_object.bo);
940 media_context->indirect_object.bo = NULL;
942 media_context->extended_state.enabled = 1;
943 dri_bo_unreference(media_context->extended_state.bo);
944 bo = dri_bo_alloc(i965->intel.bufmgr,
946 sizeof(struct i965_vld_state), 32);
948 media_context->extended_state.bo = bo;
952 i965_media_mpeg2_dec_context_init(VADriverContextP ctx, struct i965_media_context *media_context)
954 struct i965_driver_data *i965 = i965_driver_data(ctx);
958 if (mpeg2_vld_kernels == NULL) {
959 assert(NUM_MPEG2_VLD_KERNELS == (sizeof(mpeg2_vld_kernels_gen5) /
960 sizeof(mpeg2_vld_kernels_gen5[0])));
961 assert(NUM_MPEG2_VLD_KERNELS <= MAX_INTERFACE_DESC);
963 if (IS_IRONLAKE(i965->intel.device_id))
964 mpeg2_vld_kernels = mpeg2_vld_kernels_gen5;
966 mpeg2_vld_kernels = mpeg2_vld_kernels_gen4;
968 for (i = 0; i < NUM_MPEG2_VLD_KERNELS; i++) {
969 struct media_kernel *kernel = &mpeg2_vld_kernels[i];
970 kernel->bo = dri_bo_alloc(i965->intel.bufmgr,
974 dri_bo_subdata(kernel->bo, 0, kernel->size, kernel->bin);
979 media_context->urb.num_vfe_entries = 28;
980 media_context->urb.size_vfe_entry = 13;
982 media_context->urb.num_cs_entries = 1;
983 media_context->urb.size_cs_entry = 16;
985 media_context->urb.vfe_start = 0;
986 media_context->urb.cs_start = media_context->urb.vfe_start +
987 media_context->urb.num_vfe_entries * media_context->urb.size_vfe_entry;
988 assert(media_context->urb.cs_start +
989 media_context->urb.num_cs_entries * media_context->urb.size_cs_entry <= URB_SIZE((&i965->intel)));
992 media_context->media_states_setup = i965_media_mpeg2_states_setup;
993 media_context->media_objects = i965_media_mpeg2_objects;
994 media_context->private_context = i965_mpeg2_context;
995 media_context->free_private_context = i965_media_mpeg2_free_private_context;