BTW. Here's an updated pair of patches. These ones should compile, but I haven't done much testing yet.


I keep dipping in & out of this, so I loose track somewhat... What are the simplest test cases for these crashes?

Keith
Index: r200/r200_tcl.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/r200/r200_tcl.c,v
retrieving revision 1.9
diff -u -r1.9 r200_tcl.c
--- r200/r200_tcl.c     30 Apr 2003 01:50:49 -0000      1.9
+++ r200/r200_tcl.c     24 Jul 2003 18:58:35 -0000
@@ -103,32 +103,22 @@
    
 
 #define LOCAL_VARS r200ContextPtr rmesa = R200_CONTEXT(ctx)
-#define ELTS_VARS  GLushort *dest
+#define ELT_TYPE  GLushort
 
 #define ELT_INIT(prim, hw_prim) \
    r200TclPrimitive( ctx, prim, hw_prim | R200_VF_PRIM_WALK_IND )
 
-#define GET_ELTS() rmesa->tcl.Elts
+#define GET_MESA_ELTS() rmesa->tcl.Elts
 
 
-#define NEW_PRIMITIVE()  R200_NEWPRIM( rmesa )
-#define NEW_BUFFER()  r200RefillCurrentDmaRegion( rmesa )
-
 /* Don't really know how many elts will fit in what's left of cmdbuf,
  * as there is state to emit, etc:
  */
 
-#if 0
-#define GET_CURRENT_VB_MAX_ELTS() \
-   ((R200_CMD_BUF_SZ - (rmesa->store.cmd_used + 16)) / 2) 
-#define GET_SUBSEQUENT_VB_MAX_ELTS() ((R200_CMD_BUF_SZ - 16) / 2) 
-#else
 /* Testing on isosurf shows a maximum around here.  Don't know if it's
  * the card or driver or kernel module that is causing the behaviour.
  */
-#define GET_CURRENT_VB_MAX_ELTS() 300
-#define GET_SUBSEQUENT_VB_MAX_ELTS() 300
-#endif
+#define GET_MAX_HW_ELTS() 300
 
 #define RESET_STIPPLE() do {                   \
    R200_STATECHANGE( rmesa, lin );             \
@@ -147,32 +137,22 @@
 } while (0)
 
 
-/* How do you extend an existing primitive?
- */
-#define ALLOC_ELTS(nr)                                                 \
-do {                                                                   \
-   if (rmesa->dma.flush == r200FlushElts &&                            \
-       rmesa->store.cmd_used + nr*2 < R200_CMD_BUF_SZ) {               \
-                                                                       \
-      dest = (GLushort *)(rmesa->store.cmd_buf +                       \
-                         rmesa->store.cmd_used);                       \
-      rmesa->store.cmd_used += nr*2;                                   \
-   }                                                                   \
-   else {                                                              \
-      if (rmesa->dma.flush)                                            \
-        rmesa->dma.flush( rmesa );                                     \
-                                                                       \
-      r200EmitAOS( rmesa,                                              \
-                    rmesa->tcl.aos_components,                         \
-                    rmesa->tcl.nr_aos_components,                      \
-                    0 );                                               \
-                                                                       \
-      dest = r200AllocEltsOpenEnded( rmesa,                            \
-                                      rmesa->tcl.hw_primitive,         \
-                                      nr );                            \
-   }                                                                   \
-} while (0) 
+#define ALLOC_ELTS(nr) r200AllocElts( rmesa, nr )
 
+static GLushort *r200AllocElts( r200ContextPtr rmesa, GLuint nr ) 
+{
+   if (rmesa->dma.flush)
+      rmesa->dma.flush( rmesa );
+
+   r200EmitAOS( rmesa,
+               rmesa->tcl.aos_components,
+               rmesa->tcl.nr_aos_components, 0 );
+
+   return r200AllocEltsOpenEnded( rmesa, rmesa->tcl.hw_primitive, nr );
+}
+
+
+#define CLOSE_ELTS()  R200_NEWPRIM( rmesa )
 
 
 /* TODO: Try to extend existing primitive if both are identical,
@@ -217,17 +197,15 @@
 
 #ifdef MESA_BIG_ENDIAN
 /* We could do without (most of) this ugliness if dest was always 32 bit word 
aligned... */
-#define EMIT_ELT(offset, x) do {                                \
+#define EMIT_ELT(dest, offset, x) do {                                \
         int off = offset + ( ( (GLuint)dest & 0x2 ) >> 1 );     \
         GLushort *des = (GLushort *)( (GLuint)dest & ~0x2 );    \
         (des)[ off + 1 - 2 * ( off & 1 ) ] = (GLushort)(x); } while (0)
 #else
-#define EMIT_ELT(offset, x) (dest)[offset] = (GLushort) (x)
+#define EMIT_ELT(dest, offset, x) (dest)[offset] = (GLushort) (x)
 #endif
