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 */
114 #define LOCAL_VARS i830ContextPtr imesa = I830_CONTEXT(ctx)
115 #define INIT( prim ) do { \
116 I830_STATECHANGE(imesa, 0); \
117 i830RasterPrimitive( ctx, reduced_prim[prim], hw_prim[prim] ); \
120 #define FLUSH() I830_FIREVERTICES( imesa )
121 #define GET_CURRENT_VB_MAX_VERTS() \
122 (((int)imesa->vertex_high - (int)imesa->vertex_low) / (imesa->vertex_size*4))
123 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
124 (I830_DMA_BUF_SZ-8) / (imesa->vertex_size * 4)
127 #define ALLOC_VERTS( nr ) \
128 i830AllocDmaLow( imesa, nr * imesa->vertex_size * 4)
129 #define EMIT_VERTS( ctx, j, nr, buf ) \
130 i830_emit_contiguous_verts(ctx, j, (j)+(nr), buf)
132 #define TAG(x) i830_##x
133 #include "tnl_dd/t_dd_dmatmp.h"
136 /**********************************************************************/
137 /* Render pipeline stage */
138 /**********************************************************************/
140 /* Heuristic for i830, which can only emit a single primitive per dma
141 * buffer, and has only a small number of dma buffers.
143 static GLboolean
choose_render( struct vertex_buffer
*VB
, int bufsz
)
152 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
154 GLuint prim
= VB
->Primitive
[i
].mode
;
155 GLuint length
= VB
->Primitive
[i
].count
;
160 if (!hw_prim
[prim
& PRIM_MODE_MASK
])
164 nr_rverts
+= length
* scale_prim
[prim
& PRIM_MODE_MASK
];
166 if (reduced_prim
[prim
&PRIM_MODE_MASK
] != rprim
) {
168 rprim
= reduced_prim
[prim
&PRIM_MODE_MASK
];
172 nr_prims
+= i
/ bufsz
;
173 nr_rprims
+= nr_rverts
/ bufsz
;
175 if ((nr_prims
> nr_rprims
* 2) ||
176 (nr_prims
> nr_rprims
+ 3))
183 static GLboolean
i830_run_render( GLcontext
*ctx
,
184 struct tnl_pipeline_stage
*stage
)
186 i830ContextPtr imesa
= I830_CONTEXT(ctx
);
187 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
188 struct vertex_buffer
*VB
= &tnl
->vb
;
190 /* Don't handle clipping or indexed vertices.
192 if (imesa
->RenderIndex
!= 0 ||
193 !i830_validate_render( ctx
, VB
) ||
194 !choose_render( VB
, GET_SUBSEQUENT_VB_MAX_VERTS() )) {
198 imesa
->SetupNewInputs
= VERT_BIT_POS
;
200 tnl
->Driver
.Render
.Start( ctx
);
202 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
204 GLuint prim
= VB
->Primitive
[i
].mode
;
205 GLuint start
= VB
->Primitive
[i
].start
;
206 GLuint length
= VB
->Primitive
[i
].count
;
211 i830_render_tab_verts
[prim
& PRIM_MODE_MASK
]( ctx
, start
, start
+ length
,
215 tnl
->Driver
.Render
.Finish( ctx
);
217 return GL_FALSE
; /* finished the pipe */
221 static void i830_check_render( GLcontext
*ctx
,
222 struct tnl_pipeline_stage
*stage
)
224 GLuint inputs
= VERT_BIT_POS
| VERT_BIT_COLOR0
;
225 if (ctx
->RenderMode
== GL_RENDER
) {
226 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
227 inputs
|= VERT_BIT_COLOR1
;
229 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
)
230 inputs
|= VERT_BIT_TEX0
;
232 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
)
233 inputs
|= VERT_BIT_TEX1
;
235 if (ctx
->Fog
.Enabled
)
236 inputs
|= VERT_BIT_FOG
;
239 stage
->inputs
= inputs
;
242 static void dtr( struct tnl_pipeline_stage
*stage
)
248 const struct tnl_pipeline_stage _i830_render_stage
=
251 (_DD_NEW_SEPARATE_SPECULAR
|
254 _NEW_RENDERMODE
), /* re-check (new inputs) */
255 0, /* re-run (always runs) */
256 GL_TRUE
, /* active */
257 0, 0, /* inputs (set in check_render), outputs */
258 0, 0, /* changed_inputs, private */
259 dtr
, /* destructor */
260 i830_check_render
, /* check - initially set to alloc data */
261 i830_run_render
/* run */