2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
34 #include "swrast/swrast.h"
35 #include "swrast_setup/swrast_setup.h"
36 #include "tnl/t_context.h"
37 #include "tnl/t_pipeline.h"
39 #include "via_context.h"
41 #include "via_state.h"
43 #include "via_ioctl.h"
45 static void viaRenderPrimitive(GLcontext
*ctx
, GLenum prim
);
46 GLuint RasterCounter
= 0;
49 /***********************************************************************
50 * Emit primitives as inline vertices *
51 ***********************************************************************/
53 #if defined(USE_X86_ASM)
54 #define COPY_DWORDS(j, vb, vertsize, v) \
57 __asm__ __volatile__("rep ; movsl" \
58 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
64 #define COPY_DWORDS(j, vb, vertsize, v) \
66 for (j = 0; j < vertsize; j++) \
67 vb[j] = ((GLuint *)v)[j]; \
72 static void __inline__
via_draw_triangle(viaContextPtr vmesa
,
77 GLuint vertsize
= vmesa
->vertexSize
;
78 GLuint
*vb
= viaCheckDma(vmesa
, 3 * 4 * vertsize
);
81 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
82 #ifdef PERFORMANCE_MEASURE
83 if (VIA_PERFORMANCE
) P_M
;
85 COPY_DWORDS(j
, vb
, vertsize
, v0
);
86 COPY_DWORDS(j
, vb
, vertsize
, v1
);
87 COPY_DWORDS(j
, vb
, vertsize
, v2
);
88 vmesa
->dmaLow
+= 3 * 4 * vertsize
;
89 vmesa
->primitiveRendered
= GL_TRUE
;
90 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
94 static void __inline__
via_draw_quad(viaContextPtr vmesa
,
100 GLuint vertsize
= vmesa
->vertexSize
;
101 GLuint
*vb
= viaCheckDma(vmesa
, 6 * 4 * vertsize
);
103 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
104 #ifdef PERFORMANCE_MEASURE
105 if (VIA_PERFORMANCE
) P_M
;
107 COPY_DWORDS(j
, vb
, vertsize
, v0
);
108 COPY_DWORDS(j
, vb
, vertsize
, v1
);
109 COPY_DWORDS(j
, vb
, vertsize
, v3
);
110 COPY_DWORDS(j
, vb
, vertsize
, v1
);
111 COPY_DWORDS(j
, vb
, vertsize
, v2
);
112 COPY_DWORDS(j
, vb
, vertsize
, v3
);
113 vmesa
->dmaLow
+= 6 * 4 * vertsize
;
114 vmesa
->primitiveRendered
= GL_TRUE
;
115 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
119 static __inline__
void via_draw_point(viaContextPtr vmesa
,
122 /*GLfloat sz = vmesa->glCtx->Point._Size * .5;*/
123 int vertsize
= vmesa
->vertexSize
;
124 /*GLuint *vb = viaCheckDma(vmesa, 2 * 4 * vertsize);*/
125 GLuint
*vb
= viaCheckDma(vmesa
, 4 * vertsize
);
127 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
128 #ifdef PERFORMANCE_MEASURE
129 if (VIA_PERFORMANCE
) P_M
;
131 COPY_DWORDS(j
, vb
, vertsize
, v0
);
132 vmesa
->dmaLow
+= 4 * vertsize
;
133 vmesa
->primitiveRendered
= GL_TRUE
;
134 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
139 * Draw line in hardware.
142 static __inline__
void via_draw_line(viaContextPtr vmesa
,
146 GLuint vertsize
= vmesa
->vertexSize
;
147 GLuint
*vb
= viaCheckDma(vmesa
, 2 * 4 * vertsize
);
149 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
150 #ifdef PERFORMANCE_MEASURE
151 if (VIA_PERFORMANCE
) P_M
;
153 COPY_DWORDS(j
, vb
, vertsize
, v0
);
154 COPY_DWORDS(j
, vb
, vertsize
, v1
);
155 vmesa
->dmaLow
+= 2 * 4 * vertsize
;
156 vmesa
->primitiveRendered
= GL_TRUE
;
157 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
161 /***********************************************************************
162 * Macros for via_dd_tritmp.h to draw basic primitives *
163 ***********************************************************************/
165 #define TRI(a, b, c) \
167 if (VIA_DEBUG) fprintf(stderr, "hw TRI\n"); \
169 vmesa->drawTri(vmesa, a, b, c); \
171 via_draw_triangle(vmesa, a, b, c); \
174 #define QUAD(a, b, c, d) \
176 if (VIA_DEBUG) fprintf(stderr, "hw QUAD\n");\
178 vmesa->drawTri(vmesa, a, b, d); \
179 vmesa->drawTri(vmesa, b, c, d); \
182 via_draw_quad(vmesa, a, b, c, d); \
185 #define LINE(v0, v1) \
187 if(VIA_DEBUG) fprintf(stderr, "hw LINE\n");\
189 vmesa->drawLine(vmesa, v0, v1); \
191 via_draw_line(vmesa, v0, v1); \
196 if (VIA_DEBUG) fprintf(stderr, "hw POINT\n");\
198 vmesa->drawPoint(vmesa, v0); \
200 via_draw_point(vmesa, v0); \
204 /***********************************************************************
205 * Build render functions from dd templates *
206 ***********************************************************************/
208 #define VIA_OFFSET_BIT 0x01
209 #define VIA_TWOSIDE_BIT 0x02
210 #define VIA_UNFILLED_BIT 0x04
211 #define VIA_FALLBACK_BIT 0x08
212 #define VIA_MAX_TRIFUNC 0x10
216 tnl_points_func points
;
218 tnl_triangle_func triangle
;
220 } rast_tab
[VIA_MAX_TRIFUNC
];
223 #define DO_FALLBACK (IND & VIA_FALLBACK_BIT)
224 #define DO_OFFSET (IND & VIA_OFFSET_BIT)
225 #define DO_UNFILLED (IND & VIA_UNFILLED_BIT)
226 #define DO_TWOSIDE (IND & VIA_TWOSIDE_BIT)
232 #define DO_FULL_QUAD 1
236 #define HAVE_BACK_COLORS 0
237 #define HAVE_HW_FLATSHADE 1
238 #define VERTEX viaVertex
241 /* Only used to pull back colors into vertices (ie, we know color is
244 #define VIA_COLOR(dst, src) \
252 #define VIA_SPEC(dst, src) \
260 #define DEPTH_SCALE (1.0 / 0xffff)
261 #define UNFILLED_TRI unfilled_tri
262 #define UNFILLED_QUAD unfilled_quad
263 #define VERT_X(_v) _v->v.x
264 #define VERT_Y(_v) _v->v.y
265 #define VERT_Z(_v) _v->v.z
266 #define AREA_IS_CCW(a) (a > 0)
267 #define GET_VERTEX(e) (vmesa->verts + (e<<vmesa->vertexStrideShift))
269 #define VERT_SET_RGBA(v, c) VIA_COLOR(v->ub4[coloroffset], c)
270 #define VERT_COPY_RGBA(v0, v1) v0->ui[coloroffset] = v1->ui[coloroffset]
271 #define VERT_SAVE_RGBA(idx) color[idx] = v[idx]->ui[coloroffset]
272 #define VERT_RESTORE_RGBA(idx) v[idx]->ui[coloroffset] = color[idx]
273 #define VERT_SET_SPEC(v, c) if (havespec) VIA_SPEC(v->ub4[5], c)
274 #define VERT_COPY_SPEC(v0, v1) if (havespec) COPY_3V(v0->ub4[5], v1->ub4[5])
275 #define VERT_SAVE_SPEC(idx) if (havespec) spec[idx] = v[idx]->ui[5]
276 #define VERT_RESTORE_SPEC(idx) if (havespec) v[idx]->ui[5] = spec[idx]
278 #define SET_PRIMITIVE_RENDERED vmesa->primitiveRendered = GL_TRUE;
280 #define LOCAL_VARS(n) \
281 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
282 GLuint color[n], spec[n]; \
283 GLuint coloroffset = (vmesa->vertexSize == 4 ? 3 : 4); \
284 GLboolean havespec = (vmesa->vertexSize > 4); \
285 (void)color; (void)spec; (void)coloroffset; (void)havespec;
288 /***********************************************************************
289 * Helpers for rendering unfilled primitives *
290 ***********************************************************************/
292 static const GLuint hwPrim[GL_POLYGON + 1] = {
306 #define RASTERIZE(x) \
307 if (vmesa->hwPrimitive != x) { \
308 viaRasterPrimitiveFinish(ctx); \
309 viaRasterPrimitive(ctx, x, x); \
312 #define RENDER_PRIMITIVE vmesa->renderPrimitive
314 #define IND VIA_FALLBACK_BIT
315 #include "tnl_dd/t_dd_unfilled.h"
319 /***********************************************************************
320 * Generate GL render functions *
321 ***********************************************************************/
326 #include "via_dd_tritmp.h"
328 #define IND (VIA_OFFSET_BIT)
329 #define TAG(x) x##_offset
330 #include "via_dd_tritmp.h"
332 #define IND (VIA_TWOSIDE_BIT)
333 #define TAG(x) x##_twoside
334 #include "via_dd_tritmp.h"
336 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT)
337 #define TAG(x) x##_twoside_offset
338 #include "via_dd_tritmp.h"
340 #define IND (VIA_UNFILLED_BIT)
341 #define TAG(x) x##_unfilled
342 #include "via_dd_tritmp.h"
344 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
345 #define TAG(x) x##_offset_unfilled
346 #include "via_dd_tritmp.h"
348 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT)
349 #define TAG(x) x##_twoside_unfilled
350 #include "via_dd_tritmp.h"
352 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
353 #define TAG(x) x##_twoside_offset_unfilled
354 #include "via_dd_tritmp.h"
356 #define IND (VIA_FALLBACK_BIT)
357 #define TAG(x) x##_fallback
358 #include "via_dd_tritmp.h"
360 #define IND (VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
361 #define TAG(x) x##_offset_fallback
362 #include "via_dd_tritmp.h"
364 #define IND (VIA_TWOSIDE_BIT|VIA_FALLBACK_BIT)
365 #define TAG(x) x##_twoside_fallback
366 #include "via_dd_tritmp.h"
368 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
369 #define TAG(x) x##_twoside_offset_fallback
370 #include "via_dd_tritmp.h"
372 #define IND (VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
373 #define TAG(x) x##_unfilled_fallback
374 #include "via_dd_tritmp.h"
376 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
377 #define TAG(x) x##_offset_unfilled_fallback
378 #include "via_dd_tritmp.h"
380 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
381 #define TAG(x) x##_twoside_unfilled_fallback
382 #include "via_dd_tritmp.h"
384 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT| \
386 #define TAG(x) x##_twoside_offset_unfilled_fallback
387 #include "via_dd_tritmp.h"
390 static void init_rast_tab(void)
395 init_twoside_offset();
397 init_offset_unfilled();
398 init_twoside_unfilled();
399 init_twoside_offset_unfilled();
401 init_offset_fallback();
402 init_twoside_fallback();
403 init_twoside_offset_fallback();
404 init_unfilled_fallback();
405 init_offset_unfilled_fallback();
406 init_twoside_unfilled_fallback();
407 init_twoside_offset_unfilled_fallback();
411 /***********************************************************************
412 * Rasterization fallback helpers *
413 ***********************************************************************/
416 /* This code is hit only when a mix of accelerated and unaccelerated
417 * primitives are being drawn, and only for the unaccelerated
421 via_fallback_tri(viaContextPtr vmesa
,
426 GLcontext
*ctx
= vmesa
->glCtx
;
428 #ifdef PERFORMANCE_MEASURE
429 if (VIA_PERFORMANCE
) P_M
;
431 via_translate_vertex(ctx
, v0
, &v
[0]);
432 via_translate_vertex(ctx
, v1
, &v
[1]);
433 via_translate_vertex(ctx
, v2
, &v
[2]);
434 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
439 via_fallback_line(viaContextPtr vmesa
,
443 GLcontext
*ctx
= vmesa
->glCtx
;
445 #ifdef PERFORMANCE_MEASURE
446 if (VIA_PERFORMANCE
) P_M
;
448 via_translate_vertex(ctx
, v0
, &v
[0]);
449 via_translate_vertex(ctx
, v1
, &v
[1]);
450 _swrast_Line(ctx
, &v
[0], &v
[1]);
455 via_fallback_point(viaContextPtr vmesa
,
458 GLcontext
*ctx
= vmesa
->glCtx
;
460 #ifdef PERFORMANCE_MEASURE
461 if (VIA_PERFORMANCE
) P_M
;
463 via_translate_vertex(ctx
, v0
, &v
[0]);
464 _swrast_Point(ctx
, &v
[0]);
467 /**********************************************************************/
468 /* Render unclipped begin/end objects */
469 /* (No Twoside / Offset / Unfilled) */
470 /**********************************************************************/
472 #define V(x) (viaVertex *)(vertptr + ((x) << vertshift))
473 #define RENDER_POINTS(start, count) \
474 for (; start < count; start++) POINT(V(ELT(start)));
475 #define RENDER_LINE(v0, v1) LINE(V(v0), V(v1))
477 #define RENDER_TRI( v0, v1, v2) \
478 if (VIA_DEBUG) fprintf(stderr, "RENDER_TRI - simple\n"); \
479 TRI( V(v0), V(v1), V(v2))
481 #define RENDER_QUAD(v0, v1, v2, v3) QUAD(V(v0), V(v1), V(v2), V(v3))
483 #define INIT(x) viaRasterPrimitive(ctx, x, x)
487 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
488 GLubyte *vertptr = (GLubyte *)vmesa->verts; \
489 const GLuint vertshift = vmesa->vertexStrideShift; \
490 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
493 viaRasterPrimitiveFinish(ctx)
494 #define RESET_STIPPLE
495 #define RESET_OCCLUSION
496 #define PRESERVE_VB_DEFS
498 #define TAG(x) via_fast##x##_verts
499 #include "via_vb_rendertmp.h"
502 #define TAG(x) via_fast##x##_elts
503 #define ELT(x) elt[x]
504 #include "via_vb_rendertmp.h"
507 #undef NEED_EDGEFLAG_SETUP
510 #undef RESET_OCCLUSION
512 /**********************************************************************/
513 /* Render unclipped begin/end objects */
514 /* (Can handle Twoside / Offset / Unfilled */
515 /**********************************************************************/
516 #define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
517 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
518 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
520 #define RENDER_POINTS(start, count) \
521 tnl->Driver.Render.Points(ctx, start, count)
523 #define RENDER_LINE(v1, v2) \
524 LineFunc(ctx, v1, v2)
526 #define RENDER_TRI(v1, v2, v3) \
527 if (VIA_DEBUG) fprintf(stderr, "RENDER_TRI - complex\n"); \
528 if (VIA_DEBUG) fprintf(stderr, "TriangleFunc = %x\n", (unsigned int)TriangleFunc); \
529 TriangleFunc(ctx, v1, v2, v3)
531 #define RENDER_QUAD(v1, v2, v3, v4) \
532 QuadFunc(ctx, v1, v2, v3, v4)
535 TNLcontext *tnl = TNL_CONTEXT(ctx); \
536 struct vertex_buffer *VB = &tnl->vb; \
537 const GLuint * const elt = VB->Elts; \
538 const tnl_line_func LineFunc = tnl->Driver.Render.Line; \
539 const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
540 const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \
541 const GLboolean stipple = ctx->Line.StippleFlag; \
542 (void) (LineFunc && TriangleFunc && QuadFunc); \
543 (void) elt; (void) stipple;
546 viaRasterPrimitiveFinish(ctx)
548 #define TAG(x) via_##x##_verts
549 /*#define INIT(x) tnl->Driver.Render.PrimitiveNotify(ctx, x)*/
550 #define INIT(x) viaRasterPrimitive(ctx, x, x)
551 #define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple(ctx)
552 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
553 #define PRESERVE_VB_DEFS
554 #include "via_vb_rendertmp.h"
557 #define ELT(x) elt[x]
558 #define TAG(x) via_##x##_elts
559 #include "via_vb_rendertmp.h"
561 /**********************************************************************/
562 /* Render clipped primitives */
563 /**********************************************************************/
567 static void viaRenderClippedPoly(GLcontext
*ctx
, const GLuint
*elts
,
570 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
571 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
572 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
573 #ifdef PERFORMANCE_MEASURE
574 if (VIA_PERFORMANCE
) P_M
;
576 /* Render the new vertices as an unclipped polygon.
579 GLuint
*tmp
= VB
->Elts
;
580 VB
->Elts
= (GLuint
*)elts
;
581 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
](ctx
, 0, n
,
582 PRIM_BEGIN
|PRIM_END
);
585 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
588 static void viaRenderClippedLine(GLcontext
*ctx
, GLuint ii
, GLuint jj
)
590 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
591 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
592 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
593 #ifdef PERFORMANCE_MEASURE
594 if (VIA_PERFORMANCE
) P_M
;
596 vmesa
->primitiveRendered
= GL_TRUE
;
598 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
599 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
602 static void viaFastRenderClippedPoly(GLcontext
*ctx
, const GLuint
*elts
,
605 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
606 GLuint vertsize
= vmesa
->vertexSize
;
607 GLuint
*vb
= viaCheckDma(vmesa
, (n
- 2) * 3 * 4 * vertsize
);
608 GLubyte
*vertptr
= (GLubyte
*)vmesa
->verts
;
609 const GLuint vertshift
= vmesa
->vertexStrideShift
;
610 const GLuint
*start
= (const GLuint
*)V(elts
[0]);
614 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
615 #ifdef PERFORMANCE_MEASURE
616 if (VIA_PERFORMANCE
) P_M
;
618 vmesa
->primitiveRendered
= GL_TRUE
;
620 for (i
= 2; i
< n
; i
++) {
621 /*=* [DBG] exy : fix flat-shading + clipping error *=*/
622 /*COPY_DWORDS(j, vb, vertsize, start);
623 COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
624 temp1 = (GLuint *)V(elts[i - 1]);
625 COPY_DWORDS(j, vb, vertsize, V(elts[i]));
626 temp2 = (GLuint *)V(elts[i]);*/
627 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
628 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
629 temp1
= (GLuint
*)V(elts
[i
- 1]);
630 COPY_DWORDS(j
, vb
, vertsize
, start
);
631 temp2
= (GLuint
*)V(elts
[i
]);
632 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]);
633 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]);
634 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]);
636 vmesa
->dmaLow
+= (n
- 2) * 3 * 4 * vertsize
;
637 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
640 /**********************************************************************/
641 /* Choose render functions */
642 /**********************************************************************/
646 #define _VIA_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE | \
647 _DD_NEW_TRI_UNFILLED | \
648 _DD_NEW_TRI_LIGHT_TWOSIDE | \
649 _DD_NEW_TRI_OFFSET | \
650 _DD_NEW_TRI_STIPPLE | \
653 #define POINT_FALLBACK (0)
654 /*#define LINE_FALLBACK (DD_LINE_STIPPLE)
656 #define LINE_FALLBACK (0)
657 #define TRI_FALLBACK (0)
658 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
659 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
661 static void viaChooseRenderState(GLcontext
*ctx
)
663 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
664 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
665 GLuint flags
= ctx
->_TriangleCaps
;
667 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
669 if (VIA_DEBUG
) fprintf(stderr
, "_TriangleCaps = %x\n", flags
);
670 if (flags
& (ANY_FALLBACK_FLAGS
|ANY_RASTER_FLAGS
)) {
671 if (flags
& ANY_RASTER_FLAGS
) {
672 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= VIA_TWOSIDE_BIT
;
673 if (flags
& DD_TRI_OFFSET
) index
|= VIA_OFFSET_BIT
;
674 if (flags
& DD_TRI_UNFILLED
) index
|= VIA_UNFILLED_BIT
;
677 vmesa
->drawPoint
= via_draw_point
;
678 vmesa
->drawLine
= via_draw_line
;
679 vmesa
->drawTri
= via_draw_triangle
;
681 /* Hook in fallbacks for specific primitives.
683 if (flags
& ANY_FALLBACK_FLAGS
) {
684 if (flags
& POINT_FALLBACK
)
685 vmesa
->drawPoint
= via_fallback_point
;
687 if (flags
& LINE_FALLBACK
)
688 vmesa
->drawLine
= via_fallback_line
;
690 if (flags
& TRI_FALLBACK
)
691 vmesa
->drawTri
= via_fallback_tri
;
693 index
|= VIA_FALLBACK_BIT
;
697 fprintf(stderr
, "index = %x\n", index
);
698 fprintf(stderr
, "renderIndex = %x\n", vmesa
->renderIndex
);
700 if (vmesa
->renderIndex
!= index
) {
701 vmesa
->renderIndex
= index
;
703 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
704 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
705 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
706 if (VIA_DEBUG
) fprintf(stderr
, "tnl->Driver.Render.xxx = rast_tab[index].xxx = %x\n", (unsigned int)tnl
->Driver
.Render
.Triangle
);
707 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
710 tnl
->Driver
.Render
.PrimTabVerts
= via_fastrender_tab_verts
;
711 tnl
->Driver
.Render
.PrimTabElts
= via_fastrender_tab_elts
;
712 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
713 tnl
->Driver
.Render
.ClippedPolygon
= viaFastRenderClippedPoly
;
716 tnl
->Driver
.Render
.PrimTabVerts
= via_render_tab_verts
;
717 tnl
->Driver
.Render
.PrimTabElts
= via_render_tab_elts
;
718 tnl
->Driver
.Render
.ClippedLine
= viaRenderClippedLine
;
719 tnl
->Driver
.Render
.ClippedPolygon
= viaRenderClippedPoly
;
722 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
725 static const GLenum reducedPrim
[GL_POLYGON
+ 1] = {
739 static void emit_all_state(viaContextPtr vmesa
)
741 GLcontext
*ctx
= vmesa
->glCtx
;
742 GLuint
*vb
= viaCheckDma(vmesa
, 0x110);
745 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
746 #ifdef PERFORMANCE_MEASURE
747 if (VIA_PERFORMANCE
) P_M
;
751 *vb
++ = (HC_ParaType_NotTex
<< 16);
752 *vb
++ = ((HC_SubA_HEnable
<< 24) | vmesa
->regEnable
);
753 *vb
++ = ((HC_SubA_HFBBMSKL
<< 24) | vmesa
->regHFBBMSKL
);
754 *vb
++ = ((HC_SubA_HROP
<< 24) | vmesa
->regHROP
);
757 if (vmesa
->hasDepth
&& vmesa
->hasStencil
) {
758 GLuint pitch
, format
, offset
;
760 format
= HC_HZWBFM_24
;
762 offset
= vmesa
->depth
.offset
;
763 pitch
= vmesa
->depth
.pitch
;
765 *vb
++ = ((HC_SubA_HZWBBasL
<< 24) | (offset
& 0xFFFFFF));
767 *vb
++ = ((HC_SubA_HZWBBasH
<< 24) | ((offset
& 0xFF000000) >> 24));
768 *vb
++ = ((HC_SubA_HZWBType
<< 24) | HC_HDBLoc_Local
| HC_HZONEasFF_MASK
|
770 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
772 *vb
++ = ((HC_SubA_HSTREF
<< 24) | vmesa
->regHSTREF
);
773 *vb
++ = ((HC_SubA_HSTMD
<< 24) | vmesa
->regHSTMD
);
777 else if (vmesa
->hasDepth
) {
778 GLuint pitch
, format
, offset
;
780 if (vmesa
->depthBits
== 16) {
781 /* We haven't support 16bit depth yet */
782 format
= HC_HZWBFM_16
;
783 /*format = HC_HZWBFM_32;*/
784 if (VIA_DEBUG
) fprintf(stderr
, "z format = 16\n");
787 format
= HC_HZWBFM_32
;
788 if (VIA_DEBUG
) fprintf(stderr
, "z format = 32\n");
792 offset
= vmesa
->depth
.offset
;
793 pitch
= vmesa
->depth
.pitch
;
795 *vb
++ = ((HC_SubA_HZWBBasL
<< 24) | (offset
& 0xFFFFFF));
797 *vb
++ = ((HC_SubA_HZWBBasH
<< 24) | ((offset
& 0xFF000000) >> 24));
798 *vb
++ = ((HC_SubA_HZWBType
<< 24) | HC_HDBLoc_Local
| HC_HZONEasFF_MASK
|
800 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
803 else if (vmesa
->hasStencil
) {
804 GLuint pitch
, format
, offset
;
806 format
= HC_HZWBFM_24
;
808 offset
= vmesa
->depth
.offset
;
809 pitch
= vmesa
->depth
.pitch
;
811 *vb
++ = ((HC_SubA_HZWBBasL
<< 24) | (offset
& 0xFFFFFF));
813 *vb
++ = ((HC_SubA_HZWBBasH
<< 24) | ((offset
& 0xFF000000) >> 24));
814 *vb
++ = ((HC_SubA_HZWBType
<< 24) | HC_HDBLoc_Local
| HC_HZONEasFF_MASK
|
816 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
818 *vb
++ = ((HC_SubA_HSTREF
<< 24) | vmesa
->regHSTREF
);
819 *vb
++ = ((HC_SubA_HSTMD
<< 24) | vmesa
->regHSTMD
);
824 if (ctx
->Color
.AlphaEnabled
) {
825 *vb
++ = ((HC_SubA_HATMD
<< 24) | vmesa
->regHATMD
);
829 if (ctx
->Color
.BlendEnabled
) {
830 *vb
++ = ((HC_SubA_HABLCsat
<< 24) | vmesa
->regHABLCsat
);
831 *vb
++ = ((HC_SubA_HABLCop
<< 24) | vmesa
->regHABLCop
);
832 *vb
++ = ((HC_SubA_HABLAsat
<< 24) | vmesa
->regHABLAsat
);
833 *vb
++ = ((HC_SubA_HABLAop
<< 24) | vmesa
->regHABLAop
);
834 *vb
++ = ((HC_SubA_HABLRCa
<< 24) | vmesa
->regHABLRCa
);
835 *vb
++ = ((HC_SubA_HABLRFCa
<< 24) | vmesa
->regHABLRFCa
);
836 *vb
++ = ((HC_SubA_HABLRCbias
<< 24) | vmesa
->regHABLRCbias
);
837 *vb
++ = ((HC_SubA_HABLRCb
<< 24) | vmesa
->regHABLRCb
);
838 *vb
++ = ((HC_SubA_HABLRFCb
<< 24) | vmesa
->regHABLRFCb
);
839 *vb
++ = ((HC_SubA_HABLRAa
<< 24) | vmesa
->regHABLRAa
);
840 *vb
++ = ((HC_SubA_HABLRAb
<< 24) | vmesa
->regHABLRAb
);
844 if (ctx
->Fog
.Enabled
) {
845 *vb
++ = ((HC_SubA_HFogLF
<< 24) | vmesa
->regHFogLF
);
846 *vb
++ = ((HC_SubA_HFogCL
<< 24) | vmesa
->regHFogCL
);
847 *vb
++ = ((HC_SubA_HFogCH
<< 24) | vmesa
->regHFogCH
);
851 if (ctx
->Line
.StippleFlag
) {
852 *vb
++ = ((HC_SubA_HLP
<< 24) | ctx
->Line
.StipplePattern
);
853 *vb
++ = ((HC_SubA_HLPRF
<< 24) | ctx
->Line
.StippleFactor
);
856 *vb
++ = ((HC_SubA_HLP
<< 24) | 0xFFFF);
857 *vb
++ = ((HC_SubA_HLPRF
<< 24) | 0x1);
862 *vb
++ = ((HC_SubA_HPixGC
<< 24) | 0x0);
870 if (ctx
->Texture
._EnabledUnits
) {
872 struct gl_texture_unit
*texUnit0
= &ctx
->Texture
.Unit
[0];
873 struct gl_texture_unit
*texUnit1
= &ctx
->Texture
.Unit
[1];
876 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texUnit0
->_Current
->DriverData
;
877 GLuint nDummyValue
= 0;
880 *vb
++ = (HC_ParaType_Tex
<< 16) | (HC_SubType_TexGeneral
<< 24);
882 if (ctx
->Texture
._EnabledUnits
> 1) {
883 if (VIA_DEBUG
) fprintf(stderr
, "multi texture\n");
884 nDummyValue
= (HC_SubA_HTXSMD
<< 24) | (1 << 3);
886 if (t
&& t
->needClearCache
) {
887 *vb
++ = nDummyValue
| HC_HTXCHCLR_MASK
;
896 if (VIA_DEBUG
) fprintf(stderr
, "single texture\n");
897 nDummyValue
= (HC_SubA_HTXSMD
<< 24) | 0;
899 if (t
&& t
->needClearCache
) {
900 *vb
++ = nDummyValue
| HC_HTXCHCLR_MASK
;
909 *vb
++ = HC_ParaType_NotTex
<< 16;
910 *vb
++ = (HC_SubA_HEnable
<< 24) | vmesa
->regEnable
;
911 *vb
++ = (HC_SubA_HEnable
<< 24) | vmesa
->regEnable
;
915 if (texUnit0
->Enabled
) {
916 struct gl_texture_object
*texObj
= texUnit0
->_Current
;
917 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
918 GLuint numLevels
= t
->lastLevel
- t
->firstLevel
+ 1;
919 GLuint nDummyValue
= 0;
921 fprintf(stderr
, "texture0 enabled\n");
922 fprintf(stderr
, "texture level %d\n", t
->actualLevel
);
924 if (numLevels
== 8) {
925 nDummyValue
= t
->regTexFM
;
927 *vb
++ = (HC_ParaType_Tex
<< 16) | (0 << 24);
929 *vb
++ = (HC_SubA_HTXnL0OS
<< 24) |
930 ((t
->lastLevel
) << HC_HTXnLVmax_SHIFT
) | t
->firstLevel
;
931 *vb
++ = t
->regTexWidthLog2
[0];
932 *vb
++ = t
->regTexWidthLog2
[1];
933 *vb
++ = t
->regTexHeightLog2
[0];
934 *vb
++ = t
->regTexHeightLog2
[1];
935 *vb
++ = t
->regTexBaseH
[0];
936 *vb
++ = t
->regTexBaseH
[1];
937 *vb
++ = t
->regTexBaseH
[2];
939 *vb
++ = t
->regTexBaseAndPitch
[0].baseL
;
940 *vb
++ = t
->regTexBaseAndPitch
[0].pitchLog2
;
941 *vb
++ = t
->regTexBaseAndPitch
[1].baseL
;
942 *vb
++ = t
->regTexBaseAndPitch
[1].pitchLog2
;
943 *vb
++ = t
->regTexBaseAndPitch
[2].baseL
;
944 *vb
++ = t
->regTexBaseAndPitch
[2].pitchLog2
;
945 *vb
++ = t
->regTexBaseAndPitch
[3].baseL
;
946 *vb
++ = t
->regTexBaseAndPitch
[3].pitchLog2
;
947 *vb
++ = t
->regTexBaseAndPitch
[4].baseL
;
948 *vb
++ = t
->regTexBaseAndPitch
[4].pitchLog2
;
949 *vb
++ = t
->regTexBaseAndPitch
[5].baseL
;
950 *vb
++ = t
->regTexBaseAndPitch
[5].pitchLog2
;
951 *vb
++ = t
->regTexBaseAndPitch
[6].baseL
;
952 *vb
++ = t
->regTexBaseAndPitch
[6].pitchLog2
;
953 *vb
++ = t
->regTexBaseAndPitch
[7].baseL
;
954 *vb
++ = t
->regTexBaseAndPitch
[7].pitchLog2
;
957 else if (numLevels
> 1) {
958 nDummyValue
= t
->regTexFM
;
960 *vb
++ = (HC_ParaType_Tex
<< 16) | (0 << 24);
962 *vb
++ = (HC_SubA_HTXnL0OS
<< 24) |
963 ((t
->lastLevel
) << HC_HTXnLVmax_SHIFT
) | t
->firstLevel
;
964 *vb
++ = t
->regTexWidthLog2
[0];
965 *vb
++ = t
->regTexHeightLog2
[0];
968 *vb
++ = t
->regTexWidthLog2
[1];
969 *vb
++ = t
->regTexHeightLog2
[1];
973 *vb
++ = t
->regTexBaseH
[0];
976 *vb
++ = t
->regTexBaseH
[1];
980 *vb
++ = t
->regTexBaseH
[2];
984 *vb
++ = t
->regTexBaseH
[3];
990 for (j
= 0; j
< numLevels
; j
++) {
991 *vb
++ = t
->regTexBaseAndPitch
[j
].baseL
;
992 *vb
++ = t
->regTexBaseAndPitch
[j
].pitchLog2
;
997 nDummyValue
= t
->regTexFM
;
999 *vb
++ = (HC_ParaType_Tex
<< 16) | (0 << 24);
1000 *vb
++ = t
->regTexFM
;
1001 *vb
++ = (HC_SubA_HTXnL0OS
<< 24) |
1002 ((t
->lastLevel
) << HC_HTXnLVmax_SHIFT
) | t
->firstLevel
;
1003 *vb
++ = t
->regTexWidthLog2
[0];
1004 *vb
++ = t
->regTexHeightLog2
[0];
1005 *vb
++ = t
->regTexBaseH
[0];
1006 *vb
++ = t
->regTexBaseAndPitch
[0].baseL
;
1007 *vb
++ = t
->regTexBaseAndPitch
[0].pitchLog2
;
1011 *vb
++ = (HC_SubA_HTXnTB
<< 24) | vmesa
->regHTXnTB_0
;
1012 *vb
++ = (HC_SubA_HTXnMPMD
<< 24) | vmesa
->regHTXnMPMD_0
;
1013 *vb
++ = (HC_SubA_HTXnTBLCsat
<< 24) | vmesa
->regHTXnTBLCsat_0
;
1014 *vb
++ = (HC_SubA_HTXnTBLCop
<< 24) | vmesa
->regHTXnTBLCop_0
;
1015 *vb
++ = (HC_SubA_HTXnTBLMPfog
<< 24) | vmesa
->regHTXnTBLMPfog_0
;
1016 *vb
++ = (HC_SubA_HTXnTBLAsat
<< 24) | vmesa
->regHTXnTBLAsat_0
;
1017 *vb
++ = (HC_SubA_HTXnTBLRCb
<< 24) | vmesa
->regHTXnTBLRCb_0
;
1018 *vb
++ = (HC_SubA_HTXnTBLRAa
<< 24) | vmesa
->regHTXnTBLRAa_0
;
1019 *vb
++ = (HC_SubA_HTXnTBLRFog
<< 24) | vmesa
->regHTXnTBLRFog_0
;
1021 /*=* John Sheng [2003.7.18] texture combine */
1022 *vb
++ = (HC_SubA_HTXnTBLRCa
<< 24) | vmesa
->regHTXnTBLRCa_0
;
1023 *vb
++ = (HC_SubA_HTXnTBLRCc
<< 24) | vmesa
->regHTXnTBLRCc_0
;
1024 *vb
++ = (HC_SubA_HTXnTBLRCbias
<< 24) | vmesa
->regHTXnTBLRCbias_0
;
1027 if (t
->regTexFM
== HC_HTXnFM_Index8
) {
1028 struct gl_color_table
*table
= &texObj
->Palette
;
1029 GLfloat
*tableF
= (GLfloat
*)table
->Table
;
1032 *vb
++ = (HC_ParaType_Palette
<< 16) | (0 << 24);
1034 for (j
= 0; j
< table
->Size
; j
++) {
1045 if (texUnit1
->Enabled
) {
1046 struct gl_texture_object
*texObj
= texUnit1
->_Current
;
1047 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
1048 GLuint numLevels
= t
->lastLevel
- t
->firstLevel
+ 1;
1049 GLuint nDummyValue
= 0;
1051 fprintf(stderr
, "texture1 enabled\n");
1052 fprintf(stderr
, "texture level %d\n", t
->actualLevel
);
1054 if (numLevels
== 8) {
1055 nDummyValue
= t
->regTexFM
;
1057 *vb
++ = (HC_ParaType_Tex
<< 16) | (1 << 24);
1058 *vb
++ = t
->regTexFM
;
1059 *vb
++ = (HC_SubA_HTXnL0OS
<< 24) |
1060 ((t
->lastLevel
) << HC_HTXnLVmax_SHIFT
) | t
->firstLevel
;
1061 *vb
++ = t
->regTexWidthLog2
[0];
1062 *vb
++ = t
->regTexWidthLog2
[1];
1063 *vb
++ = t
->regTexHeightLog2
[0];
1064 *vb
++ = t
->regTexHeightLog2
[1];
1065 *vb
++ = t
->regTexBaseH
[0];
1066 *vb
++ = t
->regTexBaseH
[1];
1067 *vb
++ = t
->regTexBaseH
[2];
1069 *vb
++ = t
->regTexBaseAndPitch
[0].baseL
;
1070 *vb
++ = t
->regTexBaseAndPitch
[0].pitchLog2
;
1071 *vb
++ = t
->regTexBaseAndPitch
[1].baseL
;
1072 *vb
++ = t
->regTexBaseAndPitch
[1].pitchLog2
;
1073 *vb
++ = t
->regTexBaseAndPitch
[2].baseL
;
1074 *vb
++ = t
->regTexBaseAndPitch
[2].pitchLog2
;
1075 *vb
++ = t
->regTexBaseAndPitch
[3].baseL
;
1076 *vb
++ = t
->regTexBaseAndPitch
[3].pitchLog2
;
1077 *vb
++ = t
->regTexBaseAndPitch
[4].baseL
;
1078 *vb
++ = t
->regTexBaseAndPitch
[4].pitchLog2
;
1079 *vb
++ = t
->regTexBaseAndPitch
[5].baseL
;
1080 *vb
++ = t
->regTexBaseAndPitch
[5].pitchLog2
;
1081 *vb
++ = t
->regTexBaseAndPitch
[6].baseL
;
1082 *vb
++ = t
->regTexBaseAndPitch
[6].pitchLog2
;
1083 *vb
++ = t
->regTexBaseAndPitch
[7].baseL
;
1084 *vb
++ = t
->regTexBaseAndPitch
[7].pitchLog2
;
1087 else if (numLevels
> 1) {
1088 nDummyValue
= t
->regTexFM
;
1090 *vb
++ = (HC_ParaType_Tex
<< 16) | (1 << 24);
1091 *vb
++ = t
->regTexFM
;
1092 *vb
++ = (HC_SubA_HTXnL0OS
<< 24) |
1093 ((t
->lastLevel
) << HC_HTXnLVmax_SHIFT
) | t
->firstLevel
;
1094 *vb
++ = t
->regTexWidthLog2
[0];
1095 *vb
++ = t
->regTexHeightLog2
[0];
1097 if (numLevels
> 6) {
1098 *vb
++ = t
->regTexWidthLog2
[1];
1099 *vb
++ = t
->regTexHeightLog2
[1];
1103 *vb
++ = t
->regTexBaseH
[0];
1105 if (numLevels
> 3) {
1106 *vb
++ = t
->regTexBaseH
[1];
1109 if (numLevels
> 6) {
1110 *vb
++ = t
->regTexBaseH
[2];
1113 if (numLevels
> 9) {
1114 *vb
++ = t
->regTexBaseH
[3];
1120 for (j
= 0; j
< numLevels
; j
++) {
1121 *vb
++ = t
->regTexBaseAndPitch
[j
].baseL
;
1122 *vb
++ = t
->regTexBaseAndPitch
[j
].pitchLog2
;
1127 nDummyValue
= t
->regTexFM
;
1129 *vb
++ = (HC_ParaType_Tex
<< 16) | (1 << 24);
1130 *vb
++ = t
->regTexFM
;
1131 *vb
++ = (HC_SubA_HTXnL0OS
<< 24) |
1132 ((t
->lastLevel
) << HC_HTXnLVmax_SHIFT
) | t
->firstLevel
;
1133 *vb
++ = t
->regTexWidthLog2
[0];
1134 *vb
++ = t
->regTexHeightLog2
[0];
1135 *vb
++ = t
->regTexBaseH
[0];
1136 *vb
++ = t
->regTexBaseAndPitch
[0].baseL
;
1137 *vb
++ = t
->regTexBaseAndPitch
[0].pitchLog2
;
1141 *vb
++ = (HC_SubA_HTXnTB
<< 24) | vmesa
->regHTXnTB_1
;
1142 *vb
++ = (HC_SubA_HTXnMPMD
<< 24) | vmesa
->regHTXnMPMD_1
;
1143 *vb
++ = (HC_SubA_HTXnTBLCsat
<< 24) | vmesa
->regHTXnTBLCsat_1
;
1144 *vb
++ = (HC_SubA_HTXnTBLCop
<< 24) | vmesa
->regHTXnTBLCop_1
;
1145 *vb
++ = (HC_SubA_HTXnTBLMPfog
<< 24) | vmesa
->regHTXnTBLMPfog_1
;
1146 *vb
++ = (HC_SubA_HTXnTBLAsat
<< 24) | vmesa
->regHTXnTBLAsat_1
;
1147 *vb
++ = (HC_SubA_HTXnTBLRCb
<< 24) | vmesa
->regHTXnTBLRCb_1
;
1148 *vb
++ = (HC_SubA_HTXnTBLRAa
<< 24) | vmesa
->regHTXnTBLRAa_1
;
1149 *vb
++ = (HC_SubA_HTXnTBLRFog
<< 24) | vmesa
->regHTXnTBLRFog_1
;
1152 if (t
->regTexFM
== HC_HTXnFM_Index8
) {
1153 struct gl_color_table
*table
= &texObj
->Palette
;
1154 GLfloat
*tableF
= (GLfloat
*)table
->Table
;
1157 *vb
++ = (HC_ParaType_Palette
<< 16) | (1 << 24);
1159 for (j
= 0; j
< table
->Size
; j
++) {
1172 if (ctx
->Polygon
.StippleFlag
) {
1173 GLuint
*stipple
= &ctx
->PolygonStipple
[0];
1176 *vb
++ = ((HC_ParaType_Palette
<< 16) | (HC_SubType_Stipple
<< 24));
1178 *vb
++ = stipple
[31];
1179 *vb
++ = stipple
[30];
1180 *vb
++ = stipple
[29];
1181 *vb
++ = stipple
[28];
1182 *vb
++ = stipple
[27];
1183 *vb
++ = stipple
[26];
1184 *vb
++ = stipple
[25];
1185 *vb
++ = stipple
[24];
1186 *vb
++ = stipple
[23];
1187 *vb
++ = stipple
[22];
1188 *vb
++ = stipple
[21];
1189 *vb
++ = stipple
[20];
1190 *vb
++ = stipple
[19];
1191 *vb
++ = stipple
[18];
1192 *vb
++ = stipple
[17];
1193 *vb
++ = stipple
[16];
1194 *vb
++ = stipple
[15];
1195 *vb
++ = stipple
[14];
1196 *vb
++ = stipple
[13];
1197 *vb
++ = stipple
[12];
1198 *vb
++ = stipple
[11];
1199 *vb
++ = stipple
[10];
1212 *vb
++ = (HC_ParaType_NotTex
<< 16);
1213 *vb
++ = ((HC_SubA_HSPXYOS
<< 24) | (0x20 - (vmesa
->driDrawable
->h
& 0x1F)));
1214 *vb
++ = ((HC_SubA_HSPXYOS
<< 24) | (0x20 - (vmesa
->driDrawable
->h
& 0x1F)));
1218 vmesa
->dmaLow
+= (i
<< 2);
1221 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1225 static void emit_partial_state(viaContextPtr vmesa
)
1227 GLcontext
*ctx
= vmesa
->glCtx
;
1228 GLuint dirty
= vmesa
->dirty
;
1229 GLuint
*vb
= viaCheckDma(vmesa
, 0x110);
1232 if( VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1234 #ifdef PERFORMANCE_MEASURE
1235 if (VIA_PERFORMANCE
) P_M
;
1240 *vb
++ = (HC_ParaType_NotTex
<< 16);
1241 *vb
++ = ((HC_SubA_HEnable
<< 24) | vmesa
->regEnable
);
1242 *vb
++ = ((HC_SubA_HFBBMSKL
<< 24) | vmesa
->regHFBBMSKL
);
1243 *vb
++ = ((HC_SubA_HROP
<< 24) | vmesa
->regHROP
);
1246 if (dirty
& VIA_UPLOAD_DESTBUFFER
) {
1249 if (dirty
& VIA_UPLOAD_DEPTHBUFFER
) {
1252 if (dirty
* VIA_UPLOAD_DEPTH
) {
1253 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
1257 if (dirty
* VIA_UPLOAD_ALPHATEST
) {
1258 *vb
++ = ((HC_SubA_HATMD
<< 24) | vmesa
->regHATMD
);
1263 if (dirty
& VIA_UPLOAD_BLEND
) {
1264 *vb
++ = ((HC_SubA_HABLCsat
<< 24) | vmesa
->regHABLCsat
);
1265 *vb
++ = ((HC_SubA_HABLCop
<< 24) | vmesa
->regHABLCop
);
1266 *vb
++ = ((HC_SubA_HABLAsat
<< 24) | vmesa
->regHABLAsat
);
1267 *vb
++ = ((HC_SubA_HABLAop
<< 24) | vmesa
->regHABLAop
);
1268 *vb
++ = ((HC_SubA_HABLRCa
<< 24) | vmesa
->regHABLRCa
);
1269 *vb
++ = ((HC_SubA_HABLRFCa
<< 24) | vmesa
->regHABLRFCa
);
1270 *vb
++ = ((HC_SubA_HABLRCbias
<< 24) | vmesa
->regHABLRCbias
);
1271 *vb
++ = ((HC_SubA_HABLRCb
<< 24) | vmesa
->regHABLRCb
);
1272 *vb
++ = ((HC_SubA_HABLRFCb
<< 24) | vmesa
->regHABLRFCb
);
1273 *vb
++ = ((HC_SubA_HABLRAa
<< 24) | vmesa
->regHABLRAa
);
1274 *vb
++ = ((HC_SubA_HABLRAb
<< 24) | vmesa
->regHABLRAb
);
1278 if (dirty
& VIA_UPLOAD_FOG
) {
1279 *vb
++ = ((HC_SubA_HFogLF
<< 24) | vmesa
->regHFogLF
);
1280 *vb
++ = ((HC_SubA_HFogCL
<< 24) | vmesa
->regHFogCL
);
1281 *vb
++ = ((HC_SubA_HFogCH
<< 24) | vmesa
->regHFogCH
);
1285 if (dirty
& VIA_UPLOAD_LINESTIPPLE
) {
1286 *vb
++ = ((HC_SubA_HLP
<< 24) | ctx
->Line
.StipplePattern
);
1287 *vb
++ = ((HC_SubA_HLPRF
<< 24) | ctx
->Line
.StippleFactor
);
1290 *vb
++ = ((HC_SubA_HLP
<< 24) | 0xFFFF);
1291 *vb
++ = ((HC_SubA_HLPRF
<< 24) | 0x1);
1295 *vb
++ = ((HC_SubA_HPixGC
<< 24) | 0x0);
1303 if (dirty
& VIA_UPLOAD_TEXTURE
) {
1307 if (dirty
& VIA_UPLOAD_POLYGONSTIPPLE
) {
1311 vmesa
->dmaLow
+= (i
<< 2);
1314 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1317 /**********************************************************************/
1318 /* High level hooks for t_vb_render.c */
1319 /**********************************************************************/
1321 /* Determine the rasterized primitive when not drawing unfilled
1324 * Used only for the default render stage which always decomposes
1325 * primitives to trianges/lines/points. For the accelerated stage,
1326 * which renders strips as strips, the equivalent calculations are
1327 * performed in via_render.c.
1329 static void viaRenderPrimitive(GLcontext
*ctx
, GLenum prim
)
1331 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1332 GLuint rprim
= reducedPrim
[prim
];
1333 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1334 vmesa
->renderPrimitive
= prim
;
1335 viaRasterPrimitive(ctx
, rprim
, rprim
);
1336 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1339 static void viaRunPipeline(GLcontext
*ctx
)
1341 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1342 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1344 if (VIA_DEBUG
) fprintf(stderr
, "newState = %x\n", vmesa
->newState
);
1346 if (vmesa
->newState
) {
1347 if (vmesa
->newState
& _NEW_TEXTURE
)
1348 viaUpdateTextureState(ctx
); /* may modify vmesa->newState */
1350 viaChooseVertexState(ctx
);
1351 viaChooseRenderState(ctx
);
1352 vmesa
->newState
= 0;
1355 if (vmesa
->needUploadAllState
)
1356 emit_all_state(vmesa
);
1358 emit_partial_state(vmesa
);
1360 _tnl_run_pipeline(ctx
);
1361 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1364 static void viaRenderStart(GLcontext
*ctx
)
1366 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1368 /* Check for projective texturing. Make sure all texcoord
1369 * pointers point to something. (fix in mesa?)
1371 viaCheckTexSizes(ctx
);
1372 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1375 static void viaRenderFinish(GLcontext
*ctx
)
1377 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1378 if (VIA_CONTEXT(ctx
)->renderIndex
& VIA_FALLBACK_BIT
)
1380 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1384 /* System to flush dma and emit state changes based on the rasterized
1387 void viaRasterPrimitive(GLcontext
*ctx
,
1391 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1392 GLuint
*vb
= viaCheckDma(vmesa
, 32);
1395 fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1396 fprintf(stderr
, "hwprim = %x\n", hwprim
);
1398 /*=* [DBG] exy : fix wireframe + clipping error *=*/
1399 if (((rprim
== GL_TRIANGLES
&& (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
)))) {
1403 if (RasterCounter
> 0) {
1405 if (VIA_DEBUG
) fprintf(stderr
, "enter twice:%d\n",RasterCounter
);
1411 vmesa
->primitiveRendered
= GL_FALSE
;
1412 regCmdB
= vmesa
->regCmdB
;
1416 if (VIA_DEBUG
) fprintf(stderr
, "Points\n");
1417 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Point
| HC_HVCycle_Full
;
1418 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1419 vmesa
->regCmdA_End
|= HC_HShading_FlatA
;
1422 if (VIA_DEBUG
) fprintf(stderr
, "Lines\n");
1423 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Line
| HC_HVCycle_Full
;
1424 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1425 vmesa
->regCmdA_End
|= HC_HShading_FlatB
;
1429 if (VIA_DEBUG
) fprintf(stderr
, "Line Loop / Line Strip\n");
1430 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Line
| HC_HVCycle_AFP
|
1431 HC_HVCycle_AB
| HC_HVCycle_NewB
;
1432 regCmdB
|= HC_HVCycle_AB
| HC_HVCycle_NewB
| HC_HLPrst_MASK
;
1433 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1434 vmesa
->regCmdA_End
|= HC_HShading_FlatB
;
1437 if (VIA_DEBUG
) fprintf(stderr
, "Triangles\n");
1438 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_Full
;
1439 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1440 vmesa
->regCmdA_End
|= HC_HShading_FlatC
;
1442 case GL_TRIANGLE_STRIP
:
1443 if (VIA_DEBUG
) fprintf(stderr
, "Triangle Strip\n");
1444 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_AFP
|
1445 HC_HVCycle_AC
| HC_HVCycle_BB
| HC_HVCycle_NewC
;
1446 regCmdB
|= HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
1447 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1448 vmesa
->regCmdA_End
|= HC_HShading_FlatB
;
1450 case GL_TRIANGLE_FAN
:
1451 if (VIA_DEBUG
) fprintf(stderr
, "Triangle Fan\n");
1452 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_AFP
|
1453 HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
1454 regCmdB
|= HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
1455 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1456 vmesa
->regCmdA_End
|= HC_HShading_FlatC
;
1459 if (VIA_DEBUG
) fprintf(stderr
, "No HW Quads\n");
1462 if (VIA_DEBUG
) fprintf(stderr
, "No HW Quad Strip\n");
1465 if (VIA_DEBUG
) fprintf(stderr
, "Polygon\n");
1466 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_AFP
|
1467 HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
1468 regCmdB
|= HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
1469 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
1470 vmesa
->regCmdA_End
|= HC_HShading_FlatC
;
1473 if (VIA_DEBUG
) fprintf(stderr
, "Unknow\n");
1478 *vb
++ = (HC_ParaType_NotTex
<< 16);
1483 *vb
++ = (HC_ParaType_CmdVdata
<< 16);
1485 *vb
++ = vmesa
->regCmdA_End
;
1486 vmesa
->dmaLow
+= 32;
1488 vmesa
->reducedPrimitive
= rprim
;
1489 vmesa
->hwPrimitive
= rprim
;
1490 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1493 void viaRasterPrimitiveFinish(GLcontext
*ctx
)
1495 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1496 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1498 if (VIA_DEBUG
) fprintf(stderr
, "primitiveRendered = %x\n", vmesa
->primitiveRendered
);
1499 if (RasterCounter
> 1) {
1501 if (VIA_DEBUG
) fprintf(stderr
, "finish enter twice: %d\n",RasterCounter
);
1507 if (vmesa
->primitiveRendered
) {
1508 GLuint
*vb
= viaCheckDma(vmesa
, 0);
1509 GLuint cmdA
= vmesa
->regCmdA_End
| HC_HPLEND_MASK
| HC_HPMValidN_MASK
| HC_HE3Fire_MASK
;
1511 /*=* John Sheng [2003.6.20] fix pci *=*/
1512 /*if (vmesa->dmaLow & 0x1) {*/
1513 if (vmesa
->dmaLow
& 0x1 || !vmesa
->useAgp
) {
1524 if (vmesa
->dmaLow
>= (32 + DMA_OFFSET
))
1525 vmesa
->dmaLow
-= 32;
1528 if (0) viaFlushPrimsLocked(vmesa
);
1530 volatile GLuint
*pnMMIOBase
= vmesa
->regMMIOBase
;
1531 volatile GLuint
*pnEngBase
= (volatile GLuint
*)((GLuint
)pnMMIOBase
+ 0x400);
1532 int nStatus
= *pnEngBase
;
1533 if (((nStatus
& 0xFFFEFFFF) == 0x00020000)) {
1534 #ifdef PERFORMANCE_MEASURE
1537 viaFlushPrims(vmesa
);
1539 #ifdef PERFORMANCE_MEASURE
1545 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1549 /**********************************************************************/
1550 /* Transition to/from hardware rasterization. */
1551 /**********************************************************************/
1554 void viaFallback(viaContextPtr vmesa
, GLuint bit
, GLboolean mode
)
1556 GLcontext
*ctx
= vmesa
->glCtx
;
1557 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1558 GLuint oldfallback
= vmesa
->Fallback
;
1559 if (VIA_DEBUG
) fprintf(stderr
, "%s old %x bit %x mode %d\n", __FUNCTION__
,
1560 vmesa
->Fallback
, bit
, mode
);
1563 vmesa
->Fallback
|= bit
;
1564 if (oldfallback
== 0) {
1565 if (VIA_DEBUG
) fprintf(stderr
, "ENTER FALLBACK\n");
1566 VIA_FIREVERTICES(vmesa
);
1567 _swsetup_Wakeup(ctx
);
1568 vmesa
->renderIndex
= ~0;
1572 vmesa
->Fallback
&= ~bit
;
1573 if (oldfallback
== bit
) {
1574 if (VIA_DEBUG
) fprintf(stderr
, "LEAVE FALLBACK\n");
1575 tnl
->Driver
.Render
.Start
= viaRenderStart
;
1576 tnl
->Driver
.Render
.PrimitiveNotify
= viaRenderPrimitive
;
1577 tnl
->Driver
.Render
.Finish
= viaRenderFinish
;
1578 tnl
->Driver
.Render
.BuildVertices
= viaBuildVertices
;
1579 vmesa
->newState
|= (_VIA_NEW_RENDERSTATE
|_VIA_NEW_VERTEX
);
1586 /**********************************************************************/
1587 /* Initialization. */
1588 /**********************************************************************/
1591 void viaInitTriFuncs(GLcontext
*ctx
)
1593 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1594 static int firsttime
= 1;
1601 tnl
->Driver
.RunPipeline
= viaRunPipeline
;
1602 tnl
->Driver
.Render
.Start
= viaRenderStart
;
1603 tnl
->Driver
.Render
.Finish
= viaRenderFinish
;
1604 tnl
->Driver
.Render
.PrimitiveNotify
= viaRenderPrimitive
;
1605 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1606 tnl
->Driver
.Render
.BuildVertices
= viaBuildVertices
;