OSDN Git Service

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