OSDN Git Service

c61a79658d4309690ee91450d004a6492cb8896a
[android-x86/hardware-intel-common-vaapi.git] / src / gen9_vp9_encoder.h
1 /*
2  * Copyright © 2016 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  * SOFTWAR
23  *
24  * Authors:
25  *    Zhao, Yakui <yakui.zhao@intel.com>
26  *
27  */
28
29 #ifndef GEN9_VP9_ENCODER_H
30 #define GEN9_VP9_ENCODER_H
31
32 #include <drm.h>
33 #include <i915_drm.h>
34 #include <intel_bufmgr.h>
35
36 #include <va/va.h>
37 #include "i965_gpe_utils.h"
38
39 #include "vp9_probs.h"
40
41 struct encode_state;
42 struct intel_encoder_context;
43
44 #define KEY_FRAME        0
45 #define INTER_FRAME      1
46
47 #define INTEL_BRC_NONE   0
48 #define INTEL_BRC_CBR    1
49 #define INTEL_BRC_VBR    2
50 #define INTEL_BRC_CQP    3
51
52 typedef enum _VP9_MEDIA_STATE_TYPE
53 {
54     VP9_MEDIA_STATE_ENC_I_FRAME_DIST        = 0,
55     VP9_MEDIA_STATE_32X_SCALING                ,
56     VP9_MEDIA_STATE_16X_SCALING                ,
57     VP9_MEDIA_STATE_4X_SCALING                 ,
58     VP9_MEDIA_STATE_32X_ME                     ,
59     VP9_MEDIA_STATE_16X_ME                     ,
60     VP9_MEDIA_STATE_4X_ME                      ,
61     VP9_MEDIA_STATE_BRC_INIT_RESET             ,
62     VP9_MEDIA_STATE_BRC_UPDATE                 ,
63     VP9_MEDIA_STATE_MBENC_I_32x32            ,
64     VP9_MEDIA_STATE_MBENC_I_16x16            ,
65     VP9_MEDIA_STATE_MBENC_P                  ,
66     VP9_MEDIA_STATE_MBENC_TX                 ,
67     VP9_MEDIA_STATE_DYS                    ,
68     VP9_NUM_MEDIA_STATES
69 } VP9_MEDIA_STATE_TYPE;
70
71
72 enum vp9_walker_degree
73 {
74     VP9_NO_DEGREE = 0,
75     VP9_26_DEGREE,
76     VP9_45Z_DEGREE
77 };
78
79 struct vp9_encoder_kernel_parameter
80 {
81     unsigned int                curbe_size;
82     unsigned int                inline_data_size;
83     unsigned int                sampler_size;
84 };
85
86 struct vp9_encoder_scoreboard_parameter
87 {
88     unsigned int                mask;
89     unsigned int                type;
90     unsigned int                enable;
91     unsigned int                walkpat_flag;
92 };
93
94 typedef enum _INTEL_VP9_ENC_OPERATION
95 {
96     INTEL_VP9_ENC_SCALING4X = 0,
97     INTEL_VP9_ENC_SCALING2X,
98     INTEL_VP9_ENC_ME,
99     INTEL_VP9_ENC_BRC,
100     INTEL_VP9_ENC_MBENC,
101     INTEL_VP9_ENC_DYS
102 } INTEL_VP9_ENC_OPERATION;
103
104 struct gen9_surface_vp9
105 {
106     VADriverContextP ctx;
107     VASurfaceID scaled_4x_surface_id;
108     struct object_surface *scaled_4x_surface_obj;
109     VASurfaceID scaled_16x_surface_id;
110     struct object_surface *scaled_16x_surface_obj;
111
112     VASurfaceID dys_surface_id;
113     struct object_surface *dys_surface_obj;
114     VASurfaceID dys_4x_surface_id;
115     struct object_surface *dys_4x_surface_obj;
116     VASurfaceID dys_16x_surface_id;
117     struct object_surface *dys_16x_surface_obj;
118     int dys_frame_width;
119     int dys_frame_height;
120     int frame_width;
121     int frame_height;
122     unsigned int qp_value;
123     uint8_t dys_hme_flag;
124 };
125
126 /* The definition for Scaling */
127 enum vp9_binding_table_offset_scaling
128 {
129     VP9_BTI_SCALING_FRAME_SRC_Y                 = 0,
130     VP9_BTI_SCALING_FRAME_DST_Y                 = 1,
131     VP9_BTI_SCALING_FRAME_MBVPROCSTATS_DST_CM   = 6,
132     VP9_BTI_SCALING_NUM_SURFACES                = 8
133 };
134
135
136 typedef struct _vp9_scaling4x_curbe_data_cm
137 {
138     struct
139     {
140         uint32_t   input_picture_width  :16;
141         uint32_t   input_picture_height :16;
142     } dw0;
143
144     struct {
145         uint32_t   input_y_bti;
146     } dw1;
147
148     struct {
149         uint32_t   output_y_bti;
150     } dw2;
151
152     struct {
153         uint32_t reserved;
154     } dw3;
155
156     struct {
157         uint32_t reserved;
158     } dw4;
159
160     struct {
161         uint32_t reserved;
162     } dw5;
163
164     struct
165     {
166         uint32_t   reserved0                              : 1;
167         uint32_t   enable_mb_variance_output              : 1;
168         uint32_t   enable_mb_pixel_average_output         : 1;
169         uint32_t   enable_blk8x8_stat_output            : 1;
170         uint32_t   reserved1                             : 28;
171     } dw6;
172
173     struct {
174         uint32_t reserved;
175     } dw7;
176
177     struct {
178         uint32_t reserved;
179     } dw8;
180
181     struct {
182         uint32_t reserved;
183     } dw9;
184
185     struct {
186         uint32_t mbv_proc_stat_bti;
187     } dw10;
188
189     struct {
190         uint32_t reserved;
191     } dw11;
192 } vp9_scaling4x_curbe_data_cm;
193
194 typedef struct _vp9_scaling2x_curbe_data_cm
195 {
196     struct
197     {
198         uint32_t   input_picture_width  :16;
199         uint32_t   input_picture_height :16;
200     } dw0;
201
202     /* dw1-dw7 */
203     uint32_t reserved1[7];
204
205     struct {
206         uint32_t input_y_bti;
207     } dw8;
208
209     struct {
210         uint32_t output_y_bti;
211     } dw9;
212
213     uint32_t reserved2[2];
214 } vp9_scaling2x_curbe_data_cm;
215
216 typedef struct _vp9_scaling4x_inline_data_cm
217 {
218     struct
219     {
220         uint32_t       dstblk_hori_origin : 16;
221         uint32_t       dstblk_vert_origin : 16;
222     } dw0;
223
224     struct
225     {
226         uint32_t       horiblk_compmask_layer0 : 16;
227         uint32_t       vertblk_compmask_layer0 : 16;
228     } dw1;
229
230     struct
231     {
232         uint32_t       horiblk_compmask_layer1 : 16;
233         uint32_t       vertblk_compmask_layer1 : 16;
234     } dw2;
235
236     struct
237     {
238         uint32_t       horiblk_compmask_layer2 : 16;
239         uint32_t       vertblk_compmask_layer2 : 16;
240     } dw3;
241
242     struct
243     {
244         float       video_xscaling_step;
245     } dw4;
246
247     struct
248     {
249         float       video_step_delta;
250     } dw5;
251
252
253     struct
254     {
255         uint32_t       vert_blk_num                :17;
256         uint32_t       area_interest              :1;
257         uint32_t       reserved                   :14;
258     } dw6;
259
260     struct
261     {
262         uint32_t       grp_id_num;
263     } dw7;
264
265     struct
266     {
267         uint32_t       horiblk_compmask_layer3 : 16;
268         uint32_t       vertblk_compmask_layer3 : 16;
269     } dw8;
270
271     struct
272     {
273         uint32_t       horiblk_compmask_layer4 : 16;
274         uint32_t       vertblk_compmask_layer4 : 16;
275     } dw9;
276
277     struct
278     {
279         uint32_t       horiblk_compmask_layer5 : 16;
280         uint32_t       vertblk_compmask_layer5 : 16;
281     } dw10;
282
283     struct
284     {
285         uint32_t       horiblk_compmask_layer6 : 16;
286         uint32_t       vertblk_compmask_layer6 : 16;
287     } dw11;
288
289     struct
290     {
291         uint32_t       horiblk_compmask_layer7 : 16;
292         uint32_t       vertblk_compmask_layer7 : 16;
293     } dw12;
294
295     struct {
296         uint32_t reserved;
297     } dw13;
298
299     struct {
300         uint32_t reserved;
301     } dw14;
302
303     struct {
304         uint32_t reserved;
305     } dw15;
306 } vp9_scaling4x_inline_data_cm;
307
308 #define VP9_SCALING_4X                  0
309 #define VP9_SCALING_2X                  1
310 #define NUM_VP9_SCALING                 2
311
312 typedef struct _vp9_bti_scaling_offset
313 {
314     uint32_t   scaling_frame_src_y;
315     uint32_t   scaling_frame_dst_y;
316     uint32_t   reserved;
317     uint32_t   scaling_frame_mbv_proc_stat_dst;
318 } vp9_bti_scaling_offset;
319
320 struct vp9_scaling_context
321 {
322     struct i965_gpe_context gpe_contexts[NUM_VP9_SCALING];
323     vp9_bti_scaling_offset scaling_4x_bti;
324     vp9_bti_scaling_offset scaling_2x_bti;
325 };
326
327 struct gen9_search_path_delta
328 {
329     char search_path_delta_x:4;
330     char search_path_delta_y:4;
331 };
332
333 struct vp9_binding_table_me
334 {
335     uint32_t   memv_data_surface_offset;
336     uint32_t   memv16x_data_surface_offset;
337     uint32_t   me_dist_offset;
338     uint32_t   me_brc_dist_offset;
339     uint32_t   me_curr_picl0_offset;
340     uint32_t   me_curr_picl1_offset;
341 };
342
343 enum vp9_binding_table_offset_me
344 {
345     VP9_BTI_ME_MV_DATA_SURFACE              = 0,
346     VP9_BTI_16XME_MV_DATA_SURFACE           = 1,
347     VP9_BTI_ME_DISTORTION_SURFACE           = 2,
348     VP9_BTI_ME_BRC_DISTORTION_SURFACE       = 3,
349     VP9_BTI_ME_CURR_PIC_L0                  = 4,
350     VP9_BTI_ME_CURR_PIC_L1                  = VP9_BTI_ME_CURR_PIC_L0 + 17,
351     VP9_BTI_ME_NUM_SURFACES                 = VP9_BTI_ME_CURR_PIC_L1 + 5
352 };
353
354 enum VP9_ENC_ME_MODES
355 {
356     VP9_ENC_ME16X_BEFORE_ME4X       = 0,
357     VP9_ENC_ME16X_ONLY              = 1,
358     VP9_ENC_ME4X_ONLY               = 2,
359     VP9_ENC_ME4X_AFTER_ME16X        = 3
360 };
361
362 typedef struct _vp9_me_curbe_data
363 {
364     struct
365     {
366         uint32_t skip_mode_enable:1;
367         uint32_t adaptive_enable:1;
368         uint32_t bi_mix_dis:1;
369         uint32_t reserved0:2;
370         uint32_t early_ime_success_enable:1;
371         uint32_t reserved1:1;
372         uint32_t t8x8_flag_for_inter_enable:1;
373         uint32_t reserved2:16;
374         uint32_t early_ime_stop:8;
375     } dw0;
376
377     struct {
378         uint32_t max_num_mvs:6;
379         uint32_t reserved0:10;
380         uint32_t bi_weight:6;
381         uint32_t reserved1:6;
382         uint32_t uni_mix_disable:1;
383         uint32_t reserved2:3;
384     } dw1;
385
386     struct {
387         uint32_t max_len_sp:8;
388         uint32_t max_num_su:8;
389         uint32_t reserved0:16;
390     } dw2;
391
392     struct {
393         uint32_t src_size:2;
394         uint32_t reserved0:2;
395         uint32_t mb_type_remap:2;
396         uint32_t src_Access:1;
397         uint32_t ref_access:1;
398         uint32_t search_ctrl:3;
399         uint32_t dual_search_path_option:1;
400         uint32_t sub_pel_mode:2;
401         uint32_t skip_type:1;
402         uint32_t disable_field_cache_allocation:1;
403         uint32_t inter_chroma_mode:1;
404         uint32_t ft_enable:1;
405         uint32_t bme_disable_fbr:1;
406         uint32_t block_based_skip_enable:1;
407         uint32_t inter_sad:2;
408         uint32_t intra_sad:2;
409         uint32_t sub_mb_part_mask:7;
410         uint32_t reserved1:1;
411     } dw3;
412
413     struct {
414         uint32_t reserved0:8;
415         uint32_t picture_height_minus1:8;
416         uint32_t picture_width:8;
417         uint32_t reserved1:8;
418     } dw4;
419
420     struct {
421         uint32_t reserved0:8;
422         uint32_t qp_prime_y:8;
423         uint32_t ref_width:8;
424         uint32_t ref_height:8;
425     } dw5;
426
427     struct {
428         uint32_t reserved0:3;
429         uint32_t write_distortions:1;
430         uint32_t use_mv_from_prev_step:1;
431         uint32_t reserved1:3;
432         uint32_t super_combine_dist:8;
433         uint32_t max_vmvr:16;
434     } dw6;
435
436     struct {
437         uint32_t reserved0:16;
438         uint32_t mv_cost_scale_factor:2;
439         uint32_t bilinear_enable:1;
440         uint32_t src_field_polarity:1;
441         uint32_t weightedsad_harr:1;
442         uint32_t ac_only_haar:1;
443         uint32_t ref_id_cost_mode:1;
444         uint32_t reserved1:1;
445         uint32_t skip_center_mask:8;
446     } dw7;
447
448     struct {
449         uint32_t mode_0_cost:8;
450         uint32_t mode_1_cost:8;
451         uint32_t mode_2_cost:8;
452         uint32_t mode_3_cost:8;
453     } dw8;
454
455     struct {
456         uint32_t mode_4_cost:8;
457         uint32_t mode_5_cost:8;
458         uint32_t mode_6_cost:8;
459         uint32_t mode_7_cost:8;
460     } dw9;
461
462     struct {
463         uint32_t mode_8_cost:8;
464         uint32_t mode_9_cost:8;
465         uint32_t ref_id_cost:8;
466         uint32_t chroma_intra_mode_cost:8;
467     } dw10;
468
469     struct {
470         uint32_t mv_0_cost:8;
471         uint32_t mv_1_cost:8;
472         uint32_t mv_2_cost:8;
473         uint32_t mv_3_cost:8;
474     } dw11;
475
476     struct {
477         uint32_t mv_4_cost:8;
478         uint32_t mv_5_cost:8;
479         uint32_t mv_6_cost:8;
480         uint32_t mv_7_cost:8;
481     } dw12;
482
483     struct {
484         uint32_t num_ref_idx_l0_minus1:8;
485         uint32_t num_ref_idx_l1_minus1:8;
486         uint32_t actual_mb_width:8;
487         uint32_t actual_mb_height:8;
488     } dw13;
489
490     struct {
491         uint32_t l0_ref_pic_polarity_bits:8;
492         uint32_t l1_ref_pic_polarity_bits:2;
493         uint32_t reserved:22;
494     } dw14;
495
496     struct {
497         uint32_t prev_mv_read_pos_factor : 8;
498         uint32_t mv_shift_factor : 8;
499         uint32_t reserved:16;
500     } dw15;
501
502     struct {
503         struct gen9_search_path_delta sp_delta_0;
504         struct gen9_search_path_delta sp_delta_1;
505         struct gen9_search_path_delta sp_delta_2;
506         struct gen9_search_path_delta sp_delta_3;
507     } dw16;
508
509     struct {
510         struct gen9_search_path_delta sp_delta_4;
511         struct gen9_search_path_delta sp_delta_5;
512         struct gen9_search_path_delta sp_delta_6;
513         struct gen9_search_path_delta sp_delta_7;
514     } dw17;
515
516     struct {
517         struct gen9_search_path_delta sp_delta_8;
518         struct gen9_search_path_delta sp_delta_9;
519         struct gen9_search_path_delta sp_delta_10;
520         struct gen9_search_path_delta sp_delta_11;
521     } dw18;
522
523     struct {
524         struct gen9_search_path_delta sp_delta_12;
525         struct gen9_search_path_delta sp_delta_13;
526         struct gen9_search_path_delta sp_delta_14;
527         struct gen9_search_path_delta sp_delta_15;
528     } dw19;
529
530     struct {
531         struct gen9_search_path_delta sp_delta_16;
532         struct gen9_search_path_delta sp_delta_17;
533         struct gen9_search_path_delta sp_delta_18;
534         struct gen9_search_path_delta sp_delta_19;
535     } dw20;
536
537     struct {
538         struct gen9_search_path_delta sp_delta_20;
539         struct gen9_search_path_delta sp_delta_21;
540         struct gen9_search_path_delta sp_delta_22;
541         struct gen9_search_path_delta sp_delta_23;
542     } dw21;
543
544     struct {
545         struct gen9_search_path_delta sp_delta_24;
546         struct gen9_search_path_delta sp_delta_25;
547         struct gen9_search_path_delta sp_delta_26;
548         struct gen9_search_path_delta sp_delta_27;
549     } dw22;
550
551     struct {
552         struct gen9_search_path_delta sp_delta_28;
553         struct gen9_search_path_delta sp_delta_29;
554         struct gen9_search_path_delta sp_delta_30;
555         struct gen9_search_path_delta sp_delta_31;
556     } dw23;
557
558     struct {
559         struct gen9_search_path_delta sp_delta_32;
560         struct gen9_search_path_delta sp_delta_33;
561         struct gen9_search_path_delta sp_delta_34;
562         struct gen9_search_path_delta sp_delta_35;
563     } dw24;
564
565     struct {
566         struct gen9_search_path_delta sp_delta_36;
567         struct gen9_search_path_delta sp_delta_37;
568         struct gen9_search_path_delta sp_delta_38;
569         struct gen9_search_path_delta sp_delta_39;
570     } dw25;
571
572     struct {
573         struct gen9_search_path_delta sp_delta_40;
574         struct gen9_search_path_delta sp_delta_41;
575         struct gen9_search_path_delta sp_delta_42;
576         struct gen9_search_path_delta sp_delta_43;
577     } dw26;
578
579     struct {
580         struct gen9_search_path_delta sp_delta_44;
581         struct gen9_search_path_delta sp_delta_45;
582         struct gen9_search_path_delta sp_delta_46;
583         struct gen9_search_path_delta sp_delta_47;
584     } dw27;
585
586     struct {
587         struct gen9_search_path_delta sp_delta_48;
588         struct gen9_search_path_delta sp_delta_49;
589         struct gen9_search_path_delta sp_delta_50;
590         struct gen9_search_path_delta sp_delta_51;
591     } dw28;
592
593     struct {
594         struct gen9_search_path_delta sp_delta_52;
595         struct gen9_search_path_delta sp_delta_53;
596         struct gen9_search_path_delta sp_delta_54;
597         struct gen9_search_path_delta sp_delta_55;
598     } dw29;
599
600     struct {
601         uint32_t reserved0;
602     } dw30;
603
604     struct {
605         uint32_t reserved0;
606     } dw31;
607
608     struct {
609         uint32_t _4x_memv_output_data_surf_index;
610     } dw32;
611
612     struct {
613         uint32_t _16x_32x_memv_input_data_surf_index;
614     } dw33;
615
616     struct {
617         uint32_t _4x_me_output_dist_surf_index;
618     } dw34;
619
620     struct {
621         uint32_t _4x_me_output_brc_dist_surf_index;
622     } dw35;
623
624     struct {
625         uint32_t vme_fwd_inter_pred_surf_index;
626     } dw36;
627
628     struct {
629         uint32_t vme_bdw_inter_pred_surf_index;
630     } dw37;
631
632     /* reserved */
633     struct {
634         uint32_t reserved;
635     } dw38;
636 } vp9_me_curbe_data;
637
638 struct vp9_me_context
639 {
640     struct i965_gpe_context gpe_context;
641     struct vp9_binding_table_me vp9_me_bti;
642 };
643
644
645 enum vp9_binding_table_offset_mbenc
646 {
647     VP9_BTI_MBENC_CURR_Y_G9                    = 0,
648     VP9_BTI_MBENC_CURR_UV_G9                   = 1,
649     VP9_BTI_MBENC_CURR_NV12_G9                 = 2,
650     VP9_BTI_MBENC_LAST_NV12_G9                 = 3,
651     VP9_BTI_MBENC_GOLD_NV12_G9                 = 5,
652     VP9_BTI_MBENC_ALTREF_NV12_G9               = 7,
653     VP9_BTI_MBENC_SEGMENTATION_MAP_G9          = 8,
654     VP9_BTI_MBENC_TX_CURBE_G9                  = 9,
655     VP9_BTI_MBENC_HME_MV_DATA_G9               = 10,
656     VP9_BTI_MBENC_HME_DISTORTION_G9            = 11,
657     VP9_BTI_MBENC_MODE_DECISION_PREV_G9        = 12,
658     VP9_BTI_MBENC_MODE_DECISION_G9             = 13,
659     VP9_BTI_MBENC_OUT_16x16_INTER_MODES_G9     = 14,
660     VP9_BTI_MBENC_CU_RECORDS_G9                = 15,
661     VP9_BTI_MBENC_PAK_DATA_G9                  = 16,
662     VP9_BTI_MBENC_NUM_SURFACES_G9              = 17,
663 };
664
665 struct vp9_binding_table_mbenc_i32
666 {
667     uint32_t   mbenc_curr_y;
668     uint32_t   mbenc_curr_uv;
669     uint32_t   mbenc_segmentation_map;
670     uint32_t   mbenc_mode_decision;
671 };
672
673 struct vp9_binding_table_mbenc_i16
674 {
675     uint32_t   mbenc_curr_y;
676     uint32_t   mbenc_curr_uv;
677     uint32_t   mbenc_curr_nv12;
678     uint32_t   mbenc_segmentation_map;
679     uint32_t   mbenc_tx_curbe;
680     uint32_t   mbenc_mode_decision;
681 };
682
683 struct vp9_binding_table_mbenc_p
684 {
685     uint32_t   mbenc_curr_y;
686     uint32_t   mbenc_curr_uv;
687     uint32_t   mbenc_curr_nv12;
688     uint32_t   mbenc_lastref_pic;
689     uint32_t   mbenc_goldref_pic;
690     uint32_t   mbenc_altref_pic;
691     uint32_t   mbenc_hme_mvdata;
692     uint32_t   mbenc_hme_distortion;
693     uint32_t   mbenc_segmentation_map;
694     uint32_t   mbenc_tx_curbe;
695     uint32_t   mbenc_mode_decision_prev;
696     uint32_t   mbenc_mode_decision;
697     uint32_t   mbenc_output_intermodes16x16;
698 };
699
700 struct vp9_binding_table_mbenc_tx
701 {
702     uint32_t   mbenc_curr_y;
703     uint32_t   mbenc_curr_uv;
704     uint32_t   mbenc_segmentation_map;
705     uint32_t   mbenc_mode_decision;
706     uint32_t   mbenc_cu_records;
707     uint32_t   mbenc_pak_data;
708 };
709
710 typedef struct _vp9_mbenc_curbe_data
711 {
712     struct {
713         uint32_t frame_width:16;
714         uint32_t frame_height:16;
715     } dw0;
716
717     struct {
718         uint32_t frame_type          : 8;
719         uint32_t segmentation_enable : 8;
720         uint32_t ref_frame_flags     : 8;
721         uint32_t min_16for32_check   : 8;
722     } dw1;
723
724     struct {
725         uint32_t multi_pred : 8;
726         uint32_t len_sp     : 8;
727         uint32_t search_x   : 8;
728         uint32_t search_y   : 8;
729     } dw2;
730
731     struct {
732         uint32_t hme_enabled : 8;
733         uint32_t multi_ref_qp_check : 8;
734         uint32_t disable_temp_pred : 8;
735         uint32_t min_ref_for32_check : 8;
736     } dw3;
737
738     struct {
739         uint32_t skip16_threshold : 16;
740         uint32_t disable_mr_threshold : 16;
741     } dw4;
742
743     struct {
744         uint32_t enable_mbrc : 8;
745         uint32_t inter_round : 8;
746         uint32_t intra_round : 8;
747         uint32_t frame_qpindex : 8;
748     } dw5;
749
750     struct {
751         uint32_t reserved;
752     } dw6;
753
754     struct {
755         uint32_t reserved;
756     } dw7;
757
758     struct {
759         uint32_t last_ref_qp : 16;
760         uint32_t golden_ref_qp : 16;
761     } dw8;
762
763     struct {
764         uint32_t alt_ref_qp : 16;
765         uint32_t reserved : 16;
766     } dw9;
767
768     struct {
769         uint32_t sum_intra_dist;
770     } dw10;
771
772     struct {
773         uint32_t sum_inter_dist;
774     } dw11;
775
776     struct {
777         uint32_t num_intra;
778     } dw12;
779
780     struct {
781         uint32_t num_lastref;
782     } dw13;
783
784     struct {
785         uint32_t num_goldref;
786     } dw14;
787
788     struct {
789         uint32_t num_altref;
790     } dw15;
791
792     struct {
793         uint32_t ime_search_path_delta03;
794     } dw16;
795
796     struct {
797         uint32_t ime_search_path_delta47;
798     } dw17;
799
800     struct {
801         uint32_t ime_search_path_delta811;
802     } dw18;
803
804     struct {
805         uint32_t ime_search_path_delta1215;
806     } dw19;
807
808     struct {
809         uint32_t ime_search_path_delta1619;
810     } dw20;
811
812     struct {
813         uint32_t ime_search_path_delta2023;
814     } dw21;
815
816     struct {
817         uint32_t ime_search_path_delta2427;
818     } dw22;
819
820     struct {
821         uint32_t ime_search_path_delta2831;
822     } dw23;
823
824     struct {
825         uint32_t ime_search_path_delta3235;
826     } dw24;
827
828     struct {
829         uint32_t ime_search_path_delta3639;
830     } dw25;
831
832     struct {
833         uint32_t ime_search_path_delta4043;
834     } dw26;
835
836     struct {
837         uint32_t ime_search_path_delta4447;
838     } dw27;
839
840     struct {
841         uint32_t ime_search_path_delta4851;
842     } dw28;
843
844     struct {
845         uint32_t ime_search_path_delta5255;
846     } dw29;
847
848     struct {
849         uint32_t reserved;
850     } dw30;
851
852     struct {
853         uint32_t reserved;
854     } dw31;
855
856     /* DW 32 */
857     struct {
858         struct {
859             uint32_t segment_qpindex : 8;
860             uint32_t intra_non_dcpenalty_16x16 : 8;
861             uint32_t intra_non_dcpenalty_8x8   : 8;
862             uint32_t intra_non_dcpenalty_4x4   : 8;
863         } dw32;
864
865         struct {
866             uint32_t intra_non_dcpenalty_32x32 : 16;
867             uint32_t reserved   : 16;
868         } dw33;
869
870
871         struct {
872             uint32_t zero_cost : 16;
873             uint32_t near_cost : 16;
874         } dw34;
875
876         struct {
877             uint32_t nearest_cost : 16;
878             uint32_t refid_cost : 16;
879         } dw35;
880
881         struct {
882             uint32_t mv_cost0 : 16;
883             uint32_t mv_cost1 : 16;
884         } dw36;
885
886         struct {
887             uint32_t mv_cost2 : 16;
888             uint32_t mv_cost3 : 16;
889         } dw37;
890
891         struct {
892             uint32_t mv_cost4 : 16;
893             uint32_t mv_cost5 : 16;
894         } dw38;
895
896         struct {
897             uint32_t mv_cost6 : 16;
898             uint32_t mv_cost7 : 16;
899         } dw39;
900
901         struct {
902             uint32_t mv_cost0 : 8;
903             uint32_t mv_cost1 : 8;
904             uint32_t mv_cost2 : 8;
905             uint32_t mv_cost3 : 8;
906         } dw40;
907
908         struct {
909             uint32_t mv_cost4 : 8;
910             uint32_t mv_cost5 : 8;
911             uint32_t mv_cost6 : 8;
912             uint32_t mv_cost7 : 8;
913         } dw41;
914
915         struct {
916             uint32_t mode_cost0 : 8;
917             uint32_t mode_cost1 : 8;
918             uint32_t mode_cost2 : 8;
919             uint32_t mode_cost3 : 8;
920         } dw42;
921
922         struct {
923             uint32_t mode_cost4 : 8;
924             uint32_t mode_cost5 : 8;
925             uint32_t mode_cost6 : 8;
926             uint32_t mode_cost7 : 8;
927         } dw43;
928
929         struct {
930             uint32_t mode_cost8 : 8;
931             uint32_t mode_cost9 : 8;
932             uint32_t refid_cost : 8;
933             uint32_t reserved : 8;
934         } dw44;
935
936         struct {
937             uint32_t mode_cost_intra32x32 : 16;
938             uint32_t mode_cost_inter32x32 : 16;
939         } dw45;
940
941         struct {
942             uint32_t mode_cost_intra32x16 : 16;
943             uint32_t reserved : 16;
944         } dw46;
945
946         struct {
947             uint32_t lambda_intra : 16;
948             uint32_t lambda_inter : 16;
949         } dw47;
950     } segments[8];
951
952     /*
953     Segment 0: dw32 - dw47
954     Segment 1 : dw48 - dw63
955     Segment 2 : dw64 - dw79
956     Segment 3 : dw80 - dw95
957     Segment 4 : dw96 - dw111
958     Segment 5 : dw112 - dw127
959     Segment 6 : dw128 - dw143
960     Segment 7 : dw144 - dw159
961     */
962
963     // dw160
964     struct {
965         uint32_t enc_curr_y_surf_bti;
966     } dw160;
967
968     struct {
969         uint32_t reserved;
970     } dw161;
971
972     struct {
973         uint32_t enc_curr_nv12_surf_bti;
974     } dw162;
975
976     struct {
977         uint32_t reserved;
978     } dw163;
979
980     struct {
981         uint32_t reserved;
982     } dw164;
983
984     struct {
985         uint32_t reserved;
986     } dw165;
987
988     struct {
989         uint32_t segmentation_map_bti;
990     } dw166;
991
992     struct {
993         uint32_t tx_curbe_bti;
994     } dw167;
995
996     struct {
997         uint32_t hme_mvdata_bti;
998     } dw168;
999
1000     struct {
1001         uint32_t hme_distortion_bti;
1002     } dw169;
1003
1004     struct {
1005         uint32_t reserved;
1006     } dw170;
1007
1008     struct {
1009         uint32_t mode_decision_prev_bti;
1010     } dw171;
1011
1012     struct {
1013         uint32_t mode_decision_bti;
1014     } dw172;
1015
1016     struct {
1017         uint32_t output_16x16_inter_modes_bti;
1018     } dw173;
1019
1020     struct {
1021         uint32_t cu_record_bti;
1022     } dw174;
1023
1024     struct {
1025         uint32_t pak_data_bti;
1026     } dw175;
1027 } vp9_mbenc_curbe_data;
1028
1029
1030
1031 #define    VP9_MBENC_IDX_KEY_32x32         0
1032 #define    VP9_MBENC_IDX_KEY_16x16         1
1033 #define    VP9_MBENC_IDX_INTER               2
1034 #define    VP9_MBENC_IDX_TX                  3
1035 #define    NUM_VP9_MBENC                     4
1036
1037 struct vp9_mbenc_context
1038 {
1039     struct i965_gpe_context gpe_contexts[NUM_VP9_MBENC];
1040     struct vp9_binding_table_mbenc_tx vp9_mbenc_tx_bti;
1041     struct vp9_binding_table_mbenc_i32 vp9_mbenc_i32_bti;
1042     struct vp9_binding_table_mbenc_i16 vp9_mbenc_i16_bti;
1043     struct vp9_binding_table_mbenc_p vp9_mbenc_p_bti;
1044     dri_bo *mbenc_bo_dys;
1045     int mbenc_bo_size;
1046 };
1047
1048 enum vp9_binding_table_offset_dys
1049 {
1050     VP9_BTI_DYS_INPUT_NV12                  = 0,
1051     VP9_BTI_DYS_OUTPUT_Y                    = 1,
1052     VP9_BTI_DYS_OUTPUT_UV                   = 2,
1053     VP9_BTI_DYS_NUM_SURFACES                = 3
1054 };
1055
1056 struct vp9_binding_table_dys
1057 {
1058     uint32_t   dys_input_frame_nv12;
1059     uint32_t   dys_output_frame_y;
1060     uint32_t   dys_output_frame_uv;
1061 };
1062
1063 typedef struct _vp9_dys_curbe_data
1064 {
1065     struct {
1066         uint32_t input_frame_width : 16;
1067         uint32_t input_frame_height: 16;
1068     } dw0;
1069
1070     struct {
1071         uint32_t output_frame_width : 16;
1072         uint32_t output_frame_height: 16;
1073     } dw1;
1074
1075     struct {
1076         float delta_u;
1077     } dw2;
1078
1079     struct {
1080         float delta_v;
1081     } dw3;
1082
1083     /* DW4-15 */
1084     uint32_t reserved[12];
1085
1086     struct {
1087         uint32_t input_frame_nv12_bti;
1088     } dw16;
1089
1090     struct {
1091         uint32_t output_frame_y_bti;
1092     } dw17;
1093
1094     struct {
1095         uint32_t avs_sample_idx;
1096     } dw18;
1097 } vp9_dys_curbe_data;
1098
1099 // DYS kernel parameters
1100 typedef struct _gen9_vp9_dys_kernel_param
1101 {
1102     uint32_t               input_width;
1103     uint32_t               input_height;
1104     uint32_t               output_width;
1105     uint32_t               output_height;
1106     struct object_surface  *input_surface;
1107     struct object_surface  *output_surface;
1108 } gen9_vp9_dys_kernel_param;
1109
1110 struct vp9_dys_context {
1111     struct i965_gpe_context gpe_context;
1112     struct vp9_binding_table_dys vp9_dys_bti;
1113 };
1114
1115 enum vp9_binding_table_offset_brc
1116 {
1117     VP9_BTI_BRC_SRCY4X_G9                          = 0,
1118     VP9_BTI_BRC_VME_COARSE_INTRA_G9                = 1,
1119     VP9_BTI_BRC_HISTORY_G9                         = 2,
1120     VP9_BTI_BRC_CONSTANT_DATA_G9                   = 3,
1121     VP9_BTI_BRC_DISTORTION_G9                      = 4,
1122     VP9_BTI_BRC_MMDK_PAK_OUTPUT_G9                 = 5,
1123     VP9_BTI_BRC_MBENC_CURBE_INPUT_G9               = 6,
1124     VP9_BTI_BRC_MBENC_CURBE_OUTPUT_G9              = 7,
1125     VP9_BTI_BRC_PIC_STATE_INPUT_G9                 = 8,
1126     VP9_BTI_BRC_PIC_STATE_OUTPUT_G9                = 9,
1127     VP9_BTI_BRC_SEGMENT_STATE_INPUT_G9             = 10,
1128     VP9_BTI_BRC_SEGMENT_STATE_OUTPUT_G9            = 11,
1129     VP9_BTI_BRC_BITSTREAM_SIZE_G9                  = 12,
1130     VP9_BTI_BRC_HFW_DATA_G9                        = 13,
1131     VP9_BTI_BRC_NUM_SURFACES_G9                    = 14,
1132 };
1133
1134 struct vp9_binding_table_brc_intra_dist
1135 {
1136     uint32_t   intra_dist_src_y4xsurface;
1137     uint32_t   brc_intra_dist_vme_coarse_intra;
1138     uint32_t   brc_intra_dist_distortion_buffer;
1139 };
1140
1141 struct vp9_binding_table_brc_init
1142 {
1143     uint32_t   brc_history_buffer;
1144     uint32_t   brc_distortion_buffer;
1145 };
1146
1147
1148 typedef struct _vp9_brc_curbe_data
1149 {
1150     struct {
1151         uint32_t frame_width : 16;
1152         uint32_t frame_height : 16;
1153     } dw0;
1154
1155     struct {
1156         uint32_t frame_type : 8;
1157         uint32_t segmentation_enable : 8;
1158         uint32_t ref_frame_flags : 8;
1159         uint32_t num_tlevels     : 8;
1160     } dw1;
1161
1162     struct {
1163         uint32_t reserved : 16;
1164         uint32_t intra_mode_disable : 8;
1165         uint32_t loop_filter_type : 8;
1166     } dw2;
1167
1168     struct {
1169         uint32_t max_level_ratiot0 : 8;
1170         uint32_t max_level_ratiot1 : 8;
1171         uint32_t max_level_ratiot2 : 8;
1172         uint32_t max_level_ratiot3 : 8;
1173     } dw3;
1174
1175     struct {
1176         uint32_t profile_level_max_frame;
1177     } dw4;
1178
1179     struct {
1180         uint32_t init_buf_fullness;
1181     } dw5;
1182
1183     struct {
1184         uint32_t buf_size;
1185     } dw6;
1186
1187     struct {
1188         uint32_t target_bit_rate;
1189     } dw7;
1190
1191     struct {
1192         uint32_t max_bit_rate;
1193     } dw8;
1194
1195     struct {
1196         uint32_t min_bit_rate;
1197     } dw9;
1198
1199     struct {
1200         uint32_t frame_ratem;
1201     } dw10;
1202
1203     struct {
1204         uint32_t frame_rated;
1205     } dw11;
1206
1207     struct {
1208         uint32_t brc_flag : 16;
1209         uint32_t gopp     : 16;
1210     } dw12;
1211
1212     struct {
1213         uint32_t init_frame_width : 16;
1214         uint32_t init_frame_height : 16;
1215     } dw13;
1216
1217     struct {
1218         uint32_t avbr_accuracy : 16;
1219         uint32_t avbr_convergence : 16;
1220     } dw14;
1221
1222     struct {
1223         uint32_t min_qp : 16;
1224         uint32_t max_qp : 16;
1225     } dw15;
1226
1227     struct {
1228         uint32_t cq_level : 16;
1229         uint32_t reserved : 16;
1230     } dw16;
1231
1232     struct {
1233         uint32_t enable_dynamic_scaling : 16;
1234         uint32_t brc_overshoot_cbr_pct  : 16;
1235     } dw17;
1236
1237     struct {
1238         uint32_t pframe_deviation_threshold0 : 8;
1239         uint32_t pframe_deviation_threshold1 : 8;
1240         uint32_t pframe_deviation_threshold2 : 8;
1241         uint32_t pframe_deviation_threshold3 : 8;
1242     } dw18;
1243
1244     struct {
1245         uint32_t pframe_deviation_threshold4 : 8;
1246         uint32_t pframe_deviation_threshold5 : 8;
1247         uint32_t pframe_deviation_threshold6 : 8;
1248         uint32_t pframe_deviation_threshold7 : 8;
1249     } dw19;
1250
1251     struct {
1252         uint32_t vbr_deviation_threshold0 : 8;
1253         uint32_t vbr_deviation_threshold1 : 8;
1254         uint32_t vbr_deviation_threshold2 : 8;
1255         uint32_t vbr_deviation_threshold3 : 8;
1256     } dw20;
1257
1258     struct {
1259         uint32_t vbr_deviation_threshold4 : 8;
1260         uint32_t vbr_deviation_threshold5 : 8;
1261         uint32_t vbr_deviation_threshold6 : 8;
1262         uint32_t vbr_deviation_threshold7 : 8;
1263     } dw21;
1264
1265     struct {
1266         uint32_t kframe_deviation_threshold0 : 8;
1267         uint32_t kframe_deviation_threshold1 : 8;
1268         uint32_t kframe_deviation_threshold2 : 8;
1269         uint32_t kframe_deviation_threshold3 : 8;
1270     } dw22;
1271
1272     struct {
1273         uint32_t kframe_deviation_threshold4 : 8;
1274         uint32_t kframe_deviation_threshold5 : 8;
1275         uint32_t kframe_deviation_threshold6 : 8;
1276         uint32_t kframe_deviation_threshold7 : 8;
1277     } dw23;
1278
1279     struct {
1280         uint32_t target_size;
1281     } dw24;
1282
1283     struct {
1284         uint32_t frame_number;
1285     } dw25;
1286
1287     struct {
1288         uint32_t reserved;
1289     } dw26;
1290
1291     struct {
1292         uint32_t hrd_buffer_fullness_upper_limit;
1293     } dw27;
1294
1295     struct {
1296         uint32_t hrd_buffer_fullness_lower_limit;
1297     } dw28;
1298
1299     struct {
1300         uint32_t reserved;
1301     } dw29;
1302
1303     struct {
1304         uint32_t reserved;
1305     } dw30;
1306
1307     struct {
1308         uint32_t reserved;
1309     } dw31;
1310
1311     struct {
1312         uint32_t seg_delta_qp0 : 8;
1313         uint32_t seg_delta_qp1 : 8;
1314         uint32_t seg_delta_qp2 : 8;
1315         uint32_t seg_delta_qp3 : 8;
1316     } dw32;
1317
1318     struct {
1319         uint32_t seg_delta_qp4 : 8;
1320         uint32_t seg_delta_qp5 : 8;
1321         uint32_t seg_delta_qp6 : 8;
1322         uint32_t seg_delta_qp7 : 8;
1323     } dw33;
1324
1325     struct {
1326         uint32_t temporal_id : 8;
1327         uint32_t multi_ref_qp_check : 8;
1328         uint32_t reserved  : 16;
1329     } dw34;
1330
1331     struct {
1332         uint32_t max_num_pak_passes : 8;
1333         uint32_t sync_async : 8;
1334         uint32_t overflow   : 8;
1335         uint32_t mbrc       : 8;
1336     } dw35;
1337
1338     struct {
1339         uint32_t reserved : 16;
1340         uint32_t segmentation : 8;
1341         uint32_t reserved1   : 8;
1342     } dw36;
1343
1344     struct {
1345         uint32_t cur_qpindex : 8;
1346         uint32_t lastref_qpindex  : 8;
1347         uint32_t goldref_qpindex  : 8;
1348         uint32_t altref_qpindex   : 8;
1349     } dw37;
1350
1351     struct {
1352         uint32_t qdelta_ydc : 8;
1353         uint32_t qdelta_uvac  : 8;
1354         uint32_t qdelta_uvdc  : 8;
1355         uint32_t reserved   : 8;
1356     } dw38;
1357
1358     struct {
1359         uint32_t reserved;
1360     } dw39;
1361
1362     struct {
1363         uint32_t reserved;
1364     } dw40;
1365
1366     struct {
1367         uint32_t reserved;
1368     } dw41;
1369
1370     struct {
1371         uint32_t reserved;
1372     } dw42;
1373
1374     struct {
1375         uint32_t reserved;
1376     } dw43;
1377
1378     struct {
1379         uint32_t reserved;
1380     } dw44;
1381
1382     struct {
1383         uint32_t reserved;
1384     } dw45;
1385
1386     struct {
1387         uint32_t reserved;
1388     } dw46;
1389
1390     struct {
1391         uint32_t reserved;
1392     } dw47;
1393
1394     struct {
1395         uint32_t brc_y4x_input_bti;
1396     } dw48;
1397
1398     struct {
1399         uint32_t brc_vme_coarse_intra_input_bti;
1400     } dw49;
1401
1402     struct {
1403         uint32_t brc_history_buffer_bti;
1404     } dw50;
1405
1406     struct {
1407         uint32_t brc_const_data_input_bti;
1408     } dw51;
1409
1410     struct {
1411         uint32_t brc_distortion_bti;
1412     } dw52;
1413
1414     struct {
1415         uint32_t brc_mmdk_pak_output_bti;
1416     } dw53;
1417
1418     struct {
1419         uint32_t brc_enccurbe_input_bti;
1420     } dw54;
1421
1422     struct {
1423         uint32_t brc_enccurbe_output_bti;
1424     } dw55;
1425
1426     struct {
1427         uint32_t brc_pic_state_input_bti;
1428     } dw56;
1429
1430     struct {
1431         uint32_t brc_pic_state_output_bti;
1432     } dw57;
1433
1434     struct {
1435         uint32_t brc_seg_state_input_bti;
1436     } dw58;
1437
1438     struct {
1439         uint32_t brc_seg_state_output_bti;
1440     } dw59;
1441
1442     struct {
1443         uint32_t brc_bitstream_size_data_bti;
1444     } dw60;
1445
1446     struct {
1447         uint32_t brc_hfw_data_output_bti;
1448     } dw61;
1449
1450     struct {
1451         uint32_t reserved;
1452     } dw62;
1453
1454     struct {
1455         uint32_t reserved;
1456     } dw63;
1457 } vp9_brc_curbe_data;
1458
1459
1460 #define    VP9_BRC_INTRA_DIST        0
1461 #define    VP9_BRC_INIT              1
1462 #define    VP9_BRC_RESET             2
1463 #define    VP9_BRC_UPDATE            3
1464 #define    NUM_VP9_BRC                   4
1465
1466 struct vp9_brc_context {
1467     struct i965_gpe_context gpe_contexts[NUM_VP9_BRC];
1468 };
1469
1470 struct gen9_vp9_scaling_curbe_param
1471 {
1472     uint32_t                input_picture_width;
1473     uint32_t                input_picture_height;
1474     bool                    use_16x_scaling;
1475     bool                    use_32x_scaling;
1476     bool                    mb_variance_output_enabled;
1477     bool                    mb_pixel_average_output_enabled;
1478     bool                    blk8x8_stat_enabled;
1479 };
1480
1481 struct gen9_vp9_me_curbe_param
1482 {
1483     VAEncSequenceParameterBufferVP9           *pseq_param;
1484     VAEncPictureParameterBufferVP9            *ppic_param;
1485     uint32_t                                   frame_width;
1486     uint32_t                                   frame_height;
1487     uint32_t                                   ref_frame_flag;
1488     bool                                       use_16x_me;
1489     bool                                       b16xme_enabled;
1490 };
1491
1492 struct gen9_vp9_mbenc_curbe_param
1493 {
1494     VAEncSequenceParameterBufferVP9           *pseq_param;
1495     VAEncPictureParameterBufferVP9            *ppic_param;
1496     VAEncMiscParameterTypeVP9PerSegmantParam  *psegment_param;
1497
1498     uint16_t                                    frame_width_in_mb;
1499     uint16_t                                    frame_height_in_mb;
1500     uint16_t                                    frame_type;
1501     bool                                        hme_enabled;
1502     uint8_t                                     ref_frame_flag;
1503     VP9_MEDIA_STATE_TYPE                        media_state_type;
1504     struct object_surface                       *curr_obj;
1505     struct object_surface                       *last_ref_obj;
1506     struct object_surface                       *golden_ref_obj;
1507     struct object_surface                       *alt_ref_obj;
1508     int                                         picture_coding_type;
1509     bool                                        mbenc_curbe_set_in_brc_update;
1510     bool                                        multi_ref_qp_check;
1511 };
1512
1513 struct gen9_vp9_dys_curbe_param
1514 {
1515     uint32_t                                   input_width;
1516     uint32_t                                   input_height;
1517     uint32_t                                   output_width;
1518     uint32_t                                   output_height;
1519 };
1520
1521 struct gen9_vp9_brc_curbe_param
1522 {
1523     VAEncSequenceParameterBufferVP9           *pseq_param;
1524     VAEncPictureParameterBufferVP9            *ppic_param;
1525     VAEncMiscParameterTypeVP9PerSegmantParam  *psegment_param;
1526
1527     VASurfaceID                                curr_frame;
1528     uint32_t                                   picture_coding_type;
1529     /* the unit is in bits */
1530     double    *pbrc_init_current_target_buf_full_in_bits;
1531     double    *pbrc_init_reset_input_bits_per_frame;
1532     uint32_t  *pbrc_init_reset_buf_size_in_bits;
1533     uint32_t  frame_width;
1534     uint32_t  frame_height;
1535     uint32_t  frame_width_in_mb;
1536     uint32_t  frame_height_in_mb;
1537     uint32_t  ref_frame_flag;
1538     bool      hme_enabled;
1539     bool      initbrc;
1540     bool      mbbrc_enabled;
1541     bool      b_used_ref;
1542     int32_t   brc_num_pak_passes;
1543     bool      multi_ref_qp_check;
1544     int16_t   frame_number;
1545     VP9_MEDIA_STATE_TYPE                       media_state_type;
1546 };
1547
1548 struct gen9_vp9_scaling_surface_param
1549 {
1550     VASurfaceID                         curr_pic;
1551     void                                *p_scaling_bti;
1552     struct object_surface               *input_surface;
1553     struct object_surface               *output_surface;
1554     uint32_t                            input_frame_width;
1555     uint32_t                            input_frame_height;
1556     uint32_t                            output_frame_width;
1557     uint32_t                            output_frame_height;
1558     uint32_t                            vert_line_stride;
1559     uint32_t                            vert_line_stride_offset;
1560     bool                                scaling_out_use_16unorm_surf_fmt;
1561     bool                                scaling_out_use_32unorm_surf_fmt;
1562     bool                                mbv_proc_stat_enabled;
1563     struct i965_gpe_resource            *pres_mbv_proc_stat_buffer;
1564 };
1565
1566 struct gen9_vp9_brc_init_constant_buffer_param
1567 {
1568     struct i965_gpe_resource               *pres_brc_const_data_buffer;
1569     uint16_t                               picture_coding_type;
1570 };
1571
1572 struct gen9_vp9_dys_surface_param
1573 {
1574     struct object_surface                  *input_frame;
1575     struct object_surface                  *output_frame;
1576     uint32_t                               vert_line_stride;
1577     uint32_t                               vert_line_stride_offset;
1578 };
1579
1580 struct gen9_vp9_me_surface_param
1581 {
1582     VASurfaceID                             curr_pic;
1583     struct object_surface                   *last_ref_pic;
1584     struct object_surface                   *golden_ref_pic;
1585     struct object_surface                   *alt_ref_pic;
1586
1587     struct i965_gpe_resource                *pres_4x_memv_data_buffer;
1588     struct i965_gpe_resource                *pres_16x_memv_data_buffer;
1589     struct i965_gpe_resource                *pres_me_distortion_buffer;
1590     struct i965_gpe_resource                *pres_me_brc_distortion_buffer;
1591     uint32_t                                downscaled_width_in_mb;
1592     uint32_t                                downscaled_height_in_mb;
1593     uint32_t                                frame_width;
1594     uint32_t                                frame_height;
1595     bool                                    use_16x_me;
1596     bool                                    b16xme_enabled;
1597     bool                                    dys_enabled;
1598 };
1599
1600 struct gen9_vp9_mbenc_surface_param
1601 {
1602     int                                 media_state_type;
1603     struct object_surface               *last_ref_obj;
1604     struct object_surface               *golden_ref_obj;
1605     struct object_surface               *alt_ref_obj;
1606     struct object_surface               *curr_frame_obj;
1607     unsigned short                      picture_coding_type;
1608     unsigned int                        curr_surface_offset;
1609     struct i965_gpe_resource            *ps4x_memv_data_buffer;
1610     struct i965_gpe_resource            *ps4x_memv_distortion_buffer;
1611     struct i965_gpe_resource            *ps_me_brc_distortion_buffer;
1612     uint32_t                            frame_width;
1613     uint32_t                            frame_height;
1614     uint32_t                            frame_width_in_mb;
1615     uint32_t                            frame_height_in_mb;
1616     bool                                hme_enabled;
1617     bool                                segmentation_enabled;
1618     uint32_t                            mb_data_offset;
1619     struct i965_gpe_resource            *pres_mb_code_surface;
1620     struct i965_gpe_resource            *pres_segmentation_map;
1621     struct i965_gpe_resource            *pres_mode_decision_prev;
1622     struct i965_gpe_resource            *pres_mode_decision;
1623     struct i965_gpe_resource            *pres_mbenc_curbe_buffer;
1624     struct i965_gpe_resource            *pres_output_16x16_inter_modes;
1625     struct i965_gpe_resource            *pres_mode_decision_i32;
1626
1627     struct i965_gpe_context              *gpe_context_tx;
1628 };
1629
1630 typedef struct _vp9_frame_status_
1631 {
1632     uint16_t frame_width;
1633     uint16_t frame_height;
1634     uint8_t frame_type;
1635     uint8_t show_frame;
1636     uint8_t refresh_frame_context;
1637     uint8_t frame_context_idx;
1638     uint8_t intra_only;
1639 } vp9_frame_status;
1640
1641 struct gen9_hcpe_pipe_mode_select_param
1642 {
1643     uint32_t                    codec_mode;
1644     uint32_t                    stream_out;
1645 };
1646
1647 typedef struct _hcp_surface_state {
1648     struct {
1649         uint32_t surface_pitch : 17;
1650         uint32_t reserved      : 11;
1651         uint32_t surface_id    : 4;
1652     } dw1;
1653
1654     struct {
1655         uint32_t y_cb_offset    : 15;
1656         uint32_t reserved       : 12;
1657         uint32_t surface_format : 5;
1658     } dw2;
1659
1660     struct {
1661         uint32_t default_alpha  : 16;
1662         uint32_t y_cr_offset    : 16;
1663     } dw3;
1664
1665     struct {
1666         uint32_t auxilary_index : 11;
1667         uint32_t reserved0      : 1;
1668         uint32_t memory_compression : 1;
1669         uint32_t reserved1      : 18;
1670     } dw4;
1671 } hcp_surface_state;
1672
1673 struct gen9_encoder_context_vp9
1674 {
1675     struct vp9_scaling_context scaling_context;
1676     struct vp9_me_context me_context;
1677     struct vp9_mbenc_context mbenc_context;
1678     struct vp9_brc_context brc_context;
1679     struct vp9_dys_context   dys_context;
1680     void *enc_priv_state;
1681
1682     struct i965_gpe_resource            res_brc_history_buffer;
1683     struct i965_gpe_resource            res_brc_const_data_buffer;
1684     struct i965_gpe_resource            res_brc_mmdk_pak_buffer;
1685     struct i965_gpe_resource            res_brc_mbenc_curbe_write_buffer;
1686     struct i965_gpe_resource            res_pic_state_brc_read_buffer;
1687     struct i965_gpe_resource            res_pic_state_brc_write_hfw_read_buffer;
1688     struct i965_gpe_resource            res_pic_state_hfw_write_buffer;
1689     struct i965_gpe_resource            res_seg_state_brc_read_buffer;
1690     struct i965_gpe_resource            res_seg_state_brc_write_buffer;
1691     struct i965_gpe_resource            res_brc_bitstream_size_buffer;
1692     struct i965_gpe_resource            res_brc_hfw_data_buffer;
1693
1694     struct i965_gpe_resource            s4x_memv_distortion_buffer;
1695     struct i965_gpe_resource            mb_segment_map_surface;
1696     struct i965_gpe_resource            s4x_memv_data_buffer;
1697     struct i965_gpe_resource            s16x_memv_data_buffer;
1698     struct i965_gpe_resource            res_mode_decision[2];
1699     struct i965_gpe_resource            res_output_16x16_inter_modes;
1700     struct i965_gpe_resource            res_mb_code_surface;
1701
1702     /* PAK resource */
1703     struct i965_gpe_resource            res_hvd_line_buffer;
1704     struct i965_gpe_resource            res_hvd_tile_line_buffer;
1705     struct i965_gpe_resource            res_deblocking_filter_line_buffer;
1706     struct i965_gpe_resource            res_deblocking_filter_tile_line_buffer;
1707     struct i965_gpe_resource            res_deblocking_filter_tile_col_buffer;
1708
1709     struct i965_gpe_resource            res_metadata_line_buffer;
1710     struct i965_gpe_resource            res_metadata_tile_line_buffer;
1711     struct i965_gpe_resource            res_metadata_tile_col_buffer;
1712
1713     struct i965_gpe_resource            res_segmentid_buffer;
1714     struct i965_gpe_resource            res_prob_buffer;
1715     struct i965_gpe_resource            res_prob_delta_buffer;
1716     struct i965_gpe_resource            res_prob_counter_buffer;
1717
1718     struct i965_gpe_resource            res_compressed_input_buffer;
1719     struct i965_gpe_resource            res_tile_record_streamout_buffer;
1720     struct i965_gpe_resource            res_cu_stat_streamout_buffer;
1721     struct i965_gpe_resource            res_mv_temporal_buffer[2];
1722     struct i965_gpe_resource            res_pak_uncompressed_input_buffer;
1723
1724     char *frame_header_data;
1725
1726     unsigned int use_hw_scoreboard;
1727     unsigned int use_hw_non_stalling_scoreboard;
1728     unsigned int mb_stats_supported;
1729     unsigned int hme_supported;
1730     unsigned int b32xme_supported;
1731
1732     unsigned int downscaled_width_in_mb4x;
1733     unsigned int downscaled_height_in_mb4x;
1734
1735     void (*pfn_set_sample_state_dys)(
1736         VADriverContextP ctx,
1737         struct encode_state *encode_state,
1738         struct i965_gpe_context *gpe_context,
1739         struct intel_encoder_context *encoder_context);
1740
1741     void (*pfn_set_curbe_mbenc)(
1742         VADriverContextP ctx,
1743         struct encode_state *encode_state,
1744         struct i965_gpe_context *gpe_context,
1745         struct intel_encoder_context *encoder_context,
1746         struct gen9_vp9_mbenc_curbe_param *param);
1747
1748     void (*pfn_set_curbe_me)(
1749         VADriverContextP ctx,
1750         struct encode_state *encode_state,
1751         struct i965_gpe_context *gpe_context,
1752         struct intel_encoder_context *encoder_context,
1753         struct gen9_vp9_me_curbe_param *param);
1754
1755     void (*pfn_set_curbe_scaling)(
1756         VADriverContextP ctx,
1757         struct encode_state *encode_state,
1758         struct i965_gpe_context *gpe_context,
1759         struct intel_encoder_context *encoder_context,
1760         struct gen9_vp9_scaling_curbe_param *param);
1761
1762     void (*pfn_set_curbe_dys)(
1763         VADriverContextP ctx,
1764         struct encode_state *encode_state,
1765         struct i965_gpe_context *gpe_context,
1766         struct intel_encoder_context *encoder_context,
1767         struct gen9_vp9_dys_curbe_param *param);
1768
1769     void (*pfn_set_curbe_brc)(
1770         VADriverContextP ctx,
1771         struct encode_state *encode_state,
1772         struct i965_gpe_context *gpe_context,
1773         struct intel_encoder_context *encoder_context,
1774         struct gen9_vp9_brc_curbe_param *param);
1775
1776     void (*pfn_send_me_surface)(
1777         VADriverContextP ctx,
1778         struct encode_state *encode_state,
1779         struct i965_gpe_context *gpe_context,
1780         struct intel_encoder_context *encoder_context,
1781         struct gen9_vp9_me_surface_param *param);
1782
1783     void (*pfn_send_mbenc_surface)(
1784         VADriverContextP ctx,
1785         struct encode_state *encode_state,
1786         struct i965_gpe_context *gpe_context,
1787         struct intel_encoder_context *encoder_context,
1788         struct gen9_vp9_mbenc_surface_param *mbenc_param);
1789
1790     void (*pfn_send_scaling_surface)(
1791         VADriverContextP ctx,
1792         struct encode_state *encode_state,
1793         struct i965_gpe_context *gpe_context,
1794         struct intel_encoder_context *encoder_context,
1795         struct gen9_vp9_scaling_surface_param *param);
1796
1797     void (*pfn_send_dys_surface)(
1798         VADriverContextP ctx,
1799         struct encode_state *encode_state,
1800         struct i965_gpe_context *gpe_context,
1801         struct intel_encoder_context *encoder_context,
1802         struct gen9_vp9_dys_surface_param *param);
1803
1804     struct {
1805         dri_bo *bo;
1806     } reconstructed_object;
1807
1808     struct {
1809         dri_bo *bo;
1810     } uncompressed_picture_source;
1811
1812     struct {
1813         dri_bo *bo;
1814         int offset;
1815         int end_offset;
1816         int status_offset;
1817     } indirect_pak_bse_object;
1818
1819     struct {
1820         dri_bo *bo;
1821     } reference_surfaces[8];
1822 };
1823
1824 enum INTEL_ENC_VP9_TU_MODE
1825 {
1826     INTEL_ENC_VP9_TU_QUALITY      = 0,
1827     INTEL_ENC_VP9_TU_NORMAL,
1828     INTEL_ENC_VP9_TU_PERFORMANCE
1829 };
1830
1831 #define VP9_LAST_REF           0x01
1832 #define VP9_GOLDEN_REF         0x02
1833 #define VP9_ALT_REF            0x04
1834
1835 struct vp9_encode_status
1836 {
1837     uint32_t bs_byte_count;
1838     uint32_t image_status_mask;
1839     uint32_t image_status_ctrl;
1840     uint32_t media_index;
1841 };
1842
1843 struct vp9_encode_status_buffer_internal
1844 {
1845     uint32_t bs_byte_count_offset;
1846     uint32_t reserved[15];
1847
1848     uint32_t image_status_mask_offset;
1849     uint32_t image_status_ctrl_offset;
1850
1851     uint32_t vp9_image_mask_reg_offset;
1852     uint32_t vp9_image_ctrl_reg_offset;
1853     uint32_t vp9_bs_frame_reg_offset;
1854     dri_bo *bo;
1855
1856     uint32_t media_index_offset;
1857 };
1858
1859
1860 struct gen9_vp9_state {
1861     unsigned int brc_inited;
1862     unsigned int brc_reset;
1863     unsigned int brc_enabled;
1864     unsigned int use_hw_scoreboard;
1865     unsigned int use_hw_non_stalling_scoreborad;
1866     unsigned int hme_supported;
1867     unsigned int b16xme_supported;
1868     unsigned int hme_enabled;
1869     unsigned int b16xme_enabled;
1870
1871     unsigned int frame_width;
1872     unsigned int frame_height;
1873     unsigned int frame_width_in_mb;
1874     unsigned int frame_height_in_mb;
1875     unsigned int frame_width_4x;
1876     unsigned int frame_height_4x;
1877     unsigned int frame_width_16x;
1878     unsigned int frame_height_16x;
1879     unsigned int downscaled_width_4x_in_mb;
1880     unsigned int downscaled_height_4x_in_mb;
1881     unsigned int downscaled_width_16x_in_mb;
1882     unsigned int downscaled_height_16x_in_mb;
1883
1884     unsigned int res_width;
1885     unsigned int res_height;
1886     int          brc_allocated;
1887     VASurfaceID  curr_frame;
1888     VASurfaceID  last_ref_pic;
1889     VASurfaceID  alt_ref_pic;
1890     VASurfaceID  golden_ref_pic;
1891
1892     struct object_surface                       *input_surface_obj;
1893     struct object_surface                       *last_ref_obj;
1894     struct object_surface                       *golden_ref_obj;
1895     struct object_surface                       *alt_ref_obj;
1896
1897     VAEncSequenceParameterBufferVP9 *seq_param;
1898     VAEncSequenceParameterBufferVP9 bogus_seq_param;
1899     VAEncPictureParameterBufferVP9  *pic_param;
1900     VAEncMiscParameterTypeVP9PerSegmantParam *segment_param;
1901     double   brc_init_current_target_buf_full_in_bits;
1902     double   brc_init_reset_input_bits_per_frame;
1903     uint32_t brc_init_reset_buf_size_in_bits;
1904     unsigned int gop_size;
1905     unsigned int target_bit_rate;
1906     unsigned int max_bit_rate;
1907     unsigned int min_bit_rate;
1908     unsigned long init_vbv_buffer_fullness_in_bit;
1909     unsigned long vbv_buffer_size_in_bit;
1910     int      frame_number;
1911     struct intel_fraction framerate;
1912     uint8_t  ref_frame_flag;
1913     uint8_t  dys_ref_frame_flag;
1914     uint8_t  picture_coding_type;
1915     unsigned int adaptive_transform_decision_enabled;
1916     int      curr_mode_decision_index;
1917     int      target_usage;
1918     unsigned int mb_data_offset;
1919     int      curr_pak_pass;
1920     bool     first_frame;
1921     bool     dys_enabled;
1922     bool     dys_in_use;
1923     bool     mbenc_curbe_set_in_brc_update;
1924     bool     multi_ref_qp_check;
1925     bool     brc_distortion_buffer_supported;
1926     bool     brc_constant_buffer_supported;
1927     bool     mbenc_keyframe_dist_enabled;
1928     unsigned int curr_mv_temporal_index;
1929     int      tx_mode;
1930     int      num_pak_passes;
1931     char     *alias_insert_data;
1932     int      header_length;
1933     vp9_header_bitoffset frame_header;
1934
1935     struct vp9_encode_status_buffer_internal status_buffer;
1936
1937     /* the frame context related with VP9 encoding */
1938     FRAME_CONTEXT vp9_frame_ctx[FRAME_CONTEXTS];
1939     FRAME_CONTEXT vp9_current_fc;
1940     int frame_ctx_idx;
1941
1942     vp9_frame_status vp9_last_frame;
1943 };
1944
1945 struct vp9_compressed_element {
1946     uint8_t a_valid          : 1;
1947     uint8_t a_probdiff_select: 1;
1948     uint8_t a_prob_select    : 1;
1949     uint8_t a_bin            : 1;
1950     uint8_t b_valid          : 1;
1951     uint8_t b_probdiff_select: 1;
1952     uint8_t b_prob_select    : 1;
1953     uint8_t b_bin            : 1;
1954 };
1955
1956 #define VP9_BRC_HISTORY_BUFFER_SIZE             768
1957 #define VP9_BRC_CONSTANTSURFACE_SIZE            17792
1958 #define VP9_BRC_BITSTREAM_SIZE_BUFFER_SIZE      16
1959 #define VP9_BRC_MMDK_PAK_BUFFER_SIZE            64
1960 #define VP9_SEGMENT_STATE_BUFFER_SIZE           256
1961 #define VP9_HFW_BRC_DATA_BUFFER_SIZE            32
1962
1963 #endif /* GEN9_VP9_ENCODER_H */