OSDN Git Service

Fix the initilization path and the termination path in reverse
[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 #define MAX_PP_SURFACES 48
33
34 #define I965_PP_FLAG_TOP_FIELD          1
35 #define I965_PP_FLAG_BOTTOM_FIELD       2
36 #define I965_PP_FLAG_MCDI               4
37 #define I965_PP_FLAG_AVS                8
38
39 enum
40 {
41     PP_NULL = 0,
42     PP_NV12_LOAD_SAVE_N12,
43     PP_NV12_LOAD_SAVE_PL3,
44     PP_PL3_LOAD_SAVE_N12,
45     PP_PL3_LOAD_SAVE_PL3,
46     PP_NV12_SCALING,
47     PP_NV12_AVS,
48     PP_NV12_DNDI,
49     PP_NV12_DN,
50     PP_NV12_LOAD_SAVE_PA,
51     PP_PL3_LOAD_SAVE_PA,
52     PP_PA_LOAD_SAVE_NV12,
53     PP_PA_LOAD_SAVE_PL3,
54     PP_RGBX_LOAD_SAVE_NV12,
55     PP_NV12_LOAD_SAVE_RGBX,
56     NUM_PP_MODULES,
57 };
58
59 struct i965_post_processing_context;
60
61 struct pp_load_save_context
62 {
63     int dest_x;
64     int dest_y;
65     int dest_w;
66     int dest_h;
67 };
68
69 struct pp_scaling_context
70 {
71     int dest_x; /* in pixel */
72     int dest_y; /* in pixel */
73     int dest_w;
74     int dest_h;
75     float src_normalized_x;
76     float src_normalized_y;
77 };
78
79 struct pp_avs_context
80 {
81     int dest_x; /* in pixel */
82     int dest_y; /* in pixel */
83     int dest_w;
84     int dest_h;
85     float src_normalized_x;
86     float src_normalized_y;
87     int src_w;
88     int src_h;
89     float horiz_range;
90 };
91
92 struct pp_dndi_context
93 {
94     int dest_w;
95     int dest_h;
96 };
97
98 struct pp_dn_context
99 {
100     int dest_w;
101     int dest_h;
102 };
103
104 struct pp_module
105 {
106     struct i965_kernel kernel;
107     
108     /* others */
109     VAStatus (*initialize)(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
110                            const struct i965_surface *src_surface,
111                            const VARectangle *src_rect,
112                            struct i965_surface *dst_surface,
113                            const VARectangle *dst_rect,
114                            void *filter_param);
115 };
116
117 struct pp_static_parameter
118 {
119     struct {
120         /* Procamp r1.0 */
121         float procamp_constant_c0;
122         
123         /* Load and Same r1.1 */
124         unsigned int source_packed_y_offset:8;
125         unsigned int source_packed_u_offset:8;
126         unsigned int source_packed_v_offset:8;
127         unsigned int source_rgb_layout:8;       // 1 for |R|G|B|X| layout, 0 for |B|G|R|X| layout
128
129         union {
130             /* Load and Save r1.2 */
131             struct {
132                 unsigned int destination_packed_y_offset:8;
133                 unsigned int destination_packed_u_offset:8;
134                 unsigned int destination_packed_v_offset:8;
135                 unsigned int pad0:8;
136             } load_and_save;
137
138             /* CSC r1.2 */
139             struct {
140                 unsigned int pad0:24;
141                 unsigned int destination_rgb_layout:8;  // 1 for |R|G|B|X| layout, 0 for |B|G|R|X| layout
142             } csc;
143         } r1_2;
144         
145         /* Procamp r1.3 */
146         float procamp_constant_c1;
147
148         /* Procamp r1.4 */
149         float procamp_constant_c2;
150
151         /* DI r1.5 */
152         unsigned int statistics_surface_picth:16;  /* Devided by 2 */
153         unsigned int pad1:16;
154
155         union {
156             /* DI r1.6 */
157             struct {
158                 unsigned int pad0:24;
159                 unsigned int top_field_first:8;
160             } di;
161
162             /* AVS/Scaling r1.6 */
163             float normalized_video_y_scaling_step;
164         } r1_6;
165
166         /* Procamp r1.7 */
167         float procamp_constant_c5;
168     } grf1;
169     
170     struct {
171         /* Procamp r2.0 */
172         float procamp_constant_c3;
173
174         /* MBZ r2.1*/
175         unsigned int pad0;
176
177         /* WG+CSC r2.2 */
178         float wg_csc_constant_c4;
179
180         /* WG+CSC r2.3 */
181         float wg_csc_constant_c8;
182
183         /* Procamp r2.4 */
184         float procamp_constant_c4;
185
186         /* MBZ r2.5 */
187         unsigned int pad1;
188
189         /* MBZ r2.6 */
190         unsigned int pad2;
191
192         /* WG+CSC r2.7 */
193         float wg_csc_constant_c9;
194     } grf2;
195
196     struct {
197         /* WG+CSC r3.0 */
198         float wg_csc_constant_c0;
199
200         /* Blending r3.1 */
201         float scaling_step_ratio;
202
203         /* Blending r3.2 */
204         float normalized_alpha_y_scaling;
205         
206         /* WG+CSC r3.3 */
207         float wg_csc_constant_c4;
208
209         /* WG+CSC r3.4 */
210         float wg_csc_constant_c1;
211
212         /* ALL r3.5 */
213         int horizontal_origin_offset:16;
214         int vertical_origin_offset:16;
215
216         /* Shared r3.6*/
217         union {
218             /* Color filll */
219             unsigned int color_pixel;
220
221             /* WG+CSC */
222             float wg_csc_constant_c2;
223         } r3_6;
224
225         /* WG+CSC r3.7 */
226         float wg_csc_constant_c3;
227     } grf3;
228
229     struct {
230         /* WG+CSC r4.0 */
231         float wg_csc_constant_c6;
232
233         /* ALL r4.1 MBZ ???*/
234         unsigned int pad0;
235
236         /* Shared r4.2 */
237         union {
238             /* AVS */
239             struct {
240                 unsigned int pad1:15;
241                 unsigned int nlas:1;
242                 unsigned int pad2:16;
243             } avs;
244
245             /* DI */
246             struct {
247                 unsigned int motion_history_coefficient_m2:8;
248                 unsigned int motion_history_coefficient_m1:8;
249                 unsigned int pad0:16;
250             } di;
251         } r4_2;
252
253         /* WG+CSC r4.3 */
254         float wg_csc_constant_c7;
255
256         /* WG+CSC r4.4 */
257         float wg_csc_constant_c10;
258
259         /* AVS r4.5 */
260         float source_video_frame_normalized_horizontal_origin;
261
262         /* MBZ r4.6 */
263         unsigned int pad1;
264
265         /* WG+CSC r4.7 */
266         float wg_csc_constant_c11;
267     } grf4;
268 };
269
270 struct pp_inline_parameter
271 {
272     struct {
273         /* ALL r5.0 */
274         int destination_block_horizontal_origin:16;
275         int destination_block_vertical_origin:16;
276
277         /* Shared r5.1 */
278         union {
279             /* AVS/Scaling */
280             float source_surface_block_normalized_horizontal_origin;
281
282             /* FMD */
283             struct {
284                 unsigned int variance_surface_vertical_origin:16;
285                 unsigned int pad0:16;
286             } fmd;
287         } r5_1; 
288
289         /* AVS/Scaling r5.2 */
290         float source_surface_block_normalized_vertical_origin;
291
292         /* Alpha r5.3 */
293         float alpha_surface_block_normalized_horizontal_origin;
294
295         /* Alpha r5.4 */
296         float alpha_surface_block_normalized_vertical_origin;
297
298         /* Alpha r5.5 */
299         unsigned int alpha_mask_x:16;
300         unsigned int alpha_mask_y:8;
301         unsigned int block_count_x:8;
302
303         /* r5.6 */
304         /* we only support M*1 or 1*N block partitation now.
305          *   -- it means asm code only need update this mask from grf6 for the last block 
306          */
307         unsigned int block_horizontal_mask:16;
308         unsigned int block_vertical_mask:8;
309         unsigned int number_blocks:8;
310
311         /* AVS/Scaling r5.7 */
312         float normalized_video_x_scaling_step;
313     } grf5;
314
315     struct {
316         /* AVS r6.0 */
317         float video_step_delta;
318
319         /* r6.1 */    // sizeof(int) == 4?    
320         unsigned int block_horizontal_mask_right:16;
321         unsigned int block_vertical_mask_bottom:8;
322         unsigned int pad1:8;
323
324         /* r6.2 */
325         unsigned int block_horizontal_mask_middle:16;
326         unsigned int pad2:16;
327
328         /* r6.3-r6.7 */
329         unsigned int padx[5];
330     } grf6;
331 };
332
333 struct gen7_pp_static_parameter
334 {
335     struct {
336         /* r1.0-r1.5 */
337         unsigned int padx[6];
338         /* r1.6 */
339         unsigned int di_statistics_surface_pitch_div2:16;
340         unsigned int di_statistics_surface_height_div4:16;
341         /* r1.7 */
342         unsigned int di_top_field_first:8;
343         unsigned int pad0:16;
344         unsigned int pointer_to_inline_parameter:8; /* value: 7 */
345     } grf1;
346
347     struct {
348         /* r2.0 */
349         unsigned int pad3;
350
351         /* r2.1 */
352         unsigned int pad2:16;
353         unsigned int save_avs_rgb_swap:1; /* 0: RGB, 1: BGR */
354         unsigned int avs_wa_enable:1; /* must enabled for GEN7 */
355         unsigned int src_avs_rgb_swap:1;
356         /* Indicates whether the rgb is swapped for the src surface
357          * 0: RGBX(MSB. X-B-G-R). 1: BGRX(MSB: X-R-G-B)
358          */
359         unsigned int avs_wa_width:13;
360
361         /* 2.2 */
362         float avs_wa_one_div_256_width;
363
364         /* 2.3 */
365         float avs_wa_five_div_256_width;
366         
367         /* 2.4 - 2.6 */
368         unsigned int padx[3];
369
370         /* r2.7 */
371         unsigned int di_destination_packed_y_component_offset:8;
372         unsigned int di_destination_packed_u_component_offset:8;
373         unsigned int di_destination_packed_v_component_offset:8;
374         unsigned int pad0:8;
375     } grf2;
376
377     struct {
378         float sampler_load_horizontal_scaling_step_ratio;
379         unsigned int padx[7];
380     } grf3;
381
382     struct {
383         float sampler_load_vertical_scaling_step;
384         unsigned int pad0;
385         unsigned int di_hoffset_svf_from_dvf:16;
386         unsigned int di_voffset_svf_from_dvf:16;
387         unsigned int padx[5];
388     } grf4;
389
390     struct {
391         float sampler_load_vertical_frame_origin;
392         unsigned int padx[7];
393     } grf5;
394
395     struct {
396         float sampler_load_horizontal_frame_origin;
397         unsigned int padx[7];
398     } grf6;
399 };
400
401 struct gen7_pp_inline_parameter
402 {
403     struct {
404         /* r7.0 */
405         unsigned int destination_block_horizontal_origin:16;
406         unsigned int destination_block_vertical_origin:16;
407         /* r7.1: 0xffffffff */
408         unsigned int constant_0;
409         /* r7.2 */
410         unsigned int pad0;
411         /* r7.3 */
412         unsigned int pad1;
413         /* r7.4 */
414         float sampler_load_main_video_x_scaling_step;
415         /* r7.5 */
416         unsigned int pad2;
417         /* r7.6: must be zero */
418         unsigned int avs_vertical_block_number;
419         /* r7.7: 0 */
420         unsigned int group_id_number;
421     } grf7;
422
423     struct {
424         unsigned int padx[8];
425     } grf8;
426 };
427
428 struct i965_post_processing_context
429 {
430     int current_pp;
431     struct pp_module pp_modules[NUM_PP_MODULES];
432     void *pp_static_parameter;
433     void *pp_inline_parameter;
434
435     struct {
436         dri_bo *bo;
437     } surface_state_binding_table;
438
439     struct {
440         dri_bo *bo;
441     } curbe;
442
443     struct {
444         dri_bo *bo;
445         int num_interface_descriptors;
446     } idrt;
447
448     struct {
449         dri_bo *bo;
450     } vfe_state;
451
452     struct {
453         dri_bo *bo;
454         dri_bo *bo_8x8;
455         dri_bo *bo_8x8_uv;
456     } sampler_state_table;
457
458     struct {
459         unsigned int size;
460
461         unsigned int vfe_start;
462         unsigned int cs_start;
463
464         unsigned int num_vfe_entries;
465         unsigned int num_cs_entries;
466
467         unsigned int size_vfe_entry;
468         unsigned int size_cs_entry;
469     } urb;
470
471     struct {
472         dri_bo *bo;
473     } stmm;
474
475     union {
476         struct pp_load_save_context pp_load_save_context;
477         struct pp_scaling_context pp_scaling_context;
478         struct pp_avs_context pp_avs_context;
479         struct pp_dndi_context pp_dndi_context;
480         struct pp_dn_context pp_dn_context;
481     } private_context;
482
483     int (*pp_x_steps)(void *private_context);
484     int (*pp_y_steps)(void *private_context);
485     int (*pp_set_block_parameter)(struct i965_post_processing_context *pp_context, int x, int y);
486
487     struct intel_batchbuffer *batch;
488
489     unsigned int block_horizontal_mask_left:16;
490     unsigned int block_horizontal_mask_right:16;
491     unsigned int block_vertical_mask_bottom:8;
492 };
493
494 struct i965_proc_context
495 {
496     struct hw_context base;
497     struct i965_post_processing_context pp_context;
498 };
499
500 VASurfaceID
501 i965_post_processing(
502     VADriverContextP   ctx,
503     VASurfaceID        surface,
504     const VARectangle *src_rect,
505     const VARectangle *dst_rect,
506     unsigned int       flags,
507     int                *has_done_scaling 
508 );
509
510 VAStatus
511 i965_scaling_processing(
512     VADriverContextP   ctx,
513     VASurfaceID        src_surface_id,
514     const VARectangle *src_rect,
515     VASurfaceID        dst_surface_id,
516     const VARectangle *dst_rect,
517     unsigned int       flags
518 );
519
520 VAStatus
521 i965_image_processing(VADriverContextP ctx,
522                       const struct i965_surface *src_surface,
523                       const VARectangle *src_rect,
524                       struct i965_surface *dst_surface,
525                       const VARectangle *dst_rect);
526
527 void
528 i965_post_processing_terminate(VADriverContextP ctx);
529 bool
530 i965_post_processing_init(VADriverContextP ctx);
531
532 #endif /* __I965_POST_PROCESSING_H__ */