OSDN Git Service

ENC: use common gpe structure in AVC encoder
[android-x86/hardware-intel-common-vaapi.git] / src / i965_post_processing.h
1 /*
2  * Copyright © 2010 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Xiang Haihao <haihao.xiang@intel.com>
26  *
27  */
28
29 #ifndef __I965_POST_PROCESSING_H__
30 #define __I965_POST_PROCESSING_H__
31
32 #include "i965_vpp_avs.h"
33 #include <drm.h>
34 #include <i915_drm.h>
35 #include <intel_bufmgr.h>
36 #include "i965_gpe_utils.h"
37
38 #define MAX_PP_SURFACES                 48
39
40 struct i965_gpe_context;
41
42 enum
43 {
44     PP_NULL = 0,
45     PP_NV12_LOAD_SAVE_N12,
46     PP_NV12_LOAD_SAVE_PL3,
47     PP_PL3_LOAD_SAVE_N12,
48     PP_PL3_LOAD_SAVE_PL3,
49     PP_NV12_SCALING,
50     PP_NV12_AVS,
51     PP_NV12_DNDI,
52     PP_NV12_DN,
53     PP_NV12_LOAD_SAVE_PA,
54     PP_PL3_LOAD_SAVE_PA,
55     PP_PA_LOAD_SAVE_NV12,
56     PP_PA_LOAD_SAVE_PL3,
57     PP_PA_LOAD_SAVE_PA,
58     PP_RGBX_LOAD_SAVE_NV12,
59     PP_NV12_LOAD_SAVE_RGBX,
60     NUM_PP_MODULES,
61 };
62
63 struct i965_post_processing_context;
64
65 struct pp_load_save_context
66 {
67     int dest_x;
68     int dest_y;
69     int dest_w;
70     int dest_h;
71 };
72
73 struct pp_scaling_context
74 {
75     int dest_x; /* in pixel */
76     int dest_y; /* in pixel */
77     int dest_w;
78     int dest_h;
79     float src_normalized_x;
80     float src_normalized_y;
81 };
82
83 struct pp_avs_context
84 {
85     AVSState state;
86     int dest_x; /* in pixel */
87     int dest_y; /* in pixel */
88     int dest_w;
89     int dest_h;
90     float src_normalized_x;
91     float src_normalized_y;
92     int src_w;
93     int src_h;
94     float horiz_range;
95 };
96
97 enum {
98     DNDI_FRAME_IN_CURRENT = 0,
99     DNDI_FRAME_IN_PREVIOUS,
100     DNDI_FRAME_IN_STMM,
101     DNDI_FRAME_OUT_STMM,
102     DNDI_FRAME_OUT_CURRENT,
103     DNDI_FRAME_OUT_PREVIOUS,
104     DNDI_FRAME_STORE_COUNT
105 };
106
107 typedef struct dndi_frame_store {
108     struct object_surface *obj_surface;
109     VASurfaceID surface_id; /* always relative to the input surface */
110     unsigned int is_scratch_surface : 1;
111 } DNDIFrameStore;
112
113 struct pp_dndi_context
114 {
115     int dest_w;
116     int dest_h;
117     DNDIFrameStore frame_store[DNDI_FRAME_STORE_COUNT];
118
119     /* Temporary flags live until the current picture is processed */
120     unsigned int is_di_enabled          : 1;
121     unsigned int is_di_adv_enabled      : 1;
122     unsigned int is_first_frame         : 1;
123     unsigned int is_second_field        : 1;
124 };
125
126 struct pp_dn_context
127 {
128     int dest_w;
129     int dest_h;
130     dri_bo *stmm_bo;
131 };
132
133 struct i965_post_processing_context;
134  
135 struct pp_module
136 {
137     struct i965_kernel kernel;
138     
139     /* others */
140     VAStatus (*initialize)(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
141                            const struct i965_surface *src_surface,
142                            const VARectangle *src_rect,
143                            struct i965_surface *dst_surface,
144                            const VARectangle *dst_rect,
145                            void *filter_param);
146 };
147
148 struct pp_static_parameter
149 {
150     struct {
151         /* Procamp r1.0 */
152         float procamp_constant_c0;
153         
154         /* Load and Same r1.1 */
155         unsigned int source_packed_y_offset:8;
156         unsigned int source_packed_u_offset:8;
157         unsigned int source_packed_v_offset:8;
158         unsigned int source_rgb_layout:8;       // 1 for |R|G|B|X| layout, 0 for |B|G|R|X| layout
159
160         union {
161             /* Load and Save r1.2 */
162             struct {
163                 unsigned int destination_packed_y_offset:8;
164                 unsigned int destination_packed_u_offset:8;
165                 unsigned int destination_packed_v_offset:8;
166                 unsigned int pad0:8;
167             } load_and_save;
168
169             /* CSC r1.2 */
170             struct {
171                 unsigned int pad0:24;
172                 unsigned int destination_rgb_layout:8;  // 1 for |R|G|B|X| layout, 0 for |B|G|R|X| layout
173             } csc;
174         } r1_2;
175         
176         /* Procamp r1.3 */
177         float procamp_constant_c1;
178
179         /* Procamp r1.4 */
180         float procamp_constant_c2;
181
182         /* DI r1.5 */
183         unsigned int statistics_surface_picth:16;  /* Devided by 2 */
184         unsigned int pad1:16;
185
186         union {
187             /* DI r1.6 */
188             struct {
189                 unsigned int pad0:24;
190                 unsigned int top_field_first:8;
191             } di;
192
193             /* AVS/Scaling r1.6 */
194             float normalized_video_y_scaling_step;
195         } r1_6;
196
197         /* Procamp r1.7 */
198         float procamp_constant_c5;
199     } grf1;
200     
201     struct {
202         /* Procamp r2.0 */
203         float procamp_constant_c3;
204
205         /* MBZ r2.1*/
206         unsigned int pad0;
207
208         /* WG+CSC r2.2 */
209         float wg_csc_constant_c4;
210
211         /* WG+CSC r2.3 */
212         float wg_csc_constant_c8;
213
214         /* Procamp r2.4 */
215         float procamp_constant_c4;
216
217         /* MBZ r2.5 */
218         unsigned int pad1;
219
220         /* MBZ r2.6 */
221         unsigned int pad2;
222
223         /* WG+CSC r2.7 */
224         float wg_csc_constant_c9;
225     } grf2;
226
227     struct {
228         /* WG+CSC r3.0 */
229         float wg_csc_constant_c0;
230
231         /* Blending r3.1 */
232         float scaling_step_ratio;
233
234         /* Blending r3.2 */
235         float normalized_alpha_y_scaling;
236         
237         /* WG+CSC r3.3 */
238         float wg_csc_constant_c4;
239
240         /* WG+CSC r3.4 */
241         float wg_csc_constant_c1;
242
243         /* ALL r3.5 */
244         int horizontal_origin_offset:16;
245         int vertical_origin_offset:16;
246
247         /* Shared r3.6*/
248         union {
249             /* Color filll */
250             unsigned int color_pixel;
251
252             /* WG+CSC */
253             float wg_csc_constant_c2;
254         } r3_6;
255
256         /* WG+CSC r3.7 */
257         float wg_csc_constant_c3;
258     } grf3;
259
260     struct {
261         /* WG+CSC r4.0 */
262         float wg_csc_constant_c6;
263
264         /* ALL r4.1 MBZ ???*/
265         unsigned int pad0;
266
267         /* Shared r4.2 */
268         union {
269             /* AVS */
270             struct {
271                 unsigned int pad1:15;
272                 unsigned int nlas:1;
273                 unsigned int pad2:16;
274             } avs;
275
276             /* DI */
277             struct {
278                 unsigned int motion_history_coefficient_m2:8;
279                 unsigned int motion_history_coefficient_m1:8;
280                 unsigned int pad0:16;
281             } di;
282         } r4_2;
283
284         /* WG+CSC r4.3 */
285         float wg_csc_constant_c7;
286
287         /* WG+CSC r4.4 */
288         float wg_csc_constant_c10;
289
290         /* AVS r4.5 */
291         float source_video_frame_normalized_horizontal_origin;
292
293         /* MBZ r4.6 */
294         unsigned int pad1;
295
296         /* WG+CSC r4.7 */
297         float wg_csc_constant_c11;
298     } grf4;
299 };
300
301 struct pp_inline_parameter
302 {
303     struct {
304         /* ALL r5.0 */
305         int destination_block_horizontal_origin:16;
306         int destination_block_vertical_origin:16;
307
308         /* Shared r5.1 */
309         union {
310             /* AVS/Scaling */
311             float source_surface_block_normalized_horizontal_origin;
312
313             /* FMD */
314             struct {
315                 unsigned int variance_surface_vertical_origin:16;
316                 unsigned int pad0:16;
317             } fmd;
318         } r5_1; 
319
320         /* AVS/Scaling r5.2 */
321         float source_surface_block_normalized_vertical_origin;
322
323         /* Alpha r5.3 */
324         float alpha_surface_block_normalized_horizontal_origin;
325
326         /* Alpha r5.4 */
327         float alpha_surface_block_normalized_vertical_origin;
328
329         /* Alpha r5.5 */
330         unsigned int alpha_mask_x:16;
331         unsigned int alpha_mask_y:8;
332         unsigned int block_count_x:8;
333
334         /* r5.6 */
335         /* we only support M*1 or 1*N block partitation now.
336          *   -- it means asm code only need update this mask from grf6 for the last block 
337          */
338         unsigned int block_horizontal_mask:16;
339         unsigned int block_vertical_mask:8;
340         unsigned int number_blocks:8;
341
342         /* AVS/Scaling r5.7 */
343         float normalized_video_x_scaling_step;
344     } grf5;
345
346     struct {
347         /* AVS r6.0 */
348         float video_step_delta;
349
350         /* r6.1 */    // sizeof(int) == 4?    
351         unsigned int block_horizontal_mask_right:16;
352         unsigned int block_vertical_mask_bottom:8;
353         unsigned int pad1:8;
354
355         /* r6.2 */
356         unsigned int block_horizontal_mask_middle:16;
357         unsigned int pad2:16;
358
359         /* r6.3-r6.7 */
360         unsigned int padx[5];
361     } grf6;
362 };
363
364 struct gen7_pp_static_parameter
365 {
366     struct {
367         /* r1.0-r1.5 */
368         unsigned int padx[6];
369         /* r1.6 */
370         unsigned int di_statistics_surface_pitch_div2:16;
371         unsigned int di_statistics_surface_height_div4:16;
372         /* r1.7 */
373         unsigned int di_top_field_first:8;
374         unsigned int pad0:16;
375         unsigned int pointer_to_inline_parameter:8; /* value: 7 */
376     } grf1;
377
378     struct {
379         /* r2.0 */
380         /* Indicates whether the rgb is swapped for the src surface
381          * 0: RGBX(MSB. X-B-G-R). 1: BGRX(MSB: X-R-G-B)
382          */
383         unsigned int src_avs_rgb_swap:1;
384         unsigned int pad3:31;
385
386         /* r2.1 */
387         unsigned int pad2:16;
388         unsigned int save_avs_rgb_swap:1; /* 0: RGB, 1: BGR */
389         unsigned int avs_wa_enable:1; /* must enabled for GEN7 */
390         unsigned int ief_enable:1;
391         unsigned int avs_wa_width:13;
392
393         /* 2.2 */
394         float avs_wa_one_div_256_width;
395
396         /* 2.3 */
397         float avs_wa_five_div_256_width;
398         
399         /* 2.4 - 2.6 */
400         unsigned int padx[3];
401
402         /* r2.7 */
403         unsigned int di_destination_packed_y_component_offset:8;
404         unsigned int di_destination_packed_u_component_offset:8;
405         unsigned int di_destination_packed_v_component_offset:8;
406         unsigned int alpha:8;
407     } grf2;
408
409     struct {
410         float sampler_load_horizontal_scaling_step_ratio;
411         unsigned int padx[7];
412     } grf3;
413
414     struct {
415         float sampler_load_vertical_scaling_step;
416         unsigned int pad0;
417         unsigned int di_hoffset_svf_from_dvf:16;
418         unsigned int di_voffset_svf_from_dvf:16;
419         unsigned int padx[5];
420     } grf4;
421
422     struct {
423         float sampler_load_vertical_frame_origin;
424         unsigned int padx[7];
425     } grf5;
426
427     struct {
428         float sampler_load_horizontal_frame_origin;
429         unsigned int padx[7];
430     } grf6;
431
432     struct {
433         /* r7.0 -> r7.3 */
434         float coef_ry;
435         float coef_ru;
436         float coef_rv;
437         float coef_yd;
438
439         /* r7.4 -> r7.7 */
440         float coef_gy;
441         float coef_gu;
442         float coef_gv;
443         float coef_ud;
444     } grf7;
445
446     struct {
447         /* r8.0 -> r8.3 */
448         float coef_by;
449         float coef_bu;
450         float coef_bv;
451         float coef_vd;
452
453         /* r8.4 -> r8.7 */
454         unsigned int padx[4];
455     } grf8;
456 };
457
458 struct gen7_pp_inline_parameter
459 {
460     struct {
461         /* r9.0 */
462         unsigned int destination_block_horizontal_origin:16;
463         unsigned int destination_block_vertical_origin:16;
464         /* r9.1: 0xffffffff */
465         unsigned int constant_0;
466         /* r9.2 */
467         unsigned int pad0;
468         /* r9.3 */
469         unsigned int pad1;
470         /* r9.4 */
471         float sampler_load_main_video_x_scaling_step;
472         /* r9.5 */
473         unsigned int pad2;
474         /* r9.6: must be zero */
475         unsigned int avs_vertical_block_number;
476         /* r9.7: 0 */
477         unsigned int group_id_number;
478     } grf9;
479
480     struct {
481         unsigned int padx[8];
482     } grf10;
483 };
484
485 struct i965_post_processing_context
486 {
487     int current_pp;
488     struct pp_module pp_modules[NUM_PP_MODULES];
489     void *pp_static_parameter;
490     void *pp_inline_parameter;
491
492     struct {
493         dri_bo *bo;
494     } surface_state_binding_table;
495
496     struct {
497         dri_bo *bo;
498     } curbe;
499
500     struct {
501         dri_bo *bo;
502         int num_interface_descriptors;
503     } idrt;
504
505     struct {
506         dri_bo *bo;
507     } vfe_state;
508
509     struct {
510         dri_bo *bo;
511         dri_bo *bo_8x8;
512         dri_bo *bo_8x8_uv;
513     } sampler_state_table;
514
515     struct {
516         unsigned int size;
517
518         unsigned int vfe_start;
519         unsigned int cs_start;
520
521         unsigned int num_vfe_entries;
522         unsigned int num_cs_entries;
523
524         unsigned int size_vfe_entry;
525         unsigned int size_cs_entry;
526     } urb;
527
528     struct {
529         unsigned int gpgpu_mode : 1;
530         unsigned int pad0 : 7;
531         unsigned int max_num_threads : 16;
532         unsigned int num_urb_entries : 8;
533         unsigned int urb_entry_size : 16;
534         unsigned int curbe_allocation_size : 16;
535     } vfe_gpu_state;
536
537     struct intel_vebox_context *vebox_proc_ctx;
538
539     struct pp_load_save_context pp_load_save_context;
540     struct pp_scaling_context pp_scaling_context;
541     struct pp_avs_context pp_avs_context;
542     struct pp_dndi_context pp_dndi_context;
543     struct pp_dn_context pp_dn_context;
544     void *private_context; /* pointer to the current private context */
545     void *pipeline_param;  /* pointer to the pipeline parameter */
546     /**
547      * \ref Extra filter flags used as a fast path.
548      *
549      * This corresponds to vaPutSurface() flags, for direct rendering,
550      * or to VAProcPipelineParameterBuffer.filter_flags when the VPP
551      * interfaces are used. In the latter case, this is just a copy of
552      * that field.
553      */
554     unsigned int filter_flags;
555
556     int (*pp_x_steps)(void *private_context);
557     int (*pp_y_steps)(void *private_context);
558     int (*pp_set_block_parameter)(struct i965_post_processing_context *pp_context, int x, int y);
559
560     struct intel_batchbuffer *batch;
561
562     unsigned int block_horizontal_mask_left:16;
563     unsigned int block_horizontal_mask_right:16;
564     unsigned int block_vertical_mask_bottom:8;
565
566     struct {
567         dri_bo *bo;
568         int bo_size;
569         unsigned int end_offset;
570     } instruction_state;
571
572     struct {
573         dri_bo *bo;
574     } indirect_state;
575
576     struct {
577         dri_bo *bo;
578         int bo_size;
579         unsigned int end_offset;
580     } dynamic_state;
581
582     unsigned int sampler_offset;
583     int sampler_size;
584     unsigned int idrt_offset;
585     int idrt_size;
586     unsigned int curbe_offset;
587     int curbe_size;
588
589     VAStatus (*intel_post_processing)(VADriverContextP   ctx,
590                                 struct i965_post_processing_context *pp_context,
591                                 const struct i965_surface *src_surface,
592                                 const VARectangle *src_rect,
593                                 struct i965_surface *dst_surface,
594                                 const VARectangle *dst_rect,
595                                 int   pp_index,
596                                 void * filter_param);
597     void (*finalize)(VADriverContextP ctx,
598         struct i965_post_processing_context *pp_context);
599
600
601     struct i965_gpe_context scaling_10bit_context;
602     int scaling_context_initialized;
603     struct i965_gpe_context scaling_yuv420p8_context;
604 #define VPPGPE_8BIT_420    (1 << 0)
605 #define VPPGPE_8BIT_422    (1 << 1)
606 #define VPPGPE_8BIT_444    (1 << 2)
607     unsigned int scaling_8bit_initialized;
608 };
609
610 struct i965_proc_context
611 {
612     struct hw_context base;
613     void *driver_context;
614     struct i965_post_processing_context pp_context;
615 };
616
617 VASurfaceID
618 i965_post_processing(
619     VADriverContextP   ctx,
620     struct object_surface *obj_surface,
621     const VARectangle *src_rect,
622     const VARectangle *dst_rect,
623     unsigned int       va_flags,
624     int                *has_done_scaling,
625     VARectangle *calibrated_rect
626 );
627
628 VAStatus
629 i965_scaling_processing(
630     VADriverContextP   ctx,
631     struct object_surface *src_surface_obj,
632     const VARectangle *src_rect,
633     struct object_surface *dst_surface_obj,
634     const VARectangle *dst_rect,
635     unsigned int       va_flags
636 );
637
638 VAStatus
639 i965_image_processing(VADriverContextP ctx,
640                       const struct i965_surface *src_surface,
641                       const VARectangle *src_rect,
642                       struct i965_surface *dst_surface,
643                       const VARectangle *dst_rect);
644
645 void
646 i965_post_processing_terminate(VADriverContextP ctx);
647 bool
648 i965_post_processing_init(VADriverContextP ctx);
649
650
651 extern VAStatus
652 i965_proc_picture(VADriverContextP ctx,
653                   VAProfile profile,
654                   union codec_state *codec_state,
655                   struct hw_context *hw_context);
656
657 #endif /* __I965_POST_PROCESSING_H__ */