Ian Romanick wrote:
Michael wrote:

Ian Romanick wrote:

Here's a patch that prevents Think Tanks (and possibly other heavy users of triangle fans) from crashing on Radeon hardware.


To be pedantic - it's not caused by heavy usage of triangle fans, it was caused by a single triangle fan primitive occuring at the end of a cmd_buf [that could be filled with anything other than triangle fan primitives]


Right. But the odds of hitting this with infrequent use of triangle fans is pretty low. :)

Basically, I just in-lined emit_elts and did some minor clean-up.


Yeah, that should work - but I did wonder whether other primitives / paths might have the same issue? There has been a few rendering related bugs reported that are "fixed" by changing the size of cmd_buf - which is one indirect way of "fixing" something like this. Other similar errors might not cause hardware hangs.


There are a couple of other functions that look suspect: render_line_loop_elts (only if PRIM_END is set), render_tri_strip_elts (only if PRIM_PARITY is set), and render_poly_elts (this is virtually identical to render_tri_fan_elts). Neither the R100 or R200 have line-loops in hardware, so I'm not worried about render_line_loop_elts.
Given the huge numbers of apps that make massive use of triangle strips, I'm surprised that render_tri_strip_elts hasn't caused problems. NWN and FlightGear don't happen to use the render_poly_elts path, do they?


More digging required...

The attached patch is a work-in-progress which shows my ideas on how this code could be cleaned up. It makes the allocation of space for verts & elts a lot more explicit & should avoid some of the odd behaviour arising from the old code. There are several cases where it should fix bad behaviours.


It's not finished yet & I don't have a huge amount of time, but it's probably worth sharing.

Keith


? diff
? dmatmp2.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      19 Jul 2003 19:27:19 -0000
@@ -75,12 +75,14 @@
    LOCAL_VARS;
    ELTS_VARS;
 
-   ALLOC_ELTS( nr );
-
-   for ( i = 0 ; i < nr ; i+=2, elts += 2 ) {
+   for ( i = 0 ; i+1 < nr ; i+=2, elts += 2 ) {
       EMIT_TWO_ELTS( 0, elts[0], elts[1] );
       INCR_ELTS( 2 );
    }
+   if (i < nr) {
+      EMIT_ELT( 0, elts[0] );
+      INCR_ELTS( 1 );
+   }
 }
 
 static void TAG(emit_consecutive_elts)( GLcontext *ctx, GLuint start, GLuint nr )
@@ -89,8 +91,6 @@
    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 );
@@ -160,8 +160,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,18 +168,12 @@
       /* 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 ) {
         GLint i;
         ELTS_VARS;
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
            
         ALLOC_ELTS( (nr-1)*2 );
            
@@ -189,10 +182,7 @@
            INCR_ELTS( 2 );
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
    else
@@ -223,96 +213,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 );
+           nr = MIN2( dmasz, count - j );
            
-           ALLOC_ELTS( (nr-1)*2 );         
-           for ( i = j ; i+1 < j+nr ; i+=1 ) {
-              EMIT_TWO_ELTS( 0, (i+0), (i+1) );
+           ALLOC_ELTS( nr*2 ); /* allocs room for 1 more line */
+           for ( i = 0 ; i < nr - 1 ; i+=1 ) {
+              EMIT_TWO_ELTS( 0, (j+i), (j+i+1) );
               INCR_ELTS( 2 );
            }
 
            j += nr - 1;
-           if (j + 1 < count) {
-              NEW_BUFFER();
-              currentsz = dmasz;
-           }
-           else { 
-              ALLOC_ELTS( 2 ); 
+
+           /* Emit 1 more line into space alloced above */
+           if (j + 1 >= count) {
               EMIT_TWO_ELTS( 0, (j), (start) ); 
               INCR_ELTS( 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) {
+              ALLOC_ELTS( nr );
               TAG(emit_consecutive_elts)( ctx, j, nr );
-              currentsz = dmasz;
               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");
+              TAG(emit_consecutive_elts)( ctx, j, nr );
+              TAG(emit_consecutive_elts)( ctx, start, 1 );
+              CLOSE_ELTS();
            }
         }   
       }
