2 * Copyright © 2014 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>
32 #include <va/va_dec_hevc.h>
34 #include "intel_batchbuffer.h"
35 #include "intel_driver.h"
36 #include "i965_defines.h"
37 #include "i965_drv_video.h"
38 #include "i965_decoder_utils.h"
41 #include "intel_media.h"
43 #define OUT_BUFFER(buf_bo, is_target, ma) do { \
45 OUT_BCS_RELOC(batch, \
47 I915_GEM_DOMAIN_RENDER, \
48 is_target ? I915_GEM_DOMAIN_RENDER : 0, \
51 OUT_BCS_BATCH(batch, 0); \
53 OUT_BCS_BATCH(batch, 0); \
55 OUT_BCS_BATCH(batch, 0); \
58 #define OUT_BUFFER_MA_TARGET(buf_bo) OUT_BUFFER(buf_bo, 1, 1)
59 #define OUT_BUFFER_MA_REFERENCE(buf_bo) OUT_BUFFER(buf_bo, 0, 1)
60 #define OUT_BUFFER_NMA_TARGET(buf_bo) OUT_BUFFER(buf_bo, 1, 0)
61 #define OUT_BUFFER_NMA_REFERENCE(buf_bo) OUT_BUFFER(buf_bo, 0, 0)
64 gen9_hcpd_init_hevc_surface(VADriverContextP ctx,
65 VAPictureParameterBufferHEVC *pic_param,
66 struct object_surface *obj_surface,
67 struct gen9_hcpd_context *gen9_hcpd_context)
69 struct i965_driver_data *i965 = i965_driver_data(ctx);
70 GenHevcSurface *gen9_hevc_surface;
75 obj_surface->free_private_data = gen_free_hevc_surface;
76 gen9_hevc_surface = obj_surface->private_data;
78 if (!gen9_hevc_surface) {
79 gen9_hevc_surface = calloc(sizeof(GenHevcSurface), 1);
80 gen9_hevc_surface->base.frame_store_id = -1;
81 obj_surface->private_data = gen9_hevc_surface;
84 if (gen9_hevc_surface->motion_vector_temporal_bo == NULL) {
87 if (gen9_hcpd_context->ctb_size == 16)
88 size = ((gen9_hcpd_context->picture_width_in_pixels + 63) >> 6) *
89 ((gen9_hcpd_context->picture_height_in_pixels + 15) >> 4);
91 size = ((gen9_hcpd_context->picture_width_in_pixels + 31) >> 5) *
92 ((gen9_hcpd_context->picture_height_in_pixels + 31) >> 5);
94 size <<= 6; /* in unit of 64bytes */
95 gen9_hevc_surface->motion_vector_temporal_bo = dri_bo_alloc(i965->intel.bufmgr,
96 "motion vector temporal buffer",
103 gen9_hcpd_hevc_decode_init(VADriverContextP ctx,
104 struct decode_state *decode_state,
105 struct gen9_hcpd_context *gen9_hcpd_context)
107 struct i965_driver_data *i965 = i965_driver_data(ctx);
108 VAPictureParameterBufferHEVC *pic_param;
109 VASliceParameterBufferHEVC *slice_param;
110 struct object_surface *obj_surface;
112 int i, j, has_inter = 0;
114 for (j = 0; j < decode_state->num_slice_params && !has_inter; j++) {
115 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
116 slice_param = (VASliceParameterBufferHEVC *)decode_state->slice_params[j]->buffer;
118 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
119 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B ||
120 slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P) {
129 assert(decode_state->pic_param && decode_state->pic_param->buffer);
130 pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer;
131 intel_update_hevc_frame_store_index(ctx,
134 gen9_hcpd_context->reference_surfaces,
135 &gen9_hcpd_context->fs_ctx);
137 gen9_hcpd_context->picture_width_in_pixels = pic_param->pic_width_in_luma_samples;
138 gen9_hcpd_context->picture_height_in_pixels = pic_param->pic_height_in_luma_samples;
139 gen9_hcpd_context->ctb_size = (1 << (pic_param->log2_min_luma_coding_block_size_minus3 +
141 pic_param->log2_diff_max_min_luma_coding_block_size));
142 gen9_hcpd_context->picture_width_in_ctbs = ALIGN(gen9_hcpd_context->picture_width_in_pixels, gen9_hcpd_context->ctb_size) / gen9_hcpd_context->ctb_size;
143 gen9_hcpd_context->picture_height_in_ctbs = ALIGN(gen9_hcpd_context->picture_height_in_pixels, gen9_hcpd_context->ctb_size) / gen9_hcpd_context->ctb_size;
144 gen9_hcpd_context->min_cb_size = (1 << (pic_param->log2_min_luma_coding_block_size_minus3 + 3));
145 gen9_hcpd_context->picture_width_in_min_cb_minus1 = gen9_hcpd_context->picture_width_in_pixels / gen9_hcpd_context->min_cb_size - 1;
146 gen9_hcpd_context->picture_height_in_min_cb_minus1 = gen9_hcpd_context->picture_height_in_pixels / gen9_hcpd_context->min_cb_size - 1;
148 /* Current decoded picture */
149 obj_surface = decode_state->render_object;
150 hevc_ensure_surface_bo(ctx, decode_state, obj_surface, pic_param);
151 gen9_hcpd_init_hevc_surface(ctx, pic_param, obj_surface, gen9_hcpd_context);
153 size = ALIGN(gen9_hcpd_context->picture_width_in_pixels, 32) >> 3;
155 ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_line_buffer), "line buffer", size);
156 ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_line_buffer), "tile line buffer", size);
158 size = ALIGN(gen9_hcpd_context->picture_height_in_pixels + 6 * gen9_hcpd_context->picture_height_in_ctbs, 32) >> 3;
160 ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_column_buffer), "tile column buffer", size);
163 size = (((gen9_hcpd_context->picture_width_in_pixels + 15) >> 4) * 188 + 9 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9;
165 ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_line_buffer), "metadata line buffer", size);
167 size = (((gen9_hcpd_context->picture_width_in_pixels + 15) >> 4) * 172 + 9 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9;
169 ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_line_buffer), "metadata tile line buffer", size);
171 size = (((gen9_hcpd_context->picture_height_in_pixels + 15) >> 4) * 176 + 89 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9;
173 ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_column_buffer), "metadata tile column buffer", size);
175 size = (gen9_hcpd_context->picture_width_in_pixels + 8 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9;
177 ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_line_buffer), "metadata line buffer", size);
179 size = (gen9_hcpd_context->picture_width_in_pixels + 16 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9;
181 ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_line_buffer), "metadata tile line buffer", size);
183 size = (gen9_hcpd_context->picture_height_in_pixels + 8 * gen9_hcpd_context->picture_height_in_ctbs + 1023) >> 9;
185 ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_column_buffer), "metadata tile column buffer", size);
188 size = ALIGN(((gen9_hcpd_context->picture_width_in_pixels >> 1) + 3 * gen9_hcpd_context->picture_width_in_ctbs), 16) >> 3;
190 ALLOC_GEN_BUFFER((&gen9_hcpd_context->sao_line_buffer), "sao line buffer", size);
192 size = ALIGN(((gen9_hcpd_context->picture_width_in_pixels >> 1) + 6 * gen9_hcpd_context->picture_width_in_ctbs), 16) >> 3;
194 ALLOC_GEN_BUFFER((&gen9_hcpd_context->sao_tile_line_buffer), "sao tile line buffer", size);
196 size = ALIGN(((gen9_hcpd_context->picture_height_in_pixels >> 1) + 6 * gen9_hcpd_context->picture_height_in_ctbs), 16) >> 3;
198 ALLOC_GEN_BUFFER((&gen9_hcpd_context->sao_tile_column_buffer), "sao tile column buffer", size);
200 return VA_STATUS_SUCCESS;
204 gen9_hcpd_pipe_mode_select(VADriverContextP ctx,
205 struct decode_state *decode_state,
207 struct gen9_hcpd_context *gen9_hcpd_context)
209 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
211 assert(codec == HCP_CODEC_HEVC);
213 BEGIN_BCS_BATCH(batch, 4);
215 OUT_BCS_BATCH(batch, HCP_PIPE_MODE_SELECT | (4 - 2));
218 (0 << 3) | /* disable Pic Status / Error Report */
219 HCP_CODEC_SELECT_DECODE);
220 OUT_BCS_BATCH(batch, 0);
221 OUT_BCS_BATCH(batch, 0);
223 ADVANCE_BCS_BATCH(batch);
227 gen9_hcpd_surface_state(VADriverContextP ctx,
228 struct decode_state *decode_state,
229 struct gen9_hcpd_context *gen9_hcpd_context)
231 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
232 struct object_surface *obj_surface = decode_state->render_object;
233 unsigned int y_cb_offset;
237 y_cb_offset = obj_surface->y_cb_offset;
239 BEGIN_BCS_BATCH(batch, 3);
241 OUT_BCS_BATCH(batch, HCP_SURFACE_STATE | (3 - 2));
243 (0 << 28) | /* surface id */
244 (obj_surface->width - 1)); /* pitch - 1 */
246 (SURFACE_FORMAT_PLANAR_420_8 << 28) |
249 ADVANCE_BCS_BATCH(batch);
253 gen9_hcpd_pipe_buf_addr_state(VADriverContextP ctx,
254 struct decode_state *decode_state,
255 struct gen9_hcpd_context *gen9_hcpd_context)
257 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
258 struct object_surface *obj_surface;
259 GenHevcSurface *gen9_hevc_surface;
262 BEGIN_BCS_BATCH(batch, 95);
264 OUT_BCS_BATCH(batch, HCP_PIPE_BUF_ADDR_STATE | (95 - 2));
266 obj_surface = decode_state->render_object;
267 assert(obj_surface && obj_surface->bo);
268 gen9_hevc_surface = obj_surface->private_data;
269 assert(gen9_hevc_surface && gen9_hevc_surface->motion_vector_temporal_bo);
271 OUT_BUFFER_MA_TARGET(obj_surface->bo); /* DW 1..3 */
272 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_line_buffer.bo);/* DW 4..6 */
273 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_tile_line_buffer.bo); /* DW 7..9 */
274 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_tile_column_buffer.bo); /* DW 10..12 */
275 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_line_buffer.bo); /* DW 13..15 */
276 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_tile_line_buffer.bo); /* DW 16..18 */
277 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_tile_column_buffer.bo); /* DW 19..21 */
278 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->sao_line_buffer.bo); /* DW 22..24 */
279 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->sao_tile_line_buffer.bo); /* DW 25..27 */
280 OUT_BUFFER_MA_TARGET(gen9_hcpd_context->sao_tile_column_buffer.bo); /* DW 28..30 */
281 OUT_BUFFER_MA_TARGET(gen9_hevc_surface->motion_vector_temporal_bo); /* DW 31..33 */
282 OUT_BUFFER_MA_TARGET(NULL); /* DW 34..36, reserved */
284 for (i = 0; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) {
285 obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface;
288 OUT_BUFFER_NMA_REFERENCE(obj_surface->bo);
290 OUT_BUFFER_NMA_REFERENCE(NULL);
292 OUT_BCS_BATCH(batch, 0); /* DW 53, memory address attributes */
294 OUT_BUFFER_MA_REFERENCE(NULL); /* DW 54..56, ignore for decoding mode */
295 OUT_BUFFER_MA_TARGET(NULL);
296 OUT_BUFFER_MA_TARGET(NULL);
297 OUT_BUFFER_MA_TARGET(NULL);
299 for (i = 0; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) {
300 obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface;
301 gen9_hevc_surface = NULL;
303 if (obj_surface && obj_surface->private_data)
304 gen9_hevc_surface = obj_surface->private_data;
306 if (gen9_hevc_surface)
307 OUT_BUFFER_NMA_REFERENCE(gen9_hevc_surface->motion_vector_temporal_bo);
309 OUT_BUFFER_NMA_REFERENCE(NULL);
311 OUT_BCS_BATCH(batch, 0); /* DW 82, memory address attributes */
313 OUT_BUFFER_MA_TARGET(NULL); /* DW 83..85, ignore for HEVC */
314 OUT_BUFFER_MA_TARGET(NULL); /* DW 86..88, ignore for HEVC */
315 OUT_BUFFER_MA_TARGET(NULL); /* DW 89..91, ignore for HEVC */
316 OUT_BUFFER_MA_TARGET(NULL); /* DW 92..94, ignore for HEVC */
318 ADVANCE_BCS_BATCH(batch);
322 gen9_hcpd_ind_obj_base_addr_state(VADriverContextP ctx,
323 dri_bo *slice_data_bo,
324 struct gen9_hcpd_context *gen9_hcpd_context)
326 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
328 BEGIN_BCS_BATCH(batch, 14);
330 OUT_BCS_BATCH(batch, HCP_IND_OBJ_BASE_ADDR_STATE | (14 - 2));
331 OUT_BUFFER_MA_REFERENCE(slice_data_bo); /* DW 1..3 */
332 OUT_BUFFER_NMA_REFERENCE(NULL); /* DW 4..5, Upper Bound */
333 OUT_BUFFER_MA_REFERENCE(NULL); /* DW 6..8, CU, ignored */
334 OUT_BUFFER_MA_TARGET(NULL); /* DW 9..11, PAK-BSE, ignored */
335 OUT_BUFFER_NMA_TARGET(NULL); /* DW 12..13, Upper Bound */
337 ADVANCE_BCS_BATCH(batch);
341 gen9_hcpd_qm_state(VADriverContextP ctx,
348 struct gen9_hcpd_context *gen9_hcpd_context)
350 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
351 unsigned char qm_buffer[64];
353 assert(qm_length <= 64);
354 memset(qm_buffer, 0, sizeof(qm_buffer));
355 memcpy(qm_buffer, qm, qm_length);
357 BEGIN_BCS_BATCH(batch, 18);
359 OUT_BCS_BATCH(batch, HCP_QM_STATE | (18 - 2));
362 color_component << 3 |
365 intel_batchbuffer_data(batch, qm_buffer, 64);
367 ADVANCE_BCS_BATCH(batch);
371 gen9_hcpd_hevc_qm_state(VADriverContextP ctx,
372 struct decode_state *decode_state,
373 struct gen9_hcpd_context *gen9_hcpd_context)
375 VAIQMatrixBufferHEVC *iq_matrix;
376 VAPictureParameterBufferHEVC *pic_param;
379 if (decode_state->iq_matrix && decode_state->iq_matrix->buffer)
380 iq_matrix = (VAIQMatrixBufferHEVC *)decode_state->iq_matrix->buffer;
382 iq_matrix = &gen9_hcpd_context->iq_matrix_hevc;
384 assert(decode_state->pic_param && decode_state->pic_param->buffer);
385 pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer;
387 if (!pic_param->pic_fields.bits.scaling_list_enabled_flag)
388 iq_matrix = &gen9_hcpd_context->iq_matrix_hevc;
390 for (i = 0; i < 6; i++) {
391 gen9_hcpd_qm_state(ctx,
393 iq_matrix->ScalingList4x4[i], 16,
397 for (i = 0; i < 6; i++) {
398 gen9_hcpd_qm_state(ctx,
400 iq_matrix->ScalingList8x8[i], 64,
404 for (i = 0; i < 6; i++) {
405 gen9_hcpd_qm_state(ctx,
406 2, i % 3, i / 3, iq_matrix->ScalingListDC16x16[i],
407 iq_matrix->ScalingList16x16[i], 64,
411 for (i = 0; i < 2; i++) {
412 gen9_hcpd_qm_state(ctx,
413 3, 0, i % 2, iq_matrix->ScalingListDC32x32[i],
414 iq_matrix->ScalingList32x32[i], 64,
420 gen9_hcpd_pic_state(VADriverContextP ctx,
421 struct decode_state *decode_state,
422 struct gen9_hcpd_context *gen9_hcpd_context)
424 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
425 VAPictureParameterBufferHEVC *pic_param;
426 int max_pcm_size_minus3 = 0, min_pcm_size_minus3 = 0;
427 int pcm_sample_bit_depth_luma_minus1 = 7, pcm_sample_bit_depth_chroma_minus1 = 7;
431 * When not present, the value of loop_filter_across_tiles_enabled_flag
432 * is inferred to be equal to 1.
434 int loop_filter_across_tiles_enabled_flag = 1;
436 assert(decode_state->pic_param && decode_state->pic_param->buffer);
437 pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer;
439 if (pic_param->pic_fields.bits.pcm_enabled_flag) {
440 max_pcm_size_minus3 = pic_param->log2_min_pcm_luma_coding_block_size_minus3 +
441 pic_param->log2_diff_max_min_pcm_luma_coding_block_size;
442 min_pcm_size_minus3 = pic_param->log2_min_pcm_luma_coding_block_size_minus3;
443 pcm_sample_bit_depth_luma_minus1 = (pic_param->pcm_sample_bit_depth_luma_minus1 & 0x0f);
444 pcm_sample_bit_depth_chroma_minus1 = (pic_param->pcm_sample_bit_depth_chroma_minus1 & 0x0f);
446 max_pcm_size_minus3 = MIN(pic_param->log2_min_luma_coding_block_size_minus3 + pic_param->log2_diff_max_min_luma_coding_block_size, 2);
449 if (pic_param->pic_fields.bits.tiles_enabled_flag)
450 loop_filter_across_tiles_enabled_flag = pic_param->pic_fields.bits.loop_filter_across_tiles_enabled_flag;
452 BEGIN_BCS_BATCH(batch, 19);
454 OUT_BCS_BATCH(batch, HCP_PIC_STATE | (19 - 2));
457 gen9_hcpd_context->picture_height_in_min_cb_minus1 << 16 |
458 gen9_hcpd_context->picture_width_in_min_cb_minus1);
460 max_pcm_size_minus3 << 10 |
461 min_pcm_size_minus3 << 8 |
462 (pic_param->log2_min_transform_block_size_minus2 +
463 pic_param->log2_diff_max_min_transform_block_size) << 6 |
464 pic_param->log2_min_transform_block_size_minus2 << 4 |
465 (pic_param->log2_min_luma_coding_block_size_minus3 +
466 pic_param->log2_diff_max_min_luma_coding_block_size) << 2 |
467 pic_param->log2_min_luma_coding_block_size_minus3);
468 OUT_BCS_BATCH(batch, 0); /* DW 3, ignored */
471 pic_param->pic_fields.bits.strong_intra_smoothing_enabled_flag << 26 |
472 pic_param->pic_fields.bits.transquant_bypass_enabled_flag << 25 |
473 pic_param->pic_fields.bits.amp_enabled_flag << 23 |
474 pic_param->pic_fields.bits.transform_skip_enabled_flag << 22 |
475 !(pic_param->CurrPic.flags & VA_PICTURE_HEVC_BOTTOM_FIELD) << 21 |
476 !!(pic_param->CurrPic.flags & VA_PICTURE_HEVC_FIELD_PIC) << 20 |
477 pic_param->pic_fields.bits.weighted_pred_flag << 19 |
478 pic_param->pic_fields.bits.weighted_bipred_flag << 18 |
479 pic_param->pic_fields.bits.tiles_enabled_flag << 17 |
480 pic_param->pic_fields.bits.entropy_coding_sync_enabled_flag << 16 |
481 loop_filter_across_tiles_enabled_flag << 15 |
482 pic_param->pic_fields.bits.sign_data_hiding_enabled_flag << 13 |
483 pic_param->log2_parallel_merge_level_minus2 << 10 |
484 pic_param->pic_fields.bits.constrained_intra_pred_flag << 9 |
485 pic_param->pic_fields.bits.pcm_loop_filter_disabled_flag << 8 |
486 (pic_param->diff_cu_qp_delta_depth & 0x03) << 6 |
487 pic_param->pic_fields.bits.cu_qp_delta_enabled_flag << 5 |
488 pic_param->pic_fields.bits.pcm_enabled_flag << 4 |
489 pic_param->slice_parsing_fields.bits.sample_adaptive_offset_enabled_flag << 3 |
492 pcm_sample_bit_depth_luma_minus1 << 20 |
493 pcm_sample_bit_depth_chroma_minus1 << 16 |
494 pic_param->max_transform_hierarchy_depth_inter << 13 |
495 pic_param->max_transform_hierarchy_depth_intra << 10 |
496 (pic_param->pps_cr_qp_offset & 0x1f) << 5 |
497 (pic_param->pps_cb_qp_offset & 0x1f));
501 OUT_BCS_BATCH(batch, 0);
502 OUT_BCS_BATCH(batch, 0);
503 OUT_BCS_BATCH(batch, 0);
504 OUT_BCS_BATCH(batch, 0); /* DW 10 */
505 OUT_BCS_BATCH(batch, 0);
506 OUT_BCS_BATCH(batch, 0);
507 OUT_BCS_BATCH(batch, 0);
508 OUT_BCS_BATCH(batch, 0);
509 OUT_BCS_BATCH(batch, 0); /* DW 15 */
510 OUT_BCS_BATCH(batch, 0);
511 OUT_BCS_BATCH(batch, 0);
512 OUT_BCS_BATCH(batch, 0);
514 ADVANCE_BCS_BATCH(batch);
518 gen9_hcpd_tile_state(VADriverContextP ctx,
519 struct decode_state *decode_state,
520 struct gen9_hcpd_context *gen9_hcpd_context)
522 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
523 VAPictureParameterBufferHEVC *pic_param;
524 uint8_t pos_col[20], pos_row[24];
527 assert(decode_state->pic_param && decode_state->pic_param->buffer);
528 pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer;
530 memset(pos_col, 0, sizeof(pos_col));
531 memset(pos_row, 0, sizeof(pos_row));
533 for (i = 0; i <= MIN(pic_param->num_tile_columns_minus1, 18); i++)
534 pos_col[i + 1] = pos_col[i] + pic_param->column_width_minus1[i] + 1;
536 for (i = 0; i <= MIN(pic_param->num_tile_rows_minus1, 20); i++)
537 pos_row[i + 1] = pos_row[i] + pic_param->row_height_minus1[i] + 1;
539 BEGIN_BCS_BATCH(batch, 13);
541 OUT_BCS_BATCH(batch, HCP_TILE_STATE | (13 - 2));
544 pic_param->num_tile_columns_minus1 << 5 |
545 pic_param->num_tile_rows_minus1);
546 intel_batchbuffer_data(batch, pos_col, 20);
547 intel_batchbuffer_data(batch, pos_row, 24);
549 ADVANCE_BCS_BATCH(batch);
553 gen9_hcpd_get_reference_picture_frame_id(VAPictureHEVC *ref_pic,
554 GenFrameStore frame_store[MAX_GEN_HCP_REFERENCE_FRAMES])
558 if (ref_pic->picture_id == VA_INVALID_ID ||
559 (ref_pic->flags & VA_PICTURE_HEVC_INVALID))
562 for (i = 0; i < MAX_GEN_HCP_REFERENCE_FRAMES; i++) {
563 if (ref_pic->picture_id == frame_store[i].surface_id) {
564 assert(frame_store[i].frame_store_id < MAX_GEN_HCP_REFERENCE_FRAMES);
565 return frame_store[i].frame_store_id;
569 /* Should never get here !!! */
575 gen9_hcpd_ref_idx_state_1(struct intel_batchbuffer *batch,
577 VAPictureParameterBufferHEVC *pic_param,
578 VASliceParameterBufferHEVC *slice_param,
579 GenFrameStore frame_store[MAX_GEN_HCP_REFERENCE_FRAMES])
582 uint8_t num_ref_minus1 = (list ? slice_param->num_ref_idx_l1_active_minus1 : slice_param->num_ref_idx_l0_active_minus1);
583 uint8_t *ref_list = slice_param->RefPicList[list];
585 BEGIN_BCS_BATCH(batch, 18);
587 OUT_BCS_BATCH(batch, HCP_REF_IDX_STATE | (18 - 2));
589 num_ref_minus1 << 1 |
592 for (i = 0; i < 16; i++) {
593 if (i < MIN((num_ref_minus1 + 1), 15)) {
594 VAPictureHEVC *ref_pic = &pic_param->ReferenceFrames[ref_list[i]];
595 VAPictureHEVC *curr_pic = &pic_param->CurrPic;
598 !(ref_pic->flags & VA_PICTURE_HEVC_BOTTOM_FIELD) << 15 |
599 !!(ref_pic->flags & VA_PICTURE_HEVC_FIELD_PIC) << 14 |
600 !!(ref_pic->flags & VA_PICTURE_HEVC_LONG_TERM_REFERENCE) << 13 |
603 gen9_hcpd_get_reference_picture_frame_id(ref_pic, frame_store) << 8 |
604 (CLAMP(-128, 127, curr_pic->pic_order_cnt - ref_pic->pic_order_cnt) & 0xff));
606 OUT_BCS_BATCH(batch, 0);
610 ADVANCE_BCS_BATCH(batch);
614 gen9_hcpd_ref_idx_state(VADriverContextP ctx,
615 VAPictureParameterBufferHEVC *pic_param,
616 VASliceParameterBufferHEVC *slice_param,
617 struct gen9_hcpd_context *gen9_hcpd_context)
619 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
621 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I)
624 gen9_hcpd_ref_idx_state_1(batch, 0, pic_param, slice_param, gen9_hcpd_context->reference_surfaces);
626 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P)
629 gen9_hcpd_ref_idx_state_1(batch, 1, pic_param, slice_param, gen9_hcpd_context->reference_surfaces);
633 gen9_hcpd_weightoffset_state_1(struct intel_batchbuffer *batch,
635 VASliceParameterBufferHEVC *slice_param)
638 uint8_t num_ref_minus1 = (list == 1) ? slice_param->num_ref_idx_l1_active_minus1 : slice_param->num_ref_idx_l0_active_minus1;
639 int8_t *luma_offset = (list == 1) ? slice_param->luma_offset_l1 : slice_param->luma_offset_l0;
640 int8_t *delta_luma_weight = (list == 1) ? slice_param->delta_luma_weight_l1 : slice_param->delta_luma_weight_l0;
641 int8_t (* chroma_offset)[2] = (list == 1) ? slice_param->ChromaOffsetL1 : slice_param->ChromaOffsetL0;
642 int8_t (* delta_chroma_weight)[2] = (list == 1) ? slice_param->delta_chroma_weight_l1 : slice_param->delta_chroma_weight_l0;
644 BEGIN_BCS_BATCH(batch, 34);
646 OUT_BCS_BATCH(batch, HCP_WEIGHTOFFSET | (34 - 2));
647 OUT_BCS_BATCH(batch, list);
649 for (i = 0; i < 16; i++) {
650 if (i < MIN((num_ref_minus1 + 1), 15)) {
652 luma_offset[i] << 8 |
653 delta_luma_weight[i]);
655 OUT_BCS_BATCH(batch, 0);
658 for (i = 0; i < 16; i++) {
659 if (i < MIN((num_ref_minus1 + 1), 15)) {
661 chroma_offset[i][1] << 24 |
662 delta_chroma_weight[i][1] << 16 |
663 chroma_offset[i][0] << 8 |
664 delta_chroma_weight[i][0]);
666 OUT_BCS_BATCH(batch, 0);
670 ADVANCE_BCS_BATCH(batch);
674 gen9_hcpd_weightoffset_state(VADriverContextP ctx,
675 VAPictureParameterBufferHEVC *pic_param,
676 VASliceParameterBufferHEVC *slice_param,
677 struct gen9_hcpd_context *gen9_hcpd_context)
679 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
681 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I)
684 if ((slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P &&
685 !pic_param->pic_fields.bits.weighted_pred_flag) ||
686 (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B &&
687 !pic_param->pic_fields.bits.weighted_bipred_flag))
690 gen9_hcpd_weightoffset_state_1(batch, 0, slice_param);
692 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P)
695 gen9_hcpd_weightoffset_state_1(batch, 1, slice_param);
699 gen9_hcpd_get_collocated_ref_idx(VADriverContextP ctx,
700 VAPictureParameterBufferHEVC *pic_param,
701 VASliceParameterBufferHEVC *slice_param,
702 struct gen9_hcpd_context *gen9_hcpd_context)
705 VAPictureHEVC *ref_pic;
707 if (slice_param->collocated_ref_idx > 14)
710 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I)
713 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P ||
714 (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B &&
715 slice_param->LongSliceFlags.fields.collocated_from_l0_flag))
716 ref_list = slice_param->RefPicList[0];
718 assert(slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B);
719 ref_list = slice_param->RefPicList[1];
722 ref_pic = &pic_param->ReferenceFrames[ref_list[slice_param->collocated_ref_idx]];
724 return gen9_hcpd_get_reference_picture_frame_id(ref_pic, gen9_hcpd_context->reference_surfaces);
728 gen9_hcpd_is_list_low_delay(uint8_t ref_list_count,
729 uint8_t ref_list[15],
730 VAPictureHEVC *curr_pic,
731 VAPictureHEVC ref_surfaces[15])
735 for (i = 0; i < MIN(ref_list_count, 15); i++) {
736 VAPictureHEVC *ref_pic;
738 if (ref_list[i] > 14)
741 ref_pic = &ref_surfaces[ref_list[i]];
743 if (ref_pic->pic_order_cnt > curr_pic->pic_order_cnt)
751 gen9_hcpd_is_low_delay(VADriverContextP ctx,
752 VAPictureParameterBufferHEVC *pic_param,
753 VASliceParameterBufferHEVC *slice_param)
755 if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I)
757 else if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P)
758 return gen9_hcpd_is_list_low_delay(slice_param->num_ref_idx_l0_active_minus1 + 1,
759 slice_param->RefPicList[0],
761 pic_param->ReferenceFrames);
763 return gen9_hcpd_is_list_low_delay(slice_param->num_ref_idx_l0_active_minus1 + 1,
764 slice_param->RefPicList[0],
766 pic_param->ReferenceFrames) &&
767 gen9_hcpd_is_list_low_delay(slice_param->num_ref_idx_l1_active_minus1 + 1,
768 slice_param->RefPicList[1],
770 pic_param->ReferenceFrames);
774 gen9_hcpd_slice_state(VADriverContextP ctx,
775 VAPictureParameterBufferHEVC *pic_param,
776 VASliceParameterBufferHEVC *slice_param,
777 VASliceParameterBufferHEVC *next_slice_param,
778 struct gen9_hcpd_context *gen9_hcpd_context)
780 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
781 int slice_hor_pos, slice_ver_pos, next_slice_hor_pos, next_slice_ver_pos;
783 slice_hor_pos = slice_param->slice_segment_address % gen9_hcpd_context->picture_width_in_ctbs;
784 slice_ver_pos = slice_param->slice_segment_address / gen9_hcpd_context->picture_width_in_ctbs;
786 if (next_slice_param) {
787 next_slice_hor_pos = next_slice_param->slice_segment_address % gen9_hcpd_context->picture_width_in_ctbs;
788 next_slice_ver_pos = next_slice_param->slice_segment_address / gen9_hcpd_context->picture_width_in_ctbs;
790 next_slice_hor_pos = 0;
791 next_slice_ver_pos = 0;
794 BEGIN_BCS_BATCH(batch, 9);
796 OUT_BCS_BATCH(batch, HCP_SLICE_STATE | (9 - 2));
799 slice_ver_pos << 16 |
802 next_slice_ver_pos << 16 |
805 (slice_param->slice_cr_qp_offset & 0x1f) << 17 |
806 (slice_param->slice_cb_qp_offset & 0x1f) << 12 |
807 (pic_param->init_qp_minus26 + 26 + slice_param->slice_qp_delta) << 6 |
808 slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag << 5 |
809 slice_param->LongSliceFlags.fields.dependent_slice_segment_flag << 4 |
810 !next_slice_param << 2 |
811 slice_param->LongSliceFlags.fields.slice_type);
813 gen9_hcpd_get_collocated_ref_idx(ctx, pic_param, slice_param, gen9_hcpd_context) << 26 |
814 (5 - slice_param->five_minus_max_num_merge_cand - 1) << 23 |
815 slice_param->LongSliceFlags.fields.cabac_init_flag << 22 |
816 slice_param->luma_log2_weight_denom << 19 |
817 (slice_param->luma_log2_weight_denom + slice_param->delta_chroma_log2_weight_denom) << 16 |
818 slice_param->LongSliceFlags.fields.collocated_from_l0_flag << 15 |
819 gen9_hcpd_is_low_delay(ctx, pic_param, slice_param) << 14 |
820 slice_param->LongSliceFlags.fields.mvd_l1_zero_flag << 13 |
821 slice_param->LongSliceFlags.fields.slice_sao_luma_flag << 12 |
822 slice_param->LongSliceFlags.fields.slice_sao_chroma_flag << 11 |
823 slice_param->LongSliceFlags.fields.slice_loop_filter_across_slices_enabled_flag << 10 |
824 (slice_param->slice_beta_offset_div2 & 0xf) << 5 |
825 (slice_param->slice_tc_offset_div2 & 0xf) << 1 |
826 slice_param->LongSliceFlags.fields.slice_deblocking_filter_disabled_flag);
828 slice_param->slice_data_byte_offset); /* DW 5 */
833 OUT_BCS_BATCH(batch, 0); /* Ignored for decoding */
834 OUT_BCS_BATCH(batch, 0); /* Ignored for decoding */
836 ADVANCE_BCS_BATCH(batch);
840 gen9_hcpd_bsd_object(VADriverContextP ctx,
841 VASliceParameterBufferHEVC *slice_param,
842 struct gen9_hcpd_context *gen9_hcpd_context)
844 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
846 BEGIN_BCS_BATCH(batch, 3);
848 OUT_BCS_BATCH(batch, HCP_BSD_OBJECT | (3 - 2));
850 OUT_BCS_BATCH(batch, slice_param->slice_data_size);
851 OUT_BCS_BATCH(batch, slice_param->slice_data_offset);
853 ADVANCE_BCS_BATCH(batch);
857 gen9_hcpd_hevc_decode_picture(VADriverContextP ctx,
858 struct decode_state *decode_state,
859 struct gen9_hcpd_context *gen9_hcpd_context)
862 struct i965_driver_data *i965 = i965_driver_data(ctx);
863 struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch;
864 VAPictureParameterBufferHEVC *pic_param;
865 VASliceParameterBufferHEVC *slice_param, *next_slice_param, *next_slice_group_param;
866 dri_bo *slice_data_bo;
869 vaStatus = gen9_hcpd_hevc_decode_init(ctx, decode_state, gen9_hcpd_context);
871 if (vaStatus != VA_STATUS_SUCCESS)
874 assert(decode_state->pic_param && decode_state->pic_param->buffer);
875 pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer;
877 if (i965->intel.has_bsd2)
878 intel_batchbuffer_start_atomic_bcs_override(batch, 0x1000, BSD_RING0);
880 intel_batchbuffer_start_atomic_bcs(batch, 0x1000);
881 intel_batchbuffer_emit_mi_flush(batch);
883 gen9_hcpd_pipe_mode_select(ctx, decode_state, HCP_CODEC_HEVC, gen9_hcpd_context);
884 gen9_hcpd_surface_state(ctx, decode_state, gen9_hcpd_context);
885 gen9_hcpd_pipe_buf_addr_state(ctx, decode_state, gen9_hcpd_context);
886 gen9_hcpd_hevc_qm_state(ctx, decode_state, gen9_hcpd_context);
887 gen9_hcpd_pic_state(ctx, decode_state, gen9_hcpd_context);
889 if (pic_param->pic_fields.bits.tiles_enabled_flag)
890 gen9_hcpd_tile_state(ctx, decode_state, gen9_hcpd_context);
892 /* Need to double it works or not if the two slice groups have differenct slice data buffers */
893 for (j = 0; j < decode_state->num_slice_params; j++) {
894 assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
895 slice_param = (VASliceParameterBufferHEVC *)decode_state->slice_params[j]->buffer;
896 slice_data_bo = decode_state->slice_datas[j]->bo;
898 gen9_hcpd_ind_obj_base_addr_state(ctx, slice_data_bo, gen9_hcpd_context);
900 if (j == decode_state->num_slice_params - 1)
901 next_slice_group_param = NULL;
903 next_slice_group_param = (VASliceParameterBufferHEVC *)decode_state->slice_params[j + 1]->buffer;
905 for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
906 if (i < decode_state->slice_params[j]->num_elements - 1)
907 next_slice_param = slice_param + 1;
909 next_slice_param = next_slice_group_param;
911 gen9_hcpd_slice_state(ctx, pic_param, slice_param, next_slice_param, gen9_hcpd_context);
912 gen9_hcpd_ref_idx_state(ctx, pic_param, slice_param, gen9_hcpd_context);
913 gen9_hcpd_weightoffset_state(ctx, pic_param, slice_param, gen9_hcpd_context);
914 gen9_hcpd_bsd_object(ctx, slice_param, gen9_hcpd_context);
919 intel_batchbuffer_end_atomic(batch);
920 intel_batchbuffer_flush(batch);
927 gen9_hcpd_decode_picture(VADriverContextP ctx,
929 union codec_state *codec_state,
930 struct hw_context *hw_context)
932 struct gen9_hcpd_context *gen9_hcpd_context = (struct gen9_hcpd_context *)hw_context;
933 struct decode_state *decode_state = &codec_state->decode;
936 assert(gen9_hcpd_context);
938 vaStatus = intel_decoder_sanity_check_input(ctx, profile, decode_state);
940 if (vaStatus != VA_STATUS_SUCCESS)
944 case VAProfileHEVCMain:
945 case VAProfileHEVCMain10:
946 vaStatus = gen9_hcpd_hevc_decode_picture(ctx, decode_state, gen9_hcpd_context);
950 /* should never get here 1!! */
960 gen9_hcpd_context_destroy(void *hw_context)
962 struct gen9_hcpd_context *gen9_hcpd_context = (struct gen9_hcpd_context *)hw_context;
964 FREE_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_line_buffer));
965 FREE_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_line_buffer));
966 FREE_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_column_buffer));
967 FREE_GEN_BUFFER((&gen9_hcpd_context->metadata_line_buffer));
968 FREE_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_line_buffer));
969 FREE_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_column_buffer));
970 FREE_GEN_BUFFER((&gen9_hcpd_context->sao_line_buffer));
971 FREE_GEN_BUFFER((&gen9_hcpd_context->sao_tile_line_buffer));
972 FREE_GEN_BUFFER((&gen9_hcpd_context->sao_tile_column_buffer));
974 intel_batchbuffer_free(gen9_hcpd_context->base.batch);
975 free(gen9_hcpd_context);
979 gen9_hcpd_hevc_context_init(VADriverContextP ctx,
980 struct gen9_hcpd_context *gen9_hcpd_context)
982 hevc_gen_default_iq_matrix(&gen9_hcpd_context->iq_matrix_hevc);
985 static struct hw_context *
986 gen9_hcpd_context_init(VADriverContextP ctx, struct object_config *object_config)
988 struct intel_driver_data *intel = intel_driver_data(ctx);
989 struct gen9_hcpd_context *gen9_hcpd_context = calloc(1, sizeof(struct gen9_hcpd_context));
992 if (!gen9_hcpd_context)
995 gen9_hcpd_context->base.destroy = gen9_hcpd_context_destroy;
996 gen9_hcpd_context->base.run = gen9_hcpd_decode_picture;
997 gen9_hcpd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_VEBOX, 0);
999 for (i = 0; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) {
1000 gen9_hcpd_context->reference_surfaces[i].surface_id = VA_INVALID_ID;
1001 gen9_hcpd_context->reference_surfaces[i].frame_store_id = -1;
1002 gen9_hcpd_context->reference_surfaces[i].obj_surface = NULL;
1005 switch (object_config->profile) {
1006 case VAProfileHEVCMain:
1007 case VAProfileHEVCMain10:
1008 gen9_hcpd_hevc_context_init(ctx, gen9_hcpd_context);
1015 return (struct hw_context *)gen9_hcpd_context;
1019 gen9_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
1021 if (obj_config->profile == VAProfileHEVCMain ||
1022 obj_config->profile == VAProfileHEVCMain10) {
1023 return gen9_hcpd_context_init(ctx, obj_config);
1025 return gen8_dec_hw_context_init(ctx, obj_config);