• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2021 Advanced Micro Devices, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #include "util/vl_vlc.h"
29 #include "util/u_handle_table.h"
30 #include "va_private.h"
31 
32 #define AV1_REFS_PER_FRAME 7
33 #define AV1_NUM_REF_FRAMES 8
34 #define AV1_MAX_SEGMENTS 8
35 #define AV1_SEG_LVL_MAX 8
36 #define AV1_MAX_CDEF_BITS_ARRAY 8
37 #define AV1_FG_MAX_NUM_Y_POINTS 14
38 #define AV1_FG_MAX_NUM_CBR_POINTS 10
39 #define AV1_FG_MAX_NUM_POS_LUMA 24
40 #define AV1_FG_MAX_NUM_POS_CHROMA 25
41 
tile_info(vlVaContext * context,VADecPictureParameterBufferAV1 * av1)42 static void tile_info(vlVaContext *context, VADecPictureParameterBufferAV1 *av1)
43 {
44    unsigned sbCols;
45    unsigned sbRows;
46    int width_sb;
47    int height_sb;
48    unsigned startSb, i;
49    unsigned MiCols = 2 * ((av1->frame_width_minus1 + 8) >> 3);
50    unsigned MiRows = 2 * ((av1->frame_height_minus1 + 8) >> 3);
51 
52    unsigned TileColsLog2 = util_logbase2_ceil(av1->tile_cols);
53    unsigned TileRowsLog2 = util_logbase2_ceil(av1->tile_rows);
54 
55    if (av1->pic_info_fields.bits.use_superres) {
56       unsigned width = ((av1->frame_width_minus1 + 1) * 8 + av1->superres_scale_denominator / 2)
57          / av1->superres_scale_denominator;
58       MiCols = 2 * (((width - 1) + 8) >> 3);
59    }
60 
61    sbCols = (av1->seq_info_fields.fields.use_128x128_superblock) ?
62       ((MiCols + 31) >> 5) : ((MiCols + 15) >> 4);
63    sbRows = (av1->seq_info_fields.fields.use_128x128_superblock) ?
64       ((MiRows + 31) >> 5) : ((MiRows + 15) >> 4);
65 
66    width_sb = sbCols;
67    height_sb = sbRows;
68 
69    if (av1->pic_info_fields.bits.uniform_tile_spacing_flag) {
70       unsigned tileWidthSb, tileHeightSb;
71 
72       tileWidthSb = (sbCols + (1 << TileColsLog2) - 1) >> TileColsLog2;
73       i = 0;
74       for (startSb = 0; startSb < sbCols; startSb += tileWidthSb) {
75          context->desc.av1.picture_parameter.tile_col_start_sb[i] = startSb;
76          context->desc.av1.picture_parameter.width_in_sbs[i] = tileWidthSb;
77          i++;
78       }
79       context->desc.av1.picture_parameter.tile_col_start_sb[i] = sbCols;
80 
81       tileHeightSb = (sbRows + (1 << TileRowsLog2) - 1) >> TileRowsLog2;
82       i = 0;
83       for (startSb = 0; startSb < sbRows; startSb += tileHeightSb) {
84          context->desc.av1.picture_parameter.tile_row_start_sb[i] = startSb;
85          context->desc.av1.picture_parameter.height_in_sbs[i] = tileHeightSb;
86          i++;
87       }
88       context->desc.av1.picture_parameter.tile_row_start_sb[i] = sbRows;
89    } else {
90       unsigned widestTileSb = 0;
91 
92       startSb = 0;
93       for (i = 0; startSb < sbCols; ++i) {
94          unsigned sizeSb;
95 
96          context->desc.av1.picture_parameter.tile_col_start_sb[i] = startSb;
97          sizeSb = (av1->width_in_sbs_minus_1)[i] + 1;
98          context->desc.av1.picture_parameter.width_in_sbs[i] = sizeSb;
99          widestTileSb = MAX2(sizeSb, widestTileSb);
100          startSb += sizeSb;
101          width_sb -= sizeSb;
102       }
103       context->desc.av1.picture_parameter.tile_col_start_sb[i] = startSb + width_sb;
104 
105       startSb = 0;
106       for (i = 0; startSb < sbRows; ++i) {
107          unsigned height_in_sbs_minus_1 = (av1->height_in_sbs_minus_1)[i];
108          context->desc.av1.picture_parameter.height_in_sbs[i] = height_in_sbs_minus_1 + 1;
109 
110          context->desc.av1.picture_parameter.tile_row_start_sb[i] = startSb;
111          startSb += height_in_sbs_minus_1 + 1;
112          height_sb -= height_in_sbs_minus_1 + 1;
113       }
114       context->desc.av1.picture_parameter.tile_row_start_sb[i] = startSb + height_sb;
115    }
116 }
117 
vlVaHandlePictureParameterBufferAV1(vlVaDriver * drv,vlVaContext * context,vlVaBuffer * buf)118 VAStatus vlVaHandlePictureParameterBufferAV1(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
119 {
120    VADecPictureParameterBufferAV1 *av1 = buf->data;
121    int i, j;
122    bool use_lr;
123    vlVaSurface *surf;
124 
125    assert(buf->size >= sizeof(VADecPictureParameterBufferAV1) && buf->num_elements == 1);
126 
127    context->desc.av1.picture_parameter.profile = av1->profile;
128    context->desc.av1.picture_parameter.seq_info_fields.use_128x128_superblock =
129       av1->seq_info_fields.fields.use_128x128_superblock;
130    context->desc.av1.picture_parameter.seq_info_fields.enable_filter_intra =
131       av1->seq_info_fields.fields.enable_filter_intra;
132    context->desc.av1.picture_parameter.seq_info_fields.enable_cdef =
133       av1->seq_info_fields.fields.enable_cdef;
134    context->desc.av1.picture_parameter.seq_info_fields.film_grain_params_present =
135       av1->seq_info_fields.fields.film_grain_params_present;
136    context->desc.av1.picture_parameter.seq_info_fields.enable_intra_edge_filter =
137       av1->seq_info_fields.fields.enable_intra_edge_filter;
138    context->desc.av1.picture_parameter.order_hint_bits_minus_1 = av1->order_hint_bits_minus_1;
139    context->desc.av1.picture_parameter.seq_info_fields.enable_interintra_compound =
140       av1->seq_info_fields.fields.enable_interintra_compound;
141    context->desc.av1.picture_parameter.seq_info_fields.enable_masked_compound =
142       av1->seq_info_fields.fields.enable_masked_compound;
143    context->desc.av1.picture_parameter.seq_info_fields.enable_dual_filter =
144       av1->seq_info_fields.fields.enable_dual_filter;
145    context->desc.av1.picture_parameter.seq_info_fields.enable_order_hint =
146       av1->seq_info_fields.fields.enable_order_hint;
147    context->desc.av1.picture_parameter.seq_info_fields.enable_jnt_comp =
148       av1->seq_info_fields.fields.enable_jnt_comp;
149 
150    context->desc.av1.picture_parameter.seq_info_fields.ref_frame_mvs =
151       av1->seq_info_fields.fields.enable_order_hint;
152 
153    context->desc.av1.picture_parameter.bit_depth_idx = av1->bit_depth_idx;
154    context->desc.av1.picture_parameter.seq_info_fields.mono_chrome =
155       av1->seq_info_fields.fields.mono_chrome;
156    context->desc.av1.picture_parameter.seq_info_fields.subsampling_x =
157       av1->seq_info_fields.fields.subsampling_x;
158    context->desc.av1.picture_parameter.seq_info_fields.subsampling_y =
159       av1->seq_info_fields.fields.subsampling_y;
160 
161    context->desc.av1.picture_parameter.pic_info_fields.showable_frame =
162       av1->pic_info_fields.bits.showable_frame;
163    context->desc.av1.picture_parameter.pic_info_fields.frame_type =
164       av1->pic_info_fields.bits.frame_type;
165    context->desc.av1.picture_parameter.pic_info_fields.show_frame =
166       av1->pic_info_fields.bits.show_frame;
167    context->desc.av1.picture_parameter.pic_info_fields.error_resilient_mode =
168       av1->pic_info_fields.bits.error_resilient_mode;
169    context->desc.av1.picture_parameter.pic_info_fields.disable_cdf_update =
170       av1->pic_info_fields.bits.disable_cdf_update;
171    context->desc.av1.picture_parameter.pic_info_fields.allow_screen_content_tools =
172       av1->pic_info_fields.bits.allow_screen_content_tools;
173    context->desc.av1.picture_parameter.pic_info_fields.force_integer_mv =
174       av1->pic_info_fields.bits.force_integer_mv;
175    context->desc.av1.picture_parameter.pic_info_fields.allow_intrabc =
176       av1->pic_info_fields.bits.allow_intrabc;
177    context->desc.av1.picture_parameter.pic_info_fields.use_superres =
178       av1->pic_info_fields.bits.use_superres;
179    context->desc.av1.picture_parameter.pic_info_fields.is_motion_mode_switchable =
180       av1->pic_info_fields.bits.is_motion_mode_switchable;
181    context->desc.av1.picture_parameter.pic_info_fields.allow_high_precision_mv =
182       av1->pic_info_fields.bits.allow_high_precision_mv;
183    context->desc.av1.picture_parameter.pic_info_fields.use_ref_frame_mvs =
184       av1->pic_info_fields.bits.use_ref_frame_mvs;
185    context->desc.av1.picture_parameter.pic_info_fields.disable_frame_end_update_cdf =
186       av1->pic_info_fields.bits.disable_frame_end_update_cdf;
187    context->desc.av1.picture_parameter.pic_info_fields.allow_warped_motion =
188       av1->pic_info_fields.bits.allow_warped_motion;
189    context->desc.av1.picture_parameter.pic_info_fields.uniform_tile_spacing_flag =
190       av1->pic_info_fields.bits.uniform_tile_spacing_flag;
191    context->desc.av1.picture_parameter.pic_info_fields.large_scale_tile =
192       av1->pic_info_fields.bits.large_scale_tile;
193 
194    context->desc.av1.picture_parameter.matrix_coefficients =
195       av1->matrix_coefficients;
196 
197    context->desc.av1.film_grain_target = NULL;
198    if (av1->film_grain_info.film_grain_info_fields.bits.apply_grain)
199       context->desc.av1.picture_parameter.current_frame_id = av1->current_display_picture;
200    else
201       context->desc.av1.picture_parameter.current_frame_id = av1->current_frame;
202 
203    context->desc.av1.picture_parameter.order_hint = av1->order_hint;
204    context->desc.av1.picture_parameter.primary_ref_frame = av1->primary_ref_frame;
205 
206    surf = handle_table_get(drv->htab, av1->current_frame);
207    if (!surf)
208       return VA_STATUS_ERROR_INVALID_SURFACE;
209 
210    context->desc.av1.picture_parameter.max_width = surf->templat.width;
211    context->desc.av1.picture_parameter.max_height = surf->templat.height;
212    context->desc.av1.picture_parameter.frame_width = av1->frame_width_minus1 + 1;
213    context->desc.av1.picture_parameter.frame_height = av1->frame_height_minus1 + 1;
214 
215    if (context->desc.av1.picture_parameter.frame_width > context->desc.av1.picture_parameter.max_width ||
216        context->desc.av1.picture_parameter.frame_height > context->desc.av1.picture_parameter.max_height)
217       return VA_STATUS_ERROR_INVALID_PARAMETER;
218 
219    context->desc.av1.picture_parameter.superres_scale_denominator =
220       av1->superres_scale_denominator;
221 
222    for (i = 0; i < AV1_REFS_PER_FRAME; ++i)
223       context->desc.av1.picture_parameter.ref_frame_idx[i] = av1->ref_frame_idx[i];
224    context->desc.av1.picture_parameter.refresh_frame_flags = 1;
225 
226    /* Tile Info */
227    context->desc.av1.picture_parameter.tile_cols = av1->tile_cols;
228    context->desc.av1.picture_parameter.tile_rows = av1->tile_rows;
229    context->desc.av1.picture_parameter.context_update_tile_id = av1->context_update_tile_id;
230    tile_info(context, av1);
231 
232    /* Quantization Params */
233    context->desc.av1.picture_parameter.base_qindex =  av1->base_qindex;
234    context->desc.av1.picture_parameter.y_dc_delta_q = av1->y_dc_delta_q;
235    context->desc.av1.picture_parameter.u_dc_delta_q = av1->u_dc_delta_q;
236    context->desc.av1.picture_parameter.u_ac_delta_q = av1->u_ac_delta_q;
237    context->desc.av1.picture_parameter.v_dc_delta_q = av1->v_dc_delta_q;
238    context->desc.av1.picture_parameter.v_ac_delta_q = av1->v_ac_delta_q;
239    context->desc.av1.picture_parameter.qmatrix_fields.using_qmatrix =
240       av1->qmatrix_fields.bits.using_qmatrix;
241    context->desc.av1.picture_parameter.qmatrix_fields.qm_y = av1->qmatrix_fields.bits.using_qmatrix
242       ? av1->qmatrix_fields.bits.qm_y : 0xf;
243    context->desc.av1.picture_parameter.qmatrix_fields.qm_u = av1->qmatrix_fields.bits.using_qmatrix
244       ? av1->qmatrix_fields.bits.qm_u : 0xf;
245    context->desc.av1.picture_parameter.qmatrix_fields.qm_v = av1->qmatrix_fields.bits.using_qmatrix
246       ? av1->qmatrix_fields.bits.qm_v : 0xf;
247 
248    /* Segmentation Params */
249    context->desc.av1.picture_parameter.seg_info.segment_info_fields.enabled =
250       av1->seg_info.segment_info_fields.bits.enabled;
251    context->desc.av1.picture_parameter.seg_info.segment_info_fields.update_map =
252       av1->seg_info.segment_info_fields.bits.update_map;
253    context->desc.av1.picture_parameter.seg_info.segment_info_fields.update_data =
254       av1->seg_info.segment_info_fields.bits.update_data;
255    context->desc.av1.picture_parameter.seg_info.segment_info_fields.temporal_update =
256       av1->seg_info.segment_info_fields.bits.temporal_update;
257    for (i = 0; i < AV1_MAX_SEGMENTS; ++i) {
258       for (j = 0; j < AV1_SEG_LVL_MAX; ++j)
259          context->desc.av1.picture_parameter.seg_info.feature_data[i][j] =
260             av1->seg_info.feature_data[i][j];
261       context->desc.av1.picture_parameter.seg_info.feature_mask[i] = av1->seg_info.feature_mask[i];
262    }
263 
264    /* Delta Q Params */
265    context->desc.av1.picture_parameter.mode_control_fields.delta_q_present_flag =
266       av1->mode_control_fields.bits.delta_q_present_flag;
267    context->desc.av1.picture_parameter.mode_control_fields.log2_delta_q_res =
268       av1->mode_control_fields.bits.log2_delta_q_res;
269 
270    /* Delta LF Params */
271    context->desc.av1.picture_parameter.mode_control_fields.delta_lf_present_flag =
272       av1->mode_control_fields.bits.delta_lf_present_flag;
273    context->desc.av1.picture_parameter.mode_control_fields.log2_delta_lf_res =
274       av1->mode_control_fields.bits.log2_delta_lf_res;
275    context->desc.av1.picture_parameter.mode_control_fields.delta_lf_multi =
276       av1->mode_control_fields.bits.delta_lf_multi;
277 
278    context->desc.av1.picture_parameter.mode_control_fields.tx_mode =
279       av1->mode_control_fields.bits.tx_mode;
280    context->desc.av1.picture_parameter.mode_control_fields.reference_select =
281       av1->mode_control_fields.bits.reference_select;
282    context->desc.av1.picture_parameter.mode_control_fields.reduced_tx_set_used =
283       av1->mode_control_fields.bits.reduced_tx_set_used;
284    context->desc.av1.picture_parameter.mode_control_fields.skip_mode_present =
285       av1->mode_control_fields.bits.skip_mode_present;
286 
287    /* Loop Filter Params */
288    context->desc.av1.picture_parameter.interp_filter = av1->interp_filter;
289    for (i = 0; i < 2; ++i)
290       context->desc.av1.picture_parameter.filter_level[i] = av1->filter_level[i];
291    context->desc.av1.picture_parameter.filter_level_u = av1->filter_level_u;
292    context->desc.av1.picture_parameter.filter_level_v = av1->filter_level_v;
293    context->desc.av1.picture_parameter.loop_filter_info_fields.sharpness_level =
294       av1->loop_filter_info_fields.bits.sharpness_level;
295    context->desc.av1.picture_parameter.loop_filter_info_fields.mode_ref_delta_enabled =
296       av1->loop_filter_info_fields.bits.mode_ref_delta_enabled;
297    context->desc.av1.picture_parameter.loop_filter_info_fields.mode_ref_delta_update =
298       av1->loop_filter_info_fields.bits.mode_ref_delta_update;
299    for (i = 0; i < AV1_NUM_REF_FRAMES; ++i)
300       context->desc.av1.picture_parameter.ref_deltas[i] = av1->ref_deltas[i];
301    for (i = 0; i < 2; ++i)
302       context->desc.av1.picture_parameter.mode_deltas[i] = av1->mode_deltas[i];
303 
304    /* CDEF Params */
305    context->desc.av1.picture_parameter.cdef_damping_minus_3 = av1->cdef_damping_minus_3;
306    context->desc.av1.picture_parameter.cdef_bits = av1->cdef_bits;
307    for (i = 0; i < AV1_MAX_CDEF_BITS_ARRAY; ++i) {
308       context->desc.av1.picture_parameter.cdef_y_strengths[i] = av1->cdef_y_strengths[i];
309       context->desc.av1.picture_parameter.cdef_uv_strengths[i] = av1->cdef_uv_strengths[i];
310    }
311 
312    /* Loop Restoration Params */
313    context->desc.av1.picture_parameter.loop_restoration_fields.yframe_restoration_type =
314       av1->loop_restoration_fields.bits.yframe_restoration_type;
315    context->desc.av1.picture_parameter.loop_restoration_fields.cbframe_restoration_type =
316       av1->loop_restoration_fields.bits.cbframe_restoration_type;
317    context->desc.av1.picture_parameter.loop_restoration_fields.crframe_restoration_type =
318       av1->loop_restoration_fields.bits.crframe_restoration_type;
319    context->desc.av1.picture_parameter.loop_restoration_fields.lr_unit_shift =
320       av1->loop_restoration_fields.bits.lr_unit_shift;
321    context->desc.av1.picture_parameter.loop_restoration_fields.lr_uv_shift =
322       av1->loop_restoration_fields.bits.lr_uv_shift;
323 
324    use_lr = av1->loop_restoration_fields.bits.yframe_restoration_type ||
325             av1->loop_restoration_fields.bits.cbframe_restoration_type ||
326             av1->loop_restoration_fields.bits.crframe_restoration_type;
327 
328    if (use_lr) {
329       context->desc.av1.picture_parameter.lr_unit_size[0]
330          = 1 << (6 + av1->loop_restoration_fields.bits.lr_unit_shift);
331       context->desc.av1.picture_parameter.lr_unit_size[1]
332          = 1 << (6 + av1->loop_restoration_fields.bits.lr_unit_shift
333                    - av1->loop_restoration_fields.bits.lr_uv_shift);
334       context->desc.av1.picture_parameter.lr_unit_size[2]
335          = context->desc.av1.picture_parameter.lr_unit_size[1];
336    } else {
337       for (i = 0; i < 3; ++i)
338          context->desc.av1.picture_parameter.lr_unit_size[i] = (1 << 8);
339    }
340 
341    /* Global Motion Params */
342    for (i = 0; i < ARRAY_SIZE(av1->wm); ++i) {
343       context->desc.av1.picture_parameter.wm[i].wmtype = av1->wm[i].wmtype;
344       context->desc.av1.picture_parameter.wm[i].invalid = av1->wm[i].invalid;
345       for (j = 0; j < ARRAY_SIZE(av1->wm[0].wmmat); ++j)
346          context->desc.av1.picture_parameter.wm[i].wmmat[j] = av1->wm[i].wmmat[j];
347    }
348 
349    /* Film Grain Params */
350    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.apply_grain =
351       av1->film_grain_info.film_grain_info_fields.bits.apply_grain;
352    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.chroma_scaling_from_luma =
353       av1->film_grain_info.film_grain_info_fields.bits.chroma_scaling_from_luma;
354    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.grain_scaling_minus_8 =
355       av1->film_grain_info.film_grain_info_fields.bits.grain_scaling_minus_8;
356    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.ar_coeff_lag =
357       av1->film_grain_info.film_grain_info_fields.bits.ar_coeff_lag;
358    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.ar_coeff_shift_minus_6 =
359       av1->film_grain_info.film_grain_info_fields.bits.ar_coeff_shift_minus_6;
360    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.grain_scale_shift =
361       av1->film_grain_info.film_grain_info_fields.bits.grain_scale_shift;
362    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.overlap_flag =
363       av1->film_grain_info.film_grain_info_fields.bits.overlap_flag;
364    context->desc.av1.picture_parameter.film_grain_info.film_grain_info_fields.clip_to_restricted_range =
365       av1->film_grain_info.film_grain_info_fields.bits.clip_to_restricted_range;
366 
367    context->desc.av1.picture_parameter.film_grain_info.grain_seed = av1->film_grain_info.grain_seed;
368    context->desc.av1.picture_parameter.film_grain_info.num_y_points = av1->film_grain_info.num_y_points;
369    for (i = 0; i < AV1_FG_MAX_NUM_Y_POINTS; ++i) {
370       context->desc.av1.picture_parameter.film_grain_info.point_y_value[i] =
371          av1->film_grain_info.point_y_value[i];
372       context->desc.av1.picture_parameter.film_grain_info.point_y_scaling[i] =
373          av1->film_grain_info.point_y_scaling[i];
374    }
375    context->desc.av1.picture_parameter.film_grain_info.num_cb_points = av1->film_grain_info.num_cb_points;
376    context->desc.av1.picture_parameter.film_grain_info.num_cr_points = av1->film_grain_info.num_cr_points;
377    for (i = 0; i < AV1_FG_MAX_NUM_CBR_POINTS; ++i) {
378       context->desc.av1.picture_parameter.film_grain_info.point_cb_value[i] =
379          av1->film_grain_info.point_cb_value[i];
380       context->desc.av1.picture_parameter.film_grain_info.point_cb_scaling[i] =
381          av1->film_grain_info.point_cb_scaling[i];
382       context->desc.av1.picture_parameter.film_grain_info.point_cr_value[i] =
383          av1->film_grain_info.point_cr_value[i];
384       context->desc.av1.picture_parameter.film_grain_info.point_cr_scaling[i] =
385          av1->film_grain_info.point_cr_scaling[i];
386    }
387 
388    for (i = 0; i < AV1_FG_MAX_NUM_POS_LUMA; ++i)
389       context->desc.av1.picture_parameter.film_grain_info.ar_coeffs_y[i] =
390          av1->film_grain_info.ar_coeffs_y[i];
391    for (i = 0; i < AV1_FG_MAX_NUM_POS_CHROMA; ++i) {
392       context->desc.av1.picture_parameter.film_grain_info.ar_coeffs_cb[i] =
393          av1->film_grain_info.ar_coeffs_cb[i];
394       context->desc.av1.picture_parameter.film_grain_info.ar_coeffs_cr[i] =
395          av1->film_grain_info.ar_coeffs_cr[i];
396    }
397    context->desc.av1.picture_parameter.film_grain_info.cb_mult = av1->film_grain_info.cb_mult;
398    context->desc.av1.picture_parameter.film_grain_info.cb_luma_mult = av1->film_grain_info.cb_luma_mult;
399    context->desc.av1.picture_parameter.film_grain_info.cb_offset = av1->film_grain_info.cb_offset;
400    context->desc.av1.picture_parameter.film_grain_info.cr_mult = av1->film_grain_info.cr_mult;
401    context->desc.av1.picture_parameter.film_grain_info.cr_luma_mult = av1->film_grain_info.cr_luma_mult;
402    context->desc.av1.picture_parameter.film_grain_info.cr_offset = av1->film_grain_info.cr_offset;
403 
404    for (i = 0 ; i < AV1_NUM_REF_FRAMES; ++i) {
405       if (av1->pic_info_fields.bits.frame_type == 0 && av1->pic_info_fields.bits.show_frame)
406          context->desc.av1.ref[i] = NULL;
407       else
408          vlVaGetReferenceFrame(drv, av1->ref_frame_map[i], &context->desc.av1.ref[i]);
409    }
410 
411    context->desc.av1.slice_parameter.slice_count = 0;
412 
413    return VA_STATUS_SUCCESS;
414 }
415 
vlVaHandleSliceParameterBufferAV1(vlVaContext * context,vlVaBuffer * buf)416 void vlVaHandleSliceParameterBufferAV1(vlVaContext *context, vlVaBuffer *buf)
417 {
418    VASliceParameterBufferAV1 *av1 = buf->data;
419 
420    for (uint32_t buffer_idx = 0; buffer_idx < buf->num_elements; buffer_idx++, av1++) {
421       uint32_t slice_index = context->desc.av1.slice_parameter.slice_count + buffer_idx;
422 
423       ASSERTED const size_t max_pipe_av1_slices = ARRAY_SIZE(context->desc.av1.slice_parameter.slice_data_offset);
424       assert(slice_index < max_pipe_av1_slices);
425 
426       context->desc.av1.slice_parameter.slice_data_size[slice_index] = av1->slice_data_size;
427       context->desc.av1.slice_parameter.slice_data_offset[slice_index] =
428          context->slice_data_offset + av1->slice_data_offset;
429       context->desc.av1.slice_parameter.slice_data_row[slice_index] = av1->tile_row;
430       context->desc.av1.slice_parameter.slice_data_col[slice_index] = av1->tile_column;
431       context->desc.av1.slice_parameter.slice_data_anchor_frame_idx[slice_index] = av1->anchor_frame_idx;
432    }
433    context->desc.av1.slice_parameter.slice_count += buf->num_elements;
434 }
435