summaryrefslogtreecommitdiff
path: root/src/gallium
diff options
context:
space:
mode:
authorZack Rusin <zackr@vmware.com>2010-04-06 00:13:20 -0400
committerZack Rusin <zackr@vmware.com>2010-04-06 00:13:20 -0400
commit9dd70e7b85ddbc73bd976c4dab81476aa36c557e (patch)
tree6fa7b12033f424c346d4db26eec1b7ad9a201d29 /src/gallium
parent1b0bab167cd541f70c32249ca3e70da88b8c93c5 (diff)
draw llvm: fix loop iteration and vertex header offsets
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.
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c44
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_flow.c29
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_flow.h7
4 files changed, 66 insertions, 16 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 382f765e16..27df59653c 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -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);
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
index f65cf3822c..aebfe40a03 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
@@ -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,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c
index 106fc03e46..e60ab4f6ba 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c
@@ -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);
+}
+
/*
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h
index c2b50e1b60..745838570c 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h
@@ -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);
+