r300/fragprog: Move wpos_attr and fog_attr where they belong
[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 = rmesa->selected_fp->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 if (rmesa->selected_fp->wpos_attr != FRAG_ATTRIB_MAX) {
154 int tex_id = rmesa->selected_fp->wpos_attr - FRAG_ATTRIB_TEX0;
155
156 VB->AttribPtr[VERT_ATTRIB_TEX0 + tex_id] = VB->AttribPtr[VERT_ATTRIB_POS];
157 VB->TexCoordPtr[tex_id] = VB->AttribPtr[VERT_ATTRIB_POS];
158 RENDERINPUTS_SET(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX0 + tex_id);
159 }
160
161 if (rmesa->selected_fp->fog_attr != FRAG_ATTRIB_MAX) {
162 int tex_id = rmesa->selected_fp->fog_attr - FRAG_ATTRIB_TEX0;
163
164 VB->AttribPtr[VERT_ATTRIB_TEX0 + tex_id] = VB->AttribPtr[VERT_ATTRIB_FOG];
165 VB->TexCoordPtr[tex_id] = VB->AttribPtr[VERT_ATTRIB_FOG];
166 RENDERINPUTS_SET(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX0 + tex_id);
167 }
168
169 /**
170 * Sending only one texcoord component may lead to lock up,
171 * so for all textures always output 4 texcoord components to RS.
172 */
173 {
174 int i;
175 GLuint swiz, format, hw_format;
176 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
177 if (fp_reads & FRAG_BIT_TEX(i)) {
178 switch (VB->TexCoordPtr[i]->size) {
179 case 1:
180 format = EMIT_1F;
181 hw_format = R300_DATA_TYPE_FLOAT_1;
182 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
183 break;
184 case 2:
185 format = EMIT_2F;
186 hw_format = R300_DATA_TYPE_FLOAT_2;
187 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
188 break;
189 case 3:
190 format = EMIT_3F;
191 hw_format = R300_DATA_TYPE_FLOAT_3;
192 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
193 break;
194 case 4:
195 format = EMIT_4F;
196 hw_format = R300_DATA_TYPE_FLOAT_4;
197 swiz = SWIZZLE_XYZW;
198 break;
199 default:
200 continue;
201 }
202 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i);
203 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i);
204 EMIT_ATTR(_TNL_ATTRIB_TEX(i), format);
205 ADD_ATTR(VERT_ATTRIB_TEX0 + i, hw_format, SWTCL_OVM_TEX(first_free_tex), swiz, MASK_XYZW, 0);
206 ++first_free_tex;
207 }
208 }
209 }
210
211 if (first_free_tex >= ctx->Const.MaxTextureUnits) {
212 fprintf(stderr, "\tout of free texcoords to write fog coordinate\n");
213 _mesa_exit(-1);
214 }
215
216 R300_NEWPRIM(rmesa);
217 rmesa->vbuf.num_attribs = num_attrs;
218 *_InputsRead = InputsRead;
219 *_OutputsWritten = OutputsWritten;
220
221 RENDERINPUTS_COPY(rmesa->render_inputs_bitset, tnl->render_inputs_bitset);
222 }
223
224 static void r300PrepareVertices(GLcontext *ctx)
225 {
226 r300ContextPtr rmesa = R300_CONTEXT(ctx);
227 GLuint InputsRead, OutputsWritten;
228
229 r300ChooseSwtclVertexFormat(ctx, &InputsRead, &OutputsWritten);
230 r300SetupVAP(ctx, InputsRead, OutputsWritten);
231
232 rmesa->radeon.swtcl.vertex_size =
233 _tnl_install_attrs( ctx,
234 rmesa->radeon.swtcl.vertex_attrs,
235 rmesa->radeon.swtcl.vertex_attr_count,
236 NULL, 0 );
237
238 rmesa->radeon.swtcl.vertex_size /= 4;
239 }
240
241
242 static GLuint reduced_prim[] = {
243 GL_POINTS,
244 GL_LINES,
245 GL_LINES,
246 GL_LINES,
247 GL_TRIANGLES,
248 GL_TRIANGLES,
249 GL_TRIANGLES,
250 GL_TRIANGLES,
251 GL_TRIANGLES,
252 GL_TRIANGLES,
253 };
254
255 static void r300RasterPrimitive( GLcontext *ctx, GLuint prim );
256
257 /***********************************************************************
258 * Emit primitives as inline vertices *
259 ***********************************************************************/
260
261
262 #define HAVE_POINTS 1
263 #define HAVE_LINES 1
264 #define HAVE_LINE_STRIPS 1
265 #define HAVE_TRIANGLES 1
266 #define HAVE_TRI_STRIPS 1
267 #define HAVE_TRI_STRIP_1 0
268 #define HAVE_TRI_FANS 1
269 #define HAVE_QUADS 0
270 #define HAVE_QUAD_STRIPS 0
271 #define HAVE_POLYGONS 1
272 #define HAVE_ELTS 1
273
274 #undef LOCAL_VARS
275 #undef ALLOC_VERTS
276 #define CTX_ARG r300ContextPtr rmesa
277 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
278 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
279 #define LOCAL_VARS \
280 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
281 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
282 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
283 #define VERTEX r300Vertex
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_UNFILLED_BIT 0x01
304 #define R300_MAX_TRIFUNC 0x02
305
306 static struct {
307 tnl_points_func points;
308 tnl_line_func line;
309 tnl_triangle_func triangle;
310 tnl_quad_func quad;
311 } rast_tab[R300_MAX_TRIFUNC];
312
313 #define DO_FALLBACK 0
314 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
315 #define DO_TWOSIDE 0
316 #define DO_FLAT 0
317 #define DO_OFFSET 0
318 #define DO_TRI 1
319 #define DO_QUAD 1
320 #define DO_LINE 1
321 #define DO_POINTS 1
322 #define DO_FULL_QUAD 1
323
324 #define HAVE_RGBA 1
325 #define HAVE_SPEC 1
326 #define HAVE_BACK_COLORS 0
327 #define HAVE_HW_FLATSHADE 1
328 #define TAB rast_tab
329
330 #define DEPTH_SCALE 1.0
331 #define UNFILLED_TRI unfilled_tri
332 #define UNFILLED_QUAD unfilled_quad
333 #define VERT_X(_v) _v->v.x
334 #define VERT_Y(_v) _v->v.y
335 #define VERT_Z(_v) _v->v.z
336 #define AREA_IS_CCW( a ) (a < 0)
337 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
338
339 #define VERT_SET_RGBA( v, c ) \
340 do { \
341 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
342 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
343 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
344 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
345 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
346 } while (0)
347
348 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
349
350 #define VERT_SET_SPEC( v0, c ) \
351 do { \
352 if (specoffset) { \
353 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
354 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
355 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
356 } \
357 } while (0)
358
359 #define VERT_COPY_SPEC( v0, v1 ) \
360 do { \
361 if (specoffset) { \
362 v0->v.specular.red = v1->v.specular.red; \
363 v0->v.specular.green = v1->v.specular.green; \
364 v0->v.specular.blue = v1->v.specular.blue; \
365 } \
366 } while (0)
367
368 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
369 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
370 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
371 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
372
373 #undef LOCAL_VARS
374 #undef TAG
375 #undef INIT
376
377 #define LOCAL_VARS(n) \
378 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
379 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
380 GLuint coloroffset = rmesa->swtcl.coloroffset; \
381 GLuint specoffset = rmesa->swtcl.specoffset; \
382 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
383
384 /***********************************************************************
385 * Helpers for rendering unfilled primitives *
386 ***********************************************************************/
387
388 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
389 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
390 #undef TAG
391 #define TAG(x) x
392 #include "tnl_dd/t_dd_unfilled.h"
393 #undef IND
394
395
396 /***********************************************************************
397 * Generate GL render functions *
398 ***********************************************************************/
399
400
401 #define IND (0)
402 #define TAG(x) x
403 #include "tnl_dd/t_dd_tritmp.h"
404
405 #define IND (R300_UNFILLED_BIT)
406 #define TAG(x) x##_unfilled
407 #include "tnl_dd/t_dd_tritmp.h"
408
409
410 static void init_rast_tab( void )
411 {
412 init();
413 init_unfilled();
414 }
415
416 /**********************************************************************/
417 /* Render unclipped begin/end objects */
418 /**********************************************************************/
419
420 #define RENDER_POINTS( start, count ) \
421 for ( ; start < count ; start++) \
422 r300_point( rmesa, VERT(start) )
423 #define RENDER_LINE( v0, v1 ) \
424 r300_line( rmesa, VERT(v0), VERT(v1) )
425 #define RENDER_TRI( v0, v1, v2 ) \
426 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
427 #define RENDER_QUAD( v0, v1, v2, v3 ) \
428 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
429 #define INIT(x) do { \
430 r300RenderPrimitive( ctx, x ); \
431 } while (0)
432 #undef LOCAL_VARS
433 #define LOCAL_VARS \
434 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
435 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
436 const char *r300verts = (char *)rmesa->radeon.swtcl.verts; \
437 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
438 const GLboolean stipple = ctx->Line.StippleFlag; \
439 (void) elt; (void) stipple;
440 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
441 #define RESET_OCCLUSION
442 #define PRESERVE_VB_DEFS
443 #define ELT(x) (x)
444 #define TAG(x) r300_##x##_verts
445 #include "tnl/t_vb_rendertmp.h"
446 #undef ELT
447 #undef TAG
448 #define TAG(x) r300_##x##_elts
449 #define ELT(x) elt[x]
450 #include "tnl/t_vb_rendertmp.h"
451
452
453
454
455 /**********************************************************************/
456 /* Choose render functions */
457 /**********************************************************************/
458 static void r300ChooseRenderState( GLcontext *ctx )
459 {
460 TNLcontext *tnl = TNL_CONTEXT(ctx);
461 r300ContextPtr rmesa = R300_CONTEXT(ctx);
462 GLuint index = 0;
463 GLuint flags = ctx->_TriangleCaps;
464
465 if (flags & DD_TRI_UNFILLED) index |= R300_UNFILLED_BIT;
466
467 if (index != rmesa->radeon.swtcl.RenderIndex) {
468 tnl->Driver.Render.Points = rast_tab[index].points;
469 tnl->Driver.Render.Line = rast_tab[index].line;
470 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
471 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
472 tnl->Driver.Render.Quad = rast_tab[index].quad;
473
474 if (index == 0) {
475 tnl->Driver.Render.PrimTabVerts = r300_render_tab_verts;
476 tnl->Driver.Render.PrimTabElts = r300_render_tab_elts;
477 tnl->Driver.Render.ClippedPolygon = r300_fast_clipped_poly;
478 } else {
479 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
480 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
481 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
482 }
483
484 rmesa->radeon.swtcl.RenderIndex = index;
485 }
486 }
487
488
489 void r300RenderStart(GLcontext *ctx)
490 {
491 r300ContextPtr rmesa = R300_CONTEXT( ctx );
492
493 r300ChooseRenderState(ctx);
494
495 r300UpdateShaders(rmesa);
496
497 r300PrepareVertices(ctx);
498
499 r300ValidateBuffers(ctx);
500
501 r300UpdateShaderStates(rmesa);
502
503 r300EmitCacheFlush(rmesa);
504
505 /* investigate if we can put back flush optimisation if needed */
506 if (rmesa->radeon.dma.flush != NULL) {
507 rmesa->radeon.dma.flush(ctx);
508 }
509 }
510
511 void r300RenderFinish(GLcontext *ctx)
512 {
513 }
514
515 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
516 {
517 r300ContextPtr rmesa = R300_CONTEXT(ctx);
518
519 if (rmesa->radeon.swtcl.hw_primitive != hwprim) {
520 R300_NEWPRIM( rmesa );
521 rmesa->radeon.swtcl.hw_primitive = hwprim;
522 }
523 }
524
525 void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
526 {
527
528 r300ContextPtr rmesa = R300_CONTEXT(ctx);
529 rmesa->radeon.swtcl.render_primitive = prim;
530
531 if ((prim == GL_TRIANGLES) && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
532 return;
533
534 r300RasterPrimitive( ctx, reduced_prim[prim] );
535 }
536
537 void r300ResetLineStipple(GLcontext *ctx)
538 {
539 }
540
541 void r300InitSwtcl(GLcontext *ctx)
542 {
543 TNLcontext *tnl = TNL_CONTEXT(ctx);
544 r300ContextPtr rmesa = R300_CONTEXT(ctx);
545 static int firsttime = 1;
546
547 if (firsttime) {
548 init_rast_tab();
549 firsttime = 0;
550 }
551
552 tnl->Driver.Render.Start = r300RenderStart;
553 tnl->Driver.Render.Finish = r300RenderFinish;
554 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
555 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
556 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
557 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
558 tnl->Driver.Render.Interp = _tnl_interp;
559
560 /* FIXME: what are these numbers? */
561 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
562 48 * sizeof(GLfloat) );
563
564 rmesa->radeon.swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
565 rmesa->radeon.swtcl.RenderIndex = ~0;
566 rmesa->radeon.swtcl.render_primitive = GL_TRIANGLES;
567 rmesa->radeon.swtcl.hw_primitive = 0;
568
569 _tnl_invalidate_vertex_state( ctx, ~0 );
570 _tnl_invalidate_vertices( ctx, ~0 );
571
572 _tnl_need_projected_coords( ctx, GL_FALSE );
573 }
574
575 void r300DestroySwtcl(GLcontext *ctx)
576 {
577 }
578
579 static void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, struct radeon_bo *bo, GLuint offset)
580 {
581 BATCH_LOCALS(&rmesa->radeon);
582
583 if (RADEON_DEBUG & DEBUG_VERTS)
584 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
585 __FUNCTION__, vertex_size, offset);
586
587 BEGIN_BATCH(7);
588 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2);
589 OUT_BATCH(1);
590 OUT_BATCH(vertex_size | (vertex_size << 8));
591 OUT_BATCH_RELOC(offset, bo, offset, RADEON_GEM_DOMAIN_GTT, 0, 0);
592 END_BATCH();
593 }
594
595 static void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
596 {
597 BATCH_LOCALS(&rmesa->radeon);
598 int type, num_verts;
599
600 type = r300PrimitiveType(rmesa, primitive);
601 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
602
603 BEGIN_BATCH(3);
604 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
605 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
606 END_BATCH();
607 }
608
609 void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
610 {
611 r300ContextPtr rmesa = R300_CONTEXT(ctx);
612
613 rcommonEnsureCmdBufSpace(&rmesa->radeon,
614 rmesa->radeon.hw.max_state_size + (12*sizeof(int)),
615 __FUNCTION__);
616 radeonEmitState(&rmesa->radeon);
617 r300_emit_scissor(ctx);
618 r300EmitVertexAOS(rmesa,
619 rmesa->radeon.swtcl.vertex_size,
620 rmesa->radeon.dma.current,
621 current_offset);
622
623 r300EmitVbufPrim(rmesa,
624 rmesa->radeon.swtcl.hw_primitive,
625 rmesa->radeon.swtcl.numverts);
626 r300EmitCacheFlush(rmesa);
627 COMMIT_BATCH();
628 }