Merge branch 'arb_map_buffer_range'
[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
43 #define EMIT_ATTR( ATTR, STYLE ) \
44 do { \
45 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
46 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
47 rmesa->radeon.swtcl.vertex_attr_count++; \
48 } while (0)
49
50 #define EMIT_PAD( N ) \
51 do { \
52 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
53 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
54 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
55 rmesa->radeon.swtcl.vertex_attr_count++; \
56 } while (0)
57
58 #define ADD_ATTR(_attr, _format, _dst_loc, _swizzle, _write_mask, _normalize) \
59 do { \
60 attrs[num_attrs].element = (_attr); \
61 attrs[num_attrs].data_type = (_format); \
62 attrs[num_attrs].dst_loc = (_dst_loc); \
63 attrs[num_attrs].swizzle = (_swizzle); \
64 attrs[num_attrs].write_mask = (_write_mask); \
65 attrs[num_attrs]._signed = 0; \
66 attrs[num_attrs].normalize = (_normalize); \
67 ++num_attrs; \
68 } while (0)
69
70 void r300ChooseSwtclVertexFormat(GLcontext *ctx, GLuint *_InputsRead, GLuint *_OutputsWritten)
71 {
72 r300ContextPtr rmesa = R300_CONTEXT( ctx );
73 TNLcontext *tnl = TNL_CONTEXT(ctx);
74 struct vertex_buffer *VB = &tnl->vb;
75 int first_free_tex = 0;
76 GLuint InputsRead = 0;
77 GLuint OutputsWritten = 0;
78 int num_attrs = 0;
79 GLuint fp_reads = ctx->FragmentProgram._Current->Base.InputsRead;
80 struct vertex_attribute *attrs = rmesa->vbuf.attribs;
81
82 rmesa->swtcl.coloroffset = rmesa->swtcl.specoffset = 0;
83 rmesa->radeon.swtcl.vertex_attr_count = 0;
84
85 /* We always want non Ndc coords format */
86 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
87
88 /* Always write position vector */
89 InputsRead |= 1 << VERT_ATTRIB_POS;
90 OutputsWritten |= 1 << VERT_RESULT_HPOS;
91 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F );
92 ADD_ATTR(VERT_ATTRIB_POS, R300_DATA_TYPE_FLOAT_4, SWTCL_OVM_POS, SWIZZLE_XYZW, MASK_XYZW, 0);
93 rmesa->swtcl.coloroffset = 4;
94
95 if (fp_reads & FRAG_BIT_COL0) {
96 InputsRead |= 1 << VERT_ATTRIB_COLOR0;
97 OutputsWritten |= 1 << VERT_RESULT_COL0;
98 #if MESA_LITTLE_ENDIAN
99 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_RGBA );
100 ADD_ATTR(VERT_ATTRIB_COLOR0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR0, SWIZZLE_XYZW, MASK_XYZW, 1);
101 #else
102 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_ABGR );
103 ADD_ATTR(VERT_ATTRIB_COLOR0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR0, SWIZZLE_XYZW, MASK_XYZW, 1);
104 #endif
105 }
106
107 if (fp_reads & FRAG_BIT_COL1) {
108 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
109 InputsRead |= 1 << VERT_ATTRIB_COLOR1;
110 OutputsWritten |= 1 << VERT_RESULT_COL1;
111 #if MESA_LITTLE_ENDIAN
112 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4UB_4F_RGBA );
113 ADD_ATTR(VERT_ATTRIB_COLOR1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR1, swiz, MASK_XYZW, 1);
114 #else
115 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4UB_4F_ABGR );
116 ADD_ATTR(VERT_ATTRIB_COLOR1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR1, swiz, MASK_XYZW, 1);
117 #endif
118 rmesa->swtcl.specoffset = rmesa->swtcl.coloroffset + 1;
119 }
120
121 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) {
122 VB->AttribPtr[VERT_ATTRIB_GENERIC0] = VB->ColorPtr[1];
123 OutputsWritten |= 1 << VERT_RESULT_BFC0;
124 #if MESA_LITTLE_ENDIAN
125 EMIT_ATTR( _TNL_ATTRIB_GENERIC0, EMIT_4UB_4F_RGBA );
126 ADD_ATTR(VERT_ATTRIB_GENERIC0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR2, SWIZZLE_XYZW, MASK_XYZW, 1);
127 #else
128 EMIT_ATTR( _TNL_ATTRIB_GENERIC0, EMIT_4UB_4F_ABGR );
129 ADD_ATTR(VERT_ATTRIB_GENERIC0, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR2, SWIZZLE_XYZW, MASK_XYZW, 1);
130 #endif
131 if (fp_reads & FRAG_BIT_COL1) {
132 VB->AttribPtr[VERT_ATTRIB_GENERIC1] = VB->SecondaryColorPtr[1];
133 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
134 OutputsWritten |= 1 << VERT_RESULT_BFC1;
135 #if MESA_LITTLE_ENDIAN
136 EMIT_ATTR( _TNL_ATTRIB_GENERIC1, EMIT_4UB_4F_RGBA );
137 ADD_ATTR(VERT_ATTRIB_GENERIC1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR3, swiz, MASK_XYZW, 1);
138 #else
139 EMIT_ATTR( _TNL_ATTRIB_GENERIC1, EMIT_4UB_4F_ABGR );
140 ADD_ATTR(VERT_ATTRIB_GENERIC1, R300_DATA_TYPE_BYTE, SWTCL_OVM_COLOR3, swiz, MASK_XYZW, 1);
141 #endif
142 }
143 }
144
145 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_POINTSIZE )) {
146 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO);
147 InputsRead |= 1 << VERT_ATTRIB_POINT_SIZE;
148 OutputsWritten |= 1 << VERT_RESULT_PSIZ;
149 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F );
150 ADD_ATTR(VERT_ATTRIB_POINT_SIZE, R300_DATA_TYPE_FLOAT_1, SWTCL_OVM_POINT_SIZE, swiz, MASK_X, 0);
151 }
152
153 /**
154 * Sending only one texcoord component may lead to lock up,
155 * so for all textures always output 4 texcoord components to RS.
156 */
157 {
158 int i;
159 GLuint swiz, format, hw_format;
160 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
161 if (fp_reads & FRAG_BIT_TEX(i)) {
162 switch (VB->TexCoordPtr[i]->size) {
163 case 1:
164 format = EMIT_1F;
165 hw_format = R300_DATA_TYPE_FLOAT_1;
166 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
167 break;
168 case 2:
169 format = EMIT_2F;
170 hw_format = R300_DATA_TYPE_FLOAT_2;
171 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
172 break;
173 case 3:
174 format = EMIT_3F;
175 hw_format = R300_DATA_TYPE_FLOAT_3;
176 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
177 break;
178 case 4:
179 format = EMIT_4F;
180 hw_format = R300_DATA_TYPE_FLOAT_4;
181 swiz = SWIZZLE_XYZW;
182 break;
183 default:
184 continue;
185 }
186 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i);
187 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i);
188 EMIT_ATTR(_TNL_ATTRIB_TEX(i), format);
189 ADD_ATTR(VERT_ATTRIB_TEX0 + i, hw_format, SWTCL_OVM_TEX(first_free_tex), swiz, MASK_XYZW, 0);
190 ++first_free_tex;
191 }
192 }
193 }
194
195 /* RS can't put fragment position on the pixel stack, so stuff it in texcoord if needed */
196 if (fp_reads & FRAG_BIT_WPOS) {
197 if (first_free_tex >= ctx->Const.MaxTextureUnits) {
198 fprintf(stderr, "\tout of free texcoords to write w pos\n");
199 _mesa_exit(-1);
200 }
201
202 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + first_free_tex);
203 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + first_free_tex);
204 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F );
205 ADD_ATTR(VERT_ATTRIB_POS, R300_DATA_TYPE_FLOAT_4, SWTCL_OVM_TEX(first_free_tex), SWIZZLE_XYZW, MASK_XYZW, 0);
206 ++first_free_tex;
207 }
208
209 if (fp_reads & FRAG_BIT_FOGC) {
210 if (first_free_tex >= ctx->Const.MaxTextureUnits) {
211 fprintf(stderr, "\tout of free texcoords to write fog coordinate\n");
212 _mesa_exit(-1);
213 }
214
215 InputsRead |= 1 << VERT_ATTRIB_FOG;
216 OutputsWritten |= 1 << VERT_RESULT_FOGC;
217 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO);
218 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F );
219 ADD_ATTR(VERT_ATTRIB_FOG, R300_DATA_TYPE_FLOAT_1, SWTCL_OVM_TEX(first_free_tex), swiz, MASK_XYZW, 0);
220 }
221
222 R300_NEWPRIM(rmesa);
223 rmesa->vbuf.num_attribs = num_attrs;
224 *_InputsRead = InputsRead;
225 *_OutputsWritten = OutputsWritten;
226
227 RENDERINPUTS_COPY(rmesa->render_inputs_bitset, tnl->render_inputs_bitset);
228 }
229
230 static void r300PrepareVertices(GLcontext *ctx)
231 {
232 r300ContextPtr rmesa = R300_CONTEXT(ctx);
233 GLuint InputsRead, OutputsWritten;
234
235 r300ChooseSwtclVertexFormat(ctx, &InputsRead, &OutputsWritten);
236 r300SetupVAP(ctx, InputsRead, OutputsWritten);
237
238 rmesa->radeon.swtcl.vertex_size =
239 _tnl_install_attrs( ctx,
240 rmesa->radeon.swtcl.vertex_attrs,
241 rmesa->radeon.swtcl.vertex_attr_count,
242 NULL, 0 );
243
244 rmesa->radeon.swtcl.vertex_size /= 4;
245 }
246
247
248 static GLuint reduced_prim[] = {
249 GL_POINTS,
250 GL_LINES,
251 GL_LINES,
252 GL_LINES,
253 GL_TRIANGLES,
254 GL_TRIANGLES,
255 GL_TRIANGLES,
256 GL_TRIANGLES,
257 GL_TRIANGLES,
258 GL_TRIANGLES,
259 };
260
261 static void r300RasterPrimitive( GLcontext *ctx, GLuint prim );
262
263 /***********************************************************************
264 * Emit primitives as inline vertices *
265 ***********************************************************************/
266
267
268 #define HAVE_POINTS 1
269 #define HAVE_LINES 1
270 #define HAVE_LINE_STRIPS 1
271 #define HAVE_TRIANGLES 1
272 #define HAVE_TRI_STRIPS 1
273 #define HAVE_TRI_STRIP_1 0
274 #define HAVE_TRI_FANS 1
275 #define HAVE_QUADS 0
276 #define HAVE_QUAD_STRIPS 0
277 #define HAVE_POLYGONS 1
278 #define HAVE_ELTS 1
279
280 #undef LOCAL_VARS
281 #undef ALLOC_VERTS
282 #define CTX_ARG r300ContextPtr rmesa
283 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
284 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
285 #define LOCAL_VARS \
286 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
287 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
288 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
289 #define VERTEX r300Vertex
290 #undef TAG
291 #define TAG(x) r300_##x
292 #include "tnl_dd/t_dd_triemit.h"
293
294
295
296 /***********************************************************************
297 * Macros for t_dd_tritmp.h to draw basic primitives *
298 ***********************************************************************/
299
300 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
301 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
302 #define LINE( a, b ) r300_line( rmesa, a, b )
303 #define POINT( a ) r300_point( rmesa, a )
304
305 /***********************************************************************
306 * Build render functions from dd templates *
307 ***********************************************************************/
308
309 #define R300_UNFILLED_BIT 0x01
310 #define R300_MAX_TRIFUNC 0x02
311
312 static struct {
313 tnl_points_func points;
314 tnl_line_func line;
315 tnl_triangle_func triangle;
316 tnl_quad_func quad;
317 } rast_tab[R300_MAX_TRIFUNC];
318
319 #define DO_FALLBACK 0
320 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
321 #define DO_TWOSIDE 0
322 #define DO_FLAT 0
323 #define DO_OFFSET 0
324 #define DO_TRI 1
325 #define DO_QUAD 1
326 #define DO_LINE 1
327 #define DO_POINTS 1
328 #define DO_FULL_QUAD 1
329
330 #define HAVE_RGBA 1
331 #define HAVE_SPEC 1
332 #define HAVE_BACK_COLORS 0
333 #define HAVE_HW_FLATSHADE 1
334 #define TAB rast_tab
335
336 #define DEPTH_SCALE 1.0
337 #define UNFILLED_TRI unfilled_tri
338 #define UNFILLED_QUAD unfilled_quad
339 #define VERT_X(_v) _v->v.x
340 #define VERT_Y(_v) _v->v.y
341 #define VERT_Z(_v) _v->v.z
342 #define AREA_IS_CCW( a ) (a < 0)
343 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
344
345 #define VERT_SET_RGBA( v, c ) \
346 do { \
347 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
348 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
349 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
350 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
351 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
352 } while (0)
353
354 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
355
356 #define VERT_SET_SPEC( v0, c ) \
357 do { \
358 if (specoffset) { \
359 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
360 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
361 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
362 } \
363 } while (0)
364
365 #define VERT_COPY_SPEC( v0, v1 ) \
366 do { \
367 if (specoffset) { \
368 v0->v.specular.red = v1->v.specular.red; \
369 v0->v.specular.green = v1->v.specular.green; \
370 v0->v.specular.blue = v1->v.specular.blue; \
371 } \
372 } while (0)
373
374 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
375 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
376 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
377 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
378
379 #undef LOCAL_VARS
380 #undef TAG
381 #undef INIT
382
383 #define LOCAL_VARS(n) \
384 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
385 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
386 GLuint coloroffset = rmesa->swtcl.coloroffset; \
387 GLuint specoffset = rmesa->swtcl.specoffset; \
388 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
389
390 /***********************************************************************
391 * Helpers for rendering unfilled primitives *
392 ***********************************************************************/
393
394 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
395 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
396 #undef TAG
397 #define TAG(x) x
398 #include "tnl_dd/t_dd_unfilled.h"
399 #undef IND
400
401
402 /***********************************************************************
403 * Generate GL render functions *
404 ***********************************************************************/
405
406
407 #define IND (0)
408 #define TAG(x) x
409 #include "tnl_dd/t_dd_tritmp.h"
410
411 #define IND (R300_UNFILLED_BIT)
412 #define TAG(x) x##_unfilled
413 #include "tnl_dd/t_dd_tritmp.h"
414
415
416 static void init_rast_tab( void )
417 {
418 init();
419 init_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_UNFILLED) index |= R300_UNFILLED_BIT;
472
473 if (index != rmesa->radeon.swtcl.RenderIndex) {
474 tnl->Driver.Render.Points = rast_tab[index].points;
475 tnl->Driver.Render.Line = rast_tab[index].line;
476 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
477 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
478 tnl->Driver.Render.Quad = rast_tab[index].quad;
479
480 if (index == 0) {
481 tnl->Driver.Render.PrimTabVerts = r300_render_tab_verts;
482 tnl->Driver.Render.PrimTabElts = r300_render_tab_elts;
483 tnl->Driver.Render.ClippedPolygon = r300_fast_clipped_poly;
484 } else {
485 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
486 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
487 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
488 }
489
490 rmesa->radeon.swtcl.RenderIndex = index;
491 }
492 }
493
494
495 void r300RenderStart(GLcontext *ctx)
496 {
497 r300ContextPtr rmesa = R300_CONTEXT( ctx );
498
499 r300ChooseRenderState(ctx);
500 r300PrepareVertices(ctx);
501
502 r300ValidateBuffers(ctx);
503
504 r300UpdateShaders(rmesa);
505 r300UpdateShaderStates(rmesa);
506
507 r300EmitCacheFlush(rmesa);
508
509 /* investigate if we can put back flush optimisation if needed */
510 if (rmesa->radeon.dma.flush != NULL) {
511 rmesa->radeon.dma.flush(ctx);
512 }
513 }
514
515 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 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 }
540
541 void r300ResetLineStipple(GLcontext *ctx)
542 {
543 }
544
545 void r300InitSwtcl(GLcontext *ctx)
546 {
547 TNLcontext *tnl = TNL_CONTEXT(ctx);
548 r300ContextPtr rmesa = R300_CONTEXT(ctx);
549 static int firsttime = 1;
550
551 if (firsttime) {
552 init_rast_tab();
553 firsttime = 0;
554 }
555
556 tnl->Driver.Render.Start = r300RenderStart;
557 tnl->Driver.Render.Finish = r300RenderFinish;
558 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
559 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
560 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
561 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
562 tnl->Driver.Render.Interp = _tnl_interp;
563
564 /* FIXME: what are these numbers? */
565 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
566 48 * sizeof(GLfloat) );
567
568 rmesa->radeon.swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
569 rmesa->radeon.swtcl.RenderIndex = ~0;
570 rmesa->radeon.swtcl.render_primitive = GL_TRIANGLES;
571 rmesa->radeon.swtcl.hw_primitive = 0;
572
573 _tnl_invalidate_vertex_state( ctx, ~0 );
574 _tnl_invalidate_vertices( ctx, ~0 );
575
576 _tnl_need_projected_coords( ctx, GL_FALSE );
577 }
578
579 void r300DestroySwtcl(GLcontext *ctx)
580 {
581 }
582
583 static void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, struct radeon_bo *bo, GLuint offset)
584 {
585 BATCH_LOCALS(&rmesa->radeon);
586
587 if (RADEON_DEBUG & DEBUG_VERTS)
588 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
589 __FUNCTION__, vertex_size, offset);
590
591 BEGIN_BATCH(7);
592 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2);
593 OUT_BATCH(1);
594 OUT_BATCH(vertex_size | (vertex_size << 8));
595 OUT_BATCH_RELOC(offset, bo, offset, RADEON_GEM_DOMAIN_GTT, 0, 0);
596 END_BATCH();
597 }
598
599 static void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
600 {
601 BATCH_LOCALS(&rmesa->radeon);
602 int type, num_verts;
603
604 type = r300PrimitiveType(rmesa, primitive);
605 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
606
607 BEGIN_BATCH(3);
608 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
609 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
610 END_BATCH();
611 }
612
613 void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
614 {
615 r300ContextPtr rmesa = R300_CONTEXT(ctx);
616
617 rcommonEnsureCmdBufSpace(&rmesa->radeon,
618 rmesa->radeon.hw.max_state_size + (12*sizeof(int)),
619 __FUNCTION__);
620 radeonEmitState(&rmesa->radeon);
621 r300_emit_scissor(ctx);
622 r300EmitVertexAOS(rmesa,
623 rmesa->radeon.swtcl.vertex_size,
624 rmesa->radeon.dma.current,
625 current_offset);
626
627 r300EmitVbufPrim(rmesa,
628 rmesa->radeon.swtcl.hw_primitive,
629 rmesa->radeon.swtcl.numverts);
630 r300EmitCacheFlush(rmesa);
631 COMMIT_BATCH();
632 }