Merge git://proxy01.pd.intel.com:9419/git/mesa/mesa into crestline
[mesa.git] / src / mesa / drivers / dri / unichrome / via_tris.c
index 5e697e32f7abed994274e278f2456b696fe605c4..4cc7942b1b617fe88b3a8b21fb6fc92212ba5d2e 100644 (file)
 #include "via_span.h"
 #include "via_ioctl.h"
 #include "via_3d_reg.h"
+#include "via_tex.h"
 
 /***********************************************************************
  *                    Emit primitives as inline vertices               *
  ***********************************************************************/
+#define LINE_FALLBACK (0)
+#define POINT_FALLBACK (0)
+#define TRI_FALLBACK (0)
+#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
+#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
+
 
-#if 1
+#if 0
+#define COPY_DWORDS(vb, vertsize, v)           \
+do {                                           \
+   via_sse_memcpy(vb, v, vertsize * 4);                \
+   vb += vertsize;                             \
+} while (0)
+#else
+#if defined( USE_X86_ASM )
 #define COPY_DWORDS(vb, vertsize, v)                                   \
     do {                                                               \
         int j;                                                         \
@@ -68,6 +82,7 @@
         vb += vertsize;                                \
     } while (0)
 #endif
+#endif
 
 static void via_draw_triangle(struct via_context *vmesa,
                              viaVertexPtr v0,
@@ -228,7 +243,7 @@ static struct {
     tnl_line_func            line;
     tnl_triangle_func        triangle;
     tnl_quad_func            quad;
-} rast_tab[VIA_MAX_TRIFUNC];
+} rast_tab[VIA_MAX_TRIFUNC + 1];
 
 
 #define DO_FALLBACK (IND & VIA_FALLBACK_BIT)
@@ -288,20 +303,21 @@ do {                                                              \
 
 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
 
-#define VERT_SET_SPEC( v0, c )                                 \
+#define VERT_SET_SPEC( v, c )                                  \
 do {                                                           \
    if (specoffset) {                                           \
-      UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]);    \
-      UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]);  \
-      UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]);   \
+     via_color_t *color = (via_color_t *)&((v)->ui[specoffset]);       \
+     UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]);             \
+     UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]);           \
+     UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]);            \
    }                                                           \
 } while (0)
 #define VERT_COPY_SPEC( v0, v1 )                       \
 do {                                                   \
    if (specoffset) {                                   \
-      v0->v.specular.red   = v1->v.specular.red;       \
-      v0->v.specular.green = v1->v.specular.green;     \
-      v0->v.specular.blue  = v1->v.specular.blue;      \
+      v0->ub4[specoffset][0] = v1->ub4[specoffset][0]; \
+      v0->ub4[specoffset][1] = v1->ub4[specoffset][1]; \
+      v0->ub4[specoffset][2] = v1->ub4[specoffset][2]; \
    }                                                   \
 } while (0)
 
@@ -324,7 +340,7 @@ do {                                                        \
  *                Helpers for rendering unfilled primitives            *
  ***********************************************************************/
 
-static const GLenum hwPrim[GL_POLYGON + 1] = {
+static const GLenum hwPrim[GL_POLYGON + 2] = {
     GL_POINTS,
     GL_LINES,
     GL_LINES,
@@ -334,7 +350,8 @@ static const GLenum hwPrim[GL_POLYGON + 1] = {
     GL_TRIANGLES,
     GL_TRIANGLES,
     GL_TRIANGLES,
-    GL_TRIANGLES
+    GL_TRIANGLES,
+    GL_POLYGON+1
 };
 
 
@@ -417,6 +434,24 @@ static const GLenum hwPrim[GL_POLYGON + 1] = {
 #include "tnl_dd/t_dd_tritmp.h"
 
 
+/* Catchall case for flat, separate specular triangles (via has flat
+ * diffuse shading, but always does specular color with gouraud).
+ */
+#undef  DO_FALLBACK
+#undef  DO_OFFSET
+#undef  DO_UNFILLED
+#undef  DO_TWOSIDE
+#undef  DO_FLAT
+#define DO_FALLBACK (0)
+#define DO_OFFSET   (ctx->_TriangleCaps & DD_TRI_OFFSET)
+#define DO_UNFILLED (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define DO_TWOSIDE  (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE)
+#define DO_FLAT     1
+#define TAG(x) x##_flat_specular
+#define IND VIA_MAX_TRIFUNC
+#include "tnl_dd/t_dd_tritmp.h"
+
+
 static void init_rast_tab(void)
 {
     init();
@@ -435,6 +470,8 @@ static void init_rast_tab(void)
     init_offset_unfilled_fallback();
     init_twoside_unfilled_fallback();
     init_twoside_offset_unfilled_fallback();
+
+    init_flat_specular();      /* special! */
 }
 
 
@@ -560,7 +597,8 @@ static void viaRenderClippedPoly(GLcontext *ctx, const GLuint *elts,
 
     /* Restore the render primitive
      */
-    if (prim != GL_POLYGON)
+    if (prim != GL_POLYGON &&
+       prim != GL_POLYGON + 1)
        tnl->Driver.Render.PrimitiveNotify( ctx, prim );
 }
 
@@ -607,11 +645,6 @@ static void viaFastRenderClippedPoly(GLcontext *ctx, const GLuint *elts,
                               _DD_NEW_TRI_STIPPLE |             \
                               _NEW_POLYGONSTIPPLE)
 
-#define LINE_FALLBACK (0)
-#define POINT_FALLBACK (0)
-#define TRI_FALLBACK (0)
-#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
-#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
 
 static void viaChooseRenderState(GLcontext *ctx)
 {
@@ -650,6 +683,12 @@ static void viaChooseRenderState(GLcontext *ctx)
         vmesa->drawTri = via_fallback_tri;
    }
 
+
+   if ((flags & DD_SEPARATE_SPECULAR) &&
+       ctx->Light.ShadeModel == GL_FLAT) {
+      index = VIA_MAX_TRIFUNC; /* flat specular */
+   }
+
    if (vmesa->renderIndex != index) {
       vmesa->renderIndex = index;
 
@@ -705,16 +744,18 @@ static void viaChooseVertexState( GLcontext *ctx )
 {
    struct via_context *vmesa = VIA_CONTEXT(ctx);
    TNLcontext *tnl = TNL_CONTEXT(ctx);
-   GLuint index = tnl->render_inputs;
+   DECLARE_RENDERINPUTS(index_bitset);
    GLuint regCmdB = HC_HVPMSK_X | HC_HVPMSK_Y | HC_HVPMSK_Z;
    GLuint setupIndex = 0;
 
+   RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
    vmesa->vertex_attr_count = 0;
  
    /* EMIT_ATTR's must be in order as they tell t_vertex.c how to
     * build up a hardware vertex.
     */
-   if (index & (_TNL_BITS_TEX_ANY|_TNL_BIT_FOG)) {
+   if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) ||
+       RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
       EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VIA_EMIT_W, HC_HVPMSK_W );
       vmesa->coloroffset = 4;
    }
@@ -728,8 +769,9 @@ static void viaChooseVertexState( GLcontext *ctx )
              HC_HVPMSK_Cd );
       
    vmesa->specoffset = 0;
-   if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) {
-      if ((index & _TNL_BIT_COLOR1)) {
+   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) ||
+       RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
+      if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
         vmesa->specoffset = vmesa->coloroffset + 1;
         EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VIA_EMIT_SPEC, 
                    HC_HVPMSK_Cs );
@@ -737,13 +779,13 @@ static void viaChooseVertexState( GLcontext *ctx )
       else
         EMIT_PAD( 3 );
 
-      if ((index & _TNL_BIT_FOG))
+      if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG ))
         EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VIA_EMIT_FOG, HC_HVPMSK_Cs );
       else
         EMIT_PAD( 1 );
    }
 
