1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_tcl.c,v 1.2 2002/12/16 16:18:55 dawes Exp $ */
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Keith Whitwell <keith@tungstengraphics.com>
43 #include "array_cache/acache.h"
45 #include "tnl/t_pipeline.h"
47 #include "r200_context.h"
48 #include "r200_state.h"
49 #include "r200_ioctl.h"
52 #include "r200_swtcl.h"
53 #include "r200_maos.h"
59 #define HAVE_LINE_LOOP 0
60 #define HAVE_LINE_STRIPS 1
61 #define HAVE_TRIANGLES 1
62 #define HAVE_TRI_STRIPS 1
63 #define HAVE_TRI_STRIP_1 0
64 #define HAVE_TRI_FANS 1
65 #define HAVE_QUADS 0 /* hw quad verts in wrong order??? */
66 #define HAVE_QUAD_STRIPS 1
67 #define HAVE_POLYGONS 1
71 #define HW_POINTS R200_VF_PRIM_POINTS
72 #define HW_LINES R200_VF_PRIM_LINES
73 #define HW_LINE_LOOP 0
74 #define HW_LINE_STRIP R200_VF_PRIM_LINE_STRIP
75 #define HW_TRIANGLES R200_VF_PRIM_TRIANGLES
76 #define HW_TRIANGLE_STRIP_0 R200_VF_PRIM_TRIANGLE_STRIP
77 #define HW_TRIANGLE_STRIP_1 0
78 #define HW_TRIANGLE_FAN R200_VF_PRIM_TRIANGLE_FAN
79 #define HW_QUADS R200_VF_PRIM_QUADS
80 #define HW_QUAD_STRIP R200_VF_PRIM_QUAD_STRIP
81 #define HW_POLYGON R200_VF_PRIM_POLYGON
84 static GLboolean discrete_prim
[0x10] = {
92 0, /* 7 tri_w_flags */
93 1, /* 8 rect list (unused) */
94 1, /* 9 3vert point */
96 0, /* b point sprite */
104 #define LOCAL_VARS r200ContextPtr rmesa = R200_CONTEXT(ctx)
105 #define ELT_TYPE GLushort
107 #define ELT_INIT(prim, hw_prim) \
108 r200TclPrimitive( ctx, prim, hw_prim | R200_VF_PRIM_WALK_IND )
110 #define GET_MESA_ELTS() rmesa->tcl.Elts
113 /* Don't really know how many elts will fit in what's left of cmdbuf,
114 * as there is state to emit, etc:
117 /* Testing on isosurf shows a maximum around here. Don't know if it's
118 * the card or driver or kernel module that is causing the behaviour.
120 #define GET_MAX_HW_ELTS() 300
122 #define RESET_STIPPLE() do { \
123 R200_STATECHANGE( rmesa, lin ); \
124 r200EmitState( rmesa ); \
127 #define AUTO_STIPPLE( mode ) do { \
128 R200_STATECHANGE( rmesa, lin ); \
130 rmesa->hw.lin.cmd[LIN_RE_LINE_PATTERN] |= \
131 R200_LINE_PATTERN_AUTO_RESET; \
133 rmesa->hw.lin.cmd[LIN_RE_LINE_PATTERN] &= \
134 ~R200_LINE_PATTERN_AUTO_RESET; \
135 r200EmitState( rmesa ); \
139 #define ALLOC_ELTS(nr) r200AllocElts( rmesa, nr )
141 static GLushort
*r200AllocElts( r200ContextPtr rmesa
, GLuint nr
)
143 if (rmesa
->dma
.flush
)
144 rmesa
->dma
.flush( rmesa
);
147 rmesa
->tcl
.aos_components
,
148 rmesa
->tcl
.nr_aos_components
, 0 );
150 return r200AllocEltsOpenEnded( rmesa
, rmesa
->tcl
.hw_primitive
, nr
);
154 #define CLOSE_ELTS() R200_NEWPRIM( rmesa )
157 /* TODO: Try to extend existing primitive if both are identical,
158 * discrete and there are no intervening state changes. (Somewhat
159 * duplicates changes to DrawArrays code)
161 static void EMIT_PRIM( GLcontext
*ctx
,
167 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
168 r200TclPrimitive( ctx
, prim
, hwprim
);
171 rmesa
->tcl
.aos_components
,
172 rmesa
->tcl
.nr_aos_components
,
175 /* Why couldn't this packet have taken an offset param?
177 r200EmitVbufPrim( rmesa
,
178 rmesa
->tcl
.hw_primitive
,
184 /* Try & join small primitives
187 #define PREFER_DISCRETE_ELT_PRIM( NR, PRIM ) 0
189 #define PREFER_DISCRETE_ELT_PRIM( NR, PRIM ) \
192 rmesa->tcl.hw_primitive == (PRIM| \
193 R200_VF_TCL_OUTPUT_VTX_ENABLE| \
194 R200_VF_PRIM_WALK_IND)))
197 #ifdef MESA_BIG_ENDIAN
198 /* We could do without (most of) this ugliness if dest was always 32 bit word aligned... */
199 #define EMIT_ELT(dest, offset, x) do { \
200 int off = offset + ( ( (GLuint)dest & 0x2 ) >> 1 ); \
201 GLushort *des = (GLushort *)( (GLuint)dest & ~0x2 ); \
202 (des)[ off + 1 - 2 * ( off & 1 ) ] = (GLushort)(x); } while (0)
204 #define EMIT_ELT(dest, offset, x) (dest)[offset] = (GLushort) (x)
207 #define EMIT_TWO_ELTS(dest, offset, x, y) *(GLuint *)((dest)+offset) = ((y)<<16)|(x);
211 #define TAG(x) tcl_##x
212 #include "tnl_dd/t_dd_dmatmp2.h"
214 /**********************************************************************/
215 /* External entrypoints */
216 /**********************************************************************/
218 void r200EmitPrimitive( GLcontext
*ctx
,
223 tcl_render_tab_verts
[flags
&PRIM_MODE_MASK
]( ctx
, first
, last
, flags
);
226 void r200EmitEltPrimitive( GLcontext
*ctx
,
231 tcl_render_tab_elts
[flags
&PRIM_MODE_MASK
]( ctx
, first
, last
, flags
);
234 void r200TclPrimitive( GLcontext
*ctx
,
238 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
239 GLuint newprim
= hw_prim
| R200_VF_TCL_OUTPUT_VTX_ENABLE
;
241 if (newprim
!= rmesa
->tcl
.hw_primitive
||
242 !discrete_prim
[hw_prim
&0xf]) {
243 R200_NEWPRIM( rmesa
);
244 rmesa
->tcl
.hw_primitive
= newprim
;
249 /**********************************************************************/
250 /* Render pipeline stage */
251 /**********************************************************************/
256 static GLboolean
r200_run_tcl_render( GLcontext
*ctx
,
257 struct tnl_pipeline_stage
*stage
)
259 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
260 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
261 struct vertex_buffer
*VB
= &tnl
->vb
;
264 /* TODO: separate this from the swtnl pipeline
266 if (rmesa
->TclFallback
)
267 return GL_TRUE
; /* fallback to software t&l */
269 if (R200_DEBUG
& DEBUG_PRIMS
)
270 fprintf(stderr
, "%s\n", __FUNCTION__
);
275 r200ReleaseArrays( ctx
, ~0 /* stage->changed_inputs */ );
276 r200EmitArrays( ctx
, stage
->inputs
);
278 rmesa
->tcl
.Elts
= VB
->Elts
;
280 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
282 GLuint prim
= VB
->Primitive
[i
].mode
;
283 GLuint start
= VB
->Primitive
[i
].start
;
284 GLuint length
= VB
->Primitive
[i
].count
;
290 r200EmitEltPrimitive( ctx
, start
, start
+length
, prim
);
292 r200EmitPrimitive( ctx
, start
, start
+length
, prim
);
295 return GL_FALSE
; /* finished the pipe */
300 static void r200_check_tcl_render( GLcontext
*ctx
,
301 struct tnl_pipeline_stage
*stage
)
303 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
304 GLuint inputs
= VERT_BIT_POS
;
308 if (rmesa
->NewGLState
)
309 r200ValidateState( ctx
);
311 if (ctx
->RenderMode
== GL_RENDER
) {
312 /* Make all this event-driven:
314 if (ctx
->Light
.Enabled
) {
315 inputs
|= VERT_BIT_NORMAL
;
317 if (1 || ctx
->Light
.ColorMaterialEnabled
) {
318 inputs
|= VERT_BIT_COLOR0
;
322 inputs
|= VERT_BIT_COLOR0
;
324 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
) {
325 inputs
|= VERT_BIT_COLOR1
;
329 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
) {
330 if (ctx
->Texture
.Unit
[0].TexGenEnabled
) {
331 if (rmesa
->TexGenNeedNormals
[0]) {
332 inputs
|= VERT_BIT_NORMAL
;
335 inputs
|= VERT_BIT_TEX0
;
339 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
) {
340 if (ctx
->Texture
.Unit
[1].TexGenEnabled
) {
341 if (rmesa
->TexGenNeedNormals
[1]) {
342 inputs
|= VERT_BIT_NORMAL
;
345 inputs
|= VERT_BIT_TEX1
;
349 stage
->inputs
= inputs
;
356 static void r200_init_tcl_render( GLcontext
*ctx
,
357 struct tnl_pipeline_stage
*stage
)
359 stage
->check
= r200_check_tcl_render
;
360 stage
->check( ctx
, stage
);
363 static void dtr( struct tnl_pipeline_stage
*stage
)
369 /* Initial state for tcl stage.
371 const struct tnl_pipeline_stage _r200_tcl_stage
=
374 (_DD_NEW_SEPARATE_SPECULAR
|
378 _NEW_RENDERMODE
), /* re-check (new inputs) */
379 0, /* re-run (always runs) */
380 GL_TRUE
, /* active */
381 0, 0, /* inputs (set in check_render), outputs */
382 0, 0, /* changed_inputs, private */
383 dtr
, /* destructor */
384 r200_init_tcl_render
, /* check - initially set to alloc data */
385 r200_run_tcl_render
/* run */
390 /**********************************************************************/
391 /* Validate state at pipeline start */
392 /**********************************************************************/
395 /*-----------------------------------------------------------------------
396 * Manage TCL fallbacks
400 static void transition_to_swtnl( GLcontext
*ctx
)
402 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
403 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
405 R200_NEWPRIM( rmesa
);
406 rmesa
->swtcl
.vertex_format
= 0;
408 r200ChooseVertexState( ctx
);
409 r200ChooseRenderState( ctx
);
411 _mesa_validate_all_lighting_tables( ctx
);
413 tnl
->Driver
.NotifyMaterialChange
=
414 _mesa_validate_all_lighting_tables
;
416 r200ReleaseArrays( ctx
, ~0 );
418 /* Still using the D3D based hardware-rasterizer from the radeon;
419 * need to put the card into D3D mode to make it work:
421 R200_STATECHANGE( rmesa
, vap
);
422 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] &= ~R200_VAP_TCL_ENABLE
;
423 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] |= R200_VAP_D3D_TEX_DEFAULT
;
425 R200_STATECHANGE( rmesa
, vte
);
426 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] &= ~R200_VTX_W0_FMT
;
428 R200_STATECHANGE( rmesa
, set
);
429 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] |= (R200_VTX_STQ0_D3D
|
434 static void transition_to_hwtnl( GLcontext
*ctx
)
436 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
437 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
439 _tnl_need_projected_coords( ctx
, GL_FALSE
);
441 r200UpdateMaterial( ctx
);
443 tnl
->Driver
.NotifyMaterialChange
= r200UpdateMaterial
;
445 if ( rmesa
->dma
.flush
)
446 rmesa
->dma
.flush( rmesa
);
448 rmesa
->dma
.flush
= 0;
449 rmesa
->swtcl
.vertex_format
= 0;
451 if (rmesa
->swtcl
.indexed_verts
.buf
)
452 r200ReleaseDmaRegion( rmesa
, &rmesa
->swtcl
.indexed_verts
,
455 R200_STATECHANGE( rmesa
, vap
);
456 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] |= R200_VAP_TCL_ENABLE
;
457 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] &= ~(R200_VAP_FORCE_W_TO_ONE
|
458 R200_VAP_D3D_TEX_DEFAULT
);
460 R200_STATECHANGE( rmesa
, vte
);
461 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] &= ~(R200_VTX_XY_FMT
|R200_VTX_Z_FMT
);
462 rmesa
->hw
.vte
.cmd
[VTE_SE_VTE_CNTL
] |= R200_VTX_W0_FMT
;
464 R200_STATECHANGE( rmesa
, set
);
465 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] &= ~(R200_VTX_STQ0_D3D
|
469 if (R200_DEBUG
& DEBUG_FALLBACKS
)
470 fprintf(stderr
, "R200 end tcl fallback\n");
474 static char *fallbackStrings
[] = {
475 "Rasterization fallback",
476 "Unfilled triangles",
477 "Twosided lighting, differing materials",
478 "Materials in VB (maybe between begin/end)",
486 static char *getFallbackString(GLuint bit
)
493 return fallbackStrings
[i
];
498 void r200TclFallback( GLcontext
*ctx
, GLuint bit
, GLboolean mode
)
500 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
501 GLuint oldfallback
= rmesa
->TclFallback
;
504 rmesa
->TclFallback
|= bit
;
505 if (oldfallback
== 0) {
506 if (R200_DEBUG
& DEBUG_FALLBACKS
)
507 fprintf(stderr
, "R200 begin tcl fallback %s\n",
508 getFallbackString( bit
));
509 transition_to_swtnl( ctx
);
513 rmesa
->TclFallback
&= ~bit
;
514 if (oldfallback
== bit
) {
515 if (R200_DEBUG
& DEBUG_FALLBACKS
)
516 fprintf(stderr
, "R200 end tcl fallback %s\n",
517 getFallbackString( bit
));
518 transition_to_hwtnl( ctx
);