Replace the numerous switch-statements to derive GL_COMBINE post-scale
[mesa.git] / src / mesa / drivers / dri / unichrome / via_tris.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <stdio.h>
26 #include <math.h>
27
28 #include "glheader.h"
29 #include "context.h"
30 #include "mtypes.h"
31 #include "macros.h"
32 #include "colormac.h"
33
34 #include "swrast/swrast.h"
35 #include "swrast_setup/swrast_setup.h"
36 #include "tnl/t_context.h"
37 #include "tnl/t_pipeline.h"
38
39 #include "via_context.h"
40 #include "via_tris.h"
41 #include "via_state.h"
42 #include "via_vb.h"
43 #include "via_ioctl.h"
44
45 static void viaRenderPrimitive(GLcontext *ctx, GLenum prim);
46 GLuint RasterCounter = 0;
47 extern GLuint idle;
48 extern GLuint busy;
49 /***********************************************************************
50 * Emit primitives as inline vertices *
51 ***********************************************************************/
52
53 #if defined(USE_X86_ASM)
54 #define COPY_DWORDS(j, vb, vertsize, v) \
55 do { \
56 int __tmp; \
57 __asm__ __volatile__("rep ; movsl" \
58 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
59 : "0" (vertsize), \
60 "D" ((long)vb), \
61 "S" ((long)v)); \
62 } while (0)
63 #else
64 #define COPY_DWORDS(j, vb, vertsize, v) \
65 do { \
66 for (j = 0; j < vertsize; j++) \
67 vb[j] = ((GLuint *)v)[j]; \
68 vb += vertsize; \
69 } while (0)
70 #endif
71
72 static void __inline__ via_draw_triangle(viaContextPtr vmesa,
73 viaVertexPtr v0,
74 viaVertexPtr v1,
75 viaVertexPtr v2)
76 {
77 GLuint vertsize = vmesa->vertexSize;
78 GLuint *vb = viaCheckDma(vmesa, 3 * 4 * vertsize);
79 int j;
80
81 #ifdef DEBUG
82 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
83 #endif
84 #ifdef PERFORMANCE_MEASURE
85 if (VIA_PERFORMANCE) P_M;
86 #endif
87 COPY_DWORDS(j, vb, vertsize, v0);
88 COPY_DWORDS(j, vb, vertsize, v1);
89 COPY_DWORDS(j, vb, vertsize, v2);
90 vmesa->dmaLow += 3 * 4 * vertsize;
91 vmesa->primitiveRendered = GL_TRUE;
92 #ifdef DEBUG
93 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
94 #endif
95 }
96
97
98 static void __inline__ via_draw_quad(viaContextPtr vmesa,
99 viaVertexPtr v0,
100 viaVertexPtr v1,
101 viaVertexPtr v2,
102 viaVertexPtr v3)
103 {
104 GLuint vertsize = vmesa->vertexSize;
105 GLuint *vb = viaCheckDma(vmesa, 6 * 4 * vertsize);
106 int j;
107 #ifdef DEBUG
108 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
109 #endif
110 #ifdef PERFORMANCE_MEASURE
111 if (VIA_PERFORMANCE) P_M;
112 #endif
113 COPY_DWORDS(j, vb, vertsize, v0);
114 COPY_DWORDS(j, vb, vertsize, v1);
115 COPY_DWORDS(j, vb, vertsize, v3);
116 COPY_DWORDS(j, vb, vertsize, v1);
117 COPY_DWORDS(j, vb, vertsize, v2);
118 COPY_DWORDS(j, vb, vertsize, v3);
119 vmesa->dmaLow += 6 * 4 * vertsize;
120 vmesa->primitiveRendered = GL_TRUE;
121 #ifdef DEBUG
122 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
123 #endif
124 }
125
126
127 static __inline__ void via_draw_point(viaContextPtr vmesa,
128 viaVertexPtr v0)
129 {
130 /*GLfloat sz = vmesa->glCtx->Point._Size * .5;*/
131 int vertsize = vmesa->vertexSize;
132 /*GLuint *vb = viaCheckDma(vmesa, 2 * 4 * vertsize);*/
133 GLuint *vb = viaCheckDma(vmesa, 4 * vertsize);
134 int j;
135 #ifdef DEBUG
136 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
137 #endif
138 #ifdef PERFORMANCE_MEASURE
139 if (VIA_PERFORMANCE) P_M;
140 #endif
141 COPY_DWORDS(j, vb, vertsize, v0);
142 vmesa->dmaLow += 4 * vertsize;
143 vmesa->primitiveRendered = GL_TRUE;
144 #ifdef DEBUG
145 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
146 #endif
147 }
148
149
150 /*
151 * Draw line in hardware.
152 * Checked out - AC.
153 */
154 static __inline__ void via_draw_line(viaContextPtr vmesa,
155 viaVertexPtr v0,
156 viaVertexPtr v1)
157 {
158 GLuint vertsize = vmesa->vertexSize;
159 GLuint *vb = viaCheckDma(vmesa, 2 * 4 * vertsize);
160 int j;
161 #ifdef DEBUG
162 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
163 #endif
164 #ifdef PERFORMANCE_MEASURE
165 if (VIA_PERFORMANCE) P_M;
166 #endif
167 COPY_DWORDS(j, vb, vertsize, v0);
168 COPY_DWORDS(j, vb, vertsize, v1);
169 vmesa->dmaLow += 2 * 4 * vertsize;
170 vmesa->primitiveRendered = GL_TRUE;
171 #ifdef DEBUG
172 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
173 #endif
174 }
175
176
177 /***********************************************************************
178 * Macros for via_dd_tritmp.h to draw basic primitives *
179 ***********************************************************************/
180
181 #define TRI(a, b, c) \
182 do { \
183 if (VIA_DEBUG) fprintf(stderr, "hw TRI\n"); \
184 if (DO_FALLBACK) \
185 vmesa->drawTri(vmesa, a, b, c); \
186 else \
187 via_draw_triangle(vmesa, a, b, c); \
188 } while (0)
189
190 #define QUAD(a, b, c, d) \
191 do { \
192 if (VIA_DEBUG) fprintf(stderr, "hw QUAD\n");\
193 if (DO_FALLBACK) { \
194 vmesa->drawTri(vmesa, a, b, d); \
195 vmesa->drawTri(vmesa, b, c, d); \
196 } \
197 else \
198 via_draw_quad(vmesa, a, b, c, d); \
199 } while (0)
200
201 #define LINE(v0, v1) \
202 do { \
203 if(VIA_DEBUG) fprintf(stderr, "hw LINE\n");\
204 if (DO_FALLBACK) \
205 vmesa->drawLine(vmesa, v0, v1); \
206 else \
207 via_draw_line(vmesa, v0, v1); \
208 } while (0)
209
210 #define POINT(v0) \
211 do { \
212 if (VIA_DEBUG) fprintf(stderr, "hw POINT\n");\
213 if (DO_FALLBACK) \
214 vmesa->drawPoint(vmesa, v0); \
215 else \
216 via_draw_point(vmesa, v0); \
217 } while (0)
218
219
220 /***********************************************************************
221 * Build render functions from dd templates *
222 ***********************************************************************/
223
224 #define VIA_OFFSET_BIT 0x01
225 #define VIA_TWOSIDE_BIT 0x02
226 #define VIA_UNFILLED_BIT 0x04
227 #define VIA_FALLBACK_BIT 0x08
228 #define VIA_MAX_TRIFUNC 0x10
229
230
231 static struct {
232 tnl_points_func points;
233 tnl_line_func line;
234 tnl_triangle_func triangle;
235 tnl_quad_func quad;
236 } rast_tab[VIA_MAX_TRIFUNC];
237
238
239 #define DO_FALLBACK (IND & VIA_FALLBACK_BIT)
240 #define DO_OFFSET (IND & VIA_OFFSET_BIT)
241 #define DO_UNFILLED (IND & VIA_UNFILLED_BIT)
242 #define DO_TWOSIDE (IND & VIA_TWOSIDE_BIT)
243 #define DO_FLAT 0
244 #define DO_TRI 1
245 #define DO_QUAD 1
246 #define DO_LINE 1
247 #define DO_POINTS 1
248 #define DO_FULL_QUAD 1
249
250 #define HAVE_RGBA 1
251 #define HAVE_SPEC 1
252 #define HAVE_BACK_COLORS 0
253 #define HAVE_HW_FLATSHADE 1
254 #define VERTEX viaVertex
255 #define TAB rast_tab
256
257 /* Only used to pull back colors into vertices (ie, we know color is
258 * floating point).
259 */
260 #define VIA_COLOR(dst, src) \
261 do { \
262 dst[0] = src[2]; \
263 dst[1] = src[1]; \
264 dst[2] = src[0]; \
265 dst[3] = src[3]; \
266 } while (0)
267
268 #define VIA_SPEC(dst, src) \
269 do { \
270 dst[0] = src[2]; \
271 dst[1] = src[1]; \
272 dst[2] = src[0]; \
273 } while (0)
274
275
276 #define DEPTH_SCALE (1.0 / 0xffff)
277 #define UNFILLED_TRI unfilled_tri
278 #define UNFILLED_QUAD unfilled_quad
279 #define VERT_X(_v) _v->v.x
280 #define VERT_Y(_v) _v->v.y
281 #define VERT_Z(_v) _v->v.z
282 #define AREA_IS_CCW(a) (a > 0)
283 #define GET_VERTEX(e) (vmesa->verts + (e<<vmesa->vertexStrideShift))
284
285 #define VERT_SET_RGBA(v, c) VIA_COLOR(v->ub4[coloroffset], c)
286 #define VERT_COPY_RGBA(v0, v1) v0->ui[coloroffset] = v1->ui[coloroffset]
287 #define VERT_SAVE_RGBA(idx) color[idx] = v[idx]->ui[coloroffset]
288 #define VERT_RESTORE_RGBA(idx) v[idx]->ui[coloroffset] = color[idx]
289 #define VERT_SET_SPEC(v, c) if (havespec) VIA_SPEC(v->ub4[5], c)
290 #define VERT_COPY_SPEC(v0, v1) if (havespec) COPY_3V(v0->ub4[5], v1->ub4[5])
291 #define VERT_SAVE_SPEC(idx) if (havespec) spec[idx] = v[idx]->ui[5]
292 #define VERT_RESTORE_SPEC(idx) if (havespec) v[idx]->ui[5] = spec[idx]
293
294 #define SET_PRIMITIVE_RENDERED vmesa->primitiveRendered = GL_TRUE;
295
296 #define LOCAL_VARS(n) \
297 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
298 GLuint color[n], spec[n]; \
299 GLuint coloroffset = (vmesa->vertexSize == 4 ? 3 : 4); \
300 GLboolean havespec = (vmesa->vertexSize > 4); \
301 (void)color; (void)spec; (void)coloroffset; (void)havespec;
302
303
304 /***********************************************************************
305 * Helpers for rendering unfilled primitives *
306 ***********************************************************************/
307 /*
308 static const GLuint hwPrim[GL_POLYGON + 1] = {
309 PR_LINES,
310 PR_LINES,
311 PR_LINES,
312 PR_LINES,
313 PR_TRIANGLES,
314 PR_TRIANGLES,
315 PR_TRIANGLES,
316 PR_TRIANGLES,
317 PR_TRIANGLES,
318 PR_TRIANGLES
319 };
320 */
321
322 #define RASTERIZE(x) \
323 if (vmesa->hwPrimitive != x) { \
324 viaRasterPrimitiveFinish(ctx); \
325 viaRasterPrimitive(ctx, x, x); \
326 }
327
328 #define RENDER_PRIMITIVE vmesa->renderPrimitive
329 #define TAG(x) x
330 #define IND VIA_FALLBACK_BIT
331 #include "tnl_dd/t_dd_unfilled.h"
332 #undef IND
333 #undef RASTERIZE
334
335 /***********************************************************************
336 * Generate GL render functions *
337 ***********************************************************************/
338 #define RASTERIZE(x)
339
340 #define IND (0)
341 #define TAG(x) x
342 #include "via_dd_tritmp.h"
343
344 #define IND (VIA_OFFSET_BIT)
345 #define TAG(x) x##_offset
346 #include "via_dd_tritmp.h"
347
348 #define IND (VIA_TWOSIDE_BIT)
349 #define TAG(x) x##_twoside
350 #include "via_dd_tritmp.h"
351
352 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT)
353 #define TAG(x) x##_twoside_offset
354 #include "via_dd_tritmp.h"
355
356 #define IND (VIA_UNFILLED_BIT)
357 #define TAG(x) x##_unfilled
358 #include "via_dd_tritmp.h"
359
360 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
361 #define TAG(x) x##_offset_unfilled
362 #include "via_dd_tritmp.h"
363
364 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT)
365 #define TAG(x) x##_twoside_unfilled
366 #include "via_dd_tritmp.h"
367
368 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
369 #define TAG(x) x##_twoside_offset_unfilled
370 #include "via_dd_tritmp.h"
371
372 #define IND (VIA_FALLBACK_BIT)
373 #define TAG(x) x##_fallback
374 #include "via_dd_tritmp.h"
375
376 #define IND (VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
377 #define TAG(x) x##_offset_fallback
378 #include "via_dd_tritmp.h"
379
380 #define IND (VIA_TWOSIDE_BIT|VIA_FALLBACK_BIT)
381 #define TAG(x) x##_twoside_fallback
382 #include "via_dd_tritmp.h"
383
384 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
385 #define TAG(x) x##_twoside_offset_fallback
386 #include "via_dd_tritmp.h"
387
388 #define IND (VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
389 #define TAG(x) x##_unfilled_fallback
390 #include "via_dd_tritmp.h"
391
392 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
393 #define TAG(x) x##_offset_unfilled_fallback
394 #include "via_dd_tritmp.h"
395
396 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
397 #define TAG(x) x##_twoside_unfilled_fallback
398 #include "via_dd_tritmp.h"
399
400 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT| \
401 VIA_FALLBACK_BIT)
402 #define TAG(x) x##_twoside_offset_unfilled_fallback
403 #include "via_dd_tritmp.h"
404
405
406 static void init_rast_tab(void)
407 {
408 init();
409 init_offset();
410 init_twoside();
411 init_twoside_offset();
412 init_unfilled();
413 init_offset_unfilled();
414 init_twoside_unfilled();
415 init_twoside_offset_unfilled();
416 init_fallback();
417 init_offset_fallback();
418 init_twoside_fallback();
419 init_twoside_offset_fallback();
420 init_unfilled_fallback();
421 init_offset_unfilled_fallback();
422 init_twoside_unfilled_fallback();
423 init_twoside_offset_unfilled_fallback();
424 }
425
426
427 /***********************************************************************
428 * Rasterization fallback helpers *
429 ***********************************************************************/
430
431
432 /* This code is hit only when a mix of accelerated and unaccelerated
433 * primitives are being drawn, and only for the unaccelerated
434 * primitives.
435 */
436 static void
437 via_fallback_tri(viaContextPtr vmesa,
438 viaVertex *v0,
439 viaVertex *v1,
440 viaVertex *v2)
441 {
442 GLcontext *ctx = vmesa->glCtx;
443 SWvertex v[3];
444 #ifdef PERFORMANCE_MEASURE
445 if (VIA_PERFORMANCE) P_M;
446 #endif
447 via_translate_vertex(ctx, v0, &v[0]);
448 via_translate_vertex(ctx, v1, &v[1]);
449 via_translate_vertex(ctx, v2, &v[2]);
450 _swrast_Triangle(ctx, &v[0], &v[1], &v[2]);
451 }
452
453
454 static void
455 via_fallback_line(viaContextPtr vmesa,
456 viaVertex *v0,
457 viaVertex *v1)
458 {
459 GLcontext *ctx = vmesa->glCtx;
460 SWvertex v[2];
461 #ifdef PERFORMANCE_MEASURE
462 if (VIA_PERFORMANCE) P_M;
463 #endif
464 via_translate_vertex(ctx, v0, &v[0]);
465 via_translate_vertex(ctx, v1, &v[1]);
466 _swrast_Line(ctx, &v[0], &v[1]);
467 }
468
469
470 static void
471 via_fallback_point(viaContextPtr vmesa,
472 viaVertex *v0)
473 {
474 GLcontext *ctx = vmesa->glCtx;
475 SWvertex v[1];
476 #ifdef PERFORMANCE_MEASURE
477 if (VIA_PERFORMANCE) P_M;
478 #endif
479 via_translate_vertex(ctx, v0, &v[0]);
480 _swrast_Point(ctx, &v[0]);
481 }
482
483 /**********************************************************************/
484 /* Render unclipped begin/end objects */
485 /* (No Twoside / Offset / Unfilled) */
486 /**********************************************************************/
487 #define IND 0
488 #define V(x) (viaVertex *)(vertptr + ((x) << vertshift))
489 #define RENDER_POINTS(start, count) \
490 for (; start < count; start++) POINT(V(ELT(start)));
491 #define RENDER_LINE(v0, v1) LINE(V(v0), V(v1))
492
493 #define RENDER_TRI( v0, v1, v2) \
494 if (VIA_DEBUG) fprintf(stderr, "RENDER_TRI - simple\n"); \
495 TRI( V(v0), V(v1), V(v2))
496
497 #define RENDER_QUAD(v0, v1, v2, v3) QUAD(V(v0), V(v1), V(v2), V(v3))
498
499 #define INIT(x) viaRasterPrimitive(ctx, x, x)
500
501 #undef LOCAL_VARS
502 #define LOCAL_VARS \
503 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
504 GLubyte *vertptr = (GLubyte *)vmesa->verts; \
505 const GLuint vertshift = vmesa->vertexStrideShift; \
506 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
507 (void)elt;
508 #define POSTFIX \
509 viaRasterPrimitiveFinish(ctx)
510 #define RESET_STIPPLE
511 #define RESET_OCCLUSION
512 #define PRESERVE_VB_DEFS
513 #define ELT(x) x
514 #define TAG(x) via_fast##x##_verts
515 #include "via_vb_rendertmp.h"
516 #undef ELT
517 #undef TAG
518 #define TAG(x) via_fast##x##_elts
519 #define ELT(x) elt[x]
520 #include "via_vb_rendertmp.h"
521 #undef ELT
522 #undef TAG
523 #undef NEED_EDGEFLAG_SETUP
524 #undef EDGEFLAG_GET
525 #undef EDGEFLAG_SET
526 #undef RESET_OCCLUSION
527
528 /**********************************************************************/
529 /* Render unclipped begin/end objects */
530 /* (Can handle Twoside / Offset / Unfilled */
531 /**********************************************************************/
532 #define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
533 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
534 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
535
536 #define RENDER_POINTS(start, count) \
537 tnl->Driver.Render.Points(ctx, start, count)
538
539 #define RENDER_LINE(v1, v2) \
540 LineFunc(ctx, v1, v2)
541
542 #define RENDER_TRI(v1, v2, v3) \
543 if (VIA_DEBUG) fprintf(stderr, "RENDER_TRI - complex\n"); \
544 if (VIA_DEBUG) fprintf(stderr, "TriangleFunc = %x\n", (unsigned int)TriangleFunc); \
545 TriangleFunc(ctx, v1, v2, v3)
546
547 #define RENDER_QUAD(v1, v2, v3, v4) \
548 QuadFunc(ctx, v1, v2, v3, v4)
549
550 #define LOCAL_VARS \
551 TNLcontext *tnl = TNL_CONTEXT(ctx); \
552 struct vertex_buffer *VB = &tnl->vb; \
553 const GLuint * const elt = VB->Elts; \
554 const tnl_line_func LineFunc = tnl->Driver.Render.Line; \
555 const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
556 const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \
557 const GLboolean stipple = ctx->Line.StippleFlag; \
558 (void) (LineFunc && TriangleFunc && QuadFunc); \
559 (void) elt; (void) stipple;
560
561 #define POSTFIX \
562 viaRasterPrimitiveFinish(ctx)
563 #define ELT(x) x
564 #define TAG(x) via_##x##_verts
565 /*#define INIT(x) tnl->Driver.Render.PrimitiveNotify(ctx, x)*/
566 #define INIT(x) viaRasterPrimitive(ctx, x, x)
567 #define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple(ctx)
568 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
569 #define PRESERVE_VB_DEFS
570 #include "via_vb_rendertmp.h"
571 #undef ELT
572 #undef TAG
573 #define ELT(x) elt[x]
574 #define TAG(x) via_##x##_elts
575 #include "via_vb_rendertmp.h"
576
577 /**********************************************************************/
578 /* Render clipped primitives */
579 /**********************************************************************/
580
581
582
583 static void viaRenderClippedPoly(GLcontext *ctx, const GLuint *elts,
584 GLuint n)
585 {
586 TNLcontext *tnl = TNL_CONTEXT(ctx);
587 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
588 #ifdef DEBUG
589 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
590 #endif
591 #ifdef PERFORMANCE_MEASURE
592 if (VIA_PERFORMANCE) P_M;
593 #endif
594 /* Render the new vertices as an unclipped polygon.
595 */
596 {
597 GLuint *tmp = VB->Elts;
598 VB->Elts = (GLuint *)elts;
599 tnl->Driver.Render.PrimTabElts[GL_POLYGON](ctx, 0, n,
600 PRIM_BEGIN|PRIM_END);
601 VB->Elts = tmp;
602 }
603 #ifdef DEBUG
604 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
605 #endif
606 }
607
608 static void viaRenderClippedLine(GLcontext *ctx, GLuint ii, GLuint jj)
609 {
610 viaContextPtr vmesa = VIA_CONTEXT(ctx);
611 TNLcontext *tnl = TNL_CONTEXT(ctx);
612 #ifdef DEBUG
613 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
614 #endif
615 #ifdef PERFORMANCE_MEASURE
616 if (VIA_PERFORMANCE) P_M;
617 #endif
618 vmesa->primitiveRendered = GL_TRUE;
619
620 tnl->Driver.Render.Line(ctx, ii, jj);
621 #ifdef DEBUG
622 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
623 #endif
624 }
625
626 static void viaFastRenderClippedPoly(GLcontext *ctx, const GLuint *elts,
627 GLuint n)
628 {
629 viaContextPtr vmesa = VIA_CONTEXT(ctx);
630 GLuint vertsize = vmesa->vertexSize;
631 GLuint *vb = viaCheckDma(vmesa, (n - 2) * 3 * 4 * vertsize);
632 GLubyte *vertptr = (GLubyte *)vmesa->verts;
633 const GLuint vertshift = vmesa->vertexStrideShift;
634 const GLuint *start = (const GLuint *)V(elts[0]);
635 GLuint *temp1;
636 GLuint *temp2;
637 int i,j;
638 #ifdef DEBUG
639 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
640 #endif
641 #ifdef PERFORMANCE_MEASURE
642 if (VIA_PERFORMANCE) P_M;
643 #endif
644 vmesa->primitiveRendered = GL_TRUE;
645
646 for (i = 2; i < n; i++) {
647 /*=* [DBG] exy : fix flat-shading + clipping error *=*/
648 /*COPY_DWORDS(j, vb, vertsize, start);
649 COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
650 temp1 = (GLuint *)V(elts[i - 1]);
651 COPY_DWORDS(j, vb, vertsize, V(elts[i]));
652 temp2 = (GLuint *)V(elts[i]);*/
653 COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
654 COPY_DWORDS(j, vb, vertsize, V(elts[i]));
655 temp1 = (GLuint *)V(elts[i - 1]);
656 COPY_DWORDS(j, vb, vertsize, start);
657 temp2 = (GLuint *)V(elts[i]);
658 #ifdef DEBUG
659 if (VIA_DEBUG) fprintf(stderr, "start = %d - x = %f, y = %f, z = %f, w = %f, u = %f, v = %f\n", elts[0], *(GLfloat *)&start[0], *(GLfloat *)&start[1], *(GLfloat *)&start[2], *(GLfloat *)&start[3], *(GLfloat *)&start[6], *(GLfloat *)&start[7]);
660 if (VIA_DEBUG) fprintf(stderr, "%d - x = %f, y = %f, z = %f, w = %f, u = %f, v = %f\n", elts[i - 1], *(GLfloat *)&temp1[0], *(GLfloat *)&temp1[1], *(GLfloat *)&temp1[2], *(GLfloat *)&temp1[3], *(GLfloat *)&temp1[6], *(GLfloat *)&temp1[7]);
661 if (VIA_DEBUG) fprintf(stderr, "%d - x = %f, y = %f, z = %f, w = %f, u = %f, v = %f\n", elts[i], *(GLfloat *)&temp2[0], *(GLfloat *)&temp2[1], *(GLfloat *)&temp2[2], *(GLfloat *)&temp2[3], *(GLfloat *)&temp2[6], *(GLfloat *)&temp2[7]);
662 #endif
663 }
664 vmesa->dmaLow += (n - 2) * 3 * 4 * vertsize;
665 #ifdef DEBUG
666 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
667 #endif
668 }
669
670 /**********************************************************************/
671 /* Choose render functions */
672 /**********************************************************************/
673
674
675
676 #define _VIA_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE | \
677 _DD_NEW_TRI_UNFILLED | \
678 _DD_NEW_TRI_LIGHT_TWOSIDE | \
679 _DD_NEW_TRI_OFFSET | \
680 _DD_NEW_TRI_STIPPLE | \
681 _NEW_POLYGONSTIPPLE)
682
683 #define POINT_FALLBACK (0)
684 /*#define LINE_FALLBACK (DD_LINE_STIPPLE)
685 */
686 #define LINE_FALLBACK (0)
687 #define TRI_FALLBACK (0)
688 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
689 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
690
691 static void viaChooseRenderState(GLcontext *ctx)
692 {
693 TNLcontext *tnl = TNL_CONTEXT(ctx);
694 viaContextPtr vmesa = VIA_CONTEXT(ctx);
695 GLuint flags = ctx->_TriangleCaps;
696 GLuint index = 0;
697 #ifdef DEBUG
698 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
699
700 if (VIA_DEBUG) fprintf(stderr, "_TriangleCaps = %x\n", flags);
701 #endif
702 if (flags & (ANY_FALLBACK_FLAGS|ANY_RASTER_FLAGS)) {
703 if (flags & ANY_RASTER_FLAGS) {
704 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= VIA_TWOSIDE_BIT;
705 if (flags & DD_TRI_OFFSET) index |= VIA_OFFSET_BIT;
706 if (flags & DD_TRI_UNFILLED) index |= VIA_UNFILLED_BIT;
707 }
708
709 vmesa->drawPoint = via_draw_point;
710 vmesa->drawLine = via_draw_line;
711 vmesa->drawTri = via_draw_triangle;
712
713 /* Hook in fallbacks for specific primitives.
714 */
715 if (flags & ANY_FALLBACK_FLAGS) {
716 if (flags & POINT_FALLBACK)
717 vmesa->drawPoint = via_fallback_point;
718
719 if (flags & LINE_FALLBACK)
720 vmesa->drawLine = via_fallback_line;
721
722 if (flags & TRI_FALLBACK)
723 vmesa->drawTri = via_fallback_tri;
724
725 index |= VIA_FALLBACK_BIT;
726 }
727 }
728 #ifdef DEBUG
729 if (VIA_DEBUG) {
730 fprintf(stderr, "index = %x\n", index);
731 fprintf(stderr, "renderIndex = %x\n", vmesa->renderIndex);
732 }
733 #endif
734 if (vmesa->renderIndex != index) {
735 vmesa->renderIndex = index;
736
737 tnl->Driver.Render.Points = rast_tab[index].points;
738 tnl->Driver.Render.Line = rast_tab[index].line;
739 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
740 #ifdef DEBUG
741 if (VIA_DEBUG) fprintf(stderr, "tnl->Driver.Render.xxx = rast_tab[index].xxx = %x\n", (unsigned int)tnl->Driver.Render.Triangle);
742 #endif
743 tnl->Driver.Render.Quad = rast_tab[index].quad;
744
745 if (index == 0) {
746 tnl->Driver.Render.PrimTabVerts = via_fastrender_tab_verts;
747 tnl->Driver.Render.PrimTabElts = via_fastrender_tab_elts;
748 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
749 tnl->Driver.Render.ClippedPolygon = viaFastRenderClippedPoly;
750 }
751 else {
752 tnl->Driver.Render.PrimTabVerts = via_render_tab_verts;
753 tnl->Driver.Render.PrimTabElts = via_render_tab_elts;
754 tnl->Driver.Render.ClippedLine = viaRenderClippedLine;
755 tnl->Driver.Render.ClippedPolygon = viaRenderClippedPoly;
756 }
757 }
758 #ifdef DEBUG
759 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
760 #endif
761 }
762
763 static const GLenum reducedPrim[GL_POLYGON + 1] = {
764 GL_POINTS,
765 GL_LINES,
766 GL_LINES,
767 GL_LINES,
768 GL_TRIANGLES,
769 GL_TRIANGLES,
770 GL_TRIANGLES,
771 GL_TRIANGLES,
772 GL_TRIANGLES,
773 GL_TRIANGLES
774 };
775
776
777 static void emit_all_state(viaContextPtr vmesa)
778 {
779 GLcontext *ctx = vmesa->glCtx;
780 GLuint *vb = viaCheckDma(vmesa, 0x110);
781 GLuint i = 0;
782 GLuint j = 0;
783 #ifdef DEBUG
784 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
785 #endif
786 #ifdef PERFORMANCE_MEASURE
787 if (VIA_PERFORMANCE) P_M;
788 #endif
789
790 *vb++ = HC_HEADER2;
791 *vb++ = (HC_ParaType_NotTex << 16);
792 *vb++ = ((HC_SubA_HEnable << 24) | vmesa->regEnable);
793 *vb++ = ((HC_SubA_HFBBMSKL << 24) | vmesa->regHFBBMSKL);
794 *vb++ = ((HC_SubA_HROP << 24) | vmesa->regHROP);
795 i += 5;
796
797 if (vmesa->hasDepth && vmesa->hasStencil) {
798 GLuint pitch, format, offset;
799
800 format = HC_HZWBFM_24;
801
802 offset = vmesa->depth.offset;
803 pitch = vmesa->depth.pitch;
804
805 *vb++ = ((HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF));
806
807 *vb++ = ((HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24));
808 *vb++ = ((HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK |
809 format | pitch);
810 *vb++ = ((HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD);
811 /* set stencil */
812 *vb++ = ((HC_SubA_HSTREF << 24) | vmesa->regHSTREF);
813 *vb++ = ((HC_SubA_HSTMD << 24) | vmesa->regHSTMD);
814
815 i += 6;
816 }
817 else if (vmesa->hasDepth) {
818 GLuint pitch, format, offset;
819
820 if (vmesa->depthBits == 16) {
821 /* We haven't support 16bit depth yet */
822 format = HC_HZWBFM_16;
823 /*format = HC_HZWBFM_32;*/
824 #ifdef DEBUG
825 if (VIA_DEBUG) fprintf(stderr, "z format = 16\n");
826 #endif
827 }
828 else {
829 format = HC_HZWBFM_32;
830 #ifdef DEBUG
831 if (VIA_DEBUG) fprintf(stderr, "z format = 32\n");
832 #endif
833 }
834
835
836 offset = vmesa->depth.offset;
837 pitch = vmesa->depth.pitch;
838
839 *vb++ = ((HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF));
840
841 *vb++ = ((HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24));
842 *vb++ = ((HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK |
843 format | pitch);
844 *vb++ = ((HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD);
845 i += 4;
846 }
847 else if (vmesa->hasStencil) {
848 GLuint pitch, format, offset;
849
850 format = HC_HZWBFM_24;
851
852 offset = vmesa->depth.offset;
853 pitch = vmesa->depth.pitch;
854
855 *vb++ = ((HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF));
856
857 *vb++ = ((HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24));
858 *vb++ = ((HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK |
859 format | pitch);
860 *vb++ = ((HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD);
861 /* set stencil */
862 *vb++ = ((HC_SubA_HSTREF << 24) | vmesa->regHSTREF);
863 *vb++ = ((HC_SubA_HSTMD << 24) | vmesa->regHSTMD);
864
865 i += 6;
866 }
867
868 if (ctx->Color.AlphaEnabled) {
869 *vb++ = ((HC_SubA_HATMD << 24) | vmesa->regHATMD);
870 i++;
871 }
872
873 if (ctx->Color.BlendEnabled) {
874 *vb++ = ((HC_SubA_HABLCsat << 24) | vmesa->regHABLCsat);
875 *vb++ = ((HC_SubA_HABLCop << 24) | vmesa->regHABLCop);
876 *vb++ = ((HC_SubA_HABLAsat << 24) | vmesa->regHABLAsat);
877 *vb++ = ((HC_SubA_HABLAop << 24) | vmesa->regHABLAop);
878 *vb++ = ((HC_SubA_HABLRCa << 24) | vmesa->regHABLRCa);
879 *vb++ = ((HC_SubA_HABLRFCa << 24) | vmesa->regHABLRFCa);
880 *vb++ = ((HC_SubA_HABLRCbias << 24) | vmesa->regHABLRCbias);
881 *vb++ = ((HC_SubA_HABLRCb << 24) | vmesa->regHABLRCb);
882 *vb++ = ((HC_SubA_HABLRFCb << 24) | vmesa->regHABLRFCb);
883 *vb++ = ((HC_SubA_HABLRAa << 24) | vmesa->regHABLRAa);
884 *vb++ = ((HC_SubA_HABLRAb << 24) | vmesa->regHABLRAb);
885 i += 11;
886 }
887
888 if (ctx->Fog.Enabled) {
889 *vb++ = ((HC_SubA_HFogLF << 24) | vmesa->regHFogLF);
890 *vb++ = ((HC_SubA_HFogCL << 24) | vmesa->regHFogCL);
891 *vb++ = ((HC_SubA_HFogCH << 24) | vmesa->regHFogCH);
892 i += 3;
893 }
894
895 if (ctx->Line.StippleFlag) {
896 *vb++ = ((HC_SubA_HLP << 24) | ctx->Line.StipplePattern);
897 *vb++ = ((HC_SubA_HLPRF << 24) | ctx->Line.StippleFactor);
898 }
899 else {
900 *vb++ = ((HC_SubA_HLP << 24) | 0xFFFF);
901 *vb++ = ((HC_SubA_HLPRF << 24) | 0x1);
902 }
903
904 i += 2;
905
906 *vb++ = ((HC_SubA_HPixGC << 24) | 0x0);
907 i++;
908
909 if (i & 0x1) {
910 *vb++ = HC_DUMMY;
911 i++;
912 }
913
914 if (ctx->Texture._EnabledUnits) {
915
916 struct gl_texture_unit *texUnit0 = &ctx->Texture.Unit[0];
917 struct gl_texture_unit *texUnit1 = &ctx->Texture.Unit[1];
918
919 {
920 viaTextureObjectPtr t = (viaTextureObjectPtr)texUnit0->_Current->DriverData;
921 GLuint nDummyValue = 0;
922
923 *vb++ = HC_HEADER2;
924 *vb++ = (HC_ParaType_Tex << 16) | (HC_SubType_TexGeneral << 24);
925
926 if (ctx->Texture._EnabledUnits > 1) {
927 #ifdef DEBUG
928 if (VIA_DEBUG) fprintf(stderr, "multi texture\n");
929 #endif
930 nDummyValue = (HC_SubA_HTXSMD << 24) | (1 << 3);
931
932 if (t && t->needClearCache) {
933 *vb++ = nDummyValue | HC_HTXCHCLR_MASK;
934 *vb++ = nDummyValue;
935 }
936 else {
937 *vb++ = nDummyValue;
938 *vb++ = nDummyValue;
939 }
940 }
941 else {
942 #ifdef DEBUG
943 if (VIA_DEBUG) fprintf(stderr, "single texture\n");
944 #endif
945 nDummyValue = (HC_SubA_HTXSMD << 24) | 0;
946
947 if (t && t->needClearCache) {
948 *vb++ = nDummyValue | HC_HTXCHCLR_MASK;
949 *vb++ = nDummyValue;
950 }
951 else {
952 *vb++ = nDummyValue;
953 *vb++ = nDummyValue;
954 }
955 }
956 *vb++ = HC_HEADER2;
957 *vb++ = HC_ParaType_NotTex << 16;
958 *vb++ = (HC_SubA_HEnable << 24) | vmesa->regEnable;
959 *vb++ = (HC_SubA_HEnable << 24) | vmesa->regEnable;
960 i += 8;
961 }
962
963 if (texUnit0->Enabled) {
964 struct gl_texture_object *texObj = texUnit0->_Current;
965 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
966 GLuint numLevels = t->lastLevel - t->firstLevel + 1;
967 GLuint nDummyValue = 0;
968 #ifdef DEBUG
969 if (VIA_DEBUG) {
970 fprintf(stderr, "texture0 enabled\n");
971 fprintf(stderr, "texture level %d\n", t->actualLevel);
972 }
973 #endif
974 if (numLevels == 8) {
975 nDummyValue = t->regTexFM;
976 *vb++ = HC_HEADER2;
977 *vb++ = (HC_ParaType_Tex << 16) | (0 << 24);
978 *vb++ = t->regTexFM;
979 *vb++ = (HC_SubA_HTXnL0OS << 24) |
980 ((t->actualLevel) << HC_HTXnLVmax_SHIFT);
981 *vb++ = t->regTexWidthLog2[0];
982 *vb++ = t->regTexWidthLog2[1];
983 *vb++ = t->regTexHeightLog2[0];
984 *vb++ = t->regTexHeightLog2[1];
985 *vb++ = t->regTexBaseH[0];
986 *vb++ = t->regTexBaseH[1];
987 *vb++ = t->regTexBaseH[2];
988
989 *vb++ = t->regTexBaseAndPitch[0].baseL;
990 *vb++ = t->regTexBaseAndPitch[0].pitchLog2;
991 *vb++ = t->regTexBaseAndPitch[1].baseL;
992 *vb++ = t->regTexBaseAndPitch[1].pitchLog2;
993 *vb++ = t->regTexBaseAndPitch[2].baseL;
994 *vb++ = t->regTexBaseAndPitch[2].pitchLog2;
995 *vb++ = t->regTexBaseAndPitch[3].baseL;
996 *vb++ = t->regTexBaseAndPitch[3].pitchLog2;
997 *vb++ = t->regTexBaseAndPitch[4].baseL;
998 *vb++ = t->regTexBaseAndPitch[4].pitchLog2;
999 *vb++ = t->regTexBaseAndPitch[5].baseL;
1000 *vb++ = t->regTexBaseAndPitch[5].pitchLog2;
1001 *vb++ = t->regTexBaseAndPitch[6].baseL;
1002 *vb++ = t->regTexBaseAndPitch[6].pitchLog2;
1003 *vb++ = t->regTexBaseAndPitch[7].baseL;
1004 *vb++ = t->regTexBaseAndPitch[7].pitchLog2;
1005 i += 27;
1006 }
1007 else if (numLevels > 1) {
1008 nDummyValue = t->regTexFM;
1009 *vb++ = HC_HEADER2;
1010 *vb++ = (HC_ParaType_Tex << 16) | (0 << 24);
1011 *vb++ = t->regTexFM;
1012 *vb++ = (HC_SubA_HTXnL0OS << 24) |
1013 ((t->actualLevel) << HC_HTXnLVmax_SHIFT);
1014 *vb++ = t->regTexWidthLog2[0];
1015 *vb++ = t->regTexHeightLog2[0];
1016
1017 if (numLevels > 6) {
1018 *vb++ = t->regTexWidthLog2[1];
1019 *vb++ = t->regTexHeightLog2[1];
1020 i += 2;
1021 }
1022
1023 *vb++ = t->regTexBaseH[0];
1024
1025 if (numLevels > 3) {
1026 *vb++ = t->regTexBaseH[1];
1027 i++;
1028 }
1029 if (numLevels > 6) {
1030 *vb++ = t->regTexBaseH[2];
1031 i++;
1032 }
1033 if (numLevels > 9) {
1034 *vb++ = t->regTexBaseH[3];
1035 i++;
1036 }
1037
1038 i += 7;
1039
1040 for (j = 0; j < numLevels; j++) {
1041 *vb++ = t->regTexBaseAndPitch[j].baseL;
1042 *vb++ = t->regTexBaseAndPitch[j].pitchLog2;
1043 i += 2;
1044 }
1045 }
1046 else {
1047 nDummyValue = t->regTexFM;
1048 *vb++ = HC_HEADER2;
1049 *vb++ = (HC_ParaType_Tex << 16) | (0 << 24);
1050 *vb++ = t->regTexFM;
1051 *vb++ = (HC_SubA_HTXnL0OS << 24) |
1052 ((t->actualLevel) << HC_HTXnLVmax_SHIFT);
1053 *vb++ = t->regTexWidthLog2[0];
1054 *vb++ = t->regTexHeightLog2[0];
1055 *vb++ = t->regTexBaseH[0];
1056 *vb++ = t->regTexBaseAndPitch[0].baseL;
1057 *vb++ = t->regTexBaseAndPitch[0].pitchLog2;
1058 i += 9;
1059 }
1060
1061 *vb++ = (HC_SubA_HTXnTB << 24) | vmesa->regHTXnTB_0;
1062 *vb++ = (HC_SubA_HTXnMPMD << 24) | vmesa->regHTXnMPMD_0;
1063 *vb++ = (HC_SubA_HTXnTBLCsat << 24) | vmesa->regHTXnTBLCsat_0;
1064 *vb++ = (HC_SubA_HTXnTBLCop << 24) | vmesa->regHTXnTBLCop_0;
1065 *vb++ = (HC_SubA_HTXnTBLMPfog << 24) | vmesa->regHTXnTBLMPfog_0;
1066 *vb++ = (HC_SubA_HTXnTBLAsat << 24) | vmesa->regHTXnTBLAsat_0;
1067 *vb++ = (HC_SubA_HTXnTBLRCb << 24) | vmesa->regHTXnTBLRCb_0;
1068 *vb++ = (HC_SubA_HTXnTBLRAa << 24) | vmesa->regHTXnTBLRAa_0;
1069 *vb++ = (HC_SubA_HTXnTBLRFog << 24) | vmesa->regHTXnTBLRFog_0;
1070 i += 9;
1071 /*=* John Sheng [2003.7.18] texture combine */
1072 *vb++ = (HC_SubA_HTXnTBLRCa << 24) | vmesa->regHTXnTBLRCa_0;
1073 *vb++ = (HC_SubA_HTXnTBLRCc << 24) | vmesa->regHTXnTBLRCc_0;
1074 *vb++ = (HC_SubA_HTXnTBLRCbias << 24) | vmesa->regHTXnTBLRCbias_0;
1075 i += 3;
1076
1077 if (t->regTexFM == HC_HTXnFM_Index8) {
1078 struct gl_color_table *table = &texObj->Palette;
1079 GLfloat *tableF = (GLfloat *)table->Table;
1080
1081 *vb++ = HC_HEADER2;
1082 *vb++ = (HC_ParaType_Palette << 16) | (0 << 24);
1083 i += 2;
1084 for (j = 0; j < table->Size; j++) {
1085 *vb++ = tableF[j];
1086 i++;
1087 }
1088 }
1089 if (i & 0x1) {
1090 *vb++ = HC_DUMMY;
1091 i++;
1092 }
1093 }
1094
1095 if (texUnit1->Enabled) {
1096 struct gl_texture_object *texObj = texUnit1->_Current;
1097 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
1098 GLuint numLevels = t->lastLevel - t->firstLevel + 1;
1099 GLuint nDummyValue = 0;
1100 #ifdef DEBUG
1101 if (VIA_DEBUG) {
1102 fprintf(stderr, "texture1 enabled\n");
1103 fprintf(stderr, "texture level %d\n", t->actualLevel);
1104 }
1105 #endif
1106 if (numLevels == 8) {
1107 nDummyValue = t->regTexFM;
1108 *vb++ = HC_HEADER2;
1109 *vb++ = (HC_ParaType_Tex << 16) | (1 << 24);
1110 *vb++ = t->regTexFM;
1111 *vb++ = (HC_SubA_HTXnL0OS << 24) |
1112 ((t->actualLevel) << HC_HTXnLVmax_SHIFT);
1113 *vb++ = t->regTexWidthLog2[0];
1114 *vb++ = t->regTexWidthLog2[1];
1115 *vb++ = t->regTexHeightLog2[0];
1116 *vb++ = t->regTexHeightLog2[1];
1117 *vb++ = t->regTexBaseH[0];
1118 *vb++ = t->regTexBaseH[1];
1119 *vb++ = t->regTexBaseH[2];
1120
1121 *vb++ = t->regTexBaseAndPitch[0].baseL;
1122 *vb++ = t->regTexBaseAndPitch[0].pitchLog2;
1123 *vb++ = t->regTexBaseAndPitch[1].baseL;
1124 *vb++ = t->regTexBaseAndPitch[1].pitchLog2;
1125 *vb++ = t->regTexBaseAndPitch[2].baseL;
1126 *vb++ = t->regTexBaseAndPitch[2].pitchLog2;
1127 *vb++ = t->regTexBaseAndPitch[3].baseL;
1128 *vb++ = t->regTexBaseAndPitch[3].pitchLog2;
1129 *vb++ = t->regTexBaseAndPitch[4].baseL;
1130 *vb++ = t->regTexBaseAndPitch[4].pitchLog2;
1131 *vb++ = t->regTexBaseAndPitch[5].baseL;
1132 *vb++ = t->regTexBaseAndPitch[5].pitchLog2;
1133 *vb++ = t->regTexBaseAndPitch[6].baseL;
1134 *vb++ = t->regTexBaseAndPitch[6].pitchLog2;
1135 *vb++ = t->regTexBaseAndPitch[7].baseL;
1136 *vb++ = t->regTexBaseAndPitch[7].pitchLog2;
1137 i += 27;
1138 }
1139 else if (numLevels > 1) {
1140 nDummyValue = t->regTexFM;
1141 *vb++ = HC_HEADER2;
1142 *vb++ = (HC_ParaType_Tex << 16) | (1 << 24);
1143 *vb++ = t->regTexFM;
1144 *vb++ = (HC_SubA_HTXnL0OS << 24) |
1145 ((t->actualLevel) << HC_HTXnLVmax_SHIFT);
1146 *vb++ = t->regTexWidthLog2[0];
1147 *vb++ = t->regTexHeightLog2[0];
1148
1149 if (numLevels > 6) {
1150 *vb++ = t->regTexWidthLog2[1];
1151 *vb++ = t->regTexHeightLog2[1];
1152 i += 2;
1153 }
1154
1155 *vb++ = t->regTexBaseH[0];
1156
1157 if (numLevels > 3) {
1158 *vb++ = t->regTexBaseH[1];
1159 i++;
1160 }
1161 if (numLevels > 6) {
1162 *vb++ = t->regTexBaseH[2];
1163 i++;
1164 }
1165 if (numLevels > 9) {
1166 *vb++ = t->regTexBaseH[3];
1167 i++;
1168 }
1169
1170 i += 7;
1171
1172 for (j = 0; j < numLevels; j++) {
1173 *vb++ = t->regTexBaseAndPitch[j].baseL;
1174 *vb++ = t->regTexBaseAndPitch[j].pitchLog2;
1175 i += 2;
1176 }
1177 }
1178 else {
1179 nDummyValue = t->regTexFM;
1180 *vb++ = HC_HEADER2;
1181 *vb++ = (HC_ParaType_Tex << 16) | (1 << 24);
1182 *vb++ = t->regTexFM;
1183 *vb++ = (HC_SubA_HTXnL0OS << 24) |
1184 ((t->actualLevel) << HC_HTXnLVmax_SHIFT);
1185 *vb++ = t->regTexWidthLog2[0];
1186 *vb++ = t->regTexHeightLog2[0];
1187 *vb++ = t->regTexBaseH[0];
1188 *vb++ = t->regTexBaseAndPitch[0].baseL;
1189 *vb++ = t->regTexBaseAndPitch[0].pitchLog2;
1190 i += 9;
1191 }
1192
1193 *vb++ = (HC_SubA_HTXnTB << 24) | vmesa->regHTXnTB_1;
1194 *vb++ = (HC_SubA_HTXnMPMD << 24) | vmesa->regHTXnMPMD_1;
1195 *vb++ = (HC_SubA_HTXnTBLCsat << 24) | vmesa->regHTXnTBLCsat_1;
1196 *vb++ = (HC_SubA_HTXnTBLCop << 24) | vmesa->regHTXnTBLCop_1;
1197 *vb++ = (HC_SubA_HTXnTBLMPfog << 24) | vmesa->regHTXnTBLMPfog_1;
1198 *vb++ = (HC_SubA_HTXnTBLAsat << 24) | vmesa->regHTXnTBLAsat_1;
1199 *vb++ = (HC_SubA_HTXnTBLRCb << 24) | vmesa->regHTXnTBLRCb_1;
1200 *vb++ = (HC_SubA_HTXnTBLRAa << 24) | vmesa->regHTXnTBLRAa_1;
1201 *vb++ = (HC_SubA_HTXnTBLRFog << 24) | vmesa->regHTXnTBLRFog_1;
1202 i += 9;
1203
1204 if (t->regTexFM == HC_HTXnFM_Index8) {
1205 struct gl_color_table *table = &texObj->Palette;
1206 GLfloat *tableF = (GLfloat *)table->Table;
1207
1208 *vb++ = HC_HEADER2;
1209 *vb++ = (HC_ParaType_Palette << 16) | (1 << 24);
1210 i += 2;
1211 for (j = 0; j < table->Size; j++) {
1212 *vb++ = tableF[j];
1213 i++;
1214 }
1215 }
1216 if (i & 0x1) {
1217 *vb++ = HC_DUMMY;
1218 i++;
1219 }
1220 }
1221 }
1222
1223
1224 if (ctx->Polygon.StippleFlag) {
1225 GLuint *stipple = &ctx->PolygonStipple[0];
1226
1227 *vb++ = HC_HEADER2;
1228 *vb++ = ((HC_ParaType_Palette << 16) | (HC_SubType_Stipple << 24));
1229
1230 *vb++ = stipple[31];
1231 *vb++ = stipple[30];
1232 *vb++ = stipple[29];
1233 *vb++ = stipple[28];
1234 *vb++ = stipple[27];
1235 *vb++ = stipple[26];
1236 *vb++ = stipple[25];
1237 *vb++ = stipple[24];
1238 *vb++ = stipple[23];
1239 *vb++ = stipple[22];
1240 *vb++ = stipple[21];
1241 *vb++ = stipple[20];
1242 *vb++ = stipple[19];
1243 *vb++ = stipple[18];
1244 *vb++ = stipple[17];
1245 *vb++ = stipple[16];
1246 *vb++ = stipple[15];
1247 *vb++ = stipple[14];
1248 *vb++ = stipple[13];
1249 *vb++ = stipple[12];
1250 *vb++ = stipple[11];
1251 *vb++ = stipple[10];
1252 *vb++ = stipple[9];
1253 *vb++ = stipple[8];
1254 *vb++ = stipple[7];
1255 *vb++ = stipple[6];
1256 *vb++ = stipple[5];
1257 *vb++ = stipple[4];
1258 *vb++ = stipple[3];
1259 *vb++ = stipple[2];
1260 *vb++ = stipple[1];
1261 *vb++ = stipple[0];
1262
1263 *vb++ = HC_HEADER2;
1264 *vb++ = (HC_ParaType_NotTex << 16);
1265 *vb++ = ((HC_SubA_HSPXYOS << 24) | (0x20 - (vmesa->driDrawable->h & 0x1F)));
1266 *vb++ = ((HC_SubA_HSPXYOS << 24) | (0x20 - (vmesa->driDrawable->h & 0x1F)));
1267 i += 38;
1268 }
1269
1270 vmesa->dmaLow += (i << 2);
1271
1272 vmesa->dirty = 0;
1273 #ifdef DEBUG
1274 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1275 #endif
1276 }
1277
1278
1279 static void emit_partial_state(viaContextPtr vmesa)
1280 {
1281 GLcontext *ctx = vmesa->glCtx;
1282 GLuint dirty = vmesa->dirty;
1283 GLuint *vb = viaCheckDma(vmesa, 0x110);
1284 GLuint i = 0;
1285
1286 #ifdef DEBUG
1287 if( VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1288 #endif
1289
1290 #ifdef PERFORMANCE_MEASURE
1291 if (VIA_PERFORMANCE) P_M;
1292 #endif
1293 vb = vb;
1294
1295 *vb++ = HC_HEADER2;
1296 *vb++ = (HC_ParaType_NotTex << 16);
1297 *vb++ = ((HC_SubA_HEnable << 24) | vmesa->regEnable);
1298 *vb++ = ((HC_SubA_HFBBMSKL << 24) | vmesa->regHFBBMSKL);
1299 *vb++ = ((HC_SubA_HROP << 24) | vmesa->regHROP);
1300 i += 5;
1301
1302 if (dirty & VIA_UPLOAD_DESTBUFFER) {
1303 }
1304
1305 if (dirty & VIA_UPLOAD_DEPTHBUFFER) {
1306 }
1307
1308 if (dirty * VIA_UPLOAD_DEPTH) {
1309 *vb++ = ((HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD);
1310 i++;
1311 }
1312
1313 if (dirty * VIA_UPLOAD_ALPHATEST) {
1314 *vb++ = ((HC_SubA_HATMD << 24) | vmesa->regHATMD);
1315 i++;
1316 }
1317
1318
1319 if (dirty & VIA_UPLOAD_BLEND) {
1320 *vb++ = ((HC_SubA_HABLCsat << 24) | vmesa->regHABLCsat);
1321 *vb++ = ((HC_SubA_HABLCop << 24) | vmesa->regHABLCop);
1322 *vb++ = ((HC_SubA_HABLAsat << 24) | vmesa->regHABLAsat);
1323 *vb++ = ((HC_SubA_HABLAop << 24) | vmesa->regHABLAop);
1324 *vb++ = ((HC_SubA_HABLRCa << 24) | vmesa->regHABLRCa);
1325 *vb++ = ((HC_SubA_HABLRFCa << 24) | vmesa->regHABLRFCa);
1326 *vb++ = ((HC_SubA_HABLRCbias << 24) | vmesa->regHABLRCbias);
1327 *vb++ = ((HC_SubA_HABLRCb << 24) | vmesa->regHABLRCb);
1328 *vb++ = ((HC_SubA_HABLRFCb << 24) | vmesa->regHABLRFCb);
1329 *vb++ = ((HC_SubA_HABLRAa << 24) | vmesa->regHABLRAa);
1330 *vb++ = ((HC_SubA_HABLRAb << 24) | vmesa->regHABLRAb);
1331 i += 11;
1332 }
1333
1334 if (dirty & VIA_UPLOAD_FOG) {
1335 *vb++ = ((HC_SubA_HFogLF << 24) | vmesa->regHFogLF);
1336 *vb++ = ((HC_SubA_HFogCL << 24) | vmesa->regHFogCL);
1337 *vb++ = ((HC_SubA_HFogCH << 24) | vmesa->regHFogCH);
1338 i += 3;
1339 }
1340
1341 if (dirty & VIA_UPLOAD_LINESTIPPLE) {
1342 *vb++ = ((HC_SubA_HLP << 24) | ctx->Line.StipplePattern);
1343 *vb++ = ((HC_SubA_HLPRF << 24) | ctx->Line.StippleFactor);
1344 }
1345 else {
1346 *vb++ = ((HC_SubA_HLP << 24) | 0xFFFF);
1347 *vb++ = ((HC_SubA_HLPRF << 24) | 0x1);
1348 }
1349 i += 2;
1350
1351 *vb++ = ((HC_SubA_HPixGC << 24) | 0x0);
1352 i++;
1353
1354 if (i & 0x1) {
1355 *vb++ = HC_DUMMY;
1356 i++;
1357 }
1358
1359 if (dirty & VIA_UPLOAD_TEXTURE) {
1360
1361 }
1362
1363 if (dirty & VIA_UPLOAD_POLYGONSTIPPLE) {
1364
1365 }
1366
1367 vmesa->dmaLow += (i << 2);
1368
1369 vmesa->dirty = 0;
1370 #ifdef DEBUG
1371 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1372 #endif
1373 }
1374
1375 /**********************************************************************/
1376 /* High level hooks for t_vb_render.c */
1377 /**********************************************************************/
1378
1379 /* Determine the rasterized primitive when not drawing unfilled
1380 * polygons.
1381 *
1382 * Used only for the default render stage which always decomposes
1383 * primitives to trianges/lines/points. For the accelerated stage,
1384 * which renders strips as strips, the equivalent calculations are
1385 * performed in via_render.c.
1386 */
1387 static void viaRenderPrimitive(GLcontext *ctx, GLenum prim)
1388 {
1389 viaContextPtr vmesa = VIA_CONTEXT(ctx);
1390 GLuint rprim = reducedPrim[prim];
1391 #ifdef DEBUG
1392 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1393 #endif
1394 vmesa->renderPrimitive = prim;
1395 viaRasterPrimitive(ctx, rprim, rprim);
1396 #ifdef DEBUG
1397 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1398 #endif
1399 }
1400
1401 static void viaRunPipeline(GLcontext *ctx)
1402 {
1403 viaContextPtr vmesa = VIA_CONTEXT(ctx);
1404 #ifdef DEBUG
1405 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1406
1407 if (VIA_DEBUG) fprintf(stderr, "newState = %x\n", vmesa->newState);
1408 #endif
1409
1410 if (vmesa->newState) {
1411 if (vmesa->newState & _NEW_TEXTURE)
1412 viaUpdateTextureState(ctx); /* may modify vmesa->newState */
1413
1414 viaChooseVertexState(ctx);
1415 viaChooseRenderState(ctx);
1416 vmesa->newState = 0;
1417 }
1418
1419 if (vmesa->needUploadAllState)
1420 emit_all_state(vmesa);
1421 else
1422 emit_partial_state(vmesa);
1423
1424 _tnl_run_pipeline(ctx);
1425 #ifdef DEBUG
1426 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1427 #endif
1428 }
1429
1430 static void viaRenderStart(GLcontext *ctx)
1431 {
1432 #ifdef DEBUG
1433 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1434 #endif
1435
1436 /* Check for projective texturing. Make sure all texcoord
1437 * pointers point to something. (fix in mesa?)
1438 */
1439 viaCheckTexSizes(ctx);
1440 #ifdef DEBUG
1441 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1442 #endif
1443 }
1444
1445 static void viaRenderFinish(GLcontext *ctx)
1446 {
1447 #ifdef DEBUG
1448 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1449 #endif
1450 if (VIA_CONTEXT(ctx)->renderIndex & VIA_FALLBACK_BIT)
1451 _swrast_flush(ctx);
1452 #ifdef DEBUG
1453 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1454 #endif
1455 }
1456
1457
1458 /* System to flush dma and emit state changes based on the rasterized
1459 * primitive.
1460 */
1461 void viaRasterPrimitive(GLcontext *ctx,
1462 GLenum rprim,
1463 GLuint hwprim)
1464 {
1465 viaContextPtr vmesa = VIA_CONTEXT(ctx);
1466 GLuint *vb = viaCheckDma(vmesa, 32);
1467 GLuint regCmdB;
1468 #ifdef DEBUG
1469 if (VIA_DEBUG) {
1470 fprintf(stderr, "%s - in\n", __FUNCTION__);
1471 fprintf(stderr, "hwprim = %x\n", hwprim);
1472 }
1473 #endif
1474 /*=* [DBG] exy : fix wireframe + clipping error *=*/
1475 if (((rprim == GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED)))) {
1476 hwprim = GL_LINES;
1477 }
1478
1479 if (RasterCounter > 0) {
1480
1481 #ifdef DEBUG
1482 if (VIA_DEBUG) fprintf(stderr, "enter twice:%d\n",RasterCounter);
1483 #endif
1484 RasterCounter++;
1485 return;
1486 }
1487 RasterCounter++;
1488
1489 vmesa->primitiveRendered = GL_FALSE;
1490 regCmdB = vmesa->regCmdB;
1491
1492 switch (hwprim) {
1493 case GL_POINTS:
1494 #ifdef DEBUG
1495 if (VIA_DEBUG) fprintf(stderr, "Points\n");
1496 #endif
1497 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Point | HC_HVCycle_Full;
1498 if (ctx->Light.ShadeModel == GL_FLAT)
1499 vmesa->regCmdA_End |= HC_HShading_FlatA;
1500 break;
1501 case GL_LINES:
1502 #ifdef DEBUG
1503 if (VIA_DEBUG) fprintf(stderr, "Lines\n");
1504 #endif
1505 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Line | HC_HVCycle_Full;
1506 if (ctx->Light.ShadeModel == GL_FLAT)
1507 vmesa->regCmdA_End |= HC_HShading_FlatB;
1508 break;
1509 case GL_LINE_LOOP:
1510 case GL_LINE_STRIP:
1511 #ifdef DEBUG
1512 if (VIA_DEBUG) fprintf(stderr, "Line Loop / Line Strip\n");
1513 #endif
1514 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Line | HC_HVCycle_AFP |
1515 HC_HVCycle_AB | HC_HVCycle_NewB;
1516 regCmdB |= HC_HVCycle_AB | HC_HVCycle_NewB | HC_HLPrst_MASK;
1517 if (ctx->Light.ShadeModel == GL_FLAT)
1518 vmesa->regCmdA_End |= HC_HShading_FlatB;
1519 break;
1520 case GL_TRIANGLES:
1521 #ifdef DEBUG
1522 if (VIA_DEBUG) fprintf(stderr, "Triangles\n");
1523 #endif
1524 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Tri | HC_HVCycle_Full;
1525 if (ctx->Light.ShadeModel == GL_FLAT)
1526 vmesa->regCmdA_End |= HC_HShading_FlatC;
1527 break;
1528 case GL_TRIANGLE_STRIP:
1529 #ifdef DEBUG
1530 if (VIA_DEBUG) fprintf(stderr, "Triangle Strip\n");
1531 #endif
1532 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Tri | HC_HVCycle_AFP |
1533 HC_HVCycle_AC | HC_HVCycle_BB | HC_HVCycle_NewC;
1534 regCmdB |= HC_HVCycle_AA | HC_HVCycle_BC | HC_HVCycle_NewC;
1535 if (ctx->Light.ShadeModel == GL_FLAT)
1536 vmesa->regCmdA_End |= HC_HShading_FlatB;
1537 break;
1538 case GL_TRIANGLE_FAN:
1539 #ifdef DEBUG
1540 if (VIA_DEBUG) fprintf(stderr, "Triangle Fan\n");
1541 #endif
1542 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Tri | HC_HVCycle_AFP |
1543 HC_HVCycle_AA | HC_HVCycle_BC | HC_HVCycle_NewC;
1544 regCmdB |= HC_HVCycle_AA | HC_HVCycle_BC | HC_HVCycle_NewC;
1545 if (ctx->Light.ShadeModel == GL_FLAT)
1546 vmesa->regCmdA_End |= HC_HShading_FlatC;
1547 break;
1548 case GL_QUADS:
1549 #ifdef DEBUG
1550 if (VIA_DEBUG) fprintf(stderr, "No HW Quads\n");
1551 #endif
1552 return;
1553 case GL_QUAD_STRIP:
1554 #ifdef DEBUG
1555 if (VIA_DEBUG) fprintf(stderr, "No HW Quad Strip\n");
1556 #endif
1557 return;
1558 case GL_POLYGON:
1559 #ifdef DEBUG
1560 if (VIA_DEBUG) fprintf(stderr, "Polygon\n");
1561 #endif
1562 vmesa->regCmdA_End = vmesa->regCmdA | HC_HPMType_Tri | HC_HVCycle_AFP |
1563 HC_HVCycle_AA | HC_HVCycle_BC | HC_HVCycle_NewC;
1564 regCmdB |= HC_HVCycle_AA | HC_HVCycle_BC | HC_HVCycle_NewC;
1565 if (ctx->Light.ShadeModel == GL_FLAT)
1566 vmesa->regCmdA_End |= HC_HShading_FlatC;
1567 break;
1568 default:
1569 #ifdef DEBUG
1570 if (VIA_DEBUG) fprintf(stderr, "Unknow\n");
1571 #endif
1572 return;
1573 }
1574
1575 *vb++ = HC_HEADER2;
1576 *vb++ = (HC_ParaType_NotTex << 16);
1577 *vb++ = 0xCCCCCCCC;
1578 *vb++ = 0xDDDDDDDD;
1579
1580 *vb++ = HC_HEADER2;
1581 *vb++ = (HC_ParaType_CmdVdata << 16);
1582 *vb++ = regCmdB;
1583 *vb++ = vmesa->regCmdA_End;
1584 vmesa->dmaLow += 32;
1585
1586 vmesa->reducedPrimitive = rprim;
1587 vmesa->hwPrimitive = rprim;
1588 #ifdef DEBUG
1589 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1590 #endif
1591 }
1592
1593 void viaRasterPrimitiveFinish(GLcontext *ctx)
1594 {
1595 viaContextPtr vmesa = VIA_CONTEXT(ctx);
1596 #ifdef DEBUG
1597 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
1598
1599 if (VIA_DEBUG) fprintf(stderr, "primitiveRendered = %x\n", vmesa->primitiveRendered);
1600 #endif
1601 if (RasterCounter > 1) {
1602 RasterCounter--;
1603 #ifdef DEBUG
1604 if (VIA_DEBUG) fprintf(stderr, "finish enter twice: %d\n",RasterCounter);
1605 #endif
1606 return;
1607 }
1608 RasterCounter = 0;
1609
1610
1611 if (vmesa->primitiveRendered) {
1612 GLuint *vb = viaCheckDma(vmesa, 0);
1613 GLuint cmdA = vmesa->regCmdA_End | HC_HPLEND_MASK | HC_HPMValidN_MASK | HC_HE3Fire_MASK;
1614
1615 /*=* John Sheng [2003.6.20] fix pci *=*/
1616 /*if (vmesa->dmaLow & 0x1) {*/
1617 if (vmesa->dmaLow & 0x1 || !vmesa->useAgp) {
1618 *vb++ = cmdA ;
1619 vmesa->dmaLow += 4;
1620 }
1621 else {
1622 *vb++ = cmdA;
1623 *vb++ = cmdA;
1624 vmesa->dmaLow += 8;
1625 }
1626 }
1627 else {
1628 if (vmesa->dmaLow >= (32 + DMA_OFFSET))
1629 vmesa->dmaLow -= 32;
1630 }
1631
1632 if (0) viaFlushPrimsLocked(vmesa);
1633 if (0) {
1634 volatile GLuint *pnMMIOBase = vmesa->regMMIOBase;
1635 volatile GLuint *pnEngBase = (volatile GLuint *)((GLuint)pnMMIOBase + 0x400);
1636 int nStatus = *pnEngBase;
1637 if (((nStatus & 0xFFFEFFFF) == 0x00020000)) {
1638 #ifdef PERFORMANCE_MEASURE
1639 idle++;
1640 #endif
1641 viaFlushPrims(vmesa);
1642 }
1643 #ifdef PERFORMANCE_MEASURE
1644 else {
1645 busy++;
1646 }
1647 #endif
1648 }
1649 #ifdef DEBUG
1650 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
1651 #endif
1652 }
1653
1654
1655 /**********************************************************************/
1656 /* Transition to/from hardware rasterization. */
1657 /**********************************************************************/
1658
1659
1660 void viaFallback(viaContextPtr vmesa, GLuint bit, GLboolean mode)
1661 {
1662 GLcontext *ctx = vmesa->glCtx;
1663 TNLcontext *tnl = TNL_CONTEXT(ctx);
1664 GLuint oldfallback = vmesa->Fallback;
1665 #ifdef DEBUG
1666 if (VIA_DEBUG) fprintf(stderr, "%s old %x bit %x mode %d\n", __FUNCTION__,
1667 vmesa->Fallback, bit, mode);
1668 #endif
1669
1670 if (mode) {
1671 vmesa->Fallback |= bit;
1672 if (oldfallback == 0) {
1673 #ifdef DEBUG
1674 if (VIA_DEBUG) fprintf(stderr, "ENTER FALLBACK\n");
1675 #endif
1676 VIA_FIREVERTICES(vmesa);
1677 _swsetup_Wakeup(ctx);
1678 vmesa->renderIndex = ~0;
1679 }
1680 }
1681 else {
1682 vmesa->Fallback &= ~bit;
1683 if (oldfallback == bit) {
1684 #ifdef DEBUG
1685 if (VIA_DEBUG) fprintf(stderr, "LEAVE FALLBACK\n");
1686 #endif
1687 tnl->Driver.Render.Start = viaRenderStart;
1688 tnl->Driver.Render.PrimitiveNotify = viaRenderPrimitive;
1689 tnl->Driver.Render.Finish = viaRenderFinish;
1690 tnl->Driver.Render.BuildVertices = viaBuildVertices;
1691 vmesa->newState |= (_VIA_NEW_RENDERSTATE|_VIA_NEW_VERTEX);
1692 }
1693 }
1694
1695 }
1696
1697
1698 /**********************************************************************/
1699 /* Initialization. */
1700 /**********************************************************************/
1701
1702
1703 void viaInitTriFuncs(GLcontext *ctx)
1704 {
1705 TNLcontext *tnl = TNL_CONTEXT(ctx);
1706 static int firsttime = 1;
1707
1708 if (firsttime) {
1709 init_rast_tab();
1710 firsttime = 0;
1711 }
1712
1713 tnl->Driver.RunPipeline = viaRunPipeline;
1714 tnl->Driver.Render.Start = viaRenderStart;
1715 tnl->Driver.Render.Finish = viaRenderFinish;
1716 tnl->Driver.Render.PrimitiveNotify = viaRenderPrimitive;
1717 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
1718 tnl->Driver.Render.BuildVertices = viaBuildVertices;
1719 }