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