2 * GLX Hardware Device Driver for Intel i810
3 * Copyright (C) 1999 Keith Whitwell
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "main/glheader.h"
28 #include "main/mtypes.h"
29 #include "main/imports.h"
30 #include "main/macros.h"
31 #include "main/colormac.h"
33 #include "swrast_setup/swrast_setup.h"
34 #include "tnl/t_context.h"
36 #include "i810screen.h"
38 #include "i810context.h"
40 #include "i810ioctl.h"
41 #include "i810state.h"
44 #define I810_TEX1_BIT 0x1
45 #define I810_TEX0_BIT 0x2
46 #define I810_RGBA_BIT 0x4
47 #define I810_SPEC_BIT 0x8
48 #define I810_FOG_BIT 0x10
49 #define I810_XYZW_BIT 0x20
50 #define I810_PTEX_BIT 0x40
51 #define I810_MAX_SETUP 0x80
54 void (*emit
)( struct gl_context
*, GLuint
, GLuint
, void *, GLuint
);
55 tnl_interp_func interp
;
56 tnl_copy_pv_func copy_pv
;
57 GLboolean (*check_tex_sizes
)( struct gl_context
*ctx
);
60 } setup_tab
[I810_MAX_SETUP
];
62 #define TINY_VERTEX_FORMAT (GFX_OP_VERTEX_FMT | \
63 VF_TEXCOORD_COUNT_0 | \
67 #define NOTEX_VERTEX_FORMAT (GFX_OP_VERTEX_FMT | \
68 VF_TEXCOORD_COUNT_0 | \
69 VF_SPEC_FOG_ENABLE | \
73 #define TEX0_VERTEX_FORMAT (GFX_OP_VERTEX_FMT | \
74 VF_TEXCOORD_COUNT_1 | \
75 VF_SPEC_FOG_ENABLE | \
79 #define TEX1_VERTEX_FORMAT (GFX_OP_VERTEX_FMT | \
80 VF_TEXCOORD_COUNT_2 | \
81 VF_SPEC_FOG_ENABLE | \
85 #define PROJ_TEX1_VERTEX_FORMAT 0
86 #define TEX2_VERTEX_FORMAT 0
87 #define TEX3_VERTEX_FORMAT 0
88 #define PROJ_TEX3_VERTEX_FORMAT 0
90 #define DO_XYZW (IND & I810_XYZW_BIT)
91 #define DO_RGBA (IND & I810_RGBA_BIT)
92 #define DO_SPEC (IND & I810_SPEC_BIT)
93 #define DO_FOG (IND & I810_FOG_BIT)
94 #define DO_TEX0 (IND & I810_TEX0_BIT)
95 #define DO_TEX1 (IND & I810_TEX1_BIT)
98 #define DO_PTEX (IND & I810_PTEX_BIT)
100 #define VERTEX i810Vertex
101 #define VERTEX_COLOR i810_color_t
102 #define GET_VIEWPORT_MAT() I810_CONTEXT(ctx)->ViewportMatrix.m
103 #define GET_TEXSOURCE(n) n
104 #define GET_VERTEX_FORMAT() I810_CONTEXT(ctx)->Setup[I810_CTXREG_VF]
105 #define GET_VERTEX_STORE() I810_CONTEXT(ctx)->verts
106 #define GET_VERTEX_SIZE() I810_CONTEXT(ctx)->vertex_size * sizeof(GLuint)
107 #define INVALIDATE_STORED_VERTICES()
109 #define HAVE_HW_VIEWPORT 0
110 #define HAVE_HW_DIVIDE 0
111 #define HAVE_RGBA_COLOR 0
112 #define HAVE_TINY_VERTICES 1
113 #define HAVE_NOTEX_VERTICES 1
114 #define HAVE_TEX0_VERTICES 1
115 #define HAVE_TEX1_VERTICES 1
116 #define HAVE_TEX2_VERTICES 0
117 #define HAVE_TEX3_VERTICES 0
118 #define HAVE_PTEX_VERTICES 0
120 #define UNVIEWPORT_VARS GLfloat h = I810_CONTEXT(ctx)->driDrawable->h
121 #define UNVIEWPORT_X(x) x - SUBPIXEL_X
122 #define UNVIEWPORT_Y(y) - y + h + SUBPIXEL_Y
123 #define UNVIEWPORT_Z(z) z * (float)0xffff
125 #define PTEX_FALLBACK() FALLBACK(I810_CONTEXT(ctx), I810_FALLBACK_TEXTURE, 1)
127 #define INTERP_VERTEX setup_tab[I810_CONTEXT(ctx)->SetupIndex].interp
128 #define COPY_PV_VERTEX setup_tab[I810_CONTEXT(ctx)->SetupIndex].copy_pv
131 /***********************************************************************
132 * Generate pv-copying and translation functions *
133 ***********************************************************************/
135 #define TAG(x) i810_##x
136 #include "tnl_dd/t_dd_vb.c"
138 /***********************************************************************
139 * Generate vertex emit and interp functions *
140 ***********************************************************************/
143 #define IND (I810_XYZW_BIT|I810_RGBA_BIT)
144 #define TAG(x) x##_wg
145 #include "tnl_dd/t_dd_vbtmp.h"
147 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_SPEC_BIT)
148 #define TAG(x) x##_wgs
149 #include "tnl_dd/t_dd_vbtmp.h"
151 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_TEX0_BIT)
152 #define TAG(x) x##_wgt0
153 #include "tnl_dd/t_dd_vbtmp.h"
155 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_TEX0_BIT|I810_TEX1_BIT)
156 #define TAG(x) x##_wgt0t1
157 #include "tnl_dd/t_dd_vbtmp.h"
159 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_TEX0_BIT|I810_PTEX_BIT)
160 #define TAG(x) x##_wgpt0
161 #include "tnl_dd/t_dd_vbtmp.h"
163 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_SPEC_BIT|I810_TEX0_BIT)
164 #define TAG(x) x##_wgst0
165 #include "tnl_dd/t_dd_vbtmp.h"
167 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_SPEC_BIT|I810_TEX0_BIT|\
169 #define TAG(x) x##_wgst0t1
170 #include "tnl_dd/t_dd_vbtmp.h"
172 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_SPEC_BIT|I810_TEX0_BIT|\
174 #define TAG(x) x##_wgspt0
175 #include "tnl_dd/t_dd_vbtmp.h"
177 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT)
178 #define TAG(x) x##_wgf
179 #include "tnl_dd/t_dd_vbtmp.h"
181 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT)
182 #define TAG(x) x##_wgfs
183 #include "tnl_dd/t_dd_vbtmp.h"
185 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_TEX0_BIT)
186 #define TAG(x) x##_wgft0
187 #include "tnl_dd/t_dd_vbtmp.h"
189 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_TEX0_BIT|\
191 #define TAG(x) x##_wgft0t1
192 #include "tnl_dd/t_dd_vbtmp.h"
194 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_TEX0_BIT|\
196 #define TAG(x) x##_wgfpt0
197 #include "tnl_dd/t_dd_vbtmp.h"
199 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT|\
201 #define TAG(x) x##_wgfst0
202 #include "tnl_dd/t_dd_vbtmp.h"
204 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT|\
205 I810_TEX0_BIT|I810_TEX1_BIT)
206 #define TAG(x) x##_wgfst0t1
207 #include "tnl_dd/t_dd_vbtmp.h"
209 #define IND (I810_XYZW_BIT|I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT|\
210 I810_TEX0_BIT|I810_PTEX_BIT)
211 #define TAG(x) x##_wgfspt0
212 #include "tnl_dd/t_dd_vbtmp.h"
214 #define IND (I810_TEX0_BIT)
215 #define TAG(x) x##_t0
216 #include "tnl_dd/t_dd_vbtmp.h"
218 #define IND (I810_TEX0_BIT|I810_TEX1_BIT)
219 #define TAG(x) x##_t0t1
220 #include "tnl_dd/t_dd_vbtmp.h"
222 #define IND (I810_FOG_BIT)
224 #include "tnl_dd/t_dd_vbtmp.h"
226 #define IND (I810_FOG_BIT|I810_TEX0_BIT)
227 #define TAG(x) x##_ft0
228 #include "tnl_dd/t_dd_vbtmp.h"
230 #define IND (I810_FOG_BIT|I810_TEX0_BIT|I810_TEX1_BIT)
231 #define TAG(x) x##_ft0t1
232 #include "tnl_dd/t_dd_vbtmp.h"
234 #define IND (I810_RGBA_BIT)
236 #include "tnl_dd/t_dd_vbtmp.h"
238 #define IND (I810_RGBA_BIT|I810_SPEC_BIT)
239 #define TAG(x) x##_gs
240 #include "tnl_dd/t_dd_vbtmp.h"
242 #define IND (I810_RGBA_BIT|I810_TEX0_BIT)
243 #define TAG(x) x##_gt0
244 #include "tnl_dd/t_dd_vbtmp.h"
246 #define IND (I810_RGBA_BIT|I810_TEX0_BIT|I810_TEX1_BIT)
247 #define TAG(x) x##_gt0t1
248 #include "tnl_dd/t_dd_vbtmp.h"
250 #define IND (I810_RGBA_BIT|I810_SPEC_BIT|I810_TEX0_BIT)
251 #define TAG(x) x##_gst0
252 #include "tnl_dd/t_dd_vbtmp.h"
254 #define IND (I810_RGBA_BIT|I810_SPEC_BIT|I810_TEX0_BIT|I810_TEX1_BIT)
255 #define TAG(x) x##_gst0t1
256 #include "tnl_dd/t_dd_vbtmp.h"
258 #define IND (I810_RGBA_BIT|I810_FOG_BIT)
259 #define TAG(x) x##_gf
260 #include "tnl_dd/t_dd_vbtmp.h"
262 #define IND (I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT)
263 #define TAG(x) x##_gfs
264 #include "tnl_dd/t_dd_vbtmp.h"
266 #define IND (I810_RGBA_BIT|I810_FOG_BIT|I810_TEX0_BIT)
267 #define TAG(x) x##_gft0
268 #include "tnl_dd/t_dd_vbtmp.h"
270 #define IND (I810_RGBA_BIT|I810_FOG_BIT|I810_TEX0_BIT|I810_TEX1_BIT)
271 #define TAG(x) x##_gft0t1
272 #include "tnl_dd/t_dd_vbtmp.h"
274 #define IND (I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT|I810_TEX0_BIT)
275 #define TAG(x) x##_gfst0
276 #include "tnl_dd/t_dd_vbtmp.h"
278 #define IND (I810_RGBA_BIT|I810_FOG_BIT|I810_SPEC_BIT|I810_TEX0_BIT|\
280 #define TAG(x) x##_gfst0t1
281 #include "tnl_dd/t_dd_vbtmp.h"
284 static void init_setup_tab( void )
323 static void i810PrintSetupFlags(const char *msg
, GLuint flags
)
325 fprintf(stderr
, "%s(%x): %s%s%s%s%s%s\n",
328 (flags
& I810_XYZW_BIT
) ? " xyzw," : "",
329 (flags
& I810_RGBA_BIT
) ? " rgba," : "",
330 (flags
& I810_SPEC_BIT
) ? " spec," : "",
331 (flags
& I810_FOG_BIT
) ? " fog," : "",
332 (flags
& I810_TEX0_BIT
) ? " tex-0," : "",
333 (flags
& I810_TEX1_BIT
) ? " tex-1," : "");
338 void i810CheckTexSizes( struct gl_context
*ctx
)
340 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
341 i810ContextPtr imesa
= I810_CONTEXT( ctx
);
343 if (!setup_tab
[imesa
->SetupIndex
].check_tex_sizes(ctx
)) {
344 /* Invalidate stored verts
346 imesa
->SetupNewInputs
= ~0;
347 imesa
->SetupIndex
|= I810_PTEX_BIT
;
349 if (!imesa
->Fallback
&&
350 !(ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
351 tnl
->Driver
.Render
.Interp
= setup_tab
[imesa
->SetupIndex
].interp
;
352 tnl
->Driver
.Render
.CopyPV
= setup_tab
[imesa
->SetupIndex
].copy_pv
;
354 if (imesa
->Fallback
) {
355 tnl
->Driver
.Render
.Start(ctx
);
360 void i810BuildVertices( struct gl_context
*ctx
,
365 i810ContextPtr imesa
= I810_CONTEXT( ctx
);
366 GLuint stride
= imesa
->vertex_size
* sizeof(int);
367 GLubyte
*v
= ((GLubyte
*)imesa
->verts
+ (start
* stride
));
369 if (0) fprintf(stderr
, "%s\n", __FUNCTION__
);
371 newinputs
|= imesa
->SetupNewInputs
;
372 imesa
->SetupNewInputs
= 0;
377 if (newinputs
& VERT_BIT_POS
) {
378 setup_tab
[imesa
->SetupIndex
].emit( ctx
, start
, count
, v
, stride
);
382 if (newinputs
& VERT_BIT_COLOR0
)
383 ind
|= I810_RGBA_BIT
;
385 if (newinputs
& VERT_BIT_COLOR1
)
386 ind
|= I810_SPEC_BIT
;
388 if (newinputs
& VERT_BIT_TEX0
)
389 ind
|= I810_TEX0_BIT
;
391 if (newinputs
& VERT_BIT_TEX1
)
392 ind
|= I810_TEX1_BIT
;
394 if (newinputs
& VERT_BIT_FOG
)
397 if (imesa
->SetupIndex
& I810_PTEX_BIT
)
400 ind
&= imesa
->SetupIndex
;
403 setup_tab
[ind
].emit( ctx
, start
, count
, v
, stride
);
408 void i810ChooseVertexState( struct gl_context
*ctx
)
410 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
411 i810ContextPtr imesa
= I810_CONTEXT( ctx
);
412 GLuint ind
= I810_XYZW_BIT
|I810_RGBA_BIT
;
414 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
415 ind
|= I810_SPEC_BIT
;
417 if (ctx
->Fog
.Enabled
)
420 if (ctx
->Texture
._EnabledUnits
& 0x2)
422 ind
|= I810_TEX1_BIT
|I810_TEX0_BIT
;
423 else if (ctx
->Texture
._EnabledUnits
& 0x1)
425 ind
|= I810_TEX0_BIT
;
427 imesa
->SetupIndex
= ind
;
429 if (I810_DEBUG
& (DEBUG_VERTS
|DEBUG_STATE
))
430 i810PrintSetupFlags( __FUNCTION__
, ind
);
432 if (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
)) {
433 tnl
->Driver
.Render
.Interp
= i810_interp_extras
;
434 tnl
->Driver
.Render
.CopyPV
= i810_copy_pv_extras
;
436 tnl
->Driver
.Render
.Interp
= setup_tab
[ind
].interp
;
437 tnl
->Driver
.Render
.CopyPV
= setup_tab
[ind
].copy_pv
;
440 if (setup_tab
[ind
].vertex_format
!= imesa
->Setup
[I810_CTXREG_VF
]) {
441 I810_STATECHANGE(imesa
, I810_UPLOAD_CTX
);
442 imesa
->Setup
[I810_CTXREG_VF
] = setup_tab
[ind
].vertex_format
;
443 imesa
->vertex_size
= setup_tab
[ind
].vertex_size
;
449 void *i810_emit_contiguous_verts( struct gl_context
*ctx
,
454 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
455 GLuint stride
= imesa
->vertex_size
* 4;
456 setup_tab
[imesa
->SetupIndex
].emit( ctx
, start
, count
, dest
, stride
);
457 return (void *)((char *)dest
+ stride
* (count
- start
));
462 void i810InitVB( struct gl_context
*ctx
)
464 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
465 GLuint size
= TNL_CONTEXT(ctx
)->vb
.Size
;
467 imesa
->verts
= (GLubyte
*)_mesa_align_malloc(size
* 4 * 16, 32);
470 static int firsttime
= 1;
479 void i810FreeVB( struct gl_context
*ctx
)
481 i810ContextPtr imesa
= I810_CONTEXT(ctx
);
483 _mesa_align_free(imesa
->verts
);