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"
60 static void flush_last_swtcl_prim( GLcontext
*ctx
);
63 void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, struct radeon_bo
*bo
, 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 static void r300SetVertexFormat( GLcontext
*ctx
)
82 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
83 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
84 struct vertex_buffer
*VB
= &tnl
->vb
;
85 DECLARE_RENDERINPUTS(index_bitset
);
86 GLuint InputsRead
= 0, OutputsWritten
= 0;
90 GLint inputs
[VERT_ATTRIB_MAX
];
91 GLint tab
[VERT_ATTRIB_MAX
];
92 int swizzle
[VERT_ATTRIB_MAX
][4];
94 GLuint sz
, vap_fmt_1
= 0;
96 DECLARE_RENDERINPUTS(render_inputs_bitset
);
97 RENDERINPUTS_COPY(render_inputs_bitset
, tnl
->render_inputs_bitset
);
98 RENDERINPUTS_COPY( index_bitset
, tnl
->render_inputs_bitset
);
99 RENDERINPUTS_COPY(rmesa
->state
.render_inputs_bitset
, render_inputs_bitset
);
101 vte
= rmesa
->hw
.vte
.cmd
[1];
102 vte
&= ~(R300_VTX_XY_FMT
| R300_VTX_Z_FMT
| R300_VTX_W0_FMT
);
105 if ( VB
->NdcPtr
!= NULL
) {
106 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
107 vte
|= R300_VTX_XY_FMT
| R300_VTX_Z_FMT
;
110 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->ClipPtr
;
111 vte
|= R300_VTX_W0_FMT
;
114 assert( VB
->AttribPtr
[VERT_ATTRIB_POS
] != NULL
);
115 rmesa
->swtcl
.vertex_attr_count
= 0;
117 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
118 * build up a hardware vertex.
120 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POS
)) {
121 sz
= VB
->AttribPtr
[VERT_ATTRIB_POS
]->size
;
122 InputsRead
|= 1 << VERT_ATTRIB_POS
;
123 OutputsWritten
|= 1 << VERT_RESULT_HPOS
;
124 EMIT_ATTR( _TNL_ATTRIB_POS
, EMIT_1F
+ sz
- 1 );
128 EMIT_PAD(4 * sizeof(float));
131 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_POINTSIZE
)) {
132 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE
, EMIT_1F
);
133 vap_fmt_0
|= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT
;
137 if (RENDERINPUTS_TEST(index_bitset
, _TNL_ATTRIB_COLOR0
)) {
138 sz
= VB
->AttribPtr
[VERT_ATTRIB_COLOR0
]->size
;
139 rmesa
->swtcl
.coloroffset
= offset
;
140 InputsRead
|= 1 << VERT_ATTRIB_COLOR0
;
141 OutputsWritten
|= 1 << VERT_RESULT_COL0
;
142 EMIT_ATTR( _TNL_ATTRIB_COLOR0
, EMIT_1F
+ sz
- 1 );
146 rmesa
->swtcl
.specoffset
= 0;
147 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_COLOR1
)) {
148 sz
= VB
->AttribPtr
[VERT_ATTRIB_COLOR1
]->size
;
149 rmesa
->swtcl
.specoffset
= offset
;
150 EMIT_ATTR( _TNL_ATTRIB_COLOR1
, EMIT_1F
+ sz
- 1 );
151 InputsRead
|= 1 << VERT_ATTRIB_COLOR1
;
152 OutputsWritten
|= 1 << VERT_RESULT_COL1
;
155 if (RENDERINPUTS_TEST_RANGE( index_bitset
, _TNL_FIRST_TEX
, _TNL_LAST_TEX
)) {
158 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
159 if (RENDERINPUTS_TEST( index_bitset
, _TNL_ATTRIB_TEX(i
) )) {
160 sz
= VB
->TexCoordPtr
[i
]->size
;
161 InputsRead
|= 1 << (VERT_ATTRIB_TEX0
+ i
);
162 OutputsWritten
|= 1 << (VERT_RESULT_TEX0
+ i
);
163 EMIT_ATTR( _TNL_ATTRIB_TEX0
+i
, EMIT_1F
+ sz
- 1 );
164 vap_fmt_1
|= sz
<< (3 * i
);
169 for (i
= 0, nr
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
170 if (InputsRead
& (1 << i
)) {
177 /* Fixed, apply to vir0 only */
178 if (InputsRead
& (1 << VERT_ATTRIB_POS
))
179 inputs
[VERT_ATTRIB_POS
] = 0;
180 if (InputsRead
& (1 << VERT_ATTRIB_COLOR0
))
181 inputs
[VERT_ATTRIB_COLOR0
] = 2;
182 if (InputsRead
& (1 << VERT_ATTRIB_COLOR1
))
183 inputs
[VERT_ATTRIB_COLOR1
] = 3;
184 for (i
= VERT_ATTRIB_TEX0
; i
<= VERT_ATTRIB_TEX7
; i
++)
185 if (InputsRead
& (1 << i
))
186 inputs
[i
] = 6 + (i
- VERT_ATTRIB_TEX0
);
188 for (i
= 0, nr
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
189 if (InputsRead
& (1 << i
)) {
194 for (i
= 0; i
< nr
; i
++) {
197 swizzle
[i
][0] = SWIZZLE_ZERO
;
198 swizzle
[i
][1] = SWIZZLE_ZERO
;
199 swizzle
[i
][2] = SWIZZLE_ZERO
;
200 swizzle
[i
][3] = SWIZZLE_ONE
;
202 for (ci
= 0; ci
< VB
->AttribPtr
[tab
[i
]]->size
; ci
++) {
208 R300_STATECHANGE(rmesa
, vir
[0]);
209 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[0].cmd
)->packet0
.count
=
210 r300VAPInputRoute0(&rmesa
->hw
.vir
[0].cmd
[R300_VIR_CNTL_0
],
211 VB
->AttribPtr
, inputs
, tab
, nr
);
212 R300_STATECHANGE(rmesa
, vir
[1]);
213 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[1].cmd
)->packet0
.count
=
214 r300VAPInputRoute1(&rmesa
->hw
.vir
[1].cmd
[R300_VIR_CNTL_0
], swizzle
,
217 R300_STATECHANGE(rmesa
, vic
);
218 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_0
] = r300VAPInputCntl0(ctx
, InputsRead
);
219 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_1
] = r300VAPInputCntl1(ctx
, InputsRead
);
221 R300_STATECHANGE(rmesa
, vof
);
222 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = r300VAPOutputCntl0(ctx
, OutputsWritten
);
223 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = vap_fmt_1
;
225 rmesa
->swtcl
.vertex_size
=
226 _tnl_install_attrs( ctx
,
227 rmesa
->swtcl
.vertex_attrs
,
228 rmesa
->swtcl
.vertex_attr_count
,
231 rmesa
->swtcl
.vertex_size
/= 4;
233 RENDERINPUTS_COPY( rmesa
->tnl_index_bitset
, index_bitset
);
236 R300_STATECHANGE(rmesa
, vte
);
237 rmesa
->hw
.vte
.cmd
[1] = vte
;
238 rmesa
->hw
.vte
.cmd
[2] = rmesa
->swtcl
.vertex_size
;
242 /* Flush vertices in the current dma region.
244 static void flush_last_swtcl_prim( GLcontext
*ctx
)
246 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
247 struct radeon_dma
*dma
= &rmesa
->radeon
.dma
;
250 if (RADEON_DEBUG
& DEBUG_IOCTL
)
251 fprintf(stderr
, "%s\n", __FUNCTION__
);
255 GLuint current_offset
= dma
->current_used
;
257 assert (dma
->current_used
+
258 rmesa
->swtcl
.numverts
* rmesa
->swtcl
.vertex_size
* 4 ==
259 dma
->current_vertexptr
);
261 radeon_bo_unmap(dma
->current
);
262 if (dma
->current_used
!= dma
->current_vertexptr
) {
263 dma
->current_used
= dma
->current_vertexptr
;
265 rcommonEnsureCmdBufSpace(rmesa
,
266 rmesa
->hw
.max_state_size
+ (12*sizeof(int)),
268 r300EmitState(rmesa
);
269 r300EmitVertexAOS(rmesa
,
270 rmesa
->swtcl
.vertex_size
,
274 r300EmitVbufPrim(rmesa
,
275 rmesa
->swtcl
.hw_primitive
,
276 rmesa
->swtcl
.numverts
);
277 r300EmitCacheFlush(rmesa
);
280 radeonReleaseDmaRegion(&rmesa
->radeon
);
281 rmesa
->swtcl
.numverts
= 0;
285 /* Alloc space in the current dma region.
288 r300AllocDmaLowVerts( r300ContextPtr rmesa
, int nverts
, int vsize
)
290 GLuint bytes
= vsize
* nverts
;
293 if (!rmesa
->radeon
.dma
.current
|| rmesa
->radeon
.dma
.current_vertexptr
+ bytes
> rmesa
->radeon
.dma
.current
->size
) {
294 radeonRefillCurrentDmaRegion( &rmesa
->radeon
, bytes
);
297 if (!rmesa
->radeon
.dma
.flush
) {
298 rmesa
->radeon
.glCtx
->Driver
.NeedFlush
|= FLUSH_STORED_VERTICES
;
299 rmesa
->radeon
.dma
.flush
= flush_last_swtcl_prim
;
302 ASSERT( vsize
== rmesa
->swtcl
.vertex_size
* 4 );
303 ASSERT( rmesa
->radeon
.dma
.flush
== flush_last_swtcl_prim
);
304 ASSERT( rmesa
->radeon
.dma
.current_used
+
305 rmesa
->swtcl
.numverts
* rmesa
->swtcl
.vertex_size
* 4 ==
306 rmesa
->radeon
.dma
.current_vertexptr
);
308 // fprintf(stderr,"current %p %x\n", rmesa->radeon.dma.current->ptr,
309 // rmesa->radeon.dma.current_vertexptr);
310 head
= (rmesa
->radeon
.dma
.current
->ptr
+ rmesa
->radeon
.dma
.current_vertexptr
);
311 rmesa
->radeon
.dma
.current_vertexptr
+= bytes
;
312 rmesa
->swtcl
.numverts
+= nverts
;
316 static GLuint reduced_prim
[] = {
329 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint prim
);
330 static void r300RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
331 //static void r300ResetLineStipple( GLcontext *ctx );
333 /***********************************************************************
334 * Emit primitives as inline vertices *
335 ***********************************************************************/
338 #define HAVE_POINTS 1
340 #define HAVE_LINE_STRIPS 1
341 #define HAVE_TRIANGLES 1
342 #define HAVE_TRI_STRIPS 1
343 #define HAVE_TRI_STRIP_1 0
344 #define HAVE_TRI_FANS 1
346 #define HAVE_QUAD_STRIPS 0
347 #define HAVE_POLYGONS 1
352 #define CTX_ARG r300ContextPtr rmesa
353 #define GET_VERTEX_DWORDS() rmesa->swtcl.vertex_size
354 #define ALLOC_VERTS( n, size ) r300AllocDmaLowVerts( rmesa, n, size * 4 )
356 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
357 const char *r300verts = (char *)rmesa->swtcl.verts;
358 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
359 #define VERTEX r300Vertex
360 #define DO_DEBUG_VERTS (1 && (RADEON_DEBUG & DEBUG_VERTS))
361 #define PRINT_VERTEX(x)
363 #define TAG(x) r300_##x
364 #include "tnl_dd/t_dd_triemit.h"
368 /***********************************************************************
369 * Macros for t_dd_tritmp.h to draw basic primitives *
370 ***********************************************************************/
372 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
373 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
374 #define LINE( a, b ) r300_line( rmesa, a, b )
375 #define POINT( a ) r300_point( rmesa, a )
377 /***********************************************************************
378 * Build render functions from dd templates *
379 ***********************************************************************/
381 #define R300_TWOSIDE_BIT 0x01
382 #define R300_UNFILLED_BIT 0x02
383 #define R300_MAX_TRIFUNC 0x04
386 tnl_points_func points
;
388 tnl_triangle_func triangle
;
390 } rast_tab
[R300_MAX_TRIFUNC
];
392 #define DO_FALLBACK 0
393 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
394 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
401 #define DO_FULL_QUAD 1
405 #define HAVE_BACK_COLORS 0
406 #define HAVE_HW_FLATSHADE 1
409 #define DEPTH_SCALE 1.0
410 #define UNFILLED_TRI unfilled_tri
411 #define UNFILLED_QUAD unfilled_quad
412 #define VERT_X(_v) _v->v.x
413 #define VERT_Y(_v) _v->v.y
414 #define VERT_Z(_v) _v->v.z
415 #define AREA_IS_CCW( a ) (a < 0)
416 #define GET_VERTEX(e) (rmesa->swtcl.verts + (e*rmesa->swtcl.vertex_size*sizeof(int)))
418 /* Only used to pull back colors into vertices (ie, we know color is
421 #define R300_COLOR( dst, src ) \
423 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
424 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
425 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
426 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
429 #define VERT_SET_RGBA( v, c ) if (coloroffset) R300_COLOR( v->ub4[coloroffset], c )
430 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
431 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
432 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
434 #define R300_SPEC( dst, src ) \
436 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
437 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
438 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
441 #define VERT_SET_SPEC( v, c ) if (specoffset) R300_SPEC( v->ub4[specoffset], c )
442 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
443 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
444 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
450 #define LOCAL_VARS(n) \
451 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
452 GLuint color[n], spec[n]; \
453 GLuint coloroffset = rmesa->swtcl.coloroffset; \
454 GLuint specoffset = rmesa->swtcl.specoffset; \
455 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
457 /***********************************************************************
458 * Helpers for rendering unfilled primitives *
459 ***********************************************************************/
461 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
462 #define RENDER_PRIMITIVE rmesa->swtcl.render_primitive
465 #include "tnl_dd/t_dd_unfilled.h"
469 /***********************************************************************
470 * Generate GL render functions *
471 ***********************************************************************/
476 #include "tnl_dd/t_dd_tritmp.h"
478 #define IND (R300_TWOSIDE_BIT)
479 #define TAG(x) x##_twoside
480 #include "tnl_dd/t_dd_tritmp.h"
482 #define IND (R300_UNFILLED_BIT)
483 #define TAG(x) x##_unfilled
484 #include "tnl_dd/t_dd_tritmp.h"
486 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
487 #define TAG(x) x##_twoside_unfilled
488 #include "tnl_dd/t_dd_tritmp.h"
492 static void init_rast_tab( void )
497 init_twoside_unfilled();
500 /**********************************************************************/
501 /* Render unclipped begin/end objects */
502 /**********************************************************************/
504 #define RENDER_POINTS( start, count ) \
505 for ( ; start < count ; start++) \
506 r300_point( rmesa, VERT(start) )
507 #define RENDER_LINE( v0, v1 ) \
508 r300_line( rmesa, VERT(v0), VERT(v1) )
509 #define RENDER_TRI( v0, v1, v2 ) \
510 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
511 #define RENDER_QUAD( v0, v1, v2, v3 ) \
512 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
513 #define INIT(x) do { \
514 r300RenderPrimitive( ctx, x ); \
518 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
519 const GLuint vertsize = rmesa->swtcl.vertex_size; \
520 const char *r300verts = (char *)rmesa->swtcl.verts; \
521 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
522 const GLboolean stipple = ctx->Line.StippleFlag; \
523 (void) elt; (void) stipple;
524 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
525 #define RESET_OCCLUSION
526 #define PRESERVE_VB_DEFS
528 #define TAG(x) r300_##x##_verts
529 #include "tnl/t_vb_rendertmp.h"
532 #define TAG(x) r300_##x##_elts
533 #define ELT(x) elt[x]
534 #include "tnl/t_vb_rendertmp.h"
539 /**********************************************************************/
540 /* Choose render functions */
541 /**********************************************************************/
542 static void r300ChooseRenderState( GLcontext
*ctx
)
544 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
545 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
547 GLuint flags
= ctx
->_TriangleCaps
;
549 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R300_TWOSIDE_BIT
;
550 if (flags
& DD_TRI_UNFILLED
) index
|= R300_UNFILLED_BIT
;
552 if (index
!= rmesa
->swtcl
.RenderIndex
) {
553 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
554 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
555 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
556 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
557 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
560 tnl
->Driver
.Render
.PrimTabVerts
= r300_render_tab_verts
;
561 tnl
->Driver
.Render
.PrimTabElts
= r300_render_tab_elts
;
562 tnl
->Driver
.Render
.ClippedPolygon
= r300_fast_clipped_poly
;
564 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
565 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
566 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
;
569 rmesa
->swtcl
.RenderIndex
= index
;
574 static void r300RenderStart(GLcontext
*ctx
)
576 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
577 // fprintf(stderr, "%s\n", __FUNCTION__);
579 r300ChooseRenderState(ctx
);
580 r300SetVertexFormat(ctx
);
582 r300ValidateTextures(ctx
);
584 r300UpdateShaders(rmesa
);
585 r300UpdateShaderStates(rmesa
);
587 r300EmitCacheFlush(rmesa
);
588 if (rmesa
->radeon
.dma
.flush
!= NULL
) {
589 rmesa
->radeon
.dma
.flush(ctx
);
593 static void r300RenderFinish(GLcontext
*ctx
)
597 static void r300RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
599 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
601 if (rmesa
->swtcl
.hw_primitive
!= hwprim
) {
602 R300_NEWPRIM( rmesa
);
603 rmesa
->swtcl
.hw_primitive
= hwprim
;
607 static void r300RenderPrimitive(GLcontext
*ctx
, GLenum prim
)
610 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
611 rmesa
->swtcl
.render_primitive
= prim
;
613 if ((prim
== GL_TRIANGLES
) && (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
616 r300RasterPrimitive( ctx
, reduced_prim
[prim
] );
617 // fprintf(stderr, "%s\n", __FUNCTION__);
621 static void r300ResetLineStipple(GLcontext
*ctx
)
627 void r300InitSwtcl(GLcontext
*ctx
)
629 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
630 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
631 static int firsttime
= 1;
638 tnl
->Driver
.Render
.Start
= r300RenderStart
;
639 tnl
->Driver
.Render
.Finish
= r300RenderFinish
;
640 tnl
->Driver
.Render
.PrimitiveNotify
= r300RenderPrimitive
;
641 tnl
->Driver
.Render
.ResetLineStipple
= r300ResetLineStipple
;
642 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
643 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
644 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
646 /* FIXME: what are these numbers? */
647 _tnl_init_vertices( ctx
, ctx
->Const
.MaxArrayLockSize
+ 12,
648 48 * sizeof(GLfloat
) );
650 rmesa
->swtcl
.verts
= (GLubyte
*)tnl
->clipspace
.vertex_buf
;
651 rmesa
->swtcl
.RenderIndex
= ~0;
652 rmesa
->swtcl
.render_primitive
= GL_TRIANGLES
;
653 rmesa
->swtcl
.hw_primitive
= 0;
655 _tnl_invalidate_vertex_state( ctx
, ~0 );
656 _tnl_invalidate_vertices( ctx
, ~0 );
657 RENDERINPUTS_ZERO( rmesa
->tnl_index_bitset
);
659 _tnl_need_projected_coords( ctx
, GL_FALSE
);
660 r300ChooseRenderState(ctx
);
662 _mesa_validate_all_lighting_tables( ctx
);
664 tnl
->Driver
.NotifyMaterialChange
=
665 _mesa_validate_all_lighting_tables
;
668 void r300DestroySwtcl(GLcontext
*ctx
)
672 void r300EmitVertexAOS(r300ContextPtr rmesa
, GLuint vertex_size
, struct radeon_bo
*bo
, GLuint offset
)
674 BATCH_LOCALS(&rmesa
->radeon
);
676 if (RADEON_DEBUG
& DEBUG_VERTS
)
677 fprintf(stderr
, "%s: vertex_size %d, offset 0x%x \n",
678 __FUNCTION__
, vertex_size
, offset
);
681 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR
, 2);
683 OUT_BATCH(vertex_size
| (vertex_size
<< 8));
684 OUT_BATCH_RELOC(offset
, bo
, offset
, RADEON_GEM_DOMAIN_GTT
, 0, 0);
688 void r300EmitVbufPrim(r300ContextPtr rmesa
, GLuint primitive
, GLuint vertex_nr
)
690 BATCH_LOCALS(&rmesa
->radeon
);
693 type
= r300PrimitiveType(rmesa
, primitive
);
694 num_verts
= r300NumVerts(rmesa
, vertex_nr
, primitive
);
697 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2
, 0);
698 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (num_verts
<< 16) | type
);