-#define EMIT_TWO_ELTS(offset, x, y)  *(GLuint *)(dest+offset) = ((y)<<16)|(x);
-#define INCR_ELTS( nr ) dest += nr
-#define RELEASE_ELT_VERTS() \
-   r200ReleaseArrays( ctx, ~0 )
+
+#define EMIT_TWO_ELTS(dest, offset, x, y)  *(GLuint *)((dest)+offset) = ((y)<<16)|(x);
 
 
 
Index: radeon/radeon_tcl.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/radeon/radeon_tcl.c,v
retrieving revision 1.8
diff -u -r1.8 radeon_tcl.c
--- radeon/radeon_tcl.c 30 Apr 2003 01:50:55 -0000      1.8
+++ radeon/radeon_tcl.c 24 Jul 2003 18:58:35 -0000
@@ -106,32 +106,23 @@
    
 
 #define LOCAL_VARS radeonContextPtr rmesa = RADEON_CONTEXT(ctx)
-#define ELTS_VARS  GLushort *dest
+#define ELT_TYPE  GLushort
 
 #define ELT_INIT(prim, hw_prim) \
    radeonTclPrimitive( ctx, prim, hw_prim | RADEON_CP_VC_CNTL_PRIM_WALK_IND )
 
-#define GET_ELTS() rmesa->tcl.Elts
+#define GET_MESA_ELTS() rmesa->tcl.Elts
 
 
-#define NEW_PRIMITIVE()  RADEON_NEWPRIM( rmesa )
-#define NEW_BUFFER()  radeonRefillCurrentDmaRegion( rmesa )
-
 /* Don't really know how many elts will fit in what's left of cmdbuf,
  * as there is state to emit, etc:
  */
 
-#if 0
-#define GET_CURRENT_VB_MAX_ELTS() \
-   ((RADEON_CMD_BUF_SZ - (rmesa->store.cmd_used + 16)) / 2) 
-#define GET_SUBSEQUENT_VB_MAX_ELTS() ((RADEON_CMD_BUF_SZ - 16) / 2) 
-#else
 /* Testing on isosurf shows a maximum around here.  Don't know if it's
  * the card or driver or kernel module that is causing the behaviour.
  */
-#define GET_CURRENT_VB_MAX_ELTS() 300
-#define GET_SUBSEQUENT_VB_MAX_ELTS() 300
-#endif
+#define GET_MAX_HW_ELTS() 300
+
 
 #define RESET_STIPPLE() do {                   \
    RADEON_STATECHANGE( rmesa, lin );           \
@@ -150,32 +141,24 @@
 } while (0)
 
 
-/* How do you extend an existing primitive?
- */
-#define ALLOC_ELTS(nr)                                                 \
-do {                                                                   \
-   if (rmesa->dma.flush == radeonFlushElts &&                          \
-       rmesa->store.cmd_used + nr*2 < RADEON_CMD_BUF_SZ) {             \
-                                                                       \
-      dest = (GLushort *)(rmesa->store.cmd_buf +                       \
-                         rmesa->store.cmd_used);                       \
-      rmesa->store.cmd_used += nr*2;                                   \
-   }                                                                   \
-   else {                                                              \
-      if (rmesa->dma.flush)                                            \
-        rmesa->dma.flush( rmesa );                                     \
-                                                                       \
-      radeonEmitAOS( rmesa,                                            \
-                    rmesa->tcl.aos_components,                         \
-                    rmesa->tcl.nr_aos_components,                      \
-                    0 );                                               \
-                                                                       \
-      dest = radeonAllocEltsOpenEnded( rmesa,                          \
-                                      rmesa->tcl.vertex_format,        \
-                                      rmesa->tcl.hw_primitive,         \
-                                      nr );                            \
-   }                                                                   \
-} while (0) 
+
+#define ALLOC_ELTS(nr) radeonAllocElts( rmesa, nr )
+
+static GLushort *radeonAllocElts( radeonContextPtr rmesa, GLuint nr ) 
+{
+   if (rmesa->dma.flush)
+      rmesa->dma.flush( rmesa );
+
+   radeonEmitAOS( rmesa,
+               rmesa->tcl.aos_components,
+               rmesa->tcl.nr_aos_components, 0 );
+
+   return radeonAllocEltsOpenEnded( rmesa,
+                                   rmesa->tcl.vertex_format, 
+                                   rmesa->tcl.hw_primitive, nr );
+}
+
+#define CLOSE_ELTS()  RADEON_NEWPRIM( rmesa )
 
 
 
