| 1 |
/* |
| 2 |
* Copyright © 2014 Intel Corporation |
| 3 |
* |
| 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: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the |
| 13 |
* next paragraph) shall be included in all copies or substantial portions |
| 14 |
* of the Software. |
| 15 |
* |
| 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. |
| 23 |
* |
| 24 |
* Authors: |
| 25 |
* Xiang Haihao <[email protected]> |
| 26 |
* |
| 27 |
*/ |
| 28 |
|
| 29 |
#include "sysdeps.h" |
| 30 |
|
| 31 |
#include <va/va.h> |
| 32 |
#include <va/va_dec_hevc.h> |
| 33 |
|
| 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" |
| 39 |
|
| 40 |
#include "gen9_mfd.h" |
| 41 |
#include "intel_media.h" |
| 42 |
#include "vp9_probs.h" |
| 43 |
|
| 44 |
#define OUT_BUFFER(buf_bo, is_target, ma) do { \ |
| 45 |
if (buf_bo) { \ |
| 46 |
OUT_BCS_RELOC64(batch, \ |
| 47 |
buf_bo, \ |
| 48 |
I915_GEM_DOMAIN_RENDER, \ |
| 49 |
is_target ? I915_GEM_DOMAIN_RENDER : 0, \ |
| 50 |
0); \ |
| 51 |
} else { \ |
| 52 |
OUT_BCS_BATCH(batch, 0); \ |
| 53 |
OUT_BCS_BATCH(batch, 0); \ |
| 54 |
} \ |
| 55 |
if (ma) \ |
| 56 |
OUT_BCS_BATCH(batch, i965->intel.mocs_state); \ |
| 57 |
} while (0) |
| 58 |
|
| 59 |
#define OUT_BUFFER_MA_TARGET(buf_bo) OUT_BUFFER(buf_bo, 1, 1) |
| 60 |
#define OUT_BUFFER_MA_REFERENCE(buf_bo) OUT_BUFFER(buf_bo, 0, 1) |
| 61 |
#define OUT_BUFFER_NMA_TARGET(buf_bo) OUT_BUFFER(buf_bo, 1, 0) |
| 62 |
#define OUT_BUFFER_NMA_REFERENCE(buf_bo) OUT_BUFFER(buf_bo, 0, 0) |
| 63 |
|
| 64 |
static void |
| 65 |
gen9_hcpd_init_hevc_surface(VADriverContextP ctx, |
| 66 |
VAPictureParameterBufferHEVC *pic_param, |
| 67 |
struct object_surface *obj_surface, |
| 68 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 69 |
{ |
| 70 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 71 |
GenHevcSurface *gen9_hevc_surface; |
| 72 |
|
| 73 |
if (!obj_surface) |
| 74 |
return; |
| 75 |
|
| 76 |
obj_surface->free_private_data = gen_free_hevc_surface; |
| 77 |
gen9_hevc_surface = obj_surface->private_data; |
| 78 |
|
| 79 |
if (!gen9_hevc_surface) { |
| 80 |
gen9_hevc_surface = calloc(sizeof(GenHevcSurface), 1); |
| 81 |
assert(gen9_hevc_surface); |
| 82 |
gen9_hevc_surface->base.frame_store_id = -1; |
| 83 |
obj_surface->private_data = gen9_hevc_surface; |
| 84 |
} |
| 85 |
|
| 86 |
if (gen9_hevc_surface->motion_vector_temporal_bo == NULL) { |
| 87 |
uint32_t size; |
| 88 |
|
| 89 |
if (gen9_hcpd_context->ctb_size == 16) |
| 90 |
size = ((gen9_hcpd_context->picture_width_in_pixels + 63) >> 6) * |
| 91 |
((gen9_hcpd_context->picture_height_in_pixels + 15) >> 4); |
| 92 |
else |
| 93 |
size = ((gen9_hcpd_context->picture_width_in_pixels + 31) >> 5) * |
| 94 |
((gen9_hcpd_context->picture_height_in_pixels + 31) >> 5); |
| 95 |
|
| 96 |
size <<= 6; /* in unit of 64bytes */ |
| 97 |
gen9_hevc_surface->motion_vector_temporal_bo = dri_bo_alloc(i965->intel.bufmgr, |
| 98 |
"motion vector temporal buffer", |
| 99 |
size, |
| 100 |
0x1000); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
static VAStatus |
| 105 |
gen9_hcpd_hevc_decode_init(VADriverContextP ctx, |
| 106 |
struct decode_state *decode_state, |
| 107 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 108 |
{ |
| 109 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 110 |
VAPictureParameterBufferHEVC *pic_param; |
| 111 |
struct object_surface *obj_surface; |
| 112 |
uint32_t size; |
| 113 |
int size_shift = 3; |
| 114 |
|
| 115 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 116 |
pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer; |
| 117 |
intel_update_hevc_frame_store_index(ctx, |
| 118 |
decode_state, |
| 119 |
pic_param, |
| 120 |
gen9_hcpd_context->reference_surfaces, |
| 121 |
&gen9_hcpd_context->fs_ctx); |
| 122 |
|
| 123 |
gen9_hcpd_context->picture_width_in_pixels = pic_param->pic_width_in_luma_samples; |
| 124 |
gen9_hcpd_context->picture_height_in_pixels = pic_param->pic_height_in_luma_samples; |
| 125 |
gen9_hcpd_context->ctb_size = (1 << (pic_param->log2_min_luma_coding_block_size_minus3 + |
| 126 |
3 + |
| 127 |
pic_param->log2_diff_max_min_luma_coding_block_size)); |
| 128 |
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; |
| 129 |
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; |
| 130 |
gen9_hcpd_context->min_cb_size = (1 << (pic_param->log2_min_luma_coding_block_size_minus3 + 3)); |
| 131 |
gen9_hcpd_context->picture_width_in_min_cb_minus1 = gen9_hcpd_context->picture_width_in_pixels / gen9_hcpd_context->min_cb_size - 1; |
| 132 |
gen9_hcpd_context->picture_height_in_min_cb_minus1 = gen9_hcpd_context->picture_height_in_pixels / gen9_hcpd_context->min_cb_size - 1; |
| 133 |
|
| 134 |
/* Current decoded picture */ |
| 135 |
obj_surface = decode_state->render_object; |
| 136 |
hevc_ensure_surface_bo(ctx, decode_state, obj_surface, pic_param); |
| 137 |
gen9_hcpd_init_hevc_surface(ctx, pic_param, obj_surface, gen9_hcpd_context); |
| 138 |
|
| 139 |
if ((pic_param->bit_depth_luma_minus8 > 0) |
| 140 |
|| (pic_param->bit_depth_chroma_minus8 > 0)) |
| 141 |
size_shift = 2; |
| 142 |
|
| 143 |
size = ALIGN(gen9_hcpd_context->picture_width_in_pixels, 32) >> size_shift; |
| 144 |
size <<= 6; |
| 145 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_line_buffer), "line buffer", size); |
| 146 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_line_buffer), "tile line buffer", size); |
| 147 |
|
| 148 |
size = ALIGN(gen9_hcpd_context->picture_height_in_pixels + 6 * gen9_hcpd_context->picture_height_in_ctbs, 32) >> size_shift; |
| 149 |
size <<= 6; |
| 150 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_column_buffer), "tile column buffer", size); |
| 151 |
|
| 152 |
size = (((gen9_hcpd_context->picture_width_in_pixels + 15) >> 4) * 188 + 9 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9; |
| 153 |
size <<= 6; |
| 154 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_line_buffer), "metadata line buffer", size); |
| 155 |
|
| 156 |
size = (((gen9_hcpd_context->picture_width_in_pixels + 15) >> 4) * 172 + 9 * gen9_hcpd_context->picture_width_in_ctbs + 1023) >> 9; |
| 157 |
size <<= 6; |
| 158 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_line_buffer), "metadata tile line buffer", size); |
| 159 |
|
| 160 |
if (IS_CHERRYVIEW(i965->intel.device_info)) |
| 161 |
size = (((gen9_hcpd_context->picture_height_in_pixels + 15) >> 4) * 256 + 9 * gen9_hcpd_context->picture_height_in_ctbs + 1023) >> 9; |
| 162 |
else |
| 163 |
size = (((gen9_hcpd_context->picture_height_in_pixels + 15) >> 4) * 176 + 89 * gen9_hcpd_context->picture_height_in_ctbs + 1023) >> 9; |
| 164 |
size <<= 6; |
| 165 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_column_buffer), "metadata tile column buffer", size); |
| 166 |
|
| 167 |
size = ALIGN(((gen9_hcpd_context->picture_width_in_pixels >> 1) + 3 * gen9_hcpd_context->picture_width_in_ctbs), 16) >> size_shift; |
| 168 |
size <<= 6; |
| 169 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->sao_line_buffer), "sao line buffer", size); |
| 170 |
|
| 171 |
size = ALIGN(((gen9_hcpd_context->picture_width_in_pixels >> 1) + 6 * gen9_hcpd_context->picture_width_in_ctbs), 16) >> size_shift; |
| 172 |
size <<= 6; |
| 173 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->sao_tile_line_buffer), "sao tile line buffer", size); |
| 174 |
|
| 175 |
size = ALIGN(((gen9_hcpd_context->picture_height_in_pixels >> 1) + 6 * gen9_hcpd_context->picture_height_in_ctbs), 16) >> size_shift; |
| 176 |
size <<= 6; |
| 177 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->sao_tile_column_buffer), "sao tile column buffer", size); |
| 178 |
|
| 179 |
gen9_hcpd_context->first_inter_slice_collocated_ref_idx = 0; |
| 180 |
gen9_hcpd_context->first_inter_slice_collocated_from_l0_flag = 0; |
| 181 |
gen9_hcpd_context->first_inter_slice_valid = 0; |
| 182 |
|
| 183 |
return VA_STATUS_SUCCESS; |
| 184 |
} |
| 185 |
|
| 186 |
static void |
| 187 |
gen9_hcpd_pipe_mode_select(VADriverContextP ctx, |
| 188 |
struct decode_state *decode_state, |
| 189 |
int codec, |
| 190 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 191 |
{ |
| 192 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 193 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 194 |
|
| 195 |
assert((codec == HCP_CODEC_HEVC) || (codec == HCP_CODEC_VP9)); |
| 196 |
|
| 197 |
if (IS_KBL(i965->intel.device_info) || |
| 198 |
IS_GLK(i965->intel.device_info) || |
| 199 |
IS_GEN10(i965->intel.device_info)) { |
| 200 |
BEGIN_BCS_BATCH(batch, 6); |
| 201 |
|
| 202 |
OUT_BCS_BATCH(batch, HCP_PIPE_MODE_SELECT | (6 - 2)); |
| 203 |
} else { |
| 204 |
BEGIN_BCS_BATCH(batch, 4); |
| 205 |
|
| 206 |
OUT_BCS_BATCH(batch, HCP_PIPE_MODE_SELECT | (4 - 2)); |
| 207 |
} |
| 208 |
OUT_BCS_BATCH(batch, |
| 209 |
(codec << 5) | |
| 210 |
(0 << 3) | /* disable Pic Status / Error Report */ |
| 211 |
HCP_CODEC_SELECT_DECODE); |
| 212 |
OUT_BCS_BATCH(batch, 0); |
| 213 |
OUT_BCS_BATCH(batch, 0); |
| 214 |
|
| 215 |
if (IS_KBL(i965->intel.device_info) || |
| 216 |
IS_GLK(i965->intel.device_info)) { |
| 217 |
if (codec == HCP_CODEC_VP9) |
| 218 |
OUT_BCS_BATCH(batch, 1 << 6); |
| 219 |
else |
| 220 |
OUT_BCS_BATCH(batch, 0); |
| 221 |
|
| 222 |
OUT_BCS_BATCH(batch, 0); |
| 223 |
} else if (IS_GEN10(i965->intel.device_info)) { |
| 224 |
OUT_BCS_BATCH(batch, 0); |
| 225 |
OUT_BCS_BATCH(batch, 0); |
| 226 |
} |
| 227 |
|
| 228 |
ADVANCE_BCS_BATCH(batch); |
| 229 |
} |
| 230 |
|
| 231 |
static void |
| 232 |
gen9_hcpd_surface_state(VADriverContextP ctx, |
| 233 |
struct decode_state *decode_state, |
| 234 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 235 |
{ |
| 236 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 237 |
struct object_surface *obj_surface = decode_state->render_object; |
| 238 |
unsigned int y_cb_offset; |
| 239 |
VAPictureParameterBufferHEVC *pic_param; |
| 240 |
|
| 241 |
assert(obj_surface); |
| 242 |
|
| 243 |
pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer; |
| 244 |
y_cb_offset = obj_surface->y_cb_offset; |
| 245 |
|
| 246 |
BEGIN_BCS_BATCH(batch, 3); |
| 247 |
|
| 248 |
OUT_BCS_BATCH(batch, HCP_SURFACE_STATE | (3 - 2)); |
| 249 |
OUT_BCS_BATCH(batch, |
| 250 |
(0 << 28) | /* surface id */ |
| 251 |
(obj_surface->width - 1)); /* pitch - 1 */ |
| 252 |
if ((pic_param->bit_depth_luma_minus8 > 0) |
| 253 |
|| (pic_param->bit_depth_chroma_minus8 > 0)) { |
| 254 |
OUT_BCS_BATCH(batch, |
| 255 |
(SURFACE_FORMAT_P010 << 28) | |
| 256 |
y_cb_offset); |
| 257 |
} else { |
| 258 |
OUT_BCS_BATCH(batch, |
| 259 |
(SURFACE_FORMAT_PLANAR_420_8 << 28) | |
| 260 |
y_cb_offset); |
| 261 |
} |
| 262 |
|
| 263 |
ADVANCE_BCS_BATCH(batch); |
| 264 |
} |
| 265 |
|
| 266 |
static void |
| 267 |
gen9_hcpd_pipe_buf_addr_state(VADriverContextP ctx, |
| 268 |
struct decode_state *decode_state, |
| 269 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 270 |
{ |
| 271 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 272 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 273 |
struct object_surface *obj_surface; |
| 274 |
GenHevcSurface *gen9_hevc_surface; |
| 275 |
int i; |
| 276 |
|
| 277 |
BEGIN_BCS_BATCH(batch, 95); |
| 278 |
|
| 279 |
OUT_BCS_BATCH(batch, HCP_PIPE_BUF_ADDR_STATE | (95 - 2)); |
| 280 |
|
| 281 |
obj_surface = decode_state->render_object; |
| 282 |
assert(obj_surface && obj_surface->bo); |
| 283 |
gen9_hevc_surface = obj_surface->private_data; |
| 284 |
assert(gen9_hevc_surface && gen9_hevc_surface->motion_vector_temporal_bo); |
| 285 |
|
| 286 |
OUT_BUFFER_MA_TARGET(obj_surface->bo); /* DW 1..3 */ |
| 287 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_line_buffer.bo);/* DW 4..6 */ |
| 288 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_tile_line_buffer.bo); /* DW 7..9 */ |
| 289 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_tile_column_buffer.bo); /* DW 10..12 */ |
| 290 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_line_buffer.bo); /* DW 13..15 */ |
| 291 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_tile_line_buffer.bo); /* DW 16..18 */ |
| 292 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_tile_column_buffer.bo); /* DW 19..21 */ |
| 293 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->sao_line_buffer.bo); /* DW 22..24 */ |
| 294 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->sao_tile_line_buffer.bo); /* DW 25..27 */ |
| 295 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->sao_tile_column_buffer.bo); /* DW 28..30 */ |
| 296 |
OUT_BUFFER_MA_TARGET(gen9_hevc_surface->motion_vector_temporal_bo); /* DW 31..33 */ |
| 297 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 34..36, reserved */ |
| 298 |
|
| 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 |
|
| 302 |
if (obj_surface) |
| 303 |
OUT_BUFFER_NMA_REFERENCE(obj_surface->bo); |
| 304 |
else |
| 305 |
OUT_BUFFER_NMA_REFERENCE(NULL); |
| 306 |
} |
| 307 |
OUT_BCS_BATCH(batch, 0); /* DW 53, memory address attributes */ |
| 308 |
|
| 309 |
OUT_BUFFER_MA_REFERENCE(NULL); /* DW 54..56, ignore for decoding mode */ |
| 310 |
OUT_BUFFER_MA_TARGET(NULL); |
| 311 |
OUT_BUFFER_MA_TARGET(NULL); |
| 312 |
OUT_BUFFER_MA_TARGET(NULL); |
| 313 |
|
| 314 |
for (i = 0; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) { |
| 315 |
obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface; |
| 316 |
gen9_hevc_surface = NULL; |
| 317 |
|
| 318 |
if (obj_surface && obj_surface->private_data) |
| 319 |
gen9_hevc_surface = obj_surface->private_data; |
| 320 |
|
| 321 |
if (gen9_hevc_surface) |
| 322 |
OUT_BUFFER_NMA_REFERENCE(gen9_hevc_surface->motion_vector_temporal_bo); |
| 323 |
else |
| 324 |
OUT_BUFFER_NMA_REFERENCE(NULL); |
| 325 |
} |
| 326 |
OUT_BCS_BATCH(batch, 0); /* DW 82, memory address attributes */ |
| 327 |
|
| 328 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 83..85, ignore for HEVC */ |
| 329 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 86..88, ignore for HEVC */ |
| 330 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 89..91, ignore for HEVC */ |
| 331 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 92..94, ignore for HEVC */ |
| 332 |
|
| 333 |
ADVANCE_BCS_BATCH(batch); |
| 334 |
} |
| 335 |
|
| 336 |
static void |
| 337 |
gen9_hcpd_ind_obj_base_addr_state(VADriverContextP ctx, |
| 338 |
dri_bo *slice_data_bo, |
| 339 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 340 |
{ |
| 341 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 342 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 343 |
|
| 344 |
BEGIN_BCS_BATCH(batch, 14); |
| 345 |
|
| 346 |
OUT_BCS_BATCH(batch, HCP_IND_OBJ_BASE_ADDR_STATE | (14 - 2)); |
| 347 |
OUT_BUFFER_MA_REFERENCE(slice_data_bo); /* DW 1..3 */ |
| 348 |
OUT_BCS_RELOC64(batch, slice_data_bo, I915_GEM_DOMAIN_RENDER, 0, ALIGN(slice_data_bo->size, 4096)); |
| 349 |
OUT_BUFFER_MA_REFERENCE(NULL); /* DW 6..8, CU, ignored */ |
| 350 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 9..11, PAK-BSE, ignored */ |
| 351 |
OUT_BUFFER_NMA_TARGET(NULL); /* DW 12..13, Upper Bound */ |
| 352 |
|
| 353 |
ADVANCE_BCS_BATCH(batch); |
| 354 |
} |
| 355 |
|
| 356 |
static void |
| 357 |
gen10_hcpd_ind_obj_base_addr_state(VADriverContextP ctx, |
| 358 |
dri_bo *slice_data_bo, |
| 359 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 360 |
{ |
| 361 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 362 |
|
| 363 |
BEGIN_BCS_BATCH(batch, 29); |
| 364 |
|
| 365 |
OUT_BCS_BATCH(batch, HCP_IND_OBJ_BASE_ADDR_STATE | (29 - 2)); |
| 366 |
|
| 367 |
/* DW1..5 indirect bitstream*/ |
| 368 |
OUT_RELOC64(batch, |
| 369 |
slice_data_bo, |
| 370 |
I915_GEM_DOMAIN_INSTRUCTION, 0, |
| 371 |
0); |
| 372 |
OUT_BCS_BATCH(batch, 0); |
| 373 |
OUT_BCS_RELOC64(batch, slice_data_bo, |
| 374 |
I915_GEM_DOMAIN_RENDER, |
| 375 |
0, ALIGN(slice_data_bo->size, 4096)); |
| 376 |
|
| 377 |
/* DW 6..8 Indirect CU */ |
| 378 |
OUT_BCS_BATCH(batch, 0); |
| 379 |
OUT_BCS_BATCH(batch, 0); |
| 380 |
OUT_BCS_BATCH(batch, 0); |
| 381 |
|
| 382 |
/* DW 9..13 Indirect PAK_PSE */ |
| 383 |
OUT_BCS_BATCH(batch, 0); |
| 384 |
OUT_BCS_BATCH(batch, 0); |
| 385 |
OUT_BCS_BATCH(batch, 0); |
| 386 |
OUT_BCS_BATCH(batch, 0); |
| 387 |
OUT_BCS_BATCH(batch, 0); |
| 388 |
|
| 389 |
/* DW 14..16. Compressed_header */ |
| 390 |
OUT_BCS_BATCH(batch, 0); |
| 391 |
OUT_BCS_BATCH(batch, 0); |
| 392 |
OUT_BCS_BATCH(batch, 0); |
| 393 |
|
| 394 |
/* DW 17..19 . Prob-counter Stream-out */ |
| 395 |
OUT_BCS_BATCH(batch, 0); |
| 396 |
OUT_BCS_BATCH(batch, 0); |
| 397 |
OUT_BCS_BATCH(batch, 0); |
| 398 |
|
| 399 |
/* DW 20..22. Prob-delta stream-in */ |
| 400 |
OUT_BCS_BATCH(batch, 0); |
| 401 |
OUT_BCS_BATCH(batch, 0); |
| 402 |
OUT_BCS_BATCH(batch, 0); |
| 403 |
|
| 404 |
/* DW 23..25. Tile Record */ |
| 405 |
OUT_BCS_BATCH(batch, 0); |
| 406 |
OUT_BCS_BATCH(batch, 0); |
| 407 |
OUT_BCS_BATCH(batch, 0); |
| 408 |
|
| 409 |
/* DW 26..28. CU level statics buffer */ |
| 410 |
OUT_BCS_BATCH(batch, 0); |
| 411 |
OUT_BCS_BATCH(batch, 0); |
| 412 |
OUT_BCS_BATCH(batch, 0); |
| 413 |
|
| 414 |
ADVANCE_BCS_BATCH(batch); |
| 415 |
} |
| 416 |
|
| 417 |
static void |
| 418 |
gen9_hcpd_qm_state(VADriverContextP ctx, |
| 419 |
int size_id, |
| 420 |
int color_component, |
| 421 |
int pred_type, |
| 422 |
int dc, |
| 423 |
unsigned char *qm, |
| 424 |
int qm_length, |
| 425 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 426 |
{ |
| 427 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 428 |
unsigned char qm_buffer[64]; |
| 429 |
|
| 430 |
assert(qm_length <= 64); |
| 431 |
memset(qm_buffer, 0, sizeof(qm_buffer)); |
| 432 |
memcpy(qm_buffer, qm, qm_length); |
| 433 |
|
| 434 |
BEGIN_BCS_BATCH(batch, 18); |
| 435 |
|
| 436 |
OUT_BCS_BATCH(batch, HCP_QM_STATE | (18 - 2)); |
| 437 |
OUT_BCS_BATCH(batch, |
| 438 |
dc << 5 | |
| 439 |
color_component << 3 | |
| 440 |
size_id << 1 | |
| 441 |
pred_type); |
| 442 |
intel_batchbuffer_data(batch, qm_buffer, 64); |
| 443 |
|
| 444 |
ADVANCE_BCS_BATCH(batch); |
| 445 |
} |
| 446 |
|
| 447 |
static void |
| 448 |
gen9_hcpd_hevc_qm_state(VADriverContextP ctx, |
| 449 |
struct decode_state *decode_state, |
| 450 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 451 |
{ |
| 452 |
VAIQMatrixBufferHEVC *iq_matrix; |
| 453 |
VAPictureParameterBufferHEVC *pic_param; |
| 454 |
int i; |
| 455 |
|
| 456 |
if (decode_state->iq_matrix && decode_state->iq_matrix->buffer) |
| 457 |
iq_matrix = (VAIQMatrixBufferHEVC *)decode_state->iq_matrix->buffer; |
| 458 |
else |
| 459 |
iq_matrix = &gen9_hcpd_context->iq_matrix_hevc; |
| 460 |
|
| 461 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 462 |
pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer; |
| 463 |
|
| 464 |
if (!pic_param->pic_fields.bits.scaling_list_enabled_flag) |
| 465 |
iq_matrix = &gen9_hcpd_context->iq_matrix_hevc; |
| 466 |
|
| 467 |
for (i = 0; i < 6; i++) { |
| 468 |
gen9_hcpd_qm_state(ctx, |
| 469 |
0, i % 3, i / 3, 0, |
| 470 |
iq_matrix->ScalingList4x4[i], 16, |
| 471 |
gen9_hcpd_context); |
| 472 |
} |
| 473 |
|
| 474 |
for (i = 0; i < 6; i++) { |
| 475 |
gen9_hcpd_qm_state(ctx, |
| 476 |
1, i % 3, i / 3, 0, |
| 477 |
iq_matrix->ScalingList8x8[i], 64, |
| 478 |
gen9_hcpd_context); |
| 479 |
} |
| 480 |
|
| 481 |
for (i = 0; i < 6; i++) { |
| 482 |
gen9_hcpd_qm_state(ctx, |
| 483 |
2, i % 3, i / 3, iq_matrix->ScalingListDC16x16[i], |
| 484 |
iq_matrix->ScalingList16x16[i], 64, |
| 485 |
gen9_hcpd_context); |
| 486 |
} |
| 487 |
|
| 488 |
for (i = 0; i < 2; i++) { |
| 489 |
gen9_hcpd_qm_state(ctx, |
| 490 |
3, 0, i % 2, iq_matrix->ScalingListDC32x32[i], |
| 491 |
iq_matrix->ScalingList32x32[i], 64, |
| 492 |
gen9_hcpd_context); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
static void |
| 497 |
gen9_hcpd_pic_state(VADriverContextP ctx, |
| 498 |
struct decode_state *decode_state, |
| 499 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 500 |
{ |
| 501 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 502 |
VAPictureParameterBufferHEVC *pic_param; |
| 503 |
int max_pcm_size_minus3 = 0, min_pcm_size_minus3 = 0; |
| 504 |
int pcm_sample_bit_depth_luma_minus1 = 7, pcm_sample_bit_depth_chroma_minus1 = 7; |
| 505 |
/* |
| 506 |
* 7.4.3.1 |
| 507 |
* |
| 508 |
* When not present, the value of loop_filter_across_tiles_enabled_flag |
| 509 |
* is inferred to be equal to 1. |
| 510 |
*/ |
| 511 |
int loop_filter_across_tiles_enabled_flag = 1; |
| 512 |
|
| 513 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 514 |
pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer; |
| 515 |
|
| 516 |
if (pic_param->pic_fields.bits.pcm_enabled_flag) { |
| 517 |
max_pcm_size_minus3 = pic_param->log2_min_pcm_luma_coding_block_size_minus3 + |
| 518 |
pic_param->log2_diff_max_min_pcm_luma_coding_block_size; |
| 519 |
min_pcm_size_minus3 = pic_param->log2_min_pcm_luma_coding_block_size_minus3; |
| 520 |
pcm_sample_bit_depth_luma_minus1 = (pic_param->pcm_sample_bit_depth_luma_minus1 & 0x0f); |
| 521 |
pcm_sample_bit_depth_chroma_minus1 = (pic_param->pcm_sample_bit_depth_chroma_minus1 & 0x0f); |
| 522 |
} else { |
| 523 |
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); |
| 524 |
} |
| 525 |
|
| 526 |
if (pic_param->pic_fields.bits.tiles_enabled_flag) |
| 527 |
loop_filter_across_tiles_enabled_flag = pic_param->pic_fields.bits.loop_filter_across_tiles_enabled_flag; |
| 528 |
|
| 529 |
BEGIN_BCS_BATCH(batch, 19); |
| 530 |
|
| 531 |
OUT_BCS_BATCH(batch, HCP_PIC_STATE | (19 - 2)); |
| 532 |
|
| 533 |
OUT_BCS_BATCH(batch, |
| 534 |
gen9_hcpd_context->picture_height_in_min_cb_minus1 << 16 | |
| 535 |
gen9_hcpd_context->picture_width_in_min_cb_minus1); |
| 536 |
OUT_BCS_BATCH(batch, |
| 537 |
max_pcm_size_minus3 << 10 | |
| 538 |
min_pcm_size_minus3 << 8 | |
| 539 |
(pic_param->log2_min_transform_block_size_minus2 + |
| 540 |
pic_param->log2_diff_max_min_transform_block_size) << 6 | |
| 541 |
pic_param->log2_min_transform_block_size_minus2 << 4 | |
| 542 |
(pic_param->log2_min_luma_coding_block_size_minus3 + |
| 543 |
pic_param->log2_diff_max_min_luma_coding_block_size) << 2 | |
| 544 |
pic_param->log2_min_luma_coding_block_size_minus3); |
| 545 |
OUT_BCS_BATCH(batch, 0); /* DW 3, ignored */ |
| 546 |
OUT_BCS_BATCH(batch, |
| 547 |
0 << 27 | |
| 548 |
pic_param->pic_fields.bits.strong_intra_smoothing_enabled_flag << 26 | |
| 549 |
pic_param->pic_fields.bits.transquant_bypass_enabled_flag << 25 | |
| 550 |
pic_param->pic_fields.bits.amp_enabled_flag << 23 | |
| 551 |
pic_param->pic_fields.bits.transform_skip_enabled_flag << 22 | |
| 552 |
!(pic_param->CurrPic.flags & VA_PICTURE_HEVC_BOTTOM_FIELD) << 21 | |
| 553 |
!!(pic_param->CurrPic.flags & VA_PICTURE_HEVC_FIELD_PIC) << 20 | |
| 554 |
pic_param->pic_fields.bits.weighted_pred_flag << 19 | |
| 555 |
pic_param->pic_fields.bits.weighted_bipred_flag << 18 | |
| 556 |
pic_param->pic_fields.bits.tiles_enabled_flag << 17 | |
| 557 |
pic_param->pic_fields.bits.entropy_coding_sync_enabled_flag << 16 | |
| 558 |
loop_filter_across_tiles_enabled_flag << 15 | |
| 559 |
pic_param->pic_fields.bits.sign_data_hiding_enabled_flag << 13 | |
| 560 |
pic_param->log2_parallel_merge_level_minus2 << 10 | |
| 561 |
pic_param->pic_fields.bits.constrained_intra_pred_flag << 9 | |
| 562 |
pic_param->pic_fields.bits.pcm_loop_filter_disabled_flag << 8 | |
| 563 |
(pic_param->diff_cu_qp_delta_depth & 0x03) << 6 | |
| 564 |
pic_param->pic_fields.bits.cu_qp_delta_enabled_flag << 5 | |
| 565 |
pic_param->pic_fields.bits.pcm_enabled_flag << 4 | |
| 566 |
pic_param->slice_parsing_fields.bits.sample_adaptive_offset_enabled_flag << 3 | |
| 567 |
0); |
| 568 |
OUT_BCS_BATCH(batch, |
| 569 |
pic_param->bit_depth_luma_minus8 << 27 | |
| 570 |
pic_param->bit_depth_chroma_minus8 << 24 | |
| 571 |
pcm_sample_bit_depth_luma_minus1 << 20 | |
| 572 |
pcm_sample_bit_depth_chroma_minus1 << 16 | |
| 573 |
pic_param->max_transform_hierarchy_depth_inter << 13 | |
| 574 |
pic_param->max_transform_hierarchy_depth_intra << 10 | |
| 575 |
(pic_param->pps_cr_qp_offset & 0x1f) << 5 | |
| 576 |
(pic_param->pps_cb_qp_offset & 0x1f)); |
| 577 |
OUT_BCS_BATCH(batch, |
| 578 |
0 << 29 | |
| 579 |
0); |
| 580 |
OUT_BCS_BATCH(batch, 0); |
| 581 |
OUT_BCS_BATCH(batch, 0); |
| 582 |
OUT_BCS_BATCH(batch, 0); |
| 583 |
OUT_BCS_BATCH(batch, 0); /* DW 10 */ |
| 584 |
OUT_BCS_BATCH(batch, 0); |
| 585 |
OUT_BCS_BATCH(batch, 0); |
| 586 |
OUT_BCS_BATCH(batch, 0); |
| 587 |
OUT_BCS_BATCH(batch, 0); |
| 588 |
OUT_BCS_BATCH(batch, 0); /* DW 15 */ |
| 589 |
OUT_BCS_BATCH(batch, 0); |
| 590 |
OUT_BCS_BATCH(batch, 0); |
| 591 |
OUT_BCS_BATCH(batch, 0); |
| 592 |
|
| 593 |
ADVANCE_BCS_BATCH(batch); |
| 594 |
} |
| 595 |
|
| 596 |
static void |
| 597 |
gen9_hcpd_tile_state(VADriverContextP ctx, |
| 598 |
struct decode_state *decode_state, |
| 599 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 600 |
{ |
| 601 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 602 |
VAPictureParameterBufferHEVC *pic_param; |
| 603 |
uint8_t pos_col[20], pos_row[24]; |
| 604 |
int i; |
| 605 |
|
| 606 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 607 |
pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer; |
| 608 |
|
| 609 |
memset(pos_col, 0, sizeof(pos_col)); |
| 610 |
memset(pos_row, 0, sizeof(pos_row)); |
| 611 |
|
| 612 |
for (i = 0; i <= MIN(pic_param->num_tile_columns_minus1, 18); i++) |
| 613 |
pos_col[i + 1] = pos_col[i] + pic_param->column_width_minus1[i] + 1; |
| 614 |
|
| 615 |
for (i = 0; i <= MIN(pic_param->num_tile_rows_minus1, 20); i++) |
| 616 |
pos_row[i + 1] = pos_row[i] + pic_param->row_height_minus1[i] + 1; |
| 617 |
|
| 618 |
BEGIN_BCS_BATCH(batch, 13); |
| 619 |
|
| 620 |
OUT_BCS_BATCH(batch, HCP_TILE_STATE | (13 - 2)); |
| 621 |
|
| 622 |
OUT_BCS_BATCH(batch, |
| 623 |
pic_param->num_tile_columns_minus1 << 5 | |
| 624 |
pic_param->num_tile_rows_minus1); |
| 625 |
intel_batchbuffer_data(batch, pos_col, 20); |
| 626 |
intel_batchbuffer_data(batch, pos_row, 24); |
| 627 |
|
| 628 |
ADVANCE_BCS_BATCH(batch); |
| 629 |
} |
| 630 |
|
| 631 |
static int |
| 632 |
gen9_hcpd_get_reference_picture_frame_id(VAPictureHEVC *ref_pic, |
| 633 |
GenFrameStore frame_store[MAX_GEN_HCP_REFERENCE_FRAMES]) |
| 634 |
{ |
| 635 |
int i; |
| 636 |
|
| 637 |
if (ref_pic->picture_id == VA_INVALID_ID || |
| 638 |
(ref_pic->flags & VA_PICTURE_HEVC_INVALID)) |
| 639 |
return 0; |
| 640 |
|
| 641 |
for (i = 0; i < MAX_GEN_HCP_REFERENCE_FRAMES; i++) { |
| 642 |
if (ref_pic->picture_id == frame_store[i].surface_id) { |
| 643 |
assert(frame_store[i].frame_store_id < MAX_GEN_HCP_REFERENCE_FRAMES); |
| 644 |
return frame_store[i].frame_store_id; |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
/* Should never get here !!! */ |
| 649 |
assert(0); |
| 650 |
return 0; |
| 651 |
} |
| 652 |
|
| 653 |
static void |
| 654 |
gen9_hcpd_ref_idx_state_1(struct intel_batchbuffer *batch, |
| 655 |
int list, |
| 656 |
VAPictureParameterBufferHEVC *pic_param, |
| 657 |
VASliceParameterBufferHEVC *slice_param, |
| 658 |
GenFrameStore frame_store[MAX_GEN_HCP_REFERENCE_FRAMES]) |
| 659 |
{ |
| 660 |
int i; |
| 661 |
uint8_t num_ref_minus1 = (list ? slice_param->num_ref_idx_l1_active_minus1 : slice_param->num_ref_idx_l0_active_minus1); |
| 662 |
uint8_t *ref_list = slice_param->RefPicList[list]; |
| 663 |
|
| 664 |
BEGIN_BCS_BATCH(batch, 18); |
| 665 |
|
| 666 |
OUT_BCS_BATCH(batch, HCP_REF_IDX_STATE | (18 - 2)); |
| 667 |
OUT_BCS_BATCH(batch, |
| 668 |
num_ref_minus1 << 1 | |
| 669 |
list); |
| 670 |
|
| 671 |
for (i = 0; i < 16; i++) { |
| 672 |
if (i < MIN((num_ref_minus1 + 1), 15)) { |
| 673 |
VAPictureHEVC *ref_pic = &pic_param->ReferenceFrames[ref_list[i]]; |
| 674 |
VAPictureHEVC *curr_pic = &pic_param->CurrPic; |
| 675 |
|
| 676 |
OUT_BCS_BATCH(batch, |
| 677 |
!(ref_pic->flags & VA_PICTURE_HEVC_BOTTOM_FIELD) << 15 | |
| 678 |
!!(ref_pic->flags & VA_PICTURE_HEVC_FIELD_PIC) << 14 | |
| 679 |
!!(ref_pic->flags & VA_PICTURE_HEVC_LONG_TERM_REFERENCE) << 13 | |
| 680 |
0 << 12 | |
| 681 |
0 << 11 | |
| 682 |
gen9_hcpd_get_reference_picture_frame_id(ref_pic, frame_store) << 8 | |
| 683 |
(CLAMP(-128, 127, curr_pic->pic_order_cnt - ref_pic->pic_order_cnt) & 0xff)); |
| 684 |
} else { |
| 685 |
OUT_BCS_BATCH(batch, 0); |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
ADVANCE_BCS_BATCH(batch); |
| 690 |
} |
| 691 |
|
| 692 |
static void |
| 693 |
gen9_hcpd_ref_idx_state(VADriverContextP ctx, |
| 694 |
VAPictureParameterBufferHEVC *pic_param, |
| 695 |
VASliceParameterBufferHEVC *slice_param, |
| 696 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 697 |
{ |
| 698 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 699 |
|
| 700 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I) |
| 701 |
return; |
| 702 |
|
| 703 |
gen9_hcpd_ref_idx_state_1(batch, 0, pic_param, slice_param, gen9_hcpd_context->reference_surfaces); |
| 704 |
|
| 705 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P) |
| 706 |
return; |
| 707 |
|
| 708 |
gen9_hcpd_ref_idx_state_1(batch, 1, pic_param, slice_param, gen9_hcpd_context->reference_surfaces); |
| 709 |
} |
| 710 |
|
| 711 |
static void |
| 712 |
gen9_hcpd_weightoffset_state_1(struct intel_batchbuffer *batch, |
| 713 |
int list, |
| 714 |
VASliceParameterBufferHEVC *slice_param) |
| 715 |
{ |
| 716 |
int i; |
| 717 |
uint8_t num_ref_minus1 = (list == 1) ? slice_param->num_ref_idx_l1_active_minus1 : slice_param->num_ref_idx_l0_active_minus1; |
| 718 |
int8_t *luma_offset = (list == 1) ? slice_param->luma_offset_l1 : slice_param->luma_offset_l0; |
| 719 |
int8_t *delta_luma_weight = (list == 1) ? slice_param->delta_luma_weight_l1 : slice_param->delta_luma_weight_l0; |
| 720 |
int8_t (* chroma_offset)[2] = (list == 1) ? slice_param->ChromaOffsetL1 : slice_param->ChromaOffsetL0; |
| 721 |
int8_t (* delta_chroma_weight)[2] = (list == 1) ? slice_param->delta_chroma_weight_l1 : slice_param->delta_chroma_weight_l0; |
| 722 |
|
| 723 |
BEGIN_BCS_BATCH(batch, 34); |
| 724 |
|
| 725 |
OUT_BCS_BATCH(batch, HCP_WEIGHTOFFSET | (34 - 2)); |
| 726 |
OUT_BCS_BATCH(batch, list); |
| 727 |
|
| 728 |
for (i = 0; i < 16; i++) { |
| 729 |
if (i < MIN((num_ref_minus1 + 1), 15)) { |
| 730 |
OUT_BCS_BATCH(batch, |
| 731 |
(luma_offset[i] & 0xff) << 8 | |
| 732 |
(delta_luma_weight[i] & 0xff)); |
| 733 |
} else { |
| 734 |
OUT_BCS_BATCH(batch, 0); |
| 735 |
} |
| 736 |
} |
| 737 |
for (i = 0; i < 16; i++) { |
| 738 |
if (i < MIN((num_ref_minus1 + 1), 15)) { |
| 739 |
OUT_BCS_BATCH(batch, |
| 740 |
(chroma_offset[i][1] & 0xff) << 24 | |
| 741 |
(delta_chroma_weight[i][1] & 0xff) << 16 | |
| 742 |
(chroma_offset[i][0] & 0xff) << 8 | |
| 743 |
(delta_chroma_weight[i][0] & 0xff)); |
| 744 |
} else { |
| 745 |
OUT_BCS_BATCH(batch, 0); |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
ADVANCE_BCS_BATCH(batch); |
| 750 |
} |
| 751 |
|
| 752 |
static void |
| 753 |
gen9_hcpd_weightoffset_state(VADriverContextP ctx, |
| 754 |
VAPictureParameterBufferHEVC *pic_param, |
| 755 |
VASliceParameterBufferHEVC *slice_param, |
| 756 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 757 |
{ |
| 758 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 759 |
|
| 760 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I) |
| 761 |
return; |
| 762 |
|
| 763 |
if ((slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P && |
| 764 |
!pic_param->pic_fields.bits.weighted_pred_flag) || |
| 765 |
(slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B && |
| 766 |
!pic_param->pic_fields.bits.weighted_bipred_flag)) |
| 767 |
return; |
| 768 |
|
| 769 |
gen9_hcpd_weightoffset_state_1(batch, 0, slice_param); |
| 770 |
|
| 771 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P) |
| 772 |
return; |
| 773 |
|
| 774 |
gen9_hcpd_weightoffset_state_1(batch, 1, slice_param); |
| 775 |
} |
| 776 |
|
| 777 |
static int |
| 778 |
gen9_hcpd_get_collocated_ref_idx(VADriverContextP ctx, |
| 779 |
VAPictureParameterBufferHEVC *pic_param, |
| 780 |
VASliceParameterBufferHEVC *slice_param, |
| 781 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 782 |
{ |
| 783 |
uint8_t *ref_list; |
| 784 |
VAPictureHEVC *ref_pic; |
| 785 |
|
| 786 |
if (slice_param->collocated_ref_idx > 14) |
| 787 |
return 0; |
| 788 |
|
| 789 |
if (!slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag) |
| 790 |
return 0; |
| 791 |
|
| 792 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I) |
| 793 |
return 0; |
| 794 |
|
| 795 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P || |
| 796 |
(slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B && |
| 797 |
slice_param->LongSliceFlags.fields.collocated_from_l0_flag)) |
| 798 |
ref_list = slice_param->RefPicList[0]; |
| 799 |
else { |
| 800 |
assert(slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_B); |
| 801 |
ref_list = slice_param->RefPicList[1]; |
| 802 |
} |
| 803 |
|
| 804 |
ref_pic = &pic_param->ReferenceFrames[ref_list[slice_param->collocated_ref_idx]]; |
| 805 |
|
| 806 |
return gen9_hcpd_get_reference_picture_frame_id(ref_pic, gen9_hcpd_context->reference_surfaces); |
| 807 |
} |
| 808 |
|
| 809 |
static int |
| 810 |
gen9_hcpd_is_list_low_delay(uint8_t ref_list_count, |
| 811 |
uint8_t ref_list[15], |
| 812 |
VAPictureHEVC *curr_pic, |
| 813 |
VAPictureHEVC ref_surfaces[15]) |
| 814 |
{ |
| 815 |
int i; |
| 816 |
|
| 817 |
for (i = 0; i < MIN(ref_list_count, 15); i++) { |
| 818 |
VAPictureHEVC *ref_pic; |
| 819 |
|
| 820 |
if (ref_list[i] > 14) |
| 821 |
continue; |
| 822 |
|
| 823 |
ref_pic = &ref_surfaces[ref_list[i]]; |
| 824 |
|
| 825 |
if (ref_pic->pic_order_cnt > curr_pic->pic_order_cnt) |
| 826 |
return 0; |
| 827 |
} |
| 828 |
|
| 829 |
return 1; |
| 830 |
} |
| 831 |
|
| 832 |
static int |
| 833 |
gen9_hcpd_is_low_delay(VADriverContextP ctx, |
| 834 |
VAPictureParameterBufferHEVC *pic_param, |
| 835 |
VASliceParameterBufferHEVC *slice_param) |
| 836 |
{ |
| 837 |
if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I) |
| 838 |
return 0; |
| 839 |
else if (slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_P) |
| 840 |
return gen9_hcpd_is_list_low_delay(slice_param->num_ref_idx_l0_active_minus1 + 1, |
| 841 |
slice_param->RefPicList[0], |
| 842 |
&pic_param->CurrPic, |
| 843 |
pic_param->ReferenceFrames); |
| 844 |
else |
| 845 |
return gen9_hcpd_is_list_low_delay(slice_param->num_ref_idx_l0_active_minus1 + 1, |
| 846 |
slice_param->RefPicList[0], |
| 847 |
&pic_param->CurrPic, |
| 848 |
pic_param->ReferenceFrames) && |
| 849 |
gen9_hcpd_is_list_low_delay(slice_param->num_ref_idx_l1_active_minus1 + 1, |
| 850 |
slice_param->RefPicList[1], |
| 851 |
&pic_param->CurrPic, |
| 852 |
pic_param->ReferenceFrames); |
| 853 |
} |
| 854 |
|
| 855 |
static void |
| 856 |
gen9_hcpd_slice_state(VADriverContextP ctx, |
| 857 |
VAPictureParameterBufferHEVC *pic_param, |
| 858 |
VASliceParameterBufferHEVC *slice_param, |
| 859 |
VASliceParameterBufferHEVC *next_slice_param, |
| 860 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 861 |
{ |
| 862 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 863 |
int slice_hor_pos, slice_ver_pos, next_slice_hor_pos, next_slice_ver_pos; |
| 864 |
unsigned short collocated_ref_idx, collocated_from_l0_flag; |
| 865 |
int sliceqp_sign_flag = 0, sliceqp = 0; |
| 866 |
|
| 867 |
slice_hor_pos = slice_param->slice_segment_address % gen9_hcpd_context->picture_width_in_ctbs; |
| 868 |
slice_ver_pos = slice_param->slice_segment_address / gen9_hcpd_context->picture_width_in_ctbs; |
| 869 |
|
| 870 |
if (next_slice_param) { |
| 871 |
next_slice_hor_pos = next_slice_param->slice_segment_address % gen9_hcpd_context->picture_width_in_ctbs; |
| 872 |
next_slice_ver_pos = next_slice_param->slice_segment_address / gen9_hcpd_context->picture_width_in_ctbs; |
| 873 |
} else { |
| 874 |
next_slice_hor_pos = 0; |
| 875 |
next_slice_ver_pos = 0; |
| 876 |
} |
| 877 |
|
| 878 |
collocated_ref_idx = gen9_hcpd_get_collocated_ref_idx(ctx, pic_param, slice_param, gen9_hcpd_context); |
| 879 |
collocated_from_l0_flag = slice_param->LongSliceFlags.fields.collocated_from_l0_flag; |
| 880 |
|
| 881 |
if ((!gen9_hcpd_context->first_inter_slice_valid) && |
| 882 |
(slice_param->LongSliceFlags.fields.slice_type != HEVC_SLICE_I) && |
| 883 |
slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag) { |
| 884 |
gen9_hcpd_context->first_inter_slice_collocated_ref_idx = collocated_ref_idx; |
| 885 |
gen9_hcpd_context->first_inter_slice_collocated_from_l0_flag = collocated_from_l0_flag; |
| 886 |
gen9_hcpd_context->first_inter_slice_valid = 1; |
| 887 |
} |
| 888 |
|
| 889 |
/* HW requirement */ |
| 890 |
if (gen9_hcpd_context->first_inter_slice_valid && |
| 891 |
((slice_param->LongSliceFlags.fields.slice_type == HEVC_SLICE_I) || |
| 892 |
(!slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag))) { |
| 893 |
collocated_ref_idx = gen9_hcpd_context->first_inter_slice_collocated_ref_idx; |
| 894 |
collocated_from_l0_flag = gen9_hcpd_context->first_inter_slice_collocated_from_l0_flag; |
| 895 |
} |
| 896 |
|
| 897 |
sliceqp = pic_param->init_qp_minus26 + 26 + slice_param->slice_qp_delta; |
| 898 |
if ((pic_param->bit_depth_luma_minus8 > 0) |
| 899 |
|| (pic_param->bit_depth_chroma_minus8 > 0)) { |
| 900 |
if (sliceqp < 0) { |
| 901 |
sliceqp_sign_flag = 1; |
| 902 |
sliceqp = -sliceqp; |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
BEGIN_BCS_BATCH(batch, 9); |
| 907 |
|
| 908 |
OUT_BCS_BATCH(batch, HCP_SLICE_STATE | (9 - 2)); |
| 909 |
|
| 910 |
OUT_BCS_BATCH(batch, |
| 911 |
slice_ver_pos << 16 | |
| 912 |
slice_hor_pos); |
| 913 |
OUT_BCS_BATCH(batch, |
| 914 |
next_slice_ver_pos << 16 | |
| 915 |
next_slice_hor_pos); |
| 916 |
OUT_BCS_BATCH(batch, |
| 917 |
(slice_param->slice_cr_qp_offset & 0x1f) << 17 | |
| 918 |
(slice_param->slice_cb_qp_offset & 0x1f) << 12 | |
| 919 |
sliceqp << 6 | |
| 920 |
slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag << 5 | |
| 921 |
slice_param->LongSliceFlags.fields.dependent_slice_segment_flag << 4 | |
| 922 |
sliceqp_sign_flag << 3 | |
| 923 |
!next_slice_param << 2 | |
| 924 |
slice_param->LongSliceFlags.fields.slice_type); |
| 925 |
OUT_BCS_BATCH(batch, |
| 926 |
collocated_ref_idx << 26 | |
| 927 |
(5 - slice_param->five_minus_max_num_merge_cand - 1) << 23 | |
| 928 |
slice_param->LongSliceFlags.fields.cabac_init_flag << 22 | |
| 929 |
slice_param->luma_log2_weight_denom << 19 | |
| 930 |
((slice_param->luma_log2_weight_denom + slice_param->delta_chroma_log2_weight_denom) & 0x7) << 16 | |
| 931 |
collocated_from_l0_flag << 15 | |
| 932 |
gen9_hcpd_is_low_delay(ctx, pic_param, slice_param) << 14 | |
| 933 |
slice_param->LongSliceFlags.fields.mvd_l1_zero_flag << 13 | |
| 934 |
slice_param->LongSliceFlags.fields.slice_sao_luma_flag << 12 | |
| 935 |
slice_param->LongSliceFlags.fields.slice_sao_chroma_flag << 11 | |
| 936 |
slice_param->LongSliceFlags.fields.slice_loop_filter_across_slices_enabled_flag << 10 | |
| 937 |
(slice_param->slice_beta_offset_div2 & 0xf) << 5 | |
| 938 |
(slice_param->slice_tc_offset_div2 & 0xf) << 1 | |
| 939 |
slice_param->LongSliceFlags.fields.slice_deblocking_filter_disabled_flag); |
| 940 |
OUT_BCS_BATCH(batch, |
| 941 |
slice_param->slice_data_byte_offset); /* DW 5 */ |
| 942 |
OUT_BCS_BATCH(batch, |
| 943 |
0 << 26 | |
| 944 |
0 << 20 | |
| 945 |
0); |
| 946 |
OUT_BCS_BATCH(batch, 0); /* Ignored for decoding */ |
| 947 |
OUT_BCS_BATCH(batch, 0); /* Ignored for decoding */ |
| 948 |
|
| 949 |
ADVANCE_BCS_BATCH(batch); |
| 950 |
} |
| 951 |
|
| 952 |
static void |
| 953 |
gen9_hcpd_bsd_object(VADriverContextP ctx, |
| 954 |
VASliceParameterBufferHEVC *slice_param, |
| 955 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 956 |
{ |
| 957 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 958 |
|
| 959 |
BEGIN_BCS_BATCH(batch, 3); |
| 960 |
|
| 961 |
OUT_BCS_BATCH(batch, HCP_BSD_OBJECT | (3 - 2)); |
| 962 |
|
| 963 |
OUT_BCS_BATCH(batch, slice_param->slice_data_size); |
| 964 |
OUT_BCS_BATCH(batch, slice_param->slice_data_offset); |
| 965 |
|
| 966 |
ADVANCE_BCS_BATCH(batch); |
| 967 |
} |
| 968 |
|
| 969 |
static VAStatus |
| 970 |
gen9_hcpd_hevc_decode_picture(VADriverContextP ctx, |
| 971 |
struct decode_state *decode_state, |
| 972 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 973 |
{ |
| 974 |
VAStatus vaStatus; |
| 975 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 976 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 977 |
VAPictureParameterBufferHEVC *pic_param; |
| 978 |
VASliceParameterBufferHEVC *slice_param, *next_slice_param, *next_slice_group_param; |
| 979 |
dri_bo *slice_data_bo; |
| 980 |
int i, j; |
| 981 |
|
| 982 |
vaStatus = gen9_hcpd_hevc_decode_init(ctx, decode_state, gen9_hcpd_context); |
| 983 |
|
| 984 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 985 |
goto out; |
| 986 |
|
| 987 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 988 |
pic_param = (VAPictureParameterBufferHEVC *)decode_state->pic_param->buffer; |
| 989 |
|
| 990 |
if (i965->intel.has_bsd2) |
| 991 |
intel_batchbuffer_start_atomic_bcs_override(batch, 0x1000, BSD_RING0); |
| 992 |
else |
| 993 |
intel_batchbuffer_start_atomic_bcs(batch, 0x1000); |
| 994 |
intel_batchbuffer_emit_mi_flush(batch); |
| 995 |
|
| 996 |
gen9_hcpd_pipe_mode_select(ctx, decode_state, HCP_CODEC_HEVC, gen9_hcpd_context); |
| 997 |
gen9_hcpd_surface_state(ctx, decode_state, gen9_hcpd_context); |
| 998 |
gen9_hcpd_pipe_buf_addr_state(ctx, decode_state, gen9_hcpd_context); |
| 999 |
gen9_hcpd_hevc_qm_state(ctx, decode_state, gen9_hcpd_context); |
| 1000 |
gen9_hcpd_pic_state(ctx, decode_state, gen9_hcpd_context); |
| 1001 |
|
| 1002 |
if (pic_param->pic_fields.bits.tiles_enabled_flag) |
| 1003 |
gen9_hcpd_tile_state(ctx, decode_state, gen9_hcpd_context); |
| 1004 |
|
| 1005 |
/* Need to double it works or not if the two slice groups have differenct slice data buffers */ |
| 1006 |
for (j = 0; j < decode_state->num_slice_params; j++) { |
| 1007 |
assert(decode_state->slice_params && decode_state->slice_params[j]->buffer); |
| 1008 |
slice_param = (VASliceParameterBufferHEVC *)decode_state->slice_params[j]->buffer; |
| 1009 |
slice_data_bo = decode_state->slice_datas[j]->bo; |
| 1010 |
|
| 1011 |
if (IS_GEN10(i965->intel.device_info)) |
| 1012 |
gen10_hcpd_ind_obj_base_addr_state(ctx, slice_data_bo, gen9_hcpd_context); |
| 1013 |
else |
| 1014 |
gen9_hcpd_ind_obj_base_addr_state(ctx, slice_data_bo, gen9_hcpd_context); |
| 1015 |
|
| 1016 |
if (j == decode_state->num_slice_params - 1) |
| 1017 |
next_slice_group_param = NULL; |
| 1018 |
else |
| 1019 |
next_slice_group_param = (VASliceParameterBufferHEVC *)decode_state->slice_params[j + 1]->buffer; |
| 1020 |
|
| 1021 |
for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) { |
| 1022 |
if (i < decode_state->slice_params[j]->num_elements - 1) |
| 1023 |
next_slice_param = slice_param + 1; |
| 1024 |
else |
| 1025 |
next_slice_param = next_slice_group_param; |
| 1026 |
|
| 1027 |
gen9_hcpd_slice_state(ctx, pic_param, slice_param, next_slice_param, gen9_hcpd_context); |
| 1028 |
gen9_hcpd_ref_idx_state(ctx, pic_param, slice_param, gen9_hcpd_context); |
| 1029 |
gen9_hcpd_weightoffset_state(ctx, pic_param, slice_param, gen9_hcpd_context); |
| 1030 |
gen9_hcpd_bsd_object(ctx, slice_param, gen9_hcpd_context); |
| 1031 |
slice_param++; |
| 1032 |
} |
| 1033 |
} |
| 1034 |
|
| 1035 |
intel_batchbuffer_end_atomic(batch); |
| 1036 |
intel_batchbuffer_flush(batch); |
| 1037 |
|
| 1038 |
out: |
| 1039 |
return vaStatus; |
| 1040 |
} |
| 1041 |
|
| 1042 |
/*********************************************************/ |
| 1043 |
/* VP9 Code */ |
| 1044 |
/*********************************************************/ |
| 1045 |
|
| 1046 |
|
| 1047 |
#define VP9_PROB_BUFFER_FIRST_PART_SIZE 2010 |
| 1048 |
#define VP9_PROB_BUFFER_SECOND_PART_SIZE 10 |
| 1049 |
#define VP9_PROB_BUFFER_KEY_INTER_OFFSET 1667 |
| 1050 |
#define VP9_PROB_BUFFER_KEY_INTER_SIZE 343 |
| 1051 |
|
| 1052 |
#define VP9_PROB_BUFFER_UPDATE_NO 0 |
| 1053 |
#define VP9_PROB_BUFFER_UPDATE_SECNE_1 1 |
| 1054 |
#define VP9_PROB_BUFFER_UPDATE_SECNE_2 2 |
| 1055 |
#define VP9_PROB_BUFFER_UPDATE_SECNE_3 3 |
| 1056 |
#define VP9_PROB_BUFFER_UPDATE_SECNE_4 4 |
| 1057 |
#define VP9_PROB_BUFFER_UPDATE_SECNE_5 5 |
| 1058 |
|
| 1059 |
#define VP9_PROB_BUFFER_SAVED_NO 0 |
| 1060 |
#define VP9_PROB_BUFFER_SAVED_SECNE_1 1 |
| 1061 |
#define VP9_PROB_BUFFER_SAVED_SECNE_2 2 |
| 1062 |
|
| 1063 |
#define VP9_PROB_BUFFER_RESTORED_NO 0 |
| 1064 |
#define VP9_PROB_BUFFER_RESTORED_SECNE_1 1 |
| 1065 |
#define VP9_PROB_BUFFER_RESTORED_SECNE_2 2 |
| 1066 |
#define VP9_PROB_BUFFER_RESTORED_SECNE_MAX (VP9_PROB_BUFFER_RESTORED_SECNE_2 + 1) |
| 1067 |
|
| 1068 |
#define ALLOC_MV_BUFFER(gen_buffer, string, size,width,height) \ |
| 1069 |
do { \ |
| 1070 |
dri_bo_unreference(gen_buffer->bo); \ |
| 1071 |
gen_buffer->bo = dri_bo_alloc(i965->intel.bufmgr, \ |
| 1072 |
string, \ |
| 1073 |
size, \ |
| 1074 |
0x1000); \ |
| 1075 |
assert(gen_buffer->bo); \ |
| 1076 |
gen_buffer->frame_width = width ; \ |
| 1077 |
gen_buffer->frame_height = height; \ |
| 1078 |
} while (0) |
| 1079 |
|
| 1080 |
static void |
| 1081 |
vp9_update_segmentId_buffer(VADriverContextP ctx, |
| 1082 |
struct decode_state *decode_state, |
| 1083 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1084 |
{ |
| 1085 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 1086 |
VADecPictureParameterBufferVP9 *pic_param; |
| 1087 |
|
| 1088 |
int size = 0; |
| 1089 |
int is_scaling = 0; |
| 1090 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 1091 |
pic_param = (VADecPictureParameterBufferVP9 *)decode_state->pic_param->buffer; |
| 1092 |
|
| 1093 |
size = gen9_hcpd_context->picture_width_in_ctbs * gen9_hcpd_context->picture_height_in_ctbs * 1 ; |
| 1094 |
size <<= 6; |
| 1095 |
if (gen9_hcpd_context->vp9_segment_id_buffer.bo == NULL || pic_param->frame_width > gen9_hcpd_context->last_frame.frame_width || pic_param->frame_height > gen9_hcpd_context->last_frame.frame_height) { |
| 1096 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->vp9_segment_id_buffer), "vp9 segment id buffer", size); |
| 1097 |
} |
| 1098 |
|
| 1099 |
is_scaling = (pic_param->frame_width != gen9_hcpd_context->last_frame.frame_width) || (pic_param->frame_height != gen9_hcpd_context->last_frame.frame_height); |
| 1100 |
|
| 1101 |
if ((pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME) || |
| 1102 |
pic_param->pic_fields.bits.error_resilient_mode || |
| 1103 |
pic_param->pic_fields.bits.intra_only || is_scaling) { |
| 1104 |
|
| 1105 |
//VP9 Segment ID buffer needs to be zero |
| 1106 |
dri_bo_map(gen9_hcpd_context->vp9_segment_id_buffer.bo, 1); |
| 1107 |
memset((unsigned char *)gen9_hcpd_context->vp9_segment_id_buffer.bo->virtual, 0, size); |
| 1108 |
dri_bo_unmap(gen9_hcpd_context->vp9_segment_id_buffer.bo); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
static void |
| 1113 |
vp9_update_mv_temporal_buffer(VADriverContextP ctx, |
| 1114 |
struct decode_state *decode_state, |
| 1115 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1116 |
{ |
| 1117 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 1118 |
VADecPictureParameterBufferVP9 *pic_param; |
| 1119 |
int size = 0; |
| 1120 |
|
| 1121 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 1122 |
pic_param = (VADecPictureParameterBufferVP9 *)decode_state->pic_param->buffer; |
| 1123 |
|
| 1124 |
size = gen9_hcpd_context->picture_width_in_ctbs * gen9_hcpd_context->picture_height_in_ctbs * 9 ; |
| 1125 |
size <<= 6; //CL aligned |
| 1126 |
if (gen9_hcpd_context->vp9_mv_temporal_buffer_curr.bo == NULL || pic_param->frame_width > gen9_hcpd_context->vp9_mv_temporal_buffer_curr.frame_width || pic_param->frame_height > gen9_hcpd_context->vp9_mv_temporal_buffer_curr.frame_height) { |
| 1127 |
ALLOC_MV_BUFFER((&gen9_hcpd_context->vp9_mv_temporal_buffer_curr), "vp9 curr mv temporal buffer", size, pic_param->frame_width, pic_param->frame_height); |
| 1128 |
} |
| 1129 |
if (gen9_hcpd_context->vp9_mv_temporal_buffer_last.bo == NULL) { |
| 1130 |
ALLOC_MV_BUFFER((&gen9_hcpd_context->vp9_mv_temporal_buffer_last), "vp9 last mv temporal buffer", size, pic_param->frame_width, pic_param->frame_height); |
| 1131 |
} |
| 1132 |
|
| 1133 |
} |
| 1134 |
|
| 1135 |
static void |
| 1136 |
vp9_gen_default_probabilities(VADriverContextP ctx, struct gen9_hcpd_context *gen9_hcpd_context) |
| 1137 |
{ |
| 1138 |
int i = 0; |
| 1139 |
uint32_t size = 0; |
| 1140 |
|
| 1141 |
size = sizeof(FRAME_CONTEXT); |
| 1142 |
memset(&gen9_hcpd_context->vp9_fc_key_default, 0, size); |
| 1143 |
memset(&gen9_hcpd_context->vp9_fc_inter_default, 0, size); |
| 1144 |
memset(&gen9_hcpd_context->vp9_frame_ctx, 0, size * FRAME_CONTEXTS); |
| 1145 |
//more code to come here below |
| 1146 |
|
| 1147 |
//1. key default |
| 1148 |
gen9_hcpd_context->vp9_fc_key_default.tx_probs = default_tx_probs; |
| 1149 |
//dummy 52 |
| 1150 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.coeff_probs4x4, default_coef_probs_4x4); |
| 1151 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.coeff_probs8x8, default_coef_probs_8x8); |
| 1152 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.coeff_probs16x16, default_coef_probs_16x16); |
| 1153 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.coeff_probs32x32, default_coef_probs_32x32); |
| 1154 |
//dummy 16 |
| 1155 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.skip_probs, default_skip_probs); |
| 1156 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.partition_prob, vp9_kf_partition_probs); |
| 1157 |
//dummy 47 |
| 1158 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.uv_mode_prob, vp9_kf_uv_mode_prob); |
| 1159 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.seg_tree_probs, default_seg_tree_probs); |
| 1160 |
vp9_copy(gen9_hcpd_context->vp9_fc_key_default.seg_pred_probs, default_seg_pred_probs); |
| 1161 |
|
| 1162 |
//2. inter default |
| 1163 |
gen9_hcpd_context->vp9_fc_inter_default.tx_probs = default_tx_probs; |
| 1164 |
//dummy 52 |
| 1165 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.coeff_probs4x4, default_coef_probs_4x4); |
| 1166 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.coeff_probs8x8, default_coef_probs_8x8); |
| 1167 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.coeff_probs16x16, default_coef_probs_16x16); |
| 1168 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.coeff_probs32x32, default_coef_probs_32x32); |
| 1169 |
//dummy 16 |
| 1170 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.skip_probs, default_skip_probs); |
| 1171 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.inter_mode_probs, default_inter_mode_probs); |
| 1172 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.switchable_interp_prob, default_switchable_interp_prob); |
| 1173 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.intra_inter_prob, default_intra_inter_p); |
| 1174 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.comp_inter_prob, default_comp_inter_p); |
| 1175 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.single_ref_prob, default_single_ref_p); |
| 1176 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.comp_ref_prob, default_comp_ref_p); |
| 1177 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.y_mode_prob, default_if_y_probs); |
| 1178 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.partition_prob, default_partition_probs); |
| 1179 |
gen9_hcpd_context->vp9_fc_inter_default.nmvc = default_nmv_context; |
| 1180 |
//dummy 47 |
| 1181 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.uv_mode_prob, default_if_uv_probs); |
| 1182 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.seg_tree_probs, default_seg_tree_probs); |
| 1183 |
vp9_copy(gen9_hcpd_context->vp9_fc_inter_default.seg_pred_probs, default_seg_pred_probs); |
| 1184 |
|
| 1185 |
for (i = 0; i < FRAME_CONTEXTS; i++) { |
| 1186 |
gen9_hcpd_context->vp9_frame_ctx[i] = gen9_hcpd_context->vp9_fc_inter_default; |
| 1187 |
} |
| 1188 |
} |
| 1189 |
|
| 1190 |
static void |
| 1191 |
vp9_update_probabilities(VADriverContextP ctx, |
| 1192 |
struct decode_state *decode_state, |
| 1193 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1194 |
{ |
| 1195 |
VADecPictureParameterBufferVP9 *pic_param; |
| 1196 |
int i = 0; |
| 1197 |
|
| 1198 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 1199 |
pic_param = (VADecPictureParameterBufferVP9 *)decode_state->pic_param->buffer; |
| 1200 |
|
| 1201 |
//update vp9_frame_ctx according to frame_context_id |
| 1202 |
if (gen9_hcpd_context->last_frame.refresh_frame_context) { |
| 1203 |
void *pfc = (void *)&gen9_hcpd_context->vp9_frame_ctx[gen9_hcpd_context->last_frame.frame_context_idx]; |
| 1204 |
void *pprob = NULL; |
| 1205 |
|
| 1206 |
//update vp9_fc to frame_context |
| 1207 |
dri_bo_map(gen9_hcpd_context->last_frame.prob_buffer_bo, 1); |
| 1208 |
pprob = (void *)gen9_hcpd_context->last_frame.prob_buffer_bo->virtual; |
| 1209 |
if (gen9_hcpd_context->last_frame.frame_type == HCP_VP9_KEY_FRAME || |
| 1210 |
gen9_hcpd_context->last_frame.intra_only) |
| 1211 |
memcpy(pfc, pprob, VP9_PROB_BUFFER_FIRST_PART_SIZE - VP9_PROB_BUFFER_KEY_INTER_SIZE); |
| 1212 |
else |
| 1213 |
memcpy(pfc, pprob, VP9_PROB_BUFFER_FIRST_PART_SIZE); |
| 1214 |
|
| 1215 |
dri_bo_unmap(gen9_hcpd_context->last_frame.prob_buffer_bo); |
| 1216 |
} |
| 1217 |
|
| 1218 |
//first part buffer update: Case 1)Reset all 4 probablity buffers |
| 1219 |
if ((pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME) || pic_param->pic_fields.bits.intra_only || pic_param->pic_fields.bits.error_resilient_mode) { |
| 1220 |
if ((pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME) || |
| 1221 |
(pic_param->pic_fields.bits.reset_frame_context == 3) || |
| 1222 |
pic_param->pic_fields.bits.error_resilient_mode) { |
| 1223 |
//perform full buffer update |
| 1224 |
for (i = 0; i < FRAME_CONTEXTS; i++) { |
| 1225 |
memcpy(&gen9_hcpd_context->vp9_frame_ctx[i], &gen9_hcpd_context->vp9_fc_inter_default, VP9_PROB_BUFFER_FIRST_PART_SIZE); |
| 1226 |
|
| 1227 |
vp9_copy(gen9_hcpd_context->vp9_frame_ctx[i].seg_tree_probs, default_seg_tree_probs); |
| 1228 |
vp9_copy(gen9_hcpd_context->vp9_frame_ctx[i].seg_pred_probs, default_seg_pred_probs); |
| 1229 |
} |
| 1230 |
} else if (pic_param->pic_fields.bits.reset_frame_context == 2 && pic_param->pic_fields.bits.intra_only) { |
| 1231 |
memcpy(&gen9_hcpd_context->vp9_frame_ctx[pic_param->pic_fields.bits.frame_context_idx], &gen9_hcpd_context->vp9_fc_inter_default, VP9_PROB_BUFFER_FIRST_PART_SIZE); |
| 1232 |
} |
| 1233 |
pic_param->pic_fields.bits.frame_context_idx = 0; |
| 1234 |
} |
| 1235 |
|
| 1236 |
//Case 3) Update only segment probabilities |
| 1237 |
if ((pic_param->pic_fields.bits.segmentation_enabled && |
| 1238 |
pic_param->pic_fields.bits.segmentation_update_map)) { |
| 1239 |
//Update seg_tree_probs and seg_pred_probs accordingly |
| 1240 |
for (i = 0; i < SEG_TREE_PROBS; i++) { |
| 1241 |
gen9_hcpd_context->vp9_frame_ctx[pic_param->pic_fields.bits.frame_context_idx].seg_tree_probs[i] = pic_param->mb_segment_tree_probs[i]; |
| 1242 |
} |
| 1243 |
for (i = 0; i < PREDICTION_PROBS; i++) { |
| 1244 |
gen9_hcpd_context->vp9_frame_ctx[pic_param->pic_fields.bits.frame_context_idx].seg_pred_probs[i] = pic_param->segment_pred_probs[i]; |
| 1245 |
} |
| 1246 |
} |
| 1247 |
|
| 1248 |
//update vp9_fc according to frame_context_id |
| 1249 |
{ |
| 1250 |
void *pfc = (void *)&gen9_hcpd_context->vp9_frame_ctx[pic_param->pic_fields.bits.frame_context_idx]; |
| 1251 |
void *pprob = NULL; |
| 1252 |
|
| 1253 |
dri_bo_map(gen9_hcpd_context->vp9_probability_buffer.bo, 1); |
| 1254 |
|
| 1255 |
pprob = (void *)gen9_hcpd_context->vp9_probability_buffer.bo->virtual; |
| 1256 |
memcpy(pprob, pfc, 2048); |
| 1257 |
//only update 343bytes for key or intra_only frame |
| 1258 |
if (pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME || |
| 1259 |
pic_param->pic_fields.bits.intra_only) { |
| 1260 |
memcpy(pprob + VP9_PROB_BUFFER_FIRST_PART_SIZE - VP9_PROB_BUFFER_KEY_INTER_SIZE |
| 1261 |
, gen9_hcpd_context->vp9_fc_key_default.inter_mode_probs |
| 1262 |
, VP9_PROB_BUFFER_KEY_INTER_SIZE); |
| 1263 |
} |
| 1264 |
|
| 1265 |
dri_bo_unmap(gen9_hcpd_context->vp9_probability_buffer.bo); |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
static void |
| 1270 |
gen9_hcpd_init_vp9_surface(VADriverContextP ctx, |
| 1271 |
VADecPictureParameterBufferVP9 *pic_param, |
| 1272 |
struct object_surface *obj_surface, |
| 1273 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1274 |
{ |
| 1275 |
GenVP9Surface *gen9_vp9_surface; |
| 1276 |
|
| 1277 |
if (!obj_surface) |
| 1278 |
return; |
| 1279 |
|
| 1280 |
obj_surface->free_private_data = gen_free_vp9_surface; |
| 1281 |
gen9_vp9_surface = obj_surface->private_data; |
| 1282 |
|
| 1283 |
if (!gen9_vp9_surface) { |
| 1284 |
gen9_vp9_surface = calloc(sizeof(GenVP9Surface), 1); |
| 1285 |
assert(gen9_vp9_surface); |
| 1286 |
gen9_vp9_surface->base.frame_store_id = -1; |
| 1287 |
obj_surface->private_data = gen9_vp9_surface; |
| 1288 |
} |
| 1289 |
|
| 1290 |
gen9_vp9_surface->frame_width = pic_param->frame_width; |
| 1291 |
gen9_vp9_surface->frame_height = pic_param->frame_height; |
| 1292 |
|
| 1293 |
} |
| 1294 |
|
| 1295 |
static VAStatus |
| 1296 |
gen9_hcpd_vp9_decode_init(VADriverContextP ctx, |
| 1297 |
struct decode_state *decode_state, |
| 1298 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1299 |
{ |
| 1300 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 1301 |
VADecPictureParameterBufferVP9 *pic_param; |
| 1302 |
struct object_surface *obj_surface; |
| 1303 |
uint32_t size; |
| 1304 |
int width_in_mbs = 0, height_in_mbs = 0; |
| 1305 |
int bit_depth_minus8 = 0; |
| 1306 |
|
| 1307 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 1308 |
pic_param = (VADecPictureParameterBufferVP9 *)decode_state->pic_param->buffer; |
| 1309 |
|
| 1310 |
width_in_mbs = (pic_param->frame_width + 15) / 16; |
| 1311 |
height_in_mbs = (pic_param->frame_height + 15) / 16; |
| 1312 |
|
| 1313 |
//For BXT, we support only till 4K |
| 1314 |
assert(width_in_mbs > 0 && width_in_mbs <= 256); /* 4K */ |
| 1315 |
assert(height_in_mbs > 0 && height_in_mbs <= 256); |
| 1316 |
|
| 1317 |
if (!(i965->codec_info->vp9_dec_profiles & (1U << pic_param->profile))) |
| 1318 |
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE; |
| 1319 |
|
| 1320 |
if (pic_param->profile >= 2) { |
| 1321 |
if (pic_param->bit_depth >= 8) |
| 1322 |
bit_depth_minus8 = pic_param->bit_depth - 8; |
| 1323 |
|
| 1324 |
if (bit_depth_minus8 == 2) { |
| 1325 |
if (!(i965->codec_info->vp9_dec_chroma_formats & VA_RT_FORMAT_YUV420_10BPP)) |
| 1326 |
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; |
| 1327 |
} else if ((bit_depth_minus8 > 2) || (bit_depth_minus8 == 1) || (bit_depth_minus8 < 0)) |
| 1328 |
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; |
| 1329 |
} |
| 1330 |
|
| 1331 |
//Update the frame store buffers with the reference frames information |
| 1332 |
intel_update_vp9_frame_store_index(ctx, |
| 1333 |
decode_state, |
| 1334 |
pic_param, |
| 1335 |
gen9_hcpd_context->reference_surfaces); |
| 1336 |
|
| 1337 |
/* Current decoded picture */ |
| 1338 |
obj_surface = decode_state->render_object; |
| 1339 |
//Ensure there is a tiled render surface in NV12 format. If not, create one. |
| 1340 |
vp9_ensure_surface_bo(ctx, decode_state, obj_surface, pic_param); |
| 1341 |
|
| 1342 |
|
| 1343 |
//Super block in VP9 is 64x64 |
| 1344 |
gen9_hcpd_context->ctb_size = 64; |
| 1345 |
gen9_hcpd_context->min_cb_size = 8; //Min block size is 4 or 8? |
| 1346 |
|
| 1347 |
//If picture width/height is not multiple of 64, needs to upsize it to the next 64 pixels |
| 1348 |
//before calculation below. |
| 1349 |
gen9_hcpd_context->picture_width_in_ctbs = ALIGN(pic_param->frame_width, gen9_hcpd_context->ctb_size) / gen9_hcpd_context->ctb_size; |
| 1350 |
gen9_hcpd_context->picture_height_in_ctbs = ALIGN(pic_param->frame_height, gen9_hcpd_context->ctb_size) / gen9_hcpd_context->ctb_size; |
| 1351 |
|
| 1352 |
gen9_hcpd_context->picture_width_in_min_cb_minus1 = ALIGN(pic_param->frame_width, gen9_hcpd_context->min_cb_size) / gen9_hcpd_context->min_cb_size - 1; |
| 1353 |
gen9_hcpd_context->picture_height_in_min_cb_minus1 = ALIGN(pic_param->frame_height, gen9_hcpd_context->min_cb_size) / gen9_hcpd_context->min_cb_size - 1; |
| 1354 |
|
| 1355 |
gen9_hcpd_context->picture_width_in_pixels = (gen9_hcpd_context->picture_width_in_min_cb_minus1 + 1) * gen9_hcpd_context->min_cb_size ; |
| 1356 |
gen9_hcpd_context->picture_height_in_pixels = (gen9_hcpd_context->picture_height_in_min_cb_minus1 + 1) * gen9_hcpd_context->min_cb_size ; |
| 1357 |
|
| 1358 |
gen9_hcpd_init_vp9_surface(ctx, pic_param, obj_surface, gen9_hcpd_context); |
| 1359 |
|
| 1360 |
if (pic_param->profile >= 2) |
| 1361 |
size = gen9_hcpd_context->picture_width_in_ctbs * 36; //num_width_in_SB * 36 |
| 1362 |
else |
| 1363 |
size = gen9_hcpd_context->picture_width_in_ctbs * 18; //num_width_in_SB * 18 |
| 1364 |
size <<= 6; |
| 1365 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_line_buffer), "line buffer", size); |
| 1366 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_line_buffer), "tile line buffer", size); |
| 1367 |
|
| 1368 |
if (pic_param->profile >= 2) |
| 1369 |
size = gen9_hcpd_context->picture_height_in_ctbs * 34; //num_height_in_SB * 17 |
| 1370 |
else |
| 1371 |
size = gen9_hcpd_context->picture_height_in_ctbs * 17; //num_height_in_SB * 17 |
| 1372 |
size <<= 6; |
| 1373 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_column_buffer), "tile column buffer", size); |
| 1374 |
|
| 1375 |
size = gen9_hcpd_context->picture_width_in_ctbs * 5; //num_width_in_SB * 5 |
| 1376 |
size <<= 6; |
| 1377 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_line_buffer), "metadata line buffer", size); |
| 1378 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_line_buffer), "metadata tile line buffer", size); |
| 1379 |
|
| 1380 |
size = gen9_hcpd_context->picture_height_in_ctbs * 5; //num_height_in_SB * 5 |
| 1381 |
size <<= 6; |
| 1382 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_column_buffer), "metadata tile column buffer", size); |
| 1383 |
|
| 1384 |
size = gen9_hcpd_context->picture_width_in_ctbs * 1; //num_width_in_SB * 1 |
| 1385 |
size <<= 6; |
| 1386 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->hvd_line_rowstore_buffer), "hvd line rowstore buffer", size); |
| 1387 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->hvd_tile_rowstore_buffer), "hvd tile rowstore buffer", size); |
| 1388 |
|
| 1389 |
size = 32; |
| 1390 |
size <<= 6; |
| 1391 |
ALLOC_GEN_BUFFER((&gen9_hcpd_context->vp9_probability_buffer), "vp9 probability buffer", size); |
| 1392 |
|
| 1393 |
gen9_hcpd_context->first_inter_slice_collocated_ref_idx = 0; |
| 1394 |
gen9_hcpd_context->first_inter_slice_collocated_from_l0_flag = 0; |
| 1395 |
gen9_hcpd_context->first_inter_slice_valid = 0; |
| 1396 |
|
| 1397 |
return VA_STATUS_SUCCESS; |
| 1398 |
} |
| 1399 |
|
| 1400 |
static void |
| 1401 |
gen9_hcpd_vp9_surface_state(VADriverContextP ctx, |
| 1402 |
struct decode_state *decode_state, |
| 1403 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1404 |
{ |
| 1405 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 1406 |
struct object_surface *obj_surface = decode_state->render_object; |
| 1407 |
struct object_surface *tmp_obj_surface = NULL; |
| 1408 |
unsigned int y_cb_offset; |
| 1409 |
int i = 0; |
| 1410 |
|
| 1411 |
assert(obj_surface); |
| 1412 |
|
| 1413 |
y_cb_offset = obj_surface->y_cb_offset; |
| 1414 |
|
| 1415 |
BEGIN_BCS_BATCH(batch, 3); |
| 1416 |
|
| 1417 |
OUT_BCS_BATCH(batch, HCP_SURFACE_STATE | (3 - 2)); |
| 1418 |
OUT_BCS_BATCH(batch, |
| 1419 |
(0 << 28) | /* surface id */ |
| 1420 |
(obj_surface->width - 1)); /* pitch - 1 */ |
| 1421 |
OUT_BCS_BATCH(batch, |
| 1422 |
(((obj_surface->fourcc == VA_FOURCC_P010) ? SURFACE_FORMAT_P010 : SURFACE_FORMAT_PLANAR_420_8) << 28) | |
| 1423 |
y_cb_offset); |
| 1424 |
ADVANCE_BCS_BATCH(batch); |
| 1425 |
|
| 1426 |
tmp_obj_surface = obj_surface; |
| 1427 |
|
| 1428 |
for (i = 0; i < 3; i++) { |
| 1429 |
obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface; |
| 1430 |
if (obj_surface && obj_surface->private_data) { |
| 1431 |
BEGIN_BCS_BATCH(batch, 3); |
| 1432 |
|
| 1433 |
OUT_BCS_BATCH(batch, HCP_SURFACE_STATE | (3 - 2)); |
| 1434 |
OUT_BCS_BATCH(batch, |
| 1435 |
((i + 2) << 28) | /* surface id */ |
| 1436 |
(obj_surface->width - 1)); /* pitch - 1 */ |
| 1437 |
OUT_BCS_BATCH(batch, |
| 1438 |
(((obj_surface->fourcc == VA_FOURCC_P010) ? SURFACE_FORMAT_P010 : SURFACE_FORMAT_PLANAR_420_8) << 28) | |
| 1439 |
obj_surface->y_cb_offset); |
| 1440 |
ADVANCE_BCS_BATCH(batch); |
| 1441 |
} else { |
| 1442 |
BEGIN_BCS_BATCH(batch, 3); |
| 1443 |
|
| 1444 |
OUT_BCS_BATCH(batch, HCP_SURFACE_STATE | (3 - 2)); |
| 1445 |
OUT_BCS_BATCH(batch, |
| 1446 |
((i + 2) << 28) | /* surface id */ |
| 1447 |
(tmp_obj_surface->width - 1)); /* pitch - 1 */ |
| 1448 |
OUT_BCS_BATCH(batch, |
| 1449 |
(((tmp_obj_surface->fourcc == VA_FOURCC_P010) ? SURFACE_FORMAT_P010 : SURFACE_FORMAT_PLANAR_420_8) << 28) | |
| 1450 |
tmp_obj_surface->y_cb_offset); |
| 1451 |
ADVANCE_BCS_BATCH(batch); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
} |
| 1455 |
|
| 1456 |
static void |
| 1457 |
gen9_hcpd_vp9_pipe_buf_addr_state(VADriverContextP ctx, |
| 1458 |
struct decode_state *decode_state, |
| 1459 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1460 |
{ |
| 1461 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 1462 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 1463 |
struct object_surface *obj_surface; |
| 1464 |
int i = 0; |
| 1465 |
|
| 1466 |
BEGIN_BCS_BATCH(batch, 95); |
| 1467 |
|
| 1468 |
OUT_BCS_BATCH(batch, HCP_PIPE_BUF_ADDR_STATE | (95 - 2)); |
| 1469 |
|
| 1470 |
obj_surface = decode_state->render_object; |
| 1471 |
assert(obj_surface && obj_surface->bo); |
| 1472 |
|
| 1473 |
OUT_BUFFER_MA_TARGET(obj_surface->bo); /* DW 1..3 */ |
| 1474 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_line_buffer.bo);/* DW 4..6 */ |
| 1475 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_tile_line_buffer.bo); /* DW 7..9 */ |
| 1476 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->deblocking_filter_tile_column_buffer.bo); /* DW 10..12 */ |
| 1477 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_line_buffer.bo); /* DW 13..15 */ |
| 1478 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_tile_line_buffer.bo); /* DW 16..18 */ |
| 1479 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->metadata_tile_column_buffer.bo); /* DW 19..21 */ |
| 1480 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 22..24, ignore for VP9 */ |
| 1481 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 25..27, ignore for VP9 */ |
| 1482 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 28..30, ignore for VP9 */ |
| 1483 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->vp9_mv_temporal_buffer_curr.bo); /* DW 31..33 */ |
| 1484 |
|
| 1485 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 34..36, reserved */ |
| 1486 |
|
| 1487 |
/* DW 37..52 - Reference picture address */ |
| 1488 |
for (i = 0; i < 3; i++) { |
| 1489 |
obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface; |
| 1490 |
|
| 1491 |
if (obj_surface) { |
| 1492 |
OUT_BUFFER_NMA_REFERENCE(obj_surface->bo); |
| 1493 |
} else |
| 1494 |
OUT_BUFFER_NMA_REFERENCE(NULL); |
| 1495 |
} |
| 1496 |
for (; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) { |
| 1497 |
OUT_BUFFER_NMA_REFERENCE(NULL); |
| 1498 |
} |
| 1499 |
OUT_BCS_BATCH(batch, 0); /* DW 53, memory address attributes */ |
| 1500 |
|
| 1501 |
OUT_BUFFER_MA_REFERENCE(NULL); /* DW 54..56, ignore for decoding mode */ |
| 1502 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 57..59, StreamOutEnable - used for transcoding */ |
| 1503 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 60..62, DecodedPictureStatusError, ignored */ |
| 1504 |
OUT_BUFFER_MA_TARGET(NULL); /* DW 63..65, Ignored */ |
| 1505 |
|
| 1506 |
/* DW 66..81 - for 8 Collocated motion vectors */ |
| 1507 |
for (i = 0; i < 1; i++) { |
| 1508 |
OUT_BUFFER_NMA_REFERENCE(gen9_hcpd_context->vp9_mv_temporal_buffer_last.bo); |
| 1509 |
} |
| 1510 |
for (; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) { |
| 1511 |
OUT_BUFFER_NMA_REFERENCE(NULL); |
| 1512 |
} |
| 1513 |
|
| 1514 |
OUT_BCS_BATCH(batch, 0); /* DW 82, memory address attributes */ |
| 1515 |
|
| 1516 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->vp9_probability_buffer.bo); /* DW 83..85, VP9 Probability bufffer */ |
| 1517 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->vp9_segment_id_buffer.bo); /* DW 86..88, VP9 Segment ID buffer */ |
| 1518 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->hvd_line_rowstore_buffer.bo);/* DW 89..91, VP9 HVD Line Rowstore buffer */ |
| 1519 |
OUT_BUFFER_MA_TARGET(gen9_hcpd_context->hvd_tile_rowstore_buffer.bo);/* DW 92..94, VP9 HVD Tile Rowstore buffer */ |
| 1520 |
|
| 1521 |
ADVANCE_BCS_BATCH(batch); |
| 1522 |
} |
| 1523 |
|
| 1524 |
static inline int |
| 1525 |
gen9_hcpd_vp9_valid_ref_frame_size(int ref_width, int ref_height, |
| 1526 |
int cur_width, int cur_height) |
| 1527 |
{ |
| 1528 |
return 2 * cur_width >= ref_width && |
| 1529 |
2 * cur_height >= ref_height && |
| 1530 |
cur_width <= 16 * ref_width && |
| 1531 |
cur_height <= 16 * ref_height; |
| 1532 |
} |
| 1533 |
static void |
| 1534 |
gen9_hcpd_vp9_pic_state(VADriverContextP ctx, |
| 1535 |
struct decode_state *decode_state, |
| 1536 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1537 |
{ |
| 1538 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 1539 |
VADecPictureParameterBufferVP9 *pic_param; |
| 1540 |
struct object_surface *obj_surface; |
| 1541 |
GenVP9Surface *gen9_vp9_surface; |
| 1542 |
uint16_t scale_h = 0; |
| 1543 |
uint16_t scale_w = 0; |
| 1544 |
uint16_t frame_width_in_pixel = 0; |
| 1545 |
uint16_t frame_height_in_pixel = 0; |
| 1546 |
uint16_t fwidth = 64; |
| 1547 |
uint16_t fheight = 64; |
| 1548 |
int i; |
| 1549 |
int bit_depth_minus8 = 0; |
| 1550 |
|
| 1551 |
#define LEN_COMMAND_OWN 12 |
| 1552 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 1553 |
pic_param = (VADecPictureParameterBufferVP9 *)decode_state->pic_param->buffer; |
| 1554 |
|
| 1555 |
uint8_t segmentIDStreamInEnable = 0; |
| 1556 |
uint8_t segmentIDStreamOutEnable = (pic_param->pic_fields.bits.segmentation_enabled && pic_param->pic_fields.bits.segmentation_update_map); |
| 1557 |
|
| 1558 |
// For KEY_FRAME or INTRA_ONLY frame, this bit should be set to "0". |
| 1559 |
uint8_t segmentation_temporal_update = |
| 1560 |
((pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME) || (pic_param->pic_fields.bits.intra_only)) ? 0 : pic_param->pic_fields.bits.segmentation_temporal_update; |
| 1561 |
|
| 1562 |
|
| 1563 |
if (pic_param->pic_fields.bits.intra_only || (pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME)) { |
| 1564 |
segmentIDStreamInEnable = 1; |
| 1565 |
} else if (pic_param->pic_fields.bits.segmentation_enabled) { |
| 1566 |
if (!pic_param->pic_fields.bits.segmentation_update_map) { |
| 1567 |
segmentIDStreamInEnable = 1; |
| 1568 |
|
| 1569 |
} else if (pic_param->pic_fields.bits.segmentation_temporal_update) { |
| 1570 |
segmentIDStreamInEnable = 1; |
| 1571 |
} |
| 1572 |
} |
| 1573 |
|
| 1574 |
if (pic_param->pic_fields.bits.error_resilient_mode) { |
| 1575 |
segmentIDStreamInEnable = 1; |
| 1576 |
} |
| 1577 |
|
| 1578 |
//frame type of previous frame (Key or Non-Key Frame). |
| 1579 |
uint8_t last_frame_type = gen9_hcpd_context->last_frame.frame_type; |
| 1580 |
|
| 1581 |
uint8_t use_pre_frame_mvs = 0; |
| 1582 |
use_pre_frame_mvs = !((pic_param->pic_fields.bits.error_resilient_mode) || |
| 1583 |
(pic_param->frame_width != gen9_hcpd_context->last_frame.frame_width) || |
| 1584 |
(pic_param->frame_height != gen9_hcpd_context->last_frame.frame_height) || |
| 1585 |
(pic_param->pic_fields.bits.intra_only) || |
| 1586 |
(pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME) || |
| 1587 |
(gen9_hcpd_context->last_frame.intra_only) || |
| 1588 |
(last_frame_type == HCP_VP9_KEY_FRAME) || |
| 1589 |
(!gen9_hcpd_context->last_frame.show_frame)); |
| 1590 |
|
| 1591 |
uint8_t adapt_probabilities_flag = 0; |
| 1592 |
if ((pic_param->pic_fields.bits.error_resilient_mode || pic_param->pic_fields.bits.frame_parallel_decoding_mode)) |
| 1593 |
adapt_probabilities_flag = 0; //0: Do not adapt (error resilient or frame_parallel_mode are set) |
| 1594 |
else if (!(pic_param->pic_fields.bits.error_resilient_mode) && !(pic_param->pic_fields.bits.frame_parallel_decoding_mode)) |
| 1595 |
adapt_probabilities_flag = 1; //1: Adapt (not error resilient and not frame_ parallel_mode) |
| 1596 |
|
| 1597 |
frame_width_in_pixel = (gen9_hcpd_context->picture_width_in_min_cb_minus1 + 1) * gen9_hcpd_context->min_cb_size ; |
| 1598 |
frame_height_in_pixel = (gen9_hcpd_context->picture_height_in_min_cb_minus1 + 1) * gen9_hcpd_context->min_cb_size ; |
| 1599 |
|
| 1600 |
fwidth = (fwidth > frame_width_in_pixel) ? frame_width_in_pixel : fwidth; |
| 1601 |
fheight = (fheight > frame_height_in_pixel) ? frame_height_in_pixel : fheight; |
| 1602 |
|
| 1603 |
if (pic_param->profile >= 2) { |
| 1604 |
if (pic_param->bit_depth >= 8) |
| 1605 |
bit_depth_minus8 = pic_param->bit_depth - 8; |
| 1606 |
} |
| 1607 |
|
| 1608 |
BEGIN_BCS_BATCH(batch, LEN_COMMAND_OWN); |
| 1609 |
|
| 1610 |
OUT_BCS_BATCH(batch, HCP_VP9_PIC_STATE | (LEN_COMMAND_OWN - 2)); |
| 1611 |
|
| 1612 |
OUT_BCS_BATCH(batch, |
| 1613 |
(frame_height_in_pixel - 1) << 16 | |
| 1614 |
(frame_width_in_pixel - 1)); /* DW 1 */ |
| 1615 |
OUT_BCS_BATCH(batch, |
| 1616 |
segmentIDStreamInEnable << 31 | |
| 1617 |
segmentIDStreamOutEnable << 30 | |
| 1618 |
pic_param->pic_fields.bits.lossless_flag << 29 | |
| 1619 |
segmentation_temporal_update << 28 | |
| 1620 |
(pic_param->pic_fields.bits.segmentation_enabled && |
| 1621 |
pic_param->pic_fields.bits.segmentation_update_map) << 27 | |
| 1622 |
pic_param->pic_fields.bits.segmentation_enabled << 26 | |
| 1623 |
pic_param->sharpness_level << 23 | |
| 1624 |
pic_param->filter_level << 17 | |
| 1625 |
pic_param->pic_fields.bits.frame_parallel_decoding_mode << 16 | |
| 1626 |
pic_param->pic_fields.bits.error_resilient_mode << 15 | |
| 1627 |
pic_param->pic_fields.bits.refresh_frame_context << 14 | |
| 1628 |
last_frame_type << 13 | |
| 1629 |
0 << 12 | /* tx select mode */ |
| 1630 |
0 << 11 | /* Hybrid Prediction Mode */ |
| 1631 |
use_pre_frame_mvs << 10 | |
| 1632 |
pic_param->pic_fields.bits.alt_ref_frame_sign_bias << 9 | |
| 1633 |
pic_param->pic_fields.bits.golden_ref_frame_sign_bias << 8 | |
| 1634 |
pic_param->pic_fields.bits.last_ref_frame_sign_bias << 7 | |
| 1635 |
pic_param->pic_fields.bits.mcomp_filter_type << 4 | |
| 1636 |
pic_param->pic_fields.bits.allow_high_precision_mv << 3 | |
| 1637 |
pic_param->pic_fields.bits.intra_only << 2 | |
| 1638 |
adapt_probabilities_flag << 1 | |
| 1639 |
pic_param->pic_fields.bits.frame_type << 0); /* DW 2 */ |
| 1640 |
OUT_BCS_BATCH(batch, |
| 1641 |
pic_param->profile << 28 | |
| 1642 |
bit_depth_minus8 << 24 | |
| 1643 |
0 << 22 | /* only support 4:2:0 */ |
| 1644 |
pic_param->log2_tile_rows << 8 | |
| 1645 |
pic_param->log2_tile_columns << 0); /* DW 3 */ |
| 1646 |
// resolution change case |
| 1647 |
|
| 1648 |
// DW4-DW6 |
| 1649 |
for (i = 0; i < 3; i++) { |
| 1650 |
obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface; |
| 1651 |
gen9_vp9_surface = NULL; |
| 1652 |
scale_w = 0; |
| 1653 |
scale_h = 0; |
| 1654 |
if (obj_surface && obj_surface->private_data) { |
| 1655 |
gen9_vp9_surface = obj_surface->private_data; |
| 1656 |
if (!gen9_hcpd_vp9_valid_ref_frame_size(gen9_vp9_surface->frame_width, gen9_vp9_surface->frame_height, pic_param->frame_width, pic_param->frame_height)) { |
| 1657 |
scale_w = -1; |
| 1658 |
scale_h = -1; |
| 1659 |
} else { |
| 1660 |
scale_w = (gen9_vp9_surface->frame_width << 14) / pic_param->frame_width ; |
| 1661 |
scale_h = (gen9_vp9_surface->frame_height << 14) / pic_param->frame_height ; |
| 1662 |
} |
| 1663 |
OUT_BCS_BATCH(batch, |
| 1664 |
scale_w << 16 | |
| 1665 |
scale_h); |
| 1666 |
} else { |
| 1667 |
OUT_BCS_BATCH(batch, 0); |
| 1668 |
} |
| 1669 |
} |
| 1670 |
|
| 1671 |
// DW7-DW9 |
| 1672 |
for (i = 0; i < 3; i++) { |
| 1673 |
obj_surface = gen9_hcpd_context->reference_surfaces[i].obj_surface; |
| 1674 |
gen9_vp9_surface = NULL; |
| 1675 |
|
| 1676 |
if (obj_surface && obj_surface->private_data) { |
| 1677 |
gen9_vp9_surface = obj_surface->private_data; |
| 1678 |
OUT_BCS_BATCH(batch, |
| 1679 |
((gen9_vp9_surface->frame_height - 1) & 0x3fff) << 16 | |
| 1680 |
((gen9_vp9_surface->frame_width - 1) & 0x3fff)); |
| 1681 |
} else { |
| 1682 |
OUT_BCS_BATCH(batch, 0); |
| 1683 |
} |
| 1684 |
} |
| 1685 |
|
| 1686 |
OUT_BCS_BATCH(batch, |
| 1687 |
pic_param->first_partition_size << 16 | |
| 1688 |
pic_param->frame_header_length_in_bytes << 0); /* DW 10 */ |
| 1689 |
OUT_BCS_BATCH(batch, |
| 1690 |
(0 << 3) | |
| 1691 |
(0 << 2) | |
| 1692 |
(1 << 1) | |
| 1693 |
(0 << 0)); /* DW 11, ignored */ |
| 1694 |
//Rest of the DWs are not valid for BXT |
| 1695 |
for (i = 12; i < LEN_COMMAND_OWN; i++) { |
| 1696 |
OUT_BCS_BATCH(batch, 0); |
| 1697 |
} |
| 1698 |
|
| 1699 |
ADVANCE_BCS_BATCH(batch); |
| 1700 |
|
| 1701 |
} |
| 1702 |
|
| 1703 |
static void |
| 1704 |
gen9_hcpd_vp9_segment_state(VADriverContextP ctx, |
| 1705 |
VADecPictureParameterBufferVP9 *pic_param, |
| 1706 |
VASegmentParameterVP9 *seg_param, uint8_t seg_id, |
| 1707 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1708 |
{ |
| 1709 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 1710 |
|
| 1711 |
int segment_ref = seg_param->segment_flags.fields.segment_reference; |
| 1712 |
|
| 1713 |
if ((pic_param->pic_fields.bits.frame_type == HCP_VP9_KEY_FRAME) |
| 1714 |
|| (pic_param->pic_fields.bits.intra_only)) |
| 1715 |
segment_ref = 0; |
| 1716 |
|
| 1717 |
BEGIN_BCS_BATCH(batch, 7); |
| 1718 |
|
| 1719 |
OUT_BCS_BATCH(batch, HCP_VP9_SEGMENT_STATE | (7 - 2)); |
| 1720 |
OUT_BCS_BATCH(batch, seg_id << 0); /* DW 1 - SegmentID */ |
| 1721 |
OUT_BCS_BATCH(batch, |
| 1722 |
seg_param->segment_flags.fields.segment_reference_enabled << 3 | |
| 1723 |
segment_ref << 1 | |
| 1724 |
seg_param->segment_flags.fields.segment_reference_skipped << 0); /* DW 2 */ |
| 1725 |
if (pic_param->filter_level) { |
| 1726 |
OUT_BCS_BATCH(batch, |
| 1727 |
seg_param->filter_level[1][1] << 24 | //FilterLevelRef1Mode1 |
| 1728 |
seg_param->filter_level[1][0] << 16 | //FilterLevelRef1Mode0 |
| 1729 |
seg_param->filter_level[0][1] << 8 | //FilterLevelRef0Mode1 |
| 1730 |
seg_param->filter_level[0][0] << 0); //FilterLevelRef0Mode0 /* DW 3 */ |
| 1731 |
OUT_BCS_BATCH(batch, |
| 1732 |
seg_param->filter_level[3][1] << 24 | //FilterLevelRef3Mode1 |
| 1733 |
seg_param->filter_level[3][0] << 16 | //FilterLevelRef3Mode0 |
| 1734 |
seg_param->filter_level[2][1] << 8 | //FilterLevelRef2Mode1 |
| 1735 |
seg_param->filter_level[2][0] << 0); //FilterLevelRef2Mode0 /* DW 4 */ |
| 1736 |
} else { |
| 1737 |
OUT_BCS_BATCH(batch, |
| 1738 |
0); /* DW 3 */ |
| 1739 |
OUT_BCS_BATCH(batch, |
| 1740 |
0); /* DW 4 */ |
| 1741 |
} |
| 1742 |
OUT_BCS_BATCH(batch, |
| 1743 |
seg_param->luma_ac_quant_scale << 16 | |
| 1744 |
seg_param->luma_dc_quant_scale << 0); /* DW 5 */ |
| 1745 |
OUT_BCS_BATCH(batch, |
| 1746 |
seg_param->chroma_ac_quant_scale << 16 | |
| 1747 |
seg_param->chroma_dc_quant_scale << 0); /* DW 6 */ |
| 1748 |
|
| 1749 |
ADVANCE_BCS_BATCH(batch); |
| 1750 |
|
| 1751 |
} |
| 1752 |
|
| 1753 |
static void |
| 1754 |
gen9_hcpd_vp9_bsd_object(VADriverContextP ctx, |
| 1755 |
VADecPictureParameterBufferVP9 *pic_param, |
| 1756 |
VASliceParameterBufferVP9 *slice_param, |
| 1757 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1758 |
{ |
| 1759 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 1760 |
int slice_data_size = slice_param->slice_data_size - pic_param->frame_header_length_in_bytes; |
| 1761 |
int slice_data_offset = slice_param->slice_data_offset + pic_param->frame_header_length_in_bytes; |
| 1762 |
|
| 1763 |
BEGIN_BCS_BATCH(batch, 3); |
| 1764 |
|
| 1765 |
OUT_BCS_BATCH(batch, HCP_BSD_OBJECT | (3 - 2)); |
| 1766 |
|
| 1767 |
OUT_BCS_BATCH(batch, slice_data_size); |
| 1768 |
OUT_BCS_BATCH(batch, slice_data_offset); |
| 1769 |
|
| 1770 |
ADVANCE_BCS_BATCH(batch); |
| 1771 |
|
| 1772 |
} |
| 1773 |
|
| 1774 |
static VAStatus |
| 1775 |
gen9_hcpd_vp9_decode_picture(VADriverContextP ctx, |
| 1776 |
struct decode_state *decode_state, |
| 1777 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1778 |
{ |
| 1779 |
VAStatus vaStatus = VA_STATUS_SUCCESS; |
| 1780 |
struct i965_driver_data *i965 = i965_driver_data(ctx); |
| 1781 |
struct intel_batchbuffer *batch = gen9_hcpd_context->base.batch; |
| 1782 |
VADecPictureParameterBufferVP9 *pic_param; |
| 1783 |
VASliceParameterBufferVP9 *slice_param; |
| 1784 |
dri_bo *slice_data_bo; |
| 1785 |
dri_bo *tmp_bo; |
| 1786 |
uint16_t tmp; |
| 1787 |
int i = 0, num_segments = 0; |
| 1788 |
|
| 1789 |
assert(decode_state->pic_param && decode_state->pic_param->buffer); |
| 1790 |
assert(decode_state->slice_params && decode_state->slice_params[0]->buffer); |
| 1791 |
slice_param = (VASliceParameterBufferVP9 *)decode_state->slice_params[0]->buffer; |
| 1792 |
pic_param = (VADecPictureParameterBufferVP9 *)decode_state->pic_param->buffer; |
| 1793 |
|
| 1794 |
if (slice_param->slice_data_size == 1) { |
| 1795 |
goto out; |
| 1796 |
} |
| 1797 |
|
| 1798 |
vaStatus = gen9_hcpd_vp9_decode_init(ctx, decode_state, gen9_hcpd_context); |
| 1799 |
|
| 1800 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 1801 |
goto out; |
| 1802 |
|
| 1803 |
//Update segment id buffer if needed |
| 1804 |
vp9_update_segmentId_buffer(ctx, decode_state, gen9_hcpd_context); |
| 1805 |
//Update mv buffer if needed |
| 1806 |
vp9_update_mv_temporal_buffer(ctx, decode_state, gen9_hcpd_context); |
| 1807 |
//Update probability buffer if needed |
| 1808 |
vp9_update_probabilities(ctx, decode_state, gen9_hcpd_context); |
| 1809 |
|
| 1810 |
if (i965->intel.has_bsd2) |
| 1811 |
intel_batchbuffer_start_atomic_bcs_override(batch, 0x1000, BSD_RING0); |
| 1812 |
else |
| 1813 |
intel_batchbuffer_start_atomic_bcs(batch, 0x1000); |
| 1814 |
intel_batchbuffer_emit_mi_flush(batch); |
| 1815 |
|
| 1816 |
gen9_hcpd_pipe_mode_select(ctx, decode_state, HCP_CODEC_VP9, gen9_hcpd_context); |
| 1817 |
//Not sure what the surface id value should be: Gold? ALtRef? PrevRef? or Just RefPic? |
| 1818 |
gen9_hcpd_vp9_surface_state(ctx, decode_state, gen9_hcpd_context); |
| 1819 |
|
| 1820 |
//Only one VASliceParameterBufferVP9 should be sent per frame |
| 1821 |
slice_data_bo = decode_state->slice_datas[0]->bo; |
| 1822 |
|
| 1823 |
gen9_hcpd_vp9_pipe_buf_addr_state(ctx, decode_state, gen9_hcpd_context); |
| 1824 |
|
| 1825 |
if (IS_GEN10(i965->intel.device_info)) |
| 1826 |
gen10_hcpd_ind_obj_base_addr_state(ctx, slice_data_bo, gen9_hcpd_context); |
| 1827 |
else |
| 1828 |
gen9_hcpd_ind_obj_base_addr_state(ctx, slice_data_bo, gen9_hcpd_context); |
| 1829 |
|
| 1830 |
//If segmentation is disabled, only SegParam[0] is valid, |
| 1831 |
//all others should be populated with 0 |
| 1832 |
if (!pic_param->pic_fields.bits.segmentation_enabled) |
| 1833 |
num_segments = 1; |
| 1834 |
else //If segmentation is enabled, all 8 entries should be valid. |
| 1835 |
num_segments = 8; |
| 1836 |
|
| 1837 |
for (i = 0; i < num_segments; i++) { |
| 1838 |
VASegmentParameterVP9 seg_param = slice_param->seg_param[i]; |
| 1839 |
gen9_hcpd_vp9_segment_state(ctx, pic_param, &seg_param, i, gen9_hcpd_context); |
| 1840 |
} |
| 1841 |
|
| 1842 |
gen9_hcpd_vp9_pic_state(ctx, decode_state, gen9_hcpd_context); |
| 1843 |
gen9_hcpd_vp9_bsd_object(ctx, pic_param, slice_param, gen9_hcpd_context); |
| 1844 |
|
| 1845 |
intel_batchbuffer_end_atomic(batch); |
| 1846 |
intel_batchbuffer_flush(batch); |
| 1847 |
|
| 1848 |
// keep track of the last frame status |
| 1849 |
gen9_hcpd_context->last_frame.frame_width = pic_param->frame_width; |
| 1850 |
gen9_hcpd_context->last_frame.frame_height = pic_param->frame_height; |
| 1851 |
gen9_hcpd_context->last_frame.show_frame = pic_param->pic_fields.bits.show_frame; |
| 1852 |
gen9_hcpd_context->last_frame.frame_type = pic_param->pic_fields.bits.frame_type; |
| 1853 |
gen9_hcpd_context->last_frame.refresh_frame_context = pic_param->pic_fields.bits.refresh_frame_context; |
| 1854 |
gen9_hcpd_context->last_frame.frame_context_idx = pic_param->pic_fields.bits.frame_context_idx; |
| 1855 |
gen9_hcpd_context->last_frame.intra_only = pic_param->pic_fields.bits.intra_only; |
| 1856 |
dri_bo_unreference(gen9_hcpd_context->last_frame.prob_buffer_bo); |
| 1857 |
gen9_hcpd_context->last_frame.prob_buffer_bo = gen9_hcpd_context->vp9_probability_buffer.bo; |
| 1858 |
dri_bo_reference(gen9_hcpd_context->last_frame.prob_buffer_bo); |
| 1859 |
|
| 1860 |
// switch mv buffer |
| 1861 |
if (pic_param->pic_fields.bits.frame_type != HCP_VP9_KEY_FRAME) { |
| 1862 |
tmp_bo = gen9_hcpd_context->vp9_mv_temporal_buffer_last.bo; |
| 1863 |
gen9_hcpd_context->vp9_mv_temporal_buffer_last.bo = gen9_hcpd_context->vp9_mv_temporal_buffer_curr.bo; |
| 1864 |
gen9_hcpd_context->vp9_mv_temporal_buffer_curr.bo = tmp_bo; |
| 1865 |
|
| 1866 |
tmp = gen9_hcpd_context->vp9_mv_temporal_buffer_last.frame_width; |
| 1867 |
gen9_hcpd_context->vp9_mv_temporal_buffer_last.frame_width = gen9_hcpd_context->vp9_mv_temporal_buffer_curr.frame_width; |
| 1868 |
gen9_hcpd_context->vp9_mv_temporal_buffer_curr.frame_width = tmp; |
| 1869 |
|
| 1870 |
tmp = gen9_hcpd_context->vp9_mv_temporal_buffer_last.frame_height; |
| 1871 |
gen9_hcpd_context->vp9_mv_temporal_buffer_last.frame_height = gen9_hcpd_context->vp9_mv_temporal_buffer_curr.frame_height; |
| 1872 |
gen9_hcpd_context->vp9_mv_temporal_buffer_curr.frame_height = tmp; |
| 1873 |
|
| 1874 |
|
| 1875 |
} |
| 1876 |
out: |
| 1877 |
return vaStatus; |
| 1878 |
} |
| 1879 |
|
| 1880 |
|
| 1881 |
static VAStatus |
| 1882 |
gen9_hcpd_decode_picture(VADriverContextP ctx, |
| 1883 |
VAProfile profile, |
| 1884 |
union codec_state *codec_state, |
| 1885 |
struct hw_context *hw_context) |
| 1886 |
{ |
| 1887 |
struct gen9_hcpd_context *gen9_hcpd_context = (struct gen9_hcpd_context *)hw_context; |
| 1888 |
struct decode_state *decode_state = &codec_state->decode; |
| 1889 |
VAStatus vaStatus; |
| 1890 |
|
| 1891 |
assert(gen9_hcpd_context); |
| 1892 |
|
| 1893 |
vaStatus = intel_decoder_sanity_check_input(ctx, profile, decode_state); |
| 1894 |
|
| 1895 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 1896 |
goto out; |
| 1897 |
|
| 1898 |
switch (profile) { |
| 1899 |
case VAProfileHEVCMain: |
| 1900 |
case VAProfileHEVCMain10: |
| 1901 |
vaStatus = gen9_hcpd_hevc_decode_picture(ctx, decode_state, gen9_hcpd_context); |
| 1902 |
break; |
| 1903 |
case VAProfileVP9Profile0: |
| 1904 |
case VAProfileVP9Profile2: |
| 1905 |
vaStatus = gen9_hcpd_vp9_decode_picture(ctx, decode_state, gen9_hcpd_context); |
| 1906 |
break; |
| 1907 |
|
| 1908 |
default: |
| 1909 |
/* should never get here 1!! */ |
| 1910 |
assert(0); |
| 1911 |
break; |
| 1912 |
} |
| 1913 |
|
| 1914 |
out: |
| 1915 |
return vaStatus; |
| 1916 |
} |
| 1917 |
|
| 1918 |
static void |
| 1919 |
gen9_hcpd_context_destroy(void *hw_context) |
| 1920 |
{ |
| 1921 |
struct gen9_hcpd_context *gen9_hcpd_context = (struct gen9_hcpd_context *)hw_context; |
| 1922 |
|
| 1923 |
FREE_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_line_buffer)); |
| 1924 |
FREE_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_line_buffer)); |
| 1925 |
FREE_GEN_BUFFER((&gen9_hcpd_context->deblocking_filter_tile_column_buffer)); |
| 1926 |
FREE_GEN_BUFFER((&gen9_hcpd_context->metadata_line_buffer)); |
| 1927 |
FREE_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_line_buffer)); |
| 1928 |
FREE_GEN_BUFFER((&gen9_hcpd_context->metadata_tile_column_buffer)); |
| 1929 |
FREE_GEN_BUFFER((&gen9_hcpd_context->sao_line_buffer)); |
| 1930 |
FREE_GEN_BUFFER((&gen9_hcpd_context->sao_tile_line_buffer)); |
| 1931 |
FREE_GEN_BUFFER((&gen9_hcpd_context->sao_tile_column_buffer)); |
| 1932 |
FREE_GEN_BUFFER((&gen9_hcpd_context->hvd_line_rowstore_buffer)); |
| 1933 |
FREE_GEN_BUFFER((&gen9_hcpd_context->hvd_tile_rowstore_buffer)); |
| 1934 |
FREE_GEN_BUFFER((&gen9_hcpd_context->vp9_probability_buffer)); |
| 1935 |
FREE_GEN_BUFFER((&gen9_hcpd_context->vp9_segment_id_buffer)); |
| 1936 |
dri_bo_unreference(gen9_hcpd_context->vp9_mv_temporal_buffer_curr.bo); |
| 1937 |
dri_bo_unreference(gen9_hcpd_context->vp9_mv_temporal_buffer_last.bo); |
| 1938 |
dri_bo_unreference(gen9_hcpd_context->last_frame.prob_buffer_bo); |
| 1939 |
|
| 1940 |
intel_batchbuffer_free(gen9_hcpd_context->base.batch); |
| 1941 |
free(gen9_hcpd_context); |
| 1942 |
} |
| 1943 |
|
| 1944 |
static void |
| 1945 |
gen9_hcpd_hevc_context_init(VADriverContextP ctx, |
| 1946 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1947 |
{ |
| 1948 |
hevc_gen_default_iq_matrix(&gen9_hcpd_context->iq_matrix_hevc); |
| 1949 |
} |
| 1950 |
|
| 1951 |
static void |
| 1952 |
gen9_hcpd_vp9_context_init(VADriverContextP ctx, |
| 1953 |
struct gen9_hcpd_context *gen9_hcpd_context) |
| 1954 |
{ |
| 1955 |
|
| 1956 |
gen9_hcpd_context->last_frame.frame_height = 0; |
| 1957 |
gen9_hcpd_context->last_frame.show_frame = 0; |
| 1958 |
gen9_hcpd_context->last_frame.frame_type = 0; |
| 1959 |
gen9_hcpd_context->last_frame.refresh_frame_context = 0; |
| 1960 |
gen9_hcpd_context->last_frame.frame_context_idx = 0; |
| 1961 |
gen9_hcpd_context->last_frame.intra_only = 0; |
| 1962 |
gen9_hcpd_context->last_frame.prob_buffer_saved_flag = 0; |
| 1963 |
gen9_hcpd_context->last_frame.prob_buffer_restored_flag = 0; |
| 1964 |
gen9_hcpd_context->last_frame.prob_buffer_bo = NULL; |
| 1965 |
|
| 1966 |
//Super block in VP9 is 64x64 |
| 1967 |
gen9_hcpd_context->ctb_size = 64; |
| 1968 |
gen9_hcpd_context->min_cb_size = 8; //Min block size is 8 |
| 1969 |
|
| 1970 |
vp9_gen_default_probabilities(ctx, gen9_hcpd_context); |
| 1971 |
} |
| 1972 |
|
| 1973 |
static struct hw_context * |
| 1974 |
gen9_hcpd_context_init(VADriverContextP ctx, struct object_config *object_config) |
| 1975 |
{ |
| 1976 |
struct intel_driver_data *intel = intel_driver_data(ctx); |
| 1977 |
struct gen9_hcpd_context *gen9_hcpd_context = calloc(1, sizeof(struct gen9_hcpd_context)); |
| 1978 |
int i; |
| 1979 |
|
| 1980 |
if (!gen9_hcpd_context) |
| 1981 |
return NULL; |
| 1982 |
|
| 1983 |
gen9_hcpd_context->base.destroy = gen9_hcpd_context_destroy; |
| 1984 |
gen9_hcpd_context->base.run = gen9_hcpd_decode_picture; |
| 1985 |
gen9_hcpd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_VEBOX, 0); |
| 1986 |
|
| 1987 |
for (i = 0; i < ARRAY_ELEMS(gen9_hcpd_context->reference_surfaces); i++) { |
| 1988 |
gen9_hcpd_context->reference_surfaces[i].surface_id = VA_INVALID_ID; |
| 1989 |
gen9_hcpd_context->reference_surfaces[i].frame_store_id = -1; |
| 1990 |
gen9_hcpd_context->reference_surfaces[i].obj_surface = NULL; |
| 1991 |
} |
| 1992 |
|
| 1993 |
switch (object_config->profile) { |
| 1994 |
case VAProfileHEVCMain: |
| 1995 |
case VAProfileHEVCMain10: |
| 1996 |
gen9_hcpd_hevc_context_init(ctx, gen9_hcpd_context); |
| 1997 |
break; |
| 1998 |
case VAProfileVP9Profile0: |
| 1999 |
case VAProfileVP9Profile2: |
| 2000 |
gen9_hcpd_vp9_context_init(ctx, gen9_hcpd_context); |
| 2001 |
break; |
| 2002 |
|
| 2003 |
default: |
| 2004 |
break; |
| 2005 |
} |
| 2006 |
|
| 2007 |
return (struct hw_context *)gen9_hcpd_context; |
| 2008 |
} |
| 2009 |
|
| 2010 |
struct hw_context * |
| 2011 |
gen9_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config) |
| 2012 |
{ |
| 2013 |
if (obj_config->profile == VAProfileHEVCMain || |
| 2014 |
obj_config->profile == VAProfileHEVCMain10 || |
| 2015 |
obj_config->profile == VAProfileVP9Profile0 || |
| 2016 |
obj_config->profile == VAProfileVP9Profile2) { |
| 2017 |
return gen9_hcpd_context_init(ctx, obj_config); |
| 2018 |
} else { |
| 2019 |
return gen8_dec_hw_context_init(ctx, obj_config); |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
void gen9_max_resolution(struct i965_driver_data *i965, |
| 2024 |
struct object_config *obj_config, |
| 2025 |
int *w, /* out */ |
| 2026 |
int *h) /* out */ |
| 2027 |
{ |
| 2028 |
if (obj_config->profile == VAProfileJPEGBaseline) { |
| 2029 |
*w = 8192; |
| 2030 |
*h = 8192; |
| 2031 |
} else { |
| 2032 |
*w = i965->codec_info->max_width; |
| 2033 |
*h = i965->codec_info->max_height; |
| 2034 |
} |
| 2035 |
} |