-   if (index & _TNL_BIT_TEX(0)) {
+   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 )) {
       if (vmesa->ptexHack)
         EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, VIA_EMIT_PTEX0, 
                    (HC_HVPMSK_S | HC_HVPMSK_T) );
@@ -752,7 +794,7 @@ static void viaChooseVertexState( GLcontext *ctx )
                    (HC_HVPMSK_S | HC_HVPMSK_T) );
    }
 
-   if (index & _TNL_BIT_TEX(1)) {
+   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 )) {
       EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, VIA_EMIT_TEX1, 
                 (HC_HVPMSK_S | HC_HVPMSK_T) );
    }
@@ -785,17 +827,19 @@ static GLboolean viaCheckPTexHack( GLcontext *ctx )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
-   GLuint index = tnl->render_inputs;
+   DECLARE_RENDERINPUTS(index_bitset);
    GLboolean fallback = GL_FALSE;
    GLboolean ptexHack = GL_FALSE;
 
-   if (index & _TNL_BIT_TEX(0) && VB->TexCoordPtr[0]->size == 4) {
-      if ((index & _TNL_BITS_TEX_ANY) == _TNL_BIT_TEX(0))
+   RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
+
+   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 ) && VB->TexCoordPtr[0]->size == 4) {
+      if (!RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_ATTRIB_TEX1, _TNL_LAST_TEX ))
         ptexHack = GL_TRUE; 
       else
         fallback = GL_TRUE;
    }
-   if ((index & _TNL_BIT_TEX(1)) && VB->TexCoordPtr[1]->size == 4)
+   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 ) && VB->TexCoordPtr[1]->size == 4)
       fallback = GL_TRUE;
 
    FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_PROJ_TEXTURE, fallback);
@@ -863,13 +907,18 @@ void viaRasterPrimitive(GLcontext *ctx,
    RING_VARS;
 
    if (VIA_DEBUG & DEBUG_PRIMS) 
-      fprintf(stderr, "%s: %s/%s\n", 
+      fprintf(stderr, "%s: %s/%s/%s\n", 
              __FUNCTION__, _mesa_lookup_enum_by_nr(glprim),
-             _mesa_lookup_enum_by_nr(hwprim));
+             _mesa_lookup_enum_by_nr(hwprim),
+             _mesa_lookup_enum_by_nr(ctx->Light.ShadeModel));
+
+   assert (!vmesa->newState);
 
    vmesa->renderPrimitive = glprim;
 
-   if (hwprim != vmesa->hwPrimitive) {
+   if (hwprim != vmesa->hwPrimitive ||
+       ctx->Light.ShadeModel != vmesa->hwShadeModel) {
+
       VIA_FINISH_PRIM(vmesa);
 
       /* Ensure no wrapping inside this function  */    
@@ -884,7 +933,8 @@ void viaRasterPrimitive(GLcontext *ctx,
       if (ctx->Light.ShadeModel == GL_SMOOTH) {
         vmesa->regCmdA_End |= HC_HShading_Gouraud;
       }
-
+      
+      vmesa->hwShadeModel = ctx->Light.ShadeModel;
       regCmdB = vmesa->regCmdB;
 
       switch (hwprim) {