Merge remote branch 'origin/master' into lp-binning
[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 "main/glheader.h"
32 #include "main/context.h"
33 #include "main/macros.h"
34 #include "main/mtypes.h"
35
36 #include "tnl/t_context.h"
37
38 #include "via_context.h"
39 #include "via_tris.h"
40 #include "via_ioctl.h"
41
42 /*
43 * Render unclipped vertex buffers by emitting vertices directly to
44 * dma buffers. Use strip/fan hardware primitives where possible.
45 * Try to simulate missing primitives with indexed vertices.
46 */
47 #define HAVE_POINTS 1
48 #define HAVE_LINES 1
49 #define HAVE_LINE_STRIPS 1
50 #define HAVE_LINE_LOOP 1
51 #define HAVE_TRIANGLES 1
52 #define HAVE_TRI_STRIPS 1
53 #define HAVE_TRI_STRIP_1 0
54 #define HAVE_TRI_FANS 1
55 #define HAVE_POLYGONS 1
56 #define HAVE_QUADS 0
57 #define HAVE_QUAD_STRIPS 0
58
59 #define HAVE_ELTS 0
60
61 #define LOCAL_VARS struct via_context *vmesa = VIA_CONTEXT(ctx)
62 #define INIT(prim) do { \
63 viaRasterPrimitive(ctx, prim, prim); \
64 } while (0)
65 #define GET_CURRENT_VB_MAX_VERTS() \
66 ((VIA_DMA_BUF_SZ - (512 + (int)vmesa->dmaLow)) / (vmesa->vertexSize * 4))
67 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
68 (VIA_DMA_BUF_SZ - 512) / (vmesa->vertexSize * 4)
69
70 #define ALLOC_VERTS( nr ) \
71 viaExtendPrimitive( vmesa, (nr) * vmesa->vertexSize * 4)
72
73 #define EMIT_VERTS(ctx, j, nr, buf) \
74 _tnl_emit_vertices_to_buffer(ctx, j, (j)+(nr), buf )
75
76 #define FLUSH() VIA_FINISH_PRIM( vmesa )
77
78 #define TAG(x) via_fast##x
79 #include "tnl_dd/t_dd_dmatmp.h"
80 #undef TAG
81 #undef LOCAL_VARS
82 #undef INIT
83
84 /**********************************************************************/
85 /* Fast Render pipeline stage */
86 /**********************************************************************/
87 static GLboolean via_run_fastrender(GLcontext *ctx,
88 struct tnl_pipeline_stage *stage)
89 {
90 struct via_context *vmesa = VIA_CONTEXT(ctx);
91 TNLcontext *tnl = TNL_CONTEXT(ctx);
92 struct vertex_buffer *VB = &tnl->vb;
93 GLuint i;
94
95
96 tnl->Driver.Render.Start(ctx);
97
98 if (VB->ClipOrMask ||
99 vmesa->renderIndex != 0 ||
100 !via_fastvalidate_render( ctx, VB )) {
101 tnl->Driver.Render.Finish(ctx);
102 return GL_TRUE;
103 }
104
105 tnl->clipspace.new_inputs |= VERT_BIT_POS;
106
107 for (i = 0; i < VB->PrimitiveCount; ++i) {
108 GLuint mode = _tnl_translate_prim(&VB->Primitive[i]);
109 GLuint start = VB->Primitive[i].start;
110 GLuint length = VB->Primitive[i].count;
111 if (length)
112 via_fastrender_tab_verts[mode & PRIM_MODE_MASK](ctx, start, start+length, mode);
113 }
114
115 tnl->Driver.Render.Finish(ctx);
116
117 return GL_FALSE; /* finished the pipe */
118 }
119
120 const struct tnl_pipeline_stage _via_fastrender_stage =
121 {
122 "via fast render",
123 NULL,
124 NULL,
125 NULL,
126 NULL,
127 via_run_fastrender /* run */
128 };
129
130