radeon: Optimize memory handling for dma operations.
[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 * Maciej Cencora <m.cencora@gmail.com>
32 */
33
34 #include "tnl/tnl.h"
35 #include "tnl/t_pipeline.h"
36
37 #include "r300_state.h"
38 #include "r300_swtcl.h"
39 #include "r300_emit.h"
40 #include "r300_tex.h"
41 #include "r300_render.h"
42 #include "main/simple_list.h"
43
44 #define EMIT_ATTR( ATTR, STYLE ) \
45 do { \
46 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
47 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
48 rmesa->radeon.swtcl.vertex_attr_count++; \
49 } while (0)
50
51 #define EMIT_PAD( N ) \
52 do { \
53 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
54 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
55 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
56 rmesa->radeon.swtcl.vertex_attr_count++; \
57 } while (0)
58
59 #define ADD_ATTR(_attr, _format, _dst_loc, _swizzle, _write_mask, _normalize) \
60 do { \
61 attrs[num_attrs].element = (_attr); \
62 attrs[num_attrs].data_type = (_format); \
63 attrs[num_attrs].dst_loc = (_dst_loc); \
64 attrs[num_attrs].swizzle = (_swizzle); \
65 attrs[num_attrs].write_mask = (_write_mask); \
66 attrs[num_attrs]._signed = 0; \
67 attrs[num_attrs].normalize = (_normalize); \
68 ++num_attrs; \
69 } while (0)
70
71 void r300ChooseSwtclVertexFormat(GLcontext *ctx, GLuint *_InputsRead, GLuint *_OutputsWritten)
72 {
73 r300ContextPtr rmesa = R300_CONTEXT( ctx );
74 TNLcontext *tnl = TNL_CONTEXT(ctx);
75 struct vertex_buffer *VB = &tnl->vb;
76 int first_free_tex = 0;
77 GLuint InputsRead = 0;
78 GLuint OutputsWritten = 0;
79 int num_attrs = 0;
80 GLuint fp_reads = rmesa->selected_fp->InputsRead;
81 struct vertex_attribute *attrs = rmesa->vbuf.attribs;
82
83 rmesa->swtcl.coloroffset = rmesa->swtcl.specoffset = 0;
84 rmesa->radeon.swtcl.vertex_attr_count = 0;
85
86 /* We always want non Ndc coords format */
87 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
88
89 /* Always write position vector */
90 InputsRead |= 1 << VERT_ATTRIB_POS;
91 OutputsWritten |= 1 << VERT_RESULT_HPOS;
92 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F );
93 ADD_ATTR(VERT_ATTRIB_POS, R300_DATA_TYPE_FLOAT_4, SWTCL_OVM_POS, SWIZZLE_XYZW, MASK_XYZW, 0);
94 rmesa->swtcl.coloroffset = 4;
95
96 if (fp_reads & FRAG_BIT_COL0) {
97 InputsRead |= 1 << VERT_ATTRIB_COLOR0;
98 OutputsWritten |= 1 << VERT_RESULT_COL0;
99 #if MESA_LITTLE_ENDIAN
100 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_RGBA );
101 ADD_ATTR(VERT_ATTRIB_COLOR0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR0, SWIZZLE_XYZW, MASK_XYZW, 1);
102 #else
103 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_ABGR );
104 ADD_ATTR(VERT_ATTRIB_COLOR0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR0, SWIZZLE_XYZW, MASK_XYZW, 1);
105 #endif
106 }
107
108 if (fp_reads & FRAG_BIT_COL1) {
109 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
110 InputsRead |= 1 << VERT_ATTRIB_COLOR1;
111 OutputsWritten |= 1 << VERT_RESULT_COL1;
112 #if MESA_LITTLE_ENDIAN
113 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4UB_4F_RGBA );
114 ADD_ATTR(VERT_ATTRIB_COLOR1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR1, swiz, MASK_XYZW, 1);
115 #else
116 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4UB_4F_ABGR );
117 ADD_ATTR(VERT_ATTRIB_COLOR1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR1, swiz, MASK_XYZW, 1);
118 #endif
119 rmesa->swtcl.specoffset = rmesa->swtcl.coloroffset + 1;
120 }
121
122 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) {
123 VB->AttribPtr[VERT_ATTRIB_GENERIC0] = VB->ColorPtr[1];
124 OutputsWritten |= 1 << VERT_RESULT_BFC0;
125 #if MESA_LITTLE_ENDIAN
126 EMIT_ATTR( _TNL_ATTRIB_GENERIC0, EMIT_4UB_4F_RGBA );
127 ADD_ATTR(VERT_ATTRIB_GENERIC0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR2, SWIZZLE_XYZW, MASK_XYZW, 1);
128 #else
129 EMIT_ATTR( _TNL_ATTRIB_GENERIC0, EMIT_4UB_4F_ABGR );
130 ADD_ATTR(VERT_ATTRIB_GENERIC0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR2, SWIZZLE_XYZW, MASK_XYZW, 1);
131 #endif
132 if (fp_reads & FRAG_BIT_COL1) {
133 VB->AttribPtr[VERT_ATTRIB_GENERIC1] = VB->SecondaryColorPtr[1];
134 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
135 OutputsWritten |= 1 << VERT_RESULT_BFC1;
136 #if MESA_LITTLE_ENDIAN
137 EMIT_ATTR( _TNL_ATTRIB_GENERIC1, EMIT_4UB_4F_RGBA );
138 ADD_ATTR(VERT_ATTRIB_GENERIC1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR3, swiz, MASK_XYZW, 1);
139 #else
140 EMIT_ATTR( _TNL_ATTRIB_GENERIC1, EMIT_4UB_4F_ABGR );
141 ADD_ATTR(VERT_ATTRIB_GENERIC1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR3, swiz, MASK_XYZW, 1);
142 #endif
143 }
144 }
145
146 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_POINTSIZE )) {
147 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO);
148 InputsRead |= 1 << VERT_ATTRIB_POINT_SIZE;
149 OutputsWritten |= 1 << VERT_RESULT_PSIZ;
150 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F );
151 ADD_ATTR(VERT_ATTRIB_POINT_SIZE, R300_DATA_TYPE_FLOAT_1, SWTCL_OVM_POINT_SIZE, swiz, MASK_X, 0);
152 }
153
154 if (rmesa->selected_fp->wpos_attr != FRAG_ATTRIB_MAX) {
155 int tex_id = rmesa->selected_fp->wpos_attr - FRAG_ATTRIB_TEX0;
156
157 VB->AttribPtr[VERT_ATTRIB_TEX0 + tex_id] = VB->AttribPtr[VERT_ATTRIB_POS];
158 VB->TexCoordPtr[tex_id] = VB->AttribPtr[VERT_ATTRIB_POS];
159 RENDERINPUTS_SET(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX0 + tex_id);
160 }
161
162 if (rmesa->selected_fp->fog_attr != FRAG_ATTRIB_MAX) {
163 int tex_id = rmesa->selected_fp->fog_attr - FRAG_ATTRIB_TEX0;
164
165 VB->AttribPtr[VERT_ATTRIB_TEX0 + tex_id] = VB->AttribPtr[VERT_ATTRIB_FOG];
166 VB->TexCoordPtr[tex_id] = VB->AttribPtr[VERT_ATTRIB_FOG];
167 RENDERINPUTS_SET(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX0 + tex_id);
168 }
169
170 /**
171 * Sending only one texcoord component may lead to lock up,
172 * so for all textures always output 4 texcoord components to RS.
173 */
174 {
175 int i;
176 GLuint swiz, format, hw_format;
177 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
178 if (fp_reads & FRAG_BIT_TEX(i)) {
179 switch (VB->TexCoordPtr[i]->size) {
180 case 1:
181 format = EMIT_1F;
182 hw_format = R300_DATA_TYPE_FLOAT_1;
183 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
184 break;
185 case 2:
186 format = EMIT_2F;
187 hw_format = R300_DATA_TYPE_FLOAT_2;
188 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
189 break;
190 case 3:
191 format = EMIT_3F;
192 hw_format = R300_DATA_TYPE_FLOAT_3;
193 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
194 break;
195 case 4:
196 format = EMIT_4F;
197 hw_format = R300_DATA_TYPE_FLOAT_4;
198 swiz = SWIZZLE_XYZW;
199 break;
200 default:
201 continue;
202 }
203 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i);
204 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i);
205 EMIT_ATTR(_TNL_ATTRIB_TEX(i), format);
206 ADD_ATTR(VERT_ATTRIB_TEX0 + i, hw_format, SWTCL_OVM_TEX(first_free_tex), swiz, MASK_XYZW, 0);
207 ++first_free_tex;
208 }
209 }
210 }
211
212 if (first_free_tex >= ctx->Const.MaxTextureUnits) {
213 fprintf(stderr, "\tout of free texcoords to write fog coordinate\n");
214 _mesa_exit(-1);
215 }
216
217 R300_NEWPRIM(rmesa);
218 rmesa->vbuf.num_attribs = num_attrs;
219 *_InputsRead = InputsRead;
220 *_OutputsWritten = OutputsWritten;
221
222 RENDERINPUTS_COPY(rmesa->render_inputs_bitset, tnl->render_inputs_bitset);
223 }
224
225 static void r300PrepareVertices(GLcontext *ctx)
226 {
227 r300ContextPtr rmesa = R300_CONTEXT(ctx);
228 GLuint InputsRead, OutputsWritten;
229
230 r300ChooseSwtclVertexFormat(ctx, &InputsRead, &OutputsWritten);
231 r300SetupVAP(ctx, InputsRead, OutputsWritten);
232
233 rmesa->radeon.swtcl.vertex_size =
234 _tnl_install_attrs( ctx,
235 rmesa->radeon.swtcl.vertex_attrs,
236 rmesa->radeon.swtcl.vertex_attr_count,
237 NULL, 0 );
238
239 rmesa->radeon.swtcl.vertex_size /= 4;
240 }
241
242
243 static GLuint reduced_prim[] = {
244 GL_POINTS,
245 GL_LINES,
246 GL_LINES,
247 GL_LINES,
248 GL_TRIANGLES,
249 GL_TRIANGLES,
250 GL_TRIANGLES,
251 GL_TRIANGLES,
252 GL_TRIANGLES,
253 GL_TRIANGLES,
254 };
255
256 static void r300RasterPrimitive( GLcontext *ctx, GLuint prim );
257
258 /***********************************************************************
259 * Emit primitives as inline vertices *
260 ***********************************************************************/
261
262
263 #define HAVE_POINTS 1
264 #define HAVE_LINES 1
265 #define HAVE_LINE_STRIPS 1
266 #define HAVE_TRIANGLES 1
267 #define HAVE_TRI_STRIPS 1
268 #define HAVE_TRI_STRIP_1 0
269 #define HAVE_TRI_FANS 1
270 #define HAVE_QUADS 0
271 #define HAVE_QUAD_STRIPS 0
272 #define HAVE_POLYGONS 1
273 #define HAVE_ELTS 1
274
275 #undef LOCAL_VARS
276 #undef ALLOC_VERTS
277 #define CTX_ARG r300ContextPtr rmesa
278 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
279 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
280 #define LOCAL_VARS \
281 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
282 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
283 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
284 #define VERTEX r300Vertex
285 #undef TAG
286 #define TAG(x) r300_##x
287 #include "tnl_dd/t_dd_triemit.h"
288
289
290
291 /***********************************************************************
292 * Macros for t_dd_tritmp.h to draw basic primitives *
293 ***********************************************************************/
294
295 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
296 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
297 #define LINE( a, b ) r300_line( rmesa, a, b )
298 #define POINT( a ) r300_point( rmesa, a )
299
300 /***********************************************************************
301 * Build render functions from dd templates *
302 ***********************************************************************/
303
304 #define R300_UNFILLED_BIT 0x01
305 #define R300_MAX_TRIFUNC 0x02
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 0
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 #define VERT_SET_RGBA( v, c ) \
341 do { \
342 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
343 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
344 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
345 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
346 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
347 } while (0)
348
349 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
350
351 #define VERT_SET_SPEC( v0, c ) \
352 do { \
353 if (specoffset) { \
354 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
355 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
356 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
357 } \
358 } while (0)
359
360 #define VERT_COPY_SPEC( v0, v1 ) \
361 do { \
362 if (specoffset) { \
363 v0->v.specular.red = v1->v.specular.red; \
364 v0->v.specular.green = v1->v.specular.green; \
365 v0->v.specular.blue = v1->v.specular.blue; \
366 } \
367 } while (0)
368
369 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
370 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
371 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
372 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
373
374 #undef LOCAL_VARS
375 #undef TAG
376 #undef INIT
377
378 #define LOCAL_VARS(n) \
379 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
380 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
381 GLuint coloroffset = rmesa->swtcl.coloroffset; \
382 GLuint specoffset = rmesa->swtcl.specoffset; \
383 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
384
385 /***********************************************************************
386 * Helpers for rendering unfilled primitives *
387 ***********************************************************************/
388
389 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
390 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
391 #undef TAG
392 #define TAG(x) x
393 #include "tnl_dd/t_dd_unfilled.h"
394 #undef IND
395
396
397 /***********************************************************************
398 * Generate GL render functions *
399 ***********************************************************************/
400
401
402 #define IND (0)
403 #define TAG(x) x
404 #include "tnl_dd/t_dd_tritmp.h"
405
406 #define IND (R300_UNFILLED_BIT)
407 #define TAG(x) x##_unfilled
408 #include "tnl_dd/t_dd_tritmp.h"
409
410
411 static void init_rast_tab( void )
412 {
413 init();
414 init_unfilled();
415 }
416
417 /**********************************************************************/
418 /* Render unclipped begin/end objects */
419 /**********************************************************************/
420
421 #define RENDER_POINTS( start, count ) \
422 for ( ; start < count ; start++) \
423 r300_point( rmesa, VERT(start) )
424 #define RENDER_LINE( v0, v1 ) \
425 r300_line( rmesa, VERT(v0), VERT(v1) )
426 #define RENDER_TRI( v0, v1, v2 ) \
427 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
428 #define RENDER_QUAD( v0, v1, v2, v3 ) \
429 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
430 #define INIT(x) do { \
431 r300RenderPrimitive( ctx, x ); \
432 } while (0)
433 #undef LOCAL_VARS
434 #define LOCAL_VARS \
435 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
436 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
437 const char *r300verts = (char *)rmesa->radeon.swtcl.verts; \
438 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
439 const GLboolean stipple = ctx->Line.StippleFlag; \
440 (void) elt; (void) stipple;
441 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
442 #define RESET_OCCLUSION
443 #define PRESERVE_VB_DEFS
444 #define ELT(x) (x)
445 #define TAG(x) r300_##x##_verts
446 #include "tnl/t_vb_rendertmp.h"
447 #undef ELT
448 #undef TAG
449 #define TAG(x) r300_##x##_elts
450 #define ELT(x) elt[x]
451 #include "tnl/t_vb_rendertmp.h"
452
453
454
455
456 /**********************************************************************/
457 /* Choose render functions */
458 /**********************************************************************/
459 static void r300ChooseRenderState( GLcontext *ctx )
460 {
461 TNLcontext *tnl = TNL_CONTEXT(ctx);
462 r300ContextPtr rmesa = R300_CONTEXT(ctx);
463 GLuint index = 0;
464 GLuint flags = ctx->_TriangleCaps;
465
466 if (flags & DD_TRI_UNFILLED) index |= R300_UNFILLED_BIT;
467
468 if (index != rmesa->radeon.swtcl.RenderIndex) {
469 tnl->Driver.Render.Points = rast_tab[index].points;
470 tnl->Driver.Render.Line = rast_tab[index].line;
471 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
472 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
473 tnl->Driver.Render.Quad = rast_tab[index].quad;
474
475 if (index == 0) {
476 tnl->Driver.Render.PrimTabVerts = r300_render_tab_verts;
477 tnl->Driver.Render.PrimTabElts = r300_render_tab_elts;
478 tnl->Driver.Render.ClippedPolygon = r300_fast_clipped_poly;
479 } else {
480 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
481 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
482 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
483 }
484
485 rmesa->radeon.swtcl.RenderIndex = index;
486 }
487 }
488
489
490 void r300RenderStart(GLcontext *ctx)
491 {
492 r300ContextPtr rmesa = R300_CONTEXT( ctx );
493
494 r300ChooseRenderState(ctx);
495
496 r300UpdateShaders(rmesa);
497
498 r300PrepareVertices(ctx);
499
500 r300ValidateBuffers(ctx);
501
502 r300UpdateShaderStates(rmesa);
503
504 r300EmitCacheFlush(rmesa);
505
506 /* investigate if we can put back flush optimisation if needed */
507 if (rmesa->radeon.dma.flush != NULL) {
508 rmesa->radeon.dma.flush(ctx);
509 }
510 }
511
512 void r300RenderFinish(GLcontext *ctx)
513 {
514 }
515
516 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
517 {
518 r300ContextPtr rmesa = R300_CONTEXT(ctx);
519
520 if (rmesa->radeon.swtcl.hw_primitive != hwprim) {
521 R300_NEWPRIM( rmesa );
522 rmesa->radeon.swtcl.hw_primitive = hwprim;
523 }
524 }
525
526 void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
527 {
528
529 r300ContextPtr rmesa = R300_CONTEXT(ctx);
530 rmesa->radeon.swtcl.render_primitive = prim;
531
532 if ((prim == GL_TRIANGLES) && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
533 return;
534
535 r300RasterPrimitive( ctx, reduced_prim[prim] );
536 }
537
538 void r300ResetLineStipple(GLcontext *ctx)
539 {
540 }
541
542 void r300InitSwtcl(GLcontext *ctx)
543 {
544 TNLcontext *tnl = TNL_CONTEXT(ctx);
545 r300ContextPtr rmesa = R300_CONTEXT(ctx);
546 static int firsttime = 1;
547
548 if (firsttime) {
549 init_rast_tab();
550 firsttime = 0;
551 }
552
553 tnl->Driver.Render.Start = r300RenderStart;
554 tnl->Driver.Render.Finish = r300RenderFinish;
555 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
556 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
557 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
558 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
559 tnl->Driver.Render.Interp = _tnl_interp;
560
561 /* FIXME: what are these numbers? */
562 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
563 48 * sizeof(GLfloat) );
564
565 rmesa->radeon.swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
566 rmesa->radeon.swtcl.RenderIndex = ~0;
567 rmesa->radeon.swtcl.render_primitive = GL_TRIANGLES;
568 rmesa->radeon.swtcl.hw_primitive = 0;
569
570 _tnl_invalidate_vertex_state( ctx, ~0 );
571 _tnl_invalidate_vertices( ctx, ~0 );
572
573 _tnl_need_projected_coords( ctx, GL_FALSE );
574 }
575
576 void r300DestroySwtcl(GLcontext *ctx)
577 {
578 }
579
580 static void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, struct radeon_bo *bo, GLuint offset)
581 {
582 BATCH_LOCALS(&rmesa->radeon);
583
584 if (RADEON_DEBUG & DEBUG_VERTS)
585 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
586 __FUNCTION__, vertex_size, offset);
587
588 BEGIN_BATCH(7);
589 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2);
590 OUT_BATCH(1);
591 OUT_BATCH(vertex_size | (vertex_size << 8));
592 OUT_BATCH_RELOC(offset, bo, offset, RADEON_GEM_DOMAIN_GTT, 0, 0);
593 END_BATCH();
594 }
595
596 static void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
597 {
598 BATCH_LOCALS(&rmesa->radeon);
599 int type, num_verts;
600
601 type = r300PrimitiveType(rmesa, primitive);
602 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
603
604 BEGIN_BATCH(3);
605 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
606 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
607 END_BATCH();
608 }
609
610 void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
611 {
612 r300ContextPtr rmesa = R300_CONTEXT(ctx);
613
614 rcommonEnsureCmdBufSpace(&rmesa->radeon,
615 rmesa->radeon.hw.max_state_size + (12*sizeof(int)),
616 __FUNCTION__);
617 radeonEmitState(&rmesa->radeon);
618 r300_emit_scissor(ctx);
619 r300EmitVertexAOS(rmesa,
620 rmesa->radeon.swtcl.vertex_size,
621 first_elem(&rmesa->radeon.dma.reserved)->bo,
622 current_offset);
623
624 r300EmitVbufPrim(rmesa,
625 rmesa->radeon.swtcl.hw_primitive,
626 rmesa->radeon.swtcl.numverts);
627 r300EmitCacheFlush(rmesa);
628 COMMIT_BATCH();
629 }