mesa: remove a line of dead code
[mesa.git] / src / mesa / drivers / dri / i915 / intel_render.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Render unclipped vertex buffers by emitting vertices directly to
30 * dma buffers. Use strip/fan hardware acceleration where possible.
31 *
32 */
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/macros.h"
36 #include "main/imports.h"
37 #include "main/mtypes.h"
38 #include "main/enums.h"
39
40 #include "tnl/t_context.h"
41 #include "tnl/t_vertex.h"
42 #include "tnl/t_pipeline.h"
43
44 #include "intel_screen.h"
45 #include "intel_context.h"
46 #include "intel_tris.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_reg.h"
49
50 /*
51 * Render unclipped vertex buffers by emitting vertices directly to
52 * dma buffers. Use strip/fan hardware primitives where possible.
53 * Try to simulate missing primitives with indexed vertices.
54 */
55 #define HAVE_POINTS 0 /* Has it, but can't use because subpixel has to
56 * be adjusted for points on the INTEL/I845G
57 */
58 #define HAVE_LINES 1
59 #define HAVE_LINE_STRIPS 1
60 #define HAVE_TRIANGLES 1
61 #define HAVE_TRI_STRIPS 1
62 #define HAVE_TRI_STRIP_1 0 /* has it, template can't use it yet */
63 #define HAVE_TRI_FANS 1
64 #define HAVE_POLYGONS 1
65 #define HAVE_QUADS 0
66 #define HAVE_QUAD_STRIPS 0
67
68 #define HAVE_ELTS 0
69
70 static uint32_t hw_prim[GL_POLYGON + 1] = {
71 0,
72 PRIM3D_LINELIST,
73 PRIM3D_LINESTRIP,
74 PRIM3D_LINESTRIP,
75 PRIM3D_TRILIST,
76 PRIM3D_TRISTRIP,
77 PRIM3D_TRIFAN,
78 0,
79 0,
80 PRIM3D_POLY
81 };
82
83 static const GLenum reduced_prim[GL_POLYGON + 1] = {
84 GL_POINTS,
85 GL_LINES,
86 GL_LINES,
87 GL_LINES,
88 GL_TRIANGLES,
89 GL_TRIANGLES,
90 GL_TRIANGLES,
91 GL_TRIANGLES,
92 GL_TRIANGLES,
93 GL_TRIANGLES
94 };
95
96 static const int scale_prim[GL_POLYGON + 1] = {
97 0, /* fallback case */
98 1,
99 2,
100 2,
101 1,
102 3,
103 3,
104 0, /* fallback case */
105 0, /* fallback case */
106 3
107 };
108
109
110 static void
111 intelDmaPrimitive(struct intel_context *intel, GLenum prim)
112 {
113 if (0)
114 fprintf(stderr, "%s %s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(prim));
115 INTEL_FIREVERTICES(intel);
116 intel->vtbl.reduced_primitive_state(intel, reduced_prim[prim]);
117 intel_set_prim(intel, hw_prim[prim]);
118 }
119
120 static inline GLuint intel_get_vb_max(struct intel_context *intel)
121 {
122 GLuint ret;
123
124 if (intel->intelScreen->no_vbo)
125 ret = intel->batch->size - 1500;
126 else
127 ret = INTEL_VB_SIZE;
128 ret /= (intel->vertex_size * 4);
129 return ret;
130 }
131
132 static inline GLuint intel_get_current_max(struct intel_context *intel)
133 {
134
135 if (intel->intelScreen->no_vbo)
136 return intel_get_vb_max(intel);
137 else
138 return (INTEL_VB_SIZE - intel->prim.current_offset) / (intel->vertex_size * 4);
139 }
140
141 #define LOCAL_VARS struct intel_context *intel = intel_context(ctx)
142 #define INIT( prim ) \
143 do { \
144 intelDmaPrimitive( intel, prim ); \
145 } while (0)
146
147 #define FLUSH() INTEL_FIREVERTICES(intel)
148
149 #define GET_SUBSEQUENT_VB_MAX_VERTS() intel_get_vb_max(intel)
150 #define GET_CURRENT_VB_MAX_VERTS() intel_get_current_max(intel)
151
152 #define ALLOC_VERTS(nr) intel_get_prim_space(intel, nr)
153
154 #define EMIT_VERTS( ctx, j, nr, buf ) \
155 _tnl_emit_vertices_to_buffer(ctx, j, (j)+(nr), buf )
156
157 #define TAG(x) intel_##x
158 #include "tnl_dd/t_dd_dmatmp.h"
159
160
161 /**********************************************************************/
162 /* Render pipeline stage */
163 /**********************************************************************/
164
165 /* Heuristic to choose between the two render paths:
166 */
167 static GLboolean
168 choose_render(struct intel_context *intel, struct vertex_buffer *VB)
169 {
170 int vertsz = intel->vertex_size;
171 int cost_render = 0;
172 int cost_fallback = 0;
173 int nr_prims = 0;
174 int nr_rprims = 0;
175 int nr_rverts = 0;
176 int rprim = intel->reduced_primitive;
177 int i = 0;
178
179 for (i = 0; i < VB->PrimitiveCount; i++) {
180 GLuint prim = VB->Primitive[i].mode;
181 GLuint length = VB->Primitive[i].count;
182
183 if (!length)
184 continue;
185
186 nr_prims++;
187 nr_rverts += length * scale_prim[prim & PRIM_MODE_MASK];
188
189 if (reduced_prim[prim & PRIM_MODE_MASK] != rprim) {
190 nr_rprims++;
191 rprim = reduced_prim[prim & PRIM_MODE_MASK];
192 }
193 }
194
195 /* One point for each generated primitive:
196 */
197 cost_render = nr_prims;
198 cost_fallback = nr_rprims;
199
200 /* One point for every 1024 dwords (4k) of dma:
201 */
202 cost_render += (vertsz * i) / 1024;
203 cost_fallback += (vertsz * nr_rverts) / 1024;
204
205 if (0)
206 fprintf(stderr, "cost render: %d fallback: %d\n",
207 cost_render, cost_fallback);
208
209 if (cost_render > cost_fallback)
210 return GL_FALSE;
211
212 return GL_TRUE;
213 }
214
215
216 static GLboolean
217 intel_run_render(GLcontext * ctx, struct tnl_pipeline_stage *stage)
218 {
219 struct intel_context *intel = intel_context(ctx);
220 TNLcontext *tnl = TNL_CONTEXT(ctx);
221 struct vertex_buffer *VB = &tnl->vb;
222 GLuint i;
223
224 intel->vtbl.render_prevalidate( intel );
225
226 /* Don't handle clipping or indexed vertices.
227 */
228 if (intel->RenderIndex != 0 ||
229 !intel_validate_render(ctx, VB) || !choose_render(intel, VB)) {
230 return GL_TRUE;
231 }
232
233 tnl->clipspace.new_inputs |= VERT_BIT_POS;
234
235 tnl->Driver.Render.Start(ctx);
236
237 for (i = 0; i < VB->PrimitiveCount; i++) {
238 GLuint prim = _tnl_translate_prim(&VB->Primitive[i]);
239 GLuint start = VB->Primitive[i].start;
240 GLuint length = VB->Primitive[i].count;
241
242 if (!length)
243 continue;
244
245 intel_render_tab_verts[prim & PRIM_MODE_MASK] (ctx, start,
246 start + length, prim);
247 }
248
249 tnl->Driver.Render.Finish(ctx);
250
251 INTEL_FIREVERTICES(intel);
252
253 return GL_FALSE; /* finished the pipe */
254 }
255
256 static const struct tnl_pipeline_stage _intel_render_stage = {
257 "intel render",
258 NULL,
259 NULL,
260 NULL,
261 NULL,
262 intel_run_render /* run */
263 };
264
265 const struct tnl_pipeline_stage *intel_pipeline[] = {
266 &_tnl_vertex_transform_stage,
267 &_tnl_vertex_cull_stage,
268 &_tnl_normal_transform_stage,
269 &_tnl_lighting_stage,
270 &_tnl_fog_coordinate_stage,
271 &_tnl_texgen_stage,
272 &_tnl_texture_transform_stage,
273 &_tnl_point_attenuation_stage,
274 &_tnl_vertex_program_stage,
275 #if 1
276 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
277 #endif
278 &_tnl_render_stage,
279 0,
280 };