2 * Intel i810 DRI driver for Mesa 3.5
4 * Copyright (C) 1999-2000 Keith Whitwell All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL KEITH WHITWELL BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
26 * Adapted for use on the I830:
27 * Jeff Hartmann <jhartmann@2d3d.com>
29 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_render.c,v 1.2 2002/12/10 01:26:53 dawes Exp $ */
32 * Render unclipped vertex buffers by emitting vertices directly to
33 * dma buffers. Use strip/fan hardware acceleration where possible.
43 #include "tnl/t_context.h"
45 #include "i830_screen.h"
48 #include "i830_context.h"
49 #include "i830_tris.h"
50 #include "i830_state.h"
52 #include "i830_ioctl.h"
55 * Render unclipped vertex buffers by emitting vertices directly to
56 * dma buffers. Use strip/fan hardware primitives where possible.
57 * Try to simulate missing primitives with indexed vertices.
59 #define HAVE_POINTS 0 /* Has it, but can't use because subpixel has to
60 * be adjusted for points on the I830/I845G
63 #define HAVE_LINE_STRIPS 1
64 #define HAVE_TRIANGLES 1
65 #define HAVE_TRI_STRIPS 1
66 #define HAVE_TRI_STRIP_1 0 /* has it, template can't use it yet */
67 #define HAVE_TRI_FANS 1
68 #define HAVE_POLYGONS 1
70 #define HAVE_QUAD_STRIPS 0
74 static GLuint hw_prim
[GL_POLYGON
+1] = {
87 static const GLenum reduced_prim
[GL_POLYGON
+1] = {
100 static const int scale_prim
[GL_POLYGON
+1] = {
101 0, /* fallback case */
108 0, /* fallback case */
109 0, /* fallback case */
113 /* Fallback to normal rendering. Should now never be called.
115 static void VERT_FALLBACK( GLcontext
*ctx
,
120 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
121 tnl
->Driver
.Render
.PrimitiveNotify( ctx
, flags
& PRIM_MODE_MASK
);
122 tnl
->Driver
.Render
.BuildVertices( ctx
, start
, count
, ~0 );
123 tnl
->Driver
.Render
.PrimTabVerts
[flags
&PRIM_MODE_MASK
]( ctx
, start
,
125 I830_CONTEXT(ctx
)->SetupNewInputs
= VERT_BIT_CLIP
;
129 #define LOCAL_VARS i830ContextPtr imesa = I830_CONTEXT(ctx)
130 #define INIT( prim ) do { \
131 I830_STATECHANGE(imesa, 0); \
132 i830RasterPrimitive( ctx, reduced_prim[prim], hw_prim[prim] ); \
135 #define NEW_PRIMITIVE() I830_STATECHANGE( imesa, 0 )
136 #define NEW_BUFFER() I830_FIREVERTICES( imesa )
137 #define GET_CURRENT_VB_MAX_VERTS() \
138 (((int)imesa->vertex_high - (int)imesa->vertex_low) / (imesa->vertex_size*4))
139 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
140 (I830_DMA_BUF_SZ-8) / (imesa->vertex_size * 4)
142 #define EMIT_VERTS( ctx, j, nr ) \
143 i830_emit_contiguous_verts(ctx, j, (j)+(nr))
145 #define TAG(x) i830_##x
146 #include "tnl_dd/t_dd_dmatmp.h"
149 /**********************************************************************/
150 /* Render pipeline stage */
151 /**********************************************************************/
153 /* Heuristic for i830, which can only emit a single primitive per dma
154 * buffer, and has only a small number of dma buffers.
156 static GLboolean
choose_render( struct vertex_buffer
*VB
, int bufsz
)
162 int i
= 0, length
, flags
= 0;
165 for (i
= VB
->FirstPrimitive
; !(flags
& PRIM_LAST
) ; i
+= length
) {
166 flags
= VB
->Primitive
[i
];
167 length
= VB
->PrimitiveLength
[i
];
171 if (!hw_prim
[flags
& PRIM_MODE_MASK
])
175 nr_rverts
+= length
* scale_prim
[flags
& PRIM_MODE_MASK
];
177 if (reduced_prim
[flags
&PRIM_MODE_MASK
] != rprim
) {
179 rprim
= reduced_prim
[flags
&PRIM_MODE_MASK
];
183 nr_prims
+= i
/ bufsz
;
184 nr_rprims
+= nr_rverts
/ bufsz
;
186 if ((nr_prims
> nr_rprims
* 2) ||
187 (nr_prims
> nr_rprims
+ 3))
194 static GLboolean
i830_run_render( GLcontext
*ctx
,
195 struct gl_pipeline_stage
*stage
)
197 i830ContextPtr imesa
= I830_CONTEXT(ctx
);
198 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
199 struct vertex_buffer
*VB
= &tnl
->vb
;
200 GLuint i
, length
, flags
= 0;
201 /* Don't handle clipping or indexed vertices.
203 if (VB
->ClipOrMask
|| imesa
->RenderIndex
!= 0 || VB
->Elts
||
204 !choose_render( VB
, GET_SUBSEQUENT_VB_MAX_VERTS() )) {
208 imesa
->SetupNewInputs
= VERT_BIT_CLIP
;
210 tnl
->Driver
.Render
.Start( ctx
);
212 for (i
= VB
->FirstPrimitive
; !(flags
& PRIM_LAST
) ; i
+= length
) {
213 flags
= VB
->Primitive
[i
];
214 length
= VB
->PrimitiveLength
[i
];
216 i830_render_tab_verts
[flags
& PRIM_MODE_MASK
]( ctx
, i
, i
+ length
,
220 tnl
->Driver
.Render
.Finish( ctx
);
222 return GL_FALSE
; /* finished the pipe */
226 static void i830_check_render( GLcontext
*ctx
,
227 struct gl_pipeline_stage
*stage
)
229 GLuint inputs
= VERT_BIT_CLIP
| VERT_BIT_COLOR0
;
230 if (ctx
->RenderMode
== GL_RENDER
) {
231 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
232 inputs
|= VERT_BIT_COLOR1
;
234 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
)
235 inputs
|= VERT_BIT_TEX0
;
237 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
)
238 inputs
|= VERT_BIT_TEX1
;
240 if (ctx
->Fog
.Enabled
)
241 inputs
|= VERT_BIT_FOG
;
244 stage
->inputs
= inputs
;
247 static void dtr( struct gl_pipeline_stage
*stage
)
253 const struct gl_pipeline_stage _i830_render_stage
=
256 (_DD_NEW_SEPARATE_SPECULAR
|
259 _NEW_RENDERMODE
), /* re-check (new inputs) */
260 0, /* re-run (always runs) */
261 GL_TRUE
, /* active */
262 0, 0, /* inputs (set in check_render), outputs */
263 0, 0, /* changed_inputs, private */
264 dtr
, /* destructor */
265 i830_check_render
, /* check - initially set to alloc data */
266 i830_run_render
/* run */