1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_vtxfmt_x86.c,v 1.2 2002/12/16 16:18:56 dawes Exp $ */
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
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.
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"
39 #include "r200_vtxfmt.h"
41 #if defined(USE_X86_ASM)
43 #define EXTERN( FUNC ) \
44 extern const char *FUNC; \
45 extern const char *FUNC##_end
47 EXTERN ( _x86_Attribute2fv
);
48 EXTERN ( _x86_Attribute2f
);
49 EXTERN ( _x86_Attribute3fv
);
50 EXTERN ( _x86_Attribute3f
);
51 EXTERN ( _x86_Vertex3fv_6
);
52 EXTERN ( _x86_Vertex3fv_8
);
53 EXTERN ( _x86_Vertex3fv
);
54 EXTERN ( _x86_Vertex3f_4
);
55 EXTERN ( _x86_Vertex3f_6
);
56 EXTERN ( _x86_Vertex3f
);
57 EXTERN ( _x86_Color4ubv_ub
);
58 EXTERN ( _x86_Color4ubv_4f
);
59 EXTERN ( _x86_Color4ub_ub
);
60 EXTERN ( _x86_MultiTexCoord2fv
);
61 EXTERN ( _x86_MultiTexCoord2fv_2
);
62 EXTERN ( _x86_MultiTexCoord2f
);
63 EXTERN ( _x86_MultiTexCoord2f_2
);
66 /* Build specialized versions of the immediate calls on the fly for
67 * the current state. Generic x86 versions.
70 struct dynfn
*r200_makeX86Vertex3f( GLcontext
*ctx
, const int *key
)
72 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
73 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
75 if (R200_DEBUG
& DEBUG_CODEGEN
)
76 fprintf(stderr
, "%s 0x%08x 0x%08x %d\n", __FUNCTION__
,
77 key
[0], key
[1], rmesa
->vb
.vertex_size
);
79 switch (rmesa
->vb
.vertex_size
) {
82 DFN ( _x86_Vertex3f_4
, rmesa
->vb
.dfn_cache
.Vertex3f
);
83 FIXUP(dfn
->code
, 2, 0x0, (int)&rmesa
->vb
.dmaptr
);
84 FIXUP(dfn
->code
, 25, 0x0, (int)&rmesa
->vb
.vertex
[3]);
85 FIXUP(dfn
->code
, 36, 0x0, (int)&rmesa
->vb
.counter
);
86 FIXUP(dfn
->code
, 46, 0x0, (int)&rmesa
->vb
.dmaptr
);
87 FIXUP(dfn
->code
, 51, 0x0, (int)&rmesa
->vb
.counter
);
88 FIXUP(dfn
->code
, 60, 0x0, (int)&rmesa
->vb
.notify
);
93 DFN ( _x86_Vertex3f_6
, rmesa
->vb
.dfn_cache
.Vertex3f
);
94 FIXUP(dfn
->code
, 3, 0x0, (int)&rmesa
->vb
.dmaptr
);
95 FIXUP(dfn
->code
, 28, 0x0, (int)&rmesa
->vb
.vertex
[3]);
96 FIXUP(dfn
->code
, 34, 0x0, (int)&rmesa
->vb
.vertex
[4]);
97 FIXUP(dfn
->code
, 40, 0x0, (int)&rmesa
->vb
.vertex
[5]);
98 FIXUP(dfn
->code
, 57, 0x0, (int)&rmesa
->vb
.counter
);
99 FIXUP(dfn
->code
, 63, 0x0, (int)&rmesa
->vb
.dmaptr
);
100 FIXUP(dfn
->code
, 70, 0x0, (int)&rmesa
->vb
.counter
);
101 FIXUP(dfn
->code
, 79, 0x0, (int)&rmesa
->vb
.notify
);
106 DFN ( _x86_Vertex3f
, rmesa
->vb
.dfn_cache
.Vertex3f
);
107 FIXUP(dfn
->code
, 3, 0x0, (int)&rmesa
->vb
.vertex
[3]);
108 FIXUP(dfn
->code
, 9, 0x0, (int)&rmesa
->vb
.dmaptr
);
109 FIXUP(dfn
->code
, 37, 0x0, rmesa
->vb
.vertex_size
-3);
110 FIXUP(dfn
->code
, 44, 0x0, (int)&rmesa
->vb
.counter
);
111 FIXUP(dfn
->code
, 50, 0x0, (int)&rmesa
->vb
.dmaptr
);
112 FIXUP(dfn
->code
, 56, 0x0, (int)&rmesa
->vb
.counter
);
113 FIXUP(dfn
->code
, 67, 0x0, (int)&rmesa
->vb
.notify
);
123 struct dynfn
*r200_makeX86Vertex3fv( GLcontext
*ctx
, const int *key
)
125 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
126 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
128 if (R200_DEBUG
& DEBUG_CODEGEN
)
129 fprintf(stderr
, "%s 0x%08x 0x%08x %d\n", __FUNCTION__
,
130 key
[0], key
[1], rmesa
->vb
.vertex_size
);
132 switch (rmesa
->vb
.vertex_size
) {
135 DFN ( _x86_Vertex3fv_6
, rmesa
->vb
.dfn_cache
.Vertex3fv
);
136 FIXUP(dfn
->code
, 1, 0x00000000, (int)&rmesa
->vb
.dmaptr
);
137 FIXUP(dfn
->code
, 27, 0x0000001c, (int)&rmesa
->vb
.vertex
[3]);
138 FIXUP(dfn
->code
, 33, 0x00000020, (int)&rmesa
->vb
.vertex
[4]);
139 FIXUP(dfn
->code
, 45, 0x00000024, (int)&rmesa
->vb
.vertex
[5]);
140 FIXUP(dfn
->code
, 56, 0x00000000, (int)&rmesa
->vb
.dmaptr
);
141 FIXUP(dfn
->code
, 61, 0x00000004, (int)&rmesa
->vb
.counter
);
142 FIXUP(dfn
->code
, 67, 0x00000004, (int)&rmesa
->vb
.counter
);
143 FIXUP(dfn
->code
, 76, 0x00000008, (int)&rmesa
->vb
.notify
);
150 DFN ( _x86_Vertex3fv_8
, rmesa
->vb
.dfn_cache
.Vertex3fv
);
151 FIXUP(dfn
->code
, 1, 0x00000000, (int)&rmesa
->vb
.dmaptr
);
152 FIXUP(dfn
->code
, 27, 0x0000001c, (int)&rmesa
->vb
.vertex
[3]);
153 FIXUP(dfn
->code
, 33, 0x00000020, (int)&rmesa
->vb
.vertex
[4]);
154 FIXUP(dfn
->code
, 45, 0x0000001c, (int)&rmesa
->vb
.vertex
[5]);
155 FIXUP(dfn
->code
, 51, 0x00000020, (int)&rmesa
->vb
.vertex
[6]);
156 FIXUP(dfn
->code
, 63, 0x00000024, (int)&rmesa
->vb
.vertex
[7]);
157 FIXUP(dfn
->code
, 74, 0x00000000, (int)&rmesa
->vb
.dmaptr
);
158 FIXUP(dfn
->code
, 79, 0x00000004, (int)&rmesa
->vb
.counter
);
159 FIXUP(dfn
->code
, 85, 0x00000004, (int)&rmesa
->vb
.counter
);
160 FIXUP(dfn
->code
, 94, 0x00000008, (int)&rmesa
->vb
.notify
);
168 DFN ( _x86_Vertex3fv
, rmesa
->vb
.dfn_cache
.Vertex3fv
);
169 FIXUP(dfn
->code
, 8, 0x01010101, (int)&rmesa
->vb
.dmaptr
);
170 FIXUP(dfn
->code
, 32, 0x00000006, rmesa
->vb
.vertex_size
-3);
171 FIXUP(dfn
->code
, 37, 0x00000058, (int)&rmesa
->vb
.vertex
[3]);
172 FIXUP(dfn
->code
, 45, 0x01010101, (int)&rmesa
->vb
.dmaptr
);
173 FIXUP(dfn
->code
, 50, 0x02020202, (int)&rmesa
->vb
.counter
);
174 FIXUP(dfn
->code
, 58, 0x02020202, (int)&rmesa
->vb
.counter
);
175 FIXUP(dfn
->code
, 67, 0x0, (int)&rmesa
->vb
.notify
);
183 static struct dynfn
*
184 r200_makeX86Attribute2fv( struct dynfn
* cache
, const int *key
,
185 const char * name
, void * dest
)
187 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
189 if (R200_DEBUG
& DEBUG_CODEGEN
)
190 fprintf(stderr
, "%s 0x%08x\n", name
, key
[0] );
192 DFN ( _x86_Attribute2fv
, (*cache
) );
193 FIXUP(dfn
->code
, 11, 0x0, (int)dest
);
194 FIXUP(dfn
->code
, 16, 0x4, 4+(int)dest
);
199 static struct dynfn
*
200 r200_makeX86Attribute2f( struct dynfn
* cache
, const int *key
,
201 const char * name
, void * dest
)
203 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
205 if (R200_DEBUG
& DEBUG_CODEGEN
)
206 fprintf(stderr
, "%s 0x%08x\n", name
, key
[0] );
208 DFN ( _x86_Attribute2f
, (*cache
) );
209 FIXUP(dfn
->code
, 1, 0x0, (int)dest
);
215 static struct dynfn
*
216 r200_makeX86Attribute3fv( struct dynfn
* cache
, const int *key
,
217 const char * name
, void * dest
)
219 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
221 if (R200_DEBUG
& DEBUG_CODEGEN
)
222 fprintf(stderr
, "%s 0x%08x\n", name
, key
[0] );
224 DFN ( _x86_Attribute3fv
, (*cache
) );
225 FIXUP(dfn
->code
, 14, 0x0, (int)dest
);
226 FIXUP(dfn
->code
, 20, 0x4, 4+(int)dest
);
227 FIXUP(dfn
->code
, 25, 0x8, 8+(int)dest
);
232 static struct dynfn
*
233 r200_makeX86Attribute3f( struct dynfn
* cache
, const int *key
,
234 const char * name
, void * dest
)
236 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
238 if (R200_DEBUG
& DEBUG_CODEGEN
)
239 fprintf(stderr
, "%s 0x%08x\n", name
, key
[0] );
241 DFN ( _x86_Attribute3f
, (*cache
) );
242 FIXUP(dfn
->code
, 14, 0x0, (int)dest
);
243 FIXUP(dfn
->code
, 20, 0x4, 4+(int)dest
);
244 FIXUP(dfn
->code
, 25, 0x8, 8+(int)dest
);
249 struct dynfn
*r200_makeX86Normal3fv( GLcontext
*ctx
, const int *key
)
251 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
253 return r200_makeX86Attribute3fv( & rmesa
->vb
.dfn_cache
.Normal3fv
, key
,
254 __FUNCTION__
, rmesa
->vb
.normalptr
);
257 struct dynfn
*r200_makeX86Normal3f( GLcontext
*ctx
, const int *key
)
259 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
261 return r200_makeX86Attribute3f( & rmesa
->vb
.dfn_cache
.Normal3f
, key
,
262 __FUNCTION__
, rmesa
->vb
.normalptr
);
265 struct dynfn
*r200_makeX86Color4ubv( GLcontext
*ctx
, const int *key
)
267 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
268 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
271 if (R200_DEBUG
& DEBUG_CODEGEN
)
272 fprintf(stderr
, "%s 0x%08x\n", __FUNCTION__
, key
[0] );
274 if (VTX_COLOR(key
[0],0) == R200_VTX_PK_RGBA
) {
275 DFN ( _x86_Color4ubv_ub
, rmesa
->vb
.dfn_cache
.Color4ubv
);
276 FIXUP(dfn
->code
, 5, 0x12345678, (int)rmesa
->vb
.colorptr
);
281 DFN ( _x86_Color4ubv_4f
, rmesa
->vb
.dfn_cache
.Color4ubv
);
282 FIXUP(dfn
->code
, 2, 0x00000000, (int)_mesa_ubyte_to_float_color_tab
);
283 FIXUP(dfn
->code
, 27, 0xdeadbeaf, (int)rmesa
->vb
.floatcolorptr
);
284 FIXUP(dfn
->code
, 33, 0xdeadbeaf, (int)rmesa
->vb
.floatcolorptr
+4);
285 FIXUP(dfn
->code
, 55, 0xdeadbeaf, (int)rmesa
->vb
.floatcolorptr
+8);
286 FIXUP(dfn
->code
, 61, 0xdeadbeaf, (int)rmesa
->vb
.floatcolorptr
+12);
291 struct dynfn
*r200_makeX86Color4ub( GLcontext
*ctx
, const int *key
)
293 if (R200_DEBUG
& DEBUG_CODEGEN
)
294 fprintf(stderr
, "%s 0x%08x\n", __FUNCTION__
, key
[0] );
296 if (VTX_COLOR(key
[0],0) == R200_VTX_PK_RGBA
) {
297 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
298 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
300 DFN ( _x86_Color4ub_ub
, rmesa
->vb
.dfn_cache
.Color4ub
);
301 FIXUP(dfn
->code
, 18, 0x0, (int)rmesa
->vb
.colorptr
);
302 FIXUP(dfn
->code
, 24, 0x0, (int)rmesa
->vb
.colorptr
+1);
303 FIXUP(dfn
->code
, 30, 0x0, (int)rmesa
->vb
.colorptr
+2);
304 FIXUP(dfn
->code
, 36, 0x0, (int)rmesa
->vb
.colorptr
+3);
312 struct dynfn
*r200_makeX86Color3fv( GLcontext
*ctx
, const int *key
)
314 if (VTX_COLOR(key
[0],0) != R200_VTX_FP_RGB
)
318 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
320 return r200_makeX86Attribute3fv( & rmesa
->vb
.dfn_cache
.Color3fv
, key
,
321 __FUNCTION__
, rmesa
->vb
.floatcolorptr
);
325 struct dynfn
*r200_makeX86Color3f( GLcontext
*ctx
, const int *key
)
327 if (VTX_COLOR(key
[0],0) != R200_VTX_FP_RGB
)
331 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
333 return r200_makeX86Attribute3f( & rmesa
->vb
.dfn_cache
.Color3f
, key
,
334 __FUNCTION__
, rmesa
->vb
.floatcolorptr
);
340 #if 0 /* Temporarily disabled as it is broken w/the new cubemap code. - idr */
341 struct dynfn
*r200_makeX86TexCoord2fv( GLcontext
*ctx
, const int *key
)
343 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
345 return r200_makeX86Attribute2fv( & rmesa
->vb
.dfn_cache
.TexCoord2fv
, key
,
346 __FUNCTION__
, rmesa
->vb
.texcoordptr
[0] );
349 struct dynfn
*r200_makeX86TexCoord2f( GLcontext
*ctx
, const int *key
)
351 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
353 return r200_makeX86Attribute2f( & rmesa
->vb
.dfn_cache
.TexCoord2f
, key
,
354 __FUNCTION__
, rmesa
->vb
.texcoordptr
[0] );
357 struct dynfn
*r200_makeX86MultiTexCoord2fvARB( GLcontext
*ctx
, const int *key
)
359 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
360 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
362 if (R200_DEBUG
& DEBUG_CODEGEN
)
363 fprintf(stderr
, "%s 0x%08x 0x%08x\n", __FUNCTION__
, key
[0], key
[1] );
365 if (rmesa
->vb
.texcoordptr
[1] == rmesa
->vb
.texcoordptr
[0]+4) {
366 DFN ( _x86_MultiTexCoord2fv
, rmesa
->vb
.dfn_cache
.MultiTexCoord2fvARB
);
367 FIXUP(dfn
->code
, 21, 0xdeadbeef, (int)rmesa
->vb
.texcoordptr
[0]);
368 FIXUP(dfn
->code
, 27, 0xdeadbeef, (int)rmesa
->vb
.texcoordptr
[0]+4);
370 DFN ( _x86_MultiTexCoord2fv_2
, rmesa
->vb
.dfn_cache
.MultiTexCoord2fvARB
);
371 FIXUP(dfn
->code
, 14, 0x0, (int)rmesa
->vb
.texcoordptr
);
376 struct dynfn
*r200_makeX86MultiTexCoord2fARB( GLcontext
*ctx
,
379 struct dynfn
*dfn
= MALLOC_STRUCT( dynfn
);
380 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
382 if (R200_DEBUG
& DEBUG_CODEGEN
)
383 fprintf(stderr
, "%s 0x%08x 0x%08x\n", __FUNCTION__
, key
[0], key
[1] );
385 if (rmesa
->vb
.texcoordptr
[1] == rmesa
->vb
.texcoordptr
[0]+4) {
386 DFN ( _x86_MultiTexCoord2f
, rmesa
->vb
.dfn_cache
.MultiTexCoord2fARB
);
387 FIXUP(dfn
->code
, 20, 0xdeadbeef, (int)rmesa
->vb
.texcoordptr
[0]);
388 FIXUP(dfn
->code
, 26, 0xdeadbeef, (int)rmesa
->vb
.texcoordptr
[0]+4);
391 /* Note: this might get generated multiple times, even though the
392 * actual emitted code is the same.
394 DFN ( _x86_MultiTexCoord2f_2
, rmesa
->vb
.dfn_cache
.MultiTexCoord2fARB
);
395 FIXUP(dfn
->code
, 18, 0x0, (int)rmesa
->vb
.texcoordptr
);
401 void r200InitX86Codegen( struct dfn_generators
*gen
)
403 gen
->Vertex3f
= r200_makeX86Vertex3f
;
404 gen
->Vertex3fv
= r200_makeX86Vertex3fv
;
405 gen
->Color4ub
= r200_makeX86Color4ub
; /* PKCOLOR only */
406 gen
->Color4ubv
= r200_makeX86Color4ubv
; /* PKCOLOR only */
407 gen
->Normal3f
= r200_makeX86Normal3f
;
408 gen
->Normal3fv
= r200_makeX86Normal3fv
;
409 #if 0 /* Temporarily disabled as it is broken w/the new cubemap code. - idr */
410 gen
->TexCoord2f
= r200_makeX86TexCoord2f
;
411 gen
->TexCoord2fv
= r200_makeX86TexCoord2fv
;
412 gen
->MultiTexCoord2fARB
= r200_makeX86MultiTexCoord2fARB
;
413 gen
->MultiTexCoord2fvARB
= r200_makeX86MultiTexCoord2fvARB
;
415 gen
->Color3f
= r200_makeX86Color3f
;
416 gen
->Color3fv
= r200_makeX86Color3fv
;
420 /* gen->Vertex2f = r200_makeX86Vertex2f; */
421 /* gen->Vertex2fv = r200_makeX86Vertex2fv; */
422 /* gen->Color3ub = r200_makeX86Color3ub; */
423 /* gen->Color3ubv = r200_makeX86Color3ubv; */
424 /* gen->Color4f = r200_makeX86Color4f; */
425 /* gen->Color4fv = r200_makeX86Color4fv; */
426 /* gen->TexCoord1f = r200_makeX86TexCoord1f; */
427 /* gen->TexCoord1fv = r200_makeX86TexCoord1fv; */
428 /* gen->MultiTexCoord1fARB = r200_makeX86MultiTexCoord1fARB; */
429 /* gen->MultiTexCoord1fvARB = r200_makeX86MultiTexCoord1fvARB; */
435 void r200InitX86Codegen( struct dfn_generators
*gen
)