draw/llvm: fix hard-coded number of total clip planes
authorBrian Paul <brianp@vmware.com>
Mon, 10 Oct 2011 23:43:59 +0000 (17:43 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 11 Oct 2011 13:41:22 +0000 (07:41 -0600)
Instead of 12 use DRAW_TOTAL_CLIP_PLANES.  The max number of user-defined
clip planes was increased to 8 so the total number of planes is 14.
This doesn't fix any specific bug, but clearly the old code was wrong.

Reviewed-by: José Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_llvm.h
src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c

index 6a85b79a02c31b022cb677b1328ff6d039af54db..e1b9a15e528b5bde1c9fa6863362780b9643916f 100644 (file)
@@ -369,7 +369,7 @@ draw_set_mapped_constant_buffer(struct draw_context *draw,
    case PIPE_SHADER_VERTEX:
       draw->pt.user.vs_constants[slot] = buffer;
       draw->pt.user.vs_constants_size[slot] = size;
-      draw->pt.user.planes = (float (*) [12][4]) &(draw->plane[0]);
+      draw->pt.user.planes = (float (*) [DRAW_TOTAL_CLIP_PLANES][4]) &(draw->plane[0]);
       draw_vs_set_constants(draw, slot, buffer, size);
       break;
    case PIPE_SHADER_GEOMETRY:
index d427d2c9ced0b62cc8a1b8e0354573f87289dc0d..01659fe76a1c03b4a4bfd36844a21e8df125b87c 100644 (file)
@@ -191,7 +191,8 @@ create_jit_context_type(struct gallivm_state *gallivm,
 
    elem_types[0] = LLVMPointerType(float_type, 0); /* vs_constants */
    elem_types[1] = LLVMPointerType(float_type, 0); /* gs_constants */
-   elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), 12), 0); /* planes */
+   elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4),
+                                                 DRAW_TOTAL_CLIP_PLANES), 0);
    elem_types[3] = LLVMPointerType(float_type, 0); /* viewport */
    elem_types[4] = LLVMArrayType(texture_type,
                                  PIPE_MAX_VERTEX_SAMPLERS); /* textures */
@@ -708,17 +709,21 @@ store_aos(struct gallivm_state *gallivm,
    LLVMValueRef id_ptr = draw_jit_header_id(gallivm, io_ptr);
    LLVMValueRef data_ptr = draw_jit_header_data(gallivm, io_ptr);
    LLVMValueRef indices[3];
-   LLVMValueRef val, shift;
+   LLVMValueRef val;
+   int vertex_id_pad_edgeflag;
 
    indices[0] = lp_build_const_int32(gallivm, 0);
    indices[1] = index;
    indices[2] = lp_build_const_int32(gallivm, 0);
 
-   /* initialize vertex id:16 = 0xffff, pad:3 = 0, edgeflag:1 = 1 */
-   val = lp_build_const_int32(gallivm, 0xffff1);
-   shift = lp_build_const_int32(gallivm, 12);
-   val = LLVMBuildShl(builder, val, shift, "");
-   /* add clipmask:12 */   
+   /* If this assertion fails, it means we need to update the bit twidding
+    * code here.  See struct vertex_header in draw_private.h.
+    */
+   assert(DRAW_TOTAL_CLIP_PLANES==14);
+   /* initialize vertex id:16 = 0xffff, pad:1 = 0, edgeflag:1 = 1 */
+   vertex_id_pad_edgeflag = (0xffff << 16) | (1 << DRAW_TOTAL_CLIP_PLANES);
+   val = lp_build_const_int32(gallivm, vertex_id_pad_edgeflag);
+   /* OR with the clipmask */
    val = LLVMBuildOr(builder, val, clipmask, "");               
 
    /* store vertex header */
index 375b7b8b571f25537e5de2251250a0b314de6633..bc361357de537d5421352207f54d5d4cf4f3ac29 100644 (file)
@@ -98,7 +98,7 @@ struct draw_jit_context
 {
    const float *vs_constants;
    const float *gs_constants;
-   float (*planes) [12][4];
+   float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
    float *viewport;
 
    struct draw_jit_texture textures[PIPE_MAX_VERTEX_SAMPLERS];
index ef772660f7127454a3bc7ec693200ad7c098249e..b84d2b77179bc0e8b83ab47831b2f1bfbf4148e5 100644 (file)
@@ -52,6 +52,10 @@ struct draw_llvm;
 #endif
 
 
+/** Sum of frustum planes and user-defined planes */
+#define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
+
+
 struct pipe_context;
 struct draw_vertex_shader;
 struct draw_context;
@@ -66,9 +70,9 @@ struct tgsi_sampler;
  * Carry some useful information around with the vertices in the prim pipe.  
  */
 struct vertex_header {
-   unsigned clipmask:12;
+   unsigned clipmask:DRAW_TOTAL_CLIP_PLANES;
    unsigned edgeflag:1;
-   unsigned pad:3;
+   unsigned pad:1;
    unsigned vertex_id:16;
 
    float clip[4];
@@ -179,7 +183,7 @@ struct draw_context
          unsigned gs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
          
          /* pointer to planes */
-         float (*planes)[12][4]; 
+         float (*planes)[DRAW_TOTAL_CLIP_PLANES][4]; 
       } user;
 
       boolean test_fse;         /* enable FSE even though its not correct (eg for softpipe) */
@@ -277,7 +281,7 @@ struct draw_context
 
    /* Clip derived state:
     */
-   float plane[12][4];
+   float plane[DRAW_TOTAL_CLIP_PLANES][4];
    unsigned nr_planes;
    boolean depth_clamp;
 
index 2a3fb89884c61f705d947d5089869d8c1bd5c13c..7698f5ff2af752e795cb95ebe9e40d96d4cffb70 100644 (file)
@@ -184,7 +184,7 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
    fpme->llvm->jit_context.gs_constants =
       draw->pt.user.gs_constants[0];
    fpme->llvm->jit_context.planes =
-      (float (*) [12][4]) draw->pt.user.planes[0];
+      (float (*) [DRAW_TOTAL_CLIP_PLANES][4]) draw->pt.user.planes[0];
    fpme->llvm->jit_context.viewport =
       (float *)draw->viewport.scale;