Updates to tnl_dd_dmatmp.h
[mesa.git] / src / mesa / drivers / dri / r200 / r200_maos_verts.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_maos_verts.c,v 1.1 2002/10/30 12:51:52 alanh Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "glheader.h"
37 #include "imports.h"
38 #include "mmath.h"
39 #include "mtypes.h"
40 #include "enums.h"
41 #include "colormac.h"
42 #include "light.h"
43
44 #include "array_cache/acache.h"
45 #include "tnl/tnl.h"
46 #include "tnl/t_pipeline.h"
47 #include "tnl/t_imm_debug.h"
48
49 #include "r200_context.h"
50 #include "r200_state.h"
51 #include "r200_ioctl.h"
52 #include "r200_tex.h"
53 #include "r200_tcl.h"
54 #include "r200_swtcl.h"
55 #include "r200_maos.h"
56
57
58 #define R200_TCL_MAX_SETUP 13
59
60 union emit_union { float f; GLuint ui; GLubyte ub[4]; };
61
62 static struct {
63 void (*emit)( GLcontext *, GLuint, GLuint, void * );
64 GLuint vertex_size;
65 GLuint vertex_format;
66 } setup_tab[R200_TCL_MAX_SETUP];
67
68 #define DO_W (IND & R200_CP_VC_FRMT_W0)
69 #define DO_RGBA (IND & R200_CP_VC_FRMT_PKCOLOR)
70 #define DO_SPEC (IND & R200_CP_VC_FRMT_PKSPEC)
71 #define DO_FOG (IND & R200_CP_VC_FRMT_PKSPEC)
72 #define DO_TEX0 (IND & R200_CP_VC_FRMT_ST0)
73 #define DO_TEX1 (IND & R200_CP_VC_FRMT_ST1)
74 #define DO_PTEX (IND & R200_CP_VC_FRMT_Q0)
75 #define DO_NORM (IND & R200_CP_VC_FRMT_N0)
76
77 #define DO_TEX2 0
78 #define DO_TEX3 0
79
80 #define GET_TEXSOURCE(n) n
81
82 /***********************************************************************
83 * Generate vertex emit functions *
84 ***********************************************************************/
85
86
87 /* Defined in order of increasing vertex size:
88 */
89 #define IDX 0
90 #define IND (R200_CP_VC_FRMT_XY| \
91 R200_CP_VC_FRMT_Z| \
92 R200_CP_VC_FRMT_PKCOLOR)
93 #define TAG(x) x##_rgba
94 #include "r200_maos_vbtmp.h"
95
96 #define IDX 1
97 #define IND (R200_CP_VC_FRMT_XY| \
98 R200_CP_VC_FRMT_Z| \
99 R200_CP_VC_FRMT_N0)
100 #define TAG(x) x##_n
101 #include "r200_maos_vbtmp.h"
102
103 #define IDX 2
104 #define IND (R200_CP_VC_FRMT_XY| \
105 R200_CP_VC_FRMT_Z| \
106 R200_CP_VC_FRMT_PKCOLOR| \
107 R200_CP_VC_FRMT_ST0)
108 #define TAG(x) x##_rgba_st
109 #include "r200_maos_vbtmp.h"
110
111 #define IDX 3
112 #define IND (R200_CP_VC_FRMT_XY| \
113 R200_CP_VC_FRMT_Z| \
114 R200_CP_VC_FRMT_PKCOLOR| \
115 R200_CP_VC_FRMT_N0)
116 #define TAG(x) x##_rgba_n
117 #include "r200_maos_vbtmp.h"
118
119 #define IDX 4
120 #define IND (R200_CP_VC_FRMT_XY| \
121 R200_CP_VC_FRMT_Z| \
122 R200_CP_VC_FRMT_ST0| \
123 R200_CP_VC_FRMT_N0)
124 #define TAG(x) x##_st_n
125 #include "r200_maos_vbtmp.h"
126
127 #define IDX 5
128 #define IND (R200_CP_VC_FRMT_XY| \
129 R200_CP_VC_FRMT_Z| \
130 R200_CP_VC_FRMT_PKCOLOR| \
131 R200_CP_VC_FRMT_ST0| \
132 R200_CP_VC_FRMT_ST1)
133 #define TAG(x) x##_rgba_st_st
134 #include "r200_maos_vbtmp.h"
135
136 #define IDX 6
137 #define IND (R200_CP_VC_FRMT_XY| \
138 R200_CP_VC_FRMT_Z| \
139 R200_CP_VC_FRMT_PKCOLOR| \
140 R200_CP_VC_FRMT_ST0| \
141 R200_CP_VC_FRMT_N0)
142 #define TAG(x) x##_rgba_st_n
143 #include "r200_maos_vbtmp.h"
144
145 #define IDX 7
146 #define IND (R200_CP_VC_FRMT_XY| \
147 R200_CP_VC_FRMT_Z| \
148 R200_CP_VC_FRMT_PKCOLOR| \
149 R200_CP_VC_FRMT_PKSPEC| \
150 R200_CP_VC_FRMT_ST0| \
151 R200_CP_VC_FRMT_ST1)
152 #define TAG(x) x##_rgba_spec_st_st
153 #include "r200_maos_vbtmp.h"
154
155 #define IDX 8
156 #define IND (R200_CP_VC_FRMT_XY| \
157 R200_CP_VC_FRMT_Z| \
158 R200_CP_VC_FRMT_ST0| \
159 R200_CP_VC_FRMT_ST1| \
160 R200_CP_VC_FRMT_N0)
161 #define TAG(x) x##_st_st_n
162 #include "r200_maos_vbtmp.h"
163
164 #define IDX 9
165 #define IND (R200_CP_VC_FRMT_XY| \
166 R200_CP_VC_FRMT_Z| \
167 R200_CP_VC_FRMT_PKCOLOR| \
168 R200_CP_VC_FRMT_PKSPEC| \
169 R200_CP_VC_FRMT_ST0| \
170 R200_CP_VC_FRMT_ST1| \
171 R200_CP_VC_FRMT_N0)
172 #define TAG(x) x##_rgba_spec_st_st_n
173 #include "r200_maos_vbtmp.h"
174
175 #define IDX 10
176 #define IND (R200_CP_VC_FRMT_XY| \
177 R200_CP_VC_FRMT_Z| \
178 R200_CP_VC_FRMT_PKCOLOR| \
179 R200_CP_VC_FRMT_ST0| \
180 R200_CP_VC_FRMT_Q0)
181 #define TAG(x) x##_rgba_stq
182 #include "r200_maos_vbtmp.h"
183
184 #define IDX 11
185 #define IND (R200_CP_VC_FRMT_XY| \
186 R200_CP_VC_FRMT_Z| \
187 R200_CP_VC_FRMT_PKCOLOR| \
188 R200_CP_VC_FRMT_ST1| \
189 R200_CP_VC_FRMT_Q1| \
190 R200_CP_VC_FRMT_ST0| \
191 R200_CP_VC_FRMT_Q0)
192 #define TAG(x) x##_rgba_stq_stq
193 #include "r200_maos_vbtmp.h"
194
195 #define IDX 12
196 #define IND (R200_CP_VC_FRMT_XY| \
197 R200_CP_VC_FRMT_Z| \
198 R200_CP_VC_FRMT_W0| \
199 R200_CP_VC_FRMT_PKCOLOR| \
200 R200_CP_VC_FRMT_PKSPEC| \
201 R200_CP_VC_FRMT_ST0| \
202 R200_CP_VC_FRMT_Q0| \
203 R200_CP_VC_FRMT_ST1| \
204 R200_CP_VC_FRMT_Q1| \
205 R200_CP_VC_FRMT_N0)
206 #define TAG(x) x##_w_rgba_spec_stq_stq_n
207 #include "r200_maos_vbtmp.h"
208
209
210
211
212
213 /***********************************************************************
214 * Initialization
215 ***********************************************************************/
216
217
218 static void init_tcl_verts( void )
219 {
220 init_rgba();
221 init_n();
222 init_rgba_n();
223 init_rgba_st();
224 init_st_n();
225 init_rgba_st_st();
226 init_rgba_st_n();
227 init_rgba_spec_st_st();
228 init_st_st_n();
229 init_rgba_spec_st_st_n();
230 init_rgba_stq();
231 init_rgba_stq_stq();
232 init_w_rgba_spec_stq_stq_n();
233 }
234
235
236 void r200EmitArrays( GLcontext *ctx, GLuint inputs )
237 {
238 r200ContextPtr rmesa = R200_CONTEXT(ctx);
239 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
240 GLuint req = 0;
241 GLuint vtx = (rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] &
242 ~(R200_TCL_VTX_Q0|R200_TCL_VTX_Q1));
243 int i;
244 static int firsttime = 1;
245
246 if (firsttime) {
247 init_tcl_verts();
248 firsttime = 0;
249 }
250
251 if (1) {
252 req |= R200_CP_VC_FRMT_Z;
253 if (VB->ObjPtr->size == 4) {
254 req |= R200_CP_VC_FRMT_W0;
255 }
256 }
257
258 if (inputs & VERT_BIT_NORMAL) {
259 req |= R200_CP_VC_FRMT_N0;
260 }
261
262 if (inputs & VERT_BIT_COLOR0) {
263 req |= R200_CP_VC_FRMT_PKCOLOR;
264 }
265
266 if (inputs & VERT_BIT_COLOR1) {
267 req |= R200_CP_VC_FRMT_PKSPEC;
268 }
269
270 if (inputs & VERT_BIT_TEX0) {
271 req |= R200_CP_VC_FRMT_ST0;
272
273 if (VB->TexCoordPtr[0]->size == 4) {
274 req |= R200_CP_VC_FRMT_Q0;
275 vtx |= R200_TCL_VTX_Q0;
276 }
277 }
278
279 if (inputs & VERT_BIT_TEX1) {
280 req |= R200_CP_VC_FRMT_ST1;
281
282 if (VB->TexCoordPtr[1]->size == 4) {
283 req |= R200_CP_VC_FRMT_Q1;
284 vtx |= R200_TCL_VTX_Q1;
285 }
286 }
287
288 if (vtx != rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT]) {
289 R200_STATECHANGE( rmesa, tcl );
290 rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] = vtx;
291 }
292
293 for (i = 0 ; i < R200_TCL_MAX_SETUP ; i++)
294 if ((setup_tab[i].vertex_format & req) == req)
295 break;
296
297 if (rmesa->tcl.vertex_format == setup_tab[i].vertex_format &&
298 rmesa->tcl.indexed_verts.buf)
299 return;
300
301 if (rmesa->tcl.indexed_verts.buf)
302 r200ReleaseArrays( ctx, ~0 );
303
304 r200AllocDmaRegionVerts( rmesa,
305 &rmesa->tcl.indexed_verts,
306 VB->Count,
307 setup_tab[i].vertex_size * 4,
308 4);
309
310 setup_tab[i].emit( ctx, 0, VB->Count,
311 rmesa->tcl.indexed_verts.address +
312 rmesa->tcl.indexed_verts.start );
313
314 rmesa->tcl.vertex_format = setup_tab[i].vertex_format;
315 rmesa->tcl.indexed_verts.aos_start = GET_START( &rmesa->tcl.indexed_verts );
316 rmesa->tcl.indexed_verts.aos_size = setup_tab[i].vertex_size;
317 rmesa->tcl.indexed_verts.aos_stride = setup_tab[i].vertex_size;
318
319 rmesa->tcl.aos_components[0] = &rmesa->tcl.indexed_verts;
320 rmesa->tcl.nr_aos_components = 1;
321 }
322
323
324
325 void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
326 {
327 r200ContextPtr rmesa = R200_CONTEXT( ctx );
328
329 if (R200_DEBUG & DEBUG_VERTS)
330 _tnl_print_vert_flags( __FUNCTION__, newinputs );
331
332 if (newinputs)
333 r200ReleaseDmaRegion( rmesa, &rmesa->tcl.indexed_verts, __FUNCTION__ );
334 }