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"
42 #include "main/simple_list.h"
44 #include "swrast/s_context.h"
45 #include "swrast/s_fog.h"
46 #include "swrast_setup/swrast_setup.h"
48 #include "tnl/t_context.h"
49 #include "tnl/t_pipeline.h"
51 #include "r200_context.h"
52 #include "r200_ioctl.h"
53 #include "r200_state.h"
54 #include "r200_swtcl.h"
58 /***********************************************************************
60 ***********************************************************************/
62 #define EMIT_ATTR( ATTR, STYLE, F0 ) \
64 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
65 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
66 rmesa->radeon.swtcl.vertex_attr_count++; \
70 #define EMIT_PAD( N ) \
72 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
73 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
74 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
75 rmesa->radeon.swtcl.vertex_attr_count++; \
78 static void r200SetVertexFormat( GLcontext *ctx )
80 r200ContextPtr rmesa = R200_CONTEXT( ctx );
81 TNLcontext *tnl = TNL_CONTEXT(ctx);
82 struct vertex_buffer *VB = &tnl->vb;
83 DECLARE_RENDERINPUTS(index_bitset);
88 RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
92 if ( VB->NdcPtr != NULL ) {
93 VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
96 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
99 assert( VB->AttribPtr[VERT_ATTRIB_POS] != NULL );
100 rmesa->radeon.swtcl.vertex_attr_count = 0;
102 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
103 * build up a hardware vertex.
105 if ( !rmesa->swtcl.needproj ||
106 RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { /* need w coord for projected textures */
107 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F, R200_VTX_XY | R200_VTX_Z0 | R200_VTX_W0 );
111 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F, R200_VTX_XY | R200_VTX_Z0 );
115 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) {
116 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, R200_VTX_POINT_SIZE );
120 rmesa->swtcl.coloroffset = offset;
121 #if MESA_LITTLE_ENDIAN
122 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_RGBA, (R200_VTX_PK_RGBA << R200_VTX_COLOR_0_SHIFT) );
124 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_ABGR, (R200_VTX_PK_RGBA << R200_VTX_COLOR_0_SHIFT) );
128 rmesa->swtcl.specoffset = 0;
129 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) ||
130 RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
132 #if MESA_LITTLE_ENDIAN
133 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
134 rmesa->swtcl.specoffset = offset;
135 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_RGB, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) );
141 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
142 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) );
148 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
149 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) );
155 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
156 rmesa->swtcl.specoffset = offset;
157 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, (R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT) );
165 if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
168 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
169 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) {
170 GLuint sz = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]->size;
172 fmt_1 |= sz << (3 * i);
173 EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_1F + sz - 1, 0 );
178 if ( (rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] & R200_FOG_USE_MASK)
179 != R200_FOG_USE_SPEC_ALPHA ) {
180 R200_STATECHANGE( rmesa, ctx );
181 rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] &= ~R200_FOG_USE_MASK;
182 rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] |= R200_FOG_USE_SPEC_ALPHA;
185 if (!RENDERINPUTS_EQUAL( rmesa->radeon.tnl_index_bitset, index_bitset ) ||
186 (rmesa->hw.vtx.cmd[VTX_VTXFMT_0] != fmt_0) ||
187 (rmesa->hw.vtx.cmd[VTX_VTXFMT_1] != fmt_1) ) {
189 R200_STATECHANGE( rmesa, vtx );
190 rmesa->hw.vtx.cmd[VTX_VTXFMT_0] = fmt_0;
191 rmesa->hw.vtx.cmd[VTX_VTXFMT_1] = fmt_1;
193 rmesa->radeon.swtcl.vertex_size =
194 _tnl_install_attrs( ctx,
195 rmesa->radeon.swtcl.vertex_attrs,
196 rmesa->radeon.swtcl.vertex_attr_count,
198 rmesa->radeon.swtcl.vertex_size /= 4;
199 RENDERINPUTS_COPY( rmesa->radeon.tnl_index_bitset, index_bitset );
203 static void r200_predict_emit_size( r200ContextPtr rmesa )
205 if (RADEON_DEBUG & RADEON_VERTS)
206 fprintf(stderr, "%s\n", __func__);
207 const int vertex_array_size = 7;
208 const int prim_size = 3;
209 if (!rmesa->radeon.swtcl.emit_prediction) {
210 const int state_size = radeonCountStateEmitSize(&rmesa->radeon);
211 if (rcommonEnsureCmdBufSpace(&rmesa->radeon,
213 vertex_array_size + prim_size,
215 rmesa->radeon.swtcl.emit_prediction = radeonCountStateEmitSize(&rmesa->radeon);
217 rmesa->radeon.swtcl.emit_prediction = state_size;
218 rmesa->radeon.swtcl.emit_prediction += vertex_array_size + prim_size
219 + rmesa->radeon.cmdbuf.cs->cdw;
224 static void r200RenderStart( GLcontext *ctx )
226 r200SetVertexFormat( ctx );
227 if (RADEON_DEBUG & RADEON_VERTS)
228 fprintf(stderr, "%s\n", __func__);
233 * Set vertex state for SW TCL. The primary purpose of this function is to
234 * determine in advance whether or not the hardware can / should do the
235 * projection divide or Mesa should do it.
237 void r200ChooseVertexState( GLcontext *ctx )
239 r200ContextPtr rmesa = R200_CONTEXT( ctx );
240 TNLcontext *tnl = TNL_CONTEXT(ctx);
244 /* We must ensure that we don't do _tnl_need_projected_coords while in a
245 * rasterization fallback. As this function will be called again when we
246 * leave a rasterization fallback, we can just skip it for now.
248 if (rmesa->radeon.Fallback != 0)
251 vte = rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL];
252 vap = rmesa->hw.vap.cmd[VAP_SE_VAP_CNTL];
254 /* HW perspective divide is a win, but tiny vertex formats are a
257 if (!RENDERINPUTS_TEST_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )
258 || (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
259 rmesa->swtcl.needproj = GL_TRUE;
260 vte |= R200_VTX_XY_FMT | R200_VTX_Z_FMT;
261 vte &= ~R200_VTX_W0_FMT;
262 if (RENDERINPUTS_TEST_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
263 vap &= ~R200_VAP_FORCE_W_TO_ONE;
266 vap |= R200_VAP_FORCE_W_TO_ONE;
270 rmesa->swtcl.needproj = GL_FALSE;
271 vte &= ~(R200_VTX_XY_FMT | R200_VTX_Z_FMT);
272 vte |= R200_VTX_W0_FMT;
273 vap &= ~R200_VAP_FORCE_W_TO_ONE;
276 _tnl_need_projected_coords( ctx, rmesa->swtcl.needproj );
278 if (vte != rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL]) {
279 R200_STATECHANGE( rmesa, vte );
280 rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL] = vte;
283 if (vap != rmesa->hw.vap.cmd[VAP_SE_VAP_CNTL]) {
284 R200_STATECHANGE( rmesa, vap );
285 rmesa->hw.vap.cmd[VAP_SE_VAP_CNTL] = vap;
289 void r200_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
291 r200ContextPtr rmesa = R200_CONTEXT(ctx);
292 if (RADEON_DEBUG & RADEON_VERTS)
293 fprintf(stderr, "%s\n", __func__);
296 radeonEmitState(&rmesa->radeon);
297 r200EmitVertexAOS( rmesa,
298 rmesa->radeon.swtcl.vertex_size,
299 rmesa->radeon.swtcl.bo,
303 r200EmitVbufPrim( rmesa,
304 rmesa->radeon.swtcl.hw_primitive,
305 rmesa->radeon.swtcl.numverts);
306 if ( rmesa->radeon.swtcl.emit_prediction < rmesa->radeon.cmdbuf.cs->cdw )
307 WARN_ONCE("Rendering was %d commands larger than predicted size."
308 " We might overflow command buffer.\n",
309 rmesa->radeon.cmdbuf.cs->cdw - rmesa->radeon.swtcl.emit_prediction );
311 rmesa->radeon.swtcl.emit_prediction = 0;
315 /**************************************************************************/
318 static INLINE GLuint reduced_hw_prim( GLcontext *ctx, GLuint prim)
322 return (ctx->Point.PointSprite ||
323 ((ctx->_TriangleCaps & (DD_POINT_SIZE | DD_POINT_ATTEN)) &&
324 !(ctx->_TriangleCaps & (DD_POINT_SMOOTH)))) ?
325 R200_VF_PRIM_POINT_SPRITES : R200_VF_PRIM_POINTS;
331 return R200_VF_PRIM_LINES;
333 /* all others reduced to triangles */
334 return R200_VF_PRIM_TRIANGLES;
339 static void r200RasterPrimitive( GLcontext *ctx, GLuint hwprim );
340 static void r200RenderPrimitive( GLcontext *ctx, GLenum prim );
341 static void r200ResetLineStipple( GLcontext *ctx );
343 /***********************************************************************
344 * Emit primitives as inline vertices *
345 ***********************************************************************/
347 #define HAVE_POINTS 1
349 #define HAVE_LINE_STRIPS 1
350 #define HAVE_TRIANGLES 1
351 #define HAVE_TRI_STRIPS 1
352 #define HAVE_TRI_STRIP_1 0
353 #define HAVE_TRI_FANS 1
355 #define HAVE_QUAD_STRIPS 0
356 #define HAVE_POLYGONS 1
359 static void* r200_alloc_verts( r200ContextPtr rmesa, GLuint n, GLuint size)
363 r200_predict_emit_size( rmesa );
364 rv = rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 );
371 #define CTX_ARG r200ContextPtr rmesa
372 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
373 #define ALLOC_VERTS( n, size ) r200_alloc_verts(rmesa, n, size)
375 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
376 const char *r200verts = (char *)rmesa->radeon.swtcl.verts;
377 #define VERT(x) (radeonVertex *)(r200verts + ((x) * vertsize * sizeof(int)))
378 #define VERTEX radeonVertex
379 #define DO_DEBUG_VERTS (1 && (R200_DEBUG & RADEON_VERTS))
382 #define TAG(x) r200_##x
383 #include "tnl_dd/t_dd_triemit.h"
386 /***********************************************************************
387 * Macros for t_dd_tritmp.h to draw basic primitives *
388 ***********************************************************************/
390 #define QUAD( a, b, c, d ) r200_quad( rmesa, a, b, c, d )
391 #define TRI( a, b, c ) r200_triangle( rmesa, a, b, c )
392 #define LINE( a, b ) r200_line( rmesa, a, b )
393 #define POINT( a ) r200_point( rmesa, a )
395 /***********************************************************************
396 * Build render functions from dd templates *
397 ***********************************************************************/
399 #define R200_TWOSIDE_BIT 0x01
400 #define R200_UNFILLED_BIT 0x02
401 #define R200_MAX_TRIFUNC 0x04
405 tnl_points_func points;
407 tnl_triangle_func triangle;
409 } rast_tab[R200_MAX_TRIFUNC];
412 #define DO_FALLBACK 0
413 #define DO_UNFILLED (IND & R200_UNFILLED_BIT)
414 #define DO_TWOSIDE (IND & R200_TWOSIDE_BIT)
421 #define DO_FULL_QUAD 1
424 #define HAVE_BACK_COLORS 0
425 #define HAVE_HW_FLATSHADE 1
428 #define DEPTH_SCALE 1.0
429 #define UNFILLED_TRI unfilled_tri
430 #define UNFILLED_QUAD unfilled_quad
431 #define VERT_X(_v) _v->v.x
432 #define VERT_Y(_v) _v->v.y
433 #define VERT_Z(_v) _v->v.z
434 #define AREA_IS_CCW( a ) (a < 0)
435 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
437 #define VERT_SET_RGBA( v, c ) \
439 radeon_color_t *color = (radeon_color_t *)&((v)->ui[coloroffset]); \
440 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
441 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
442 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
443 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
446 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
448 #define VERT_SET_SPEC( v, c ) \
451 radeon_color_t *spec = (radeon_color_t *)&((v)->ui[specoffset]); \
452 UNCLAMPED_FLOAT_TO_UBYTE(spec->red, (c)[0]); \
453 UNCLAMPED_FLOAT_TO_UBYTE(spec->green, (c)[1]); \
454 UNCLAMPED_FLOAT_TO_UBYTE(spec->blue, (c)[2]); \
457 #define VERT_COPY_SPEC( v0, v1 ) \
460 radeon_color_t *spec0 = (radeon_color_t *)&((v0)->ui[specoffset]); \
461 radeon_color_t *spec1 = (radeon_color_t *)&((v1)->ui[specoffset]); \
462 spec0->red = spec1->red; \
463 spec0->green = spec1->green; \
464 spec0->blue = spec1->blue; \
468 /* These don't need LE32_TO_CPU() as they used to save and restore
469 * colors which are already in the correct format.
471 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
472 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
473 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
474 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
480 #define LOCAL_VARS(n) \
481 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
482 GLuint color[n] = {0}, spec[n] = {0}; \
483 GLuint coloroffset = rmesa->swtcl.coloroffset; \
484 GLuint specoffset = rmesa->swtcl.specoffset; \
485 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
487 /***********************************************************************
488 * Helpers for rendering unfilled primitives *
489 ***********************************************************************/
491 #define RASTERIZE(x) r200RasterPrimitive( ctx, reduced_hw_prim(ctx, x) )
492 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
495 #include "tnl_dd/t_dd_unfilled.h"
499 /***********************************************************************
500 * Generate GL render functions *
501 ***********************************************************************/
506 #include "tnl_dd/t_dd_tritmp.h"
508 #define IND (R200_TWOSIDE_BIT)
509 #define TAG(x) x##_twoside
510 #include "tnl_dd/t_dd_tritmp.h"
512 #define IND (R200_UNFILLED_BIT)
513 #define TAG(x) x##_unfilled
514 #include "tnl_dd/t_dd_tritmp.h"
516 #define IND (R200_TWOSIDE_BIT|R200_UNFILLED_BIT)
517 #define TAG(x) x##_twoside_unfilled
518 #include "tnl_dd/t_dd_tritmp.h"
521 static void init_rast_tab( void )
526 init_twoside_unfilled();
529 /**********************************************************************/
530 /* Render unclipped begin/end objects */
531 /**********************************************************************/
533 #define RENDER_POINTS( start, count ) \
534 for ( ; start < count ; start++) \
535 r200_point( rmesa, VERT(start) )
536 #define RENDER_LINE( v0, v1 ) \
537 r200_line( rmesa, VERT(v0), VERT(v1) )
538 #define RENDER_TRI( v0, v1, v2 ) \
539 r200_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
540 #define RENDER_QUAD( v0, v1, v2, v3 ) \
541 r200_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
542 #define INIT(x) do { \
543 r200RenderPrimitive( ctx, x ); \
547 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
548 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
549 const char *r200verts = (char *)rmesa->radeon.swtcl.verts; \
550 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
551 const GLboolean stipple = ctx->Line.StippleFlag; \
552 (void) elt; (void) stipple;
553 #define RESET_STIPPLE if ( stipple ) r200ResetLineStipple( ctx );
554 #define RESET_OCCLUSION
555 #define PRESERVE_VB_DEFS
557 #define TAG(x) r200_##x##_verts
558 #include "tnl/t_vb_rendertmp.h"
561 #define TAG(x) r200_##x##_elts
562 #define ELT(x) elt[x]
563 #include "tnl/t_vb_rendertmp.h"
567 /**********************************************************************/
568 /* Choose render functions */
569 /**********************************************************************/
571 void r200ChooseRenderState( GLcontext *ctx )
573 TNLcontext *tnl = TNL_CONTEXT(ctx);
574 r200ContextPtr rmesa = R200_CONTEXT(ctx);
576 GLuint flags = ctx->_TriangleCaps;
578 if (!rmesa->radeon.TclFallback || rmesa->radeon.Fallback)
581 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= R200_TWOSIDE_BIT;
582 if (flags & DD_TRI_UNFILLED) index |= R200_UNFILLED_BIT;
584 if (index != rmesa->radeon.swtcl.RenderIndex) {
585 tnl->Driver.Render.Points = rast_tab[index].points;
586 tnl->Driver.Render.Line = rast_tab[index].line;
587 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
588 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
589 tnl->Driver.Render.Quad = rast_tab[index].quad;
592 tnl->Driver.Render.PrimTabVerts = r200_render_tab_verts;
593 tnl->Driver.Render.PrimTabElts = r200_render_tab_elts;
594 tnl->Driver.Render.ClippedPolygon = r200_fast_clipped_poly;
596 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
597 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
598 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
601 rmesa->radeon.swtcl.RenderIndex = index;
606 /**********************************************************************/
607 /* High level hooks for t_vb_render.c */
608 /**********************************************************************/
611 static void r200RasterPrimitive( GLcontext *ctx, GLuint hwprim )
613 r200ContextPtr rmesa = R200_CONTEXT(ctx);
615 if (rmesa->radeon.swtcl.hw_primitive != hwprim) {
616 /* need to disable perspective-correct texturing for point sprites */
617 if ((hwprim & 0xf) == R200_VF_PRIM_POINT_SPRITES && ctx->Point.PointSprite) {
618 if (rmesa->hw.set.cmd[SET_RE_CNTL] & R200_PERSPECTIVE_ENABLE) {
619 R200_STATECHANGE( rmesa, set );
620 rmesa->hw.set.cmd[SET_RE_CNTL] &= ~R200_PERSPECTIVE_ENABLE;
623 else if (!(rmesa->hw.set.cmd[SET_RE_CNTL] & R200_PERSPECTIVE_ENABLE)) {
624 R200_STATECHANGE( rmesa, set );
625 rmesa->hw.set.cmd[SET_RE_CNTL] |= R200_PERSPECTIVE_ENABLE;
627 R200_NEWPRIM( rmesa );
628 rmesa->radeon.swtcl.hw_primitive = hwprim;
632 static void r200RenderPrimitive( GLcontext *ctx, GLenum prim )
634 r200ContextPtr rmesa = R200_CONTEXT(ctx);
635 rmesa->radeon.swtcl.render_primitive = prim;
636 if (prim < GL_TRIANGLES || !(ctx->_TriangleCaps & DD_TRI_UNFILLED))
637 r200RasterPrimitive( ctx, reduced_hw_prim(ctx, prim) );
640 static void r200RenderFinish( GLcontext *ctx )
644 static void r200ResetLineStipple( GLcontext *ctx )
646 r200ContextPtr rmesa = R200_CONTEXT(ctx);
647 R200_STATECHANGE( rmesa, lin );
651 /**********************************************************************/
652 /* Transition to/from hardware rasterization. */
653 /**********************************************************************/
655 static const char * const fallbackStrings[] = {
657 "glDrawBuffer(GL_FRONT_AND_BACK)",
658 "glEnable(GL_STENCIL) without hw stencil buffer",
659 "glRenderMode(selection or feedback)",
661 "Mixing GL_CLAMP_TO_BORDER and GL_CLAMP (or GL_MIRROR_CLAMP_ATI)"
665 static const char *getFallbackString(GLuint bit)
672 return fallbackStrings[i];
676 void r200Fallback( GLcontext *ctx, GLuint bit, GLboolean mode )
678 r200ContextPtr rmesa = R200_CONTEXT(ctx);
679 TNLcontext *tnl = TNL_CONTEXT(ctx);
680 GLuint oldfallback = rmesa->radeon.Fallback;
683 rmesa->radeon.Fallback |= bit;
684 if (oldfallback == 0) {
685 radeon_firevertices(&rmesa->radeon);
686 TCL_FALLBACK( ctx, R200_TCL_FALLBACK_RASTER, GL_TRUE );
687 _swsetup_Wakeup( ctx );
688 rmesa->radeon.swtcl.RenderIndex = ~0;
689 if (R200_DEBUG & RADEON_FALLBACKS) {
690 fprintf(stderr, "R200 begin rasterization fallback: 0x%x %s\n",
691 bit, getFallbackString(bit));
696 rmesa->radeon.Fallback &= ~bit;
697 if (oldfallback == bit) {
699 _swrast_flush( ctx );
700 tnl->Driver.Render.Start = r200RenderStart;
701 tnl->Driver.Render.PrimitiveNotify = r200RenderPrimitive;
702 tnl->Driver.Render.Finish = r200RenderFinish;
704 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
705 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
706 tnl->Driver.Render.Interp = _tnl_interp;
708 tnl->Driver.Render.ResetLineStipple = r200ResetLineStipple;
709 TCL_FALLBACK( ctx, R200_TCL_FALLBACK_RASTER, GL_FALSE );
710 if (rmesa->radeon.TclFallback) {
711 /* These are already done if rmesa->radeon.TclFallback goes to
712 * zero above. But not if it doesn't (R200_NO_TCL for
715 _tnl_invalidate_vertex_state( ctx, ~0 );
716 _tnl_invalidate_vertices( ctx, ~0 );
717 RENDERINPUTS_ZERO( rmesa->radeon.tnl_index_bitset );
718 r200ChooseVertexState( ctx );
719 r200ChooseRenderState( ctx );
721 if (R200_DEBUG & RADEON_FALLBACKS) {
722 fprintf(stderr, "R200 end rasterization fallback: 0x%x %s\n",
723 bit, getFallbackString(bit));
733 * Cope with depth operations by drawing individual pixels as points.
736 * The way the vertex state is set in this routine is hokey. It seems to
737 * work, but it's very hackish. This whole routine is pretty hackish. If
738 * the bitmap is small enough, it seems like it would be faster to copy it
739 * to AGP memory and use it as a non-power-of-two texture (i.e.,
740 * NV_texture_rectangle).
743 r200PointsBitmap( GLcontext *ctx, GLint px, GLint py,
744 GLsizei width, GLsizei height,
745 const struct gl_pixelstore_attrib *unpack,
746 const GLubyte *bitmap )
748 r200ContextPtr rmesa = R200_CONTEXT(ctx);
749 const GLfloat *rc = ctx->Current.RasterColor;
758 TCL_FALLBACK( ctx, R200_TCL_FALLBACK_BITMAP, 1 );
760 /* Choose tiny vertex format
763 const GLuint fmt_0 = R200_VTX_XY | R200_VTX_Z0 | R200_VTX_W0
764 | (R200_VTX_PK_RGBA << R200_VTX_COLOR_0_SHIFT);
765 const GLuint fmt_1 = 0;
766 GLuint vte = rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL];
767 GLuint vap = rmesa->hw.vap.cmd[VAP_SE_VAP_CNTL];
769 vte &= ~(R200_VTX_XY_FMT | R200_VTX_Z_FMT);
770 vte |= R200_VTX_W0_FMT;
771 vap &= ~R200_VAP_FORCE_W_TO_ONE;
773 rmesa->radeon.swtcl.vertex_size = 5;
775 if ( (rmesa->hw.vtx.cmd[VTX_VTXFMT_0] != fmt_0)
776 || (rmesa->hw.vtx.cmd[VTX_VTXFMT_1] != fmt_1) ) {
778 R200_STATECHANGE( rmesa, vtx );
779 rmesa->hw.vtx.cmd[VTX_VTXFMT_0] = fmt_0;
780 rmesa->hw.vtx.cmd[VTX_VTXFMT_1] = fmt_1;
783 if (vte != rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL]) {
784 R200_STATECHANGE( rmesa, vte );
785 rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL] = vte;
788 if (vap != rmesa->hw.vap.cmd[VAP_SE_VAP_CNTL]) {
789 R200_STATECHANGE( rmesa, vap );
790 rmesa->hw.vap.cmd[VAP_SE_VAP_CNTL] = vap;
794 /* Ready for point primitives:
796 r200RenderPrimitive( ctx, GL_POINTS );
798 /* Turn off the hw viewport transformation:
800 R200_STATECHANGE( rmesa, vte );
801 orig_vte = rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL];
802 rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL] &= ~(R200_VPORT_X_SCALE_ENA |
803 R200_VPORT_Y_SCALE_ENA |
804 R200_VPORT_Z_SCALE_ENA |
805 R200_VPORT_X_OFFSET_ENA |
806 R200_VPORT_Y_OFFSET_ENA |
807 R200_VPORT_Z_OFFSET_ENA);
809 /* Turn off other stuff: Stipple?, texture?, blending?, etc.
813 /* Populate the vertex
815 * Incorporate FOG into RGBA
817 if (ctx->Fog.Enabled) {
818 const GLfloat *fc = ctx->Fog.Color;
822 if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
823 f = _swrast_z_to_fogfactor(ctx, ctx->Current.Attrib[VERT_ATTRIB_FOG][0]);
825 f = _swrast_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
827 color[0] = f * rc[0] + (1.F - f) * fc[0];
828 color[1] = f * rc[1] + (1.F - f) * fc[1];
829 color[2] = f * rc[2] + (1.F - f) * fc[2];
832 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.red, color[0]);
833 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.green, color[1]);
834 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.blue, color[2]);
835 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.alpha, color[3]);
838 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.red, rc[0]);
839 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.green, rc[1]);
840 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.blue, rc[2]);
841 UNCLAMPED_FLOAT_TO_CHAN(vert.tv.color.alpha, rc[3]);
845 vert.tv.z = ctx->Current.RasterPos[2];
848 /* Update window height
850 LOCK_HARDWARE( &rmesa->radeon );
851 UNLOCK_HARDWARE( &rmesa->radeon );
852 h = radeon_get_drawable(&rmesa->radeon)->h + radeon_get_drawable(&rmesa->radeon)->y;
853 px += radeon_get_drawable(&rmesa->radeon)->x;
855 /* Clipping handled by existing mechansims in r200_ioctl.c?
857 for (row=0; row<height; row++) {
858 const GLubyte *src = (const GLubyte *)
859 _mesa_image_address2d(unpack, bitmap, width, height,
860 GL_COLOR_INDEX, GL_BITMAP, row, 0 );
862 if (unpack->LsbFirst) {
864 GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
865 for (col=0; col<width; col++) {
868 vert.tv.y = h - (py+row) - 1;
869 r200_point( rmesa, &vert );
872 mask = ((mask << 1) & 0xff) | (mask >> 7);
875 /* get ready for next row */
881 GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
882 for (col=0; col<width; col++) {
885 vert.tv.y = h - (py+row) - 1;
886 r200_point( rmesa, &vert );
889 mask = ((mask << 7) & 0xff) | (mask >> 1);
891 /* get ready for next row */
897 /* Fire outstanding vertices, restore state
899 R200_STATECHANGE( rmesa, vte );
900 rmesa->hw.vte.cmd[VTE_SE_VTE_CNTL] = orig_vte;
904 TCL_FALLBACK( ctx, R200_TCL_FALLBACK_BITMAP, 0 );
906 /* Need to restore vertexformat?
908 if (rmesa->radeon.TclFallback)
909 r200ChooseVertexState( ctx );
914 /**********************************************************************/
915 /* Initialization. */
916 /**********************************************************************/
918 void r200InitSwtcl( GLcontext *ctx )
920 TNLcontext *tnl = TNL_CONTEXT(ctx);
921 r200ContextPtr rmesa = R200_CONTEXT(ctx);
922 static int firsttime = 1;
928 rmesa->radeon.swtcl.emit_prediction = 0;
930 tnl->Driver.Render.Start = r200RenderStart;
931 tnl->Driver.Render.Finish = r200RenderFinish;
932 tnl->Driver.Render.PrimitiveNotify = r200RenderPrimitive;
933 tnl->Driver.Render.ResetLineStipple = r200ResetLineStipple;
934 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
935 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
936 tnl->Driver.Render.Interp = _tnl_interp;
938 /* FIXME: what are these numbers? */
939 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
940 36 * sizeof(GLfloat) );
942 rmesa->radeon.swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
943 rmesa->radeon.swtcl.RenderIndex = ~0;
944 rmesa->radeon.swtcl.render_primitive = GL_TRIANGLES;
945 rmesa->radeon.swtcl.hw_primitive = 0;