2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
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/image.h"
40 #include "main/imports.h"
41 #include "main/macros.h"
43 #include "swrast/s_context.h"
44 #include "swrast/s_fog.h"
45 #include "swrast_setup/swrast_setup.h"
46 #include "math/m_translate.h"
48 #include "tnl/t_context.h"
49 #include "tnl/t_pipeline.h"
51 #include "radeon_bo.h"
52 #include "r200_context.h"
53 #include "r200_ioctl.h"
54 #include "r200_state.h"
55 #include "r200_swtcl.h"
59 static void flush_last_swtcl_prim( GLcontext
*ctx
);
62 /***********************************************************************
64 ***********************************************************************/
66 #define EMIT_ATTR( ATTR, STYLE, F0 ) \
68 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = (ATTR); \
69 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = (STYLE); \
70 rmesa->swtcl.vertex_attr_count++; \
74 #define EMIT_PAD( N ) \
76 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = 0; \
77 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = EMIT_PAD; \
78 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].offset = (N); \
79 rmesa->swtcl.vertex_attr_count++; \
82 static void r200SetVertexFormat( GLcontext
*ctx
)
84 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
85 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
86 struct vertex_buffer
*VB
= &tnl
->vb
;
87 DECLARE_RENDERINPUTS(index_bitset
);
92 RENDERINPUTS_COPY( index_bitset
, tnl
->render_inputs_bitset
);
96 if ( VB
->NdcPtr
!= NULL
) {
97 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
100 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
103 assert( VB
->AttribPtr
[VERT_ATTRIB_POS
] != NULL
);
104 rmesa
->swtcl
.vertex_attr_count
= 0;
106 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
107 * build up a hardware vertex.
109 if ( !rmesa
->swtcl
.needproj
||
110 RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) { /* need w coord for projected textures */
111 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
, R200_VTX_XY
| R200_VTX_Z0
| R200_VTX_W0
);
115 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_3F
, R200_VTX_XY
| R200_VTX_Z0
);
119 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
120 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
, R200_VTX_POINT_SIZE
);
124 rmesa
->swtcl
.coloroffset
= offset
;
125 #if MESA_LITTLE_ENDIAN
126 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_RGBA
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_0_SHIFT
) );
128 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_ABGR
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_0_SHIFT
) );
132 rmesa
->swtcl
.specoffset
= 0;
133 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
) ||
134 RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
136 #if MESA_LITTLE_ENDIAN
137 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
138 rmesa
->swtcl
.specoffset
= offset
;
139 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_RGB
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
145 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
146 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1UB_1F
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
152 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
153 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1UB_1F
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
159 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
160 rmesa
->swtcl
.specoffset
= offset
;
161 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_BGR
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
169 if (RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
172 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
173 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_TEX(i
) )) {
174 GLuint sz
= VB
->TexCoordPtr
[i
]->size
;
176 fmt_1
|= sz
<< (3 * i
);
177 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_1F
+ sz
- 1, 0 );
182 if ( (rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] & R200_FOG_USE_MASK
)
183 != R200_FOG_USE_SPEC_ALPHA
) {
184 R200_STATECHANGE( rmesa
, ctx
);
185 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] &= ~R200_FOG_USE_MASK
;
186 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] |= R200_FOG_USE_SPEC_ALPHA
;
189 if (!RENDERINPUTS_EQUAL( rmesa
->radeon
.tnl_index_bitset
, index_bitset
) ||
190 (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] != fmt_0
) ||
191 (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] != fmt_1
) ) {
193 R200_STATECHANGE( rmesa
, vtx
);
194 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] = fmt_0
;
195 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] = fmt_1
;
197 rmesa
->swtcl
.vertex_size
=
198 _tnl_install_attrs( ctx
,
199 rmesa
->swtcl
.vertex_attrs
,
200 rmesa
->swtcl
.vertex_attr_count
,
202 rmesa
->swtcl
.vertex_size
/= 4;
203 RENDERINPUTS_COPY( rmesa
->radeon
.tnl_index_bitset
, index_bitset
);
208 static void r200RenderStart( GLcontext
*ctx
)
210 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
212 r200SetVertexFormat( ctx
);
217 * Set vertex state for SW TCL. The primary purpose of this function is to
218 * determine in advance whether or not the hardware can / should do the
219 * projection divide or Mesa should do it.
221 void r200ChooseVertexState( GLcontext
*ctx
)
223 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
224 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
228 /* We must ensure that we don't do _tnl_need_projected_coords while in a
229 * rasterization fallback. As this function will be called again when we
230 * leave a rasterization fallback, we can just skip it for now.
232 if (rmesa
->radeon
.Fallback
!= 0)
235 vte
= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
];
236 vap
= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
];
238 /* HW perspective divide is a win, but tiny vertex formats are a
241 if (!RENDERINPUTS_TEST_RANGE( tnl
->render_inputs_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)
242 || (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
243 rmesa
->swtcl
.needproj
= GL_TRUE
;
244 vte
|= R200_VTX_XY_FMT
| R200_VTX_Z_FMT
;
245 vte
&= ~R200_VTX_W0_FMT
;
246 if (RENDERINPUTS_TEST_RANGE( tnl
->render_inputs_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
247 vap
&= ~R200_VAP_FORCE_W_TO_ONE
;
250 vap
|= R200_VAP_FORCE_W_TO_ONE
;
254 rmesa
->swtcl
.needproj
= GL_FALSE
;
255 vte
&= ~(R200_VTX_XY_FMT
| R200_VTX_Z_FMT
);
256 vte
|= R200_VTX_W0_FMT
;
257 vap
&= ~R200_VAP_FORCE_W_TO_ONE
;
260 _tnl_need_projected_coords( ctx
, rmesa
->swtcl
.needproj
);
262 if (vte
!= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
]) {
263 R200_STATECHANGE( rmesa
, vte
);
264 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] = vte
;
267 if (vap
!= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
]) {
268 R200_STATECHANGE( rmesa
, vap
);
269 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] = vap
;
274 /* Flush vertices in the current dma region.
276 static void flush_last_swtcl_prim(GLcontext
*ctx
)
278 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
279 if (R200_DEBUG
& DEBUG_IOCTL
)
280 fprintf(stderr
, "%s\n", __FUNCTION__
);
282 rmesa
->swtcl
.flush
= NULL
;
284 radeon_bo_unmap(rmesa
->swtcl
.bo
);
285 rcommonEnsureCmdBufSpace(rmesa
,
286 rmesa
->hw
.max_state_size
+ (12*sizeof(int)),
290 r200EmitState(rmesa
);
291 r200EmitVertexAOS( rmesa
,
292 rmesa
->swtcl
.vertex_size
,
296 r200EmitVbufPrim( rmesa
,
297 rmesa
->swtcl
.hw_primitive
,
298 rmesa
->swtcl
.numverts
);
300 radeon_bo_unref(rmesa
->swtcl
.bo
);
302 rmesa
->swtcl
.numverts
= 0;
306 /* Alloc space in the current dma region.
309 r200AllocDmaLowVerts( r200ContextPtr rmesa
, int nverts
, int vsize
)
311 GLuint bytes
= vsize
* nverts
;
313 rmesa
->swtcl
.bo
= radeon_bo_open(rmesa
->radeon
.radeonScreen
->bom
,
314 0, bytes
, 4, RADEON_GEM_DOMAIN_GTT
, 0);
315 radeon_bo_map(rmesa
->swtcl
.bo
, 1);
316 if (rmesa
->swtcl
.flush
== NULL
) {
317 rmesa
->radeon
.glCtx
->Driver
.NeedFlush
|= FLUSH_STORED_VERTICES
;
318 rmesa
->swtcl
.flush
= flush_last_swtcl_prim
;
320 return rmesa
->swtcl
.bo
->ptr
;
326 /**************************************************************************/
329 static INLINE GLuint
reduced_hw_prim( GLcontext
*ctx
, GLuint prim
)
333 return (ctx
->Point
.PointSprite
||
334 ((ctx
->_TriangleCaps
& (DD_POINT_SIZE
| DD_POINT_ATTEN
)) &&
335 !(ctx
->_TriangleCaps
& (DD_POINT_SMOOTH
)))) ?
336 R200_VF_PRIM_POINT_SPRITES
: R200_VF_PRIM_POINTS
;
342 return R200_VF_PRIM_LINES
;
344 /* all others reduced to triangles */
345 return R200_VF_PRIM_TRIANGLES
;
350 static void r200RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
);
351 static void r200RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
352 static void r200ResetLineStipple( GLcontext
*ctx
);
354 /***********************************************************************
355 * Emit primitives as inline vertices *
356 ***********************************************************************/
358 #define HAVE_POINTS 1
360 #define HAVE_LINE_STRIPS 1
361 #define HAVE_TRIANGLES 1
362 #define HAVE_TRI_STRIPS 1
363 #define HAVE_TRI_STRIP_1 0
364 #define HAVE_TRI_FANS 1
366 #define HAVE_QUAD_STRIPS 0
367 #define HAVE_POLYGONS 1
372 #define CTX_ARG r200ContextPtr rmesa
373 #define GET_VERTEX_DWORDS() rmesa->swtcl.vertex_size
374 #define ALLOC_VERTS( n, size ) r200AllocDmaLowVerts( rmesa, n, size * 4 )
376 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
377 const char *r200verts = (char *)rmesa->swtcl.verts;
378 #define VERT(x) (radeonVertex *)(r200verts + ((x) * vertsize * sizeof(int)))
379 #define VERTEX radeonVertex
380 #define DO_DEBUG_VERTS (1 && (R200_DEBUG & DEBUG_VERTS))
383 #define TAG(x) r200_##x
384 #include "tnl_dd/t_dd_triemit.h"
387 /***********************************************************************
388 * Macros for t_dd_tritmp.h to draw basic primitives *
389 ***********************************************************************/
391 #define QUAD( a, b, c, d ) r200_quad( rmesa, a, b, c, d )
392 #define TRI( a, b, c ) r200_triangle( rmesa, a, b, c )
393 #define LINE( a, b ) r200_line( rmesa, a, b )
394 #define POINT( a ) r200_point( rmesa, a )
396 /***********************************************************************
397 * Build render functions from dd templates *
398 ***********************************************************************/
400 #define R200_TWOSIDE_BIT 0x01
401 #define R200_UNFILLED_BIT 0x02
402 #define R200_MAX_TRIFUNC 0x04
406 tnl_points_func points
;
408 tnl_triangle_func triangle
;
410 } rast_tab
[R200_MAX_TRIFUNC
];
413 #define DO_FALLBACK 0
414 #define DO_UNFILLED (IND & R200_UNFILLED_BIT)
415 #define DO_TWOSIDE (IND & R200_TWOSIDE_BIT)
422 #define DO_FULL_QUAD 1
426 #define HAVE_BACK_COLORS 0
427 #define HAVE_HW_FLATSHADE 1
430 #define DEPTH_SCALE 1.0
431 #define UNFILLED_TRI unfilled_tri
432 #define UNFILLED_QUAD unfilled_quad
433 #define VERT_X(_v) _v->v.x
434 #define VERT_Y(_v) _v->v.y
435 #define VERT_Z(_v) _v->v.z
436 #define AREA_IS_CCW( a ) (a < 0)
437 #define GET_VERTEX(e) (rmesa->swtcl.verts + (e*rmesa->swtcl.vertex_size*sizeof(int)))
439 #define VERT_SET_RGBA( v, c ) \
441 radeon_color_t *color = (radeon_color_t *)&((v)->ui[coloroffset]); \
442 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
443 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
444 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
445 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
448 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
450 #define VERT_SET_SPEC( v, c ) \
453 radeon_color_t *spec = (radeon_color_t *)&((v)->ui[specoffset]); \
454 UNCLAMPED_FLOAT_TO_UBYTE(spec->red, (c)[0]); \
455 UNCLAMPED_FLOAT_TO_UBYTE(spec->green, (c)[1]); \
456 UNCLAMPED_FLOAT_TO_UBYTE(spec->blue, (c)[2]); \
459 #define VERT_COPY_SPEC( v0, v1 ) \
462 radeon_color_t *spec0 = (radeon_color_t *)&((v0)->ui[specoffset]); \
463 radeon_color_t *spec1 = (radeon_color_t *)&((v1)->ui[specoffset]); \
464 spec0->red = spec1->red; \
465 spec0->green = spec1->green; \
466 spec0->blue = spec1->blue; \
470 /* These don't need LE32_TO_CPU() as they used to save and restore
471 * colors which are already in the correct format.
473 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
474 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
475 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
476 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
482 #define LOCAL_VARS(n) \
483 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
484 GLuint color[n], spec[n]; \
485 GLuint coloroffset = rmesa->swtcl.coloroffset; \
486 GLuint specoffset = rmesa->swtcl.specoffset; \
487 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
489 /***********************************************************************
490 * Helpers for rendering unfilled primitives *
491 ***********************************************************************/
493 #define RASTERIZE(x) r200RasterPrimitive( ctx, reduced_hw_prim(ctx, x) )
494 #define RENDER_PRIMITIVE rmesa->swtcl.render_primitive
497 #include "tnl_dd/t_dd_unfilled.h"
501 /***********************************************************************
502 * Generate GL render functions *
503 ***********************************************************************/
508 #include "tnl_dd/t_dd_tritmp.h"
510 #define IND (R200_TWOSIDE_BIT)
511 #define TAG(x) x##_twoside
512 #include "tnl_dd/t_dd_tritmp.h"
514 #define IND (R200_UNFILLED_BIT)
515 #define TAG(x) x##_unfilled
516 #include "tnl_dd/t_dd_tritmp.h"
518 #define IND (R200_TWOSIDE_BIT|R200_UNFILLED_BIT)
519 #define TAG(x) x##_twoside_unfilled
520 #include "tnl_dd/t_dd_tritmp.h"
523 static void init_rast_tab( void )
528 init_twoside_unfilled();
531 /**********************************************************************/
532 /* Render unclipped begin/end objects */
533 /**********************************************************************/
535 #define RENDER_POINTS( start, count ) \
536 for ( ; start < count ; start++) \
537 r200_point( rmesa, VERT(start) )
538 #define RENDER_LINE( v0, v1 ) \
539 r200_line( rmesa, VERT(v0), VERT(v1) )
540 #define RENDER_TRI( v0, v1, v2 ) \
541 r200_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
542 #define RENDER_QUAD( v0, v1, v2, v3 ) \
543 r200_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
544 #define INIT(x) do { \
545 r200RenderPrimitive( ctx, x ); \
549 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
550 const GLuint vertsize = rmesa->swtcl.vertex_size; \
551 const char *r200verts = (char *)rmesa->swtcl.verts; \
552 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
553 const GLboolean stipple = ctx->Line.StippleFlag; \
554 (void) elt; (void) stipple;
555 #define RESET_STIPPLE if ( stipple ) r200ResetLineStipple( ctx );
556 #define RESET_OCCLUSION
557 #define PRESERVE_VB_DEFS
559 #define TAG(x) r200_##x##_verts
560 #include "tnl/t_vb_rendertmp.h"
563 #define TAG(x) r200_##x##_elts
564 #define ELT(x) elt[x]
565 #include "tnl/t_vb_rendertmp.h"
569 /**********************************************************************/
570 /* Choose render functions */
571 /**********************************************************************/
573 void r200ChooseRenderState( GLcontext
*ctx
)
575 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
576 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
578 GLuint flags
= ctx
->_TriangleCaps
;
580 if (!rmesa
->radeon
.TclFallback
|| rmesa
->radeon
.Fallback
)
583 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R200_TWOSIDE_BIT
;
584 if (flags
& DD_TRI_UNFILLED
) index
|= R200_UNFILLED_BIT
;
586 if (index
!= rmesa
->swtcl
.RenderIndex
) {
587 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
588 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
589 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
590 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
591 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
594 tnl
->Driver
.Render
.PrimTabVerts
= r200_render_tab_verts
;
595 tnl
->Driver
.Render
.PrimTabElts
= r200_render_tab_elts
;
596 tnl
->Driver
.Render
.ClippedPolygon
= r200_fast_clipped_poly
;
598 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
599 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
600 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
603 rmesa
->swtcl
.RenderIndex
= index
;
608 /**********************************************************************/
609 /* High level hooks for t_vb_render.c */
610 /**********************************************************************/
613 static void r200RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
615 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
617 if (rmesa
->swtcl
.hw_primitive
!= hwprim
) {
618 /* need to disable perspective-correct texturing for point sprites */
619 if ((hwprim
& 0xf) == R200_VF_PRIM_POINT_SPRITES
&& ctx
->Point
.PointSprite
) {
620 if (rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] & R200_PERSPECTIVE_ENABLE
) {
621 R200_STATECHANGE( rmesa
, set
);
622 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] &= ~R200_PERSPECTIVE_ENABLE
;
625 else if (!(rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] & R200_PERSPECTIVE_ENABLE
)) {
626 R200_STATECHANGE( rmesa
, set
);
627 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] |= R200_PERSPECTIVE_ENABLE
;
629 R200_NEWPRIM( rmesa
);
630 rmesa
->swtcl
.hw_primitive
= hwprim
;
634 static void r200RenderPrimitive( GLcontext
*ctx
, GLenum prim
)
636 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
637 rmesa
->swtcl
.render_primitive
= prim
;
638 if (prim
< GL_TRIANGLES
|| !(ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
639 r200RasterPrimitive( ctx
, reduced_hw_prim(ctx
, prim
) );
642 static void r200RenderFinish( GLcontext
*ctx
)
646 static void r200ResetLineStipple( GLcontext
*ctx
)
648 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
649 R200_STATECHANGE( rmesa
, lin
);
653 /**********************************************************************/
654 /* Transition to/from hardware rasterization. */
655 /**********************************************************************/
657 static const char * const fallbackStrings
[] = {
659 "glDrawBuffer(GL_FRONT_AND_BACK)",
660 "glEnable(GL_STENCIL) without hw stencil buffer",
661 "glRenderMode(selection or feedback)",
663 "Mixing GL_CLAMP_TO_BORDER and GL_CLAMP (or GL_MIRROR_CLAMP_ATI)"
667 static const char *getFallbackString(GLuint bit
)
674 return fallbackStrings
[i
];
678 void r200Fallback( GLcontext
*ctx
, GLuint bit
, GLboolean mode
)
680 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
681 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
682 GLuint oldfallback
= rmesa
->radeon
.Fallback
;
685 rmesa
->radeon
.Fallback
|= bit
;
686 if (oldfallback
== 0) {
687 R200_FIREVERTICES( rmesa
);
688 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_RASTER
, GL_TRUE
);
689 _swsetup_Wakeup( ctx
);
690 rmesa
->swtcl
.RenderIndex
= ~0;
691 if (R200_DEBUG
& DEBUG_FALLBACKS
) {
692 fprintf(stderr
, "R200 begin rasterization fallback: 0x%x %s\n",
693 bit
, getFallbackString(bit
));
698 rmesa
->radeon
.Fallback
&= ~bit
;
699 if (oldfallback
== bit
) {
701 _swrast_flush( ctx
);
702 tnl
->Driver
.Render
.Start
= r200RenderStart
;
703 tnl
->Driver
.Render
.PrimitiveNotify
= r200RenderPrimitive
;
704 tnl
->Driver
.Render
.Finish
= r200RenderFinish
;
706 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
707 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
708 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
710 tnl
->Driver
.Render
.ResetLineStipple
= r200ResetLineStipple
;
711 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_RASTER
, GL_FALSE
);
712 if (rmesa
->radeon
.TclFallback
) {
713 /* These are already done if rmesa->radeon.TclFallback goes to
714 * zero above. But not if it doesn't (R200_NO_TCL for
717 _tnl_invalidate_vertex_state( ctx
, ~0 );
718 _tnl_invalidate_vertices( ctx
, ~0 );
719 RENDERINPUTS_ZERO( rmesa
->radeon
.tnl_index_bitset
);
720 r200ChooseVertexState( ctx
);
721 r200ChooseRenderState( ctx
);
723 if (R200_DEBUG
& DEBUG_FALLBACKS
) {
724 fprintf(stderr
, "R200 end rasterization fallback: 0x%x %s\n",
725 bit
, getFallbackString(bit
));
735 * Cope with depth operations by drawing individual pixels as points.
738 * The way the vertex state is set in this routine is hokey. It seems to
739 * work, but it's very hackish. This whole routine is pretty hackish. If
740 * the bitmap is small enough, it seems like it would be faster to copy it
741 * to AGP memory and use it as a non-power-of-two texture (i.e.,
742 * NV_texture_rectangle).
745 r200PointsBitmap( GLcontext
*ctx
, GLint px
, GLint py
,
746 GLsizei width
, GLsizei height
,
747 const struct gl_pixelstore_attrib
*unpack
,
748 const GLubyte
*bitmap
)
750 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
751 const GLfloat
*rc
= ctx
->Current
.RasterColor
;
760 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_BITMAP
, 1 );
762 /* Choose tiny vertex format
765 const GLuint fmt_0
= R200_VTX_XY
| R200_VTX_Z0
| R200_VTX_W0
766 | (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_0_SHIFT
);
767 const GLuint fmt_1
= 0;
768 GLuint vte
= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
];
769 GLuint vap
= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
];
771 vte
&= ~(R200_VTX_XY_FMT
| R200_VTX_Z_FMT
);
772 vte
|= R200_VTX_W0_FMT
;
773 vap
&= ~R200_VAP_FORCE_W_TO_ONE
;
775 rmesa
->swtcl
.vertex_size
= 5;
777 if ( (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] != fmt_0
)
778 || (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] != fmt_1
) ) {
780 R200_STATECHANGE( rmesa
, vtx
);
781 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] = fmt_0
;
782 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] = fmt_1
;
785 if (vte
!= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
]) {
786 R200_STATECHANGE( rmesa
, vte
);
787 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] = vte
;
790 if (vap
!= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
]) {
791 R200_STATECHANGE( rmesa
, vap
);
792 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] = vap
;
796 /* Ready for point primitives:
798 r200RenderPrimitive( ctx
, GL_POINTS
);
800 /* Turn off the hw viewport transformation:
802 R200_STATECHANGE( rmesa
, vte
);
803 orig_vte
= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
];
804 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] &= ~(R200_VPORT_X_SCALE_ENA
|
805 R200_VPORT_Y_SCALE_ENA
|
806 R200_VPORT_Z_SCALE_ENA
|
807 R200_VPORT_X_OFFSET_ENA
|
808 R200_VPORT_Y_OFFSET_ENA
|
809 R200_VPORT_Z_OFFSET_ENA
);
811 /* Turn off other stuff: Stipple?, texture?, blending?, etc.
815 /* Populate the vertex
817 * Incorporate FOG into RGBA
819 if (ctx
->Fog
.Enabled
) {
820 const GLfloat
*fc
= ctx
->Fog
.Color
;
824 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
825 f
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0]);
827 f
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.RasterDistance
);
829 color
[0] = f
* rc
[0] + (1.F
- f
) * fc
[0];
830 color
[1] = f
* rc
[1] + (1.F
- f
) * fc
[1];
831 color
[2] = f
* rc
[2] + (1.F
- f
) * fc
[2];
834 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.red
, color
[0]);
835 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.green
, color
[1]);
836 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.blue
, color
[2]);
837 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.alpha
, color
[3]);
840 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.red
, rc
[0]);
841 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.green
, rc
[1]);
842 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.blue
, rc
[2]);
843 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.alpha
, rc
[3]);
847 vert
.tv
.z
= ctx
->Current
.RasterPos
[2];
850 /* Update window height
852 LOCK_HARDWARE( &rmesa
->radeon
);
853 UNLOCK_HARDWARE( &rmesa
->radeon
);
854 h
= rmesa
->radeon
.dri
.drawable
->h
+ rmesa
->radeon
.dri
.drawable
->y
;
855 px
+= rmesa
->radeon
.dri
.drawable
->x
;
857 /* Clipping handled by existing mechansims in r200_ioctl.c?
859 for (row
=0; row
<height
; row
++) {
860 const GLubyte
*src
= (const GLubyte
*)
861 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
862 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0 );
864 if (unpack
->LsbFirst
) {
866 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
867 for (col
=0; col
<width
; col
++) {
870 vert
.tv
.y
= h
- (py
+row
) - 1;
871 r200_point( rmesa
, &vert
);
874 mask
= ((mask
<< 1) & 0xff) | (mask
>> 7);
877 /* get ready for next row */
883 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
884 for (col
=0; col
<width
; col
++) {
887 vert
.tv
.y
= h
- (py
+row
) - 1;
888 r200_point( rmesa
, &vert
);
891 mask
= ((mask
<< 7) & 0xff) | (mask
>> 1);
893 /* get ready for next row */
899 /* Fire outstanding vertices, restore state
901 R200_STATECHANGE( rmesa
, vte
);
902 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] = orig_vte
;
906 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_BITMAP
, 0 );
908 /* Need to restore vertexformat?
910 if (rmesa
->radeon
.TclFallback
)
911 r200ChooseVertexState( ctx
);
916 /**********************************************************************/
917 /* Initialization. */
918 /**********************************************************************/
920 void r200InitSwtcl( GLcontext
*ctx
)
922 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
923 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
924 static int firsttime
= 1;
931 tnl
->Driver
.Render
.Start
= r200RenderStart
;
932 tnl
->Driver
.Render
.Finish
= r200RenderFinish
;
933 tnl
->Driver
.Render
.PrimitiveNotify
= r200RenderPrimitive
;
934 tnl
->Driver
.Render
.ResetLineStipple
= r200ResetLineStipple
;
935 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
936 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
937 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
939 /* FIXME: what are these numbers? */
940 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
941 36 * sizeof(GLfloat
) );
943 rmesa
->swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
944 rmesa
->swtcl
.RenderIndex
= ~0;
945 rmesa
->swtcl
.render_primitive
= GL_TRIANGLES
;
946 rmesa
->swtcl
.hw_primitive
= 0;
950 void r200DestroySwtcl( GLcontext
*ctx
)
952 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);