@@ -222,17 +205,15 @@
 
 #ifdef MESA_BIG_ENDIAN
 /* We could do without (most of) this ugliness if dest was always 32 bit word 
aligned... */
-#define EMIT_ELT(offset, x) do {                               \
+#define EMIT_ELT(dest, offset, x) do {                         \
        int off = offset + ( ( (GLuint)dest & 0x2 ) >> 1 );     \
        GLushort *des = (GLushort *)( (GLuint)dest & ~0x2 );    \
        (des)[ off + 1 - 2 * ( off & 1 ) ] = (GLushort)(x); } while (0)
 #else
-#define EMIT_ELT(offset, x) (dest)[offset] = (GLushort) (x)
+#define EMIT_ELT(dest, offset, x) (dest)[offset] = (GLushort) (x)
 #endif
-#define EMIT_TWO_ELTS(offset, x, y)  *(GLuint *)(dest+offset) = ((y)<<16)|(x);
-#define INCR_ELTS( nr ) dest += nr
-#define RELEASE_ELT_VERTS() \
-   radeonReleaseArrays( ctx, ~0 )
+
+#define EMIT_TWO_ELTS(dest, offset, x, y)  *(GLuint *)(dest+offset) = ((y)<<16)|(x);
 
 
 
? diff
Index: t_dd_dmatmp2.h
===================================================================
RCS file: /cvsroot/dri/xc/xc/extras/Mesa/src/tnl_dd/t_dd_dmatmp2.h,v
retrieving revision 1.4
diff -u -r1.4 t_dd_dmatmp2.h
--- t_dd_dmatmp2.h      26 Aug 2002 22:16:02 -0000      1.4
+++ t_dd_dmatmp2.h      24 Jul 2003 19:00:09 -0000
@@ -56,10 +56,10 @@
 
 
 #ifndef EMIT_TWO_ELTS
-#define EMIT_TWO_ELTS( offset, elt0, elt1 )    \
+#define EMIT_TWO_ELTS( dest, offset, elt0, elt1 )      \
 do {                                           \
-   EMIT_ELT( offset, elt0 );                   \
-   EMIT_ELT( offset+1, elt1 );                         \
+   (dest)[offset] = (elt0);                    \
+   (dest)[offset+1] = (elt1);                  \
 } while (0)
 #endif
 
@@ -69,36 +69,42 @@
 /**********************************************************************/
 
 
