98208cd77e65e0a0a9a9157fb6e071ed9dd69e4d
[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 "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"
45
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"
50 #include "tnl/tnl.h"
51 #include "tnl/t_context.h"
52 #include "tnl/t_pipeline.h"
53
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"
59
60 void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, struct radeon_bo *bo, GLuint offset);
61 void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr);
62 #define EMIT_ATTR( ATTR, STYLE ) \
63 do { \
64 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
65 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
66 rmesa->radeon.swtcl.vertex_attr_count++; \
67 } while (0)
68
69 #define EMIT_PAD( N ) \
70 do { \
71 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
72 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
73 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
74 rmesa->radeon.swtcl.vertex_attr_count++; \
75 } while (0)
76
77 static void r300SetVertexFormat( GLcontext *ctx )
78 {
79 r300ContextPtr rmesa = R300_CONTEXT( ctx );
80 TNLcontext *tnl = TNL_CONTEXT(ctx);
81 struct vertex_buffer *VB = &tnl->vb;
82 DECLARE_RENDERINPUTS(index_bitset);
83 GLuint InputsRead = 0, OutputsWritten = 0;
84 int vap_fmt_0 = 0;
85 int offset = 0;
86 int vte = 0;
87 GLint inputs[VERT_ATTRIB_MAX];
88 GLint tab[VERT_ATTRIB_MAX];
89 int swizzle[VERT_ATTRIB_MAX][4];
90 GLuint i, nr;
91 GLuint sz, vap_fmt_1 = 0;
92
93 DECLARE_RENDERINPUTS(render_inputs_bitset);
94 RENDERINPUTS_COPY(render_inputs_bitset, tnl->render_inputs_bitset);
95 RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
96 RENDERINPUTS_COPY(rmesa->state.render_inputs_bitset, render_inputs_bitset);
97
98 vte = rmesa->hw.vte.cmd[1];
99 vte &= ~(R300_VTX_XY_FMT | R300_VTX_Z_FMT | R300_VTX_W0_FMT);
100 /* Important:
101 */
102 if ( VB->NdcPtr != NULL ) {
103 VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
104 vte |= R300_VTX_XY_FMT | R300_VTX_Z_FMT;
105 }
106 else {
107 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
108 vte |= R300_VTX_W0_FMT;
109 }
110
111 assert( VB->AttribPtr[VERT_ATTRIB_POS] != NULL );
112 rmesa->radeon.swtcl.vertex_attr_count = 0;
113
114 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
115 * build up a hardware vertex.
116 */
117 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POS)) {
118 sz = VB->AttribPtr[VERT_ATTRIB_POS]->size;
119 InputsRead |= 1 << VERT_ATTRIB_POS;
120 OutputsWritten |= 1 << VERT_RESULT_HPOS;
121 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_1F + sz - 1 );
122 offset = sz;
123 } else {
124 offset = 4;
125 EMIT_PAD(4 * sizeof(float));
126 }
127
128 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) {
129 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F );
130 vap_fmt_0 |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT;
131 offset += 1;
132 }
133
134 if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_COLOR0)) {
135 sz = VB->AttribPtr[VERT_ATTRIB_COLOR0]->size;
136 rmesa->swtcl.coloroffset = offset;
137 InputsRead |= 1 << VERT_ATTRIB_COLOR0;
138 OutputsWritten |= 1 << VERT_RESULT_COL0;
139 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_1F + sz - 1 );
140 offset += sz;
141 }
142
143 rmesa->swtcl.specoffset = 0;
144 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
145 sz = VB->AttribPtr[VERT_ATTRIB_COLOR1]->size;
146 rmesa->swtcl.specoffset = offset;
147 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_1F + sz - 1 );
148 InputsRead |= 1 << VERT_ATTRIB_COLOR1;
149 OutputsWritten |= 1 << VERT_RESULT_COL1;
150 }
151
152 if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
153 int i;
154
155 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
156 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) {
157 sz = VB->TexCoordPtr[i]->size;
158 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i);
159 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i);
160 EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_1F + sz - 1 );
161 vap_fmt_1 |= sz << (3 * i);
162 }
163 }
164 }
165
166 for (i = 0, nr = 0; i < VERT_ATTRIB_MAX; i++) {
167 if (InputsRead & (1 << i)) {
168 inputs[i] = nr++;
169 } else {
170 inputs[i] = -1;
171 }
172 }
173
174 /* Fixed, apply to vir0 only */
175 if (InputsRead & (1 << VERT_ATTRIB_POS))
176 inputs[VERT_ATTRIB_POS] = 0;
177 if (InputsRead & (1 << VERT_ATTRIB_COLOR0))
178 inputs[VERT_ATTRIB_COLOR0] = 2;
179 if (InputsRead & (1 << VERT_ATTRIB_COLOR1))
180 inputs[VERT_ATTRIB_COLOR1] = 3;
181 for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++)
182 if (InputsRead & (1 << i))
183 inputs[i] = 6 + (i - VERT_ATTRIB_TEX0);
184
185 for (i = 0, nr = 0; i < VERT_ATTRIB_MAX; i++) {
186 if (InputsRead & (1 << i)) {
187 tab[nr++] = i;
188 }
189 }
190
191 for (i = 0; i < nr; i++) {
192 int ci;
193
194 swizzle[i][0] = SWIZZLE_ZERO;
195 swizzle[i][1] = SWIZZLE_ZERO;
196 swizzle[i][2] = SWIZZLE_ZERO;
197 swizzle[i][3] = SWIZZLE_ONE;
198
199 for (ci = 0; ci < VB->AttribPtr[tab[i]]->size; ci++) {
200 swizzle[i][ci] = ci;
201 }
202 }
203
204 R300_NEWPRIM(rmesa);
205 R300_STATECHANGE(rmesa, vir[0]);
206 ((drm_r300_cmd_header_t *) rmesa->hw.vir[0].cmd)->packet0.count =
207 r300VAPInputRoute0(&rmesa->hw.vir[0].cmd[R300_VIR_CNTL_0],
208 VB->AttribPtr, inputs, tab, nr);
209 R300_STATECHANGE(rmesa, vir[1]);
210 ((drm_r300_cmd_header_t *) rmesa->hw.vir[1].cmd)->packet0.count =
211 r300VAPInputRoute1(&rmesa->hw.vir[1].cmd[R300_VIR_CNTL_0], swizzle,
212 nr);
213
214 R300_STATECHANGE(rmesa, vic);
215 rmesa->hw.vic.cmd[R300_VIC_CNTL_0] = r300VAPInputCntl0(ctx, InputsRead);
216 rmesa->hw.vic.cmd[R300_VIC_CNTL_1] = r300VAPInputCntl1(ctx, InputsRead);
217
218 R300_STATECHANGE(rmesa, vof);
219 rmesa->hw.vof.cmd[R300_VOF_CNTL_0] = r300VAPOutputCntl0(ctx, OutputsWritten);
220 rmesa->hw.vof.cmd[R300_VOF_CNTL_1] = vap_fmt_1;
221
222 rmesa->radeon.swtcl.vertex_size =
223 _tnl_install_attrs( ctx,
224 rmesa->radeon.swtcl.vertex_attrs,
225 rmesa->radeon.swtcl.vertex_attr_count,
226 NULL, 0 );
227
228 rmesa->radeon.swtcl.vertex_size /= 4;
229
230 RENDERINPUTS_COPY( rmesa->tnl_index_bitset, index_bitset );
231
232
233 R300_STATECHANGE(rmesa, vte);
234 rmesa->hw.vte.cmd[1] = vte;
235 rmesa->hw.vte.cmd[2] = rmesa->radeon.swtcl.vertex_size;
236 }
237
238 static GLuint reduced_prim[] = {
239 GL_POINTS,
240 GL_LINES,
241 GL_LINES,
242 GL_LINES,
243 GL_TRIANGLES,
244 GL_TRIANGLES,
245 GL_TRIANGLES,
246 GL_TRIANGLES,
247 GL_TRIANGLES,
248 GL_TRIANGLES,
249 };
250
251 static void r300RasterPrimitive( GLcontext *ctx, GLuint prim );
252 static void r300RenderPrimitive( GLcontext *ctx, GLenum prim );
253 //static void r300ResetLineStipple( GLcontext *ctx );
254
255 /***********************************************************************
256 * Emit primitives as inline vertices *
257 ***********************************************************************/
258
259
260 #define HAVE_POINTS 1
261 #define HAVE_LINES 1
262 #define HAVE_LINE_STRIPS 1
263 #define HAVE_TRIANGLES 1
264 #define HAVE_TRI_STRIPS 1
265 #define HAVE_TRI_STRIP_1 0
266 #define HAVE_TRI_FANS 1
267 #define HAVE_QUADS 0
268 #define HAVE_QUAD_STRIPS 0
269 #define HAVE_POLYGONS 1
270 #define HAVE_ELTS 1
271
272 #undef LOCAL_VARS
273 #undef ALLOC_VERTS
274 #define CTX_ARG r300ContextPtr rmesa
275 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
276 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
277 #define LOCAL_VARS \
278 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
279 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
280 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
281 #define VERTEX r300Vertex
282 #define DO_DEBUG_VERTS (1 && (RADEON_DEBUG & DEBUG_VERTS))
283 #define PRINT_VERTEX(x)
284 #undef TAG
285 #define TAG(x) r300_##x
286 #include "tnl_dd/t_dd_triemit.h"
287
288
289
290 /***********************************************************************
291 * Macros for t_dd_tritmp.h to draw basic primitives *
292 ***********************************************************************/
293
294 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
295 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
296 #define LINE( a, b ) r300_line( rmesa, a, b )
297 #define POINT( a ) r300_point( rmesa, a )
298
299 /***********************************************************************
300 * Build render functions from dd templates *
301 ***********************************************************************/
302
303 #define R300_TWOSIDE_BIT 0x01
304 #define R300_UNFILLED_BIT 0x02
305 #define R300_MAX_TRIFUNC 0x04
306
307 static struct {
308 tnl_points_func points;
309 tnl_line_func line;
310 tnl_triangle_func triangle;
311 tnl_quad_func quad;
312 } rast_tab[R300_MAX_TRIFUNC];
313
314 #define DO_FALLBACK 0
315 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
316 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
317 #define DO_FLAT 0
318 #define DO_OFFSET 0
319 #define DO_TRI 1
320 #define DO_QUAD 1
321 #define DO_LINE 1
322 #define DO_POINTS 1
323 #define DO_FULL_QUAD 1
324
325 #define HAVE_RGBA 1
326 #define HAVE_SPEC 1
327 #define HAVE_BACK_COLORS 0
328 #define HAVE_HW_FLATSHADE 1
329 #define TAB rast_tab
330
331 #define DEPTH_SCALE 1.0
332 #define UNFILLED_TRI unfilled_tri
333 #define UNFILLED_QUAD unfilled_quad
334 #define VERT_X(_v) _v->v.x
335 #define VERT_Y(_v) _v->v.y
336 #define VERT_Z(_v) _v->v.z
337 #define AREA_IS_CCW( a ) (a < 0)
338 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
339
340 /* Only used to pull back colors into vertices (ie, we know color is
341 * floating point).
342 */
343 #define R300_COLOR( dst, src ) \
344 do { \
345 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
346 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
347 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
348 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
349 } while (0)
350
351 #define VERT_SET_RGBA( v, c ) if (coloroffset) R300_COLOR( v->ub4[coloroffset], c )
352 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
353 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
354 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
355
356 #define R300_SPEC( dst, src ) \
357 do { \
358 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
359 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
360 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
361 } while (0)
362
363 #define VERT_SET_SPEC( v, c ) if (specoffset) R300_SPEC( v->ub4[specoffset], c )
364 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
365 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
366 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
367
368 #undef LOCAL_VARS
369 #undef TAG
370 #undef INIT
371
372 #define LOCAL_VARS(n) \
373 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
374 GLuint color[n], spec[n]; \
375 GLuint coloroffset = rmesa->swtcl.coloroffset; \
376 GLuint specoffset = rmesa->swtcl.specoffset; \
377 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
378
379 /***********************************************************************
380 * Helpers for rendering unfilled primitives *
381 ***********************************************************************/
382
383 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
384 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
385 #undef TAG
386 #define TAG(x) x
387 #include "tnl_dd/t_dd_unfilled.h"
388 #undef IND
389
390
391 /***********************************************************************
392 * Generate GL render functions *
393 ***********************************************************************/
394
395
396 #define IND (0)
397 #define TAG(x) x
398 #include "tnl_dd/t_dd_tritmp.h"
399
400 #define IND (R300_TWOSIDE_BIT)
401 #define TAG(x) x##_twoside
402 #include "tnl_dd/t_dd_tritmp.h"
403
404 #define IND (R300_UNFILLED_BIT)
405 #define TAG(x) x##_unfilled
406 #include "tnl_dd/t_dd_tritmp.h"
407
408 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
409 #define TAG(x) x##_twoside_unfilled
410 #include "tnl_dd/t_dd_tritmp.h"
411
412
413
414 static void init_rast_tab( void )
415 {
416 init();
417 init_twoside();
418 init_unfilled();
419 init_twoside_unfilled();
420 }
421
422 /**********************************************************************/
423 /* Render unclipped begin/end objects */
424 /**********************************************************************/
425
426 #define RENDER_POINTS( start, count ) \
427 for ( ; start < count ; start++) \
428 r300_point( rmesa, VERT(start) )
429 #define RENDER_LINE( v0, v1 ) \
430 r300_line( rmesa, VERT(v0), VERT(v1) )
431 #define RENDER_TRI( v0, v1, v2 ) \
432 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
433 #define RENDER_QUAD( v0, v1, v2, v3 ) \
434 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
435 #define INIT(x) do { \
436 r300RenderPrimitive( ctx, x ); \
437 } while (0)
438 #undef LOCAL_VARS
439 #define LOCAL_VARS \
440 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
441 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
442 const char *r300verts = (char *)rmesa->radeon.swtcl.verts; \
443 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
444 const GLboolean stipple = ctx->Line.StippleFlag; \
445 (void) elt; (void) stipple;
446 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
447 #define RESET_OCCLUSION
448 #define PRESERVE_VB_DEFS
449 #define ELT(x) (x)
450 #define TAG(x) r300_##x##_verts
451 #include "tnl/t_vb_rendertmp.h"
452 #undef ELT
453 #undef TAG
454 #define TAG(x) r300_##x##_elts
455 #define ELT(x) elt[x]
456 #include "tnl/t_vb_rendertmp.h"
457
458
459
460
461 /**********************************************************************/
462 /* Choose render functions */
463 /**********************************************************************/
464 static void r300ChooseRenderState( GLcontext *ctx )
465 {
466 TNLcontext *tnl = TNL_CONTEXT(ctx);
467 r300ContextPtr rmesa = R300_CONTEXT(ctx);
468 GLuint index = 0;
469 GLuint flags = ctx->_TriangleCaps;
470
471 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= R300_TWOSIDE_BIT;
472 if (flags & DD_TRI_UNFILLED) index |= R300_UNFILLED_BIT;
473
474 if (index != rmesa->radeon.swtcl.RenderIndex) {
475 tnl->Driver.Render.Points = rast_tab[index].points;
476 tnl->Driver.Render.Line = rast_tab[index].line;
477 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
478 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
479 tnl->Driver.Render.Quad = rast_tab[index].quad;
480
481 if (index == 0) {
482 tnl->Driver.Render.PrimTabVerts = r300_render_tab_verts;
483 tnl->Driver.Render.PrimTabElts = r300_render_tab_elts;
484 tnl->Driver.Render.ClippedPolygon = r300_fast_clipped_poly;
485 } else {
486 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
487 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
488 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
489 }
490
491 rmesa->radeon.swtcl.RenderIndex = index;
492 }
493 }
494
495
496 static void r300RenderStart(GLcontext *ctx)
497 {
498 r300ContextPtr rmesa = R300_CONTEXT( ctx );
499 // fprintf(stderr, "%s\n", __FUNCTION__);
500
501 r300ChooseRenderState(ctx);
502 r300SetVertexFormat(ctx);
503
504 r300ValidateBuffers(ctx);
505
506 r300UpdateShaders(rmesa);
507 r300UpdateShaderStates(rmesa);
508
509 r300EmitCacheFlush(rmesa);
510 if (rmesa->radeon.dma.flush != NULL) {
511 rmesa->radeon.dma.flush(ctx);
512 }
513 }
514
515 static void r300RenderFinish(GLcontext *ctx)
516 {
517 }
518
519 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
520 {
521 r300ContextPtr rmesa = R300_CONTEXT(ctx);
522
523 if (rmesa->radeon.swtcl.hw_primitive != hwprim) {
524 R300_NEWPRIM( rmesa );
525 rmesa->radeon.swtcl.hw_primitive = hwprim;
526 }
527 }
528
529 static void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
530 {
531
532 r300ContextPtr rmesa = R300_CONTEXT(ctx);
533 rmesa->radeon.swtcl.render_primitive = prim;
534
535 if ((prim == GL_TRIANGLES) && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
536 return;
537
538 r300RasterPrimitive( ctx, reduced_prim[prim] );
539 // fprintf(stderr, "%s\n", __FUNCTION__);
540
541 }
542
543 static void r300ResetLineStipple(GLcontext *ctx)
544 {
545
546
547 }
548
549 void r300InitSwtcl(GLcontext *ctx)
550 {
551 TNLcontext *tnl = TNL_CONTEXT(ctx);
552 r300ContextPtr rmesa = R300_CONTEXT(ctx);
553 static int firsttime = 1;
554
555 if (firsttime) {
556 init_rast_tab();
557 firsttime = 0;
558 }
559
560 tnl->Driver.Render.Start = r300RenderStart;
561 tnl->Driver.Render.Finish = r300RenderFinish;
562 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
563 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
564 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
565 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
566 tnl->Driver.Render.Interp = _tnl_interp;
567
568 /* FIXME: what are these numbers? */
569 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
570 48 * sizeof(GLfloat) );
571
572 rmesa->radeon.swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
573 rmesa->radeon.swtcl.RenderIndex = ~0;
574 rmesa->radeon.swtcl.render_primitive = GL_TRIANGLES;
575 rmesa->radeon.swtcl.hw_primitive = 0;
576
577 _tnl_invalidate_vertex_state( ctx, ~0 );
578 _tnl_invalidate_vertices( ctx, ~0 );
579 RENDERINPUTS_ZERO( rmesa->tnl_index_bitset );
580
581 _tnl_need_projected_coords( ctx, GL_FALSE );
582 r300ChooseRenderState(ctx);
583
584 _mesa_validate_all_lighting_tables( ctx );
585
586 tnl->Driver.NotifyMaterialChange =
587 _mesa_validate_all_lighting_tables;
588 }
589
590 void r300DestroySwtcl(GLcontext *ctx)
591 {
592 }
593
594 void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, struct radeon_bo *bo, GLuint offset)
595 {
596 BATCH_LOCALS(&rmesa->radeon);
597
598 if (RADEON_DEBUG & DEBUG_VERTS)
599 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
600 __FUNCTION__, vertex_size, offset);
601
602 BEGIN_BATCH(5);
603 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2);
604 OUT_BATCH(1);
605 OUT_BATCH(vertex_size | (vertex_size << 8));
606 OUT_BATCH_RELOC(offset, bo, offset, RADEON_GEM_DOMAIN_GTT, 0, 0);
607 END_BATCH();
608 }
609
610 void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
611 {
612 BATCH_LOCALS(&rmesa->radeon);
613 int type, num_verts;
614
615 type = r300PrimitiveType(rmesa, primitive);
616 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
617
618 BEGIN_BATCH(3);
619 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
620 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
621 END_BATCH();
622 }
623
624 void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
625 {
626 r300ContextPtr rmesa = R300_CONTEXT(ctx);
627
628 rcommonEnsureCmdBufSpace(&rmesa->radeon,
629 rmesa->hw.max_state_size + (12*sizeof(int)),
630 __FUNCTION__);
631 r300EmitState(rmesa);
632 r300EmitVertexAOS(rmesa,
633 rmesa->radeon.swtcl.vertex_size,
634 rmesa->radeon.dma.current,
635 current_offset);
636
637 r300EmitVbufPrim(rmesa,
638 rmesa->radeon.swtcl.hw_primitive,
639 rmesa->radeon.swtcl.numverts);
640 r300EmitCacheFlush(rmesa);
641 COMMIT_BATCH();
642
643 }