@@ -356,8 +310,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,19 +323,11 @@
        */
       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 ) {
         GLint i;
         ELTS_VARS;
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
            
         ALLOC_ELTS( (nr-2)*3 );
            
@@ -393,10 +338,7 @@
            INCR_ELTS( 3 );
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
    else if ((flags & PRIM_PARITY) == 0)  
@@ -414,7 +356,7 @@
       EMIT_ELT( 1, (start+0) );
       EMIT_ELT( 2, (start+2) );
       INCR_ELTS( 3 );
-      NEW_PRIMITIVE();
+      CLOSE_ELTS();
 
       start++;
       if (start + 2 >= count)
@@ -438,25 +380,17 @@
 
    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 ) {
         GLint i;
         ELTS_VARS;
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
            
         ALLOC_ELTS( (nr-1)*3 );
            
@@ -466,11 +400,8 @@
            EMIT_ELT( 2, (i+1) );
            INCR_ELTS( 3 );
         }
-
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        
+        CLOSE_ELTS();
       }
    }
    else {
@@ -511,29 +442,20 @@
    } 
    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;
         GLint quads, i;
 
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
         quads = (nr/2)-1;
            
         ALLOC_ELTS( quads*6 );
@@ -545,10 +467,7 @@
            INCR_ELTS( 6 );
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
    else {
@@ -577,27 +496,19 @@
        * 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;
         GLint quads, i;
-        nr = MIN2( currentsz, count - j );
+        nr = MIN2( dmasz, count - j );
         quads = nr/4;
 
         ALLOC_ELTS( quads*6 );
@@ -609,10 +520,7 @@
            INCR_ELTS( 6 );
         }
 
-        if (nr == currentsz) {
-           NEW_BUFFER();
-           currentsz = dmasz;
-        }
+        CLOSE_ELTS();
       }
    }
 }
@@ -653,22 +561,17 @@
                                     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_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 );
+      nr = MIN2( dmasz, count - j );
+      ALLOC_ELTS( nr );
       TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      CLOSE_ELTS();
    }
 }
 
@@ -680,9 +583,8 @@
                                    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;
 
    if (start+1 >= count)
@@ -698,18 +600,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 );
+      nr = MIN2( dmasz, count - j );
+      ALLOC_ELTS( nr );
       TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      CLOSE_ELTS();
    }
 
    if ((flags & PRIM_END) && ctx->Line.StippleFlag)
@@ -723,9 +620,8 @@
                                         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;
 
    if (start+1 >= count)
@@ -736,15 +632,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 );
+      nr = MIN2( dmasz, count - j );
+      ALLOC_ELTS( nr );
       TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      CLOSE_ELTS();
    }
 }
 
@@ -755,9 +647,8 @@
                                        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;
 
    if (0) fprintf(stderr, "%s\n", __FUNCTION__);
@@ -783,27 +674,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 );
+   for ( ; j + 1 < count; ) {
+      nr = MIN2( dmasz, count - j );
+      ALLOC_ELTS( nr+1 );      /* Reserve possible space for last elt */
       TAG(emit_elts)( ctx, elts+j, nr );
-      currentsz = dmasz;
+      j += nr - 1;
+      if (j + 1 >= count && flags & PRIM_END) {
+        TAG(emit_elts)( ctx, elts+start, 1 );
+      }
+      CLOSE_ELTS();
    }
-
-   if (flags & PRIM_END)
-      TAG(emit_elts)( ctx, elts+start, 1 );
-
-   NEW_PRIMITIVE();
 }
 
 
@@ -813,32 +697,26 @@
                                        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;
 
    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 );
