mesa/main: fix gl_buffer_index enum comparison
[mesa.git] / src / mesa / x86 / gen_matypes.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Gareth Hughes
26 */
27
28 /*
29 * This generates an asm version of mtypes.h (called matypes.h), so that
30 * Mesa's x86 assembly code can access the internal structures easily.
31 * This will be particularly useful when developing new x86 asm code for
32 * Mesa, including lighting, clipping, texture image conversion etc.
33 */
34
35 #include <stdio.h>
36 #include <inttypes.h>
37
38 #include "main/glheader.h"
39 #include "main/mtypes.h"
40 #include "tnl/t_context.h"
41
42
43 #undef offsetof
44 #define offsetof( type, member ) ((size_t) &((type *)0)->member)
45
46
47 #define OFFSET_HEADER( x ) \
48 do { \
49 printf( "\n" ); \
50 printf( "\n" ); \
51 printf( "/* =====================================================" \
52 "========\n" ); \
53 printf( " * Offsets for " x "\n" ); \
54 printf( " */\n" ); \
55 printf( "\n" ); \
56 } while (0)
57
58 #define DEFINE_HEADER( x ) \
59 do { \
60 printf( "\n" ); \
61 printf( "/*\n" ); \
62 printf( " * Flags for " x "\n" ); \
63 printf( " */\n" ); \
64 printf( "\n" ); \
65 } while (0)
66
67 #ifdef ASM_OFFSETS
68
69 /*
70 * Format the asm output in a special way that we can manipulate
71 * after the fact and turn into the final header for the target.
72 */
73
74 #define DEFINE_UL( s, ul ) \
75 __asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
76
77 #define DEFINE( s, d ) \
78 DEFINE_UL( s, d )
79
80 #define printf( x ) \
81 __asm__ __volatile__ ( "\n->" x )
82
83 #else
84
85 #define DEFINE_UL( s, ul ) \
86 printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
87
88 #define DEFINE( s, d ) \
89 printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
90
91 #endif
92
93 #define OFFSET( s, t, m ) \
94 DEFINE_UL( s, offsetof( t, m ) )
95
96 #define SIZEOF( s, t ) \
97 DEFINE_UL( s, sizeof(t) )
98
99
100
101 int main( int argc, char **argv )
102 {
103 printf( "/*\n" );
104 printf( " * This file is automatically generated from the Mesa internal type\n" );
105 printf( " * definitions. Do not edit directly.\n" );
106 printf( " */\n" );
107 printf( "\n" );
108 printf( "#ifndef __ASM_TYPES_H__\n" );
109 printf( "#define __ASM_TYPES_H__\n" );
110 printf( "\n" );
111
112
113 /* struct gl_context offsets:
114 */
115 OFFSET_HEADER( "struct gl_context" );
116
117 printf( "\n" );
118 OFFSET( "CTX_LIGHT_ENABLED ", struct gl_context, Light.Enabled );
119 OFFSET( "CTX_LIGHT_SHADE_MODEL ", struct gl_context, Light.ShadeModel );
120 OFFSET( "CTX_LIGHT_COLOR_MAT_FACE ", struct gl_context, Light.ColorMaterialFace );
121 OFFSET( "CTX_LIGHT_COLOR_MAT_MODE ", struct gl_context, Light.ColorMaterialMode );
122 OFFSET( "CTX_LIGHT_COLOR_MAT_MASK ", struct gl_context, Light._ColorMaterialBitmask );
123 OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", struct gl_context, Light.ColorMaterialEnabled );
124 OFFSET( "CTX_LIGHT_ENABLED_LIGHTS ", struct gl_context, Light._EnabledLights );
125 OFFSET( "CTX_LIGHT_NEED_VERTS ", struct gl_context, Light._NeedVertices );
126 OFFSET( "CTX_LIGHT_BASE_COLOR ", struct gl_context, Light._BaseColor );
127
128
129 /* struct vertex_buffer offsets:
130 */
131 OFFSET_HEADER( "struct vertex_buffer" );
132
133 OFFSET( "VB_SIZE ", struct vertex_buffer, Size );
134 OFFSET( "VB_COUNT ", struct vertex_buffer, Count );
135 printf( "\n" );
136 OFFSET( "VB_ELTS ", struct vertex_buffer, Elts );
137 OFFSET( "VB_OBJ_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_POS] );
138 OFFSET( "VB_EYE_PTR ", struct vertex_buffer, EyePtr );
139 OFFSET( "VB_CLIP_PTR ", struct vertex_buffer, ClipPtr );
140 OFFSET( "VB_PROJ_CLIP_PTR ", struct vertex_buffer, NdcPtr );
141 OFFSET( "VB_CLIP_OR_MASK ", struct vertex_buffer, ClipOrMask );
142 OFFSET( "VB_CLIP_MASK ", struct vertex_buffer, ClipMask );
143 OFFSET( "VB_NORMAL_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_NORMAL] );
144 OFFSET( "VB_EDGE_FLAG ", struct vertex_buffer, EdgeFlag );
145 OFFSET( "VB_TEX0_COORD_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX0] );
146 OFFSET( "VB_TEX1_COORD_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX1] );
147 OFFSET( "VB_TEX2_COORD_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX2] );
148 OFFSET( "VB_TEX3_COORD_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_TEX3] );
149 OFFSET( "VB_INDEX_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR_INDEX] );
150 OFFSET( "VB_COLOR_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR0] );
151 OFFSET( "VB_SECONDARY_COLOR_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_COLOR1] );
152 OFFSET( "VB_FOG_COORD_PTR ", struct vertex_buffer, AttribPtr[_TNL_ATTRIB_FOG] );
153 OFFSET( "VB_PRIMITIVE ", struct vertex_buffer, Primitive );
154 printf( "\n" );
155
156 DEFINE_HEADER( "struct vertex_buffer" );
157
158 /* XXX use new labels here someday after vertex proram is done */
159 DEFINE( "VERT_BIT_OBJ ", VERT_BIT_POS );
160 DEFINE( "VERT_BIT_NORM ", VERT_BIT_NORMAL );
161 DEFINE( "VERT_BIT_RGBA ", VERT_BIT_COLOR0 );
162 DEFINE( "VERT_BIT_SPEC_RGB ", VERT_BIT_COLOR1 );
163 DEFINE( "VERT_BIT_FOG_COORD ", VERT_BIT_FOG );
164 DEFINE( "VERT_BIT_TEX0 ", VERT_BIT_TEX0 );
165 DEFINE( "VERT_BIT_TEX1 ", VERT_BIT_TEX1 );
166 DEFINE( "VERT_BIT_TEX2 ", VERT_BIT_TEX2 );
167 DEFINE( "VERT_BIT_TEX3 ", VERT_BIT_TEX3 );
168
169
170 /* GLvector4f offsets:
171 */
172 OFFSET_HEADER( "GLvector4f" );
173
174 OFFSET( "V4F_DATA ", GLvector4f, data );
175 OFFSET( "V4F_START ", GLvector4f, start );
176 OFFSET( "V4F_COUNT ", GLvector4f, count );
177 OFFSET( "V4F_STRIDE ", GLvector4f, stride );
178 OFFSET( "V4F_SIZE ", GLvector4f, size );
179 OFFSET( "V4F_FLAGS ", GLvector4f, flags );
180
181 DEFINE_HEADER( "GLvector4f" );
182
183 DEFINE( "VEC_MALLOC ", VEC_MALLOC );
184 DEFINE( "VEC_NOT_WRITEABLE ", VEC_NOT_WRITEABLE );
185 DEFINE( "VEC_BAD_STRIDE ", VEC_BAD_STRIDE );
186 printf( "\n" );
187 DEFINE( "VEC_SIZE_1 ", VEC_SIZE_1 );
188 DEFINE( "VEC_SIZE_2 ", VEC_SIZE_2 );
189 DEFINE( "VEC_SIZE_3 ", VEC_SIZE_3 );
190 DEFINE( "VEC_SIZE_4 ", VEC_SIZE_4 );
191
192
193 /* GLmatrix offsets:
194 */
195 OFFSET_HEADER( "GLmatrix" );
196
197 OFFSET( "MATRIX_DATA ", GLmatrix, m );
198 OFFSET( "MATRIX_INV ", GLmatrix, inv );
199 OFFSET( "MATRIX_FLAGS ", GLmatrix, flags );
200 OFFSET( "MATRIX_TYPE ", GLmatrix, type );
201
202
203 /* struct gl_light offsets:
204 */
205 OFFSET_HEADER( "struct gl_light" );
206
207 printf( "\n" );
208 OFFSET( "LIGHT_AMBIENT ", struct gl_light, Ambient );
209 OFFSET( "LIGHT_DIFFUSE ", struct gl_light, Diffuse );
210 OFFSET( "LIGHT_SPECULAR ", struct gl_light, Specular );
211 OFFSET( "LIGHT_EYE_POSITION ", struct gl_light, EyePosition );
212 OFFSET( "LIGHT_SPOT_DIRECTION ", struct gl_light, SpotDirection );
213 OFFSET( "LIGHT_SPOT_EXPONENT ", struct gl_light, SpotExponent );
214 OFFSET( "LIGHT_SPOT_CUTOFF ", struct gl_light, SpotCutoff );
215 OFFSET( "LIGHT_COS_CUTOFF ", struct gl_light, _CosCutoff );
216 OFFSET( "LIGHT_CONST_ATTEN ", struct gl_light, ConstantAttenuation );
217 OFFSET( "LIGHT_LINEAR_ATTEN ", struct gl_light, LinearAttenuation );
218 OFFSET( "LIGHT_QUADRATIC_ATTEN ", struct gl_light, QuadraticAttenuation );
219 OFFSET( "LIGHT_ENABLED ", struct gl_light, Enabled );
220 printf( "\n" );
221 OFFSET( "LIGHT_FLAGS ", struct gl_light, _Flags );
222 printf( "\n" );
223 OFFSET( "LIGHT_POSITION ", struct gl_light, _Position );
224 OFFSET( "LIGHT_VP_INF_NORM ", struct gl_light, _VP_inf_norm );
225 OFFSET( "LIGHT_H_INF_NORM ", struct gl_light, _h_inf_norm );
226 OFFSET( "LIGHT_NORM_DIRECTION ", struct gl_light, _NormSpotDirection );
227 OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light, _VP_inf_spot_attenuation );
228 printf( "\n" );
229 OFFSET( "LIGHT_MAT_AMBIENT ", struct gl_light, _MatAmbient );
230 OFFSET( "LIGHT_MAT_DIFFUSE ", struct gl_light, _MatDiffuse );
231 OFFSET( "LIGHT_MAT_SPECULAR ", struct gl_light, _MatSpecular );
232 printf( "\n" );
233 SIZEOF( "SIZEOF_GL_LIGHT ", struct gl_light );
234
235 DEFINE_HEADER( "struct gl_light" );
236
237 DEFINE( "LIGHT_SPOT ", LIGHT_SPOT );
238 DEFINE( "LIGHT_LOCAL_VIEWER ", LIGHT_LOCAL_VIEWER );
239 DEFINE( "LIGHT_POSITIONAL ", LIGHT_POSITIONAL );
240 printf( "\n" );
241 DEFINE( "LIGHT_NEED_VERTICES ", LIGHT_NEED_VERTICES );
242
243
244 /* struct gl_lightmodel offsets:
245 */
246 OFFSET_HEADER( "struct gl_lightmodel" );
247
248 OFFSET( "LIGHT_MODEL_AMBIENT ", struct gl_lightmodel, Ambient );
249 OFFSET( "LIGHT_MODEL_LOCAL_VIEWER ", struct gl_lightmodel, LocalViewer );
250 OFFSET( "LIGHT_MODEL_TWO_SIDE ", struct gl_lightmodel, TwoSide );
251 OFFSET( "LIGHT_MODEL_COLOR_CONTROL ", struct gl_lightmodel, ColorControl );
252
253
254 printf( "\n" );
255 printf( "\n" );
256 printf( "#endif /* __ASM_TYPES_H__ */\n" );
257
258 return 0;
259 }