-static void TAG(emit_elts)( GLcontext *ctx, GLuint *elts, GLuint nr )
+static ELT_TYPE *TAG(emit_elts)( GLcontext *ctx, 
+                           ELT_TYPE *dest,
+                           GLuint *elts, GLuint nr )
 {
    GLint i;
    LOCAL_VARS;
-   ELTS_VARS;
 
-   ALLOC_ELTS( nr );
-
-   for ( i = 0 ; i < nr ; i+=2, elts += 2 ) {
-      EMIT_TWO_ELTS( 0, elts[0], elts[1] );
-      INCR_ELTS( 2 );
+   for ( i = 0 ; i+1 < nr ; i+=2, elts += 2 ) {
+      EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
+      dest += 2;
+   }
+   if (i < nr) {
+      dest[0] = elts[0];
+      dest += 1;
    }
+   
+   return dest;
 }
 
-static void TAG(emit_consecutive_elts)( GLcontext *ctx, GLuint start, GLuint nr )
+static ELT_TYPE *TAG(emit_consecutive_elts)( GLcontext *ctx, 
+                                       ELT_TYPE *dest,
+                                       GLuint start, GLuint nr )
 {
    GLint i;
    LOCAL_VARS;
-   ELTS_VARS;
-
-   ALLOC_ELTS( nr );
 
    for ( i = 0 ; i+1 < nr ; i+=2, start += 2 ) {
-      EMIT_TWO_ELTS( 0, start, start+1 );
-      INCR_ELTS( 2 );
+      EMIT_TWO_ELTS( dest, 0, start, start+1 );
+      dest += 2;
    }
    if (i < nr) {
-      EMIT_ELT( 0, start );
-      INCR_ELTS( 1 );
+      dest[0] = start;
+      dest += 1;
    }
+
+   return dest;
 }
 
 /***********************************************************************
@@ -160,8 +166,7 @@
 
    if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_LINES ))
    {   
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      int dmasz = GET_MAX_HW_ELTS();
       GLuint j, nr;
 
       ELT_INIT( GL_LINES, HW_LINES );
@@ -169,30 +174,21 @@
       /* Emit whole number of lines in each full buffer.
        */
       dmasz = dmasz/2;
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
-      currentsz = currentsz/2;
 
-      if (currentsz < 4) {
-        NEW_BUFFER();
-        currentsz = dmasz;
-      }
 
       for (j = start; j + 1 < count; j += nr - 1 ) {
+        ELT_TYPE *dest;
         GLint i;
-        ELTS_VARS;
-        nr = MIN2( currentsz, count - j );
-           
-        ALLOC_ELTS( (nr-1)*2 );
+
+        nr = MIN2( dmasz, count - j );
+        dest = ALLOC_ELTS( (nr-1)*2 );
            
         for ( i = j ; i+1 < j+nr ; i+=1 ) {
-           EMIT_TWO_ELTS( 0, (i+0), (i+1) );
-           INCR_ELTS( 2 );
+           EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
+           dest += 2;
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
    else
@@ -223,96 +219,60 @@
         return;
 
       if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_LINES )) {
-        int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-        int currentsz;
+        int dmasz = GET_MAX_HW_ELTS();
 
         ELT_INIT( GL_LINES, HW_LINES );
 
         /* Emit whole number of lines in each full buffer.
          */
         dmasz = dmasz/2;
-        currentsz = GET_CURRENT_VB_MAX_ELTS();
-        currentsz = currentsz/2;
-
-        if (currentsz < 4) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
 
         /* Ensure last vertex doesn't wrap:
          */
-        currentsz--;
         dmasz--;
 
         for (; j + 1 < count;  ) {
            GLint i;
-           ELTS_VARS;
-           nr = MIN2( currentsz, count - j );
-           
-           ALLOC_ELTS( (nr-1)*2 );         
-           for ( i = j ; i+1 < j+nr ; i+=1 ) {
-              EMIT_TWO_ELTS( 0, (i+0), (i+1) );
-              INCR_ELTS( 2 );
+           ELT_TYPE *dest;
+
+           nr = MIN2( dmasz, count - j );
+           dest = ALLOC_ELTS( nr*2 );  /* allocs room for 1 more line */
+
+           for ( i = 0 ; i < nr - 1 ; i+=1 ) {
+              EMIT_TWO_ELTS( dest, 0, (j+i), (j+i+1) );
+              dest += 2;
            }
 
            j += nr - 1;
-           if (j + 1 < count) {
-              NEW_BUFFER();
-              currentsz = dmasz;
-           }
-           else { 
-              ALLOC_ELTS( 2 ); 
-              EMIT_TWO_ELTS( 0, (j), (start) ); 
-              INCR_ELTS( 2 ); 
-           } 
+
+           /* Emit 1 more line into space alloced above */
+           if (j + 1 >= count) {
+              EMIT_TWO_ELTS( dest, 0, (j), (start) ); 
+              dest += 2; 
+           }
+ 
+           CLOSE_ELTS();
         }
       }
       else
       {
-        int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-        int currentsz;
+        int dmasz = GET_MAX_HW_ELTS() - 1;
 
         ELT_INIT( GL_LINE_STRIP, HW_LINE_STRIP );
 
-        currentsz = GET_CURRENT_VB_MAX_ELTS();
-
-        if (currentsz < 8) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
-
-        /* Ensure last vertex doesn't wrap:
-         */
-        currentsz--;
-        dmasz--;
-
         for ( ; j + 1 < count;  ) {
-           nr = MIN2( currentsz, count - j );
+           nr = MIN2( dmasz, count - j );
            if (j + nr < count) {
-              TAG(emit_consecutive_elts)( ctx, j, nr );
-              currentsz = dmasz;
+              ELT_TYPE *dest = ALLOC_ELTS( nr );
+              dest = TAG(emit_consecutive_elts)( ctx, dest, j, nr );
               j += nr - 1;
-              NEW_BUFFER();
+              CLOSE_ELTS();
            }
            else if (nr) {
-              ELTS_VARS;
-              int i;
-
-              ALLOC_ELTS( nr + 1 );
-              for ( i = 0 ; i+1 < nr ; i+=2, j += 2 ) {
-                 EMIT_TWO_ELTS( 0, j, j+1 );
-                 INCR_ELTS( 2 );
-              }
-              if (i < nr) {
-                 EMIT_ELT( 0, j ); j++;
-                 INCR_ELTS( 1 );
-              }
-              EMIT_ELT( 0, start );
-              INCR_ELTS( 1 );
-              NEW_BUFFER();
-           }
-           else {
-              fprintf(stderr, "warining nr==0\n");
+              ELT_TYPE *dest = ALLOC_ELTS( nr + 1 );
+              dest = TAG(emit_consecutive_elts)( ctx, dest, j, nr );
+              dest = TAG(emit_consecutive_elts)( ctx, dest, start, 1 );
+              CLOSE_ELTS();
            }
         }   
       }
@@ -356,8 +316,7 @@
 
    if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_TRIANGLES ))
    {   
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      int dmasz = GET_MAX_HW_ELTS();
       int parity = 0;
       GLuint j, nr;
 
@@ -370,33 +329,22 @@
        */
       dmasz = dmasz/3;
       dmasz -= dmasz & 1;
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
-      currentsz = currentsz/3;
-      currentsz -= currentsz & 1;
-
-      if (currentsz < 4) {
-        NEW_BUFFER();
-        currentsz = dmasz;
-      }
 
       for (j = start; j + 2 < count; j += nr - 2 ) {
+        ELT_TYPE *dest;
         GLint i;
-        ELTS_VARS;
-        nr = MIN2( currentsz, count - j );
-           
-        ALLOC_ELTS( (nr-2)*3 );
+
+        nr = MIN2( dmasz, count - j );
+        dest = ALLOC_ELTS( (nr-2)*3 );
            
         for ( i = j ; i+2 < j+nr ; i++, parity^=1 ) {
-           EMIT_ELT( 0, (i+0+parity) );
-           EMIT_ELT( 1, (i+1-parity) );
-           EMIT_ELT( 2, (i+2) );
-           INCR_ELTS( 3 );
+           EMIT_ELT( dest, 0, (i+0+parity) );
+           EMIT_ELT( dest, 1, (i+1-parity) );
+           EMIT_ELT( dest, 2, (i+2) );
+           dest += 3;
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
    else if ((flags & PRIM_PARITY) == 0)  
@@ -407,14 +355,15 @@
       /* Emit the first triangle with elts, then the rest as a regular strip.
        * TODO:  Make this unlikely in t_imm_api.c
        */
-      ELTS_VARS;
+      ELT_TYPE *dest;
+
       ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
-      ALLOC_ELTS( 3 );
-      EMIT_ELT( 0, (start+1) );
-      EMIT_ELT( 1, (start+0) );
-      EMIT_ELT( 2, (start+2) );
-      INCR_ELTS( 3 );
-      NEW_PRIMITIVE();
+      dest = ALLOC_ELTS( 3 );
+      EMIT_ELT( dest, 0, (start+1) );
+      EMIT_ELT( dest, 1, (start+0) );
+      EMIT_ELT( dest, 2, (start+2) );
+      dest += 3;
+      CLOSE_ELTS();
 
       start++;
       if (start + 2 >= count)
@@ -438,39 +387,28 @@
 
    if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_TRIANGLES ))
    {   
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      int dmasz = GET_MAX_HW_ELTS();
       GLuint j, nr;
 
       ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
 
       dmasz = dmasz/3;
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
-      currentsz = currentsz/3;
-
-      if (currentsz < 4) {
-        NEW_BUFFER();
-        currentsz = dmasz;
-      }
 
       for (j = start + 1; j + 1 < count; j += nr - 1 ) {
+        ELT_TYPE *dest;
         GLint i;
-        ELTS_VARS;
-        nr = MIN2( currentsz, count - j );
-           
-        ALLOC_ELTS( (nr-1)*3 );
+
+        nr = MIN2( dmasz, count - j );
+        dest = ALLOC_ELTS( (nr-1)*3 );
            
         for ( i = j ; i+1 < j+nr ; i++ ) {
-           EMIT_ELT( 0, (start) );
-           EMIT_ELT( 1, (i) );
-           EMIT_ELT( 2, (i+1) );
-           INCR_ELTS( 3 );
-        }
-
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
+           EMIT_ELT( dest, 0, (start) );
+           EMIT_ELT( dest, 1, (i) );
+           EMIT_ELT( dest, 2, (i+1) );
+           dest += 3;
         }
+        
+        CLOSE_ELTS();
       }
    }
    else {
@@ -511,44 +449,31 @@
    } 
    else if (ctx->_TriangleCaps & DD_FLATSHADE) {
       LOCAL_VARS;
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      int dmasz = GET_MAX_HW_ELTS();
       GLuint j, nr;
 
       ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
 
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
-
       /* Emit whole number of quads in total, and in each buffer.
        */
-      currentsz = (currentsz/6)*2;
       dmasz = (dmasz/6)*2;
 
-      if (currentsz < 4) {
-        NEW_BUFFER();
-        currentsz = dmasz;
-      }
-
       for (j = start; j + 3 < count; j += nr - 2 ) {
-        ELTS_VARS;
+        ELT_TYPE *dest;
         GLint quads, i;
 
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
         quads = (nr/2)-1;
-           
-        ALLOC_ELTS( quads*6 );
+        dest = ALLOC_ELTS( quads*6 );
            
         for ( i = j ; i < j+quads*2 ; i+=2 ) {
-           EMIT_TWO_ELTS( 0, (i+0), (i+1) );
-           EMIT_TWO_ELTS( 2, (i+2), (i+1) );
-           EMIT_TWO_ELTS( 4, (i+3), (i+2) );
-           INCR_ELTS( 6 );
+           EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
+           EMIT_TWO_ELTS( dest, 2, (i+2), (i+1) );
+           EMIT_TWO_ELTS( dest, 4, (i+3), (i+2) );
+           dest += 6;
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
    else {
@@ -577,42 +502,31 @@
        * using indexed vertices and the triangle primitive: 
        */
       LOCAL_VARS;
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      int dmasz = GET_MAX_HW_ELTS();
       GLuint j, nr;
 
       ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
 
       /* Adjust for rendering as triangles:
        */
-      currentsz = (currentsz/6)*4;
       dmasz = (dmasz/6)*4;
 
-      if (currentsz < 8) {
-        NEW_BUFFER();
-        currentsz = dmasz;
-      }
-
       for (j = start; j < count; j += nr ) {
-        ELTS_VARS;
+        ELT_TYPE *dest;
         GLint quads, i;
-        nr = MIN2( currentsz, count - j );
-        quads = nr/4;
 
-        ALLOC_ELTS( quads*6 );
+        nr = MIN2( dmasz, count - j );
+        quads = nr/4;
+        dest = ALLOC_ELTS( quads*6 );
 
         for ( i = j ; i < j+quads*4 ; i+=4 ) {
-           EMIT_TWO_ELTS( 0, (i+0), (i+1) );
-           EMIT_TWO_ELTS( 2, (i+3), (i+1) );
-           EMIT_TWO_ELTS( 4, (i+2), (i+3) );
-           INCR_ELTS( 6 );
+           EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
+           EMIT_TWO_ELTS( dest, 2, (i+3), (i+1) );
+           EMIT_TWO_ELTS( dest, 4, (i+2), (i+3) );
+           dest += 6;
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
 }
@@ -653,22 +567,18 @@
                                     GLuint flags )
 {
    LOCAL_VARS;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
-   GLuint *elts = GET_ELTS();
+   int dmasz = GET_MAX_HW_ELTS();
+   GLuint *elts = GET_MESA_ELTS();
    GLuint j, nr;
+   ELT_TYPE *dest;
 
    ELT_INIT( GL_POINTS, HW_POINTS );
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8)
-      currentsz = dmasz;
-
    for (j = start; j < count; j += nr ) {
-      nr = MIN2( currentsz, count - j );
-      TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j );
+      dest = ALLOC_ELTS( nr );
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+      CLOSE_ELTS();
    }
 }
 
@@ -680,10 +590,10 @@
                                    GLuint flags )
 {
    LOCAL_VARS;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
-   GLuint *elts = GET_ELTS();
+   int dmasz = GET_MAX_HW_ELTS();
+   GLuint *elts = GET_MESA_ELTS();
    GLuint j, nr;
+   ELT_TYPE *dest;
 
    if (start+1 >= count)
       return;
@@ -698,18 +608,13 @@
    /* Emit whole number of lines in total and in each buffer:
     */
    count -= (count-start) & 1;
-   currentsz -= currentsz & 1;
    dmasz -= dmasz & 1;
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8)
-      currentsz = dmasz;
-
    for (j = start; j < count; j += nr ) {
-      nr = MIN2( currentsz, count - j );
-      TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j );
+      dest = ALLOC_ELTS( nr );
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+      CLOSE_ELTS();
    }
 
    if ((flags & PRIM_END) && ctx->Line.StippleFlag)
