Merge branch 'master' of git+ssh://znh@git.freedesktop.org/git/mesa/mesa into 965...
[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 "glheader.h"
38 #include "mtypes.h"
39 #include "colormac.h"
40 #include "enums.h"
41 #include "image.h"
42 #include "imports.h"
43 #include "macros.h"
44
45 #include "swrast/s_context.h"
46 #include "swrast/s_fog.h"
47 #include "swrast_setup/swrast_setup.h"
48 #include "math/m_translate.h"
49 #include "tnl/tnl.h"
50 #include "tnl/t_context.h"
51 #include "tnl/t_pipeline.h"
52
53 #include "r300_context.h"
54 #include "r300_swtcl.h"
55 #include "r300_state.h"
56 #include "r300_ioctl.h"
57 #include "r300_emit.h"
58 #include "r300_mem.h"
59
60 static void flush_last_swtcl_prim( r300ContextPtr rmesa );
61
62
63 void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, GLuint offset);
64 void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr);
65 #define EMIT_ATTR( ATTR, STYLE ) \
66 do { \
67 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = (ATTR); \
68 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = (STYLE); \
69 rmesa->swtcl.vertex_attr_count++; \
70 } while (0)
71
72 #define EMIT_PAD( N ) \
73 do { \
74 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].attrib = 0; \
75 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].format = EMIT_PAD; \
76 rmesa->swtcl.vertex_attrs[rmesa->swtcl.vertex_attr_count].offset = (N); \
77 rmesa->swtcl.vertex_attr_count++; \
78 } while (0)
79
80 /* this differs from the VIR0 in emit.c - TODO merge them using another option */
81 static GLuint r300VAPInputRoute0(uint32_t * dst, GLvector4f ** attribptr,
82 int *inputs, GLint * tab, GLuint nr)
83 {
84 GLuint i, dw;
85
86 /* type, inputs, stop bit, size */
87 for (i = 0; i + 1 < nr; i += 2) {
88 dw = (inputs[tab[i]] << 8) | 0x3;
89 dw |= ((inputs[tab[i + 1]] << 8) | 0x3) << 16;
90 if (i + 2 == nr) {
91 dw |= (R300_VAP_INPUT_ROUTE_END << 16);
92 }
93 dst[i >> 1] = dw;
94 }
95
96 if (nr & 1) {
97 dw = (inputs[tab[nr - 1]] << 8) | 0x3;
98 dw |= R300_VAP_INPUT_ROUTE_END;
99 dst[nr >> 1] = dw;
100 }
101
102 return (nr + 1) >> 1;
103 }
104
105 static void r300SetVertexFormat( GLcontext *ctx )
106 {
107 r300ContextPtr rmesa = R300_CONTEXT( ctx );
108 TNLcontext *tnl = TNL_CONTEXT(ctx);
109 struct vertex_buffer *VB = &tnl->vb;
110 DECLARE_RENDERINPUTS(index_bitset);
111 GLuint InputsRead = 0, OutputsWritten = 0;
112 int vap_fmt_0 = 0;
113 int vap_vte_cntl = 0;
114 int offset = 0;
115 int vte = 0;
116 GLint inputs[VERT_ATTRIB_MAX];
117 GLint tab[VERT_ATTRIB_MAX];
118 int swizzle[VERT_ATTRIB_MAX][4];
119 GLuint i, nr;
120
121 DECLARE_RENDERINPUTS(render_inputs_bitset);
122 RENDERINPUTS_COPY(render_inputs_bitset, tnl->render_inputs_bitset);
123 RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
124 RENDERINPUTS_COPY(rmesa->state.render_inputs_bitset, render_inputs_bitset);
125
126 /* Important:
127 */
128 if ( VB->NdcPtr != NULL ) {
129 VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
130 }
131 else {
132 VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
133 }
134
135 assert( VB->AttribPtr[VERT_ATTRIB_POS] != NULL );
136 rmesa->swtcl.vertex_attr_count = 0;
137
138 /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
139 * build up a hardware vertex.
140 */
141 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POS)) {
142 vap_vte_cntl |= R300_VTX_W0_FMT;
143 InputsRead |= 1 << VERT_ATTRIB_POS;
144 OutputsWritten |= 1 << VERT_RESULT_HPOS;
145 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F );
146 } else
147 EMIT_PAD(4 * sizeof(float));
148
149 offset = 4;
150
151 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_POINTSIZE )) {
152 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F );
153 vap_fmt_0 |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT;
154 offset += 1;
155 }
156
157 if (RENDERINPUTS_TEST(index_bitset, _TNL_ATTRIB_COLOR0)) {
158 rmesa->swtcl.coloroffset = offset;
159 InputsRead |= 1 << VERT_ATTRIB_COLOR0;
160 OutputsWritten |= 1 << VERT_RESULT_COL0;
161 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4F );
162 }
163
164 offset += 4;
165
166 rmesa->swtcl.specoffset = 0;
167 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
168 rmesa->swtcl.specoffset = offset;
169 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4F );
170 InputsRead |= 1 << VERT_ATTRIB_COLOR1;
171 OutputsWritten |= 1 << VERT_RESULT_COL1;
172 }
173
174 if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX )) {
175 int i;
176
177 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
178 if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(i) )) {
179 InputsRead |= 1 << (VERT_ATTRIB_TEX0 + i);
180 OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i);
181 EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_4F );
182 }
183 }
184 }
185
186 for (i = 0, nr = 0; i < VERT_ATTRIB_MAX; i++) {
187 if (InputsRead & (1 << i)) {
188 inputs[i] = nr++;
189 } else {
190 inputs[i] = -1;
191 }
192 }
193
194 /* Fixed, apply to vir0 only */
195 if (InputsRead & (1 << VERT_ATTRIB_POS))
196 inputs[VERT_ATTRIB_POS] = 0;
197 if (InputsRead & (1 << VERT_ATTRIB_COLOR0))
198 inputs[VERT_ATTRIB_COLOR0] = 2;
199 if (InputsRead & (1 << VERT_ATTRIB_COLOR1))
200 inputs[VERT_ATTRIB_COLOR1] = 3;
201 for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++)
202 if (InputsRead & (1 << i))
203 inputs[i] = 6 + (i - VERT_ATTRIB_TEX0);
204
205 for (i = 0, nr = 0; i < VERT_ATTRIB_MAX; i++) {
206 if (InputsRead & (1 << i)) {
207 tab[nr++] = i;
208 }
209 }
210
211 for (i = 0; i < nr; i++) {
212 int ci;
213
214 swizzle[i][0] = SWIZZLE_ZERO;
215 swizzle[i][1] = SWIZZLE_ZERO;
216 swizzle[i][2] = SWIZZLE_ZERO;
217 swizzle[i][3] = SWIZZLE_ONE;
218
219 for (ci = 0; ci < VB->AttribPtr[tab[i]]->size; ci++) {
220 swizzle[i][ci] = ci;
221 }
222 }
223
224 R300_NEWPRIM(rmesa);
225 R300_STATECHANGE(rmesa, vir[0]);
226 ((drm_r300_cmd_header_t *) rmesa->hw.vir[0].cmd)->packet0.count =
227 r300VAPInputRoute0(&rmesa->hw.vir[0].cmd[R300_VIR_CNTL_0],
228 VB->AttribPtr, inputs, tab, nr);
229 R300_STATECHANGE(rmesa, vir[1]);
230 ((drm_r300_cmd_header_t *) rmesa->hw.vir[1].cmd)->packet0.count =
231 r300VAPInputRoute1(&rmesa->hw.vir[1].cmd[R300_VIR_CNTL_0], swizzle,
232 nr);
233
234 R300_STATECHANGE(rmesa, vic);
235 rmesa->hw.vic.cmd[R300_VIC_CNTL_0] = r300VAPInputCntl0(ctx, InputsRead);
236 rmesa->hw.vic.cmd[R300_VIC_CNTL_1] = r300VAPInputCntl1(ctx, InputsRead);
237
238 R300_STATECHANGE(rmesa, vof);
239 rmesa->hw.vof.cmd[R300_VOF_CNTL_0] = r300VAPOutputCntl0(ctx, OutputsWritten);
240 rmesa->hw.vof.cmd[R300_VOF_CNTL_1] = r300VAPOutputCntl1(ctx, OutputsWritten);
241
242 rmesa->swtcl.vertex_size =
243 _tnl_install_attrs( ctx,
244 rmesa->swtcl.vertex_attrs,
245 rmesa->swtcl.vertex_attr_count,
246 NULL, 0 );
247
248 rmesa->swtcl.vertex_size /= 4;
249
250 RENDERINPUTS_COPY( rmesa->tnl_index_bitset, index_bitset );
251
252 vte = rmesa->hw.vte.cmd[1];
253 R300_STATECHANGE(rmesa, vte);
254 rmesa->hw.vte.cmd[1] = vte;
255 rmesa->hw.vte.cmd[2] = rmesa->swtcl.vertex_size;
256 }
257
258
259 /* Flush vertices in the current dma region.
260 */
261 static void flush_last_swtcl_prim( r300ContextPtr rmesa )
262 {
263 if (RADEON_DEBUG & DEBUG_IOCTL)
264 fprintf(stderr, "%s\n", __FUNCTION__);
265
266 rmesa->dma.flush = NULL;
267
268 if (rmesa->dma.current.buf) {
269 struct r300_dma_region *current = &rmesa->dma.current;
270 GLuint current_offset = GET_START(current);
271
272 assert (current->start +
273 rmesa->swtcl.numverts * rmesa->swtcl.vertex_size * 4 ==
274 current->ptr);
275
276 if (rmesa->dma.current.start != rmesa->dma.current.ptr) {
277
278 r300EnsureCmdBufSpace( rmesa, rmesa->hw.max_state_size + (12*sizeof(int)), __FUNCTION__);
279
280 r300EmitState(rmesa);
281
282 r300EmitVertexAOS( rmesa,
283 rmesa->swtcl.vertex_size,
284 current_offset);
285
286 r300EmitVbufPrim( rmesa,
287 rmesa->swtcl.hw_primitive,
288 rmesa->swtcl.numverts);
289
290 r300EmitCacheFlush(rmesa);
291 }
292
293 rmesa->swtcl.numverts = 0;
294 current->start = current->ptr;
295 }
296 }
297
298 /* Alloc space in the current dma region.
299 */
300 static void *
301 r300AllocDmaLowVerts( r300ContextPtr rmesa, int nverts, int vsize )
302 {
303 GLuint bytes = vsize * nverts;
304
305 if ( rmesa->dma.current.ptr + bytes > rmesa->dma.current.end )
306 r300RefillCurrentDmaRegion( rmesa, bytes);
307
308 if (!rmesa->dma.flush) {
309 rmesa->radeon.glCtx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
310 rmesa->dma.flush = flush_last_swtcl_prim;
311 }
312
313 ASSERT( vsize == rmesa->swtcl.vertex_size * 4 );
314 ASSERT( rmesa->dma.flush == flush_last_swtcl_prim );
315 ASSERT( rmesa->dma.current.start +
316 rmesa->swtcl.numverts * rmesa->swtcl.vertex_size * 4 ==
317 rmesa->dma.current.ptr );
318
319 {
320 GLubyte *head = (GLubyte *) (rmesa->dma.current.address + rmesa->dma.current.ptr);
321 rmesa->dma.current.ptr += bytes;
322 rmesa->swtcl.numverts += nverts;
323 return head;
324 }
325 }
326
327 static GLuint reduced_prim[] = {
328 GL_POINTS,
329 GL_LINES,
330 GL_LINES,
331 GL_LINES,
332 GL_TRIANGLES,
333 GL_TRIANGLES,
334 GL_TRIANGLES,
335 GL_TRIANGLES,
336 GL_TRIANGLES,
337 GL_TRIANGLES,
338 };
339
340 static void r300RasterPrimitive( GLcontext *ctx, GLuint prim );
341 static void r300RenderPrimitive( GLcontext *ctx, GLenum prim );
342 //static void r300ResetLineStipple( GLcontext *ctx );
343
344 /***********************************************************************
345 * Emit primitives as inline vertices *
346 ***********************************************************************/
347
348
349 #define HAVE_POINTS 1
350 #define HAVE_LINES 1
351 #define HAVE_LINE_STRIPS 1
352 #define HAVE_TRIANGLES 1
353 #define HAVE_TRI_STRIPS 1
354 #define HAVE_TRI_STRIP_1 0
355 #define HAVE_TRI_FANS 1
356 #define HAVE_QUADS 0
357 #define HAVE_QUAD_STRIPS 0
358 #define HAVE_POLYGONS 1
359 #define HAVE_ELTS 1
360
361 #undef LOCAL_VARS
362 #undef ALLOC_VERTS
363 #define CTX_ARG r300ContextPtr rmesa
364 #define GET_VERTEX_DWORDS() rmesa->swtcl.vertex_size
365 #define ALLOC_VERTS( n, size ) r300AllocDmaLowVerts( rmesa, n, size * 4 )
366 #define LOCAL_VARS \
367 r300ContextPtr rmesa = R300_CONTEXT(ctx); \
368 const char *r300verts = (char *)rmesa->swtcl.verts;
369 #define VERT(x) (r300Vertex *)(r300verts + ((x) * vertsize * sizeof(int)))
370 #define VERTEX r300Vertex
371 #define DO_DEBUG_VERTS (1 && (RADEON_DEBUG & DEBUG_VERTS))
372 #define PRINT_VERTEX(x)
373 #undef TAG
374 #define TAG(x) r300_##x
375 #include "tnl_dd/t_dd_triemit.h"
376
377
378
379 /***********************************************************************
380 * Macros for t_dd_tritmp.h to draw basic primitives *
381 ***********************************************************************/
382
383 #define QUAD( a, b, c, d ) r300_quad( rmesa, a, b, c, d )
384 #define TRI( a, b, c ) r300_triangle( rmesa, a, b, c )
385 #define LINE( a, b ) r300_line( rmesa, a, b )
386 #define POINT( a ) r300_point( rmesa, a )
387
388 /***********************************************************************
389 * Build render functions from dd templates *
390 ***********************************************************************/
391
392 #define R300_TWOSIDE_BIT 0x01
393 #define R300_UNFILLED_BIT 0x02
394 #define R300_MAX_TRIFUNC 0x04
395
396 static struct {
397 tnl_points_func points;
398 tnl_line_func line;
399 tnl_triangle_func triangle;
400 tnl_quad_func quad;
401 } rast_tab[R300_MAX_TRIFUNC];
402
403 #define DO_FALLBACK 0
404 #define DO_UNFILLED (IND & R300_UNFILLED_BIT)
405 #define DO_TWOSIDE (IND & R300_TWOSIDE_BIT)
406 #define DO_FLAT 0
407 #define DO_OFFSET 0
408 #define DO_TRI 1
409 #define DO_QUAD 1
410 #define DO_LINE 1
411 #define DO_POINTS 1
412 #define DO_FULL_QUAD 1
413
414 #define HAVE_RGBA 1
415 #define HAVE_SPEC 1
416 #define HAVE_BACK_COLORS 0
417 #define HAVE_HW_FLATSHADE 1
418 #define TAB rast_tab
419
420 #define DEPTH_SCALE 1.0
421 #define UNFILLED_TRI unfilled_tri
422 #define UNFILLED_QUAD unfilled_quad
423 #define VERT_X(_v) _v->v.x
424 #define VERT_Y(_v) _v->v.y
425 #define VERT_Z(_v) _v->v.z
426 #define AREA_IS_CCW( a ) (a < 0)
427 #define GET_VERTEX(e) (rmesa->swtcl.verts + (e*rmesa->swtcl.vertex_size*sizeof(int)))
428
429 /* Only used to pull back colors into vertices (ie, we know color is
430 * floating point).
431 */
432 #define R300_COLOR( dst, src ) \
433 do { \
434 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
435 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
436 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
437 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
438 } while (0)
439
440 #define VERT_SET_RGBA( v, c ) if (coloroffset) R300_COLOR( v->ub4[coloroffset], c )
441 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
442 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
443 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
444
445 #define R300_SPEC( dst, src ) \
446 do { \
447 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
448 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
449 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
450 } while (0)
451
452 #define VERT_SET_SPEC( v, c ) if (specoffset) R300_SPEC( v->ub4[specoffset], c )
453 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
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], spec[n]; \
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->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->swtcl.vertex_size; \
531 const char *r300verts = (char *)rmesa->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->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->swtcl.RenderIndex = index;
581 }
582 }
583
584
585 static void r300RenderStart(GLcontext *ctx)
586 {
587 r300ContextPtr rmesa = R300_CONTEXT( ctx );
588 // fprintf(stderr, "%s\n", __FUNCTION__);
589
590 r300ChooseRenderState(ctx);
591 r300SetVertexFormat(ctx);
592
593 r300UpdateShaderStates(rmesa);
594
595 r300EmitCacheFlush(rmesa);
596
597 if (rmesa->dma.flush != 0 &&
598 rmesa->dma.flush != flush_last_swtcl_prim)
599 rmesa->dma.flush( rmesa );
600
601 }
602
603 static void r300RenderFinish(GLcontext *ctx)
604 {
605 }
606
607 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
608 {
609 r300ContextPtr rmesa = R300_CONTEXT(ctx);
610
611 if (rmesa->swtcl.hw_primitive != hwprim) {
612 R300_NEWPRIM( rmesa );
613 rmesa->swtcl.hw_primitive = hwprim;
614 }
615 }
616
617 static void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
618 {
619
620 r300ContextPtr rmesa = R300_CONTEXT(ctx);
621 rmesa->swtcl.render_primitive = prim;
622
623 if ((prim == GL_TRIANGLES) && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
624 return;
625
626 r300RasterPrimitive( ctx, reduced_prim[prim] );
627 // fprintf(stderr, "%s\n", __FUNCTION__);
628
629 }
630
631 static void r300ResetLineStipple(GLcontext *ctx)
632 {
633
634
635 }
636
637 void r300InitSwtcl(GLcontext *ctx)
638 {
639 TNLcontext *tnl = TNL_CONTEXT(ctx);
640 r300ContextPtr rmesa = R300_CONTEXT(ctx);
641 static int firsttime = 1;
642
643 if (firsttime) {
644 init_rast_tab();
645 firsttime = 0;
646 }
647
648 tnl->Driver.Render.Start = r300RenderStart;
649 tnl->Driver.Render.Finish = r300RenderFinish;
650 tnl->Driver.Render.PrimitiveNotify = r300RenderPrimitive;
651 tnl->Driver.Render.ResetLineStipple = r300ResetLineStipple;
652 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
653 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
654 tnl->Driver.Render.Interp = _tnl_interp;
655
656 /* FIXME: what are these numbers? */
657 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
658 48 * sizeof(GLfloat) );
659
660 rmesa->swtcl.verts = (GLubyte *)tnl->clipspace.vertex_buf;
661 rmesa->swtcl.RenderIndex = ~0;
662 rmesa->swtcl.render_primitive = GL_TRIANGLES;
663 rmesa->swtcl.hw_primitive = 0;
664
665 _tnl_invalidate_vertex_state( ctx, ~0 );
666 _tnl_invalidate_vertices( ctx, ~0 );
667 RENDERINPUTS_ZERO( rmesa->tnl_index_bitset );
668
669 _tnl_need_projected_coords( ctx, GL_FALSE );
670 r300ChooseRenderState(ctx);
671 }
672
673 void r300DestroySwtcl(GLcontext *ctx)
674 {
675 }
676
677 void r300EmitVertexAOS(r300ContextPtr rmesa, GLuint vertex_size, GLuint offset)
678 {
679 int cmd_reserved = 0;
680 int cmd_written = 0;
681
682 drm_radeon_cmd_header_t *cmd = NULL;
683 if (RADEON_DEBUG & DEBUG_VERTS)
684 fprintf(stderr, "%s: vertex_size %d, offset 0x%x \n",
685 __FUNCTION__, vertex_size, offset);
686
687 start_packet3(CP_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 2), 2);
688 e32(1);
689 e32(vertex_size | (vertex_size << 8));
690 e32(offset);
691 }
692
693 void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vertex_nr)
694 {
695
696 int cmd_reserved = 0;
697 int cmd_written = 0;
698 int type, num_verts;
699 drm_radeon_cmd_header_t *cmd = NULL;
700
701 type = r300PrimitiveType(rmesa, primitive);
702 num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
703
704 start_packet3(CP_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0), 0);
705 e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (num_verts << 16) | type);
706 }