extend some DrawRangeElements cases to support rendering more than 65535 verts in...
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_vtxfmt_c.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_vtxfmt_c.c,v 1.2 2002/12/16 16:18:59 dawes Exp $ */
2 /**************************************************************************
3
4 Copyright 2002 ATI Technologies Inc., Ontario, Canada, and
5 Tungsten Graphics Inc., Cedar Park, Texas.
6
7 All Rights Reserved.
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 #include "glheader.h"
36 #include "mtypes.h"
37 #include "colormac.h"
38 #include "simple_list.h"
39 #include "api_noop.h"
40 #include "vtxfmt.h"
41
42 #include "radeon_vtxfmt.h"
43
44 #include "dispatch.h"
45
46 /* Fallback versions of all the entrypoints for situations where
47 * codegen isn't available. This is still a lot faster than the
48 * vb/pipeline implementation in Mesa.
49 */
50 static void radeon_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
51 {
52 GET_CURRENT_CONTEXT(ctx);
53 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
54 int i;
55
56 *rmesa->vb.dmaptr++ = *(int *)&x;
57 *rmesa->vb.dmaptr++ = *(int *)&y;
58 *rmesa->vb.dmaptr++ = *(int *)&z;
59
60 for (i = 3; i < rmesa->vb.vertex_size; i++)
61 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
62
63 if (--rmesa->vb.counter == 0)
64 rmesa->vb.notify();
65 }
66
67
68 static void radeon_Vertex3fv( const GLfloat *v )
69 {
70 GET_CURRENT_CONTEXT(ctx);
71 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
72 int i;
73
74 *rmesa->vb.dmaptr++ = *(int *)&v[0];
75 *rmesa->vb.dmaptr++ = *(int *)&v[1];
76 *rmesa->vb.dmaptr++ = *(int *)&v[2];
77
78 for (i = 3; i < rmesa->vb.vertex_size; i++)
79 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
80
81 if (--rmesa->vb.counter == 0)
82 rmesa->vb.notify();
83 }
84
85
86 static void radeon_Vertex2f( GLfloat x, GLfloat y )
87 {
88 GET_CURRENT_CONTEXT(ctx);
89 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
90 int i;
91
92 *rmesa->vb.dmaptr++ = *(int *)&x;
93 *rmesa->vb.dmaptr++ = *(int *)&y;
94 *rmesa->vb.dmaptr++ = 0;
95
96 for (i = 3; i < rmesa->vb.vertex_size; i++)
97 *rmesa->vb.dmaptr++ = *(int *)&rmesa->vb.vertex[i];
98
99 if (--rmesa->vb.counter == 0)
100 rmesa->vb.notify();
101 }
102
103
104 static void radeon_Vertex2fv( const GLfloat *v )
105 {
106 GET_CURRENT_CONTEXT(ctx);
107 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
108 int i;
109
110 *rmesa->vb.dmaptr++ = *(int *)&v[0];
111 *rmesa->vb.dmaptr++ = *(int *)&v[1];
112 *rmesa->vb.dmaptr++ = 0;
113
114 for (i = 3; i < rmesa->vb.vertex_size; i++)
115 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
116
117 if (--rmesa->vb.counter == 0)
118 rmesa->vb.notify();
119 }
120
121
122 #if 0
123 /* Color for ubyte (packed) color formats:
124 */
125 static void radeon_Color3ub_ub( GLubyte r, GLubyte g, GLubyte b )
126 {
127 GET_CURRENT_CONTEXT(ctx);
128 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
129 radeon_color_t *dest = rmesa->vb.colorptr;
130 dest->red = r;
131 dest->green = g;
132 dest->blue = b;
133 dest->alpha = 0xff;
134 }
135
136 static void radeon_Color3ubv_ub( const GLubyte *v )
137 {
138 GET_CURRENT_CONTEXT(ctx);
139 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
140 radeon_color_t *dest = rmesa->vb.colorptr;
141 dest->red = v[0];
142 dest->green = v[1];
143 dest->blue = v[2];
144 dest->alpha = 0xff;
145 }
146
147 static void radeon_Color4ub_ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
148 {
149 GET_CURRENT_CONTEXT(ctx);
150 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
151 radeon_color_t *dest = rmesa->vb.colorptr;
152 dest->red = r;
153 dest->green = g;
154 dest->blue = b;
155 dest->alpha = a;
156 }
157
158 static void radeon_Color4ubv_ub( const GLubyte *v )
159 {
160 GET_CURRENT_CONTEXT(ctx);
161 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
162 *(GLuint *)rmesa->vb.colorptr = LE32_TO_CPU(*(GLuint *)v);
163 }
164 #endif /* 0 */
165
166 static void radeon_Color3f_ub( GLfloat r, GLfloat g, GLfloat b )
167 {
168 GET_CURRENT_CONTEXT(ctx);
169 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
170 radeon_color_t *dest = rmesa->vb.colorptr;
171 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
172 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
173 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
174 dest->alpha = 255;
175 }
176
177 static void radeon_Color3fv_ub( const GLfloat *v )
178 {
179 GET_CURRENT_CONTEXT(ctx);
180 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
181 radeon_color_t *dest = rmesa->vb.colorptr;
182 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
183 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
184 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
185 dest->alpha = 255;
186 }
187
188 static void radeon_Color4f_ub( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
189 {
190 GET_CURRENT_CONTEXT(ctx);
191 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
192 radeon_color_t *dest = rmesa->vb.colorptr;
193 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
194 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
195 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
196 UNCLAMPED_FLOAT_TO_UBYTE( dest->alpha, a );
197 }
198
199 static void radeon_Color4fv_ub( const GLfloat *v )
200 {
201 GET_CURRENT_CONTEXT(ctx);
202 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
203 radeon_color_t *dest = rmesa->vb.colorptr;
204 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
205 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
206 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
207 UNCLAMPED_FLOAT_TO_UBYTE( dest->alpha, v[3] );
208 }
209
210
211 /* Color for float color+alpha formats:
212 */
213 #if 0
214 static void radeon_Color3ub_4f( GLubyte r, GLubyte g, GLubyte b )
215 {
216 GET_CURRENT_CONTEXT(ctx);
217 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
218 GLfloat *dest = rmesa->vb.floatcolorptr;
219 dest[0] = UBYTE_TO_FLOAT(r);
220 dest[1] = UBYTE_TO_FLOAT(g);
221 dest[2] = UBYTE_TO_FLOAT(b);
222 dest[3] = 1.0;
223 }
224
225 static void radeon_Color3ubv_4f( const GLubyte *v )
226 {
227 GET_CURRENT_CONTEXT(ctx);
228 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
229 GLfloat *dest = rmesa->vb.floatcolorptr;
230 dest[0] = UBYTE_TO_FLOAT(v[0]);
231 dest[1] = UBYTE_TO_FLOAT(v[1]);
232 dest[2] = UBYTE_TO_FLOAT(v[2]);
233 dest[3] = 1.0;
234 }
235
236 static void radeon_Color4ub_4f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
237 {
238 GET_CURRENT_CONTEXT(ctx);
239 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
240 GLfloat *dest = rmesa->vb.floatcolorptr;
241 dest[0] = UBYTE_TO_FLOAT(r);
242 dest[1] = UBYTE_TO_FLOAT(g);
243 dest[2] = UBYTE_TO_FLOAT(b);
244 dest[3] = UBYTE_TO_FLOAT(a);
245 }
246
247 static void radeon_Color4ubv_4f( const GLubyte *v )
248 {
249 GET_CURRENT_CONTEXT(ctx);
250 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
251 GLfloat *dest = rmesa->vb.floatcolorptr;
252 dest[0] = UBYTE_TO_FLOAT(v[0]);
253 dest[1] = UBYTE_TO_FLOAT(v[1]);
254 dest[2] = UBYTE_TO_FLOAT(v[2]);
255 dest[3] = UBYTE_TO_FLOAT(v[3]);
256 }
257 #endif /* 0 */
258
259
260 static void radeon_Color3f_4f( GLfloat r, GLfloat g, GLfloat b )
261 {
262 GET_CURRENT_CONTEXT(ctx);
263 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
264 GLfloat *dest = rmesa->vb.floatcolorptr;
265 dest[0] = r;
266 dest[1] = g;
267 dest[2] = b;
268 dest[3] = 1.0;
269 }
270
271 static void radeon_Color3fv_4f( const GLfloat *v )
272 {
273 GET_CURRENT_CONTEXT(ctx);
274 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
275 GLfloat *dest = rmesa->vb.floatcolorptr;
276 dest[0] = v[0];
277 dest[1] = v[1];
278 dest[2] = v[2];
279 dest[3] = 1.0;
280 }
281
282 static void radeon_Color4f_4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
283 {
284 GET_CURRENT_CONTEXT(ctx);
285 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
286 GLfloat *dest = rmesa->vb.floatcolorptr;
287 dest[0] = r;
288 dest[1] = g;
289 dest[2] = b;
290 dest[3] = a;
291 }
292
293 static void radeon_Color4fv_4f( const GLfloat *v )
294 {
295 GET_CURRENT_CONTEXT(ctx);
296 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
297 GLfloat *dest = rmesa->vb.floatcolorptr;
298 dest[0] = v[0];
299 dest[1] = v[1];
300 dest[2] = v[2];
301 dest[3] = v[3];
302 }
303
304
305 /* Color for float color formats:
306 */
307 #if 0
308 static void radeon_Color3ub_3f( GLubyte r, GLubyte g, GLubyte b )
309 {
310 GET_CURRENT_CONTEXT(ctx);
311 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
312 GLfloat *dest = rmesa->vb.floatcolorptr;
313 dest[0] = UBYTE_TO_FLOAT(r);
314 dest[1] = UBYTE_TO_FLOAT(g);
315 dest[2] = UBYTE_TO_FLOAT(b);
316 }
317
318 static void radeon_Color3ubv_3f( const GLubyte *v )
319 {
320 GET_CURRENT_CONTEXT(ctx);
321 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
322 GLfloat *dest = rmesa->vb.floatcolorptr;
323 dest[0] = UBYTE_TO_FLOAT(v[0]);
324 dest[1] = UBYTE_TO_FLOAT(v[1]);
325 dest[2] = UBYTE_TO_FLOAT(v[2]);
326 }
327
328 static void radeon_Color4ub_3f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
329 {
330 GET_CURRENT_CONTEXT(ctx);
331 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
332 GLfloat *dest = rmesa->vb.floatcolorptr;
333 dest[0] = UBYTE_TO_FLOAT(r);
334 dest[1] = UBYTE_TO_FLOAT(g);
335 dest[2] = UBYTE_TO_FLOAT(b);
336 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(a);
337 }
338
339 static void radeon_Color4ubv_3f( const GLubyte *v )
340 {
341 GET_CURRENT_CONTEXT(ctx);
342 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
343 GLfloat *dest = rmesa->vb.floatcolorptr;
344 dest[0] = UBYTE_TO_FLOAT(v[0]);
345 dest[1] = UBYTE_TO_FLOAT(v[1]);
346 dest[2] = UBYTE_TO_FLOAT(v[2]);
347 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(v[3]);
348 }
349 #endif /* 0 */
350
351
352 static void radeon_Color3f_3f( GLfloat r, GLfloat g, GLfloat b )
353 {
354 GET_CURRENT_CONTEXT(ctx);
355 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
356 GLfloat *dest = rmesa->vb.floatcolorptr;
357 dest[0] = r;
358 dest[1] = g;
359 dest[2] = b;
360 }
361
362 static void radeon_Color3fv_3f( const GLfloat *v )
363 {
364 GET_CURRENT_CONTEXT(ctx);
365 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
366 GLfloat *dest = rmesa->vb.floatcolorptr;
367 dest[0] = v[0];
368 dest[1] = v[1];
369 dest[2] = v[2];
370 }
371
372 static void radeon_Color4f_3f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
373 {
374 GET_CURRENT_CONTEXT(ctx);
375 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
376 GLfloat *dest = rmesa->vb.floatcolorptr;
377 dest[0] = r;
378 dest[1] = g;
379 dest[2] = b;
380 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = a;
381 }
382
383 static void radeon_Color4fv_3f( const GLfloat *v )
384 {
385 GET_CURRENT_CONTEXT(ctx);
386 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
387 GLfloat *dest = rmesa->vb.floatcolorptr;
388 dest[0] = v[0];
389 dest[1] = v[1];
390 dest[2] = v[2];
391 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = v[3];
392 }
393
394
395 /* Secondary Color:
396 */
397 #if 0
398 static void radeon_SecondaryColor3ubEXT_ub( GLubyte r, GLubyte g, GLubyte b )
399 {
400 GET_CURRENT_CONTEXT(ctx);
401 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
402 radeon_color_t *dest = rmesa->vb.specptr;
403 dest->red = r;
404 dest->green = g;
405 dest->blue = b;
406 dest->alpha = 0xff;
407 }
408
409 static void radeon_SecondaryColor3ubvEXT_ub( const GLubyte *v )
410 {
411 GET_CURRENT_CONTEXT(ctx);
412 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
413 radeon_color_t *dest = rmesa->vb.specptr;
414 dest->red = v[0];
415 dest->green = v[1];
416 dest->blue = v[2];
417 dest->alpha = 0xff;
418 }
419 #endif /* 0 */
420
421 static void radeon_SecondaryColor3fEXT_ub( GLfloat r, GLfloat g, GLfloat b )
422 {
423 GET_CURRENT_CONTEXT(ctx);
424 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
425 radeon_color_t *dest = rmesa->vb.specptr;
426 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
427 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
428 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
429 dest->alpha = 255;
430 }
431
432 static void radeon_SecondaryColor3fvEXT_ub( const GLfloat *v )
433 {
434 GET_CURRENT_CONTEXT(ctx);
435 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
436 radeon_color_t *dest = rmesa->vb.specptr;
437 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
438 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
439 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
440 dest->alpha = 255;
441 }
442
443 #if 0
444 static void radeon_SecondaryColor3ubEXT_3f( GLubyte r, GLubyte g, GLubyte b )
445 {
446 GET_CURRENT_CONTEXT(ctx);
447 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
448 GLfloat *dest = rmesa->vb.floatspecptr;
449 dest[0] = UBYTE_TO_FLOAT(r);
450 dest[1] = UBYTE_TO_FLOAT(g);
451 dest[2] = UBYTE_TO_FLOAT(b);
452 dest[3] = 1.0;
453 }
454
455 static void radeon_SecondaryColor3ubvEXT_3f( const GLubyte *v )
456 {
457 GET_CURRENT_CONTEXT(ctx);
458 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
459 GLfloat *dest = rmesa->vb.floatspecptr;
460 dest[0] = UBYTE_TO_FLOAT(v[0]);
461 dest[1] = UBYTE_TO_FLOAT(v[1]);
462 dest[2] = UBYTE_TO_FLOAT(v[2]);
463 dest[3] = 1.0;
464 }
465 #endif /* 0 */
466
467 static void radeon_SecondaryColor3fEXT_3f( GLfloat r, GLfloat g, GLfloat b )
468 {
469 GET_CURRENT_CONTEXT(ctx);
470 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
471 GLfloat *dest = rmesa->vb.floatspecptr;
472 dest[0] = r;
473 dest[1] = g;
474 dest[2] = b;
475 dest[3] = 1.0;
476 }
477
478 static void radeon_SecondaryColor3fvEXT_3f( const GLfloat *v )
479 {
480 GET_CURRENT_CONTEXT(ctx);
481 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
482 GLfloat *dest = rmesa->vb.floatspecptr;
483 dest[0] = v[0];
484 dest[1] = v[1];
485 dest[2] = v[2];
486 dest[3] = 1.0;
487 }
488
489
490 /* Normal
491 */
492 static void radeon_Normal3f( GLfloat n0, GLfloat n1, GLfloat n2 )
493 {
494 GET_CURRENT_CONTEXT(ctx);
495 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
496 GLfloat *dest = rmesa->vb.normalptr;
497 dest[0] = n0;
498 dest[1] = n1;
499 dest[2] = n2;
500 }
501
502 static void radeon_Normal3fv( const GLfloat *v )
503 {
504 GET_CURRENT_CONTEXT(ctx);
505 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
506 GLfloat *dest = rmesa->vb.normalptr;
507 dest[0] = v[0];
508 dest[1] = v[1];
509 dest[2] = v[2];
510 }
511
512
513 /* TexCoord
514 */
515 static void radeon_TexCoord1f( GLfloat s )
516 {
517 GET_CURRENT_CONTEXT(ctx);
518 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
519 GLfloat *dest = rmesa->vb.texcoordptr[0];
520 dest[0] = s;
521 dest[1] = 0;
522 }
523
524 static void radeon_TexCoord1fv( const GLfloat *v )
525 {
526 GET_CURRENT_CONTEXT(ctx);
527 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
528 GLfloat *dest = rmesa->vb.texcoordptr[0];
529 dest[0] = v[0];
530 dest[1] = 0;
531 }
532
533 static void radeon_TexCoord2f( GLfloat s, GLfloat t )
534 {
535 GET_CURRENT_CONTEXT(ctx);
536 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
537 GLfloat *dest = rmesa->vb.texcoordptr[0];
538 dest[0] = s;
539 dest[1] = t;
540 }
541
542 static void radeon_TexCoord2fv( const GLfloat *v )
543 {
544 GET_CURRENT_CONTEXT(ctx);
545 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
546 GLfloat *dest = rmesa->vb.texcoordptr[0];
547 dest[0] = v[0];
548 dest[1] = v[1];
549 }
550
551
552 /* MultiTexcoord
553 *
554 * Technically speaking, these functions should subtract GL_TEXTURE0 from
555 * \c target before masking and using it. The value of GL_TEXTURE0 is 0x84C0,
556 * which has the low-order 5 bits 0. For all possible valid values of
557 * \c target. Subtracting GL_TEXTURE0 has the net effect of masking \c target
558 * with 0x1F. Masking with 0x1F and then masking with 0x01 is redundant, so
559 * the subtraction has been omitted.
560 */
561
562 static void radeon_MultiTexCoord1fARB( GLenum target, GLfloat s )
563 {
564 GET_CURRENT_CONTEXT(ctx);
565 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
566 GLfloat *dest = rmesa->vb.texcoordptr[target & 3];
567 dest[0] = s;
568 dest[1] = 0;
569 }
570
571 static void radeon_MultiTexCoord1fvARB( GLenum target, const GLfloat *v )
572 {
573 GET_CURRENT_CONTEXT(ctx);
574 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
575 GLfloat *dest = rmesa->vb.texcoordptr[target & 3];
576 dest[0] = v[0];
577 dest[1] = 0;
578 }
579
580 static void radeon_MultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
581 {
582 GET_CURRENT_CONTEXT(ctx);
583 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
584 GLfloat *dest = rmesa->vb.texcoordptr[target & 3];
585 dest[0] = s;
586 dest[1] = t;
587 }
588
589 static void radeon_MultiTexCoord2fvARB( GLenum target, const GLfloat *v )
590 {
591 GET_CURRENT_CONTEXT(ctx);
592 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
593 GLfloat *dest = rmesa->vb.texcoordptr[target & 3];
594 dest[0] = v[0];
595 dest[1] = v[1];
596 }
597
598 static struct dynfn *lookup( struct dynfn *l, int key )
599 {
600 struct dynfn *f;
601
602 foreach( f, l ) {
603 if (f->key == key)
604 return f;
605 }
606
607 return NULL;
608 }
609
610 /* Can't use the loopback template for this:
611 */
612
613 #define CHOOSE(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
614 static void choose_##FN ARGS1 \
615 { \
616 GET_CURRENT_CONTEXT(ctx); \
617 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
618 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
619 struct dynfn *dfn; \
620 \
621 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
622 if (dfn == 0) \
623 dfn = rmesa->vb.codegen.FN( ctx, key ); \
624 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
625 fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ ); \
626 \
627 if (dfn) \
628 SET_ ## FN (ctx->Exec, (FNTYPE)(dfn->code)); \
629 else { \
630 if (RADEON_DEBUG & DEBUG_CODEGEN) \
631 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
632 SET_ ## FN (ctx->Exec, radeon_##FN); \
633 } \
634 \
635 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
636 CALL_ ## FN (ctx->Exec, ARGS2); \
637 }
638
639
640
641 /* For the _3f case, only allow one color function to be hooked in at
642 * a time. Eventually, use a similar mechanism to allow selecting the
643 * color component of the vertex format based on client behaviour.
644 *
645 * Note: Perform these actions even if there is a codegen or cached
646 * codegen version of the chosen function.
647 */
648 #define CHOOSE_COLOR(FN, FNTYPE, NR, MASK, ACTIVE, ARGS1, ARGS2 ) \
649 static void choose_##FN ARGS1 \
650 { \
651 GET_CURRENT_CONTEXT(ctx); \
652 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
653 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
654 struct dynfn *dfn; \
655 \
656 if (rmesa->vb.vertex_format & ACTIVE_PKCOLOR) { \
657 SET_ ## FN (ctx->Exec, radeon_##FN##_ub); \
658 } \
659 else if ((rmesa->vb.vertex_format & \
660 (ACTIVE_FPCOLOR|ACTIVE_FPALPHA)) == ACTIVE_FPCOLOR) { \
661 \
662 if (rmesa->vb.installed_color_3f_sz != NR) { \
663 rmesa->vb.installed_color_3f_sz = NR; \
664 if (NR == 3) ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = 1.0; \
665 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) { \
666 radeon_copy_to_current( ctx ); \
667 _mesa_install_exec_vtxfmt( ctx, &rmesa->vb.vtxfmt ); \
668 CALL_ ## FN (ctx->Exec, ARGS2); \
669 return; \
670 } \
671 } \
672 \
673 SET_ ## FN (ctx->Exec, radeon_##FN##_3f); \
674 } \
675 else { \
676 SET_ ## FN (ctx->Exec, radeon_##FN##_4f); \
677 } \
678 \
679 \
680 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
681 if (!dfn) dfn = rmesa->vb.codegen.FN( ctx, key ); \
682 \
683 if (dfn) { \
684 if (RADEON_DEBUG & DEBUG_CODEGEN) \
685 fprintf(stderr, "%s -- codegen version\n", __FUNCTION__ ); \
686 SET_ ## FN (ctx->Exec, (FNTYPE)dfn->code); \
687 } \
688 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
689 fprintf(stderr, "%s -- 'c' version\n", __FUNCTION__ ); \
690 \
691 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
692 CALL_ ## FN (ctx->Exec, ARGS2); \
693 }
694
695
696
697 /* Right now there are both _ub and _3f versions of the secondary color
698 * functions. Currently, we only set-up the hardware to use the _ub versions.
699 * The _3f versions are needed for the cases where secondary color isn't used
700 * in the vertex format, but it still needs to be stored in the context
701 * state vector.
702 */
703 #define CHOOSE_SECONDARY_COLOR(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
704 static void choose_##FN ARGS1 \
705 { \
706 GET_CURRENT_CONTEXT(ctx); \
707 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
708 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
709 struct dynfn *dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
710 \
711 if (dfn == 0) \
712 dfn = rmesa->vb.codegen.FN( ctx, key ); \
713 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
714 fprintf(stderr, "%s -- cached version\n", __FUNCTION__ ); \
715 \
716 if (dfn) \
717 SET_ ## FN (ctx->Exec, (FNTYPE)(dfn->code)); \
718 else { \
719 if (RADEON_DEBUG & DEBUG_CODEGEN) \
720 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
721 SET_ ## FN (ctx->Exec, ((rmesa->vb.vertex_format & ACTIVE_PKSPEC) != 0) \
722 ? radeon_##FN##_ub : radeon_##FN##_3f); \
723 } \
724 \
725 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
726 CALL_ ## FN (ctx->Exec, ARGS2); \
727 }
728
729
730
731
732
733 /* Shorthands
734 */
735 #define ACTIVE_XYZW (RADEON_CP_VC_FRMT_W0|RADEON_CP_VC_FRMT_Z)
736 #define ACTIVE_NORM RADEON_CP_VC_FRMT_N0
737
738 #define ACTIVE_PKCOLOR RADEON_CP_VC_FRMT_PKCOLOR
739 #define ACTIVE_FPCOLOR RADEON_CP_VC_FRMT_FPCOLOR
740 #define ACTIVE_FPALPHA RADEON_CP_VC_FRMT_FPALPHA
741 #define ACTIVE_COLOR (ACTIVE_FPCOLOR|ACTIVE_PKCOLOR)
742
743 #define ACTIVE_PKSPEC RADEON_CP_VC_FRMT_PKSPEC
744 #define ACTIVE_FPSPEC RADEON_CP_VC_FRMT_FPSPEC
745 #define ACTIVE_SPEC (ACTIVE_FPSPEC|ACTIVE_PKSPEC)
746
747 #define ACTIVE_ST0 RADEON_CP_VC_FRMT_ST0
748 #define ACTIVE_ST1 RADEON_CP_VC_FRMT_ST1
749 #define ACTIVE_ST2 RADEON_CP_VC_FRMT_ST2
750 #define ACTIVE_ST_ALL (RADEON_CP_VC_FRMT_ST1|RADEON_CP_VC_FRMT_ST0|RADEON_CP_VC_FRMT_ST2)
751
752 /* Each codegen function should be able to be fully specified by a
753 * subsetted version of rmesa->vb.vertex_format.
754 */
755 #define MASK_NORM (ACTIVE_XYZW)
756 #define MASK_COLOR (MASK_NORM|ACTIVE_NORM)
757 #define MASK_SPEC (MASK_COLOR|ACTIVE_COLOR)
758 #define MASK_ST0 (MASK_SPEC|ACTIVE_SPEC)
759 #define MASK_ST1 (MASK_ST0|ACTIVE_ST0)
760 #define MASK_ST2 (MASK_ST1|ACTIVE_ST1)
761 #define MASK_ST_ALL (MASK_ST2|ACTIVE_ST2)
762 #define MASK_VERTEX (MASK_ST_ALL|ACTIVE_FPALPHA)
763
764
765 typedef void (*p4f)( GLfloat, GLfloat, GLfloat, GLfloat );
766 typedef void (*p3f)( GLfloat, GLfloat, GLfloat );
767 typedef void (*p2f)( GLfloat, GLfloat );
768 typedef void (*p1f)( GLfloat );
769 typedef void (*pe2f)( GLenum, GLfloat, GLfloat );
770 typedef void (*pe1f)( GLenum, GLfloat );
771 typedef void (*p4ub)( GLubyte, GLubyte, GLubyte, GLubyte );
772 typedef void (*p3ub)( GLubyte, GLubyte, GLubyte );
773 typedef void (*pfv)( const GLfloat * );
774 typedef void (*pefv)( GLenum, const GLfloat * );
775 typedef void (*pubv)( const GLubyte * );
776
777
778 CHOOSE(Normal3f, p3f, MASK_NORM, ACTIVE_NORM,
779 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
780 CHOOSE(Normal3fv, pfv, MASK_NORM, ACTIVE_NORM,
781 (const GLfloat *v), (v))
782
783 #if 0
784 CHOOSE_COLOR(Color4ub, p4ub, 4, MASK_COLOR, ACTIVE_COLOR,
785 (GLubyte a,GLubyte b, GLubyte c, GLubyte d), (a,b,c,d))
786 CHOOSE_COLOR(Color4ubv, pubv, 4, MASK_COLOR, ACTIVE_COLOR,
787 (const GLubyte *v), (v))
788 CHOOSE_COLOR(Color3ub, p3ub, 3, MASK_COLOR, ACTIVE_COLOR,
789 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
790 CHOOSE_COLOR(Color3ubv, pubv, 3, MASK_COLOR, ACTIVE_COLOR,
791 (const GLubyte *v), (v))
792 #endif
793
794 CHOOSE_COLOR(Color4f, p4f, 4, MASK_COLOR, ACTIVE_COLOR,
795 (GLfloat a,GLfloat b, GLfloat c, GLfloat d), (a,b,c,d))
796 CHOOSE_COLOR(Color4fv, pfv, 4, MASK_COLOR, ACTIVE_COLOR,
797 (const GLfloat *v), (v))
798 CHOOSE_COLOR(Color3f, p3f, 3, MASK_COLOR, ACTIVE_COLOR,
799 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
800 CHOOSE_COLOR(Color3fv, pfv, 3, MASK_COLOR, ACTIVE_COLOR,
801 (const GLfloat *v), (v))
802
803
804 #if 0
805 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubEXT, p3ub, MASK_SPEC, ACTIVE_SPEC,
806 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
807 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubvEXT, pubv, MASK_SPEC, ACTIVE_SPEC,
808 (const GLubyte *v), (v))
809 #endif
810 CHOOSE_SECONDARY_COLOR(SecondaryColor3fEXT, p3f, MASK_SPEC, ACTIVE_SPEC,
811 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
812 CHOOSE_SECONDARY_COLOR(SecondaryColor3fvEXT, pfv, MASK_SPEC, ACTIVE_SPEC,
813 (const GLfloat *v), (v))
814
815 CHOOSE(TexCoord2f, p2f, MASK_ST0, ACTIVE_ST0,
816 (GLfloat a,GLfloat b), (a,b))
817 CHOOSE(TexCoord2fv, pfv, MASK_ST0, ACTIVE_ST0,
818 (const GLfloat *v), (v))
819 CHOOSE(TexCoord1f, p1f, MASK_ST0, ACTIVE_ST0,
820 (GLfloat a), (a))
821 CHOOSE(TexCoord1fv, pfv, MASK_ST0, ACTIVE_ST0,
822 (const GLfloat *v), (v))
823
824 CHOOSE(MultiTexCoord2fARB, pe2f, MASK_ST_ALL, ACTIVE_ST_ALL,
825 (GLenum u,GLfloat a,GLfloat b), (u,a,b))
826 CHOOSE(MultiTexCoord2fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
827 (GLenum u,const GLfloat *v), (u,v))
828 CHOOSE(MultiTexCoord1fARB, pe1f, MASK_ST_ALL, ACTIVE_ST_ALL,
829 (GLenum u,GLfloat a), (u,a))
830 CHOOSE(MultiTexCoord1fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
831 (GLenum u,const GLfloat *v), (u,v))
832
833 CHOOSE(Vertex3f, p3f, MASK_VERTEX, MASK_VERTEX,
834 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
835 CHOOSE(Vertex3fv, pfv, MASK_VERTEX, MASK_VERTEX,
836 (const GLfloat *v), (v))
837 CHOOSE(Vertex2f, p2f, MASK_VERTEX, MASK_VERTEX,
838 (GLfloat a,GLfloat b), (a,b))
839 CHOOSE(Vertex2fv, pfv, MASK_VERTEX, MASK_VERTEX,
840 (const GLfloat *v), (v))
841
842
843
844
845
846 void radeonVtxfmtInitChoosers( GLvertexformat *vfmt )
847 {
848 vfmt->Color3f = choose_Color3f;
849 vfmt->Color3fv = choose_Color3fv;
850 vfmt->Color4f = choose_Color4f;
851 vfmt->Color4fv = choose_Color4fv;
852 vfmt->SecondaryColor3fEXT = choose_SecondaryColor3fEXT;
853 vfmt->SecondaryColor3fvEXT = choose_SecondaryColor3fvEXT;
854 vfmt->MultiTexCoord1fARB = choose_MultiTexCoord1fARB;
855 vfmt->MultiTexCoord1fvARB = choose_MultiTexCoord1fvARB;
856 vfmt->MultiTexCoord2fARB = choose_MultiTexCoord2fARB;
857 vfmt->MultiTexCoord2fvARB = choose_MultiTexCoord2fvARB;
858 vfmt->Normal3f = choose_Normal3f;
859 vfmt->Normal3fv = choose_Normal3fv;
860 vfmt->TexCoord1f = choose_TexCoord1f;
861 vfmt->TexCoord1fv = choose_TexCoord1fv;
862 vfmt->TexCoord2f = choose_TexCoord2f;
863 vfmt->TexCoord2fv = choose_TexCoord2fv;
864 vfmt->Vertex2f = choose_Vertex2f;
865 vfmt->Vertex2fv = choose_Vertex2fv;
866 vfmt->Vertex3f = choose_Vertex3f;
867 vfmt->Vertex3fv = choose_Vertex3fv;
868
869 #if 0
870 vfmt->Color3ub = choose_Color3ub;
871 vfmt->Color3ubv = choose_Color3ubv;
872 vfmt->Color4ub = choose_Color4ub;
873 vfmt->Color4ubv = choose_Color4ubv;
874 vfmt->SecondaryColor3ubEXT = choose_SecondaryColor3ubEXT;
875 vfmt->SecondaryColor3ubvEXT = choose_SecondaryColor3ubvEXT;
876 #endif
877 }
878
879
880 static struct dynfn *codegen_noop( GLcontext *ctx, int key )
881 {
882 (void) ctx; (void) key;
883 return NULL;
884 }
885
886 void radeonInitCodegen( struct dfn_generators *gen, GLboolean useCodegen )
887 {
888 gen->Vertex3f = codegen_noop;
889 gen->Vertex3fv = codegen_noop;
890 gen->Color4ub = codegen_noop;
891 gen->Color4ubv = codegen_noop;
892 gen->Normal3f = codegen_noop;
893 gen->Normal3fv = codegen_noop;
894 gen->TexCoord2f = codegen_noop;
895 gen->TexCoord2fv = codegen_noop;
896 gen->MultiTexCoord2fARB = codegen_noop;
897 gen->MultiTexCoord2fvARB = codegen_noop;
898 gen->Vertex2f = codegen_noop;
899 gen->Vertex2fv = codegen_noop;
900 gen->Color3ub = codegen_noop;
901 gen->Color3ubv = codegen_noop;
902 gen->Color4f = codegen_noop;
903 gen->Color4fv = codegen_noop;
904 gen->Color3f = codegen_noop;
905 gen->Color3fv = codegen_noop;
906 gen->SecondaryColor3fEXT = codegen_noop;
907 gen->SecondaryColor3fvEXT = codegen_noop;
908 gen->SecondaryColor3ubEXT = codegen_noop;
909 gen->SecondaryColor3ubvEXT = codegen_noop;
910 gen->TexCoord1f = codegen_noop;
911 gen->TexCoord1fv = codegen_noop;
912 gen->MultiTexCoord1fARB = codegen_noop;
913 gen->MultiTexCoord1fvARB = codegen_noop;
914
915 if (useCodegen) {
916 #if defined(USE_X86_ASM)
917 radeonInitX86Codegen( gen );
918 #endif
919
920 #if defined(USE_SSE_ASM)
921 radeonInitSSECodegen( gen );
922 #endif
923 }
924 }