+      nr = MIN2( dmasz, count - j );
+      ALLOC_ELTS( nr );
       TAG(emit_elts)( ctx, elts+j, nr );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      CLOSE_ELTS();
    }
 }
 
@@ -851,36 +729,33 @@
 {
    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();
 
    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) {
+        ALLOC_ELTS( nr );      
+        TAG(emit_elts)( ctx, elts+j, 1 );
+        TAG(emit_elts)( ctx, elts+j, nr-1 );
+        nr--; flags &= ~PRIM_PARITY;
+        CLOSE_ELTS();
+      }
+      else {
+        ALLOC_ELTS( nr );
+        TAG(emit_elts)( ctx, elts+j, nr );
+        CLOSE_ELTS();
+      }
    }
 }
 
@@ -890,28 +765,21 @@
                                      GLuint flags )
 {
    LOCAL_VARS;
-   GLuint *elts = GET_ELTS();
-   GLuint j, nr;
-   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
-   int currentsz;
+   GLuint *elts = GET_MESA_ELTS();
+   GLuint i, j, nr;
+   int dmasz = GET_MAX_HW_ELTS();
 
    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 );
+      nr = MIN2( dmasz, count - j + 1 );
+      ALLOC_ELTS( nr );
       TAG(emit_elts)( ctx, elts+start, 1 );
       TAG(emit_elts)( ctx, elts+j, nr - 1 );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      CLOSE_ELTS();
    }
 }
 
@@ -922,28 +790,21 @@
                                   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();
 
    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 );
+      nr = MIN2( dmasz, count - j + 1 );
+      ALLOC_ELTS( nr );
       TAG(emit_elts)( ctx, elts+start, 1 );
       TAG(emit_elts)( ctx, elts+j, nr - 1 );
-      NEW_PRIMITIVE();
-      currentsz = dmasz;
+      CLOSE_ELTS();
    }
 }
 
@@ -959,31 +820,22 @@
    }
    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();
-
       /* 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)
            {
@@ -1000,20 +852,18 @@
                  INCR_ELTS( 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 );
+           nr = MIN2( dmasz, count - j );
+           ALLOC_ELTS( nr );
            TAG(emit_elts)( ctx, elts+j, nr );
-           NEW_PRIMITIVE();
-           currentsz = dmasz;
+           CLOSE_ELTS();
         }
       }
    }
@@ -1031,32 +881,24 @@
    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;
            GLint i;
@@ -1069,10 +911,9 @@
               EMIT_TWO_ELTS( 4, elts[2], elts[3] );
               INCR_ELTS( 6 );
            }
-        }
 
-        NEW_PRIMITIVE();
-        currentsz = dmasz;
+           CLOSE_ELTS();
+        }
       }
    }
 }
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     19 Jul 2003 19:28:28 -0000
@@ -108,27 +108,17 @@
 #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 );             \
@@ -151,14 +141,6 @@
  */
 #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 );                                     \
                                                                        \
@@ -170,9 +152,9 @@
       dest = r200AllocEltsOpenEnded( rmesa,                            \
                                       rmesa->tcl.hw_primitive,         \
                                       nr );                            \
-   }                                                                   \
 } while (0) 
 
+#define CLOSE_ELTS()  R200_NEWPRIM( rmesa )
 
 
 /* TODO: Try to extend existing primitive if both are identical,
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 19 Jul 2003 19:28:42 -0000
@@ -111,27 +111,18 @@
 #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 );           \
@@ -154,14 +145,6 @@
  */
 #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 );                                     \
                                                                        \
@@ -174,9 +157,10 @@
                                       rmesa->tcl.vertex_format,        \
                                       rmesa->tcl.hw_primitive,         \
                                       nr );                            \
-   }                                                                   \
 } while (0) 
 
+
+#define CLOSE_ELTS()  RADEON_NEWPRIM( rmesa )
 
 
 /* TODO: Try to extend existing primitive if both are identical,

Reply via email to