1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
26 **************************************************************************/
29 * Render unclipped vertex buffers by emitting vertices directly to
30 * dma buffers. Use strip/fan hardware acceleration where possible.
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"
40 #include "math/m_xform.h"
42 #include "tnl/t_context.h"
43 #include "tnl/t_vertex.h"
44 #include "tnl/t_pipeline.h"
46 #include "intel_screen.h"
47 #include "intel_context.h"
48 #include "intel_tris.h"
49 #include "intel_batchbuffer.h"
50 #include "intel_reg.h"
53 * Render unclipped vertex buffers by emitting vertices directly to
54 * dma buffers. Use strip/fan hardware primitives where possible.
55 * Try to simulate missing primitives with indexed vertices.
59 #define HAVE_LINE_STRIPS 1
60 #define HAVE_TRIANGLES 1
61 #define HAVE_TRI_STRIPS 1
62 #define HAVE_TRI_FANS 1
63 #define HAVE_POLYGONS 1
67 static const uint32_t hw_prim
[GL_POLYGON
+ 1] = {
68 [GL_POINTS
] = PRIM3D_POINTLIST
,
69 [GL_LINES
] = PRIM3D_LINELIST
,
70 [GL_LINE_LOOP
] = PRIM3D_LINESTRIP
,
71 [GL_LINE_STRIP
] = PRIM3D_LINESTRIP
,
72 [GL_TRIANGLES
] = PRIM3D_TRILIST
,
73 [GL_TRIANGLE_STRIP
] = PRIM3D_TRISTRIP
,
74 [GL_TRIANGLE_FAN
] = PRIM3D_TRIFAN
,
77 [GL_POLYGON
] = PRIM3D_POLY
,
80 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
81 [GL_POINTS
] = GL_POINTS
,
82 [GL_LINES
] = GL_LINES
,
83 [GL_LINE_LOOP
] = GL_LINES
,
84 [GL_LINE_STRIP
] = GL_LINES
,
85 [GL_TRIANGLES
] = GL_TRIANGLES
,
86 [GL_TRIANGLE_STRIP
] = GL_TRIANGLES
,
87 [GL_TRIANGLE_FAN
] = GL_TRIANGLES
,
88 [GL_QUADS
] = GL_TRIANGLES
,
89 [GL_QUAD_STRIP
] = GL_TRIANGLES
,
90 [GL_POLYGON
] = GL_TRIANGLES
,
93 static const int scale_prim
[GL_POLYGON
+ 1] = {
99 [GL_TRIANGLE_STRIP
] = 3,
100 [GL_TRIANGLE_FAN
] = 3,
101 [GL_QUADS
] = 0, /* fallback case */
102 [GL_QUAD_STRIP
] = 0, /* fallback case */
108 intelDmaPrimitive(struct intel_context
*intel
, GLenum prim
)
111 fprintf(stderr
, "%s %s\n", __func__
, _mesa_enum_to_string(prim
));
112 INTEL_FIREVERTICES(intel
);
113 intel
->vtbl
.reduced_primitive_state(intel
, reduced_prim
[prim
]);
114 intel_set_prim(intel
, hw_prim
[prim
]);
117 #define INTEL_NO_VBO_STATE_RESERVED 1500
119 static inline GLuint
intel_get_vb_max(struct intel_context
*intel
)
123 if (intel
->intelScreen
->no_vbo
) {
124 ret
= intel
->batch
.bo
->size
- INTEL_NO_VBO_STATE_RESERVED
;
127 ret
/= (intel
->vertex_size
* 4);
131 static inline GLuint
intel_get_current_max(struct intel_context
*intel
)
135 if (intel
->intelScreen
->no_vbo
) {
136 ret
= intel_batchbuffer_space(intel
);
137 ret
= ret
<= INTEL_NO_VBO_STATE_RESERVED
? 0 : ret
- INTEL_NO_VBO_STATE_RESERVED
;
139 ret
= (INTEL_VB_SIZE
- intel
->prim
.current_offset
);
141 return ret
/ (intel
->vertex_size
* 4);
144 #define LOCAL_VARS struct intel_context *intel = intel_context(ctx)
145 #define INIT( prim ) \
147 intelDmaPrimitive( intel, prim ); \
150 #define FLUSH() INTEL_FIREVERTICES(intel)
152 #define GET_SUBSEQUENT_VB_MAX_VERTS() intel_get_vb_max(intel)
153 #define GET_CURRENT_VB_MAX_VERTS() intel_get_current_max(intel)
155 #define ALLOC_VERTS(nr) intel_get_prim_space(intel, nr)
157 #define EMIT_VERTS( ctx, j, nr, buf ) \
158 _tnl_emit_vertices_to_buffer(ctx, j, (j)+(nr), buf )
160 #define TAG(x) intel_##x
161 #include "tnl_dd/t_dd_dmatmp.h"
164 /**********************************************************************/
165 /* Render pipeline stage */
166 /**********************************************************************/
168 /* Heuristic to choose between the two render paths:
171 choose_render(struct intel_context
*intel
, struct vertex_buffer
*VB
)
173 int vertsz
= intel
->vertex_size
;
175 int cost_fallback
= 0;
179 int rprim
= intel
->reduced_primitive
;
182 for (i
= 0; i
< VB
->PrimitiveCount
; i
++) {
183 GLuint prim
= VB
->Primitive
[i
].mode
;
184 GLuint length
= VB
->Primitive
[i
].count
;
190 nr_rverts
+= length
* scale_prim
[prim
& PRIM_MODE_MASK
];
192 if (reduced_prim
[prim
& PRIM_MODE_MASK
] != rprim
) {
194 rprim
= reduced_prim
[prim
& PRIM_MODE_MASK
];
198 /* One point for each generated primitive:
200 cost_render
= nr_prims
;
201 cost_fallback
= nr_rprims
;
203 /* One point for every 1024 dwords (4k) of dma:
205 cost_render
+= (vertsz
* i
) / 1024;
206 cost_fallback
+= (vertsz
* nr_rverts
) / 1024;
209 fprintf(stderr
, "cost render: %d fallback: %d\n",
210 cost_render
, cost_fallback
);
212 if (cost_render
> cost_fallback
)
220 intel_run_render(struct gl_context
* ctx
, struct tnl_pipeline_stage
*stage
)
222 struct intel_context
*intel
= intel_context(ctx
);
223 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
224 struct vertex_buffer
*VB
= &tnl
->vb
;
227 intel
->vtbl
.render_prevalidate( intel
);
229 /* Don't handle clipping or indexed vertices.
231 if (intel
->RenderIndex
!= 0 ||
232 !intel_validate_render(ctx
, VB
) || !choose_render(intel
, VB
)) {
236 tnl
->clipspace
.new_inputs
|= VERT_BIT_POS
;
238 tnl
->Driver
.Render
.Start(ctx
);
240 for (i
= 0; i
< VB
->PrimitiveCount
; i
++) {
241 GLuint prim
= _tnl_translate_prim(&VB
->Primitive
[i
]);
242 GLuint start
= VB
->Primitive
[i
].start
;
243 GLuint length
= VB
->Primitive
[i
].count
;
248 intel_render_tab_verts
[prim
& PRIM_MODE_MASK
] (ctx
, start
,
252 tnl
->Driver
.Render
.Finish(ctx
);
254 INTEL_FIREVERTICES(intel
);
256 return false; /* finished the pipe */
259 static const struct tnl_pipeline_stage _intel_render_stage
= {
265 intel_run_render
/* run */
268 const struct tnl_pipeline_stage
*intel_pipeline
[] = {
269 &_tnl_vertex_transform_stage
,
270 &_tnl_normal_transform_stage
,
271 &_tnl_lighting_stage
,
272 &_tnl_fog_coordinate_stage
,
274 &_tnl_texture_transform_stage
,
275 &_tnl_point_attenuation_stage
,
276 &_tnl_vertex_program_stage
,
278 &_intel_render_stage
, /* ADD: unclipped rastersetup-to-dma */