b47413ff43c46e784984e13f6b267c2c23ca2e2f
[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 struct shine_tab {
68 float exponent;
69 float values[258];
70 unsigned last_used;
71 };
72
73 struct lit_info {
74 lit_func func;
75 struct shine_tab *shine_tab;
76 };
77
78 #define MAX_SHINE_TAB 4
79 #define MAX_LIT_INFO 16
80
81 /* This is the temporary storage used by all the aos_sse vs varients.
82 * Create one per context and reuse by passing a pointer in at
83 * vs_varient creation??
84 */
85 struct aos_machine {
86 float input [MAX_INPUTS ][4];
87 float output [MAX_OUTPUTS ][4];
88 float temp [MAX_TEMPS ][4];
89 float constant [MAX_CONSTANTS ][4]; /* fixme -- should just be a pointer */
90 float immediate[MAX_IMMEDIATES][4]; /* fixme -- should just be a pointer */
91 float internal [MAX_INTERNALS ][4];
92
93 float scale[4]; /* viewport */
94 float translate[4]; /* viewport */
95
96 float tmp[2][4]; /* scratch space for LIT */
97
98 struct shine_tab shine_tab[MAX_SHINE_TAB];
99 struct lit_info lit_info[MAX_LIT_INFO];
100 unsigned now;
101
102
103 ushort fpu_rnd_nearest;
104 ushort fpu_rnd_neg_inf;
105 ushort fpu_restore;
106 ushort fpucntl; /* one of FPU_* above */
107
108 struct {
109 const void *input_ptr;
110 unsigned input_stride;
111
112 unsigned output_offset;
113 } attrib[PIPE_MAX_ATTRIBS];
114 };
115
116
117
118
119 struct aos_compilation {
120 struct x86_function *func;
121 struct draw_vs_varient_aos_sse *vaos;
122
123 unsigned insn_counter;
124 unsigned num_immediates;
125 unsigned count;
126 unsigned lit_count;
127
128 struct {
129 unsigned idx:16;
130 unsigned file:8;
131 unsigned dirty:8;
132 unsigned last_used;
133 } xmm[8];
134
135
136 boolean input_fetched[PIPE_MAX_ATTRIBS];
137 unsigned output_last_write[PIPE_MAX_ATTRIBS];
138
139 boolean have_sse2;
140 boolean error;
141 short fpucntl;
142
143 /* these are actually known values, but putting them in a struct
144 * like this is helpful to keep them in sync across the file.
145 */
146 struct x86_reg tmp_EAX;
147 struct x86_reg idx_EBX; /* either start+i or &elt[i] */
148 struct x86_reg outbuf_ECX;
149 struct x86_reg machine_EDX;
150 struct x86_reg count_ESI; /* decrements to zero */
151 };
152
153 struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp );
154 void aos_release_xmm_reg( struct aos_compilation *cp, unsigned idx );
155
156 void aos_adopt_xmm_reg( struct aos_compilation *cp,
157 struct x86_reg reg,
158 unsigned file,
159 unsigned idx,
160 unsigned dirty );
161
162 struct x86_reg aos_get_shader_reg( struct aos_compilation *cp,
163 unsigned file,
164 unsigned idx );
165
166 boolean aos_fetch_inputs( struct aos_compilation *cp,
167 boolean linear );
168
169 boolean aos_emit_outputs( struct aos_compilation *cp );
170
171
172 #define IMM_ONES 0 /* 1, 1,1,1 */
173 #define IMM_SWZ 1 /* 1,-1,0, 0xffffffff */
174 #define IMM_IDENTITY 2 /* 0, 0,0,1 */
175 #define IMM_INV_255 3 /* 1/255, 1/255, 1/255, 1/255 */
176 #define IMM_255 4 /* 255, 255, 255, 255 */
177 #define IMM_NEGS 5 /* -1,-1,-1,-1 */
178 #define IMM_RSQ 6 /* -.5,1.5,_,_ */
179 #define IMM_PSIZE 7 /* not really an immediate - updated each run */
180
181 struct x86_reg aos_get_internal( struct aos_compilation *cp,
182 unsigned imm );
183 struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp,
184 unsigned imm );
185
186
187 #define ERROR(cp, msg) \
188 do { \
189 debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
190 cp->error = 1; \
191 assert(0); \
192 } while (0)
193
194
195
196
197
198
199 struct draw_vs_varient_aos_sse {
200 struct draw_vs_varient base;
201 struct draw_context *draw;
202
203 #if 0
204 struct {
205 const void *ptr;
206 unsigned stride;
207 } attrib[PIPE_MAX_ATTRIBS];
208 #endif
209
210 struct aos_machine *machine; /* XXX: temporarily unshared */
211
212 vsv_run_linear_func gen_run_linear;
213 vsv_run_elts_func gen_run_elts;
214
215
216 struct x86_function func[2];
217 };
218
219
220
221 #endif
222