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 /***********************************************************************
61 ***********************************************************************/
63 #define EMIT_ATTR( ATTR, STYLE, F0 ) \
65 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
66 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
67 rmesa->radeon.swtcl.vertex_attr_count++; \
71 #define EMIT_PAD( N ) \
73 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
74 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
75 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
76 rmesa->radeon.swtcl.vertex_attr_count++; \
79 static void r200SetVertexFormat( GLcontext
*ctx
)
81 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
82 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
83 struct vertex_buffer
*VB
= &tnl
->vb
;
84 DECLARE_RENDERINPUTS(index_bitset
);
89 RENDERINPUTS_COPY( index_bitset
, tnl
->render_inputs_bitset
);
93 if ( VB
->NdcPtr
!= NULL
) {
94 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
97 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
100 assert( VB
->AttribPtr
[VERT_ATTRIB_POS
] != NULL
);
101 rmesa
->radeon
.swtcl
.vertex_attr_count
= 0;
103 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
104 * build up a hardware vertex.
106 if ( !rmesa
->swtcl
.needproj
||
107 RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) { /* need w coord for projected textures */
108 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
, R200_VTX_XY
| R200_VTX_Z0
| R200_VTX_W0
);
112 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_3F
, R200_VTX_XY
| R200_VTX_Z0
);
116 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
117 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
, R200_VTX_POINT_SIZE
);
121 rmesa
->swtcl
.coloroffset
= offset
;
122 #if MESA_LITTLE_ENDIAN
123 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_RGBA
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_0_SHIFT
) );
125 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_ABGR
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_0_SHIFT
) );
129 rmesa
->swtcl
.specoffset
= 0;
130 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
) ||
131 RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
133 #if MESA_LITTLE_ENDIAN
134 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
135 rmesa
->swtcl
.specoffset
= offset
;
136 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_RGB
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
142 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
143 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1UB_1F
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
149 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_FOG
)) {
150 EMIT_ATTR( _TNL_ATTRIB_FOG
, EMIT_1UB_1F
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
156 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
157 rmesa
->swtcl
.specoffset
= offset
;
158 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_BGR
, (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_1_SHIFT
) );
166 if (RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
169 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
170 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_TEX(i
) )) {
171 GLuint sz
= VB
->TexCoordPtr
[i
]->size
;
173 fmt_1
|= sz
<< (3 * i
);
174 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_1F
+ sz
- 1, 0 );
179 if ( (rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] & R200_FOG_USE_MASK
)
180 != R200_FOG_USE_SPEC_ALPHA
) {
181 R200_STATECHANGE( rmesa
, ctx
);
182 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] &= ~R200_FOG_USE_MASK
;
183 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] |= R200_FOG_USE_SPEC_ALPHA
;
186 if (!RENDERINPUTS_EQUAL( rmesa
->radeon
.tnl_index_bitset
, index_bitset
) ||
187 (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] != fmt_0
) ||
188 (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] != fmt_1
) ) {
190 R200_STATECHANGE( rmesa
, vtx
);
191 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] = fmt_0
;
192 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] = fmt_1
;
194 rmesa
->radeon
.swtcl
.vertex_size
=
195 _tnl_install_attrs( ctx
,
196 rmesa
->radeon
.swtcl
.vertex_attrs
,
197 rmesa
->radeon
.swtcl
.vertex_attr_count
,
199 rmesa
->radeon
.swtcl
.vertex_size
/= 4;
200 RENDERINPUTS_COPY( rmesa
->radeon
.tnl_index_bitset
, index_bitset
);
205 static void r200RenderStart( GLcontext
*ctx
)
207 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
209 r200SetVertexFormat( ctx
);
214 * Set vertex state for SW TCL. The primary purpose of this function is to
215 * determine in advance whether or not the hardware can / should do the
216 * projection divide or Mesa should do it.
218 void r200ChooseVertexState( GLcontext
*ctx
)
220 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
221 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
225 /* We must ensure that we don't do _tnl_need_projected_coords while in a
226 * rasterization fallback. As this function will be called again when we
227 * leave a rasterization fallback, we can just skip it for now.
229 if (rmesa
->radeon
.Fallback
!= 0)
232 vte
= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
];
233 vap
= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
];
235 /* HW perspective divide is a win, but tiny vertex formats are a
238 if (!RENDERINPUTS_TEST_RANGE( tnl
->render_inputs_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)
239 || (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
240 rmesa
->swtcl
.needproj
= GL_TRUE
;
241 vte
|= R200_VTX_XY_FMT
| R200_VTX_Z_FMT
;
242 vte
&= ~R200_VTX_W0_FMT
;
243 if (RENDERINPUTS_TEST_RANGE( tnl
->render_inputs_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
244 vap
&= ~R200_VAP_FORCE_W_TO_ONE
;
247 vap
|= R200_VAP_FORCE_W_TO_ONE
;
251 rmesa
->swtcl
.needproj
= GL_FALSE
;
252 vte
&= ~(R200_VTX_XY_FMT
| R200_VTX_Z_FMT
);
253 vte
|= R200_VTX_W0_FMT
;
254 vap
&= ~R200_VAP_FORCE_W_TO_ONE
;
257 _tnl_need_projected_coords( ctx
, rmesa
->swtcl
.needproj
);
259 if (vte
!= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
]) {
260 R200_STATECHANGE( rmesa
, vte
);
261 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] = vte
;
264 if (vap
!= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
]) {
265 R200_STATECHANGE( rmesa
, vap
);
266 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] = vap
;
270 void r200_swtcl_flush(GLcontext
*ctx
, uint32_t current_offset
)
272 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
273 rcommonEnsureCmdBufSpace(&rmesa
->radeon
,
274 rmesa
->hw
.max_state_size
+ (12*sizeof(int)),
278 r200EmitState(rmesa
);
279 r200EmitVertexAOS( rmesa
,
280 rmesa
->radeon
.swtcl
.vertex_size
,
281 rmesa
->radeon
.dma
.current
,
285 r200EmitVbufPrim( rmesa
,
286 rmesa
->radeon
.swtcl
.hw_primitive
,
287 rmesa
->radeon
.swtcl
.numverts
);
291 /**************************************************************************/
294 static INLINE GLuint
reduced_hw_prim( GLcontext
*ctx
, GLuint prim
)
298 return (ctx
->Point
.PointSprite
||
299 ((ctx
->_TriangleCaps
& (DD_POINT_SIZE
| DD_POINT_ATTEN
)) &&
300 !(ctx
->_TriangleCaps
& (DD_POINT_SMOOTH
)))) ?
301 R200_VF_PRIM_POINT_SPRITES
: R200_VF_PRIM_POINTS
;
307 return R200_VF_PRIM_LINES
;
309 /* all others reduced to triangles */
310 return R200_VF_PRIM_TRIANGLES
;
315 static void r200RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
);
316 static void r200RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
317 static void r200ResetLineStipple( GLcontext
*ctx
);
319 /***********************************************************************
320 * Emit primitives as inline vertices *
321 ***********************************************************************/
323 #define HAVE_POINTS 1
325 #define HAVE_LINE_STRIPS 1
326 #define HAVE_TRIANGLES 1
327 #define HAVE_TRI_STRIPS 1
328 #define HAVE_TRI_STRIP_1 0
329 #define HAVE_TRI_FANS 1
331 #define HAVE_QUAD_STRIPS 0
332 #define HAVE_POLYGONS 1
337 #define CTX_ARG r200ContextPtr rmesa
338 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
339 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
341 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
342 const char *r200verts = (char *)rmesa->radeon.swtcl.verts;
343 #define VERT(x) (radeonVertex *)(r200verts + ((x) * vertsize * sizeof(int)))
344 #define VERTEX radeonVertex
345 #define DO_DEBUG_VERTS (1 && (R200_DEBUG & DEBUG_VERTS))
348 #define TAG(x) r200_##x
349 #include "tnl_dd/t_dd_triemit.h"
352 /***********************************************************************
353 * Macros for t_dd_tritmp.h to draw basic primitives *
354 ***********************************************************************/
356 #define QUAD( a, b, c, d ) r200_quad( rmesa, a, b, c, d )
357 #define TRI( a, b, c ) r200_triangle( rmesa, a, b, c )
358 #define LINE( a, b ) r200_line( rmesa, a, b )
359 #define POINT( a ) r200_point( rmesa, a )
361 /***********************************************************************
362 * Build render functions from dd templates *
363 ***********************************************************************/
365 #define R200_TWOSIDE_BIT 0x01
366 #define R200_UNFILLED_BIT 0x02
367 #define R200_MAX_TRIFUNC 0x04
371 tnl_points_func points
;
373 tnl_triangle_func triangle
;
375 } rast_tab
[R200_MAX_TRIFUNC
];
378 #define DO_FALLBACK 0
379 #define DO_UNFILLED (IND & R200_UNFILLED_BIT)
380 #define DO_TWOSIDE (IND & R200_TWOSIDE_BIT)
387 #define DO_FULL_QUAD 1
391 #define HAVE_BACK_COLORS 0
392 #define HAVE_HW_FLATSHADE 1
395 #define DEPTH_SCALE 1.0
396 #define UNFILLED_TRI unfilled_tri
397 #define UNFILLED_QUAD unfilled_quad
398 #define VERT_X(_v) _v->v.x
399 #define VERT_Y(_v) _v->v.y
400 #define VERT_Z(_v) _v->v.z
401 #define AREA_IS_CCW( a ) (a < 0)
402 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
404 #define VERT_SET_RGBA( v, c ) \
406 radeon_color_t *color = (radeon_color_t *)&((v)->ui[coloroffset]); \
407 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
408 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
409 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
410 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
413 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
415 #define VERT_SET_SPEC( v, c ) \
418 radeon_color_t *spec = (radeon_color_t *)&((v)->ui[specoffset]); \
419 UNCLAMPED_FLOAT_TO_UBYTE(spec->red, (c)[0]); \
420 UNCLAMPED_FLOAT_TO_UBYTE(spec->green, (c)[1]); \
421 UNCLAMPED_FLOAT_TO_UBYTE(spec->blue, (c)[2]); \
424 #define VERT_COPY_SPEC( v0, v1 ) \
427 radeon_color_t *spec0 = (radeon_color_t *)&((v0)->ui[specoffset]); \
428 radeon_color_t *spec1 = (radeon_color_t *)&((v1)->ui[specoffset]); \
429 spec0->red = spec1->red; \
430 spec0->green = spec1->green; \
431 spec0->blue = spec1->blue; \
435 /* These don't need LE32_TO_CPU() as they used to save and restore
436 * colors which are already in the correct format.
438 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
439 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
440 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
441 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
447 #define LOCAL_VARS(n) \
448 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
449 GLuint color[n], spec[n]; \
450 GLuint coloroffset = rmesa->swtcl.coloroffset; \
451 GLuint specoffset = rmesa->swtcl.specoffset; \
452 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
454 /***********************************************************************
455 * Helpers for rendering unfilled primitives *
456 ***********************************************************************/
458 #define RASTERIZE(x) r200RasterPrimitive( ctx, reduced_hw_prim(ctx, x) )
459 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
462 #include "tnl_dd/t_dd_unfilled.h"
466 /***********************************************************************
467 * Generate GL render functions *
468 ***********************************************************************/
473 #include "tnl_dd/t_dd_tritmp.h"
475 #define IND (R200_TWOSIDE_BIT)
476 #define TAG(x) x##_twoside
477 #include "tnl_dd/t_dd_tritmp.h"
479 #define IND (R200_UNFILLED_BIT)
480 #define TAG(x) x##_unfilled
481 #include "tnl_dd/t_dd_tritmp.h"
483 #define IND (R200_TWOSIDE_BIT|R200_UNFILLED_BIT)
484 #define TAG(x) x##_twoside_unfilled
485 #include "tnl_dd/t_dd_tritmp.h"
488 static void init_rast_tab( void )
493 init_twoside_unfilled();
496 /**********************************************************************/
497 /* Render unclipped begin/end objects */
498 /**********************************************************************/
500 #define RENDER_POINTS( start, count ) \
501 for ( ; start < count ; start++) \
502 r200_point( rmesa, VERT(start) )
503 #define RENDER_LINE( v0, v1 ) \
504 r200_line( rmesa, VERT(v0), VERT(v1) )
505 #define RENDER_TRI( v0, v1, v2 ) \
506 r200_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
507 #define RENDER_QUAD( v0, v1, v2, v3 ) \
508 r200_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
509 #define INIT(x) do { \
510 r200RenderPrimitive( ctx, x ); \
514 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
515 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
516 const char *r200verts = (char *)rmesa->radeon.swtcl.verts; \
517 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
518 const GLboolean stipple = ctx->Line.StippleFlag; \
519 (void) elt; (void) stipple;
520 #define RESET_STIPPLE if ( stipple ) r200ResetLineStipple( ctx );
521 #define RESET_OCCLUSION
522 #define PRESERVE_VB_DEFS
524 #define TAG(x) r200_##x##_verts
525 #include "tnl/t_vb_rendertmp.h"
528 #define TAG(x) r200_##x##_elts
529 #define ELT(x) elt[x]
530 #include "tnl/t_vb_rendertmp.h"
534 /**********************************************************************/
535 /* Choose render functions */
536 /**********************************************************************/
538 void r200ChooseRenderState( GLcontext
*ctx
)
540 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
541 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
543 GLuint flags
= ctx
->_TriangleCaps
;
545 if (!rmesa
->radeon
.TclFallback
|| rmesa
->radeon
.Fallback
)
548 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R200_TWOSIDE_BIT
;
549 if (flags
& DD_TRI_UNFILLED
) index
|= R200_UNFILLED_BIT
;
551 if (index
!= rmesa
->radeon
.swtcl
.RenderIndex
) {
552 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
553 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
554 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
555 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
556 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
559 tnl
->Driver
.Render
.PrimTabVerts
= r200_render_tab_verts
;
560 tnl
->Driver
.Render
.PrimTabElts
= r200_render_tab_elts
;
561 tnl
->Driver
.Render
.ClippedPolygon
= r200_fast_clipped_poly
;
563 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
564 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
565 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
568 rmesa
->radeon
.swtcl
.RenderIndex
= index
;
573 /**********************************************************************/
574 /* High level hooks for t_vb_render.c */
575 /**********************************************************************/
578 static void r200RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
580 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
582 if (rmesa
->radeon
.swtcl
.hw_primitive
!= hwprim
) {
583 /* need to disable perspective-correct texturing for point sprites */
584 if ((hwprim
& 0xf) == R200_VF_PRIM_POINT_SPRITES
&& ctx
->Point
.PointSprite
) {
585 if (rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] & R200_PERSPECTIVE_ENABLE
) {
586 R200_STATECHANGE( rmesa
, set
);
587 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] &= ~R200_PERSPECTIVE_ENABLE
;
590 else if (!(rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] & R200_PERSPECTIVE_ENABLE
)) {
591 R200_STATECHANGE( rmesa
, set
);
592 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] |= R200_PERSPECTIVE_ENABLE
;
594 R200_NEWPRIM( rmesa
);
595 rmesa
->radeon
.swtcl
.hw_primitive
= hwprim
;
599 static void r200RenderPrimitive( GLcontext
*ctx
, GLenum prim
)
601 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
602 rmesa
->radeon
.swtcl
.render_primitive
= prim
;
603 if (prim
< GL_TRIANGLES
|| !(ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
604 r200RasterPrimitive( ctx
, reduced_hw_prim(ctx
, prim
) );
607 static void r200RenderFinish( GLcontext
*ctx
)
611 static void r200ResetLineStipple( GLcontext
*ctx
)
613 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
614 R200_STATECHANGE( rmesa
, lin
);
618 /**********************************************************************/
619 /* Transition to/from hardware rasterization. */
620 /**********************************************************************/
622 static const char * const fallbackStrings
[] = {
624 "glDrawBuffer(GL_FRONT_AND_BACK)",
625 "glEnable(GL_STENCIL) without hw stencil buffer",
626 "glRenderMode(selection or feedback)",
628 "Mixing GL_CLAMP_TO_BORDER and GL_CLAMP (or GL_MIRROR_CLAMP_ATI)"
632 static const char *getFallbackString(GLuint bit
)
639 return fallbackStrings
[i
];
643 void r200Fallback( GLcontext
*ctx
, GLuint bit
, GLboolean mode
)
645 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
646 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
647 GLuint oldfallback
= rmesa
->radeon
.Fallback
;
650 rmesa
->radeon
.Fallback
|= bit
;
651 if (oldfallback
== 0) {
652 R200_FIREVERTICES( rmesa
);
653 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_RASTER
, GL_TRUE
);
654 _swsetup_Wakeup( ctx
);
655 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
656 if (R200_DEBUG
& DEBUG_FALLBACKS
) {
657 fprintf(stderr
, "R200 begin rasterization fallback: 0x%x %s\n",
658 bit
, getFallbackString(bit
));
663 rmesa
->radeon
.Fallback
&= ~bit
;
664 if (oldfallback
== bit
) {
666 _swrast_flush( ctx
);
667 tnl
->Driver
.Render
.Start
= r200RenderStart
;
668 tnl
->Driver
.Render
.PrimitiveNotify
= r200RenderPrimitive
;
669 tnl
->Driver
.Render
.Finish
= r200RenderFinish
;
671 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
672 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
673 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
675 tnl
->Driver
.Render
.ResetLineStipple
= r200ResetLineStipple
;
676 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_RASTER
, GL_FALSE
);
677 if (rmesa
->radeon
.TclFallback
) {
678 /* These are already done if rmesa->radeon.TclFallback goes to
679 * zero above. But not if it doesn't (R200_NO_TCL for
682 _tnl_invalidate_vertex_state( ctx
, ~0 );
683 _tnl_invalidate_vertices( ctx
, ~0 );
684 RENDERINPUTS_ZERO( rmesa
->radeon
.tnl_index_bitset
);
685 r200ChooseVertexState( ctx
);
686 r200ChooseRenderState( ctx
);
688 if (R200_DEBUG
& DEBUG_FALLBACKS
) {
689 fprintf(stderr
, "R200 end rasterization fallback: 0x%x %s\n",
690 bit
, getFallbackString(bit
));
700 * Cope with depth operations by drawing individual pixels as points.
703 * The way the vertex state is set in this routine is hokey. It seems to
704 * work, but it's very hackish. This whole routine is pretty hackish. If
705 * the bitmap is small enough, it seems like it would be faster to copy it
706 * to AGP memory and use it as a non-power-of-two texture (i.e.,
707 * NV_texture_rectangle).
710 r200PointsBitmap( GLcontext
*ctx
, GLint px
, GLint py
,
711 GLsizei width
, GLsizei height
,
712 const struct gl_pixelstore_attrib
*unpack
,
713 const GLubyte
*bitmap
)
715 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
716 const GLfloat
*rc
= ctx
->Current
.RasterColor
;
725 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_BITMAP
, 1 );
727 /* Choose tiny vertex format
730 const GLuint fmt_0
= R200_VTX_XY
| R200_VTX_Z0
| R200_VTX_W0
731 | (R200_VTX_PK_RGBA
<< R200_VTX_COLOR_0_SHIFT
);
732 const GLuint fmt_1
= 0;
733 GLuint vte
= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
];
734 GLuint vap
= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
];
736 vte
&= ~(R200_VTX_XY_FMT
| R200_VTX_Z_FMT
);
737 vte
|= R200_VTX_W0_FMT
;
738 vap
&= ~R200_VAP_FORCE_W_TO_ONE
;
740 rmesa
->radeon
.swtcl
.vertex_size
= 5;
742 if ( (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] != fmt_0
)
743 || (rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] != fmt_1
) ) {
745 R200_STATECHANGE( rmesa
, vtx
);
746 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] = fmt_0
;
747 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] = fmt_1
;
750 if (vte
!= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
]) {
751 R200_STATECHANGE( rmesa
, vte
);
752 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] = vte
;
755 if (vap
!= rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
]) {
756 R200_STATECHANGE( rmesa
, vap
);
757 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] = vap
;
761 /* Ready for point primitives:
763 r200RenderPrimitive( ctx
, GL_POINTS
);
765 /* Turn off the hw viewport transformation:
767 R200_STATECHANGE( rmesa
, vte
);
768 orig_vte
= rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
];
769 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] &= ~(R200_VPORT_X_SCALE_ENA
|
770 R200_VPORT_Y_SCALE_ENA
|
771 R200_VPORT_Z_SCALE_ENA
|
772 R200_VPORT_X_OFFSET_ENA
|
773 R200_VPORT_Y_OFFSET_ENA
|
774 R200_VPORT_Z_OFFSET_ENA
);
776 /* Turn off other stuff: Stipple?, texture?, blending?, etc.
780 /* Populate the vertex
782 * Incorporate FOG into RGBA
784 if (ctx
->Fog
.Enabled
) {
785 const GLfloat
*fc
= ctx
->Fog
.Color
;
789 if (ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORDINATE_EXT
)
790 f
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0]);
792 f
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.RasterDistance
);
794 color
[0] = f
* rc
[0] + (1.F
- f
) * fc
[0];
795 color
[1] = f
* rc
[1] + (1.F
- f
) * fc
[1];
796 color
[2] = f
* rc
[2] + (1.F
- f
) * fc
[2];
799 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.red
, color
[0]);
800 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.green
, color
[1]);
801 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.blue
, color
[2]);
802 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.alpha
, color
[3]);
805 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.red
, rc
[0]);
806 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.green
, rc
[1]);
807 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.blue
, rc
[2]);
808 UNCLAMPED_FLOAT_TO_CHAN(vert
.tv
.color
.alpha
, rc
[3]);
812 vert
.tv
.z
= ctx
->Current
.RasterPos
[2];
815 /* Update window height
817 LOCK_HARDWARE( &rmesa
->radeon
);
818 UNLOCK_HARDWARE( &rmesa
->radeon
);
819 h
= rmesa
->radeon
.dri
.drawable
->h
+ rmesa
->radeon
.dri
.drawable
->y
;
820 px
+= rmesa
->radeon
.dri
.drawable
->x
;
822 /* Clipping handled by existing mechansims in r200_ioctl.c?
824 for (row
=0; row
<height
; row
++) {
825 const GLubyte
*src
= (const GLubyte
*)
826 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
827 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0 );
829 if (unpack
->LsbFirst
) {
831 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
832 for (col
=0; col
<width
; col
++) {
835 vert
.tv
.y
= h
- (py
+row
) - 1;
836 r200_point( rmesa
, &vert
);
839 mask
= ((mask
<< 1) & 0xff) | (mask
>> 7);
842 /* get ready for next row */
848 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
849 for (col
=0; col
<width
; col
++) {
852 vert
.tv
.y
= h
- (py
+row
) - 1;
853 r200_point( rmesa
, &vert
);
856 mask
= ((mask
<< 7) & 0xff) | (mask
>> 1);
858 /* get ready for next row */
864 /* Fire outstanding vertices, restore state
866 R200_STATECHANGE( rmesa
, vte
);
867 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] = orig_vte
;
871 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_BITMAP
, 0 );
873 /* Need to restore vertexformat?
875 if (rmesa
->radeon
.TclFallback
)
876 r200ChooseVertexState( ctx
);
881 /**********************************************************************/
882 /* Initialization. */
883 /**********************************************************************/
885 void r200InitSwtcl( GLcontext
*ctx
)
887 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
888 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
889 static int firsttime
= 1;
896 tnl
->Driver
.Render
.Start
= r200RenderStart
;
897 tnl
->Driver
.Render
.Finish
= r200RenderFinish
;
898 tnl
->Driver
.Render
.PrimitiveNotify
= r200RenderPrimitive
;
899 tnl
->Driver
.Render
.ResetLineStipple
= r200ResetLineStipple
;
900 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
901 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
902 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
904 /* FIXME: what are these numbers? */
905 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
906 36 * sizeof(GLfloat
) );
908 rmesa
->radeon
.swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
909 rmesa
->radeon
.swtcl
.RenderIndex
= ~0;
910 rmesa
->radeon
.swtcl
.render_primitive
= GL_TRIANGLES
;
911 rmesa
->radeon
.swtcl
.hw_primitive
= 0;
915 void r200DestroySwtcl( GLcontext
*ctx
)
917 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);