d8a68f7fc5ec40fc1775c6126a2d792ca6e4abca
[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_swtcl.h"
38 #include "r300_emit.h"
39 #include "r300_tex.h"
40
41 #define EMIT_ATTR( ATTR, STYLE ) \
42 do { \
43 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = (ATTR); \
44 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = (STYLE); \
45 rmesa->radeon.swtcl.vertex_attr_count++; \
46 } while (0)
47
48 #define EMIT_PAD( N ) \
49 do { \
50 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].attrib = 0; \
51 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].format = EMIT_PAD; \
52 rmesa->radeon.swtcl.vertex_attrs[rmesa->radeon.swtcl.vertex_attr_count].offset = (N); \
53 rmesa->radeon.swtcl.vertex_attr_count++; \
54 } while (0)
55
56 #define ADD_ATTR(_attr, _format, _dst_loc, _swizzle, _write_mask) \
57 do { \
58 attrs[num_attrs].attr = (_attr); \
59 attrs[num_attrs].format = (_format); \
60 attrs[num_attrs].dst_loc = (_dst_loc); \
61 attrs[num_attrs].swizzle = (_swizzle); \
62 attrs[num_attrs].write_mask = (_write_mask); \
63 ++num_attrs; \
64 } while (0)
65
66 static void r300SwtclVAPSetup(GLcontext *ctx, GLuint InputsRead, GLuint OutputsWritten)
67 {
68 r300ContextPtr rmesa = R300_CONTEXT( ctx );
69 TNLcontext *tnl = TNL_CONTEXT(ctx);
70 struct vertex_buffer *VB = &tnl->vb;
71 struct vertex_attribute *attrs = rmesa->swtcl.vert_attrs;
72 int vte = 0;
73 int i, j, reg_count;
74 uint32_t *vir0 = &rmesa->hw.vir[0].cmd[1];
75 uint32_t *vir1 = &rmesa->hw.vir[1].cmd[1];
76
77 for (i = 0; i < R300_VIR_CMDSIZE-1; ++i)
78 vir0[i] = vir1[i] = 0;
79
80 for (i = 0, j = 0; i < rmesa->radeon.swtcl.vertex_attr_count; ++i) {
81 int tmp, data_format;
82 switch (attrs[i].format) {
83 case EMIT_1F:
84 data_format = R300_DATA_TYPE_FLOAT_1;
85 break;
86 case EMIT_2F:
87 data_format = R300_DATA_TYPE_FLOAT_2;
88 break;
89 case EMIT_3F:
90 data_format = R300_DATA_TYPE_FLOAT_3;
91 break;
92 case EMIT_4F:
93 data_format = R300_DATA_TYPE_FLOAT_4;
94 break;
95 case EMIT_4UB_4F_RGBA:
96 case EMIT_4UB_4F_ABGR:
97 data_format = R300_DATA_TYPE_BYTE | R300_NORMALIZE;
98 break;
99 default:
100 fprintf(stderr, "%s: Invalid data format type", __FUNCTION__);
101 _mesa_exit(-1);
102 break;
103 }
104
105 tmp = data_format | (attrs[i].dst_loc << R300_DST_VEC_LOC_SHIFT);
106 if (i % 2 == 0) {
107 vir0[j] = tmp << R300_DATA_TYPE_0_SHIFT;
108 vir1[j] = attrs[i].swizzle | (attrs[i].write_mask << R300_WRITE_ENA_SHIFT);
109 } else {
110 vir0[j] |= tmp << R300_DATA_TYPE_1_SHIFT;
111 vir1[j] |= (attrs[i].swizzle | (attrs[i].write_mask << R300_WRITE_ENA_SHIFT)) << R300_SWIZZLE1_SHIFT;
112 ++j;
113 }
114 }
115
116 reg_count = (rmesa->radeon.swtcl.vertex_attr_count + 1) >> 1;
117 if (rmesa->radeon.swtcl.vertex_attr_count % 2 != 0) {
118 vir0[reg_count-1] |= R300_LAST_VEC << R300_DATA_TYPE_0_SHIFT;
119 } else {
120 vir0[reg_count-1] |= R300_LAST_VEC << R300_DATA_TYPE_1_SHIFT;
121 }
122
123 R300_STATECHANGE(rmesa, vir[0]);
124 R300_STATECHANGE(rmesa, vir[1]);
125 R300_STATECHANGE(rmesa, vof);
126 R300_STATECHANGE(rmesa, vte);
127 R300_STATECHANGE(rmesa, vic);
128
129 if (rmesa->radeon.radeonScreen->kernel_mm) {
130 rmesa->hw.vir[0].cmd[0] &= 0xC000FFFF;
131 rmesa->hw.vir[1].cmd[0] &= 0xC000FFFF;
132 rmesa->hw.vir[0].cmd[0] |= (reg_count & 0x3FFF) << 16;
133 rmesa->hw.vir[1].cmd[0] |= (reg_count & 0x3FFF) << 16;
134 } else {
135 ((drm_r300_cmd_header_t *) rmesa->hw.vir[0].cmd)->packet0.count = reg_count;
136 ((drm_r300_cmd_header_t *) rmesa->hw.vir[1].cmd)->packet0.count = reg_count;
137 }
138
139 rmesa->hw.vic.cmd[R300_VIC_CNTL_0] = r300VAPInputCntl0(ctx, InputsRead);
140 rmesa->hw.vic.cmd[R300_VIC_CNTL_1] = r300VAPInputCntl1(ctx, InputsRead);
141 rmesa->hw.vof.cmd[R300_VOF_CNTL_0] = r300VAPOutputCntl0(ctx, OutputsWritten);
142 rmesa->hw.vof.cmd[R300_VOF_CNTL_1] = r300VAPOutputCntl1(ctx, OutputsWritten);
143
144 vte = rmesa->hw.vte.cmd[1];
145 vte &= ~(R300_VTX_XY_FMT | R300_VTX_Z_FMT | R300_VTX_W0_FMT);
146 /* Important:
147 */
148 if ( VB->NdcPtr != NULL ) {
149 VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
150 vte |= R300_VTX_XY_FMT | R300_VTX_Z_FMT;
151 }
152 else {
153 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
154 vte |= R300_VTX_W0_FMT;
155 }
156
157 assert( VB->AttribPtr[VERT_ATTRIB_POS] != NULL );
158
159 rmesa->hw.vte.cmd[1] = vte;
160 rmesa->hw.vte.cmd[2] = rmesa->radeon.swtcl.vertex_size;
161 }
162
163
164 static void r300SetVertexFormat( GLcontext *ctx )
165 {
166 r300ContextPtr rmesa = R300_CONTEXT( ctx );
167 TNLcontext *tnl = TNL_CONTEXT(ctx);
168 struct vertex_buffer *VB = &tnl->vb;
169 int fog_id = -1;
170 GLuint InputsRead = 0;
171 GLuint OutputsWritten = 0;
172 int num_attrs = 0;
173 struct vertex_attribute *attrs = rmesa->swtcl.vert_attrs;
174
175 rmesa->swtcl.coloroffset = rmesa->swtcl.specoffset = 0;
176 rmesa->radeon.swtcl.vertex_attr_count = 0;
177
178 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_POS)) {
179 InputsRead |= 1 << VERT_ATTRIB_POS;
180 OutputsWritten |= 1 << VERT_RESULT_HPOS;
181 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F );
182 ADD_ATTR(VERT_ATTRIB_POS, EMIT_4F, SWTCL_OVM_POS, SWIZZLE_XYZW, MASK_XYZW);
183 rmesa->swtcl.coloroffset = 4;
184 }
185
186 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR0)) {
187 InputsRead |= 1 << VERT_ATTRIB_COLOR0;
188 OutputsWritten |= 1 << VERT_RESULT_COL0;
189 #if MESA_LITTLE_ENDIAN
190 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_RGBA );
191 ADD_ATTR(VERT_ATTRIB_COLOR0, EMIT_4UB_4F_RGBA, SWTCL_OVM_COLOR0, SWIZZLE_XYZW, MASK_XYZW);
192 #else
193 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_ABGR );
194 ADD_ATTR(VERT_ATTRIB_COLOR0, EMIT_4UB_4F_ABGR, SWTCL_OVM_COLOR0, SWIZZLE_XYZW, MASK_XYZW);
195 #endif
196 }
197
198 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR1 )) {
199 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
200 InputsRead |= 1 << VERT_ATTRIB_COLOR1;
201 OutputsWritten |= 1 << VERT_RESULT_COL1;
202 #if MESA_LITTLE_ENDIAN
203 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4UB_4F_RGBA );
204 ADD_ATTR(VERT_ATTRIB_COLOR1, EMIT_4UB_4F_RGBA, SWTCL_OVM_COLOR1, swiz, MASK_XYZW);
205 #else
206 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4UB_4F_ABGR );
207 ADD_ATTR(VERT_ATTRIB_COLOR1, EMIT_4UB_4F_ABGR, SWTCL_OVM_COLOR1, swiz, MASK_XYZW);
208 #endif
209 rmesa->swtcl.specoffset = rmesa->swtcl.coloroffset + 1;
210 }
211
212 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_POINTSIZE )) {
213 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO);
214 InputsRead |= 1 << VERT_ATTRIB_POINT_SIZE;
215 OutputsWritten |= 1 << VERT_RESULT_PSIZ;
216 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F );
217 ADD_ATTR(VERT_ATTRIB_POINT_SIZE, EMIT_1F, SWTCL_OVM_POINT_SIZE, swiz, MASK_X);
218 }
219
220 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_FOG)) {
221 /* find first free tex coord slot */
222 if (RENDERINPUTS_TEST_RANGE(tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
223 int i;
224 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
225 if (!RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX(i) )) {
226 fog_id = i;
227 break;
228 }
229 }
230 } else {
231 fog_id = 0;
232 }
233
234 if (fog_id == -1) {
235 fprintf(stderr, "\tout of free texcoords to do fog\n");
236 _mesa_exit(-1);
237 }
238
239 InputsRead |= 1 << VERT_ATTRIB_FOG;
240 OutputsWritten |= 1 << VERT_RESULT_FOGC;
241 GLuint swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO);
242 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F );
243 ADD_ATTR(VERT_ATTRIB_FOG, EMIT_1F, SWTCL_OVM_TEX(fog_id), swiz, MASK_X);
244 }
245
246 if (RENDERINPUTS_TEST_RANGE(tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
247 int i;
248 GLuint swiz, mask, format;
249 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
250 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX(i) )) {
251 switch (VB->TexCoordPtr[i]->size) {
252 case 1:
253 case 2:
254 format = EMIT_2F;
255 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ZERO);
256 mask = MASK_X | MASK_Y;
257 break;
258 case 3:
259 format = EMIT_3F;
260 swiz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
261 mask = MASK_X | MASK_Y | MASK_Z;
262 break;
263 case 4:
264 format = EMIT_4F;
265 swiz = SWIZZLE_XYZW;
266 mask = MASK_XYZW;
267 break;
268 default:
269 continue;
270 }
271 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i);
272 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i);
273 EMIT_ATTR(_TNL_ATTRIB_TEX(i), format);
274 ADD_ATTR(VERT_ATTRIB_TEX0 + i, format, SWTCL_OVM_TEX(i), swiz, mask);
275 }
276 }
277 }
278
279 /* RS can't put fragment position on the pixel stack, so stuff it in texcoord if needed */
280 if (RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_POS) && (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_WPOS)) {
281 int first_free_tex = -1;
282 if (fog_id >= 0) {
283 first_free_tex = fog_id+1;
284 } else {
285 if (RENDERINPUTS_TEST_RANGE(tnl->render_inputs_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
286 int i;
287 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
288 if (!RENDERINPUTS_TEST(tnl->render_inputs_bitset, _TNL_ATTRIB_TEX(i) )) {
289 first_free_tex = i;
290 break;
291 }
292 }
293 } else {
294 first_free_tex = 0;
295 }
296 }
297
298 if (first_free_tex == -1) {
299 fprintf(stderr, "\tout of free texcoords to write w pos\n");
300 _mesa_exit(-1);
301 }
302
303 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + first_free_tex);
304 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + first_free_tex);
305 EMIT_ATTR( _TNL_ATTRIB_TEX(first_free_tex), EMIT_4F );
306 ADD_ATTR(VERT_ATTRIB_TEX0 + first_free_tex, EMIT_4F, SWTCL_OVM_TEX(first_free_tex), SWIZZLE_XYZW, MASK_XYZW);
307 }
308
309 R300_NEWPRIM(rmesa);
310 r300SwtclVAPSetup(ctx, InputsRead, OutputsWritten);
311
312 rmesa->radeon.swtcl.vertex_size =
313 _tnl_install_attrs( ctx,
314 rmesa->radeon.swtcl.vertex_attrs,
315 rmesa->radeon.swtcl.vertex_attr_count,
316 NULL, 0 );
317
318 rmesa->radeon.swtcl.vertex_size /= 4;
319
320 RENDERINPUTS_COPY(rmesa->state.render_inputs_bitset, tnl->render_inputs_bitset);
321 }
322
323
324 static GLuint reduced_prim[] = {
325 GL_POINTS,
326 GL_LINES,
327 GL_LINES,
328 GL_LINES,
329 GL_TRIANGLES,
330 GL_TRIANGLES,
331 GL_TRIANGLES,
332 GL_TRIANGLES,
333 GL_TRIANGLES,
334 GL_TRIANGLES,
335 };
336
337 static void r300RasterPrimitive( GLcontext *ctx, GLuint prim );
338 static void r300RenderPrimitive( GLcontext *ctx, GLenum prim );
339
340 /***********************************************************************
341 * Emit primitives as inline vertices *
342 ***********************************************************************/
343
344
345 #define HAVE_POINTS 1
346 #define HAVE_LINES 1
347 #define HAVE_LINE_STRIPS 1
348 #define HAVE_TRIANGLES 1
349 #define HAVE_TRI_STRIPS 1
350 #define HAVE_TRI_STRIP_1 0
351 #define HAVE_TRI_FANS 1
352 #define HAVE_QUADS 0
353 #define HAVE_QUAD_STRIPS 0
354 #define HAVE_POLYGONS 1
355 #define HAVE_ELTS 1
356
357 #undef LOCAL_VARS
358 #undef ALLOC_VERTS
359 #define CTX_ARG r300ContextPtr rmesa
360 #define GET_VERTEX_DWORDS() rmesa->radeon.swtcl.vertex_size
361 #define ALLOC_VERTS( n, size ) rcommonAllocDmaLowVerts( &rmesa->radeon, n, size * 4 )
362 #define LOCAL_VARS \
363 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
364 const char *r300verts = (char *)rmesa->radeon.swtcl.verts;
365 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
366 #define VERTEX r300Vertex
367 #undef TAG
368 #define TAG(x) r300_##x
369 #include "tnl_dd/t_dd_triemit.h"
370
371
372
373 /***********************************************************************
374 * Macros for t_dd_tritmp.h to draw basic primitives *
375 ***********************************************************************/
376
377 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
378 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
379 #define LINE( a, b ) r300_line( rmesa, a, b )
380 #define POINT( a ) r300_point( rmesa, a )
381
382 /***********************************************************************
383 * Build render functions from dd templates *
384 ***********************************************************************/
385
386 #define R300_TWOSIDE_BIT 0x01
387 #define R300_UNFILLED_BIT 0x02
388 #define R300_MAX_TRIFUNC 0x04
389
390 static struct {
391 tnl_points_func points;
392 tnl_line_func line;
393 tnl_triangle_func triangle;
394 tnl_quad_func quad;
395 } rast_tab[R300_MAX_TRIFUNC];
396
397 #define DO_FALLBACK 0
398 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
399 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
400 #define DO_FLAT 0
401 #define DO_OFFSET 0
402 #define DO_TRI 1
403 #define DO_QUAD 1
404 #define DO_LINE 1
405 #define DO_POINTS 1
406 #define DO_FULL_QUAD 1
407
408 #define HAVE_RGBA 1
409 #define HAVE_SPEC 1
410 #define HAVE_BACK_COLORS 0
411 #define HAVE_HW_FLATSHADE 1
412 #define TAB rast_tab
413
414 #define DEPTH_SCALE 1.0
415 #define UNFILLED_TRI unfilled_tri
416 #define UNFILLED_QUAD unfilled_quad
417 #define VERT_X(_v) _v->v.x
418 #define VERT_Y(_v) _v->v.y
419 #define VERT_Z(_v) _v->v.z
420 #define AREA_IS_CCW( a ) (a < 0)
421 #define GET_VERTEX(e) (rmesa->radeon.swtcl.verts + (e*rmesa->radeon.swtcl.vertex_size*sizeof(int)))
422
423 #define VERT_SET_RGBA( v, c ) \
424 do { \
425 r300_color_t *color = (r300_color_t *)&((v)->ui[coloroffset]); \
426 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
427 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
428 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
429 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
430 } while (0)
431
432 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
433
434 #define VERT_SET_SPEC( v0, c ) \
435 do { \
436 if (specoffset) { \
437 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
438 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
439 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
440 } \
441 } while (0)
442
443 #define VERT_COPY_SPEC( v0, v1 ) \
444 do { \
445 if (specoffset) { \
446 v0->v.specular.red = v1->v.specular.red; \
447 v0->v.specular.green = v1->v.specular.green; \
448 v0->v.specular.blue = v1->v.specular.blue; \
449 } \
450 } while (0)
451
452 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
453 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
454 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
455 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
456
457 #undef LOCAL_VARS
458 #undef TAG
459 #undef INIT
460
461 #define LOCAL_VARS(n) \
462 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
463 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
464 GLuint coloroffset = rmesa->swtcl.coloroffset; \
465 GLuint specoffset = rmesa->swtcl.specoffset; \
466 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
467
468 /***********************************************************************
469 * Helpers for rendering unfilled primitives *
470 ***********************************************************************/
471
472 #define RASTERIZE(x) r300RasterPrimitive( ctx, reduced_prim[x] )
473 #define RENDER_PRIMITIVE rmesa->radeon.swtcl.render_primitive
474 #undef TAG
475 #define TAG(x) x
476 #include "tnl_dd/t_dd_unfilled.h"
477 #undef IND
478
479
480 /***********************************************************************
481 * Generate GL render functions *
482 ***********************************************************************/
483
484
485 #define IND (0)
486 #define TAG(x) x
487 #include "tnl_dd/t_dd_tritmp.h"
488
489 #define IND (R300_TWOSIDE_BIT)
490 #define TAG(x) x##_twoside
491 #include "tnl_dd/t_dd_tritmp.h"
492
493 #define IND (R300_UNFILLED_BIT)
494 #define TAG(x) x##_unfilled
495 #include "tnl_dd/t_dd_tritmp.h"
496
497 #define IND (R300_TWOSIDE_BIT|R300_UNFILLED_BIT)
498 #define TAG(x) x##_twoside_unfilled
499 #include "tnl_dd/t_dd_tritmp.h"
500
501
502
503 static void init_rast_tab( void )
504 {
505 init();
506 init_twoside();
507 init_unfilled();
508 init_twoside_unfilled();
509 }
510
511 /**********************************************************************/
512 /* Render unclipped begin/end objects */
513 /**********************************************************************/
514
515 #define RENDER_POINTS( start, count ) \
516 for ( ; start < count ; start++) \
517 r300_point( rmesa, VERT(start) )
518 #define RENDER_LINE( v0, v1 ) \
519 r300_line( rmesa, VERT(v0), VERT(v1) )
520 #define RENDER_TRI( v0, v1, v2 ) \
521 r300_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
522 #define RENDER_QUAD( v0, v1, v2, v3 ) \
523 r300_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
524 #define INIT(x) do { \
525 r300RenderPrimitive( ctx, x ); \
526 } while (0)
527 #undef LOCAL_VARS
528 #define LOCAL_VARS \
529 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
530 const GLuint vertsize = rmesa->radeon.swtcl.vertex_size; \
531 const char *r300verts = (char *)rmesa->radeon.swtcl.verts; \
532 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
533 const GLboolean stipple = ctx->Line.StippleFlag; \
534 (void) elt; (void) stipple;
535 #define RESET_STIPPLE //if ( stipple ) r200ResetLineStipple( ctx );
536 #define RESET_OCCLUSION
537 #define PRESERVE_VB_DEFS
538 #define ELT(x) (x)
539 #define TAG(x) r300_##x##_verts
540 #include "tnl/t_vb_rendertmp.h"
541 #undef ELT
542 #undef TAG
543 #define TAG(x) r300_##x##_elts
544 #define ELT(x) elt[x]
545 #include "tnl/t_vb_rendertmp.h"
546
547
548
549
550 /**********************************************************************/
551 /* Choose render functions */
552 /**********************************************************************/
553 static void r300ChooseRenderState( GLcontext *ctx )
554 {
555 TNLcontext *tnl = TNL_CONTEXT(ctx);
556 r300ContextPtr rmesa = R300_CONTEXT(ctx);
557 GLuint index = 0;
558 GLuint flags = ctx->_TriangleCaps;
559
560 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= R300_TWOSIDE_BIT;
561 if (flags & DD_TRI_UNFILLED) index |= R300_UNFILLED_BIT;
562
563 if (index != rmesa->radeon.swtcl.RenderIndex) {
564 tnl->Driver.Render.Points = rast_tab[index].points;
565 tnl->Driver.Render.Line = rast_tab[index].line;
566 tnl->Driver.Render.ClippedLine = rast_tab[index].line;
567 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
568 tnl->Driver.Render.Quad = rast_tab[index].quad;
569
570 if (index == 0) {
571 tnl->Driver.Render.PrimTabVerts = r300_render_tab_verts;
572 tnl->Driver.Render.PrimTabElts = r300_render_tab_elts;
573 tnl->Driver.Render.ClippedPolygon = r300_fast_clipped_poly;
574 } else {
575 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
576 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
577 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
578 }
579
580 rmesa->radeon.swtcl.RenderIndex = index;
581 }
582 }
583
584
585 static void r300RenderStart(GLcontext *ctx)
586 {
587 r300ContextPtr rmesa = R300_CONTEXT( ctx );
588
589 r300ChooseRenderState(ctx);
590 r300SetVertexFormat(ctx);
591
592 r300ValidateBuffers(ctx);
593
594 r300UpdateShaders(rmesa);
595 r300UpdateShaderStates(rmesa);
596
597 r300EmitCacheFlush(rmesa);
598
599 /* investigate if we can put back flush optimisation if needed */
600 if (rmesa->radeon.dma.flush != NULL) {
601 rmesa->radeon.dma.flush(ctx);
602 }
603 }
604
605 static void r300RenderFinish(GLcontext *ctx)
606 {
607 }
608
609 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
610 {
611 r300ContextPtr rmesa = R300_CONTEXT(ctx);
612
613 if (rmesa->radeon.swtcl.hw_primitive != hwprim) {
614 R300_NEWPRIM( rmesa );
615 rmesa->radeon.swtcl.hw_primitive = hwprim;
616 }
617 }
618
619 static void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
620 {
621
622 r300ContextPtr rmesa = R300_CONTEXT(ctx);
623 rmesa->radeon.swtcl.render_primitive = prim;
624
625 if ((prim == GL_TRIANGLES) && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
626 return;
627
628 r300RasterPrimitive( ctx, reduced_prim[prim] );
629 }
630
631 static void r300ResetLineStipple(GLcontext *ctx)
632 {
633 }
634
635 void r300InitSwtcl(GLcontext *ctx)
636 {
637 TNLcontext *tnl = TNL_CONTEXT(ctx);
638 r300ContextPtr rmesa = R300_CONTEXT(ctx);
639 static int firsttime = 1;
640
641 if (firsttime) {
642 init_rast_tab();
643 firsttime = 0;
644 }
645
646 tnl->Driver.Render.Start = r300RenderStart;
647 tnl->Driver.Render.Finish = r300RenderFinish;
648 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
649 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
650 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
651 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
652 tnl->Driver.Render.Interp = _tnl_interp;
653
654 /* FIXME: what are these numbers? */
655 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
656 48 * sizeof(GLfloat) );
657
658 rmesa->radeon.swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
659 rmesa->radeon.swtcl.RenderIndex = ~0;
660 rmesa->radeon.swtcl.render_primitive = GL_TRIANGLES;
661 rmesa->radeon.swtcl.hw_primitive = 0;
662
663 _tnl_invalidate_vertex_state( ctx, ~0 );
664 _tnl_invalidate_vertices( ctx, ~0 );
665
666 _tnl_need_projected_coords( ctx, GL_FALSE );
667 r300ChooseRenderState(ctx);
668 }
669
670 void r300DestroySwtcl(GLcontext *ctx)
671 {
672 }
673
674 static void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, struct radeon_bo *bo, GLuint offset)
675 {
676 BATCH_LOCALS(&rmesa->radeon);
677
678 if (RADEON_DEBUG & DEBUG_VERTS)
679 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
680 __FUNCTION__, vertex_size, offset);
681
682 BEGIN_BATCH(7);
683 OUT_BATCH_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2);
684 OUT_BATCH(1);
685 OUT_BATCH(vertex_size | (vertex_size << 8));
686 OUT_BATCH_RELOC(offset, bo, offset, RADEON_GEM_DOMAIN_GTT, 0, 0);
687 END_BATCH();
688 }
689
690 static void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
691 {
692 BATCH_LOCALS(&rmesa->radeon);
693 int type, num_verts;
694
695 type = r300PrimitiveType(rmesa, primitive);
696 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
697
698 BEGIN_BATCH(3);
699 OUT_BATCH_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
700 OUT_BATCH(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
701 END_BATCH();
702 }
703
704 void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
705 {
706 r300ContextPtr rmesa = R300_CONTEXT(ctx);
707
708 rcommonEnsureCmdBufSpace(&rmesa->radeon,
709 rmesa->radeon.hw.max_state_size + (12*sizeof(int)),
710 __FUNCTION__);
711 radeonEmitState(&rmesa->radeon);
712 r300EmitVertexAOS(rmesa,
713 rmesa->radeon.swtcl.vertex_size,
714 rmesa->radeon.dma.current,
715 current_offset);
716
717 r300EmitVbufPrim(rmesa,
718 rmesa->radeon.swtcl.hw_primitive,
719 rmesa->radeon.swtcl.numverts);
720 r300EmitCacheFlush(rmesa);
721 COMMIT_BATCH();
722 }