Fix some wrapping bugs in the last commit. Probably there are more
[mesa.git] / src / mesa / drivers / dri / unichrome / via_render.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
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, sub license,
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS 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 OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /*
27 * Render unclipped vertex buffers by emitting vertices directly to
28 * dma buffers. Use strip/fan hardware acceleration where possible.
29 *
30 */
31 #include "glheader.h"
32 #include "context.h"
33 #include "macros.h"
34 #include "mtypes.h"
35
36 #include "tnl/t_context.h"
37
38 #include "via_context.h"
39 #include "via_tris.h"
40 #include "via_state.h"
41 #include "via_vb.h"
42 #include "via_ioctl.h"
43
44 /*
45 * Render unclipped vertex buffers by emitting vertices directly to
46 * dma buffers. Use strip/fan hardware primitives where possible.
47 * Try to simulate missing primitives with indexed vertices.
48 */
49 #define HAVE_POINTS 1
50 #define HAVE_LINES 1
51 #define HAVE_LINE_STRIPS 1
52 #define HAVE_LINE_LOOP 1
53 #define HAVE_TRIANGLES 1
54 #define HAVE_TRI_STRIPS 1
55 #define HAVE_TRI_STRIP_1 0 /* has it, template can't use it yet */
56 #define HAVE_TRI_FANS 1
57 #define HAVE_POLYGONS 1
58 #define HAVE_QUADS 0
59 #define HAVE_QUAD_STRIPS 0
60
61 #define HAVE_ELTS 0
62
63 #define LOCAL_VARS viaContextPtr vmesa = VIA_CONTEXT(ctx)
64 #define INIT(prim) do { \
65 viaRasterPrimitive(ctx, prim, prim); \
66 } while (0)
67 #define GET_CURRENT_VB_MAX_VERTS() \
68 ((VIA_DMA_BUF_SZ - (512 + (int)vmesa->dmaLow)) / (vmesa->vertexSize * 4))
69 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
70 (VIA_DMA_BUF_SZ - 512) / (vmesa->vertexSize * 4)
71
72 #define ALLOC_VERTS( nr ) \
73 viaExtendPrimitive( vmesa, (nr) * vmesa->vertexSize * 4)
74
75 #define EMIT_VERTS(ctx, j, nr, buf) \
76 via_emit_contiguous_verts(ctx, j, (j) + (nr), buf)
77
78 #define FLUSH() VIA_FINISH_PRIM( vmesa )
79
80 #define TAG(x) via_fast##x
81 #include "tnl_dd/t_dd_dmatmp.h"
82 #undef TAG
83 #undef LOCAL_VARS
84 #undef INIT
85
86 /**********************************************************************/
87 /* Fast Render pipeline stage */
88 /**********************************************************************/
89 static GLboolean via_run_fastrender(GLcontext *ctx,
90 struct tnl_pipeline_stage *stage)
91 {
92 viaContextPtr vmesa = VIA_CONTEXT(ctx);
93 TNLcontext *tnl = TNL_CONTEXT(ctx);
94 struct vertex_buffer *VB = &tnl->vb;
95 GLuint i;
96
97 /* Don't handle clipping or indexed vertices.
98 */
99 if (VB->ClipOrMask ||
100 vmesa->renderIndex != 0 ||
101 !via_fastvalidate_render( ctx, VB )) {
102 if (VIA_DEBUG) {
103 fprintf(stderr, "slow path\n");
104 fprintf(stderr, "ClipOrMask = %08x\n", VB->ClipOrMask);
105 fprintf(stderr, "renderIndex = %08x\n", vmesa->renderIndex);
106 fprintf(stderr, "Elts = %08x\n", (GLuint)VB->Elts);
107 }
108 return GL_TRUE;
109 }
110 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
111 vmesa->setupNewInputs = VERT_BIT_CLIP;
112
113 tnl->Driver.Render.Start(ctx);
114
115 for (i = 0; i < VB->PrimitiveCount; ++i) {
116 GLuint mode = VB->Primitive[i].mode;
117 GLuint start = VB->Primitive[i].start;
118 GLuint length = VB->Primitive[i].count;
119 if (length)
120 via_fastrender_tab_verts[mode & PRIM_MODE_MASK](ctx, start, start+length, mode);
121 }
122
123 tnl->Driver.Render.Finish(ctx);
124
125 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
126 return GL_FALSE; /* finished the pipe */
127 }
128
129
130 static void via_check_fastrender(GLcontext *ctx, struct tnl_pipeline_stage *stage)
131 {
132 GLuint inputs = VERT_BIT_CLIP | VERT_BIT_COLOR0;
133
134 if (ctx->RenderMode == GL_RENDER) {
135 if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
136 inputs |= VERT_BIT_COLOR1;
137
138 if (ctx->Texture.Unit[0]._ReallyEnabled)
139 inputs |= VERT_BIT_TEX0;
140
141 if (ctx->Texture.Unit[1]._ReallyEnabled)
142 inputs |= VERT_BIT_TEX1;
143
144 if (ctx->Fog.Enabled)
145 inputs |= VERT_BIT_FOG;
146 }
147
148 stage->inputs = inputs;
149 }
150
151
152 static void fastdtr(struct tnl_pipeline_stage *stage)
153 {
154 (void)stage;
155 }
156
157
158 const struct tnl_pipeline_stage _via_fastrender_stage =
159 {
160 "via fast render",
161 (_DD_NEW_SEPARATE_SPECULAR |
162 _NEW_TEXTURE|
163 _NEW_FOG|
164 _NEW_RENDERMODE), /* re-check (new inputs) */
165 0, /* re-run (always runs) */
166 GL_TRUE, /* active */
167 0, 0, /* inputs (set in check_render), outputs */
168 0, 0, /* changed_inputs, private */
169 fastdtr, /* destructor */
170 via_check_fastrender, /* check - initially set to alloc data */
171 via_run_fastrender /* run */
172 };
173
174