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 */
45 #include "swrast/s_context.h"
46 #include "swrast/s_fog.h"
47 #include "swrast_setup/swrast_setup.h"
48 #include "math/m_translate.h"
50 #include "tnl/t_context.h"
51 #include "tnl/t_pipeline.h"
53 #include "r300_context.h"
54 #include "r300_swtcl.h"
55 #include "r300_state.h"
56 #include "r300_ioctl.h"
57 #include "r300_emit.h"
60 static void flush_last_swtcl_prim( r300ContextPtr rmesa
);
63 void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, GLuint offset
);
64 void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
);
65 #define EMIT_ATTR( ATTR, STYLE ) \
67 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = (ATTR); \
68 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = (STYLE); \
69 rmesa->swtcl.vertex_attr_count++; \
72 #define EMIT_PAD( N ) \
74 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = 0; \
75 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = EMIT_PAD; \
76 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].offset = (N); \
77 rmesa->swtcl.vertex_attr_count++; \
80 /* this differs from the VIR0 in emit.c - TODO merge them using another option */
81 static GLuint
r300VAPInputRoute0(uint32_t * dst
, GLvector4f
** attribptr
,
82 int *inputs
, GLint
* tab
, GLuint nr
)
86 /* type, inputs, stop bit, size */
87 for (i
= 0; i
+ 1 < nr
; i
+= 2) {
88 dw
= (inputs
[tab
[i
]] << 8) | 0x3;
89 dw
|= ((inputs
[tab
[i
+ 1]] << 8) | 0x3) << 16;
91 dw
|= (R300_VAP_INPUT_ROUTE_END
<< 16);
97 dw
= (inputs
[tab
[nr
- 1]] << 8) | 0x3;
98 dw
|= R300_VAP_INPUT_ROUTE_END
;
102 return (nr
+ 1) >> 1;
105 static void r300SetVertexFormat( GLcontext
*ctx
)
107 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
108 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
109 struct vertex_buffer
*VB
= &tnl
->vb
;
110 DECLARE_RENDERINPUTS(index_bitset
);
111 GLuint InputsRead
= 0, OutputsWritten
= 0;
113 int vap_vte_cntl
= 0;
116 GLint inputs
[VERT_ATTRIB_MAX
];
117 GLint tab
[VERT_ATTRIB_MAX
];
118 int swizzle
[VERT_ATTRIB_MAX
][4];
121 DECLARE_RENDERINPUTS(render_inputs_bitset
);
122 RENDERINPUTS_COPY(render_inputs_bitset
, tnl
->render_inputs_bitset
);
123 RENDERINPUTS_COPY( index_bitset
, tnl
->render_inputs_bitset
);
124 RENDERINPUTS_COPY(rmesa
->state
.render_inputs_bitset
, render_inputs_bitset
);
128 if ( VB
->NdcPtr
!= NULL
) {
129 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
132 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
135 assert( VB
->AttribPtr
[VERT_ATTRIB_POS
] != NULL
);
136 rmesa
->swtcl
.vertex_attr_count
= 0;
138 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
139 * build up a hardware vertex.
141 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POS
)) {
142 vap_vte_cntl
|= R300_VTX_W0_FMT
;
143 InputsRead
|= 1 << VERT_ATTRIB_POS
;
144 OutputsWritten
|= 1 << VERT_RESULT_HPOS
;
145 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_4F
);
147 EMIT_PAD(4 * sizeof(float));
151 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
152 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
);
153 vap_fmt_0
|= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT
;
157 if (RENDERINPUTS_TEST(index_bitset
, _TNL_ATTRIB_COLOR0
)) {
158 rmesa
->swtcl
.coloroffset
= offset
;
159 InputsRead
|= 1 << VERT_ATTRIB_COLOR0
;
160 OutputsWritten
|= 1 << VERT_RESULT_COL0
;
161 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_4F
);
166 rmesa
->swtcl
.specoffset
= 0;
167 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
168 rmesa
->swtcl
.specoffset
= offset
;
169 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_4F
);
170 InputsRead
|= 1 << VERT_ATTRIB_COLOR1
;
171 OutputsWritten
|= 1 << VERT_RESULT_COL1
;
174 if (RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
177 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
178 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_TEX(i
) )) {
179 InputsRead
|= 1 << (VERT_ATTRIB_TEX0
+ i
);
180 OutputsWritten
|= 1 << (VERT_RESULT_TEX0
+ i
);
181 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_4F
);
186 for (i
= 0, nr
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
187 if (InputsRead
& (1 << i
)) {
194 /* Fixed, apply to vir0 only */
195 if (InputsRead
& (1 << VERT_ATTRIB_POS
))
196 inputs
[VERT_ATTRIB_POS
] = 0;
197 if (InputsRead
& (1 << VERT_ATTRIB_COLOR0
))
198 inputs
[VERT_ATTRIB_COLOR0
] = 2;
199 if (InputsRead
& (1 << VERT_ATTRIB_COLOR1
))
200 inputs
[VERT_ATTRIB_COLOR1
] = 3;
201 for (i
= VERT_ATTRIB_TEX0
; i
<= VERT_ATTRIB_TEX7
; i
++)
202 if (InputsRead
& (1 << i
))
203 inputs
[i
] = 6 + (i
- VERT_ATTRIB_TEX0
);
205 for (i
= 0, nr
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
206 if (InputsRead
& (1 << i
)) {
211 for (i
= 0; i
< nr
; i
++) {
214 swizzle
[i
][0] = SWIZZLE_ZERO
;
215 swizzle
[i
][1] = SWIZZLE_ZERO
;
216 swizzle
[i
][2] = SWIZZLE_ZERO
;
217 swizzle
[i
][3] = SWIZZLE_ONE
;
219 for (ci
= 0; ci
< VB
->AttribPtr
[tab
[i
]]->size
; ci
++) {
225 R300_STATECHANGE(rmesa
, vir
[0]);
226 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[0].cmd
)->packet0
.count
=
227 r300VAPInputRoute0(&rmesa
->hw
.vir
[0].cmd
[R300_VIR_CNTL_0
],
228 VB
->AttribPtr
, inputs
, tab
, nr
);
229 R300_STATECHANGE(rmesa
, vir
[1]);
230 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[1].cmd
)->packet0
.count
=
231 r300VAPInputRoute1(&rmesa
->hw
.vir
[1].cmd
[R300_VIR_CNTL_0
], swizzle
,
234 R300_STATECHANGE(rmesa
, vic
);
235 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_0
] = r300VAPInputCntl0(ctx
, InputsRead
);
236 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_1
] = r300VAPInputCntl1(ctx
, InputsRead
);
238 R300_STATECHANGE(rmesa
, vof
);
239 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = r300VAPOutputCntl0(ctx
, OutputsWritten
);
240 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = r300VAPOutputCntl1(ctx
, OutputsWritten
);
242 rmesa
->swtcl
.vertex_size
=
243 _tnl_install_attrs( ctx
,
244 rmesa
->swtcl
.vertex_attrs
,
245 rmesa
->swtcl
.vertex_attr_count
,
248 rmesa
->swtcl
.vertex_size
/= 4;
250 RENDERINPUTS_COPY( rmesa
->tnl_index_bitset
, index_bitset
);
252 vte
= rmesa
->hw
.vte
.cmd
[1];
253 R300_STATECHANGE(rmesa
, vte
);
254 rmesa
->hw
.vte
.cmd
[1] = vte
;
255 rmesa
->hw
.vte
.cmd
[2] = rmesa
->swtcl
.vertex_size
;
259 /* Flush vertices in the current dma region.
261 static void flush_last_swtcl_prim( r300ContextPtr rmesa
)
263 if (RADEON_DEBUG
& DEBUG_IOCTL
)
264 fprintf(stderr
, "%s\n", __FUNCTION__
);
266 rmesa
->dma
.flush
= NULL
;
268 if (rmesa
->dma
.current
.buf
) {
269 struct r300_dma_region
*current
= &rmesa
->dma
.current
;
270 GLuint current_offset
= GET_START(current
);
272 assert (current
->start
+
273 rmesa
->swtcl
.numverts
* rmesa
->swtcl
.vertex_size
* 4 ==
276 if (rmesa
->dma
.current
.start
!= rmesa
->dma
.current
.ptr
) {
278 r300EnsureCmdBufSpace( rmesa
, rmesa
->hw
.max_state_size
+ (12*sizeof(int)), __FUNCTION__
);
280 r300EmitState(rmesa
);
282 r300EmitVertexAOS( rmesa
,
283 rmesa
->swtcl
.vertex_size
,
286 r300EmitVbufPrim( rmesa
,
287 rmesa
->swtcl
.hw_primitive
,
288 rmesa
->swtcl
.numverts
);
290 r300EmitCacheFlush(rmesa
);
293 rmesa
->swtcl
.numverts
= 0;
294 current
->start
= current
->ptr
;
298 /* Alloc space in the current dma region.
301 r300AllocDmaLowVerts( r300ContextPtr rmesa
, int nverts
, int vsize
)
303 GLuint bytes
= vsize
* nverts
;
305 if ( rmesa
->dma
.current
.ptr
+ bytes
> rmesa
->dma
.current
.end
)
306 r300RefillCurrentDmaRegion( rmesa
, bytes
);
308 if (!rmesa
->dma
.flush
) {
309 rmesa
->radeon
.glCtx
->Driver
.NeedFlush
|= FLUSH_STORED_VERTICES
;
310 rmesa
->dma
.flush
= flush_last_swtcl_prim
;
313 ASSERT( vsize
== rmesa
->swtcl
.vertex_size
* 4 );
314 ASSERT( rmesa
->dma
.flush
== flush_last_swtcl_prim
);
315 ASSERT( rmesa
->dma
.current
.start
+
316 rmesa
->swtcl
.numverts
* rmesa
->swtcl
.vertex_size
* 4 ==
317 rmesa
->dma
.current
.ptr
);
320 GLubyte
*head
= (GLubyte
*) (rmesa
->dma
.current
.address
+ rmesa
->dma
.current
.ptr
);
321 rmesa
->dma
.current
.ptr
+= bytes
;
322 rmesa
->swtcl
.numverts
+= nverts
;
327 static GLuint reduced_prim
[] = {
340 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint prim
);
341 static void r300RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
342 //static void r300ResetLineStipple( GLcontext *ctx );
344 /***********************************************************************
345 * Emit primitives as inline vertices *
346 ***********************************************************************/
349 #define HAVE_POINTS 1
351 #define HAVE_LINE_STRIPS 1
352 #define HAVE_TRIANGLES 1
353 #define HAVE_TRI_STRIPS 1
354 #define HAVE_TRI_STRIP_1 0
355 #define HAVE_TRI_FANS 1
357 #define HAVE_QUAD_STRIPS 0
358 #define HAVE_POLYGONS 1
363 #define CTX_ARG r300ContextPtr rmesa
364 #define GET_VERTEX_DWORDS() rmesa->swtcl.vertex_size
365 #define ALLOC_VERTS( n, size ) r300AllocDmaLowVerts( rmesa, n, size * 4 )
367 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
368 const char *r300verts = (char *)rmesa->swtcl.verts;
369 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
370 #define VERTEX r300Vertex
371 #define DO_DEBUG_VERTS (1 && (RADEON_DEBUG & DEBUG_VERTS))
372 #define PRINT_VERTEX(x)
374 #define TAG(x) r300_##x
375 #include "tnl_dd/t_dd_triemit.h"
379 /***********************************************************************
380 * Macros for t_dd_tritmp.h to draw basic primitives *
381 ***********************************************************************/
383 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
384 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
385 #define LINE( a, b ) r300_line( rmesa, a, b )
386 #define POINT( a ) r300_point( rmesa, a )
388 /***********************************************************************
389 * Build render functions from dd templates *
390 ***********************************************************************/
392 #define R300_TWOSIDE_BIT 0x01
393 #define R300_UNFILLED_BIT 0x02
394 #define R300_MAX_TRIFUNC 0x04
397 tnl_points_func points
;
399 tnl_triangle_func triangle
;
401 } rast_tab
[R300_MAX_TRIFUNC
];
403 #define DO_FALLBACK 0
404 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
405 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
412 #define DO_FULL_QUAD 1
416 #define HAVE_BACK_COLORS 0
417 #define HAVE_HW_FLATSHADE 1
420 #define DEPTH_SCALE 1.0
421 #define UNFILLED_TRI unfilled_tri
422 #define UNFILLED_QUAD unfilled_quad
423 #define VERT_X(_v) _v->v.x
424 #define VERT_Y(_v) _v->v.y
425 #define VERT_Z(_v) _v->v.z
426 #define AREA_IS_CCW( a ) (a < 0)
427 #define GET_VERTEX(e) (rmesa->swtcl.verts + (e*rmesa->swtcl.vertex_size*sizeof(int)))
429 /* Only used to pull back colors into vertices (ie, we know color is
432 #define R300_COLOR( dst, src ) \
434 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
435 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
436 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
437 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
440 #define VERT_SET_RGBA( v, c ) if (coloroffset) R300_COLOR( v->ub4[coloroffset], c )
441 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
442 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
443 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
445 #define R300_SPEC( dst, src ) \
447 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
448 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
449 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
452 #define VERT_SET_SPEC( v, c ) if (specoffset) R300_SPEC( v->ub4[specoffset], c )
453 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
454 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
455 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
461 #define LOCAL_VARS(n) \
462 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
463 GLuint color[n], spec[n]; \
464 GLuint coloroffset = rmesa->swtcl.coloroffset; \
465 GLuint specoffset = rmesa->swtcl.specoffset; \
466 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
468 /***********************************************************************
469 * Helpers for rendering unfilled primitives *
470 ***********************************************************************/
472 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
473 #define RENDER_PRIMITIVE rmesa->swtcl.render_primitive
476 #include "tnl_dd/t_dd_unfilled.h"
480 /***********************************************************************
481 * Generate GL render functions *
482 ***********************************************************************/
487 #include "tnl_dd/t_dd_tritmp.h"
489 #define IND (R300_TWOSIDE_BIT)
490 #define TAG(x) x##_twoside
491 #include "tnl_dd/t_dd_tritmp.h"
493 #define IND (R300_UNFILLED_BIT)
494 #define TAG(x) x##_unfilled
495 #include "tnl_dd/t_dd_tritmp.h"
497 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
498 #define TAG(x) x##_twoside_unfilled
499 #include "tnl_dd/t_dd_tritmp.h"
503 static void init_rast_tab( void )
508 init_twoside_unfilled();
511 /**********************************************************************/
512 /* Render unclipped begin/end objects */
513 /**********************************************************************/
515 #define RENDER_POINTS( start, count ) \
516 for ( ; start < count ; start++) \
517 r300_point( rmesa, VERT(start) )
518 #define RENDER_LINE( v0, v1 ) \
519 r300_line( rmesa, VERT(v0), VERT(v1) )
520 #define RENDER_TRI( v0, v1, v2 ) \
521 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
522 #define RENDER_QUAD( v0, v1, v2, v3 ) \
523 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
524 #define INIT(x) do { \
525 r300RenderPrimitive( ctx, x ); \
529 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
530 const GLuint vertsize = rmesa->swtcl.vertex_size; \
531 const char *r300verts = (char *)rmesa->swtcl.verts; \
532 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
533 const GLboolean stipple = ctx->Line.StippleFlag; \
534 (void) elt; (void) stipple;
535 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
536 #define RESET_OCCLUSION
537 #define PRESERVE_VB_DEFS
539 #define TAG(x) r300_##x##_verts
540 #include "tnl/t_vb_rendertmp.h"
543 #define TAG(x) r300_##x##_elts
544 #define ELT(x) elt[x]
545 #include "tnl/t_vb_rendertmp.h"
550 /**********************************************************************/
551 /* Choose render functions */
552 /**********************************************************************/
553 static void r300ChooseRenderState( GLcontext
*ctx
)
555 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
556 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
558 GLuint flags
= ctx
->_TriangleCaps
;
560 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R300_TWOSIDE_BIT
;
561 if (flags
& DD_TRI_UNFILLED
) index
|= R300_UNFILLED_BIT
;
563 if (index
!= rmesa
->swtcl
.RenderIndex
) {
564 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
565 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
566 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
567 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
568 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
571 tnl
->Driver
.Render
.PrimTabVerts
= r300_render_tab_verts
;
572 tnl
->Driver
.Render
.PrimTabElts
= r300_render_tab_elts
;
573 tnl
->Driver
.Render
.ClippedPolygon
= r300_fast_clipped_poly
;
575 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
576 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
577 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
580 rmesa
->swtcl
.RenderIndex
= index
;
585 static void r300RenderStart(GLcontext
*ctx
)
587 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
588 // fprintf(stderr, "%s\n", __FUNCTION__);
590 r300ChooseRenderState(ctx
);
591 r300SetVertexFormat(ctx
);
593 r300UpdateShaderStates(rmesa
);
595 r300EmitCacheFlush(rmesa
);
597 if (rmesa
->dma
.flush
!= 0 &&
598 rmesa
->dma
.flush
!= flush_last_swtcl_prim
)
599 rmesa
->dma
.flush( rmesa
);
603 static void r300RenderFinish(GLcontext
*ctx
)
607 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
609 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
611 if (rmesa
->swtcl
.hw_primitive
!= hwprim
) {
612 R300_NEWPRIM( rmesa
);
613 rmesa
->swtcl
.hw_primitive
= hwprim
;
617 static void r300RenderPrimitive(GLcontext
*ctx
, GLenum prim
)
620 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
621 rmesa
->swtcl
.render_primitive
= prim
;
623 if ((prim
== GL_TRIANGLES
) && (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
626 r300RasterPrimitive( ctx
, reduced_prim
[prim
] );
627 // fprintf(stderr, "%s\n", __FUNCTION__);
631 static void r300ResetLineStipple(GLcontext
*ctx
)
637 void r300InitSwtcl(GLcontext
*ctx
)
639 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
640 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
641 static int firsttime
= 1;
648 tnl
->Driver
.Render
.Start
= r300RenderStart
;
649 tnl
->Driver
.Render
.Finish
= r300RenderFinish
;
650 tnl
->Driver
.Render
.PrimitiveNotify
= r300RenderPrimitive
;
651 tnl
->Driver
.Render
.ResetLineStipple
= r300ResetLineStipple
;
652 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
653 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
654 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
656 /* FIXME: what are these numbers? */
657 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
658 48 * sizeof(GLfloat
) );
660 rmesa
->swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
661 rmesa
->swtcl
.RenderIndex
= ~0;
662 rmesa
->swtcl
.render_primitive
= GL_TRIANGLES
;
663 rmesa
->swtcl
.hw_primitive
= 0;
665 _tnl_invalidate_vertex_state( ctx
, ~0 );
666 _tnl_invalidate_vertices( ctx
, ~0 );
667 RENDERINPUTS_ZERO( rmesa
->tnl_index_bitset
);
669 _tnl_need_projected_coords( ctx
, GL_FALSE
);
670 r300ChooseRenderState(ctx
);
673 void r300DestroySwtcl(GLcontext
*ctx
)
677 void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, GLuint offset
)
679 int cmd_reserved
= 0;
682 drm_radeon_cmd_header_t
*cmd
= NULL
;
683 if (RADEON_DEBUG
& DEBUG_VERTS
)
684 fprintf(stderr
, "%s: vertex_size %d, offset 0x%x \n",
685 __FUNCTION__
, vertex_size
, offset
);
687 start_packet3(CP_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR
, 2), 2);
689 e32(vertex_size
| (vertex_size
<< 8));
693 void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
)
696 int cmd_reserved
= 0;
699 drm_radeon_cmd_header_t
*cmd
= NULL
;
701 type
= r300PrimitiveType(rmesa
, primitive
);
702 num_verts
= r300NumVerts(rmesa
, vertex_nr
, primitive
);
704 start_packet3(CP_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2
, 0), 0);
705 e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (num_verts
<< 16) | type
);