@@ -723,10 +628,10 @@
                                         GLuint flags )
 {
    LOCAL_VARS;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
-   GLuint *elts = GET_ELTS();
+   int dmasz = GET_MAX_HW_ELTS();
+   GLuint *elts = GET_MESA_ELTS();
    GLuint j, nr;
+   ELT_TYPE *dest;
 
    if (start+1 >= count)
       return;
@@ -736,15 +641,11 @@
    if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag)
       RESET_STIPPLE();
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8)
-      currentsz = dmasz;
-
    for (j = start; j + 1 < count; j += nr - 1 ) {
-      nr = MIN2( currentsz, count - j );
-      TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j );
+      dest = ALLOC_ELTS( nr );
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+      CLOSE_ELTS();
    }
 }
 
@@ -755,10 +656,10 @@
                                        GLuint flags )
 {
    LOCAL_VARS;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
-   GLuint *elts = GET_ELTS();
+   int dmasz = GET_MAX_HW_ELTS();
+   GLuint *elts = GET_MESA_ELTS();
    GLuint j, nr;
+   ELT_TYPE *dest;
 
    if (0) fprintf(stderr, "%s\n", __FUNCTION__);
 
@@ -783,27 +684,20 @@
       RESET_STIPPLE();
 
    
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8) {
-      NEW_BUFFER();
-      currentsz = dmasz;
-   }
-
    /* Ensure last vertex doesn't wrap:
     */
