OSDN Git Service

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