cleaned up reduced prim
[mesa.git] / src / mesa / drivers / dri / r300 / r300_swtcl.c
1 /**************************************************************************
2
3 Copyright (C) 2007 Dave Airlie
4
5 All Rights Reserved.
6
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:
13
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
16 Software.
17
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.
25
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Dave Airlie <airlied@linux.ie>
31 */
32
33 /* derived from r200 swtcl path */
34
35
36
37 #include "glheader.h"
38 #include "mtypes.h"
39 #include "colormac.h"
40 #include "enums.h"
41 #include "image.h"
42 #include "imports.h"
43 #include "macros.h"
44
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"
49 #include "tnl/tnl.h"
50 #include "tnl/t_context.h"
51 #include "tnl/t_pipeline.h"
52
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"
58 #include "r300_mem.h"
59
60 #define R300_NEWPRIM( rmesa ) \
61 do { \
62 if ( rmesa->dma.flush ) \
63 rmesa->dma.flush( rmesa ); \
64 } while (0)
65
66 static void flush_last_swtcl_prim( r300ContextPtr rmesa );
67
68
69 void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, GLuint offset);
70 void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr);
71 #define EMIT_ATTR( ATTR, STYLE, F0 ) \
72 do { \
73 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = (ATTR); \
74 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = (STYLE); \
75 rmesa->swtcl.vertex_attr_count++; \
76 vap_fmt_0 |= F0; \
77 } while (0)
78
79 #define EMIT_PAD( N ) \
80 do { \
81 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = 0; \
82 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = EMIT_PAD; \
83 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].offset = (N); \
84 rmesa->swtcl.vertex_attr_count++; \
85 } while (0)
86
87 static void r300SetVertexFormat( GLcontext *ctx )
88 {
89 r300ContextPtr rmesa = R300_CONTEXT( ctx );
90 TNLcontext *tnl = TNL_CONTEXT(ctx);
91 struct vertex_buffer *VB = &tnl->vb;
92 DECLARE_RENDERINPUTS(index_bitset);
93 int vap_fmt_0 = 0;
94 int vap_fmt_1 = 0;
95 int vap_vte_cntl = 0;
96 int offset = 0;
97
98 RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
99
100 /* Important:
101 */
102 if ( VB->NdcPtr != NULL ) {
103 VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
104 }
105 else {
106 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
107 }
108
109 assert( VB->AttribPtr[VERT_ATTRIB_POS] != NULL );
110 rmesa->swtcl.vertex_attr_count = 0;
111
112 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
113 * build up a hardware vertex.
114 */
115 if ( !rmesa->swtcl.needproj ||
116 RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) { /* need w coord for projected textures */
117 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F, R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT);
118 vap_vte_cntl |= R300_VTX_XY_FMT | R300_VTX_Z_FMT | R300_VTX_W0_FMT;
119
120 offset = 4;
121 }
122 else {
123 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F, R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT );
124 vap_vte_cntl |= R300_VTX_XY_FMT | R300_VTX_Z_FMT;
125 offset = 3;
126 }
127
128 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) {
129 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT);
130 offset += 1;
131 }
132
133 rmesa->swtcl.coloroffset = offset;
134 #if MESA_LITTLE_ENDIAN
135 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_RGBA, R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT );
136 #else
137 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_ABGR, R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT );
138 #endif
139 offset += 1;
140
141 rmesa->swtcl.specoffset = 0;
142 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) ||
143 RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
144
145 #if MESA_LITTLE_ENDIAN
146 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
147 rmesa->swtcl.specoffset = offset;
148 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_RGB, R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT );
149 }
150 else {
151 EMIT_PAD( 3 );
152 }
153
154 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
155 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT );
156 }
157 else {
158 EMIT_PAD( 1 );
159 }
160 #else
161 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
162 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT );
163 }
164 else {
165 EMIT_PAD( 1 );
166 }
167
168 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
169 rmesa->swtcl.specoffset = offset;
170 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT );
171 }
172 else {
173 EMIT_PAD( 3 );
174 }
175 #endif
176 }
177
178 if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
179 int i;
180
181 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
182 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) {
183 GLuint sz = VB->TexCoordPtr[i]->size;
184
185 vap_fmt_1 |= sz << (3 * i);
186 EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_1F + sz - 1, 0 );
187 }
188 }
189 }
190
191 #if 0
192 if ( (rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] & R200_FOG_USE_MASK)
193 != R200_FOG_USE_SPEC_ALPHA ) {
194 R200_STATECHANGE( rmesa, ctx );
195 rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] &= ~R200_FOG_USE_MASK;
196 rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] |= R200_FOG_USE_SPEC_ALPHA;
197 }
198 #endif
199
200 if (!RENDERINPUTS_EQUAL( rmesa->tnl_index_bitset, index_bitset ) ||
201 (rmesa->hw.vof.cmd[R300_VOF_CNTL_0] != vap_fmt_0) ||
202 (rmesa->hw.vof.cmd[R300_VOF_CNTL_1] != vap_fmt_1) ) {
203 R300_NEWPRIM(rmesa);
204 R300_STATECHANGE(rmesa, vof);
205 rmesa->hw.vof.cmd[R300_VOF_CNTL_0] =
206 vap_fmt_0;
207 rmesa->hw.vof.cmd[R300_VOF_CNTL_1] =
208 vap_fmt_1;
209
210 rmesa->swtcl.vertex_size =
211 _tnl_install_attrs( ctx,
212 rmesa->swtcl.vertex_attrs,
213 rmesa->swtcl.vertex_attr_count,
214 NULL, 0 );
215 rmesa->swtcl.vertex_size /= 4;
216 RENDERINPUTS_COPY( rmesa->tnl_index_bitset, index_bitset );
217 }
218 }
219
220
221 /* Flush vertices in the current dma region.
222 */
223 static void flush_last_swtcl_prim( r300ContextPtr rmesa )
224 {
225 if (RADEON_DEBUG & DEBUG_IOCTL)
226 fprintf(stderr, "%s\n", __FUNCTION__);
227
228 rmesa->dma.flush = NULL;
229
230 if (rmesa->dma.current.buf) {
231 struct r300_dma_region *current = &rmesa->dma.current;
232 // GLuint current_offset = rmesa->state.swtcl_dma.aos_offset;
233
234 GLuint current_offset = r300_mem_offset(rmesa,current->buf->id);
235 // assert (!(rmesa->swtcl.hw_primitive & R200_VF_PRIM_WALK_IND));
236
237 assert (current->start +
238 rmesa->swtcl.numverts * rmesa->swtcl.vertex_size * 4 ==
239 current->ptr);
240
241 if (rmesa->dma.current.start != rmesa->dma.current.ptr) {
242 // r200EnsureCmdBufSpace( rmesa, VERT_AOS_BUFSZ +
243 // rmesa->hw.max_state_size + VBUF_BUFSZ );
244 r300EmitVertexAOS( rmesa,
245 rmesa->swtcl.vertex_size,
246 current_offset);
247
248 r300EmitVbufPrim( rmesa,
249 rmesa->swtcl.hw_primitive,
250 rmesa->swtcl.numverts);
251 }
252
253 rmesa->swtcl.numverts = 0;
254 current->start = current->ptr;
255 }
256 }
257
258
259 static void *
260 r300AllocDmaLowVerts( r300ContextPtr rmesa, int nverts, int vsize )
261 {
262 GLuint bytes = vsize * nverts;
263
264 r300AllocDmaRegion(rmesa, &rmesa->state.swtcl_dma, bytes, 0);
265
266 if (!rmesa->dma.flush) {
267 rmesa->dma.flush = flush_last_swtcl_prim;
268 rmesa->radeon.glCtx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
269 }
270
271
272 rmesa->swtcl.numverts += nverts;
273 rmesa->dma.current.ptr += bytes;
274 return (rmesa->dma.current.address + rmesa->dma.current.ptr);
275 }
276
277
278 static INLINE GLuint reduced_hw_prim( GLcontext *ctx, GLuint prim)
279 {
280 switch (prim) {
281 case GL_POINTS:
282 return R300_VAP_VF_CNTL__PRIM_POINTS;
283 case GL_LINES:
284 return R300_VAP_VF_CNTL__PRIM_LINES;
285 /* fallthrough */
286 case GL_LINE_LOOP:
287 return R300_VAP_VF_CNTL__PRIM_LINE_LOOP;
288 /* fallthrough */
289 case GL_LINE_STRIP:
290 return R300_VAP_VF_CNTL__PRIM_LINE_STRIP;
291 default:
292 /* all others reduced to triangles */
293 return R300_VAP_VF_CNTL__PRIM_TRIANGLES;
294 }
295 }
296
297 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim );
298 static void r300RenderPrimitive( GLcontext *ctx, GLenum prim );
299 //static void r300ResetLineStipple( GLcontext *ctx );
300
301 static void r300PrintVertex(r300Vertex *v)
302 {
303 fprintf(stderr,"Vertex %p\n", v);
304
305 }
306
307 /***********************************************************************
308 * Emit primitives as inline vertices *
309 ***********************************************************************/
310
311
312 #define HAVE_POINTS 1
313 #define HAVE_LINES 1
314 #define HAVE_LINE_STRIPS 1
315 #define HAVE_TRIANGLES 1
316 #define HAVE_TRI_STRIPS 1
317 #define HAVE_TRI_STRIP_1 0
318 #define HAVE_TRI_FANS 1
319 #define HAVE_QUADS 0
320 #define HAVE_QUAD_STRIPS 0
321 #define HAVE_POLYGONS 1
322 #define HAVE_ELTS 1
323
324 #undef LOCAL_VARS
325 #undef ALLOC_VERTS
326 #define CTX_ARG r300ContextPtr rmesa
327 #define GET_VERTEX_DWORDS() rmesa->swtcl.vertex_size
328 #define ALLOC_VERTS( n, size ) r300AllocDmaLowVerts( rmesa, n, size * 4 )
329 #define LOCAL_VARS \
330 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
331 const char *r300verts = (char *)rmesa->swtcl.verts;
332 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
333 #define VERTEX r300Vertex
334 #define DO_DEBUG_VERTS (1 && (RADEON_DEBUG & DEBUG_VERTS))
335 #define PRINT_VERTEX(x) r300PrintVertex(x)
336 #undef TAG
337 #define TAG(x) r300_##x
338 #include "tnl_dd/t_dd_triemit.h"
339
340
341
342 /***********************************************************************
343 * Macros for t_dd_tritmp.h to draw basic primitives *
344 ***********************************************************************/
345
346 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
347 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
348 #define LINE( a, b ) r300_line( rmesa, a, b )
349 #define POINT( a ) r300_point( rmesa, a )
350
351 /***********************************************************************
352 * Build render functions from dd templates *
353 ***********************************************************************/
354
355 #define R300_TWOSIDE_BIT 0x01
356 #define R300_UNFILLED_BIT 0x02
357 #define R300_MAX_TRIFUNC 0x04
358
359 static struct {
360 tnl_points_func points;
361 tnl_line_func line;
362 tnl_triangle_func triangle;
363 tnl_quad_func quad;
364 } rast_tab[R300_MAX_TRIFUNC];
365
366 #define DO_FALLBACK 0
367 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
368 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
369 #define DO_FLAT 0
370 #define DO_OFFSET 0
371 #define DO_TRI 1
372 #define DO_QUAD 1
373 #define DO_LINE 1
374 #define DO_POINTS 1
375 #define DO_FULL_QUAD 1
376
377 #define HAVE_RGBA 1
378 #define HAVE_SPEC 1
379 #define HAVE_BACK_COLORS 0
380 #define HAVE_HW_FLATSHADE 1
381 #define TAB rast_tab
382
383 #define DEPTH_SCALE 1.0
384 #define UNFILLED_TRI unfilled_tri
385 #define UNFILLED_QUAD unfilled_quad
386 #define VERT_X(_v) _v->v.x
387 #define VERT_Y(_v) _v->v.y
388 #define VERT_Z(_v) _v->v.z
389 #define AREA_IS_CCW( a ) (a < 0)
390 #define GET_VERTEX(e) (rmesa->swtcl.verts + (e*rmesa->swtcl.vertex_size*sizeof(int)))
391
392 #define VERT_SET_RGBA( v, c ) \
393 do { \
394 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
395 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
396 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
397 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
398 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
399 } while (0)
400
401 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
402
403 #define VERT_SET_SPEC( v, c ) \
404 do { \
405 if (specoffset) { \
406 r300_color_t *spec = (r300_color_t *)&((v)->ui[specoffset]); \
407 UNCLAMPED_FLOAT_TO_UBYTE(spec->red, (c)[0]); \
408 UNCLAMPED_FLOAT_TO_UBYTE(spec->green, (c)[1]); \
409 UNCLAMPED_FLOAT_TO_UBYTE(spec->blue, (c)[2]); \
410 } \
411 } while (0)
412 #define VERT_COPY_SPEC( v0, v1 ) \
413 do { \
414 if (specoffset) { \
415 r300_color_t *spec0 = (r300_color_t *)&((v0)->ui[specoffset]); \
416 r300_color_t *spec1 = (r300_color_t *)&((v1)->ui[specoffset]); \
417 spec0->red = spec1->red; \
418 spec0->green = spec1->green; \
419 spec0->blue = spec1->blue; \
420 } \
421 } while (0)
422
423 /* These don't need LE32_TO_CPU() as they used to save and restore
424 * colors which are already in the correct format.
425 */
426 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
427 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
428 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
429 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
430
431 #undef LOCAL_VARS
432 #undef TAG
433 #undef INIT
434
435 #define LOCAL_VARS(n) \
436 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
437 GLuint color[n], spec[n]; \
438 GLuint coloroffset = rmesa->swtcl.coloroffset; \
439 GLuint specoffset = rmesa->swtcl.specoffset; \
440 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
441
442 /***********************************************************************
443 * Helpers for rendering unfilled primitives *
444 ***********************************************************************/
445
446 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_hw_prim(ctx, x) )
447 #define RENDER_PRIMITIVE rmesa->swtcl.render_primitive
448 #undef TAG
449 #define TAG(x) x
450 #include "tnl_dd/t_dd_unfilled.h"
451 #undef IND
452
453
454 /***********************************************************************
455 * Generate GL render functions *
456 ***********************************************************************/
457
458
459 #define IND (0)
460 #define TAG(x) x
461 #include "tnl_dd/t_dd_tritmp.h"
462
463 #define IND (R300_TWOSIDE_BIT)
464 #define TAG(x) x##_twoside
465 #include "tnl_dd/t_dd_tritmp.h"
466
467 #define IND (R300_UNFILLED_BIT)
468 #define TAG(x) x##_unfilled
469 #include "tnl_dd/t_dd_tritmp.h"
470
471 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
472 #define TAG(x) x##_twoside_unfilled
473 #include "tnl_dd/t_dd_tritmp.h"
474
475
476 static void init_rast_tab( void )
477 {
478 init();
479 init_twoside();
480 init_unfilled();
481 init_twoside_unfilled();
482 }
483
484 /**********************************************************************/
485 /* Render unclipped begin/end objects */
486 /**********************************************************************/
487
488 #define RENDER_POINTS( start, count ) \
489 for ( ; start < count ; start++) \
490 r300_point( rmesa, VERT(start) )
491 #define RENDER_LINE( v0, v1 ) \
492 r300_line( rmesa, VERT(v0), VERT(v1) )
493 #define RENDER_TRI( v0, v1, v2 ) \
494 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
495 #define RENDER_QUAD( v0, v1, v2, v3 ) \
496 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
497 #define INIT(x) do { \
498 r300RenderPrimitive( ctx, x ); \
499 } while (0)
500 #undef LOCAL_VARS
501 #define LOCAL_VARS \
502 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
503 const GLuint vertsize = rmesa->swtcl.vertex_size; \
504 const char *r300verts = (char *)rmesa->swtcl.verts; \
505 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
506 const GLboolean stipple = ctx->Line.StippleFlag; \
507 (void) elt; (void) stipple;
508 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
509 #define RESET_OCCLUSION
510 #define PRESERVE_VB_DEFS
511 #define ELT(x) (x)
512 #define TAG(x) r300_##x##_verts
513 #include "tnl/t_vb_rendertmp.h"
514 #undef ELT
515 #undef TAG
516 #define TAG(x) r300_##x##_elts
517 #define ELT(x) elt[x]
518 #include "tnl/t_vb_rendertmp.h"
519
520
521
522
523 /**********************************************************************/
524 /* Choose render functions */
525 /**********************************************************************/
526
527 void r300ChooseRenderState( GLcontext *ctx )
528 {
529 TNLcontext *tnl = TNL_CONTEXT(ctx);
530 r300ContextPtr rmesa = R300_CONTEXT(ctx);
531 GLuint index = 0;
532 GLuint flags = ctx->_TriangleCaps;
533
534 // if (!rmesa->TclFallback || rmesa->Fallback)
535 // return;
536
537 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= R300_TWOSIDE_BIT;
538 if (flags & DD_TRI_UNFILLED) index |= R300_UNFILLED_BIT;
539
540 if (index != rmesa->swtcl.RenderIndex) {
541 tnl->Driver.Render.Points = rast_tab[index].points;
542 tnl->Driver.Render.Line = rast_tab[index].line;
543 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
544 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
545 tnl->Driver.Render.Quad = rast_tab[index].quad;
546
547 if (index == 0) {
548 tnl->Driver.Render.PrimTabVerts = r300_render_tab_verts;
549 tnl->Driver.Render.PrimTabElts = r300_render_tab_elts;
550 tnl->Driver.Render.ClippedPolygon = r300_fast_clipped_poly;
551 } else {
552 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
553 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
554 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
555 }
556
557 rmesa->swtcl.RenderIndex = index;
558 }
559 }
560
561
562 static void r300RenderStart(GLcontext *ctx)
563 {
564 r300ContextPtr rmesa = R300_CONTEXT( ctx );
565 fprintf(stderr, "%s\n", __FUNCTION__);
566
567 r300SetVertexFormat(ctx);
568 if (rmesa->dma.flush != 0 &&
569 rmesa->dma.flush != flush_last_swtcl_prim)
570 rmesa->dma.flush( rmesa );
571 }
572
573 static void r300RenderFinish(GLcontext *ctx)
574 {
575 fprintf(stderr, "%s\n", __FUNCTION__);
576 }
577
578 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
579 {
580 r300ContextPtr rmesa = R300_CONTEXT(ctx);
581
582 if (rmesa->swtcl.hw_primitive != hwprim) {
583 R300_NEWPRIM( rmesa );
584 rmesa->swtcl.hw_primitive = hwprim;
585 }
586 }
587
588 static void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
589 {
590
591 r300ContextPtr rmesa = R300_CONTEXT(ctx);
592 rmesa->swtcl.render_primitive = prim;
593 if (prim < GL_TRIANGLES || !(ctx->_TriangleCaps & DD_TRI_UNFILLED))
594 r300RasterPrimitive( ctx, reduced_hw_prim(ctx, prim) );
595 fprintf(stderr, "%s\n", __FUNCTION__);
596
597 }
598
599 static void r300ResetLineStipple(GLcontext *ctx)
600 {
601
602
603 }
604
605 void r300InitSwtcl(GLcontext *ctx)
606 {
607 TNLcontext *tnl = TNL_CONTEXT(ctx);
608 r300ContextPtr rmesa = R300_CONTEXT(ctx);
609 static int firsttime = 1;
610
611 if (firsttime) {
612 init_rast_tab();
613 firsttime = 0;
614 }
615
616 tnl->Driver.Render.Start = r300RenderStart;
617 tnl->Driver.Render.Finish = r300RenderFinish;
618 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
619 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
620 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
621 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
622 tnl->Driver.Render.Interp = _tnl_interp;
623
624 /* FIXME: what are these numbers? */
625 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
626 36 * sizeof(GLfloat) );
627
628 rmesa->swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
629 rmesa->swtcl.RenderIndex = ~0;
630 rmesa->swtcl.render_primitive = GL_TRIANGLES;
631 rmesa->swtcl.hw_primitive = 0;
632
633 _tnl_invalidate_vertex_state( ctx, ~0 );
634 _tnl_invalidate_vertices( ctx, ~0 );
635 RENDERINPUTS_ZERO( rmesa->tnl_index_bitset );
636
637 r300ChooseRenderState(ctx);
638 }
639
640 void r300DestroySwtcl(GLcontext *ctx)
641 {
642 }
643
644 void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, GLuint offset)
645 {
646 int cmd_reserved = 0;
647 int cmd_written = 0;
648
649 drm_radeon_cmd_header_t *cmd = NULL;
650 if (1)//RADEON_DEBUG & DEBUG_VERTS)
651 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
652 __FUNCTION__, vertex_size, offset);
653
654 start_packet3(CP_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2), 2);
655 e32(1);
656 e32(vertex_size | (vertex_size << 8));
657 e32(offset);
658 }
659
660 void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
661 {
662
663 int cmd_reserved = 0;
664 int cmd_written = 0;
665 int type, num_verts;
666 drm_radeon_cmd_header_t *cmd = NULL;
667
668 type = r300PrimitiveType(rmesa, primitive);
669 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
670 r300EmitState(rmesa);
671
672 start_packet3(CP_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0), 0);
673 e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
674 }