-   currentsz--;
    dmasz--;
 
-   for ( ; j + 1 < count; j += nr - 1 ) {
-      nr = MIN2( currentsz, count - j );
-      TAG(emit_elts)( ctx, elts+j, nr );
-      currentsz = dmasz;
+   for ( ; j + 1 < count; ) {
+      nr = MIN2( dmasz, count - j );
+      dest = ALLOC_ELTS( nr+1 );       /* Reserve possible space for last elt */
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+      j += nr - 1;
+      if (j + 1 >= count && flags & PRIM_END) {
+        dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
+      }
+      CLOSE_ELTS();
    }
-
-   if (flags & PRIM_END)
-      TAG(emit_elts)( ctx, elts+start, 1 );
-
-   NEW_PRIMITIVE();
 }
 
 
@@ -813,32 +707,27 @@
                                        GLuint flags )
 {
    LOCAL_VARS;
-   GLuint *elts = GET_ELTS();
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS()/3*3;
-   int currentsz;
+   GLuint *elts = GET_MESA_ELTS();
+   int dmasz = GET_MAX_HW_ELTS()/3*3;
    GLuint j, nr;
+   ELT_TYPE *dest;
 
    if (start+2 >= count)
       return;
 
-/*     NEW_PRIMITIVE(); */
    ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
 
    /* Emit whole number of tris in total.  dmasz is already a multiple
     * of 3.
     */
    count -= (count-start)%3;
-   currentsz -= currentsz%3;
-   if (currentsz < 8)
-      currentsz = dmasz;
 
    for (j = start; j < count; j += nr) {
-      nr = MIN2( currentsz, count - j );
-      TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j );
+      dest = ALLOC_ELTS( nr );
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+      CLOSE_ELTS();
    }
 }
 
