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
);
82 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
84 #ifdef PERFORMANCE_MEASURE
85 if (VIA_PERFORMANCE
) P_M
;
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
;
93 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
98 static void __inline__
via_draw_quad(viaContextPtr vmesa
,
104 GLuint vertsize
= vmesa
->vertexSize
;
105 GLuint
*vb
= viaCheckDma(vmesa
, 6 * 4 * vertsize
);
108 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
110 #ifdef PERFORMANCE_MEASURE
111 if (VIA_PERFORMANCE
) P_M
;
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
;
122 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
127 static __inline__
void via_draw_point(viaContextPtr vmesa
,
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
);
136 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
138 #ifdef PERFORMANCE_MEASURE
139 if (VIA_PERFORMANCE
) P_M
;
141 COPY_DWORDS(j
, vb
, vertsize
, v0
);
142 vmesa
->dmaLow
+= 4 * vertsize
;
143 vmesa
->primitiveRendered
= GL_TRUE
;
145 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
151 * Draw line in hardware.
154 static __inline__
void via_draw_line(viaContextPtr vmesa
,
158 GLuint vertsize
= vmesa
->vertexSize
;
159 GLuint
*vb
= viaCheckDma(vmesa
, 2 * 4 * vertsize
);
162 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
164 #ifdef PERFORMANCE_MEASURE
165 if (VIA_PERFORMANCE
) P_M
;
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
;
172 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
177 /***********************************************************************
178 * Macros for via_dd_tritmp.h to draw basic primitives *
179 ***********************************************************************/
181 #define TRI(a, b, c) \
183 if (VIA_DEBUG) fprintf(stderr, "hw TRI\n"); \
185 vmesa->drawTri(vmesa, a, b, c); \
187 via_draw_triangle(vmesa, a, b, c); \
190 #define QUAD(a, b, c, d) \
192 if (VIA_DEBUG) fprintf(stderr, "hw QUAD\n");\
194 vmesa->drawTri(vmesa, a, b, d); \
195 vmesa->drawTri(vmesa, b, c, d); \
198 via_draw_quad(vmesa, a, b, c, d); \
201 #define LINE(v0, v1) \
203 if(VIA_DEBUG) fprintf(stderr, "hw LINE\n");\
205 vmesa->drawLine(vmesa, v0, v1); \
207 via_draw_line(vmesa, v0, v1); \
212 if (VIA_DEBUG) fprintf(stderr, "hw POINT\n");\
214 vmesa->drawPoint(vmesa, v0); \
216 via_draw_point(vmesa, v0); \
220 /***********************************************************************
221 * Build render functions from dd templates *
222 ***********************************************************************/
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
234 triangle_func triangle
;
236 } rast_tab
[VIA_MAX_TRIFUNC
];
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)
248 #define DO_FULL_QUAD 1
252 #define HAVE_BACK_COLORS 0
253 #define HAVE_HW_FLATSHADE 1
254 #define VERTEX viaVertex
257 /* Only used to pull back colors into vertices (ie, we know color is
260 #define VIA_COLOR(dst, src) \
268 #define VIA_SPEC(dst, src) \
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))
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]
294 #define SET_PRIMITIVE_RENDERED vmesa->primitiveRendered = GL_TRUE;
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;
304 /***********************************************************************
305 * Helpers for rendering unfilled primitives *
306 ***********************************************************************/
308 static const GLuint hwPrim[GL_POLYGON + 1] = {
322 #define RASTERIZE(x) \
323 if (vmesa->hwPrimitive != x) { \
324 viaRasterPrimitiveFinish(ctx); \
325 viaRasterPrimitive(ctx, x, x); \
328 #define RENDER_PRIMITIVE vmesa->renderPrimitive
330 #define IND VIA_FALLBACK_BIT
331 #include "tnl_dd/t_dd_unfilled.h"
335 /***********************************************************************
336 * Generate GL render functions *
337 ***********************************************************************/
342 #include "via_dd_tritmp.h"
344 #define IND (VIA_OFFSET_BIT)
345 #define TAG(x) x##_offset
346 #include "via_dd_tritmp.h"
348 #define IND (VIA_TWOSIDE_BIT)
349 #define TAG(x) x##_twoside
350 #include "via_dd_tritmp.h"
352 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT)
353 #define TAG(x) x##_twoside_offset
354 #include "via_dd_tritmp.h"
356 #define IND (VIA_UNFILLED_BIT)
357 #define TAG(x) x##_unfilled
358 #include "via_dd_tritmp.h"
360 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
361 #define TAG(x) x##_offset_unfilled
362 #include "via_dd_tritmp.h"
364 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT)
365 #define TAG(x) x##_twoside_unfilled
366 #include "via_dd_tritmp.h"
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"
372 #define IND (VIA_FALLBACK_BIT)
373 #define TAG(x) x##_fallback
374 #include "via_dd_tritmp.h"
376 #define IND (VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
377 #define TAG(x) x##_offset_fallback
378 #include "via_dd_tritmp.h"
380 #define IND (VIA_TWOSIDE_BIT|VIA_FALLBACK_BIT)
381 #define TAG(x) x##_twoside_fallback
382 #include "via_dd_tritmp.h"
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"
388 #define IND (VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
389 #define TAG(x) x##_unfilled_fallback
390 #include "via_dd_tritmp.h"
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"
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"
400 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT| \
402 #define TAG(x) x##_twoside_offset_unfilled_fallback
403 #include "via_dd_tritmp.h"
406 static void init_rast_tab(void)
411 init_twoside_offset();
413 init_offset_unfilled();
414 init_twoside_unfilled();
415 init_twoside_offset_unfilled();
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();
427 /***********************************************************************
428 * Rasterization fallback helpers *
429 ***********************************************************************/
432 /* This code is hit only when a mix of accelerated and unaccelerated
433 * primitives are being drawn, and only for the unaccelerated
437 via_fallback_tri(viaContextPtr vmesa
,
442 GLcontext
*ctx
= vmesa
->glCtx
;
444 #ifdef PERFORMANCE_MEASURE
445 if (VIA_PERFORMANCE
) P_M
;
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]);
455 via_fallback_line(viaContextPtr vmesa
,
459 GLcontext
*ctx
= vmesa
->glCtx
;
461 #ifdef PERFORMANCE_MEASURE
462 if (VIA_PERFORMANCE
) P_M
;
464 via_translate_vertex(ctx
, v0
, &v
[0]);
465 via_translate_vertex(ctx
, v1
, &v
[1]);
466 _swrast_Line(ctx
, &v
[0], &v
[1]);
471 via_fallback_point(viaContextPtr vmesa
,
474 GLcontext
*ctx
= vmesa
->glCtx
;
476 #ifdef PERFORMANCE_MEASURE
477 if (VIA_PERFORMANCE
) P_M
;
479 via_translate_vertex(ctx
, v0
, &v
[0]);
480 _swrast_Point(ctx
, &v
[0]);
483 /**********************************************************************/
484 /* Render unclipped begin/end objects */
485 /* (No Twoside / Offset / Unfilled) */
486 /**********************************************************************/
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))
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))
497 #define RENDER_QUAD(v0, v1, v2, v3) QUAD(V(v0), V(v1), V(v2), V(v3))
499 #define INIT(x) viaRasterPrimitive(ctx, x, x)
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; \
509 viaRasterPrimitiveFinish(ctx)
510 #define RESET_STIPPLE
511 #define RESET_OCCLUSION
512 #define PRESERVE_VB_DEFS
514 #define TAG(x) via_fast##x##_verts
515 #include "via_vb_rendertmp.h"
518 #define TAG(x) via_fast##x##_elts
519 #define ELT(x) elt[x]
520 #include "via_vb_rendertmp.h"
523 #undef NEED_EDGEFLAG_SETUP
526 #undef RESET_OCCLUSION
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
536 #define RENDER_POINTS(start, count) \
537 tnl->Driver.Render.Points(ctx, start, count)
539 #define RENDER_LINE(v1, v2) \
540 LineFunc(ctx, v1, v2)
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)
547 #define RENDER_QUAD(v1, v2, v3, v4) \
548 QuadFunc(ctx, v1, v2, v3, v4)
551 TNLcontext *tnl = TNL_CONTEXT(ctx); \
552 struct vertex_buffer *VB = &tnl->vb; \
553 const GLuint * const elt = VB->Elts; \
554 const line_func LineFunc = tnl->Driver.Render.Line; \
555 const triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
556 const quad_func QuadFunc = tnl->Driver.Render.Quad; \
557 const GLboolean stipple = ctx->Line.StippleFlag; \
558 (void) (LineFunc && TriangleFunc && QuadFunc); \
559 (void) elt; (void) stipple;
562 viaRasterPrimitiveFinish(ctx)
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"
573 #define ELT(x) elt[x]
574 #define TAG(x) via_##x##_elts
575 #include "via_vb_rendertmp.h"
577 /**********************************************************************/
578 /* Render clipped primitives */
579 /**********************************************************************/
583 static void viaRenderClippedPoly(GLcontext
*ctx
, const GLuint
*elts
,
586 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
587 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
589 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
591 #ifdef PERFORMANCE_MEASURE
592 if (VIA_PERFORMANCE
) P_M
;
594 /* Render the new vertices as an unclipped polygon.
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
);
604 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
608 static void viaRenderClippedLine(GLcontext
*ctx
, GLuint ii
, GLuint jj
)
610 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
611 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
613 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 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
622 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
626 static void viaFastRenderClippedPoly(GLcontext
*ctx
, const GLuint
*elts
,
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]);
639 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
641 #ifdef PERFORMANCE_MEASURE
642 if (VIA_PERFORMANCE
) P_M
;
644 vmesa
->primitiveRendered
= GL_TRUE
;
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
]);
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]);
664 vmesa
->dmaLow
+= (n
- 2) * 3 * 4 * vertsize
;
666 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
670 /**********************************************************************/
671 /* Choose render functions */
672 /**********************************************************************/
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 | \
683 #define POINT_FALLBACK (0)
684 /*#define LINE_FALLBACK (DD_LINE_STIPPLE)
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)
691 static void viaChooseRenderState(GLcontext
*ctx
)
693 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
694 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
695 GLuint flags
= ctx
->_TriangleCaps
;
698 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
700 if (VIA_DEBUG
) fprintf(stderr
, "_TriangleCaps = %x\n", flags
);
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
;
709 vmesa
->drawPoint
= via_draw_point
;
710 vmesa
->drawLine
= via_draw_line
;
711 vmesa
->drawTri
= via_draw_triangle
;
713 /* Hook in fallbacks for specific primitives.
715 if (flags
& ANY_FALLBACK_FLAGS
) {
716 if (flags
& POINT_FALLBACK
)
717 vmesa
->drawPoint
= via_fallback_point
;
719 if (flags
& LINE_FALLBACK
)
720 vmesa
->drawLine
= via_fallback_line
;
722 if (flags
& TRI_FALLBACK
)
723 vmesa
->drawTri
= via_fallback_tri
;
725 index
|= VIA_FALLBACK_BIT
;
730 fprintf(stderr
, "index = %x\n", index
);
731 fprintf(stderr
, "renderIndex = %x\n", vmesa
->renderIndex
);
734 if (vmesa
->renderIndex
!= index
) {
735 vmesa
->renderIndex
= index
;
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
;
741 if (VIA_DEBUG
) fprintf(stderr
, "tnl->Driver.Render.xxx = rast_tab[index].xxx = %x\n", (unsigned int)tnl
->Driver
.Render
.Triangle
);
743 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
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
;
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
;
759 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
763 static const GLenum reducedPrim
[GL_POLYGON
+ 1] = {
777 static void emit_all_state(viaContextPtr vmesa
)
779 GLcontext
*ctx
= vmesa
->glCtx
;
780 GLuint
*vb
= viaCheckDma(vmesa
, 0x110);
784 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
786 #ifdef PERFORMANCE_MEASURE
787 if (VIA_PERFORMANCE
) P_M
;
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
);
797 if (vmesa
->hasDepth
&& vmesa
->hasStencil
) {
798 GLuint pitch
, format
, offset
;
800 format
= HC_HZWBFM_24
;
802 offset
= vmesa
->depth
.offset
;
803 pitch
= vmesa
->depth
.pitch
;
805 *vb
++ = ((HC_SubA_HZWBBasL
<< 24) | (offset
& 0xFFFFFF));
807 *vb
++ = ((HC_SubA_HZWBBasH
<< 24) | ((offset
& 0xFF000000) >> 24));
808 *vb
++ = ((HC_SubA_HZWBType
<< 24) | HC_HDBLoc_Local
| HC_HZONEasFF_MASK
|
810 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
812 *vb
++ = ((HC_SubA_HSTREF
<< 24) | vmesa
->regHSTREF
);
813 *vb
++ = ((HC_SubA_HSTMD
<< 24) | vmesa
->regHSTMD
);
817 else if (vmesa
->hasDepth
) {
818 GLuint pitch
, format
, offset
;
820 if (vmesa
->depthBits
== 16) {
821 /* We haven't support 16bit depth yet */
822 format
= HC_HZWBFM_16
;
823 /*format = HC_HZWBFM_32;*/
825 if (VIA_DEBUG
) fprintf(stderr
, "z format = 16\n");
829 format
= HC_HZWBFM_32
;
831 if (VIA_DEBUG
) fprintf(stderr
, "z format = 32\n");
836 offset
= vmesa
->depth
.offset
;
837 pitch
= vmesa
->depth
.pitch
;
839 *vb
++ = ((HC_SubA_HZWBBasL
<< 24) | (offset
& 0xFFFFFF));
841 *vb
++ = ((HC_SubA_HZWBBasH
<< 24) | ((offset
& 0xFF000000) >> 24));
842 *vb
++ = ((HC_SubA_HZWBType
<< 24) | HC_HDBLoc_Local
| HC_HZONEasFF_MASK
|
844 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
847 else if (vmesa
->hasStencil
) {
848 GLuint pitch
, format
, offset
;
850 format
= HC_HZWBFM_24
;
852 offset
= vmesa
->depth
.offset
;
853 pitch
= vmesa
->depth
.pitch
;
855 *vb
++ = ((HC_SubA_HZWBBasL
<< 24) | (offset
& 0xFFFFFF));
857 *vb
++ = ((HC_SubA_HZWBBasH
<< 24) | ((offset
& 0xFF000000) >> 24));
858 *vb
++ = ((HC_SubA_HZWBType
<< 24) | HC_HDBLoc_Local
| HC_HZONEasFF_MASK
|
860 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
862 *vb
++ = ((HC_SubA_HSTREF
<< 24) | vmesa
->regHSTREF
);
863 *vb
++ = ((HC_SubA_HSTMD
<< 24) | vmesa
->regHSTMD
);
868 if (ctx
->Color
.AlphaEnabled
) {
869 *vb
++ = ((HC_SubA_HATMD
<< 24) | vmesa
->regHATMD
);
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
);
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
);
895 if (ctx
->Line
.StippleFlag
) {
896 *vb
++ = ((HC_SubA_HLP
<< 24) | ctx
->Line
.StipplePattern
);
897 *vb
++ = ((HC_SubA_HLPRF
<< 24) | ctx
->Line
.StippleFactor
);
900 *vb
++ = ((HC_SubA_HLP
<< 24) | 0xFFFF);
901 *vb
++ = ((HC_SubA_HLPRF
<< 24) | 0x1);
906 *vb
++ = ((HC_SubA_HPixGC
<< 24) | 0x0);
914 if (ctx
->Texture
._EnabledUnits
) {
916 struct gl_texture_unit
*texUnit0
= &ctx
->Texture
.Unit
[0];
917 struct gl_texture_unit
*texUnit1
= &ctx
->Texture
.Unit
[1];
920 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texUnit0
->_Current
->DriverData
;
921 GLuint nDummyValue
= 0;
924 *vb
++ = (HC_ParaType_Tex
<< 16) | (HC_SubType_TexGeneral
<< 24);
926 if (ctx
->Texture
._EnabledUnits
> 1) {
928 if (VIA_DEBUG
) fprintf(stderr
, "multi texture\n");
930 nDummyValue
= (HC_SubA_HTXSMD
<< 24) | (1 << 3);
932 if (t
&& t
->needClearCache
) {
933 *vb
++ = nDummyValue
| HC_HTXCHCLR_MASK
;
943 if (VIA_DEBUG
) fprintf(stderr
, "single texture\n");
945 nDummyValue
= (HC_SubA_HTXSMD
<< 24) | 0;
947 if (t
&& t
->needClearCache
) {
948 *vb
++ = nDummyValue
| HC_HTXCHCLR_MASK
;
957 *vb
++ = HC_ParaType_NotTex
<< 16;
958 *vb
++ = (HC_SubA_HEnable
<< 24) | vmesa
->regEnable
;
959 *vb
++ = (HC_SubA_HEnable
<< 24) | vmesa
->regEnable
;
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;
970 fprintf(stderr
, "texture0 enabled\n");
971 fprintf(stderr
, "texture level %d\n", t
->actualLevel
);
974 if (numLevels
== 8) {
975 nDummyValue
= t
->regTexFM
;
977 *vb
++ = (HC_ParaType_Tex
<< 16) | (0 << 24);
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];
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
;
1007 else if (numLevels
> 1) {
1008 nDummyValue
= t
->regTexFM
;
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];
1017 if (numLevels
> 6) {
1018 *vb
++ = t
->regTexWidthLog2
[1];
1019 *vb
++ = t
->regTexHeightLog2
[1];
1023 *vb
++ = t
->regTexBaseH
[0];
1025 if (numLevels
> 3) {
1026 *vb
++ = t
->regTexBaseH
[1];
1029 if (numLevels
> 6) {
1030 *vb
++ = t
->regTexBaseH
[2];
1033 if (numLevels
> 9) {
1034 *vb
++ = t
->regTexBaseH
[3];
1040 for (j
= 0; j
< numLevels
; j
++) {
1041 *vb
++ = t
->regTexBaseAndPitch
[j
].baseL
;
1042 *vb
++ = t
->regTexBaseAndPitch
[j
].pitchLog2
;
1047 nDummyValue
= t
->regTexFM
;
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
;
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
;
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
;
1077 if (t
->regTexFM
== HC_HTXnFM_Index8
) {
1078 struct gl_color_table
*table
= &texObj
->Palette
;
1079 GLfloat
*tableF
= (GLfloat
*)table
->Table
;
1082 *vb
++ = (HC_ParaType_Palette
<< 16) | (0 << 24);
1084 for (j
= 0; j
< table
->Size
; j
++) {
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;
1102 fprintf(stderr
, "texture1 enabled\n");
1103 fprintf(stderr
, "texture level %d\n", t
->actualLevel
);
1106 if (numLevels
== 8) {
1107 nDummyValue
= t
->regTexFM
;
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];
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
;
1139 else if (numLevels
> 1) {
1140 nDummyValue
= t
->regTexFM
;
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];
1149 if (numLevels
> 6) {
1150 *vb
++ = t
->regTexWidthLog2
[1];
1151 *vb
++ = t
->regTexHeightLog2
[1];
1155 *vb
++ = t
->regTexBaseH
[0];
1157 if (numLevels
> 3) {
1158 *vb
++ = t
->regTexBaseH
[1];
1161 if (numLevels
> 6) {
1162 *vb
++ = t
->regTexBaseH
[2];
1165 if (numLevels
> 9) {
1166 *vb
++ = t
->regTexBaseH
[3];
1172 for (j
= 0; j
< numLevels
; j
++) {
1173 *vb
++ = t
->regTexBaseAndPitch
[j
].baseL
;
1174 *vb
++ = t
->regTexBaseAndPitch
[j
].pitchLog2
;
1179 nDummyValue
= t
->regTexFM
;
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
;
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
;
1204 if (t
->regTexFM
== HC_HTXnFM_Index8
) {
1205 struct gl_color_table
*table
= &texObj
->Palette
;
1206 GLfloat
*tableF
= (GLfloat
*)table
->Table
;
1209 *vb
++ = (HC_ParaType_Palette
<< 16) | (1 << 24);
1211 for (j
= 0; j
< table
->Size
; j
++) {
1224 if (ctx
->Polygon
.StippleFlag
) {
1225 GLuint
*stipple
= &ctx
->PolygonStipple
[0];
1228 *vb
++ = ((HC_ParaType_Palette
<< 16) | (HC_SubType_Stipple
<< 24));
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];
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)));
1270 vmesa
->dmaLow
+= (i
<< 2);
1274 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1279 static void emit_partial_state(viaContextPtr vmesa
)
1281 GLcontext
*ctx
= vmesa
->glCtx
;
1282 GLuint dirty
= vmesa
->dirty
;
1283 GLuint
*vb
= viaCheckDma(vmesa
, 0x110);
1287 if( VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1290 #ifdef PERFORMANCE_MEASURE
1291 if (VIA_PERFORMANCE
) P_M
;
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
);
1302 if (dirty
& VIA_UPLOAD_DESTBUFFER
) {
1305 if (dirty
& VIA_UPLOAD_DEPTHBUFFER
) {
1308 if (dirty
* VIA_UPLOAD_DEPTH
) {
1309 *vb
++ = ((HC_SubA_HZWTMD
<< 24) | vmesa
->regHZWTMD
);
1313 if (dirty
* VIA_UPLOAD_ALPHATEST
) {
1314 *vb
++ = ((HC_SubA_HATMD
<< 24) | vmesa
->regHATMD
);
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
);
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
);
1341 if (dirty
& VIA_UPLOAD_LINESTIPPLE
) {
1342 *vb
++ = ((HC_SubA_HLP
<< 24) | ctx
->Line
.StipplePattern
);
1343 *vb
++ = ((HC_SubA_HLPRF
<< 24) | ctx
->Line
.StippleFactor
);
1346 *vb
++ = ((HC_SubA_HLP
<< 24) | 0xFFFF);
1347 *vb
++ = ((HC_SubA_HLPRF
<< 24) | 0x1);
1351 *vb
++ = ((HC_SubA_HPixGC
<< 24) | 0x0);
1359 if (dirty
& VIA_UPLOAD_TEXTURE
) {
1363 if (dirty
& VIA_UPLOAD_POLYGONSTIPPLE
) {
1367 vmesa
->dmaLow
+= (i
<< 2);
1371 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1375 /**********************************************************************/
1376 /* High level hooks for t_vb_render.c */
1377 /**********************************************************************/
1379 /* Determine the rasterized primitive when not drawing unfilled
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.
1387 static void viaRenderPrimitive(GLcontext
*ctx
, GLenum prim
)
1389 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1390 GLuint rprim
= reducedPrim
[prim
];
1392 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1394 vmesa
->renderPrimitive
= prim
;
1395 viaRasterPrimitive(ctx
, rprim
, rprim
);
1397 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1401 static void viaRunPipeline(GLcontext
*ctx
)
1403 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1405 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1407 if (VIA_DEBUG
) fprintf(stderr
, "newState = %x\n", vmesa
->newState
);
1410 if (vmesa
->newState
) {
1411 if (vmesa
->newState
& _NEW_TEXTURE
)
1412 viaUpdateTextureState(ctx
); /* may modify vmesa->newState */
1414 viaChooseVertexState(ctx
);
1415 viaChooseRenderState(ctx
);
1416 vmesa
->newState
= 0;
1419 if (vmesa
->needUploadAllState
)
1420 emit_all_state(vmesa
);
1422 emit_partial_state(vmesa
);
1424 _tnl_run_pipeline(ctx
);
1426 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1430 static void viaRenderStart(GLcontext
*ctx
)
1433 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1436 /* Check for projective texturing. Make sure all texcoord
1437 * pointers point to something. (fix in mesa?)
1439 viaCheckTexSizes(ctx
);
1441 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1445 static void viaRenderFinish(GLcontext
*ctx
)
1448 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1450 if (VIA_CONTEXT(ctx
)->renderIndex
& VIA_FALLBACK_BIT
)
1453 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1458 /* System to flush dma and emit state changes based on the rasterized
1461 void viaRasterPrimitive(GLcontext
*ctx
,
1465 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1466 GLuint
*vb
= viaCheckDma(vmesa
, 32);
1470 fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1471 fprintf(stderr
, "hwprim = %x\n", hwprim
);
1474 /*=* [DBG] exy : fix wireframe + clipping error *=*/
1475 if (((rprim
== GL_TRIANGLES
&& (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
)))) {
1479 if (RasterCounter
> 0) {
1482 if (VIA_DEBUG
) fprintf(stderr
, "enter twice:%d\n",RasterCounter
);
1489 vmesa
->primitiveRendered
= GL_FALSE
;
1490 regCmdB
= vmesa
->regCmdB
;
1495 if (VIA_DEBUG
) fprintf(stderr
, "Points\n");
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
;
1503 if (VIA_DEBUG
) fprintf(stderr
, "Lines\n");
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
;
1512 if (VIA_DEBUG
) fprintf(stderr
, "Line Loop / Line Strip\n");
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
;
1522 if (VIA_DEBUG
) fprintf(stderr
, "Triangles\n");
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
;
1528 case GL_TRIANGLE_STRIP
:
1530 if (VIA_DEBUG
) fprintf(stderr
, "Triangle Strip\n");
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
;
1538 case GL_TRIANGLE_FAN
:
1540 if (VIA_DEBUG
) fprintf(stderr
, "Triangle Fan\n");
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
;
1550 if (VIA_DEBUG
) fprintf(stderr
, "No HW Quads\n");
1555 if (VIA_DEBUG
) fprintf(stderr
, "No HW Quad Strip\n");
1560 if (VIA_DEBUG
) fprintf(stderr
, "Polygon\n");
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
;
1570 if (VIA_DEBUG
) fprintf(stderr
, "Unknow\n");
1576 *vb
++ = (HC_ParaType_NotTex
<< 16);
1581 *vb
++ = (HC_ParaType_CmdVdata
<< 16);
1583 *vb
++ = vmesa
->regCmdA_End
;
1584 vmesa
->dmaLow
+= 32;
1586 vmesa
->reducedPrimitive
= rprim
;
1587 vmesa
->hwPrimitive
= rprim
;
1589 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1593 void viaRasterPrimitiveFinish(GLcontext
*ctx
)
1595 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
1597 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1599 if (VIA_DEBUG
) fprintf(stderr
, "primitiveRendered = %x\n", vmesa
->primitiveRendered
);
1601 if (RasterCounter
> 1) {
1604 if (VIA_DEBUG
) fprintf(stderr
, "finish enter twice: %d\n",RasterCounter
);
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
;
1615 /*=* John Sheng [2003.6.20] fix pci *=*/
1616 /*if (vmesa->dmaLow & 0x1) {*/
1617 if (vmesa
->dmaLow
& 0x1 || !vmesa
->useAgp
) {
1628 if (vmesa
->dmaLow
>= (32 + DMA_OFFSET
))
1629 vmesa
->dmaLow
-= 32;
1632 if (0) viaFlushPrimsLocked(vmesa
);
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
1641 viaFlushPrims(vmesa
);
1643 #ifdef PERFORMANCE_MEASURE
1650 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1655 /**********************************************************************/
1656 /* Transition to/from hardware rasterization. */
1657 /**********************************************************************/
1660 void viaFallback(viaContextPtr vmesa
, GLuint bit
, GLboolean mode
)
1662 GLcontext
*ctx
= vmesa
->glCtx
;
1663 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1664 GLuint oldfallback
= vmesa
->Fallback
;
1666 if (VIA_DEBUG
) fprintf(stderr
, "%s old %x bit %x mode %d\n", __FUNCTION__
,
1667 vmesa
->Fallback
, bit
, mode
);
1671 vmesa
->Fallback
|= bit
;
1672 if (oldfallback
== 0) {
1674 if (VIA_DEBUG
) fprintf(stderr
, "ENTER FALLBACK\n");
1676 VIA_FIREVERTICES(vmesa
);
1677 _swsetup_Wakeup(ctx
);
1678 vmesa
->renderIndex
= ~0;
1682 vmesa
->Fallback
&= ~bit
;
1683 if (oldfallback
== bit
) {
1685 if (VIA_DEBUG
) fprintf(stderr
, "LEAVE FALLBACK\n");
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
);
1698 /**********************************************************************/
1699 /* Initialization. */
1700 /**********************************************************************/
1703 void viaInitTriFuncs(GLcontext
*ctx
)
1705 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1706 static int firsttime
= 1;
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
;