OSDN Git Service

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