@@ -851,36 +740,34 @@
 {
    LOCAL_VARS;
    GLuint j, nr;
-   GLuint *elts = GET_ELTS();
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
+   GLuint *elts = GET_MESA_ELTS();
+   int dmasz = GET_MAX_HW_ELTS();
+   ELT_TYPE *dest;
 
    if (start+2 >= count)
       return;
 
    ELT_INIT( GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0 );
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8) {
-      NEW_BUFFER();
-      currentsz = dmasz;
-   }
-
-   if ((flags & PRIM_PARITY) && count - start > 2) {
-      TAG(emit_elts)( ctx, elts+start, 1 );
-      currentsz--;
-   }
-
    /* Keep the same winding over multiple buffers:
     */
    dmasz -= (dmasz & 1);
-   currentsz -= (currentsz & 1);
 
    for (j = start ; j + 2 < count; j += nr - 2 ) {
-      nr = MIN2( currentsz, count - j );
-      TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j );
+
+      if (flags & PRIM_PARITY) {
+        dest = ALLOC_ELTS( nr );       
+        dest = TAG(emit_elts)( ctx, dest, elts+j, 1 );
+        dest = TAG(emit_elts)( ctx, dest, elts+j, nr-1 );
+        nr--; flags &= ~PRIM_PARITY;
+        CLOSE_ELTS();
+      }
+      else {
+        dest = ALLOC_ELTS( nr );
+        dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+        CLOSE_ELTS();
+      }
    }
 }
 
@@ -890,28 +777,22 @@
                                      GLuint flags )
 {
    LOCAL_VARS;
-   GLuint *elts = GET_ELTS();
+   GLuint *elts = GET_MESA_ELTS();
    GLuint j, nr;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
+   int dmasz = GET_MAX_HW_ELTS();
+   ELT_TYPE *dest;
 
    if (start+2 >= count)
       return;
 
    ELT_INIT( GL_TRIANGLE_FAN, HW_TRIANGLE_FAN );
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8) {
-      NEW_BUFFER();
-      currentsz = dmasz;
-   }
-
    for (j = start + 1 ; j + 1 < count; j += nr - 1 ) {
-      nr = MIN2( currentsz, count - j + 1 );
-      TAG(emit_elts)( ctx, elts+start, 1 );
-      TAG(emit_elts)( ctx, elts+j, nr - 1 );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j + 1 );
+      dest = ALLOC_ELTS( nr );
+      dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr - 1 );
+      CLOSE_ELTS();
    }
 }
 
@@ -922,28 +803,22 @@
                                   GLuint flags )
 {
    LOCAL_VARS;
-   GLuint *elts = GET_ELTS();
+   GLuint *elts = GET_MESA_ELTS();
    GLuint j, nr;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
+   int dmasz = GET_MAX_HW_ELTS();
+   ELT_TYPE *dest;
 
    if (start+2 >= count)
       return;
 
    ELT_INIT( GL_POLYGON, HW_POLYGON );
 
-   currentsz = GET_CURRENT_VB_MAX_ELTS();
-   if (currentsz < 8) {
-      NEW_BUFFER();
-      currentsz = dmasz;
-   }
-
    for (j = start + 1 ; j + 1 < count ; j += nr - 1 ) {
-      nr = MIN2( currentsz, count - j + 1 );
-      TAG(emit_elts)( ctx, elts+start, 1 );
-      TAG(emit_elts)( ctx, elts+j, nr - 1 );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      nr = MIN2( dmasz, count - j + 1 );
+      dest = ALLOC_ELTS( nr );
+      dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
+      dest = TAG(emit_elts)( ctx, dest, elts+j, nr - 1 );
+      CLOSE_ELTS();
    }
 }
 
