1 /**************************************************************************
3 Copyright (C) 2007 Dave Airlie
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Dave Airlie <airlied@linux.ie>
33 /* derived from r200 swtcl path */
37 #include "main/glheader.h"
38 #include "main/mtypes.h"
39 #include "main/colormac.h"
40 #include "main/enums.h"
41 #include "main/image.h"
42 #include "main/imports.h"
43 #include "main/light.h"
44 #include "main/macros.h"
46 #include "swrast/s_context.h"
47 #include "swrast/s_fog.h"
48 #include "swrast_setup/swrast_setup.h"
49 #include "math/m_translate.h"
51 #include "tnl/t_context.h"
52 #include "tnl/t_pipeline.h"
54 #include "r300_context.h"
55 #include "r300_swtcl.h"
56 #include "r300_state.h"
57 #include "r300_ioctl.h"
58 #include "r300_emit.h"
61 static void flush_last_swtcl_prim( r300ContextPtr rmesa
);
64 void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, GLuint offset
);
65 void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
);
66 #define EMIT_ATTR( ATTR, STYLE ) \
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++; \
73 #define EMIT_PAD( N ) \
75 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = 0; \
76 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = EMIT_PAD; \
77 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].offset = (N); \
78 rmesa->swtcl.vertex_attr_count++; \
81 static void r300SetVertexFormat( GLcontext
*ctx
)
83 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
84 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
85 struct vertex_buffer
*VB
= &tnl
->vb
;
86 DECLARE_RENDERINPUTS(index_bitset
);
87 GLuint InputsRead
= 0, OutputsWritten
= 0;
92 GLint inputs
[VERT_ATTRIB_MAX
];
93 GLint tab
[VERT_ATTRIB_MAX
];
94 int swizzle
[VERT_ATTRIB_MAX
][4];
96 GLuint sz
, vap_fmt_1
= 0;
98 DECLARE_RENDERINPUTS(render_inputs_bitset
);
99 RENDERINPUTS_COPY(render_inputs_bitset
, tnl
->render_inputs_bitset
);
100 RENDERINPUTS_COPY( index_bitset
, tnl
->render_inputs_bitset
);
101 RENDERINPUTS_COPY(rmesa
->state
.render_inputs_bitset
, render_inputs_bitset
);
103 vte
= rmesa
->hw
.vte
.cmd
[1];
104 vte
&= ~(R300_VTX_XY_FMT
| R300_VTX_Z_FMT
| R300_VTX_W0_FMT
);
107 if ( VB
->NdcPtr
!= NULL
) {
108 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
109 vte
|= R300_VTX_XY_FMT
| R300_VTX_Z_FMT
;
112 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
113 vte
|= R300_VTX_W0_FMT
;
116 assert( VB
->AttribPtr
[VERT_ATTRIB_POS
] != NULL
);
117 rmesa
->swtcl
.vertex_attr_count
= 0;
119 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
120 * build up a hardware vertex.
122 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POS
)) {
123 sz
= VB
->AttribPtr
[VERT_ATTRIB_POS
]->size
;
124 InputsRead
|= 1 << VERT_ATTRIB_POS
;
125 OutputsWritten
|= 1 << VERT_RESULT_HPOS
;
126 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_1F
+ sz
- 1 );
130 EMIT_PAD(4 * sizeof(float));
133 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
134 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
);
135 vap_fmt_0
|= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT
;
139 if (RENDERINPUTS_TEST(index_bitset
, _TNL_ATTRIB_COLOR0
)) {
140 sz
= VB
->AttribPtr
[VERT_ATTRIB_COLOR0
]->size
;
141 rmesa
->swtcl
.coloroffset
= offset
;
142 InputsRead
|= 1 << VERT_ATTRIB_COLOR0
;
143 OutputsWritten
|= 1 << VERT_RESULT_COL0
;
144 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_1F
+ sz
- 1 );
148 rmesa
->swtcl
.specoffset
= 0;
149 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
150 sz
= VB
->AttribPtr
[VERT_ATTRIB_COLOR1
]->size
;
151 rmesa
->swtcl
.specoffset
= offset
;
152 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_1F
+ sz
- 1 );
153 InputsRead
|= 1 << VERT_ATTRIB_COLOR1
;
154 OutputsWritten
|= 1 << VERT_RESULT_COL1
;
157 if (RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
160 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
161 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_TEX(i
) )) {
162 sz
= VB
->TexCoordPtr
[i
]->size
;
163 InputsRead
|= 1 << (VERT_ATTRIB_TEX0
+ i
);
164 OutputsWritten
|= 1 << (VERT_RESULT_TEX0
+ i
);
165 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_1F
+ sz
- 1 );
166 vap_fmt_1
|= sz
<< (3 * i
);
171 for (i
= 0, nr
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
172 if (InputsRead
& (1 << i
)) {
179 /* Fixed, apply to vir0 only */
180 if (InputsRead
& (1 << VERT_ATTRIB_POS
))
181 inputs
[VERT_ATTRIB_POS
] = 0;
182 if (InputsRead
& (1 << VERT_ATTRIB_COLOR0
))
183 inputs
[VERT_ATTRIB_COLOR0
] = 2;
184 if (InputsRead
& (1 << VERT_ATTRIB_COLOR1
))
185 inputs
[VERT_ATTRIB_COLOR1
] = 3;
186 for (i
= VERT_ATTRIB_TEX0
; i
<= VERT_ATTRIB_TEX7
; i
++)
187 if (InputsRead
& (1 << i
))
188 inputs
[i
] = 6 + (i
- VERT_ATTRIB_TEX0
);
190 for (i
= 0, nr
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
191 if (InputsRead
& (1 << i
)) {
196 for (i
= 0; i
< nr
; i
++) {
199 swizzle
[i
][0] = SWIZZLE_ZERO
;
200 swizzle
[i
][1] = SWIZZLE_ZERO
;
201 swizzle
[i
][2] = SWIZZLE_ZERO
;
202 swizzle
[i
][3] = SWIZZLE_ONE
;
204 for (ci
= 0; ci
< VB
->AttribPtr
[tab
[i
]]->size
; ci
++) {
210 R300_STATECHANGE(rmesa
, vir
[0]);
211 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[0].cmd
)->packet0
.count
=
212 r300VAPInputRoute0(&rmesa
->hw
.vir
[0].cmd
[R300_VIR_CNTL_0
],
213 VB
->AttribPtr
, inputs
, tab
, nr
);
214 R300_STATECHANGE(rmesa
, vir
[1]);
215 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[1].cmd
)->packet0
.count
=
216 r300VAPInputRoute1(&rmesa
->hw
.vir
[1].cmd
[R300_VIR_CNTL_0
], swizzle
,
219 R300_STATECHANGE(rmesa
, vic
);
220 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_0
] = r300VAPInputCntl0(ctx
, InputsRead
);
221 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_1
] = r300VAPInputCntl1(ctx
, InputsRead
);
223 R300_STATECHANGE(rmesa
, vof
);
224 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = r300VAPOutputCntl0(ctx
, OutputsWritten
);
225 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = vap_fmt_1
;
227 rmesa
->swtcl
.vertex_size
=
228 _tnl_install_attrs( ctx
,
229 rmesa
->swtcl
.vertex_attrs
,
230 rmesa
->swtcl
.vertex_attr_count
,
233 rmesa
->swtcl
.vertex_size
/= 4;
235 RENDERINPUTS_COPY( rmesa
->tnl_index_bitset
, index_bitset
);
238 R300_STATECHANGE(rmesa
, vte
);
239 rmesa
->hw
.vte
.cmd
[1] = vte
;
240 rmesa
->hw
.vte
.cmd
[2] = rmesa
->swtcl
.vertex_size
;
244 /* Flush vertices in the current dma region.
246 static void flush_last_swtcl_prim( r300ContextPtr rmesa
)
248 if (RADEON_DEBUG
& DEBUG_IOCTL
)
249 fprintf(stderr
, "%s\n", __FUNCTION__
);
251 rmesa
->dma
.flush
= NULL
;
253 if (rmesa
->dma
.current
.buf
) {
254 struct r300_dma_region
*current
= &rmesa
->dma
.current
;
255 GLuint current_offset
= GET_START(current
);
257 assert (current
->start
+
258 rmesa
->swtcl
.numverts
* rmesa
->swtcl
.vertex_size
* 4 ==
261 if (rmesa
->dma
.current
.start
!= rmesa
->dma
.current
.ptr
) {
263 r300EnsureCmdBufSpace( rmesa
, rmesa
->hw
.max_state_size
+ (12*sizeof(int)), __FUNCTION__
);
265 r300EmitState(rmesa
);
267 r300EmitVertexAOS( rmesa
,
268 rmesa
->swtcl
.vertex_size
,
271 r300EmitVbufPrim( rmesa
,
272 rmesa
->swtcl
.hw_primitive
,
273 rmesa
->swtcl
.numverts
);
275 r300EmitCacheFlush(rmesa
);
278 rmesa
->swtcl
.numverts
= 0;
279 current
->start
= current
->ptr
;
283 /* Alloc space in the current dma region.
286 r300AllocDmaLowVerts( r300ContextPtr rmesa
, int nverts
, int vsize
)
288 GLuint bytes
= vsize
* nverts
;
290 if ( rmesa
->dma
.current
.ptr
+ bytes
> rmesa
->dma
.current
.end
)
291 r300RefillCurrentDmaRegion( rmesa
, bytes
);
293 if (!rmesa
->dma
.flush
) {
294 rmesa
->radeon
.glCtx
->Driver
.NeedFlush
|= FLUSH_STORED_VERTICES
;
295 rmesa
->dma
.flush
= flush_last_swtcl_prim
;
298 ASSERT( vsize
== rmesa
->swtcl
.vertex_size
* 4 );
299 ASSERT( rmesa
->dma
.flush
== flush_last_swtcl_prim
);
300 ASSERT( rmesa
->dma
.current
.start
+
301 rmesa
->swtcl
.numverts
* rmesa
->swtcl
.vertex_size
* 4 ==
302 rmesa
->dma
.current
.ptr
);
305 GLubyte
*head
= (GLubyte
*) (rmesa
->dma
.current
.address
+ rmesa
->dma
.current
.ptr
);
306 rmesa
->dma
.current
.ptr
+= bytes
;
307 rmesa
->swtcl
.numverts
+= nverts
;
312 static GLuint reduced_prim
[] = {
325 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint prim
);
326 static void r300RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
327 //static void r300ResetLineStipple( GLcontext *ctx );
329 /***********************************************************************
330 * Emit primitives as inline vertices *
331 ***********************************************************************/
334 #define HAVE_POINTS 1
336 #define HAVE_LINE_STRIPS 1
337 #define HAVE_TRIANGLES 1
338 #define HAVE_TRI_STRIPS 1
339 #define HAVE_TRI_STRIP_1 0
340 #define HAVE_TRI_FANS 1
342 #define HAVE_QUAD_STRIPS 0
343 #define HAVE_POLYGONS 1
348 #define CTX_ARG r300ContextPtr rmesa
349 #define GET_VERTEX_DWORDS() rmesa->swtcl.vertex_size
350 #define ALLOC_VERTS( n, size ) r300AllocDmaLowVerts( rmesa, n, size * 4 )
352 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
353 const char *r300verts = (char *)rmesa->swtcl.verts;
354 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
355 #define VERTEX r300Vertex
356 #define DO_DEBUG_VERTS (1 && (RADEON_DEBUG & DEBUG_VERTS))
357 #define PRINT_VERTEX(x)
359 #define TAG(x) r300_##x
360 #include "tnl_dd/t_dd_triemit.h"
364 /***********************************************************************
365 * Macros for t_dd_tritmp.h to draw basic primitives *
366 ***********************************************************************/
368 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
369 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
370 #define LINE( a, b ) r300_line( rmesa, a, b )
371 #define POINT( a ) r300_point( rmesa, a )
373 /***********************************************************************
374 * Build render functions from dd templates *
375 ***********************************************************************/
377 #define R300_TWOSIDE_BIT 0x01
378 #define R300_UNFILLED_BIT 0x02
379 #define R300_MAX_TRIFUNC 0x04
382 tnl_points_func points
;
384 tnl_triangle_func triangle
;
386 } rast_tab
[R300_MAX_TRIFUNC
];
388 #define DO_FALLBACK 0
389 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
390 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
397 #define DO_FULL_QUAD 1
401 #define HAVE_BACK_COLORS 0
402 #define HAVE_HW_FLATSHADE 1
405 #define DEPTH_SCALE 1.0
406 #define UNFILLED_TRI unfilled_tri
407 #define UNFILLED_QUAD unfilled_quad
408 #define VERT_X(_v) _v->v.x
409 #define VERT_Y(_v) _v->v.y
410 #define VERT_Z(_v) _v->v.z
411 #define AREA_IS_CCW( a ) (a < 0)
412 #define GET_VERTEX(e) (rmesa->swtcl.verts + (e*rmesa->swtcl.vertex_size*sizeof(int)))
414 /* Only used to pull back colors into vertices (ie, we know color is
417 #define R300_COLOR( dst, src ) \
419 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
420 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
421 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
422 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
425 #define VERT_SET_RGBA( v, c ) if (coloroffset) R300_COLOR( v->ub4[coloroffset], c )
426 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
427 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
428 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
430 #define R300_SPEC( dst, src ) \
432 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
433 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
434 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
437 #define VERT_SET_SPEC( v, c ) if (specoffset) R300_SPEC( v->ub4[specoffset], c )
438 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
439 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
440 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
446 #define LOCAL_VARS(n) \
447 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
448 GLuint color[n], spec[n]; \
449 GLuint coloroffset = rmesa->swtcl.coloroffset; \
450 GLuint specoffset = rmesa->swtcl.specoffset; \
451 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
453 /***********************************************************************
454 * Helpers for rendering unfilled primitives *
455 ***********************************************************************/
457 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
458 #define RENDER_PRIMITIVE rmesa->swtcl.render_primitive
461 #include "tnl_dd/t_dd_unfilled.h"
465 /***********************************************************************
466 * Generate GL render functions *
467 ***********************************************************************/
472 #include "tnl_dd/t_dd_tritmp.h"
474 #define IND (R300_TWOSIDE_BIT)
475 #define TAG(x) x##_twoside
476 #include "tnl_dd/t_dd_tritmp.h"
478 #define IND (R300_UNFILLED_BIT)
479 #define TAG(x) x##_unfilled
480 #include "tnl_dd/t_dd_tritmp.h"
482 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
483 #define TAG(x) x##_twoside_unfilled
484 #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 r300_point( rmesa, VERT(start) )
503 #define RENDER_LINE( v0, v1 ) \
504 r300_line( rmesa, VERT(v0), VERT(v1) )
505 #define RENDER_TRI( v0, v1, v2 ) \
506 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
507 #define RENDER_QUAD( v0, v1, v2, v3 ) \
508 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
509 #define INIT(x) do { \
510 r300RenderPrimitive( ctx, x ); \
514 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
515 const GLuint vertsize = rmesa->swtcl.vertex_size; \
516 const char *r300verts = (char *)rmesa->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) r300_##x##_verts
525 #include "tnl/t_vb_rendertmp.h"
528 #define TAG(x) r300_##x##_elts
529 #define ELT(x) elt[x]
530 #include "tnl/t_vb_rendertmp.h"
535 /**********************************************************************/
536 /* Choose render functions */
537 /**********************************************************************/
538 static void r300ChooseRenderState( GLcontext
*ctx
)
540 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
541 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
543 GLuint flags
= ctx
->_TriangleCaps
;
545 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R300_TWOSIDE_BIT
;
546 if (flags
& DD_TRI_UNFILLED
) index
|= R300_UNFILLED_BIT
;
548 if (index
!= rmesa
->swtcl
.RenderIndex
) {
549 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
550 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
551 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
552 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
553 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
556 tnl
->Driver
.Render
.PrimTabVerts
= r300_render_tab_verts
;
557 tnl
->Driver
.Render
.PrimTabElts
= r300_render_tab_elts
;
558 tnl
->Driver
.Render
.ClippedPolygon
= r300_fast_clipped_poly
;
560 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
561 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
562 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
565 rmesa
->swtcl
.RenderIndex
= index
;
570 static void r300RenderStart(GLcontext
*ctx
)
572 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
573 // fprintf(stderr, "%s\n", __FUNCTION__);
575 r300ChooseRenderState(ctx
);
576 r300SetVertexFormat(ctx
);
578 r300UpdateShaders(rmesa
);
579 r300UpdateShaderStates(rmesa
);
581 r300EmitCacheFlush(rmesa
);
583 if (rmesa
->dma
.flush
!= 0 &&
584 rmesa
->dma
.flush
!= flush_last_swtcl_prim
)
585 rmesa
->dma
.flush( rmesa
);
589 static void r300RenderFinish(GLcontext
*ctx
)
593 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
595 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
597 if (rmesa
->swtcl
.hw_primitive
!= hwprim
) {
598 R300_NEWPRIM( rmesa
);
599 rmesa
->swtcl
.hw_primitive
= hwprim
;
603 static void r300RenderPrimitive(GLcontext
*ctx
, GLenum prim
)
606 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
607 rmesa
->swtcl
.render_primitive
= prim
;
609 if ((prim
== GL_TRIANGLES
) && (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
612 r300RasterPrimitive( ctx
, reduced_prim
[prim
] );
613 // fprintf(stderr, "%s\n", __FUNCTION__);
617 static void r300ResetLineStipple(GLcontext
*ctx
)
623 void r300InitSwtcl(GLcontext
*ctx
)
625 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
626 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
627 static int firsttime
= 1;
634 tnl
->Driver
.Render
.Start
= r300RenderStart
;
635 tnl
->Driver
.Render
.Finish
= r300RenderFinish
;
636 tnl
->Driver
.Render
.PrimitiveNotify
= r300RenderPrimitive
;
637 tnl
->Driver
.Render
.ResetLineStipple
= r300ResetLineStipple
;
638 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
639 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
640 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
642 /* FIXME: what are these numbers? */
643 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
644 48 * sizeof(GLfloat
) );
646 rmesa
->swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
647 rmesa
->swtcl
.RenderIndex
= ~0;
648 rmesa
->swtcl
.render_primitive
= GL_TRIANGLES
;
649 rmesa
->swtcl
.hw_primitive
= 0;
651 _tnl_invalidate_vertex_state( ctx
, ~0 );
652 _tnl_invalidate_vertices( ctx
, ~0 );
653 RENDERINPUTS_ZERO( rmesa
->tnl_index_bitset
);
655 _tnl_need_projected_coords( ctx
, GL_FALSE
);
656 r300ChooseRenderState(ctx
);
658 _mesa_validate_all_lighting_tables( ctx
);
660 tnl
->Driver
.NotifyMaterialChange
=
661 _mesa_validate_all_lighting_tables
;
664 void r300DestroySwtcl(GLcontext
*ctx
)
668 void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, GLuint offset
)
670 int cmd_reserved
= 0;
673 drm_radeon_cmd_header_t
*cmd
= NULL
;
674 if (RADEON_DEBUG
& DEBUG_VERTS
)
675 fprintf(stderr
, "%s: vertex_size %d, offset 0x%x \n",
676 __FUNCTION__
, vertex_size
, offset
);
678 start_packet3(CP_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR
, 2), 2);
680 e32(vertex_size
| (vertex_size
<< 8));
684 void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
)
687 int cmd_reserved
= 0;
690 drm_radeon_cmd_header_t
*cmd
= NULL
;
692 type
= r300PrimitiveType(rmesa
, primitive
);
693 num_verts
= r300NumVerts(rmesa
, vertex_nr
, primitive
);
695 start_packet3(CP_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2
, 0), 0);
696 e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (num_verts
<< 16) | type
);