Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / auxiliary / draw / draw_vs_aos.h
1 /**************************************************************************
2  * 
3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  * 
26  **************************************************************************/
27
28 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
29  */
30
31 #ifndef DRAW_VS_AOS_H
32 #define DRAW_VS_AOS_H
33
34 #include "pipe/p_config.h"
35 #include "tgsi/tgsi_exec.h"
36 #include "draw_vs.h"
37
38 #ifdef PIPE_ARCH_X86
39
40 struct tgsi_token;
41 struct x86_function;
42
43 #include "pipe/p_state.h"
44 #include "rtasm/rtasm_x86sse.h"
45
46
47
48
49
50 #define X    0
51 #define Y    1
52 #define Z    2
53 #define W    3
54
55 #define MAX_INPUTS     PIPE_MAX_ATTRIBS
56 #define MAX_OUTPUTS    PIPE_MAX_SHADER_OUTPUTS
57 #define MAX_TEMPS      TGSI_EXEC_NUM_TEMPS
58 #define MAX_CONSTANTS  1024  /** only used for sanity checking */
59 #define MAX_IMMEDIATES 1024  /** only used for sanity checking */
60 #define MAX_INTERNALS  8     /** see IMM_x values below */
61
62 #define AOS_FILE_INTERNAL TGSI_FILE_COUNT
63
64 #define FPU_RND_NEG    1
65 #define FPU_RND_NEAREST 2
66
67 struct aos_machine;
68 typedef void (PIPE_CDECL *lit_func)( struct aos_machine *,
69                                     float *result,
70                                     const float *in,
71                                     unsigned count );
72
73 void PIPE_CDECL aos_do_lit( struct aos_machine *machine,
74                             float *result,
75                             const float *in,
76                             unsigned count );
77
78 struct shine_tab {
79    float exponent;
80    float values[258];
81    unsigned last_used;
82 };
83
84 struct lit_info {
85    lit_func func;
86    struct shine_tab *shine_tab;
87 };
88
89 #define MAX_SHINE_TAB    4
90 #define MAX_LIT_INFO     16
91
92 struct aos_buffer {
93    const void *base_ptr;
94    unsigned stride;
95    void *ptr;                   /* updated per vertex */
96 };
97
98
99
100
101 /* This is the temporary storage used by all the aos_sse vs variants.
102  * Create one per context and reuse by passing a pointer in at
103  * vs_variant creation??
104  */
105 struct aos_machine {
106    float input    [MAX_INPUTS    ][4];
107    float output   [MAX_OUTPUTS   ][4];
108    float temp     [MAX_TEMPS     ][4];
109    float internal [MAX_INTERNALS ][4];
110
111    float scale[4];              /* viewport */
112    float translate[4];          /* viewport */
113
114    float tmp[2][4];             /* scratch space for LIT */
115
116    struct shine_tab shine_tab[MAX_SHINE_TAB];
117    struct lit_info  lit_info[MAX_LIT_INFO];
118    unsigned now;
119    
120
121    ushort fpu_rnd_nearest;
122    ushort fpu_rnd_neg_inf;
123    ushort fpu_restore;
124    ushort fpucntl;              /* one of FPU_* above */
125
126    const float (*immediates)[4];     /* points to shader data */
127    const void *constants[PIPE_MAX_CONSTANT_BUFFERS]; /* points to draw data */
128
129    const struct aos_buffer *buffer; /* points to ? */
130 };
131
132
133
134
135 struct aos_compilation {
136    struct x86_function *func;
137    struct draw_vs_variant_aos_sse *vaos;
138
139    unsigned insn_counter;
140    unsigned num_immediates;
141    unsigned count;
142    unsigned lit_count;
143
144    struct {
145       unsigned idx:16;
146       unsigned file:8;
147       unsigned dirty:8;
148       unsigned last_used;
149    } xmm[8];
150
151    unsigned x86_reg[2];                /* one of X86_* */
152
153    boolean input_fetched[PIPE_MAX_ATTRIBS];
154    unsigned output_last_write[PIPE_MAX_ATTRIBS];
155
156    boolean have_sse2;
157    boolean error;
158    short fpucntl;
159
160    /* these are actually known values, but putting them in a struct
161     * like this is helpful to keep them in sync across the file.
162     */
163    struct x86_reg tmp_EAX;
164    struct x86_reg idx_EBX;     /* either start+i or &elt[i] */
165    struct x86_reg outbuf_ECX;
166    struct x86_reg machine_EDX;
167    struct x86_reg count_ESI;    /* decrements to zero */
168    struct x86_reg temp_EBP;
169    struct x86_reg stack_ESP;
170 };
171
172 struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp );
173 void aos_release_xmm_reg( struct aos_compilation *cp, unsigned idx );
174
175 void aos_adopt_xmm_reg( struct aos_compilation *cp,
176                         struct x86_reg reg,
177                         unsigned file,
178                         unsigned idx,
179                         unsigned dirty );
180
181 void aos_spill_all( struct aos_compilation *cp );
182
183 struct x86_reg aos_get_shader_reg( struct aos_compilation *cp, 
184                                    unsigned file,
185                                    unsigned idx );
186
187 boolean aos_init_inputs( struct aos_compilation *cp, boolean linear );
188 boolean aos_fetch_inputs( struct aos_compilation *cp, boolean linear );
189 boolean aos_incr_inputs( struct aos_compilation *cp, boolean linear );
190
191 boolean aos_emit_outputs( struct aos_compilation *cp );
192
193
194 #define IMM_ONES     0              /* 1, 1,1,1 */
195 #define IMM_SWZ      1              /* 1,-1,0, 0xffffffff */
196 #define IMM_IDENTITY 2              /* 0, 0,0,1 */
197 #define IMM_INV_255  3              /* 1/255, 1/255, 1/255, 1/255 */
198 #define IMM_255      4              /* 255, 255, 255, 255 */
199 #define IMM_NEGS     5              /* -1,-1,-1,-1 */
200 #define IMM_RSQ      6              /* -.5,1.5,_,_ */
201 #define IMM_PSIZE    7              /* not really an immediate - updated each run */
202
203 struct x86_reg aos_get_internal( struct aos_compilation *cp,
204                                  unsigned imm );
205 struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp,
206                                      unsigned imm );
207
208
209 #define AOS_ERROR(cp, msg)                                                  \
210 do {                                                                    \
211    if (0) debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
212    cp->error = 1;                                                       \
213 } while (0)
214
215
216 #define X86_NULL       0
217 #define X86_IMMEDIATES 1
218 #define X86_CONSTANTS  2
219 #define X86_BUFFERS    3
220
221 struct x86_reg aos_get_x86( struct aos_compilation *cp,
222                             unsigned which_reg,
223                             unsigned value );
224
225
226 typedef void (PIPE_CDECL *vaos_run_elts_func)( struct aos_machine *,
227                                                const unsigned *elts,
228                                                unsigned count,
229                                                void *output_buffer);
230
231 typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *,
232                                                 unsigned start,
233                                                 unsigned count,
234                                                 void *output_buffer);
235
236
237 struct draw_vs_variant_aos_sse {
238    struct draw_vs_variant base;
239    struct draw_context *draw;
240
241    struct aos_buffer *buffer;
242    unsigned nr_vb;
243
244    vaos_run_linear_func gen_run_linear;
245    vaos_run_elts_func gen_run_elts;
246
247
248    struct x86_function func[2];
249 };
250
251
252 #endif
253
254 #endif 
255