translate: don't crash on elts paths with instances
authorZack Rusin <zackr@vmware.com>
Wed, 16 Jun 2010 12:52:33 +0000 (08:52 -0400)
committerZack Rusin <zackr@vmware.com>
Wed, 16 Jun 2010 18:43:56 +0000 (14:43 -0400)
src/gallium/auxiliary/translate/translate_generic.c

index f8dbd2b36a147a971cba8bbb03b68ef2dd3c8bde..0e43a512ee89c070a6cd75802416071fdb7c3b17 100644 (file)
@@ -378,25 +378,28 @@ static void PIPE_CDECL generic_run_elts( struct translate *translate,
         char *dst = (vert + 
                      tg->attrib[attr].output_offset);
 
-         if (tg->attrib[attr].instance_divisor) {
-            index = instance_id / tg->attrib[attr].instance_divisor;
-         } else {
-            index = elt;
-         }
+         if (tg->attrib[attr].type == TRANSLATE_ELEMENT_NORMAL) {
+            if (tg->attrib[attr].instance_divisor) {
+               index = instance_id / tg->attrib[attr].instance_divisor;
+            } else {
+               index = elt;
+            }
 
-         index = MIN2(index, tg->attrib[attr].max_index);
+            index = MIN2(index, tg->attrib[attr].max_index);
 
-         src = tg->attrib[attr].input_ptr +
-               tg->attrib[attr].input_stride * index;
+            src = tg->attrib[attr].input_ptr +
+                  tg->attrib[attr].input_stride * index;
 
-        tg->attrib[attr].fetch( data, src, 0, 0 );
+            tg->attrib[attr].fetch( data, src, 0, 0 );
 
+         } else {
+            data[0] = (float)instance_id;
+         }
          if (0) debug_printf("vert %d/%d attr %d: %f %f %f %f\n",
                              i, elt, attr, data[0], data[1], data[2], data[3]);
 
         tg->attrib[attr].emit( data, dst );
       }
-      
       vert += tg->translate.key.output_stride;
    }
 }