draw llvm: fix loop iteration and vertex header offsets
authorZack Rusin <zackr@vmware.com>
Tue, 6 Apr 2010 04:13:20 +0000 (00:13 -0400)
committerZack Rusin <zackr@vmware.com>
Tue, 6 Apr 2010 04:13:20 +0000 (00:13 -0400)
the loop was doing a NE comparison which we could have skipped if the prim
was triangles (3 verts) and our step was 4 verts. also fix offsets in conversion
to aos.

src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/auxiliary/gallivm/lp_bld_flow.c
src/gallium/auxiliary/gallivm/lp_bld_flow.h

index 382f765e16c9e60c5e6c992bbfdb4b0dc48dbfa8..27df59653c2602f85ab6d2bf57788ac0bef0f47e 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <llvm-c/Transforms/Scalar.h>
 
+#define DEBUG_STORE 0
+
 static void
 init_globals(struct draw_llvm *llvm)
 {
@@ -235,7 +237,7 @@ generate_vs(struct draw_llvm *llvm,
                      NULL/*sampler*/);
 }
 
-
+#if DEBUG_STORE
 static void print_vectorf(LLVMBuilderRef builder,
                          LLVMValueRef vec)
 {
@@ -251,6 +253,7 @@ static void print_vectorf(LLVMBuilderRef builder,
    lp_build_printf(builder, "vector = [%f, %f, %f, %f]\n",
                    val[0], val[1], val[2], val[3]);
 }
+#endif
 
 static void
 generate_fetch(LLVMBuilderRef builder,
@@ -404,6 +407,9 @@ store_aos(LLVMBuilderRef builder,
    LLVMBuildStore(builder, LLVMConstInt(LLVMInt32Type(),
                                         0xffff, 0), id_ptr);
 
+#if DEBUG_STORE
+   lp_build_printf(builder, "    ---- %p storing at %d (%p)\n", io_ptr, index, data_ptr);
+#endif
 #if 0
    /*lp_build_printf(builder, " ---- %p storing at %d (%p)  ", io_ptr, index, data_ptr);
      print_vectorf(builder, value);*/
@@ -458,16 +464,10 @@ store_aos_array(LLVMBuilderRef builder,
                 int num_outputs)
 {
    LLVMValueRef attr_index = LLVMConstInt(LLVMInt32Type(), attrib, 0);
-   LLVMValueRef ind0 = start_index;
-   LLVMValueRef ind1 =
-      LLVMBuildAdd(builder, start_index,
-                   LLVMConstInt(LLVMInt32Type(), 1, 0), "");
-   LLVMValueRef ind2 =
-      LLVMBuildAdd(builder, start_index,
-                   LLVMConstInt(LLVMInt32Type(), 2, 0), "");
-   LLVMValueRef ind3 =
-      LLVMBuildAdd(builder, start_index,
-                   LLVMConstInt(LLVMInt32Type(), 3, 0), "");
+   LLVMValueRef ind0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
+   LLVMValueRef ind1 = LLVMConstInt(LLVMInt32Type(), 1, 0);
+   LLVMValueRef ind2 = LLVMConstInt(LLVMInt32Type(), 2, 0);
+   LLVMValueRef ind3 = LLVMConstInt(LLVMInt32Type(), 3, 0);
    LLVMValueRef io0_ptr, io1_ptr, io2_ptr, io3_ptr;
 
    debug_assert(NUM_CHANNELS == 4);
@@ -481,7 +481,10 @@ store_aos_array(LLVMBuilderRef builder,
    io3_ptr = LLVMBuildGEP(builder, io_ptr,
                           &ind3, 1, "");
 
-   /*lp_build_printf(builder, "io = %d\n", start_index);*/
+#if DEBUG_STORE
+   lp_build_printf(builder, "io = %d, indexes[%d, %d, %d, %d]\n",
+                   start_index, ind0, ind1, ind2, ind3);
+#endif
 
    store_aos(builder, io0_ptr, attr_index, aos[0]);
    store_aos(builder, io1_ptr, attr_index, aos[1]);
@@ -499,6 +502,9 @@ convert_to_aos(LLVMBuilderRef builder,
 {
    unsigned chan, attrib;
 
+#if DEBUG_STORE
+   lp_build_printf(builder, "   # storing begin\n");
+#endif
    for (attrib = 0; attrib < num_outputs; ++attrib) {
       LLVMValueRef soa[4];
       LLVMValueRef aos[4];
@@ -522,6 +528,9 @@ convert_to_aos(LLVMBuilderRef builder,
                       attrib,
                       num_outputs);
    }
+#if DEBUG_STORE
+   lp_build_printf(builder, "   # storing end\n");
+#endif
 }
 
 void
@@ -586,13 +595,20 @@ draw_llvm_generate(struct draw_llvm *llvm)
 
    step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0);
 
+#if DEBUG_STORE
+   lp_build_printf(builder, "start = %d, end = %d, step = %d\n",
+                   start, end, step);
+#endif
    lp_build_loop_begin(builder, start, &lp_loop);
    {
       LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS];
       LLVMValueRef aos_attribs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS];
       LLVMValueRef io = LLVMBuildGEP(builder, io_ptr, &lp_loop.counter, 1, "");
       const LLVMValueRef (*ptr_aos)[NUM_CHANNELS];
-
+#if DEBUG_STORE
+      lp_build_printf(builder, " --- loop counter %d\n",
+                      lp_loop.counter);
+#endif
       for (i = 0; i < NUM_CHANNELS; ++i) {
          LLVMValueRef true_index = LLVMBuildAdd(
             builder,
@@ -620,7 +636,7 @@ draw_llvm_generate(struct draw_llvm *llvm)
                      draw->vs.vertex_shader->info.num_outputs,
                      max_vertices, lp_loop.counter);
    }
-   lp_build_loop_end(builder, end, step, &lp_loop);
+   lp_build_loop_end_cond(builder, end, step, LLVMIntUGE, &lp_loop);
 
    LLVMBuildRetVoid(builder);
 
index f65cf3822c499d4c7e01eb98bdbbf2eb276706b7..aebfe40a03713734cb97ae3ce9e2e06a559aaecf 100644 (file)
@@ -245,8 +245,6 @@ static void llvm_middle_end_linear_run( struct draw_pt_middle_end *middle,
       return;
    }
 
-   debug_printf("--- pipe verts data[0] = %p, data[1] = %p\n",
-                pipeline_verts->data[0], pipeline_verts->data[1]);
    fpme->llvm->jit_func( &fpme->llvm->jit_context,
                          pipeline_verts,
                          (const char **)draw->pt.user.vbuffer,
index 106fc03e46f8e4dec9e9900e922758d51995b96a..e60ab4f6ba193f7c94b9fa12a0ee383618ccb913 100644 (file)
@@ -570,6 +570,35 @@ lp_build_loop_end(LLVMBuilderRef builder,
    LLVMPositionBuilderAtEnd(builder, after_block);
 }
 
+void
+lp_build_loop_end_cond(LLVMBuilderRef builder,
+                       LLVMValueRef end,
+                       LLVMValueRef step,
+                       int llvm_cond,
+                       struct lp_build_loop_state *state)
+{
+   LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+   LLVMValueRef function = LLVMGetBasicBlockParent(block);
+   LLVMValueRef next;
+   LLVMValueRef cond;
+   LLVMBasicBlockRef after_block;
+
+   if (!step)
+      step = LLVMConstInt(LLVMTypeOf(end), 1, 0);
+
+   next = LLVMBuildAdd(builder, state->counter, step, "");
+
+   cond = LLVMBuildICmp(builder, llvm_cond, next, end, "");
+
+   after_block = LLVMAppendBasicBlock(function, "");
+
+   LLVMBuildCondBr(builder, cond, after_block, state->block);
+
+   LLVMAddIncoming(state->counter, &next, &block, 1);
+
+   LLVMPositionBuilderAtEnd(builder, after_block);
+}
+
 
 
 /*
index c2b50e1b6020fc1fb7d4759e38aac8728239313c..745838570c87629a8767ecf70d8b4417ffa6d8cc 100644 (file)
@@ -124,6 +124,13 @@ lp_build_loop_end(LLVMBuilderRef builder,
                   LLVMValueRef step,
                   struct lp_build_loop_state *state);
 
+void
+lp_build_loop_end_cond(LLVMBuilderRef builder,
+                       LLVMValueRef end,
+                       LLVMValueRef step,
+                       int cond, /* LLVM condition */
+                       struct lp_build_loop_state *state);
+