draw: Respect pipe_vertex_buffer::max_index in llvm generated code.
authorJosé Fonseca <jfonseca@vmware.com>
Sun, 25 Apr 2010 20:43:49 +0000 (21:43 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sun, 25 Apr 2010 22:41:49 +0000 (23:41 +0100)
Everybody should respect max_index, specially llvm generated code, which
likes to eat vertices 4 at a time, so it may end up chew a bit a bit more
than actually exists.

src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_llvm.h

index 936753f66b91e1e46f93df68de7764451f3f20ed..703b46b518bf6ffa02a63fdd8e0846bb194eff07 100644 (file)
@@ -286,10 +286,16 @@ generate_fetch(LLVMBuilderRef builder,
    LLVMValueRef vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr,
                                            &indices, 1, "");
    LLVMValueRef vb_stride = draw_jit_vbuffer_stride(builder, vbuf);
+   LLVMValueRef vb_max_index = draw_jit_vbuffer_max_index(builder, vbuf);
    LLVMValueRef vb_buffer_offset = draw_jit_vbuffer_offset(builder, vbuf);
-   LLVMValueRef stride = LLVMBuildMul(builder,
-                                      vb_stride,
-                                      index, "");
+   LLVMValueRef cond;
+   LLVMValueRef stride;
+
+   cond = LLVMBuildICmp(builder, LLVMIntULE, index, vb_max_index, "");
+
+   index = LLVMBuildSelect(builder, cond, index, vb_max_index, "");
+
+   stride = LLVMBuildMul(builder, vb_stride, index, "");
 
    vbuffer_ptr = LLVMBuildLoad(builder, vbuffer_ptr, "vbuffer");
 
index 28b9044a81eeb482a0c965e098aee3fbeb3b2b1b..20f4f3da5f3552474f00672666ded84bcd8eedc1 100644 (file)
@@ -78,7 +78,10 @@ struct draw_jit_context
 #define draw_jit_vbuffer_stride(_builder, _ptr)         \
    lp_build_struct_get(_builder, _ptr, 0, "stride")
 
-#define draw_jit_vbuffer_offset(_builder, _ptr)                 \
+#define draw_jit_vbuffer_max_index(_builder, _ptr)      \
+   lp_build_struct_get(_builder, _ptr, 1, "max_index")
+
+#define draw_jit_vbuffer_offset(_builder, _ptr)         \
    lp_build_struct_get(_builder, _ptr, 2, "buffer_offset")