r600: make sure the number of indices is valid
authorAlex Deucher <alexdeucher@gmail.com>
Mon, 17 Aug 2009 21:47:27 +0000 (17:47 -0400)
committerAlex Deucher <alexdeucher@gmail.com>
Mon, 17 Aug 2009 21:47:27 +0000 (17:47 -0400)
make sure the number of indices is valid for the
requested prim type.  glxgears sends invalid
quad strips with only 2 indices for example.

src/mesa/drivers/dri/r600/r700_render.c

index 6705dbcf4b9aff5ba66fe5262872d4473f86a257..9e2971a34366bdd1aafb36d6253c370aaee9ae9e 100644 (file)
@@ -223,18 +223,71 @@ static unsigned int r700PrimitiveType(int prim)
     }
 }
 
+static int r700NumVerts(int num_verts, int prim)
+{
+       int verts_off = 0;
+
+       switch (prim & PRIM_MODE_MASK) {
+       case GL_POINTS:
+               verts_off = 0;
+               break;
+       case GL_LINES:
+               verts_off = num_verts % 2;
+               break;
+       case GL_LINE_STRIP:
+               if (num_verts < 2)
+                       verts_off = num_verts;
+               break;
+       case GL_LINE_LOOP:
+               if (num_verts < 2)
+                       verts_off = num_verts;
+               break;
+       case GL_TRIANGLES:
+               verts_off = num_verts % 3;
+               break;
+       case GL_TRIANGLE_STRIP:
+               if (num_verts < 3)
+                       verts_off = num_verts;
+               break;
+       case GL_TRIANGLE_FAN:
+               if (num_verts < 3)
+                       verts_off = num_verts;
+               break;
+       case GL_QUADS:
+               verts_off = num_verts % 4;
+               break;
+       case GL_QUAD_STRIP:
+               if (num_verts < 4)
+                       verts_off = num_verts;
+               else
+                       verts_off = num_verts % 2;
+               break;
+       case GL_POLYGON:
+               if (num_verts < 3)
+                       verts_off = num_verts;
+               break;
+       default:
+               assert(0);
+               return -1;
+               break;
+       }
+
+       return num_verts - verts_off;
+}
+
 static void r700RunRenderPrimitive(GLcontext * ctx, int start, int end, int prim)
 {
        context_t *context = R700_CONTEXT(ctx);
        BATCH_LOCALS(&context->radeon);
        int type, i, total_emit;
-       int num_indices = end - start;
+       int num_indices;
        uint32_t vgt_draw_initiator = 0;
        uint32_t vgt_index_type     = 0;
        uint32_t vgt_primitive_type = 0;
        uint32_t vgt_num_indices    = 0;
 
        type = r700PrimitiveType(prim);
+       num_indices = r700NumVerts(end - start, prim);
 
        if (type < 0 || num_indices <= 0)
                return;