OSDN Git Service

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