@@ -959,61 +834,49 @@
    }
    else {
       LOCAL_VARS;
-      GLuint *elts = GET_ELTS();
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      GLuint *elts = GET_MESA_ELTS();
+      int dmasz = GET_MAX_HW_ELTS();
       GLuint j, nr;
-
-      NEW_PRIMITIVE();
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
+      ELT_TYPE *dest;
 
       /* Emit whole number of quads in total, and in each buffer.
        */
       dmasz -= dmasz & 1;
       count -= (count-start) & 1;
-      currentsz -= currentsz & 1;
-
-      if (currentsz < 12)
-        currentsz = dmasz;
 
       if (ctx->_TriangleCaps & DD_FLATSHADE) {
         ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
 
-        currentsz = currentsz/6*2;
         dmasz = dmasz/6*2;
 
         for (j = start; j + 3 < count; j += nr - 2 ) {
-           nr = MIN2( currentsz, count - j );
+           nr = MIN2( dmasz, count - j );
 
            if (nr >= 4)
            {
-              GLint i;
               GLint quads = (nr/2)-1;
-              ELTS_VARS;
-
-              ALLOC_ELTS( quads*6 );
+              ELT_TYPE *dest = ALLOC_ELTS( quads*6 );
+              GLint i;
 
               for ( i = j-start ; i < j-start+quads ; i++, elts += 2 ) {
-                 EMIT_TWO_ELTS( 0, elts[0], elts[1] );
-                 EMIT_TWO_ELTS( 2, elts[2], elts[1] );
-                 EMIT_TWO_ELTS( 4, elts[3], elts[2] );
-                 INCR_ELTS( 6 );
+                 EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
+                 EMIT_TWO_ELTS( dest, 2, elts[2], elts[1] );
+                 EMIT_TWO_ELTS( dest, 4, elts[3], elts[2] );
+                 dest += 6;
               }
 
-              NEW_PRIMITIVE();
+              CLOSE_ELTS();
            }
-
-           currentsz = dmasz;
         }
       }
       else {
         ELT_INIT( GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0 );
 
         for (j = start; j + 3 < count; j += nr - 2 ) {
-           nr = MIN2( currentsz, count - j );
-           TAG(emit_elts)( ctx, elts+j, nr );
-           NEW_PRIMITIVE();
-           currentsz = dmasz;
+           nr = MIN2( dmasz, count - j );
+           dest = ALLOC_ELTS( nr );
+           dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
+           CLOSE_ELTS();
         }
       }
    }
@@ -1031,48 +894,38 @@
    if (HAVE_QUADS && 0) {
    } else {
       LOCAL_VARS;
-      GLuint *elts = GET_ELTS();
-      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-      int currentsz;
+      GLuint *elts = GET_MESA_ELTS();
+      int dmasz = GET_MAX_HW_ELTS();
       GLuint j, nr;
 
       ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
-      currentsz = GET_CURRENT_VB_MAX_ELTS();
 
       /* Emit whole number of quads in total, and in each buffer.
        */
       dmasz -= dmasz & 3;
       count -= (count-start) & 3;
-      currentsz -= currentsz & 3;
 
       /* Adjust for rendering as triangles:
        */
-      currentsz = currentsz/6*4;
       dmasz = dmasz/6*4;
 
-      if (currentsz < 8)
-        currentsz = dmasz;
-
       for (j = start; j + 3 < count; j += nr - 2 ) {
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
 
-        if (nr >= 4)
         {
            GLint quads = nr/4;
+           ELT_TYPE *dest = ALLOC_ELTS( quads * 6 );
            GLint i;
-           ELTS_VARS;
-           ALLOC_ELTS( quads * 6 );
 
            for ( i = j-start ; i < j-start+quads ; i++, elts += 4 ) {
-              EMIT_TWO_ELTS( 0, elts[0], elts[1] );
-              EMIT_TWO_ELTS( 2, elts[3], elts[1] );
-              EMIT_TWO_ELTS( 4, elts[2], elts[3] );
-              INCR_ELTS( 6 );
+              EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
+              EMIT_TWO_ELTS( dest, 2, elts[3], elts[1] );
+              EMIT_TWO_ELTS( dest, 4, elts[2], elts[3] );
+              dest += 6;
            }
-        }
 
-        NEW_PRIMITIVE();
-        currentsz = dmasz;
+           CLOSE_ELTS();
+        }
       }
    }
 }

Reply via email to