1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
26 **************************************************************************/
29 * Render unclipped vertex buffers by emitting vertices directly to
30 * dma buffers. Use strip/fan hardware acceleration where possible.
40 #include "tnl/t_context.h"
41 #include "tnl/t_vertex.h"
43 #include "intel_screen.h"
44 #include "intel_context.h"
45 #include "intel_tris.h"
46 #include "intel_batchbuffer.h"
47 #include "intel_reg.h"
50 * Render unclipped vertex buffers by emitting vertices directly to
51 * dma buffers. Use strip/fan hardware primitives where possible.
52 * Try to simulate missing primitives with indexed vertices.
54 #define HAVE_POINTS 0 /* Has it, but can't use because subpixel has to
55 * be adjusted for points on the INTEL/I845G
58 #define HAVE_LINE_STRIPS 1
59 #define HAVE_TRIANGLES 1
60 #define HAVE_TRI_STRIPS 1
61 #define HAVE_TRI_STRIP_1 0 /* has it, template can't use it yet */
62 #define HAVE_TRI_FANS 1
63 #define HAVE_POLYGONS 1
65 #define HAVE_QUAD_STRIPS 0
69 static GLuint hw_prim
[GL_POLYGON
+ 1] = {
82 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
95 static const int scale_prim
[GL_POLYGON
+ 1] = {
96 0, /* fallback case */
103 0, /* fallback case */
104 0, /* fallback case */
110 intelDmaPrimitive(struct intel_context
*intel
, GLenum prim
)
113 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
114 INTEL_FIREVERTICES(intel
);
115 intel
->vtbl
.reduced_primitive_state(intel
, reduced_prim
[prim
]);
116 intelStartInlinePrimitive(intel
, hw_prim
[prim
], INTEL_BATCH_CLIPRECTS
);
120 #define LOCAL_VARS struct intel_context *intel = intel_context(ctx)
121 #define INIT( prim ) \
123 intelDmaPrimitive( intel, prim ); \
126 #define FLUSH() INTEL_FIREVERTICES(intel)
128 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
129 ((intel->batch->size - 1500) / (intel->vertex_size*4))
130 #define GET_CURRENT_VB_MAX_VERTS() GET_SUBSEQUENT_VB_MAX_VERTS()
132 #define ALLOC_VERTS( nr ) \
133 intelExtendInlinePrimitive( intel, (nr) * intel->vertex_size )
135 #define EMIT_VERTS( ctx, j, nr, buf ) \
136 _tnl_emit_vertices_to_buffer(ctx, j, (j)+(nr), buf )
138 #define TAG(x) intel_##x
139 #include "tnl_dd/t_dd_dmatmp.h"
142 /**********************************************************************/
143 /* Render pipeline stage */
144 /**********************************************************************/
146 /* Heuristic to choose between the two render paths:
149 choose_render(struct intel_context
*intel
, struct vertex_buffer
*VB
)
151 int vertsz
= intel
->vertex_size
;
153 int cost_fallback
= 0;
157 int rprim
= intel
->reduced_primitive
;
160 for (i
= 0; i
< VB
->PrimitiveCount
; i
++) {
161 GLuint prim
= VB
->Primitive
[i
].mode
;
162 GLuint length
= VB
->Primitive
[i
].count
;
168 nr_rverts
+= length
* scale_prim
[prim
& PRIM_MODE_MASK
];
170 if (reduced_prim
[prim
& PRIM_MODE_MASK
] != rprim
) {
172 rprim
= reduced_prim
[prim
& PRIM_MODE_MASK
];
176 /* One point for each generated primitive:
178 cost_render
= nr_prims
;
179 cost_fallback
= nr_rprims
;
181 /* One point for every 1024 dwords (4k) of dma:
183 cost_render
+= (vertsz
* i
) / 1024;
184 cost_fallback
+= (vertsz
* nr_rverts
) / 1024;
187 fprintf(stderr
, "cost render: %d fallback: %d\n",
188 cost_render
, cost_fallback
);
190 if (cost_render
> cost_fallback
)
198 intel_run_render(GLcontext
* ctx
, struct tnl_pipeline_stage
*stage
)
200 struct intel_context
*intel
= intel_context(ctx
);
201 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
202 struct vertex_buffer
*VB
= &tnl
->vb
;
205 intel
->vtbl
.render_prevalidate( intel
);
207 /* Don't handle clipping or indexed vertices.
209 if (intel
->RenderIndex
!= 0 ||
210 !intel_validate_render(ctx
, VB
) || !choose_render(intel
, VB
)) {
214 tnl
->clipspace
.new_inputs
|= VERT_BIT_POS
;
216 tnl
->Driver
.Render
.Start(ctx
);
218 for (i
= 0; i
< VB
->PrimitiveCount
; i
++) {
219 GLuint prim
= _tnl_translate_prim(&VB
->Primitive
[i
]);
220 GLuint start
= VB
->Primitive
[i
].start
;
221 GLuint length
= VB
->Primitive
[i
].count
;
226 intel_render_tab_verts
[prim
& PRIM_MODE_MASK
] (ctx
, start
,
227 start
+ length
, prim
);
230 tnl
->Driver
.Render
.Finish(ctx
);
232 INTEL_FIREVERTICES(intel
);
234 return GL_FALSE
; /* finished the pipe */
237 const struct tnl_pipeline_stage _intel_render_stage
= {
243 intel_run_render
/* run */