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 /**************************************************************************
4 Copyright 2002 ATI Technologies Inc., Ontario, Canada, and
5 Tungsten Graphics Inc., Cedar Park, Texas.
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:
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.
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.
29 **************************************************************************/
33 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "simple_list.h"
42 #include "radeon_vtxfmt.h"
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.
50 static void radeon_Vertex3f( GLfloat x
, GLfloat y
, GLfloat z
)
52 GET_CURRENT_CONTEXT(ctx
);
53 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
56 *rmesa
->vb
.dmaptr
++ = *(int *)&x
;
57 *rmesa
->vb
.dmaptr
++ = *(int *)&y
;
58 *rmesa
->vb
.dmaptr
++ = *(int *)&z
;
60 for (i
= 3; i
< rmesa
->vb
.vertex_size
; i
++)
61 *rmesa
->vb
.dmaptr
++ = rmesa
->vb
.vertex
[i
].i
;
63 if (--rmesa
->vb
.counter
== 0)
68 static void radeon_Vertex3fv( const GLfloat
*v
)
70 GET_CURRENT_CONTEXT(ctx
);
71 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
74 *rmesa
->vb
.dmaptr
++ = *(int *)&v
[0];
75 *rmesa
->vb
.dmaptr
++ = *(int *)&v
[1];
76 *rmesa
->vb
.dmaptr
++ = *(int *)&v
[2];
78 for (i
= 3; i
< rmesa
->vb
.vertex_size
; i
++)
79 *rmesa
->vb
.dmaptr
++ = rmesa
->vb
.vertex
[i
].i
;
81 if (--rmesa
->vb
.counter
== 0)
86 static void radeon_Vertex2f( GLfloat x
, GLfloat y
)
88 GET_CURRENT_CONTEXT(ctx
);
89 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
92 *rmesa
->vb
.dmaptr
++ = *(int *)&x
;
93 *rmesa
->vb
.dmaptr
++ = *(int *)&y
;
94 *rmesa
->vb
.dmaptr
++ = 0;
96 for (i
= 3; i
< rmesa
->vb
.vertex_size
; i
++)
97 *rmesa
->vb
.dmaptr
++ = *(int *)&rmesa
->vb
.vertex
[i
];
99 if (--rmesa
->vb
.counter
== 0)
104 static void radeon_Vertex2fv( const GLfloat
*v
)
106 GET_CURRENT_CONTEXT(ctx
);
107 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
110 *rmesa
->vb
.dmaptr
++ = *(int *)&v
[0];
111 *rmesa
->vb
.dmaptr
++ = *(int *)&v
[1];
112 *rmesa
->vb
.dmaptr
++ = 0;
114 for (i
= 3; i
< rmesa
->vb
.vertex_size
; i
++)
115 *rmesa
->vb
.dmaptr
++ = rmesa
->vb
.vertex
[i
].i
;
117 if (--rmesa
->vb
.counter
== 0)
123 /* Color for ubyte (packed) color formats:
125 static void radeon_Color3ub_ub( GLubyte r
, GLubyte g
, GLubyte b
)
127 GET_CURRENT_CONTEXT(ctx
);
128 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
129 radeon_color_t
*dest
= rmesa
->vb
.colorptr
;
136 static void radeon_Color3ubv_ub( const GLubyte
*v
)
138 GET_CURRENT_CONTEXT(ctx
);
139 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
140 radeon_color_t
*dest
= rmesa
->vb
.colorptr
;
147 static void radeon_Color4ub_ub( GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
149 GET_CURRENT_CONTEXT(ctx
);
150 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
151 radeon_color_t
*dest
= rmesa
->vb
.colorptr
;
158 static void radeon_Color4ubv_ub( const GLubyte
*v
)
160 GET_CURRENT_CONTEXT(ctx
);
161 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
162 *(GLuint
*)rmesa
->vb
.colorptr
= LE32_TO_CPU(*(GLuint
*)v
);
166 static void radeon_Color3f_ub( GLfloat r
, GLfloat g
, GLfloat b
)
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
);
177 static void radeon_Color3fv_ub( const GLfloat
*v
)
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] );
188 static void radeon_Color4f_ub( GLfloat r
, GLfloat g
, GLfloat b
, GLfloat a
)
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
);
199 static void radeon_Color4fv_ub( const GLfloat
*v
)
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] );
211 /* Color for float color+alpha formats:
214 static void radeon_Color3ub_4f( GLubyte r
, GLubyte g
, GLubyte b
)
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
);
225 static void radeon_Color3ubv_4f( const GLubyte
*v
)
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]);
236 static void radeon_Color4ub_4f( GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
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
);
247 static void radeon_Color4ubv_4f( const GLubyte
*v
)
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]);
260 static void radeon_Color3f_4f( GLfloat r
, GLfloat g
, GLfloat b
)
262 GET_CURRENT_CONTEXT(ctx
);
263 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
264 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
271 static void radeon_Color3fv_4f( const GLfloat
*v
)
273 GET_CURRENT_CONTEXT(ctx
);
274 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
275 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
282 static void radeon_Color4f_4f( GLfloat r
, GLfloat g
, GLfloat b
, GLfloat a
)
284 GET_CURRENT_CONTEXT(ctx
);
285 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
286 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
293 static void radeon_Color4fv_4f( const GLfloat
*v
)
295 GET_CURRENT_CONTEXT(ctx
);
296 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
297 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
305 /* Color for float color formats:
308 static void radeon_Color3ub_3f( GLubyte r
, GLubyte g
, GLubyte b
)
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
);
318 static void radeon_Color3ubv_3f( const GLubyte
*v
)
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]);
328 static void radeon_Color4ub_3f( GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
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
);
339 static void radeon_Color4ubv_3f( const GLubyte
*v
)
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]);
352 static void radeon_Color3f_3f( GLfloat r
, GLfloat g
, GLfloat b
)
354 GET_CURRENT_CONTEXT(ctx
);
355 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
356 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
362 static void radeon_Color3fv_3f( const GLfloat
*v
)
364 GET_CURRENT_CONTEXT(ctx
);
365 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
366 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
372 static void radeon_Color4f_3f( GLfloat r
, GLfloat g
, GLfloat b
, GLfloat a
)
374 GET_CURRENT_CONTEXT(ctx
);
375 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
376 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
380 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][3] = a
;
383 static void radeon_Color4fv_3f( const GLfloat
*v
)
385 GET_CURRENT_CONTEXT(ctx
);
386 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
387 GLfloat
*dest
= rmesa
->vb
.floatcolorptr
;
391 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
][3] = v
[3];
398 static void radeon_SecondaryColor3ubEXT_ub( GLubyte r
, GLubyte g
, GLubyte b
)
400 GET_CURRENT_CONTEXT(ctx
);
401 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
402 radeon_color_t
*dest
= rmesa
->vb
.specptr
;
409 static void radeon_SecondaryColor3ubvEXT_ub( const GLubyte
*v
)
411 GET_CURRENT_CONTEXT(ctx
);
412 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
413 radeon_color_t
*dest
= rmesa
->vb
.specptr
;
421 static void radeon_SecondaryColor3fEXT_ub( GLfloat r
, GLfloat g
, GLfloat b
)
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
);
432 static void radeon_SecondaryColor3fvEXT_ub( const GLfloat
*v
)
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] );
444 static void radeon_SecondaryColor3ubEXT_3f( GLubyte r
, GLubyte g
, GLubyte b
)
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
);
455 static void radeon_SecondaryColor3ubvEXT_3f( const GLubyte
*v
)
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]);
467 static void radeon_SecondaryColor3fEXT_3f( GLfloat r
, GLfloat g
, GLfloat b
)
469 GET_CURRENT_CONTEXT(ctx
);
470 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
471 GLfloat
*dest
= rmesa
->vb
.floatspecptr
;
478 static void radeon_SecondaryColor3fvEXT_3f( const GLfloat
*v
)
480 GET_CURRENT_CONTEXT(ctx
);
481 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
482 GLfloat
*dest
= rmesa
->vb
.floatspecptr
;
492 static void radeon_Normal3f( GLfloat n0
, GLfloat n1
, GLfloat n2
)
494 GET_CURRENT_CONTEXT(ctx
);
495 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
496 GLfloat
*dest
= rmesa
->vb
.normalptr
;
502 static void radeon_Normal3fv( const GLfloat
*v
)
504 GET_CURRENT_CONTEXT(ctx
);
505 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
506 GLfloat
*dest
= rmesa
->vb
.normalptr
;
515 static void radeon_TexCoord1f( GLfloat s
)
517 GET_CURRENT_CONTEXT(ctx
);
518 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
519 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[0];
524 static void radeon_TexCoord1fv( const GLfloat
*v
)
526 GET_CURRENT_CONTEXT(ctx
);
527 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
528 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[0];
533 static void radeon_TexCoord2f( GLfloat s
, GLfloat t
)
535 GET_CURRENT_CONTEXT(ctx
);
536 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
537 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[0];
542 static void radeon_TexCoord2fv( const GLfloat
*v
)
544 GET_CURRENT_CONTEXT(ctx
);
545 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
546 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[0];
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.
562 static void radeon_MultiTexCoord1fARB( GLenum target
, GLfloat s
)
564 GET_CURRENT_CONTEXT(ctx
);
565 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
566 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[target
& 3];
571 static void radeon_MultiTexCoord1fvARB( GLenum target
, const GLfloat
*v
)
573 GET_CURRENT_CONTEXT(ctx
);
574 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
575 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[target
& 3];
580 static void radeon_MultiTexCoord2fARB( GLenum target
, GLfloat s
, GLfloat t
)
582 GET_CURRENT_CONTEXT(ctx
);
583 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
584 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[target
& 3];
589 static void radeon_MultiTexCoord2fvARB( GLenum target
, const GLfloat
*v
)
591 GET_CURRENT_CONTEXT(ctx
);
592 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
593 GLfloat
*dest
= rmesa
->vb
.texcoordptr
[target
& 3];
598 static struct dynfn
*lookup( struct dynfn
*l
, int key
)
610 /* Can't use the loopback template for this:
613 #define CHOOSE(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
614 static void choose_##FN ARGS1 \
616 GET_CURRENT_CONTEXT(ctx); \
617 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
618 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
621 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
623 dfn = rmesa->vb.codegen.FN( ctx, key ); \
624 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
625 fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ ); \
628 SET_ ## FN (ctx->Exec, (FNTYPE)(dfn->code)); \
630 if (RADEON_DEBUG & DEBUG_CODEGEN) \
631 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
632 SET_ ## FN (ctx->Exec, radeon_##FN); \
635 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
636 CALL_ ## FN (ctx->Exec, ARGS2); \
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.
645 * Note: Perform these actions even if there is a codegen or cached
646 * codegen version of the chosen function.
648 #define CHOOSE_COLOR(FN, FNTYPE, NR, MASK, ACTIVE, ARGS1, ARGS2 ) \
649 static void choose_##FN ARGS1 \
651 GET_CURRENT_CONTEXT(ctx); \
652 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
653 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
656 if (rmesa->vb.vertex_format & ACTIVE_PKCOLOR) { \
657 SET_ ## FN (ctx->Exec, radeon_##FN##_ub); \
659 else if ((rmesa->vb.vertex_format & \
660 (ACTIVE_FPCOLOR|ACTIVE_FPALPHA)) == ACTIVE_FPCOLOR) { \
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); \
673 SET_ ## FN (ctx->Exec, radeon_##FN##_3f); \
676 SET_ ## FN (ctx->Exec, radeon_##FN##_4f); \
680 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
681 if (!dfn) dfn = rmesa->vb.codegen.FN( ctx, key ); \
684 if (RADEON_DEBUG & DEBUG_CODEGEN) \
685 fprintf(stderr, "%s -- codegen version\n", __FUNCTION__ ); \
686 SET_ ## FN (ctx->Exec, (FNTYPE)dfn->code); \
688 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
689 fprintf(stderr, "%s -- 'c' version\n", __FUNCTION__ ); \
691 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
692 CALL_ ## FN (ctx->Exec, ARGS2); \
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
703 #define CHOOSE_SECONDARY_COLOR(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
704 static void choose_##FN ARGS1 \
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 ); \
712 dfn = rmesa->vb.codegen.FN( ctx, key ); \
713 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
714 fprintf(stderr, "%s -- cached version\n", __FUNCTION__ ); \
717 SET_ ## FN (ctx->Exec, (FNTYPE)(dfn->code)); \
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); \
725 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
726 CALL_ ## FN (ctx->Exec, ARGS2); \
735 #define ACTIVE_XYZW (RADEON_CP_VC_FRMT_W0|RADEON_CP_VC_FRMT_Z)
736 #define ACTIVE_NORM RADEON_CP_VC_FRMT_N0
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)
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)
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)
752 /* Each codegen function should be able to be fully specified by a
753 * subsetted version of rmesa->vb.vertex_format.
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)
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
* );
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
))
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
))
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
))
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
))
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
))
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
,
821 CHOOSE(TexCoord1fv
, pfv
, MASK_ST0
, ACTIVE_ST0
,
822 (const GLfloat
*v
), (v
))
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
))
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
))
846 void radeonVtxfmtInitChoosers( GLvertexformat
*vfmt
)
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
;
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
;
880 static struct dynfn
*codegen_noop( GLcontext
*ctx
, int key
)
882 (void) ctx
; (void) key
;
886 void radeonInitCodegen( struct dfn_generators
*gen
, GLboolean useCodegen
)
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
;
916 #if defined(USE_X86_ASM)
917 radeonInitX86Codegen( gen
);
920 #if defined(USE_SSE_ASM)
921 radeonInitSSECodegen( gen
);