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.
35 #include "swrast/swrast.h"
36 #include "swrast_setup/swrast_setup.h"
37 #include "tnl/t_context.h"
38 #include "tnl/t_pipeline.h"
40 #include "via_context.h"
42 #include "via_state.h"
44 #include "via_ioctl.h"
46 /***********************************************************************
47 * Emit primitives as inline vertices *
48 ***********************************************************************/
51 #define COPY_DWORDS(vb, vertsize, v) \
55 __asm__ __volatile__("rep ; movsl" \
56 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
62 #define COPY_DWORDS(vb, vertsize, v) \
65 for (j = 0; j < vertsize; j++) \
66 vb[j] = ((GLuint *)v)[j]; \
71 static void __inline__
via_draw_triangle(viaContextPtr vmesa
,
76 GLuint vertsize
= vmesa
->vertexSize
;
77 GLuint
*vb
= viaAllocDma(vmesa
, 3 * 4 * vertsize
);
78 /* fprintf(stderr, "%s: %p %p %p\n", __FUNCTION__, v0, v1, v2); */
79 COPY_DWORDS(vb
, vertsize
, v0
);
80 COPY_DWORDS(vb
, vertsize
, v1
);
81 COPY_DWORDS(vb
, vertsize
, v2
);
85 static void __inline__
via_draw_quad(viaContextPtr vmesa
,
91 GLuint vertsize
= vmesa
->vertexSize
;
92 GLuint
*vb
= viaAllocDma(vmesa
, 6 * 4 * vertsize
);
94 /* fprintf(stderr, "%s: %p %p %p %p\n", __FUNCTION__, v0, v1, v2, v3); */
95 COPY_DWORDS(vb
, vertsize
, v0
);
96 COPY_DWORDS(vb
, vertsize
, v1
);
97 COPY_DWORDS(vb
, vertsize
, v3
);
98 COPY_DWORDS(vb
, vertsize
, v1
);
99 COPY_DWORDS(vb
, vertsize
, v2
);
100 COPY_DWORDS(vb
, vertsize
, v3
);
103 static __inline__
void via_draw_line(viaContextPtr vmesa
,
107 GLuint vertsize
= vmesa
->vertexSize
;
108 GLuint
*vb
= viaAllocDma(vmesa
, 2 * 4 * vertsize
);
109 COPY_DWORDS(vb
, vertsize
, v0
);
110 COPY_DWORDS(vb
, vertsize
, v1
);
114 static __inline__
void via_draw_point(viaContextPtr vmesa
,
117 GLuint vertsize
= vmesa
->vertexSize
;
118 GLuint
*vb
= viaAllocDma(vmesa
, 4 * vertsize
);
119 COPY_DWORDS(vb
, vertsize
, v0
);
125 /***********************************************************************
126 * Macros for via_dd_tritmp.h to draw basic primitives *
127 ***********************************************************************/
129 #define TRI(a, b, c) \
131 if (VIA_DEBUG) fprintf(stderr, "hw TRI\n"); \
133 vmesa->drawTri(vmesa, a, b, c); \
135 via_draw_triangle(vmesa, a, b, c); \
138 #define QUAD(a, b, c, d) \
140 if (VIA_DEBUG) fprintf(stderr, "hw QUAD\n");\
142 vmesa->drawTri(vmesa, a, b, d); \
143 vmesa->drawTri(vmesa, b, c, d); \
146 via_draw_quad(vmesa, a, b, c, d); \
149 #define LINE(v0, v1) \
151 if(VIA_DEBUG) fprintf(stderr, "hw LINE\n");\
153 vmesa->drawLine(vmesa, v0, v1); \
155 via_draw_line(vmesa, v0, v1); \
160 if (VIA_DEBUG) fprintf(stderr, "hw POINT\n");\
162 vmesa->drawPoint(vmesa, v0); \
164 via_draw_point(vmesa, v0); \
168 /***********************************************************************
169 * Build render functions from dd templates *
170 ***********************************************************************/
172 #define VIA_OFFSET_BIT 0x01
173 #define VIA_TWOSIDE_BIT 0x02
174 #define VIA_UNFILLED_BIT 0x04
175 #define VIA_FALLBACK_BIT 0x08
176 #define VIA_MAX_TRIFUNC 0x10
180 tnl_points_func points
;
182 tnl_triangle_func triangle
;
184 } rast_tab
[VIA_MAX_TRIFUNC
];
187 #define DO_FALLBACK (IND & VIA_FALLBACK_BIT)
188 #define DO_OFFSET (IND & VIA_OFFSET_BIT)
189 #define DO_UNFILLED (IND & VIA_UNFILLED_BIT)
190 #define DO_TWOSIDE (IND & VIA_TWOSIDE_BIT)
196 #define DO_FULL_QUAD 1
200 #define HAVE_BACK_COLORS 0
201 #define HAVE_HW_FLATSHADE 1
202 #define VERTEX viaVertex
205 /* Only used to pull back colors into vertices (ie, we know color is
208 #define VIA_COLOR(dst, src) \
216 #define VIA_SPEC(dst, src) \
224 #define DEPTH_SCALE (1.0 / 0xffff)
225 #define UNFILLED_TRI unfilled_tri
226 #define UNFILLED_QUAD unfilled_quad
227 #define VERT_X(_v) _v->v.x
228 #define VERT_Y(_v) _v->v.y
229 #define VERT_Z(_v) _v->v.z
230 #define AREA_IS_CCW(a) (a > 0)
231 #define GET_VERTEX(e) (vmesa->verts + (e * vmesa->vertexSize * sizeof(int)))
233 #define VERT_SET_RGBA( v, c ) \
235 via_color_t *color = (via_color_t *)&((v)->ui[coloroffset]); \
236 UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]); \
237 UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]); \
238 UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]); \
239 UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]); \
242 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
244 #define VERT_SET_SPEC( v0, c ) \
247 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]); \
248 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]); \
249 UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]); \
252 #define VERT_COPY_SPEC( v0, v1 ) \
255 v0->v.specular.red = v1->v.specular.red; \
256 v0->v.specular.green = v1->v.specular.green; \
257 v0->v.specular.blue = v1->v.specular.blue; \
262 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
263 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
264 #define VERT_SAVE_SPEC( idx ) if (havespec) spec[idx] = v[idx]->ui[5]
265 #define VERT_RESTORE_SPEC( idx ) if (havespec) v[idx]->ui[5] = spec[idx]
268 #define LOCAL_VARS(n) \
269 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
270 GLuint color[n], spec[n]; \
271 GLuint coloroffset = (vmesa->vertexSize == 4 ? 3 : 4); \
272 GLboolean havespec = (vmesa->vertexSize > 4); \
273 (void)color; (void)spec; (void)coloroffset; (void)havespec;
276 /***********************************************************************
277 * Helpers for rendering unfilled primitives *
278 ***********************************************************************/
280 static const GLenum hwPrim
[GL_POLYGON
+ 1] = {
294 #define RASTERIZE(x) viaRasterPrimitive( ctx, x, hwPrim[x] )
295 #define RENDER_PRIMITIVE vmesa->renderPrimitive
297 #define IND VIA_FALLBACK_BIT
298 #include "tnl_dd/t_dd_unfilled.h"
302 /***********************************************************************
303 * Generate GL render functions *
304 ***********************************************************************/
309 #include "tnl_dd/t_dd_tritmp.h"
311 #define IND (VIA_OFFSET_BIT)
312 #define TAG(x) x##_offset
313 #include "tnl_dd/t_dd_tritmp.h"
315 #define IND (VIA_TWOSIDE_BIT)
316 #define TAG(x) x##_twoside
317 #include "tnl_dd/t_dd_tritmp.h"
319 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT)
320 #define TAG(x) x##_twoside_offset
321 #include "tnl_dd/t_dd_tritmp.h"
323 #define IND (VIA_UNFILLED_BIT)
324 #define TAG(x) x##_unfilled
325 #include "tnl_dd/t_dd_tritmp.h"
327 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
328 #define TAG(x) x##_offset_unfilled
329 #include "tnl_dd/t_dd_tritmp.h"
331 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT)
332 #define TAG(x) x##_twoside_unfilled
333 #include "tnl_dd/t_dd_tritmp.h"
335 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT)
336 #define TAG(x) x##_twoside_offset_unfilled
337 #include "tnl_dd/t_dd_tritmp.h"
339 #define IND (VIA_FALLBACK_BIT)
340 #define TAG(x) x##_fallback
341 #include "tnl_dd/t_dd_tritmp.h"
343 #define IND (VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
344 #define TAG(x) x##_offset_fallback
345 #include "tnl_dd/t_dd_tritmp.h"
347 #define IND (VIA_TWOSIDE_BIT|VIA_FALLBACK_BIT)
348 #define TAG(x) x##_twoside_fallback
349 #include "tnl_dd/t_dd_tritmp.h"
351 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_FALLBACK_BIT)
352 #define TAG(x) x##_twoside_offset_fallback
353 #include "tnl_dd/t_dd_tritmp.h"
355 #define IND (VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
356 #define TAG(x) x##_unfilled_fallback
357 #include "tnl_dd/t_dd_tritmp.h"
359 #define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
360 #define TAG(x) x##_offset_unfilled_fallback
361 #include "tnl_dd/t_dd_tritmp.h"
363 #define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)
364 #define TAG(x) x##_twoside_unfilled_fallback
365 #include "tnl_dd/t_dd_tritmp.h"
367 #define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT| \
369 #define TAG(x) x##_twoside_offset_unfilled_fallback
370 #include "tnl_dd/t_dd_tritmp.h"
373 static void init_rast_tab(void)
378 init_twoside_offset();
380 init_offset_unfilled();
381 init_twoside_unfilled();
382 init_twoside_offset_unfilled();
384 init_offset_fallback();
385 init_twoside_fallback();
386 init_twoside_offset_fallback();
387 init_unfilled_fallback();
388 init_offset_unfilled_fallback();
389 init_twoside_unfilled_fallback();
390 init_twoside_offset_unfilled_fallback();
394 /***********************************************************************
395 * Rasterization fallback helpers *
396 ***********************************************************************/
399 /* This code is hit only when a mix of accelerated and unaccelerated
400 * primitives are being drawn, and only for the unaccelerated
404 via_fallback_tri(viaContextPtr vmesa
,
409 GLcontext
*ctx
= vmesa
->glCtx
;
411 via_translate_vertex(ctx
, v0
, &v
[0]);
412 via_translate_vertex(ctx
, v1
, &v
[1]);
413 via_translate_vertex(ctx
, v2
, &v
[2]);
414 viaSpanRenderStart( ctx
);
415 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
416 viaSpanRenderFinish( ctx
);
421 via_fallback_line(viaContextPtr vmesa
,
425 GLcontext
*ctx
= vmesa
->glCtx
;
427 via_translate_vertex(ctx
, v0
, &v
[0]);
428 via_translate_vertex(ctx
, v1
, &v
[1]);
429 viaSpanRenderStart( ctx
);
430 _swrast_Line(ctx
, &v
[0], &v
[1]);
431 viaSpanRenderFinish( ctx
);
436 via_fallback_point(viaContextPtr vmesa
,
439 GLcontext
*ctx
= vmesa
->glCtx
;
441 via_translate_vertex(ctx
, v0
, &v
[0]);
442 viaSpanRenderStart( ctx
);
443 _swrast_Point(ctx
, &v
[0]);
444 viaSpanRenderFinish( ctx
);
447 /**********************************************************************/
448 /* Render unclipped begin/end objects */
449 /**********************************************************************/
451 #define V(x) (viaVertex *)(vertptr + ((x) * vertsize * sizeof(int)))
452 #define RENDER_POINTS(start, count) \
453 for (; start < count; start++) POINT(V(ELT(start)));
454 #define RENDER_LINE(v0, v1) LINE(V(v0), V(v1))
455 #define RENDER_TRI( v0, v1, v2) TRI( V(v0), V(v1), V(v2))
456 #define RENDER_QUAD(v0, v1, v2, v3) QUAD(V(v0), V(v1), V(v2), V(v3))
457 #define INIT(x) viaRasterPrimitive(ctx, x, hwPrim[x])
460 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
461 GLubyte *vertptr = (GLubyte *)vmesa->verts; \
462 const GLuint vertsize = vmesa->vertexSize; \
463 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
465 #define RESET_STIPPLE
466 #define RESET_OCCLUSION
467 #define PRESERVE_VB_DEFS
469 #define TAG(x) via_fast##x##_verts
470 #include "tnl/t_vb_rendertmp.h"
473 #define TAG(x) via_fast##x##_elts
474 #define ELT(x) elt[x]
475 #include "tnl/t_vb_rendertmp.h"
478 #undef NEED_EDGEFLAG_SETUP
481 #undef RESET_OCCLUSION
484 /**********************************************************************/
485 /* Render clipped primitives */
486 /**********************************************************************/
490 static void viaRenderClippedPoly(GLcontext
*ctx
, const GLuint
*elts
,
493 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
494 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
495 GLuint prim
= VIA_CONTEXT(ctx
)->renderPrimitive
;
497 /* Render the new vertices as an unclipped polygon.
500 GLuint
*tmp
= VB
->Elts
;
501 VB
->Elts
= (GLuint
*)elts
;
502 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
](ctx
, 0, n
,
503 PRIM_BEGIN
|PRIM_END
);
507 /* Restore the render primitive
509 if (prim
!= GL_POLYGON
)
510 tnl
->Driver
.Render
.PrimitiveNotify( ctx
, prim
);
513 static void viaRenderClippedLine(GLcontext
*ctx
, GLuint ii
, GLuint jj
)
515 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
516 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
519 static void viaFastRenderClippedPoly(GLcontext
*ctx
, const GLuint
*elts
,
522 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
523 GLuint vertsize
= vmesa
->vertexSize
;
524 GLuint
*vb
= viaAllocDma(vmesa
, (n
- 2) * 3 * 4 * vertsize
);
525 GLubyte
*vertptr
= (GLubyte
*)vmesa
->verts
;
526 const GLuint
*start
= (const GLuint
*)V(elts
[0]);
529 for (i
= 2; i
< n
; i
++) {
530 COPY_DWORDS(vb
, vertsize
, V(elts
[i
- 1]));
531 COPY_DWORDS(vb
, vertsize
, V(elts
[i
]));
532 COPY_DWORDS(vb
, vertsize
, start
);
536 /**********************************************************************/
537 /* Choose render functions */
538 /**********************************************************************/
542 #define _VIA_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE | \
543 _DD_NEW_TRI_UNFILLED | \
544 _DD_NEW_TRI_LIGHT_TWOSIDE | \
545 _DD_NEW_TRI_OFFSET | \
546 _DD_NEW_TRI_STIPPLE | \
549 /* Via does support line stipple in hardware, and it is partially
550 * working in the older versions of this driver:
552 #define LINE_FALLBACK (DD_LINE_STIPPLE)
553 #define POINT_FALLBACK (0)
554 #define TRI_FALLBACK (0)
555 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
556 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
558 static void viaChooseRenderState(GLcontext
*ctx
)
560 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
561 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
562 GLuint flags
= ctx
->_TriangleCaps
;
564 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
566 if (VIA_DEBUG
) fprintf(stderr
, "_TriangleCaps = %x\n", flags
);
567 if (flags
& (ANY_FALLBACK_FLAGS
|ANY_RASTER_FLAGS
)) {
568 if (flags
& ANY_RASTER_FLAGS
) {
569 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= VIA_TWOSIDE_BIT
;
570 if (flags
& DD_TRI_OFFSET
) index
|= VIA_OFFSET_BIT
;
571 if (flags
& DD_TRI_UNFILLED
) index
|= VIA_UNFILLED_BIT
;
574 vmesa
->drawPoint
= via_draw_point
;
575 vmesa
->drawLine
= via_draw_line
;
576 vmesa
->drawTri
= via_draw_triangle
;
578 /* Hook in fallbacks for specific primitives.
580 if (flags
& ANY_FALLBACK_FLAGS
) {
581 if (flags
& POINT_FALLBACK
)
582 vmesa
->drawPoint
= via_fallback_point
;
584 if (flags
& LINE_FALLBACK
)
585 vmesa
->drawLine
= via_fallback_line
;
587 if (flags
& TRI_FALLBACK
)
588 vmesa
->drawTri
= via_fallback_tri
;
590 index
|= VIA_FALLBACK_BIT
;
594 fprintf(stderr
, "index = %x\n", index
);
595 fprintf(stderr
, "renderIndex = %x\n", vmesa
->renderIndex
);
597 if (vmesa
->renderIndex
!= index
) {
598 vmesa
->renderIndex
= index
;
600 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
601 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
602 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
604 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
607 tnl
->Driver
.Render
.PrimTabVerts
= via_fastrender_tab_verts
;
608 tnl
->Driver
.Render
.PrimTabElts
= via_fastrender_tab_elts
;
609 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
610 tnl
->Driver
.Render
.ClippedPolygon
= viaFastRenderClippedPoly
;
613 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
614 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
615 tnl
->Driver
.Render
.ClippedLine
= viaRenderClippedLine
;
616 tnl
->Driver
.Render
.ClippedPolygon
= viaRenderClippedPoly
;
619 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
626 /**********************************************************************/
627 /* High level hooks for t_vb_render.c */
628 /**********************************************************************/
630 static void viaRunPipeline(GLcontext
*ctx
)
632 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
634 if (vmesa
->newState
) {
635 viaValidateState( ctx
);
637 if (!vmesa
->Fallback
) {
638 viaChooseVertexState(ctx
);
639 viaChooseRenderState(ctx
);
643 _tnl_run_pipeline(ctx
);
646 static void viaRenderStart(GLcontext
*ctx
)
648 /* Check for projective texturing. Make sure all texcoord
649 * pointers point to something. (fix in mesa?)
651 viaCheckTexSizes(ctx
);
654 static void viaRenderFinish(GLcontext
*ctx
)
656 if (VIA_CONTEXT(ctx
)->renderIndex
& VIA_FALLBACK_BIT
)
659 VIA_FINISH_PRIM(VIA_CONTEXT(ctx
));
664 /* System to flush dma and emit state changes based on the rasterized
667 void viaRasterPrimitive(GLcontext
*ctx
,
671 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
676 fprintf(stderr
, "%s: %s/%s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(glprim
),
677 _mesa_lookup_enum_by_nr(hwprim
));
679 VIA_FINISH_PRIM(vmesa
);
681 vmesa
->renderPrimitive
= glprim
;
683 regCmdB
= vmesa
->regCmdB
;
687 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Point
| HC_HVCycle_Full
;
688 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
689 vmesa
->regCmdA_End
|= HC_HShading_FlatA
;
692 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Line
| HC_HVCycle_Full
;
693 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
694 vmesa
->regCmdA_End
|= HC_HShading_FlatB
;
698 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Line
| HC_HVCycle_AFP
|
699 HC_HVCycle_AB
| HC_HVCycle_NewB
;
700 regCmdB
|= HC_HVCycle_AB
| HC_HVCycle_NewB
| HC_HLPrst_MASK
;
701 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
702 vmesa
->regCmdA_End
|= HC_HShading_FlatB
;
705 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_Full
;
706 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
707 vmesa
->regCmdA_End
|= HC_HShading_FlatC
;
709 case GL_TRIANGLE_STRIP
:
710 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_AFP
|
711 HC_HVCycle_AC
| HC_HVCycle_BB
| HC_HVCycle_NewC
;
712 regCmdB
|= HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
713 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
714 vmesa
->regCmdA_End
|= HC_HShading_FlatB
;
716 case GL_TRIANGLE_FAN
:
717 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_AFP
|
718 HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
719 regCmdB
|= HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
720 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
721 vmesa
->regCmdA_End
|= HC_HShading_FlatC
;
730 vmesa
->regCmdA_End
= vmesa
->regCmdA
| HC_HPMType_Tri
| HC_HVCycle_AFP
|
731 HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
732 regCmdB
|= HC_HVCycle_AA
| HC_HVCycle_BC
| HC_HVCycle_NewC
;
733 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
734 vmesa
->regCmdA_End
|= HC_HShading_FlatC
;
741 assert((vmesa
->dmaLow
& 0x4) == 0);
744 OUT_RING( HC_HEADER2
);
745 OUT_RING( (HC_ParaType_NotTex
<< 16) );
746 OUT_RING( 0xCCCCCCCC );
747 OUT_RING( 0xDDDDDDDD );
749 OUT_RING( HC_HEADER2
);
750 OUT_RING( (HC_ParaType_CmdVdata
<< 16) );
752 OUT_RING( vmesa
->regCmdA_End
);
755 vmesa
->dmaLastPrim
= vmesa
->dmaLow
;
756 vmesa
->hwPrimitive
= hwprim
;
759 /* Callback for mesa:
761 static void viaRenderPrimitive( GLcontext
*ctx
, GLuint prim
)
763 viaRasterPrimitive( ctx
, prim
, hwPrim
[prim
] );
767 void viaFinishPrimitive(viaContextPtr vmesa
)
769 if (!vmesa
->dmaLastPrim
) {
772 else if (vmesa
->dmaLow
!= vmesa
->dmaLastPrim
) {
773 GLuint cmdA
= vmesa
->regCmdA_End
| HC_HPLEND_MASK
| HC_HPMValidN_MASK
| HC_HE3Fire_MASK
;
776 /* KW: modified 0x1 to 0x4 below:
778 if ((vmesa
->dmaLow
& 0x1) || !vmesa
->useAgp
) {
779 BEGIN_RING_NOCHECK( 1 );
784 BEGIN_RING_NOCHECK( 2 );
789 vmesa
->dmaLastPrim
= 0;
791 if (1 || vmesa
->dmaLow
> VIA_DMA_HIGHWATER
)
792 viaFlushPrims( vmesa
);
795 assert(vmesa
->dmaLow
>= (32 + DMA_OFFSET
));
797 vmesa
->dmaLastPrim
= 0;
802 /**********************************************************************/
803 /* Transition to/from hardware rasterization. */
804 /**********************************************************************/
807 void viaFallback(viaContextPtr vmesa
, GLuint bit
, GLboolean mode
)
809 GLcontext
*ctx
= vmesa
->glCtx
;
810 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
811 GLuint oldfallback
= vmesa
->Fallback
;
812 if (VIA_DEBUG
) fprintf(stderr
, "%s old %x bit %x mode %d\n", __FUNCTION__
,
813 vmesa
->Fallback
, bit
, mode
);
816 vmesa
->Fallback
|= bit
;
817 if (oldfallback
== 0) {
818 if (VIA_DEBUG
) fprintf(stderr
, "ENTER FALLBACK\n");
819 VIA_FLUSH_DMA(vmesa
);
820 _swsetup_Wakeup(ctx
);
821 vmesa
->renderIndex
= ~0;
825 vmesa
->Fallback
&= ~bit
;
826 if (oldfallback
== bit
) {
827 if (VIA_DEBUG
) fprintf(stderr
, "LEAVE FALLBACK\n");
828 tnl
->Driver
.Render
.Start
= viaRenderStart
;
829 tnl
->Driver
.Render
.PrimitiveNotify
= viaRenderPrimitive
;
830 tnl
->Driver
.Render
.Finish
= viaRenderFinish
;
831 tnl
->Driver
.Render
.BuildVertices
= viaBuildVertices
;
832 vmesa
->newState
|= (_VIA_NEW_RENDERSTATE
|_VIA_NEW_VERTEX
);
839 /**********************************************************************/
840 /* Initialization. */
841 /**********************************************************************/
844 void viaInitTriFuncs(GLcontext
*ctx
)
846 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
847 static int firsttime
= 1;
854 tnl
->Driver
.RunPipeline
= viaRunPipeline
;
855 tnl
->Driver
.Render
.Start
= viaRenderStart
;
856 tnl
->Driver
.Render
.Finish
= viaRenderFinish
;
857 tnl
->Driver
.Render
.PrimitiveNotify
= viaRenderPrimitive
;
858 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
859 tnl
->Driver
.Render
.BuildVertices
= viaBuildVertices
;