1 /**************************************************************************
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "main/glheader.h"
36 #include "main/mtypes.h"
37 #include "main/colormac.h"
38 #include "main/enums.h"
39 #include "main/imports.h"
40 #include "main/macros.h"
41 #include "main/simple_list.h"
43 #include "swrast_setup/swrast_setup.h"
44 #include "math/m_translate.h"
46 #include "tnl/t_context.h"
47 #include "tnl/t_pipeline.h"
49 #include "radeon_context.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_state.h"
52 #include "radeon_swtcl.h"
53 #include "radeon_tcl.h"
56 /* R100: xyzw, c0, c1/fog, stq[0..2] = 4+1+1+3*3 = 15 right? */
57 /* R200: xyzw, c0, c1/fog, strq[0..5] = 4+1+1+4*6 = 30 */
58 #define RADEON_MAX_TNL_VERTEX_SIZE (15 * sizeof(GLfloat)) /* for mesa _tnl stage */
60 /***********************************************************************
62 ***********************************************************************/
64 #define EMIT_ATTR( ATTR, STYLE, F0 ) \
66 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
67 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
68 rmesa->radeon.swtcl.vertex_attr_count++; \
72 #define EMIT_PAD( N ) \
74 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
75 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
76 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
77 rmesa->radeon.swtcl.vertex_attr_count++; \
80 static GLuint radeon_cp_vc_frmts
[3][2] =
82 { RADEON_CP_VC_FRMT_ST0
, RADEON_CP_VC_FRMT_ST0
| RADEON_CP_VC_FRMT_Q0
},
83 { RADEON_CP_VC_FRMT_ST1
, RADEON_CP_VC_FRMT_ST1
| RADEON_CP_VC_FRMT_Q1
},
84 { RADEON_CP_VC_FRMT_ST2
, RADEON_CP_VC_FRMT_ST2
| RADEON_CP_VC_FRMT_Q2
},
87 static void radeonSetVertexFormat( GLcontext
*ctx
)
89 r100ContextPtr rmesa
= R100_CONTEXT( ctx
);
90 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
91 struct vertex_buffer
*VB
= &tnl
->vb
;
92 DECLARE_RENDERINPUTS(index_bitset
);
96 RENDERINPUTS_COPY( index_bitset
, tnl
->render_inputs_bitset
);
100 if ( VB
->NdcPtr
!= NULL
) {
101 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
104 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
107 assert( VB
->AttribPtr
[VERT_ATTRIB_POS
] != NULL
);
108 rmesa
->radeon
.swtcl
.vertex_attr_count
= 0;
110 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
111 * build up a hardware vertex.
113 if ( !rmesa
->swtcl
.needproj
||
114 RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) { /* for projtex */
115 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
,
116 RADEON_CP_VC_FRMT_XY
| RADEON_CP_VC_FRMT_Z
| RADEON_CP_VC_FRMT_W0
);
120 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_3F
,
121 RADEON_CP_VC_FRMT_XY
| RADEON_CP_VC_FRMT_Z
);
125 rmesa
->swtcl
.coloroffset
= offset
;
126 #if MESA_LITTLE_ENDIAN
127 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_RGBA
,
128 RADEON_CP_VC_FRMT_PKCOLOR
);
130 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_ABGR
,
131 RADEON_CP_VC_FRMT_PKCOLOR
);
135 rmesa
->swtcl
.specoffset
= 0;
136 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
) ||
137 RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
139 #if MESA_LITTLE_ENDIAN
140 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
141 rmesa
->swtcl
.specoffset
= offset
;
142 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_RGB
,
143 RADEON_CP_VC_FRMT_PKSPEC
);
149 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
150 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1UB_1F
,
151 RADEON_CP_VC_FRMT_PKSPEC
);
157 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
158 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1UB_1F
,
159 RADEON_CP_VC_FRMT_PKSPEC
);
165 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
166 rmesa
->swtcl
.specoffset
= offset
;
167 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_BGR
,
168 RADEON_CP_VC_FRMT_PKSPEC
);
176 if (RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
179 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
180 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_TEX(i
) )) {
181 GLuint sz
= VB
->TexCoordPtr
[i
]->size
;
186 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_2F
,
187 radeon_cp_vc_frmts
[i
][0] );
191 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
& (TEXTURE_CUBE_BIT
) ) {
192 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_3F
,
193 radeon_cp_vc_frmts
[i
][1] );
195 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_3F_XYW
,
196 radeon_cp_vc_frmts
[i
][1] );
206 if (!RENDERINPUTS_EQUAL( rmesa
->radeon
.tnl_index_bitset
, index_bitset
) ||
207 fmt_0
!= rmesa
->swtcl
.vertex_format
) {
208 RADEON_NEWPRIM(rmesa
);
209 rmesa
->swtcl
.vertex_format
= fmt_0
;
210 rmesa
->radeon
.swtcl
.vertex_size
=
211 _tnl_install_attrs( ctx
,
212 rmesa
->radeon
.swtcl
.vertex_attrs
,
213 rmesa
->radeon
.swtcl
.vertex_attr_count
,
215 rmesa
->radeon
.swtcl
.vertex_size
/= 4;
216 RENDERINPUTS_COPY( rmesa
->radeon
.tnl_index_bitset
, index_bitset
);
217 if (RADEON_DEBUG
& DEBUG_VERTS
)
218 fprintf( stderr
, "%s: vertex_size= %d floats\n",
219 __FUNCTION__
, rmesa
->radeon
.swtcl
.vertex_size
);
224 static void radeonRenderStart( GLcontext
*ctx
)
226 r100ContextPtr rmesa
= R100_CONTEXT( ctx
);
228 radeonSetVertexFormat( ctx
);
230 if (rmesa
->radeon
.dma
.flush
!= 0 &&
231 rmesa
->radeon
.dma
.flush
!= rcommon_flush_last_swtcl_prim
)
232 rmesa
->radeon
.dma
.flush( ctx
);
234 if (!rmesa
->radeon
.swtcl
.primitive_counter
) {
235 if (rcommonEnsureCmdBufSpace(&rmesa
->radeon
,
236 radeonCountStateEmitSize( &rmesa
->radeon
) +
237 (8 + 8 + 7), /* scissor + primis + VertexAOS */
239 rmesa
->radeon
.swtcl
.primitive_counter
= 0;
241 rmesa
->radeon
.swtcl
.primitive_counter
= 1;
247 * Set vertex state for SW TCL. The primary purpose of this function is to
248 * determine in advance whether or not the hardware can / should do the
249 * projection divide or Mesa should do it.
251 void radeonChooseVertexState( GLcontext
*ctx
)
253 r100ContextPtr rmesa
= R100_CONTEXT( ctx
);
254 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
256 GLuint se_coord_fmt
= rmesa
->hw
.set
.cmd
[SET_SE_COORDFMT
];
258 se_coord_fmt
&= ~(RADEON_VTX_XY_PRE_MULT_1_OVER_W0
|
259 RADEON_VTX_Z_PRE_MULT_1_OVER_W0
|
260 RADEON_VTX_W0_IS_NOT_1_OVER_W0
);
262 /* We must ensure that we don't do _tnl_need_projected_coords while in a
263 * rasterization fallback. As this function will be called again when we
264 * leave a rasterization fallback, we can just skip it for now.
266 if (rmesa
->radeon
.Fallback
!= 0)
269 /* HW perspective divide is a win, but tiny vertex formats are a
273 if ((!RENDERINPUTS_TEST_RANGE( tnl
->render_inputs_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
) &&
274 !RENDERINPUTS_TEST( tnl
->render_inputs_bitset
, _TNL_ATTRIB_COLOR1
))
275 || (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
276 rmesa
->swtcl
.needproj
= GL_TRUE
;
277 se_coord_fmt
|= (RADEON_VTX_XY_PRE_MULT_1_OVER_W0
|
278 RADEON_VTX_Z_PRE_MULT_1_OVER_W0
);
281 rmesa
->swtcl
.needproj
= GL_FALSE
;
282 se_coord_fmt
|= (RADEON_VTX_W0_IS_NOT_1_OVER_W0
);
285 _tnl_need_projected_coords( ctx
, rmesa
->swtcl
.needproj
);
287 if ( se_coord_fmt
!= rmesa
->hw
.set
.cmd
[SET_SE_COORDFMT
] ) {
288 RADEON_STATECHANGE( rmesa
, set
);
289 rmesa
->hw
.set
.cmd
[SET_SE_COORDFMT
] = se_coord_fmt
;
293 void r100_swtcl_flush(GLcontext
*ctx
, uint32_t current_offset
)
295 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
299 radeonEmitState(&rmesa
->radeon
);
300 radeonEmitVertexAOS( rmesa
,
301 rmesa
->radeon
.swtcl
.vertex_size
,
302 first_elem(&rmesa
->radeon
.dma
.reserved
)->bo
,
306 radeonEmitVbufPrim( rmesa
,
307 rmesa
->swtcl
.vertex_format
,
308 rmesa
->radeon
.swtcl
.hw_primitive
,
309 rmesa
->radeon
.swtcl
.numverts
);
312 rmesa
->radeon
.swtcl
.primitive_counter
= 0;
317 * Render unclipped vertex buffers by emitting vertices directly to
318 * dma buffers. Use strip/fan hardware primitives where possible.
319 * Try to simulate missing primitives with indexed vertices.
321 #define HAVE_POINTS 1
323 #define HAVE_LINE_STRIPS 1
324 #define HAVE_TRIANGLES 1
325 #define HAVE_TRI_STRIPS 1
326 #define HAVE_TRI_STRIP_1 0
327 #define HAVE_TRI_FANS 1
329 #define HAVE_QUAD_STRIPS 0
330 #define HAVE_POLYGONS 0
331 /* \todo: is it possible to make "ELTS" work with t_vertex code ? */
334 static const GLuint hw_prim
[GL_POLYGON
+1] = {
335 RADEON_CP_VC_CNTL_PRIM_TYPE_POINT
,
336 RADEON_CP_VC_CNTL_PRIM_TYPE_LINE
,
338 RADEON_CP_VC_CNTL_PRIM_TYPE_LINE_STRIP
,
339 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
,
340 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_STRIP
,
341 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_FAN
,
348 radeonDmaPrimitive( r100ContextPtr rmesa
, GLenum prim
)
350 RADEON_NEWPRIM( rmesa
);
351 rmesa
->radeon
.swtcl
.hw_primitive
= hw_prim
[prim
];
352 // assert(rmesa->radeon.dma.current.ptr == rmesa->radeon.dma.current.start);
355 #define LOCAL_VARS r100ContextPtr rmesa = R100_CONTEXT(ctx)
356 #define INIT( prim ) radeonDmaPrimitive( rmesa, prim )
357 #define FLUSH() RADEON_NEWPRIM( rmesa )
358 #define GET_CURRENT_VB_MAX_VERTS() 10\
359 // (((int)rmesa->radeon.dma.current.end - (int)rmesa->radeon.dma.current.ptr) / (rmesa->radeon.swtcl.vertex_size*4))
360 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
361 ((RADEON_BUFFER_SIZE) / (rmesa->radeon.swtcl.vertex_size*4))
362 #define ALLOC_VERTS( nr ) \
363 rcommonAllocDmaLowVerts( &rmesa->radeon, nr, rmesa->radeon.swtcl.vertex_size * 4 )
364 #define EMIT_VERTS( ctx, j, nr, buf ) \
365 _tnl_emit_vertices_to_buffer(ctx, j, (j)+(nr), buf)
367 #define TAG(x) radeon_dma_##x
368 #include "tnl_dd/t_dd_dmatmp.h"
371 /**********************************************************************/
372 /* Render pipeline stage */
373 /**********************************************************************/
376 static GLboolean
radeon_run_render( GLcontext
*ctx
,
377 struct tnl_pipeline_stage
*stage
)
379 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
380 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
381 struct vertex_buffer
*VB
= &tnl
->vb
;
382 tnl_render_func
*tab
= TAG(render_tab_verts
);
385 if (rmesa
->radeon
.swtcl
.RenderIndex
!= 0 ||
386 !radeon_dma_validate_render( ctx
, VB
))
389 tnl
->Driver
.Render
.Start( ctx
);
391 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
393 GLuint prim
= VB
->Primitive
[i
].mode
;
394 GLuint start
= VB
->Primitive
[i
].start
;
395 GLuint length
= VB
->Primitive
[i
].count
;
400 if (RADEON_DEBUG
& DEBUG_PRIMS
)
401 fprintf(stderr
, "radeon_render.c: prim %s %d..%d\n",
402 _mesa_lookup_enum_by_nr(prim
& PRIM_MODE_MASK
),
403 start
, start
+length
);
406 tab
[prim
& PRIM_MODE_MASK
]( ctx
, start
, start
+ length
, prim
);
409 tnl
->Driver
.Render
.Finish( ctx
);
411 return GL_FALSE
; /* finished the pipe */
416 const struct tnl_pipeline_stage _radeon_render_stage
=
423 radeon_run_render
/* run */
427 /**************************************************************************/
430 static const GLuint reduced_hw_prim
[GL_POLYGON
+1] = {
431 RADEON_CP_VC_CNTL_PRIM_TYPE_POINT
,
432 RADEON_CP_VC_CNTL_PRIM_TYPE_LINE
,
433 RADEON_CP_VC_CNTL_PRIM_TYPE_LINE
,
434 RADEON_CP_VC_CNTL_PRIM_TYPE_LINE
,
435 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
,
436 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
,
437 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
,
438 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
,
439 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
,
440 RADEON_CP_VC_CNTL_PRIM_TYPE_TRI_LIST
443 static void radeonRasterPrimitive( GLcontext
*ctx
, GLuint hwprim
);
444 static void radeonRenderPrimitive( GLcontext
*ctx
, GLenum prim
);
445 static void radeonResetLineStipple( GLcontext
*ctx
);
448 /***********************************************************************
449 * Emit primitives as inline vertices *
450 ***********************************************************************/
454 #define CTX_ARG r100ContextPtr rmesa
455 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
456 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, (size) * 4 )
459 r100ContextPtr rmesa = R100_CONTEXT(ctx); \
460 const char *radeonverts = (char *)rmesa->radeon.swtcl.verts;
461 #define VERT(x) (radeonVertex *)(radeonverts + ((x) * (vertsize) * sizeof(int)))
462 #define VERTEX radeonVertex
464 #define TAG(x) radeon_##x
465 #include "tnl_dd/t_dd_triemit.h"
468 /***********************************************************************
469 * Macros for t_dd_tritmp.h to draw basic primitives *
470 ***********************************************************************/
472 #define QUAD( a, b, c, d ) radeon_quad( rmesa, a, b, c, d )
473 #define TRI( a, b, c ) radeon_triangle( rmesa, a, b, c )
474 #define LINE( a, b ) radeon_line( rmesa, a, b )
475 #define POINT( a ) radeon_point( rmesa, a )
477 /***********************************************************************
478 * Build render functions from dd templates *
479 ***********************************************************************/
481 #define RADEON_TWOSIDE_BIT 0x01
482 #define RADEON_UNFILLED_BIT 0x02
483 #define RADEON_MAX_TRIFUNC 0x04
487 tnl_points_func points
;
489 tnl_triangle_func triangle
;
491 } rast_tab
[RADEON_MAX_TRIFUNC
];
494 #define DO_FALLBACK 0
496 #define DO_UNFILLED (IND & RADEON_UNFILLED_BIT)
497 #define DO_TWOSIDE (IND & RADEON_TWOSIDE_BIT)
503 #define DO_FULL_QUAD 1
507 #define HAVE_BACK_COLORS 0
508 #define HAVE_HW_FLATSHADE 1
511 #define DEPTH_SCALE 1.0
512 #define UNFILLED_TRI unfilled_tri
513 #define UNFILLED_QUAD unfilled_quad
514 #define VERT_X(_v) _v->v.x
515 #define VERT_Y(_v) _v->v.y
516 #define VERT_Z(_v) _v->v.z
517 #define AREA_IS_CCW( a ) (a < 0)
518 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + ((e) * rmesa->radeon.swtcl.vertex_size * sizeof(int)))
520 #define VERT_SET_RGBA( v, c ) \
522 radeon_color_t *color = (radeon_color_t *)&((v)->ui[coloroffset]); \
523 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
524 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
525 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
526 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
529 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
531 #define VERT_SET_SPEC( v, c ) \
534 radeon_color_t *spec = (radeon_color_t *)&((v)->ui[specoffset]); \
535 UNCLAMPED_FLOAT_TO_UBYTE(spec->red, (c)[0]); \
536 UNCLAMPED_FLOAT_TO_UBYTE(spec->green, (c)[1]); \
537 UNCLAMPED_FLOAT_TO_UBYTE(spec->blue, (c)[2]); \
540 #define VERT_COPY_SPEC( v0, v1 ) \
543 radeon_color_t *spec0 = (radeon_color_t *)&((v0)->ui[specoffset]); \
544 radeon_color_t *spec1 = (radeon_color_t *)&((v1)->ui[specoffset]); \
545 spec0->red = spec1->red; \
546 spec0->green = spec1->green; \
547 spec0->blue = spec1->blue; \
551 /* These don't need LE32_TO_CPU() as they used to save and restore
552 * colors which are already in the correct format.
554 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
555 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
556 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
557 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
563 #define LOCAL_VARS(n) \
564 r100ContextPtr rmesa = R100_CONTEXT(ctx); \
565 GLuint color[n] = {0}, spec[n] = {0}; \
566 GLuint coloroffset = rmesa->swtcl.coloroffset; \
567 GLuint specoffset = rmesa->swtcl.specoffset; \
568 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
570 /***********************************************************************
571 * Helpers for rendering unfilled primitives *
572 ***********************************************************************/
574 #define RASTERIZE(x) radeonRasterPrimitive( ctx, reduced_hw_prim[x] )
575 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
578 #include "tnl_dd/t_dd_unfilled.h"
582 /***********************************************************************
583 * Generate GL render functions *
584 ***********************************************************************/
589 #include "tnl_dd/t_dd_tritmp.h"
591 #define IND (RADEON_TWOSIDE_BIT)
592 #define TAG(x) x##_twoside
593 #include "tnl_dd/t_dd_tritmp.h"
595 #define IND (RADEON_UNFILLED_BIT)
596 #define TAG(x) x##_unfilled
597 #include "tnl_dd/t_dd_tritmp.h"
599 #define IND (RADEON_TWOSIDE_BIT|RADEON_UNFILLED_BIT)
600 #define TAG(x) x##_twoside_unfilled
601 #include "tnl_dd/t_dd_tritmp.h"
604 static void init_rast_tab( void )
609 init_twoside_unfilled();
612 /**********************************************************************/
613 /* Render unclipped begin/end objects */
614 /**********************************************************************/
616 #define RENDER_POINTS( start, count ) \
617 for ( ; start < count ; start++) \
618 radeon_point( rmesa, VERT(start) )
619 #define RENDER_LINE( v0, v1 ) \
620 radeon_line( rmesa, VERT(v0), VERT(v1) )
621 #define RENDER_TRI( v0, v1, v2 ) \
622 radeon_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
623 #define RENDER_QUAD( v0, v1, v2, v3 ) \
624 radeon_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
626 #define INIT(x) do { \
627 radeonRenderPrimitive( ctx, x ); \
631 r100ContextPtr rmesa = R100_CONTEXT(ctx); \
632 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
633 const char *radeonverts = (char *)rmesa->radeon.swtcl.verts; \
634 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
635 const GLboolean stipple = ctx->Line.StippleFlag; \
636 (void) elt; (void) stipple;
637 #define RESET_STIPPLE if ( stipple ) radeonResetLineStipple( ctx );
638 #define RESET_OCCLUSION
639 #define PRESERVE_VB_DEFS
641 #define TAG(x) radeon_##x##_verts
642 #include "tnl/t_vb_rendertmp.h"
645 #define TAG(x) radeon_##x##_elts
646 #define ELT(x) elt[x]
647 #include "tnl/t_vb_rendertmp.h"
651 /**********************************************************************/
652 /* Choose render functions */
653 /**********************************************************************/
655 void radeonChooseRenderState( GLcontext
*ctx
)
657 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
658 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
660 GLuint flags
= ctx
->_TriangleCaps
;
662 if (!rmesa
->radeon
.TclFallback
|| rmesa
->radeon
.Fallback
)
665 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= RADEON_TWOSIDE_BIT
;
666 if (flags
& DD_TRI_UNFILLED
) index
|= RADEON_UNFILLED_BIT
;
668 if (index
!= rmesa
->radeon
.swtcl
.RenderIndex
) {
669 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
670 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
671 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
672 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
673 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
676 tnl
->Driver
.Render
.PrimTabVerts
= radeon_render_tab_verts
;
677 tnl
->Driver
.Render
.PrimTabElts
= radeon_render_tab_elts
;
678 tnl
->Driver
.Render
.ClippedPolygon
= radeon_fast_clipped_poly
;
680 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
681 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
682 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
685 rmesa
->radeon
.swtcl
.RenderIndex
= index
;
690 /**********************************************************************/
691 /* High level hooks for t_vb_render.c */
692 /**********************************************************************/
695 static void radeonRasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
697 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
699 if (rmesa
->radeon
.swtcl
.hw_primitive
!= hwprim
) {
700 RADEON_NEWPRIM( rmesa
);
701 rmesa
->radeon
.swtcl
.hw_primitive
= hwprim
;
705 static void radeonRenderPrimitive( GLcontext
*ctx
, GLenum prim
)
707 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
708 rmesa
->radeon
.swtcl
.render_primitive
= prim
;
709 if (prim
< GL_TRIANGLES
|| !(ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
710 radeonRasterPrimitive( ctx
, reduced_hw_prim
[prim
] );
713 static void radeonRenderFinish( GLcontext
*ctx
)
717 static void radeonResetLineStipple( GLcontext
*ctx
)
719 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
720 RADEON_STATECHANGE( rmesa
, lin
);
724 /**********************************************************************/
725 /* Transition to/from hardware rasterization. */
726 /**********************************************************************/
728 static const char * const fallbackStrings
[] = {
730 "glDrawBuffer(GL_FRONT_AND_BACK)",
731 "glEnable(GL_STENCIL) without hw stencil buffer",
732 "glRenderMode(selection or feedback)",
736 "Mixing GL_CLAMP_TO_BORDER and GL_CLAMP (or GL_MIRROR_CLAMP_ATI)"
740 static const char *getFallbackString(GLuint bit
)
747 return fallbackStrings
[i
];
751 void radeonFallback( GLcontext
*ctx
, GLuint bit
, GLboolean mode
)
753 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
754 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
755 GLuint oldfallback
= rmesa
->radeon
.Fallback
;
758 rmesa
->radeon
.Fallback
|= bit
;
759 if (oldfallback
== 0) {
760 radeon_firevertices(&rmesa
->radeon
);
761 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_RASTER
, GL_TRUE
);
762 _swsetup_Wakeup( ctx
);
763 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
764 if (RADEON_DEBUG
& DEBUG_FALLBACKS
) {
765 fprintf(stderr
, "Radeon begin rasterization fallback: 0x%x %s\n",
766 bit
, getFallbackString(bit
));
771 rmesa
->radeon
.Fallback
&= ~bit
;
772 if (oldfallback
== bit
) {
773 _swrast_flush( ctx
);
774 tnl
->Driver
.Render
.Start
= radeonRenderStart
;
775 tnl
->Driver
.Render
.PrimitiveNotify
= radeonRenderPrimitive
;
776 tnl
->Driver
.Render
.Finish
= radeonRenderFinish
;
778 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
779 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
780 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
782 tnl
->Driver
.Render
.ResetLineStipple
= radeonResetLineStipple
;
783 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_RASTER
, GL_FALSE
);
784 if (rmesa
->radeon
.TclFallback
) {
785 /* These are already done if rmesa->radeon.TclFallback goes to
786 * zero above. But not if it doesn't (RADEON_NO_TCL for
789 _tnl_invalidate_vertex_state( ctx
, ~0 );
790 _tnl_invalidate_vertices( ctx
, ~0 );
791 RENDERINPUTS_ZERO( rmesa
->radeon
.tnl_index_bitset
);
792 radeonChooseVertexState( ctx
);
793 radeonChooseRenderState( ctx
);
795 if (RADEON_DEBUG
& DEBUG_FALLBACKS
) {
796 fprintf(stderr
, "Radeon end rasterization fallback: 0x%x %s\n",
797 bit
, getFallbackString(bit
));
804 /**********************************************************************/
805 /* Initialization. */
806 /**********************************************************************/
808 void radeonInitSwtcl( GLcontext
*ctx
)
810 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
811 r100ContextPtr rmesa
= R100_CONTEXT(ctx
);
812 static int firsttime
= 1;
817 rmesa
->radeon
.swtcl
.primitive_counter
= 0;
820 tnl
->Driver
.Render
.Start
= radeonRenderStart
;
821 tnl
->Driver
.Render
.Finish
= radeonRenderFinish
;
822 tnl
->Driver
.Render
.PrimitiveNotify
= radeonRenderPrimitive
;
823 tnl
->Driver
.Render
.ResetLineStipple
= radeonResetLineStipple
;
824 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
825 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
826 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
828 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
829 RADEON_MAX_TNL_VERTEX_SIZE
);
831 rmesa
->radeon
.swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
832 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
833 rmesa
->radeon
.swtcl
.render_primitive
= GL_TRIANGLES
;
834 rmesa
->radeon
.swtcl
.hw_primitive
= 0;