Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_exec_generic.c
1 /**************************************************************************
2
3 Copyright 2004 Tungsten Graphics Inc., Cedar Park, Texas.
4
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ATI, TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "glheader.h"
34 #include "context.h"
35 #include "macros.h"
36 #include "vtxfmt.h"
37 #include "dlist.h"
38 #include "state.h"
39 #include "light.h"
40 #include "api_arrayelt.h"
41 #include "api_noop.h"
42
43 #include "brw_exec.h"
44
45
46 /* Versions of all the entrypoints for situations where codegen isn't
47 * available.
48 *
49 * Note: Only one size for each attribute may be active at once.
50 * Eg. if Color3f is installed/active, then Color4f may not be, even
51 * if the vertex actually contains 4 color coordinates. This is
52 * because the 3f version won't otherwise set color[3] to 1.0 -- this
53 * is the job of the chooser function when switching between Color4f
54 * and Color3f.
55 */
56 #define ATTRFV( ATTR, N ) \
57 static void attrib_##ATTR##_##N( const GLfloat *v ) \
58 { \
59 GET_CURRENT_CONTEXT( ctx ); \
60 struct brw_exec_context *exec = IMM_CONTEXT(ctx)->exec; \
61 \
62 if ((ATTR) == 0) { \
63 GLuint i; \
64 \
65 if (N>0) exec->vtx.vbptr[0] = v[0]; \
66 if (N>1) exec->vtx.vbptr[1] = v[1]; \
67 if (N>2) exec->vtx.vbptr[2] = v[2]; \
68 if (N>3) exec->vtx.vbptr[3] = v[3]; \
69 \
70 for (i = N; i < exec->vtx.vertex_size; i++) \
71 exec->vtx.vbptr[i] = exec->vtx.vertex[i]; \
72 \
73 exec->vtx.vbptr += exec->vtx.vertex_size; \
74 exec->ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; \
75 \
76 if (++exec->vtx.vert_count >= exec->vtx.max_vert) \
77 brw_exec_vtx_wrap( exec ); \
78 } \
79 else { \
80 GLfloat *dest = exec->vtx.attrptr[ATTR]; \
81 if (N>0) dest[0] = v[0]; \
82 if (N>1) dest[1] = v[1]; \
83 if (N>2) dest[2] = v[2]; \
84 if (N>3) dest[3] = v[3]; \
85 } \
86 }
87
88 #define INIT(TAB, ATTR) \
89 TAB[ATTR][0] = attrib_##ATTR##_1; \
90 TAB[ATTR][1] = attrib_##ATTR##_2; \
91 TAB[ATTR][2] = attrib_##ATTR##_3; \
92 TAB[ATTR][3] = attrib_##ATTR##_4;
93
94
95 #define ATTRS( ATTRIB ) \
96 ATTRFV( ATTRIB, 1 ) \
97 ATTRFV( ATTRIB, 2 ) \
98 ATTRFV( ATTRIB, 3 ) \
99 ATTRFV( ATTRIB, 4 )
100
101 ATTRS( 0 )
102 ATTRS( 1 )
103 ATTRS( 2 )
104 ATTRS( 3 )
105 ATTRS( 4 )
106 ATTRS( 5 )
107 ATTRS( 6 )
108 ATTRS( 7 )
109 ATTRS( 8 )
110 ATTRS( 9 )
111 ATTRS( 10 )
112 ATTRS( 11 )
113 ATTRS( 12 )
114 ATTRS( 13 )
115 ATTRS( 14 )
116 ATTRS( 15 )
117
118 void brw_exec_generic_attr_table_init( brw_attrfv_func (*tab)[4] )
119 {
120 INIT( tab, 0 );
121 INIT( tab, 1 );
122 INIT( tab, 2 );
123 INIT( tab, 3 );
124 INIT( tab, 4 );
125 INIT( tab, 5 );
126 INIT( tab, 6 );
127 INIT( tab, 7 );
128 INIT( tab, 8 );
129 INIT( tab, 9 );
130 INIT( tab, 10 );
131 INIT( tab, 11 );
132 INIT( tab, 12 );
133 INIT( tab, 13 );
134 INIT( tab, 14 );
135 INIT( tab, 15 );
136 }
137
138 /* These can be made efficient with codegen. Further, by adding more
139 * logic to do_choose(), the double-dispatch for legacy entrypoints
140 * like glVertex3f() can be removed.
141 */
142 #define DISPATCH_ATTRFV( ATTR, COUNT, P ) \
143 do { \
144 GET_CURRENT_CONTEXT( ctx ); \
145 struct brw_exec_context *exec = IMM_CONTEXT(ctx)->exec; \
146 exec->vtx.tabfv[ATTR][COUNT-1]( P ); \
147 } while (0)
148
149 #define DISPATCH_ATTR1FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 1, V )
150 #define DISPATCH_ATTR2FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 2, V )
151 #define DISPATCH_ATTR3FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 3, V )
152 #define DISPATCH_ATTR4FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 4, V )
153
154 #define DISPATCH_ATTR1F( ATTR, S ) DISPATCH_ATTRFV( ATTR, 1, &(S) )
155
156 #define DISPATCH_ATTR2F( ATTR, S,T ) \
157 do { \
158 GLfloat v[2]; \
159 v[0] = S; v[1] = T; \
160 DISPATCH_ATTR2FV( ATTR, v ); \
161 } while (0)
162 #define DISPATCH_ATTR3F( ATTR, S,T,R ) \
163 do { \
164 GLfloat v[3]; \
165 v[0] = S; v[1] = T; v[2] = R; \
166 DISPATCH_ATTR3FV( ATTR, v ); \
167 } while (0)
168 #define DISPATCH_ATTR4F( ATTR, S,T,R,Q ) \
169 do { \
170 GLfloat v[4]; \
171 v[0] = S; v[1] = T; v[2] = R; v[3] = Q; \
172 DISPATCH_ATTR4FV( ATTR, v ); \
173 } while (0)
174
175
176 static void GLAPIENTRY brw_Vertex2f( GLfloat x, GLfloat y )
177 {
178 DISPATCH_ATTR2F( BRW_ATTRIB_POS, x, y );
179 }
180
181 static void GLAPIENTRY brw_Vertex2fv( const GLfloat *v )
182 {
183 DISPATCH_ATTR2FV( BRW_ATTRIB_POS, v );
184 }
185
186 static void GLAPIENTRY brw_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
187 {
188 DISPATCH_ATTR3F( BRW_ATTRIB_POS, x, y, z );
189 }
190
191 static void GLAPIENTRY brw_Vertex3fv( const GLfloat *v )
192 {
193 DISPATCH_ATTR3FV( BRW_ATTRIB_POS, v );
194 }
195
196 static void GLAPIENTRY brw_Vertex4f( GLfloat x, GLfloat y, GLfloat z,
197 GLfloat w )
198 {
199 DISPATCH_ATTR4F( BRW_ATTRIB_POS, x, y, z, w );
200 }
201
202 static void GLAPIENTRY brw_Vertex4fv( const GLfloat *v )
203 {
204 DISPATCH_ATTR4FV( BRW_ATTRIB_POS, v );
205 }
206
207 static void GLAPIENTRY brw_TexCoord1f( GLfloat x )
208 {
209 DISPATCH_ATTR1F( BRW_ATTRIB_TEX0, x );
210 }
211
212 static void GLAPIENTRY brw_TexCoord1fv( const GLfloat *v )
213 {
214 DISPATCH_ATTR1FV( BRW_ATTRIB_TEX0, v );
215 }
216
217 static void GLAPIENTRY brw_TexCoord2f( GLfloat x, GLfloat y )
218 {
219 DISPATCH_ATTR2F( BRW_ATTRIB_TEX0, x, y );
220 }
221
222 static void GLAPIENTRY brw_TexCoord2fv( const GLfloat *v )
223 {
224 DISPATCH_ATTR2FV( BRW_ATTRIB_TEX0, v );
225 }
226
227 static void GLAPIENTRY brw_TexCoord3f( GLfloat x, GLfloat y, GLfloat z )
228 {
229 DISPATCH_ATTR3F( BRW_ATTRIB_TEX0, x, y, z );
230 }
231
232 static void GLAPIENTRY brw_TexCoord3fv( const GLfloat *v )
233 {
234 DISPATCH_ATTR3FV( BRW_ATTRIB_TEX0, v );
235 }
236
237 static void GLAPIENTRY brw_TexCoord4f( GLfloat x, GLfloat y, GLfloat z,
238 GLfloat w )
239 {
240 DISPATCH_ATTR4F( BRW_ATTRIB_TEX0, x, y, z, w );
241 }
242
243 static void GLAPIENTRY brw_TexCoord4fv( const GLfloat *v )
244 {
245 DISPATCH_ATTR4FV( BRW_ATTRIB_TEX0, v );
246 }
247
248 static void GLAPIENTRY brw_Normal3f( GLfloat x, GLfloat y, GLfloat z )
249 {
250 DISPATCH_ATTR3F( BRW_ATTRIB_NORMAL, x, y, z );
251 }
252
253 static void GLAPIENTRY brw_Normal3fv( const GLfloat *v )
254 {
255 DISPATCH_ATTR3FV( BRW_ATTRIB_NORMAL, v );
256 }
257
258 static void GLAPIENTRY brw_FogCoordfEXT( GLfloat x )
259 {
260 DISPATCH_ATTR1F( BRW_ATTRIB_FOG, x );
261 }
262
263 static void GLAPIENTRY brw_FogCoordfvEXT( const GLfloat *v )
264 {
265 DISPATCH_ATTR1FV( BRW_ATTRIB_FOG, v );
266 }
267
268 static void GLAPIENTRY brw_Color3f( GLfloat x, GLfloat y, GLfloat z )
269 {
270 DISPATCH_ATTR3F( BRW_ATTRIB_COLOR0, x, y, z );
271 }
272
273 static void GLAPIENTRY brw_Color3fv( const GLfloat *v )
274 {
275 DISPATCH_ATTR3FV( BRW_ATTRIB_COLOR0, v );
276 }
277
278 static void GLAPIENTRY brw_Color4f( GLfloat x, GLfloat y, GLfloat z,
279 GLfloat w )
280 {
281 DISPATCH_ATTR4F( BRW_ATTRIB_COLOR0, x, y, z, w );
282 }
283
284 static void GLAPIENTRY brw_Color4fv( const GLfloat *v )
285 {
286 DISPATCH_ATTR4FV( BRW_ATTRIB_COLOR0, v );
287 }
288
289 static void GLAPIENTRY brw_SecondaryColor3fEXT( GLfloat x, GLfloat y,
290 GLfloat z )
291 {
292 DISPATCH_ATTR3F( BRW_ATTRIB_COLOR1, x, y, z );
293 }
294
295 static void GLAPIENTRY brw_SecondaryColor3fvEXT( const GLfloat *v )
296 {
297 DISPATCH_ATTR3FV( BRW_ATTRIB_COLOR1, v );
298 }
299
300 static void GLAPIENTRY brw_MultiTexCoord1f( GLenum target, GLfloat x )
301 {
302 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
303 DISPATCH_ATTR1F( attr, x );
304 }
305
306 static void GLAPIENTRY brw_MultiTexCoord1fv( GLenum target,
307 const GLfloat *v )
308 {
309 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
310 DISPATCH_ATTR1FV( attr, v );
311 }
312
313 static void GLAPIENTRY brw_MultiTexCoord2f( GLenum target, GLfloat x,
314 GLfloat y )
315 {
316 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
317 DISPATCH_ATTR2F( attr, x, y );
318 }
319
320 static void GLAPIENTRY brw_MultiTexCoord2fv( GLenum target,
321 const GLfloat *v )
322 {
323 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
324 DISPATCH_ATTR2FV( attr, v );
325 }
326
327 static void GLAPIENTRY brw_MultiTexCoord3f( GLenum target, GLfloat x,
328 GLfloat y, GLfloat z)
329 {
330 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
331 DISPATCH_ATTR3F( attr, x, y, z );
332 }
333
334 static void GLAPIENTRY brw_MultiTexCoord3fv( GLenum target,
335 const GLfloat *v )
336 {
337 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
338 DISPATCH_ATTR3FV( attr, v );
339 }
340
341 static void GLAPIENTRY brw_MultiTexCoord4f( GLenum target, GLfloat x,
342 GLfloat y, GLfloat z,
343 GLfloat w )
344 {
345 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
346 DISPATCH_ATTR4F( attr, x, y, z, w );
347 }
348
349 static void GLAPIENTRY brw_MultiTexCoord4fv( GLenum target,
350 const GLfloat *v )
351 {
352 GLuint attr = (target & 0x7) + BRW_ATTRIB_TEX0;
353 DISPATCH_ATTR4FV( attr, v );
354 }
355
356
357 static void GLAPIENTRY brw_VertexAttrib1fNV( GLuint index, GLfloat x )
358 {
359 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
360 DISPATCH_ATTR1F( index, x );
361 }
362
363 static void GLAPIENTRY brw_VertexAttrib1fvNV( GLuint index,
364 const GLfloat *v )
365 {
366 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
367 DISPATCH_ATTR1FV( index, v );
368 }
369
370 static void GLAPIENTRY brw_VertexAttrib2fNV( GLuint index, GLfloat x,
371 GLfloat y )
372 {
373 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
374 DISPATCH_ATTR2F( index, x, y );
375 }
376
377 static void GLAPIENTRY brw_VertexAttrib2fvNV( GLuint index,
378 const GLfloat *v )
379 {
380 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
381 DISPATCH_ATTR2FV( index, v );
382 }
383
384 static void GLAPIENTRY brw_VertexAttrib3fNV( GLuint index, GLfloat x,
385 GLfloat y, GLfloat z )
386 {
387 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
388 DISPATCH_ATTR3F( index, x, y, z );
389 }
390
391 static void GLAPIENTRY brw_VertexAttrib3fvNV( GLuint index,
392 const GLfloat *v )
393 {
394 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
395 DISPATCH_ATTR3FV( index, v );
396 }
397
398 static void GLAPIENTRY brw_VertexAttrib4fNV( GLuint index, GLfloat x,
399 GLfloat y, GLfloat z,
400 GLfloat w )
401 {
402 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
403 DISPATCH_ATTR4F( index, x, y, z, w );
404 }
405
406 static void GLAPIENTRY brw_VertexAttrib4fvNV( GLuint index,
407 const GLfloat *v )
408 {
409 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
410 DISPATCH_ATTR4FV( index, v );
411 }
412
413
414 /*
415 * XXX adjust index
416 */
417
418 static void GLAPIENTRY brw_VertexAttrib1fARB( GLuint index, GLfloat x )
419 {
420 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
421 DISPATCH_ATTR1F( index, x );
422 }
423
424 static void GLAPIENTRY brw_VertexAttrib1fvARB( GLuint index,
425 const GLfloat *v )
426 {
427 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
428 DISPATCH_ATTR1FV( index, v );
429 }
430
431 static void GLAPIENTRY brw_VertexAttrib2fARB( GLuint index, GLfloat x,
432 GLfloat y )
433 {
434 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
435 DISPATCH_ATTR2F( index, x, y );
436 }
437
438 static void GLAPIENTRY brw_VertexAttrib2fvARB( GLuint index,
439 const GLfloat *v )
440 {
441 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
442 DISPATCH_ATTR2FV( index, v );
443 }
444
445 static void GLAPIENTRY brw_VertexAttrib3fARB( GLuint index, GLfloat x,
446 GLfloat y, GLfloat z )
447 {
448 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
449 DISPATCH_ATTR3F( index, x, y, z );
450 }
451
452 static void GLAPIENTRY brw_VertexAttrib3fvARB( GLuint index,
453 const GLfloat *v )
454 {
455 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
456 DISPATCH_ATTR3FV( index, v );
457 }
458
459 static void GLAPIENTRY brw_VertexAttrib4fARB( GLuint index, GLfloat x,
460 GLfloat y, GLfloat z,
461 GLfloat w )
462 {
463 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
464 DISPATCH_ATTR4F( index, x, y, z, w );
465 }
466
467 static void GLAPIENTRY brw_VertexAttrib4fvARB( GLuint index,
468 const GLfloat *v )
469 {
470 if (index >= BRW_ATTRIB_FIRST_MATERIAL) index = ERROR_ATTRIB;
471 DISPATCH_ATTR4FV( index, v );
472 }
473
474
475 /* Install the generic versions of the 2nd level dispatch
476 * functions. Some of these have a codegen alternative.
477 */
478 void brw_exec_vtx_generic_init( struct brw_exec_context *exec )
479 {
480 GLvertexformat *vfmt = &exec->vtxfmt;
481
482 vfmt->Color3f = brw_Color3f;
483 vfmt->Color3fv = brw_Color3fv;
484 vfmt->Color4f = brw_Color4f;
485 vfmt->Color4fv = brw_Color4fv;
486 vfmt->FogCoordfEXT = brw_FogCoordfEXT;
487 vfmt->FogCoordfvEXT = brw_FogCoordfvEXT;
488 vfmt->MultiTexCoord1fARB = brw_MultiTexCoord1f;
489 vfmt->MultiTexCoord1fvARB = brw_MultiTexCoord1fv;
490 vfmt->MultiTexCoord2fARB = brw_MultiTexCoord2f;
491 vfmt->MultiTexCoord2fvARB = brw_MultiTexCoord2fv;
492 vfmt->MultiTexCoord3fARB = brw_MultiTexCoord3f;
493 vfmt->MultiTexCoord3fvARB = brw_MultiTexCoord3fv;
494 vfmt->MultiTexCoord4fARB = brw_MultiTexCoord4f;
495 vfmt->MultiTexCoord4fvARB = brw_MultiTexCoord4fv;
496 vfmt->Normal3f = brw_Normal3f;
497 vfmt->Normal3fv = brw_Normal3fv;
498 vfmt->SecondaryColor3fEXT = brw_SecondaryColor3fEXT;
499 vfmt->SecondaryColor3fvEXT = brw_SecondaryColor3fvEXT;
500 vfmt->TexCoord1f = brw_TexCoord1f;
501 vfmt->TexCoord1fv = brw_TexCoord1fv;
502 vfmt->TexCoord2f = brw_TexCoord2f;
503 vfmt->TexCoord2fv = brw_TexCoord2fv;
504 vfmt->TexCoord3f = brw_TexCoord3f;
505 vfmt->TexCoord3fv = brw_TexCoord3fv;
506 vfmt->TexCoord4f = brw_TexCoord4f;
507 vfmt->TexCoord4fv = brw_TexCoord4fv;
508 vfmt->Vertex2f = brw_Vertex2f;
509 vfmt->Vertex2fv = brw_Vertex2fv;
510 vfmt->Vertex3f = brw_Vertex3f;
511 vfmt->Vertex3fv = brw_Vertex3fv;
512 vfmt->Vertex4f = brw_Vertex4f;
513 vfmt->Vertex4fv = brw_Vertex4fv;
514 vfmt->VertexAttrib1fNV = brw_VertexAttrib1fNV;
515 vfmt->VertexAttrib1fvNV = brw_VertexAttrib1fvNV;
516 vfmt->VertexAttrib2fNV = brw_VertexAttrib2fNV;
517 vfmt->VertexAttrib2fvNV = brw_VertexAttrib2fvNV;
518 vfmt->VertexAttrib3fNV = brw_VertexAttrib3fNV;
519 vfmt->VertexAttrib3fvNV = brw_VertexAttrib3fvNV;
520 vfmt->VertexAttrib4fNV = brw_VertexAttrib4fNV;
521 vfmt->VertexAttrib4fvNV = brw_VertexAttrib4fvNV;
522 vfmt->VertexAttrib1fARB = brw_VertexAttrib1fARB;
523 vfmt->VertexAttrib1fvARB = brw_VertexAttrib1fvARB;
524 vfmt->VertexAttrib2fARB = brw_VertexAttrib2fARB;
525 vfmt->VertexAttrib2fvARB = brw_VertexAttrib2fvARB;
526 vfmt->VertexAttrib3fARB = brw_VertexAttrib3fARB;
527 vfmt->VertexAttrib3fvARB = brw_VertexAttrib3fvARB;
528 vfmt->VertexAttrib4fARB = brw_VertexAttrib4fARB;
529 vfmt->VertexAttrib4fvARB = brw_VertexAttrib4fvARB;
530 }