Merge branch 'gallium-tex-surfaces' into gallium-0.1
[mesa.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
35 struct tgsi_token;
36 struct x86_function;
37
38 #include "pipe/p_state.h"
39 #include "rtasm/rtasm_x86sse.h"
40
41
42
43
44
45 #define X 0
46 #define Y 1
47 #define Z 2
48 #define W 3
49
50 #define MAX_INPUTS PIPE_MAX_ATTRIBS
51 #define MAX_OUTPUTS PIPE_MAX_ATTRIBS
52 #define MAX_TEMPS PIPE_MAX_ATTRIBS /* say */
53 #define MAX_CONSTANTS PIPE_MAX_ATTRIBS /* say */
54 #define MAX_IMMEDIATES PIPE_MAX_ATTRIBS /* say */
55 #define MAX_INTERNALS 8
56
57 #define AOS_FILE_INTERNAL TGSI_FILE_COUNT
58
59 #define FPU_RND_NEG 1
60 #define FPU_RND_NEAREST 2
61
62 struct aos_machine;
63 typedef void (PIPE_CDECL *lit_func)( struct aos_machine *,
64 float *result,
65 const float *in,
66 unsigned count );
67
68 void PIPE_CDECL aos_do_lit( struct aos_machine *machine,
69 float *result,
70 const float *in,
71 unsigned count );
72
73 struct shine_tab {
74 float exponent;
75 float values[258];
76 unsigned last_used;
77 };
78
79 struct lit_info {
80 lit_func func;
81 struct shine_tab *shine_tab;
82 };
83
84 #define MAX_SHINE_TAB 4
85 #define MAX_LIT_INFO 16
86
87 struct aos_attrib {
88 const void *input_ptr;
89 unsigned input_stride;
90 };
91
92
93
94
95 /* This is the temporary storage used by all the aos_sse vs varients.
96 * Create one per context and reuse by passing a pointer in at
97 * vs_varient creation??
98 */
99 struct aos_machine {
100 float input [MAX_INPUTS ][4];
101 float output [MAX_OUTPUTS ][4];
102 float temp [MAX_TEMPS ][4];
103 float internal [MAX_INTERNALS ][4];
104
105 float scale[4]; /* viewport */
106 float translate[4]; /* viewport */
107
108 float tmp[2][4]; /* scratch space for LIT */
109
110 struct shine_tab shine_tab[MAX_SHINE_TAB];
111 struct lit_info lit_info[MAX_LIT_INFO];
112 unsigned now;
113
114
115 ushort fpu_rnd_nearest;
116 ushort fpu_rnd_neg_inf;
117 ushort fpu_restore;
118 ushort fpucntl; /* one of FPU_* above */
119
120 const float (*immediates)[4]; /* points to shader data */
121 const float (*constants)[4]; /* points to draw data */
122
123 const struct aos_attrib *attrib; /* points to ? */
124 };
125
126
127
128
129 struct aos_compilation {
130 struct x86_function *func;
131 struct draw_vs_varient_aos_sse *vaos;
132
133 unsigned insn_counter;
134 unsigned num_immediates;
135 unsigned count;
136 unsigned lit_count;
137
138 struct {
139 unsigned idx:16;
140 unsigned file:8;
141 unsigned dirty:8;
142 unsigned last_used;
143 } xmm[8];
144
145 unsigned ebp; /* one of X86_* */
146
147 boolean input_fetched[PIPE_MAX_ATTRIBS];
148 unsigned output_last_write[PIPE_MAX_ATTRIBS];
149
150 boolean have_sse2;
151 boolean error;
152 short fpucntl;
153
154 /* these are actually known values, but putting them in a struct
155 * like this is helpful to keep them in sync across the file.
156 */
157 struct x86_reg tmp_EAX;
158 struct x86_reg idx_EBX; /* either start+i or &elt[i] */
159 struct x86_reg outbuf_ECX;
160 struct x86_reg machine_EDX;
161 struct x86_reg count_ESI; /* decrements to zero */
162 struct x86_reg temp_EBP;
163 struct x86_reg stack_ESP;
164 };
165
166 struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp );
167 void aos_release_xmm_reg( struct aos_compilation *cp, unsigned idx );
168
169 void aos_adopt_xmm_reg( struct aos_compilation *cp,
170 struct x86_reg reg,
171 unsigned file,
172 unsigned idx,
173 unsigned dirty );
174
175 struct x86_reg aos_get_shader_reg( struct aos_compilation *cp,
176 unsigned file,
177 unsigned idx );
178
179 boolean aos_fetch_inputs( struct aos_compilation *cp,
180 boolean linear );
181
182 boolean aos_emit_outputs( struct aos_compilation *cp );
183
184
185 #define IMM_ONES 0 /* 1, 1,1,1 */
186 #define IMM_SWZ 1 /* 1,-1,0, 0xffffffff */
187 #define IMM_IDENTITY 2 /* 0, 0,0,1 */
188 #define IMM_INV_255 3 /* 1/255, 1/255, 1/255, 1/255 */
189 #define IMM_255 4 /* 255, 255, 255, 255 */
190 #define IMM_NEGS 5 /* -1,-1,-1,-1 */
191 #define IMM_RSQ 6 /* -.5,1.5,_,_ */
192 #define IMM_PSIZE 7 /* not really an immediate - updated each run */
193
194 struct x86_reg aos_get_internal( struct aos_compilation *cp,
195 unsigned imm );
196 struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp,
197 unsigned imm );
198
199
200 #define ERROR(cp, msg) \
201 do { \
202 debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
203 cp->error = 1; \
204 assert(0); \
205 } while (0)
206
207
208 #define X86_NULL 0
209 #define X86_IMMEDIATES 1
210 #define X86_CONSTANTS 2
211 #define X86_ATTRIBS 3
212
213 struct x86_reg aos_get_x86( struct aos_compilation *cp,
214 unsigned value );
215
216
217 typedef void (PIPE_CDECL *vaos_run_elts_func)( struct aos_machine *,
218 const unsigned *elts,
219 unsigned count,
220 void *output_buffer);
221
222 typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *,
223 unsigned start,
224 unsigned count,
225 void *output_buffer);
226
227
228 struct draw_vs_varient_aos_sse {
229 struct draw_vs_varient base;
230 struct draw_context *draw;
231
232 struct aos_attrib *attrib;
233
234 vaos_run_linear_func gen_run_linear;
235 vaos_run_elts_func gen_run_elts;
236
237
238 struct x86_function func[2];
239 };
240
241
242
243 #endif
244