Use a consistent number to identify undefined vertices.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 7 Nov 2007 12:08:19 +0000 (12:08 +0000)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 7 Nov 2007 13:41:00 +0000 (13:41 +0000)
src/mesa/pipe/draw/draw_clip.c
src/mesa/pipe/draw/draw_private.h
src/mesa/pipe/draw/draw_vertex_cache.c
src/mesa/pipe/i915simple/i915_prim_vbuf.c
src/mesa/pipe/softpipe/sp_prim_vbuf.c

index 222022d..bc62d42 100644 (file)
@@ -102,7 +102,7 @@ static void interp( const struct clipper *clip,
       dst->clipmask = 0;
       dst->edgeflag = 0;
       dst->pad = 0;
-      dst->vertex_id = 0;
+      dst->vertex_id = UNDEFINED_VERTEX_ID;
    }
 
    /* Clip coordinates:  interpolate normally
index f52ff0b..bdc3a6b 100644 (file)
@@ -52,6 +52,7 @@
 
 struct gallivm_prog;
 struct gallivm_cpu_engine;
+
 /**
  * Basic vertex info.
  * Carry some useful information around with the vertices in the prim pipe.  
@@ -67,6 +68,9 @@ struct vertex_header {
    float data[][4];            /* Note variable size */
 };
 
+/* NOTE: It should match vertex_id size above */
+#define UNDEFINED_VERTEX_ID 0xffff
+
 /* XXX This is too large */
 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
 
@@ -299,7 +303,7 @@ dup_vert( struct draw_stage *stage,
 {   
    struct vertex_header *tmp = stage->tmp[idx];
    memcpy(tmp, vert, stage->draw->vertex_info.size * sizeof(float) );
-   tmp->vertex_id = ~0;
+   tmp->vertex_id = UNDEFINED_VERTEX_ID;
    return tmp;
 }
 
index 511f371..6689907 100644 (file)
@@ -88,7 +88,7 @@ static struct vertex_header *get_vertex( struct draw_context *draw,
       draw->vcache.vertex[slot]->clipmask = 0;
       draw->vcache.vertex[slot]->edgeflag = 1; /*XXX use user's edge flag! */
       draw->vcache.vertex[slot]->pad = 0;
-      draw->vcache.vertex[slot]->vertex_id = ~0;
+      draw->vcache.vertex[slot]->vertex_id = UNDEFINED_VERTEX_ID;
    }
 
 
@@ -130,7 +130,7 @@ void draw_vertex_cache_reset_vertex_ids( struct draw_context *draw )
    unsigned i;
 
    for (i = 0; i < Elements(draw->vcache.vertex); i++)
-      draw->vcache.vertex[i]->vertex_id = ~0;
+      draw->vcache.vertex[i]->vertex_id = UNDEFINED_VERTEX_ID;
 }
 
 
index c33cc21..8881d16 100644 (file)
@@ -98,15 +98,16 @@ static INLINE struct vbuf_stage *vbuf_stage( struct draw_stage *stage )
 }
 
 
-static inline 
-boolean overflow( void *map, void *ptr, unsigned bytes, unsigned bufsz )
+static INLINE boolean 
+overflow( void *map, void *ptr, unsigned bytes, unsigned bufsz )
 {
    unsigned long used = (char *)ptr - (char *)map;
    return (used + bytes) > bufsz;
 }
 
 
-static void check_space( struct vbuf_stage *vbuf )
+static INLINE void 
+check_space( struct vbuf_stage *vbuf )
 {
    if (overflow( vbuf->vertex_map, 
                  vbuf->vertex_ptr,  
@@ -125,7 +126,7 @@ static void check_space( struct vbuf_stage *vbuf )
  * have a couple of slots at the beginning (1-dword header, 4-dword
  * clip pos) that we ignore here.
  */
-static inline void 
+static INLINE void 
 emit_vertex( struct vbuf_stage *vbuf,
              struct vertex_header *vertex )
 {
@@ -137,6 +138,15 @@ emit_vertex( struct vbuf_stage *vbuf,
 //   fprintf(stderr, "emit vertex %d to %p\n", 
 //           vbuf->nr_vertices, vbuf->vertex_ptr);
 
+   if(vertex->vertex_id != UNDEFINED_VERTEX_ID) {
+      if(vertex->vertex_id < vbuf->nr_vertices)
+        return;
+      else
+        fprintf(stderr, "Bad vertex id 0x%04x (>= 0x%04x)\n", 
+                vertex->vertex_id, vbuf->nr_vertices);
+      return;
+   }
+      
    vertex->vertex_id = vbuf->nr_vertices++;
 
    for (i = 0; i < vinfo->num_attribs; i++) {
@@ -190,8 +200,7 @@ static void vbuf_tri( struct draw_stage *stage,
    check_space( vbuf );
 
    for (i = 0; i < 3; i++) {
-      if (prim->v[i]->vertex_id == 0xffff) 
-         emit_vertex( vbuf, prim->v[i] );
+      emit_vertex( vbuf, prim->v[i] );
       
       vbuf->element_map[vbuf->nr_elements++] = prim->v[i]->vertex_id;
    }
@@ -207,8 +216,7 @@ static void vbuf_line(struct draw_stage *stage,
    check_space( vbuf );
 
    for (i = 0; i < 2; i++) {
-      if (prim->v[i]->vertex_id == 0xffff) 
-         emit_vertex( vbuf, prim->v[i] );
+      emit_vertex( vbuf, prim->v[i] );
 
       vbuf->element_map[vbuf->nr_elements++] = prim->v[i]->vertex_id;
    }   
@@ -222,8 +230,7 @@ static void vbuf_point(struct draw_stage *stage,
 
    check_space( vbuf );
 
-   if (prim->v[0]->vertex_id == 0xffff) 
-      emit_vertex( vbuf, prim->v[0] );
+   emit_vertex( vbuf, prim->v[0] );
    
    vbuf->element_map[vbuf->nr_elements++] = prim->v[0]->vertex_id;
 }
index ddf662e..7cb3da6 100644 (file)
@@ -140,7 +140,7 @@ static void vbuf_tri( struct draw_stage *stage,
       vbuf_flush_elements( stage );
 
    for (i = 0; i < 3; i++) {
-      if (prim->v[i]->vertex_id == 0xffff
+      if (prim->v[i]->vertex_id == UNDEFINED_VERTEX_ID
          emit_vertex( vbuf, prim->v[i] );
       
       vbuf->element_map[vbuf->nr_elements++] = (ushort) prim->v[i]->vertex_id;
@@ -158,7 +158,7 @@ static void vbuf_line(struct draw_stage *stage,
       vbuf_flush_elements( stage );
 
    for (i = 0; i < 2; i++) {
-      if (prim->v[i]->vertex_id == 0xffff
+      if (prim->v[i]->vertex_id == UNDEFINED_VERTEX_ID
          emit_vertex( vbuf, prim->v[i] );
 
       vbuf->element_map[vbuf->nr_elements++] = (ushort) prim->v[i]->vertex_id;
@@ -174,7 +174,7 @@ static void vbuf_point(struct draw_stage *stage,
    if (!check_space( vbuf ))
       vbuf_flush_elements( stage );
 
-   if (prim->v[0]->vertex_id == 0xffff
+   if (prim->v[0]->vertex_id == UNDEFINED_VERTEX_ID
       emit_vertex( vbuf, prim->v[0] );
    
    vbuf->element_map[vbuf->nr_elements++] = (ushort) prim->v[0]->vertex_id;