2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
34 #include "intel_batchbuffer.h"
35 #include "intel_driver.h"
37 #include "i965_defines.h"
38 #include "i965_drv_video.h"
39 #include "i965_avc_ildb.h"
40 #include "i965_media_h264.h"
41 #include "i965_media.h"
44 #include "shaders/h264/mc/export.inc"
47 #include "shaders/h264/mc/export.inc.gen5"
49 #define PICTURE_FRAME 0
50 #define PICTURE_FIELD 1
51 #define PICTURE_MBAFF 2
54 AVC_ILDB_ROOT_Y_ILDB_FRAME,
55 AVC_ILDB_CHILD_Y_ILDB_FRAME,
56 AVC_ILDB_ROOT_UV_ILDB_FRAME,
57 AVC_ILDB_CHILD_UV_ILDB_FRAME,
58 AVC_ILDB_ROOT_Y_ILDB_FIELD,
59 AVC_ILDB_CHILD_Y_ILDB_FIELD,
60 AVC_ILDB_ROOT_UV_ILDB_FIELD,
61 AVC_ILDB_CHILD_UV_ILDB_FIELD,
62 AVC_ILDB_ROOT_Y_ILDB_MBAFF,
63 AVC_ILDB_CHILD_Y_ILDB_MBAFF,
64 AVC_ILDB_ROOT_UV_ILDB_MBAFF,
65 AVC_ILDB_CHILD_UV_ILDB_MBAFF
68 static unsigned long avc_ildb_kernel_offset_gen4[] = {
69 AVC_ILDB_ROOT_Y_ILDB_FRAME_IP * INST_UNIT_GEN4,
70 AVC_ILDB_CHILD_Y_ILDB_FRAME_IP * INST_UNIT_GEN4,
71 AVC_ILDB_ROOT_UV_ILDB_FRAME_IP * INST_UNIT_GEN4,
72 AVC_ILDB_CHILD_UV_ILDB_FRAME_IP * INST_UNIT_GEN4,
73 AVC_ILDB_ROOT_Y_ILDB_FIELD_IP * INST_UNIT_GEN4,
74 AVC_ILDB_CHILD_Y_ILDB_FIELD_IP * INST_UNIT_GEN4,
75 AVC_ILDB_ROOT_UV_ILDB_FIELD_IP * INST_UNIT_GEN4,
76 AVC_ILDB_CHILD_UV_ILDB_FIELD_IP * INST_UNIT_GEN4,
77 AVC_ILDB_ROOT_Y_ILDB_MBAFF_IP * INST_UNIT_GEN4,
78 AVC_ILDB_CHILD_Y_ILDB_MBAFF_IP * INST_UNIT_GEN4,
79 AVC_ILDB_ROOT_UV_ILDB_MBAFF_IP * INST_UNIT_GEN4,
80 AVC_ILDB_CHILD_UV_ILDB_MBAFF_IP * INST_UNIT_GEN4
83 static unsigned long avc_ildb_kernel_offset_gen5[] = {
84 AVC_ILDB_ROOT_Y_ILDB_FRAME_IP_GEN5 * INST_UNIT_GEN5,
85 AVC_ILDB_CHILD_Y_ILDB_FRAME_IP_GEN5 * INST_UNIT_GEN5,
86 AVC_ILDB_ROOT_UV_ILDB_FRAME_IP_GEN5 * INST_UNIT_GEN5,
87 AVC_ILDB_CHILD_UV_ILDB_FRAME_IP_GEN5 * INST_UNIT_GEN5,
88 AVC_ILDB_ROOT_Y_ILDB_FIELD_IP_GEN5 * INST_UNIT_GEN5,
89 AVC_ILDB_CHILD_Y_ILDB_FIELD_IP_GEN5 * INST_UNIT_GEN5,
90 AVC_ILDB_ROOT_UV_ILDB_FIELD_IP_GEN5 * INST_UNIT_GEN5,
91 AVC_ILDB_CHILD_UV_ILDB_FIELD_IP_GEN5 * INST_UNIT_GEN5,
92 AVC_ILDB_ROOT_Y_ILDB_MBAFF_IP_GEN5 * INST_UNIT_GEN5,
93 AVC_ILDB_CHILD_Y_ILDB_MBAFF_IP_GEN5 * INST_UNIT_GEN5,
94 AVC_ILDB_ROOT_UV_ILDB_MBAFF_IP_GEN5 * INST_UNIT_GEN5,
95 AVC_ILDB_CHILD_UV_ILDB_MBAFF_IP_GEN5 * INST_UNIT_GEN5
98 struct avc_ildb_root_input {
99 unsigned int blocks_per_row : 16;
100 unsigned int blocks_per_column : 16;
102 unsigned int picture_type : 16;
103 unsigned int max_concurrent_threads : 16;
105 unsigned int debug_field : 16;
106 unsigned int mbaff_frame_flag : 1;
107 unsigned int bottom_field_flag : 1;
108 unsigned int control_data_expansion_flag : 1;
109 unsigned int chroma_format : 1;
110 unsigned int pad0 : 12;
112 unsigned int ramp_constant_0;
114 unsigned int ramp_constant_1;
124 #define NUM_AVC_ILDB_INTERFACES ARRAY_ELEMS(avc_ildb_kernel_offset_gen4)
125 static unsigned long *avc_ildb_kernel_offset = NULL;
128 i965_avc_ildb_surface_state(VADriverContextP ctx,
129 struct decode_state *decode_state,
130 struct i965_h264_context *i965_h264_context)
132 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
133 struct i965_surface_state *ss;
134 struct object_surface *obj_surface;
135 VAPictureParameterBufferH264 *pic_param;
136 VAPictureH264 *va_pic;
140 assert(decode_state->pic_param && decode_state->pic_param->buffer);
141 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
142 va_pic = &pic_param->CurrPic;
143 obj_surface = decode_state->render_object;
145 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].s_bo = i965_h264_context->avc_ildb_data.bo;
146 dri_bo_reference(avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].s_bo);
147 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].offset = 0;
148 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].surface_type = I965_SURFACE_BUFFER;
149 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].width = ((avc_ildb_context->mbs_per_picture * EDGE_CONTROL_DATA_IN_DWS - 1) & 0x7f);
150 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].height = (((avc_ildb_context->mbs_per_picture * EDGE_CONTROL_DATA_IN_DWS - 1) >> 7) & 0x1fff);
151 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].depth = (((avc_ildb_context->mbs_per_picture * EDGE_CONTROL_DATA_IN_DWS - 1) >> 20) & 0x7f);
152 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].pitch = EDGE_CONTROL_DATA_IN_BTYES - 1;
153 avc_ildb_context->surface[SURFACE_EDGE_CONTROL_DATA].is_target = 0;
155 avc_ildb_context->surface[SURFACE_SRC_Y].s_bo = obj_surface->bo;
156 dri_bo_reference(avc_ildb_context->surface[SURFACE_SRC_Y].s_bo);
157 avc_ildb_context->surface[SURFACE_SRC_Y].offset = 0;
158 avc_ildb_context->surface[SURFACE_SRC_Y].surface_type = I965_SURFACE_2D;
159 avc_ildb_context->surface[SURFACE_SRC_Y].format = I965_SURFACEFORMAT_R8_SINT;
160 avc_ildb_context->surface[SURFACE_SRC_Y].width = obj_surface->width / 4 - 1;
161 avc_ildb_context->surface[SURFACE_SRC_Y].height = obj_surface->height - 1;
162 avc_ildb_context->surface[SURFACE_SRC_Y].depth = 0;
163 avc_ildb_context->surface[SURFACE_SRC_Y].pitch = obj_surface->width - 1;
164 avc_ildb_context->surface[SURFACE_SRC_Y].vert_line_stride = !!(va_pic->flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD));
165 avc_ildb_context->surface[SURFACE_SRC_Y].vert_line_stride_ofs = !!(va_pic->flags & VA_PICTURE_H264_BOTTOM_FIELD);
166 avc_ildb_context->surface[SURFACE_SRC_Y].is_target = 0;
168 avc_ildb_context->surface[SURFACE_SRC_UV].s_bo = obj_surface->bo;
169 dri_bo_reference(avc_ildb_context->surface[SURFACE_SRC_UV].s_bo);
170 avc_ildb_context->surface[SURFACE_SRC_UV].offset = obj_surface->width * obj_surface->height;
171 avc_ildb_context->surface[SURFACE_SRC_UV].surface_type = I965_SURFACE_2D;
172 avc_ildb_context->surface[SURFACE_SRC_UV].format = I965_SURFACEFORMAT_R8G8_SINT;
173 avc_ildb_context->surface[SURFACE_SRC_UV].width = obj_surface->width / 4 - 1;
174 avc_ildb_context->surface[SURFACE_SRC_UV].height = obj_surface->height / 2 - 1;
175 avc_ildb_context->surface[SURFACE_SRC_UV].depth = 0;
176 avc_ildb_context->surface[SURFACE_SRC_UV].pitch = obj_surface->width - 1;
177 avc_ildb_context->surface[SURFACE_SRC_UV].vert_line_stride = !!(va_pic->flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD));
178 avc_ildb_context->surface[SURFACE_SRC_UV].vert_line_stride_ofs = !!(va_pic->flags & VA_PICTURE_H264_BOTTOM_FIELD);
179 avc_ildb_context->surface[SURFACE_SRC_UV].is_target = 0;
181 avc_ildb_context->surface[SURFACE_DEST_Y].s_bo = obj_surface->bo;
182 dri_bo_reference(avc_ildb_context->surface[SURFACE_DEST_Y].s_bo);
183 avc_ildb_context->surface[SURFACE_DEST_Y].offset = 0;
184 avc_ildb_context->surface[SURFACE_DEST_Y].surface_type = I965_SURFACE_2D;
185 avc_ildb_context->surface[SURFACE_DEST_Y].format = I965_SURFACEFORMAT_R8_SINT;
186 avc_ildb_context->surface[SURFACE_DEST_Y].width = obj_surface->width / 4 - 1;
187 avc_ildb_context->surface[SURFACE_DEST_Y].height = obj_surface->height - 1;
188 avc_ildb_context->surface[SURFACE_DEST_Y].depth = 0;
189 avc_ildb_context->surface[SURFACE_DEST_Y].pitch = obj_surface->width - 1;
190 avc_ildb_context->surface[SURFACE_DEST_Y].vert_line_stride = !!(va_pic->flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD));
191 avc_ildb_context->surface[SURFACE_DEST_Y].vert_line_stride_ofs = !!(va_pic->flags & VA_PICTURE_H264_BOTTOM_FIELD);
192 avc_ildb_context->surface[SURFACE_DEST_Y].is_target = 1;
194 avc_ildb_context->surface[SURFACE_DEST_UV].s_bo = obj_surface->bo;
195 dri_bo_reference(avc_ildb_context->surface[SURFACE_DEST_UV].s_bo);
196 avc_ildb_context->surface[SURFACE_DEST_UV].offset = obj_surface->width * obj_surface->height;
197 avc_ildb_context->surface[SURFACE_DEST_UV].surface_type = I965_SURFACE_2D;
198 avc_ildb_context->surface[SURFACE_DEST_UV].format = I965_SURFACEFORMAT_R8G8_SINT;
199 avc_ildb_context->surface[SURFACE_DEST_UV].width = obj_surface->width / 4 - 1;
200 avc_ildb_context->surface[SURFACE_DEST_UV].height = obj_surface->height / 2 - 1;
201 avc_ildb_context->surface[SURFACE_DEST_UV].depth = 0;
202 avc_ildb_context->surface[SURFACE_DEST_UV].pitch = obj_surface->width - 1;
203 avc_ildb_context->surface[SURFACE_DEST_UV].vert_line_stride = !!(va_pic->flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD));
204 avc_ildb_context->surface[SURFACE_DEST_UV].vert_line_stride_ofs = !!(va_pic->flags & VA_PICTURE_H264_BOTTOM_FIELD);
205 avc_ildb_context->surface[SURFACE_DEST_UV].is_target = 1;
207 for (i = 0; i < NUM_AVC_ILDB_SURFACES; i++) {
208 bo = avc_ildb_context->surface[i].ss_bo;
212 memset(ss, 0, sizeof(*ss));
213 ss->ss0.surface_type = avc_ildb_context->surface[i].surface_type;
214 ss->ss0.surface_format = avc_ildb_context->surface[i].format;
215 ss->ss0.vert_line_stride = avc_ildb_context->surface[i].vert_line_stride;
216 ss->ss0.vert_line_stride_ofs = avc_ildb_context->surface[i].vert_line_stride_ofs;
217 ss->ss1.base_addr = avc_ildb_context->surface[i].s_bo->offset + avc_ildb_context->surface[i].offset;
218 ss->ss2.width = avc_ildb_context->surface[i].width;
219 ss->ss2.height = avc_ildb_context->surface[i].height;
220 ss->ss3.depth = avc_ildb_context->surface[i].depth;
221 ss->ss3.pitch = avc_ildb_context->surface[i].pitch;
222 dri_bo_emit_reloc(bo,
223 I915_GEM_DOMAIN_RENDER,
224 avc_ildb_context->surface[i].is_target ? I915_GEM_DOMAIN_RENDER : 0,
225 avc_ildb_context->surface[i].offset,
226 offsetof(struct i965_surface_state, ss1),
227 avc_ildb_context->surface[i].s_bo);
233 i965_avc_ildb_binding_table(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
235 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
236 unsigned int *binding_table;
237 dri_bo *bo = avc_ildb_context->binding_table.bo;
242 binding_table = bo->virtual;
243 memset(binding_table, 0, bo->size);
245 for (i = 0; i < NUM_AVC_ILDB_SURFACES; i++) {
246 binding_table[i] = avc_ildb_context->surface[i].ss_bo->offset;
247 dri_bo_emit_reloc(bo,
248 I915_GEM_DOMAIN_INSTRUCTION, 0,
250 i * sizeof(*binding_table),
251 avc_ildb_context->surface[i].ss_bo);
258 i965_avc_ildb_interface_descriptor_table(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
260 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
261 struct i965_interface_descriptor *desc;
265 bo = avc_ildb_context->idrt.bo;
270 for (i = 0; i < NUM_AVC_ILDB_INTERFACES; i++) {
271 int kernel_offset = avc_ildb_kernel_offset[i];
272 memset(desc, 0, sizeof(*desc));
273 desc->desc0.grf_reg_blocks = 7;
274 desc->desc0.kernel_start_pointer = (i965_h264_context->avc_kernels[H264_AVC_COMBINED].bo->offset + kernel_offset) >> 6; /* reloc */
275 desc->desc1.const_urb_entry_read_offset = 0;
276 desc->desc1.const_urb_entry_read_len = ((i == AVC_ILDB_ROOT_Y_ILDB_FRAME ||
277 i == AVC_ILDB_ROOT_Y_ILDB_FIELD ||
278 i == AVC_ILDB_ROOT_Y_ILDB_MBAFF) ? 1 : 0);
279 desc->desc3.binding_table_entry_count = 0;
280 desc->desc3.binding_table_pointer =
281 avc_ildb_context->binding_table.bo->offset >> 5; /*reloc */
283 dri_bo_emit_reloc(bo,
284 I915_GEM_DOMAIN_INSTRUCTION, 0,
285 desc->desc0.grf_reg_blocks + kernel_offset,
286 i * sizeof(*desc) + offsetof(struct i965_interface_descriptor, desc0),
287 i965_h264_context->avc_kernels[H264_AVC_COMBINED].bo);
289 dri_bo_emit_reloc(bo,
290 I915_GEM_DOMAIN_INSTRUCTION, 0,
291 desc->desc3.binding_table_entry_count,
292 i * sizeof(*desc) + offsetof(struct i965_interface_descriptor, desc3),
293 avc_ildb_context->binding_table.bo);
301 i965_avc_ildb_vfe_state(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
303 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
304 struct i965_vfe_state *vfe_state;
307 bo = avc_ildb_context->vfe_state.bo;
310 vfe_state = bo->virtual;
311 memset(vfe_state, 0, sizeof(*vfe_state));
312 vfe_state->vfe1.max_threads = 0;
313 vfe_state->vfe1.urb_entry_alloc_size = avc_ildb_context->urb.size_vfe_entry - 1;
314 vfe_state->vfe1.num_urb_entries = avc_ildb_context->urb.num_vfe_entries;
315 vfe_state->vfe1.vfe_mode = VFE_GENERIC_MODE;
316 vfe_state->vfe1.children_present = 1;
317 vfe_state->vfe2.interface_descriptor_base =
318 avc_ildb_context->idrt.bo->offset >> 4; /* reloc */
319 dri_bo_emit_reloc(bo,
320 I915_GEM_DOMAIN_INSTRUCTION, 0,
322 offsetof(struct i965_vfe_state, vfe2),
323 avc_ildb_context->idrt.bo);
328 i965_avc_ildb_upload_constants(VADriverContextP ctx,
329 struct decode_state *decode_state,
330 struct i965_h264_context *i965_h264_context)
332 struct i965_driver_data *i965 = i965_driver_data(ctx);
333 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
334 VAPictureParameterBufferH264 *pic_param;
335 struct avc_ildb_root_input *root_input;
337 assert(decode_state->pic_param && decode_state->pic_param->buffer);
338 pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
340 dri_bo_map(avc_ildb_context->curbe.bo, 1);
341 assert(avc_ildb_context->curbe.bo->virtual);
342 root_input = avc_ildb_context->curbe.bo->virtual;
344 if (IS_IRONLAKE(i965->intel.device_info)) {
345 root_input->max_concurrent_threads = 76; /* 72 - 2 + 8 - 2 */
347 root_input->max_concurrent_threads = 54; /* 50 - 2 + 8 - 2 */
350 if (pic_param->pic_fields.bits.field_pic_flag)
351 root_input->picture_type = PICTURE_FIELD;
353 if (pic_param->seq_fields.bits.mb_adaptive_frame_field_flag)
354 root_input->picture_type = PICTURE_MBAFF;
356 root_input->picture_type = PICTURE_FRAME;
359 avc_ildb_context->picture_type = root_input->picture_type;
360 root_input->blocks_per_row = pic_param->picture_width_in_mbs_minus1 + 1;
361 root_input->blocks_per_column = (pic_param->picture_height_in_mbs_minus1 + 1) /
362 (1 + (root_input->picture_type != PICTURE_FRAME));
363 avc_ildb_context->mbs_per_picture = (pic_param->picture_width_in_mbs_minus1 + 1) *
364 (pic_param->picture_height_in_mbs_minus1 + 1);
366 root_input->mbaff_frame_flag = (root_input->picture_type == PICTURE_MBAFF);
367 root_input->bottom_field_flag = !!(pic_param->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD);
368 root_input->control_data_expansion_flag = 1; /* Always 1 on G4x+ */
369 root_input->chroma_format = (pic_param->seq_fields.bits.chroma_format_idc != 1); /* 0=4:0:0, 1=4:2:0 */
371 root_input->ramp_constant_0 = 0x03020100;
373 root_input->ramp_constant_1 = 0x07060504;
375 root_input->constant_0 = -2;
376 root_input->constant_1 = 1;
378 dri_bo_unmap(avc_ildb_context->curbe.bo);
382 i965_avc_ildb_states_setup(VADriverContextP ctx,
383 struct decode_state *decode_state,
384 struct i965_h264_context *i965_h264_context)
386 i965_avc_ildb_surface_state(ctx, decode_state, i965_h264_context);
387 i965_avc_ildb_binding_table(ctx, i965_h264_context);
388 i965_avc_ildb_interface_descriptor_table(ctx, i965_h264_context);
389 i965_avc_ildb_vfe_state(ctx, i965_h264_context);
390 i965_avc_ildb_upload_constants(ctx, decode_state, i965_h264_context);
394 i965_avc_ildb_pipeline_select(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
396 struct intel_batchbuffer *batch = i965_h264_context->batch;
398 BEGIN_BATCH(batch, 1);
399 OUT_BATCH(batch, CMD_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA);
400 ADVANCE_BATCH(batch);
404 i965_avc_ildb_urb_layout(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
406 struct i965_driver_data *i965 = i965_driver_data(ctx);
407 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
408 struct intel_batchbuffer *batch = i965_h264_context->batch;
409 unsigned int vfe_fence, cs_fence;
411 vfe_fence = avc_ildb_context->urb.cs_start;
412 cs_fence = i965->intel.device_info->urb_size;
414 BEGIN_BATCH(batch, 3);
415 OUT_BATCH(batch, CMD_URB_FENCE | UF0_VFE_REALLOC | UF0_CS_REALLOC | 1);
418 (vfe_fence << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */
419 (cs_fence << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */
420 ADVANCE_BATCH(batch);
424 i965_avc_ildb_state_base_address(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
426 struct i965_driver_data *i965 = i965_driver_data(ctx);
427 struct intel_batchbuffer *batch = i965_h264_context->batch;
429 if (IS_IRONLAKE(i965->intel.device_info)) {
430 BEGIN_BATCH(batch, 8);
431 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 6);
432 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
433 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
434 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
435 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
436 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
437 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
438 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
439 ADVANCE_BATCH(batch);
441 BEGIN_BATCH(batch, 6);
442 OUT_BATCH(batch, CMD_STATE_BASE_ADDRESS | 4);
443 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
444 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
445 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
446 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
447 OUT_BATCH(batch, 0 | BASE_ADDRESS_MODIFY);
448 ADVANCE_BATCH(batch);
453 i965_avc_ildb_state_pointers(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
455 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
456 struct intel_batchbuffer *batch = i965_h264_context->batch;
458 BEGIN_BATCH(batch, 3);
459 OUT_BATCH(batch, CMD_MEDIA_STATE_POINTERS | 1);
461 OUT_RELOC(batch, avc_ildb_context->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
462 ADVANCE_BATCH(batch);
466 i965_avc_ildb_cs_urb_layout(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
468 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
469 struct intel_batchbuffer *batch = i965_h264_context->batch;
471 BEGIN_BATCH(batch, 2);
472 OUT_BATCH(batch, CMD_CS_URB_STATE | 0);
474 ((avc_ildb_context->urb.size_cs_entry - 1) << 4) | /* URB Entry Allocation Size */
475 (avc_ildb_context->urb.num_cs_entries << 0)); /* Number of URB Entries */
476 ADVANCE_BATCH(batch);
480 i965_avc_ildb_constant_buffer(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
482 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
483 struct intel_batchbuffer *batch = i965_h264_context->batch;
485 BEGIN_BATCH(batch, 2);
486 OUT_BATCH(batch, CMD_CONSTANT_BUFFER | (1 << 8) | (2 - 2));
487 OUT_RELOC(batch, avc_ildb_context->curbe.bo,
488 I915_GEM_DOMAIN_INSTRUCTION, 0,
489 avc_ildb_context->urb.size_cs_entry - 1);
490 ADVANCE_BATCH(batch);
494 i965_avc_ildb_objects(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
496 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;
497 struct intel_batchbuffer *batch = i965_h264_context->batch;
499 BEGIN_BATCH(batch, 6);
500 OUT_BATCH(batch, CMD_MEDIA_OBJECT | 4);
502 switch (avc_ildb_context->picture_type) {
504 OUT_BATCH(batch, AVC_ILDB_ROOT_Y_ILDB_FRAME);
508 OUT_BATCH(batch, AVC_ILDB_ROOT_Y_ILDB_FIELD);
512 OUT_BATCH(batch, AVC_ILDB_ROOT_Y_ILDB_MBAFF);
521 OUT_BATCH(batch, 0); /* no indirect data */
525 ADVANCE_BATCH(batch);
529 i965_avc_ildb_pipeline_setup(VADriverContextP ctx, struct i965_h264_context *i965_h264_context)
531 struct intel_batchbuffer *batch = i965_h264_context->batch;
533 intel_batchbuffer_emit_mi_flush(batch);
534 i965_avc_ildb_pipeline_select(ctx, i965_h264_context);
535 i965_avc_ildb_state_base_address(ctx, i965_h264_context);
536 i965_avc_ildb_state_pointers(ctx, i965_h264_context);
537 i965_avc_ildb_urb_layout(ctx, i965_h264_context);
538 i965_avc_ildb_cs_urb_layout(ctx, i965_h264_context);
539 i965_avc_ildb_constant_buffer(ctx, i965_h264_context);
540 i965_avc_ildb_objects(ctx, i965_h264_context);
544 i965_avc_ildb(VADriverContextP ctx, struct decode_state *decode_state, void *h264_context)
546 struct i965_h264_context *i965_h264_context = (struct i965_h264_context *)h264_context;
548 if (i965_h264_context->enable_avc_ildb) {
549 i965_avc_ildb_states_setup(ctx, decode_state, i965_h264_context);
550 i965_avc_ildb_pipeline_setup(ctx, i965_h264_context);
555 i965_avc_ildb_decode_init(VADriverContextP ctx, void *h264_context)
557 struct i965_driver_data *i965 = i965_driver_data(ctx);
558 struct i965_h264_context *i965_h264_context = (struct i965_h264_context *)h264_context;
559 struct i965_avc_ildb_context *avc_ildb_context = &i965_h264_context->avc_ildb_context;;
563 dri_bo_unreference(avc_ildb_context->curbe.bo);
564 bo = dri_bo_alloc(i965->intel.bufmgr,
568 avc_ildb_context->curbe.bo = bo;
570 dri_bo_unreference(avc_ildb_context->binding_table.bo);
571 bo = dri_bo_alloc(i965->intel.bufmgr,
573 NUM_AVC_ILDB_SURFACES * sizeof(unsigned int), 32);
575 avc_ildb_context->binding_table.bo = bo;
577 dri_bo_unreference(avc_ildb_context->idrt.bo);
578 bo = dri_bo_alloc(i965->intel.bufmgr,
579 "interface discriptor",
580 NUM_AVC_ILDB_INTERFACES * sizeof(struct i965_interface_descriptor), 16);
582 avc_ildb_context->idrt.bo = bo;
584 dri_bo_unreference(avc_ildb_context->vfe_state.bo);
585 bo = dri_bo_alloc(i965->intel.bufmgr,
587 sizeof(struct i965_vfe_state), 32);
589 avc_ildb_context->vfe_state.bo = bo;
591 avc_ildb_context->urb.num_vfe_entries = 1;
592 avc_ildb_context->urb.size_vfe_entry = 640;
593 avc_ildb_context->urb.num_cs_entries = 1;
594 avc_ildb_context->urb.size_cs_entry = 1;
595 avc_ildb_context->urb.vfe_start = 0;
596 avc_ildb_context->urb.cs_start = avc_ildb_context->urb.vfe_start +
597 avc_ildb_context->urb.num_vfe_entries * avc_ildb_context->urb.size_vfe_entry;
598 assert(avc_ildb_context->urb.cs_start +
599 avc_ildb_context->urb.num_cs_entries * avc_ildb_context->urb.size_cs_entry <= i965->intel.device_info->urb_size);
601 for (i = 0; i < NUM_AVC_ILDB_SURFACES; i++) {
602 dri_bo_unreference(avc_ildb_context->surface[i].s_bo);
603 avc_ildb_context->surface[i].s_bo = NULL;
605 dri_bo_unreference(avc_ildb_context->surface[i].ss_bo);
606 bo = dri_bo_alloc(i965->intel.bufmgr,
608 sizeof(struct i965_surface_state), 32);
610 avc_ildb_context->surface[i].ss_bo = bo;
614 assert(NUM_AVC_ILDB_INTERFACES == ARRAY_ELEMS(avc_ildb_kernel_offset_gen5));
616 if (IS_IRONLAKE(i965->intel.device_info)) {
617 avc_ildb_kernel_offset = avc_ildb_kernel_offset_gen5;
619 avc_ildb_kernel_offset = avc_ildb_kernel_offset_gen4;
624 i965_avc_ildb_ternimate(struct i965_avc_ildb_context *avc_ildb_context)
628 dri_bo_unreference(avc_ildb_context->curbe.bo);
629 avc_ildb_context->curbe.bo = NULL;
631 dri_bo_unreference(avc_ildb_context->binding_table.bo);
632 avc_ildb_context->binding_table.bo = NULL;
634 dri_bo_unreference(avc_ildb_context->idrt.bo);
635 avc_ildb_context->idrt.bo = NULL;
637 dri_bo_unreference(avc_ildb_context->vfe_state.bo);
638 avc_ildb_context->vfe_state.bo = NULL;
640 for (i = 0; i < NUM_AVC_ILDB_SURFACES; i++) {
641 dri_bo_unreference(avc_ildb_context->surface[i].ss_bo);
642 avc_ildb_context->surface[i].ss_bo = NULL;
644 dri_bo_unreference(avc_ildb_context->surface[i].s_bo);
645 avc_ildb_context->surface[i].s_bo = NULL;