draw: use the instance id when fetching vertex data
authorZack Rusin <zackr@vmware.com>
Fri, 16 Jul 2010 15:58:20 +0000 (11:58 -0400)
committerZack Rusin <zackr@vmware.com>
Fri, 16 Jul 2010 15:58:20 +0000 (11:58 -0400)
src/gallium/auxiliary/draw/draw_llvm.c

index 315544d7b87907aba84503f3a51bbaedb62d82f4..61c53a06b37af4b5bf2389274224c44cb884f05e 100644 (file)
@@ -368,7 +368,8 @@ generate_fetch(LLVMBuilderRef builder,
                LLVMValueRef *res,
                struct pipe_vertex_element *velem,
                LLVMValueRef vbuf,
-               LLVMValueRef index)
+               LLVMValueRef index,
+               unsigned instance_id)
 {
    LLVMValueRef indices = LLVMConstInt(LLVMInt64Type(), velem->vertex_buffer_index, 0);
    LLVMValueRef vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr,
@@ -393,6 +394,11 @@ generate_fetch(LLVMBuilderRef builder,
    stride = LLVMBuildAdd(builder, stride,
                          LLVMConstInt(LLVMInt32Type(), velem->src_offset, 0),
                          "");
+   if (velem->instance_divisor) {
+      stride = LLVMBuildMul(builder, stride,
+                            LLVMConstInt(LLVMInt32Type(), instance_id, 0),
+                            "");
+   }
 
    /*lp_build_printf(builder, "vbuf index = %d, stride is %d\n", indices, stride);*/
    vbuffer_ptr = LLVMBuildGEP(builder, vbuffer_ptr, &stride, 1, "");
@@ -745,7 +751,8 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
             LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr,
                                            &vb_index, 1, "");
             generate_fetch(builder, vbuffers_ptr,
-                           &aos_attribs[j][i], velem, vb, true_index);
+                           &aos_attribs[j][i], velem, vb, true_index,
+                           draw->instance_id);
          }
       }
       convert_to_soa(builder, aos_attribs, inputs,
@@ -908,7 +915,8 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
             LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr,
                                            &vb_index, 1, "");
             generate_fetch(builder, vbuffers_ptr,
-                           &aos_attribs[j][i], velem, vb, true_index);
+                           &aos_attribs[j][i], velem, vb, true_index,
+                           draw->instance_id);
          }
       }
       convert_to_soa(builder, aos_attribs, inputs,