llvmpipe: refactoring of visibility counter handling
authorRoland Scheidegger <sroland@vmware.com>
Wed, 6 Feb 2013 21:09:46 +0000 (13:09 -0800)
committerRoland Scheidegger <sroland@vmware.com>
Sat, 9 Feb 2013 00:32:30 +0000 (16:32 -0800)
There can be other per-thread data than just vis_counter, so pass a struct
around instead (some of our non-public code uses this already and this
difference is a major cause of merge pain).

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/drivers/llvmpipe/lp_jit.c
src/gallium/drivers/llvmpipe/lp_jit.h
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_rast_priv.h
src/gallium/drivers/llvmpipe/lp_state_fs.c

index d0a791671e644dcaf1f108851ffa3d88427a8287..f517b67fff6d6a74c7a1cc1262b02e0a4f718af0 100644 (file)
@@ -190,6 +190,25 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp)
       lp->jit_context_ptr_type = LLVMPointerType(context_type, 0);
    }
 
+   /* struct lp_jit_thread_data */
+   {
+      LLVMTypeRef elem_types[LP_JIT_THREAD_DATA_COUNT];
+      LLVMTypeRef thread_data_type;
+
+      elem_types[LP_JIT_THREAD_DATA_COUNTER] = LLVMInt32TypeInContext(lc);
+
+      thread_data_type = LLVMStructTypeInContext(lc, elem_types,
+                                                 Elements(elem_types), 0);
+
+#if HAVE_LLVM < 0x0300
+      LLVMInvalidateStructLayout(gallivm->target, thread_data_type);
+
+      LLVMAddTypeName(gallivm->module, "thread_data", thread_data_type);
+#endif
+
+      lp->jit_thread_data_ptr_type = LLVMPointerType(thread_data_type, 0);
+   }
+
    if (gallivm_debug & GALLIVM_DEBUG_IR) {
       LLVMDumpModule(gallivm->module);
    }
index 3057c0dc2b0c36b4cd111d0913de364d28d0a4a1..472d3911e71937d7532b556b08cee7db840d10a9 100644 (file)
@@ -162,6 +162,22 @@ enum {
    lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
 
 
+struct lp_jit_thread_data
+{
+   uint32_t vis_counter;
+};
+
+
+enum {
+   LP_JIT_THREAD_DATA_COUNTER = 0,
+   LP_JIT_THREAD_DATA_COUNT
+};
+
+
+#define lp_jit_thread_data_counter(_gallivm, _ptr) \
+   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
+
+
 /**
  * typedef for fragment shader function
  *
@@ -189,7 +205,7 @@ typedef void
                     uint8_t **color,
                     void *depth,
                     uint32_t mask,
-                    uint32_t *counter,
+                    struct lp_jit_thread_data *thread_data,
                     unsigned *stride);
 
 
index 2daf2fefa2645124614c69de7dcdf8291fa7a430..09c578769bc4ec34cb4ccd446e4705cd4e609987 100644 (file)
@@ -386,7 +386,7 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task,
                                             color,
                                             depth,
                                             0xffff,
-                                            &task->vis_counter,
+                                            &task->thread_data,
                                             stride);
          END_JIT_CALL();
       }
@@ -469,7 +469,7 @@ lp_rast_shade_quads_mask(struct lp_rasterizer_task *task,
                                          color,
                                          depth,
                                          mask,
-                                         &task->vis_counter,
+                                         &task->thread_data,
                                          stride);
    END_JIT_CALL();
 }
@@ -491,7 +491,7 @@ lp_rast_begin_query(struct lp_rasterizer_task *task,
 
    switch (pq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
-      task->vis_counter = 0;
+      task->thread_data.vis_counter = 0;
       break;
    case PIPE_QUERY_PRIMITIVES_GENERATED:
    case PIPE_QUERY_PRIMITIVES_EMITTED:
@@ -519,7 +519,7 @@ lp_rast_end_query(struct lp_rasterizer_task *task,
 
    switch (pq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
-      pq->count[task->thread_index] += task->vis_counter;
+      pq->count[task->thread_index] += task->thread_data.vis_counter;
       break;
    case PIPE_QUERY_TIMESTAMP:
       pq->count[task->thread_index] = os_time_get_nano();
index afcf33382f4e3eb429b774e97fc1e986afd1e2ea..5db8fcd19b21181b56670a260ffedcc7db5790e8 100644 (file)
@@ -94,8 +94,8 @@ struct lp_rasterizer_task
    /** "my" index */
    unsigned thread_index;
 
-   /* occlude counter for visiable pixels */
-   uint32_t vis_counter;
+   /* occlude counter for visible pixels */
+   struct lp_jit_thread_data thread_data;
    uint64_t query_start;
    struct llvmpipe_query *query[PIPE_QUERY_TYPES];
 
@@ -276,7 +276,7 @@ lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
                                       color,
                                       depth,
                                       0xffff,
-                                      &task->vis_counter,
+                                      &task->thread_data,
                                       stride );
    END_JIT_CALL();
 }
index 00f3b6990e3fd0c67299200935c560beac47d117..90a67e62b856d48616007febd680e6057656f0ff 100644 (file)
@@ -233,7 +233,7 @@ generate_fs(struct gallivm_state *gallivm,
             LLVMValueRef facing,
             unsigned partial_mask,
             LLVMValueRef mask_input,
-            LLVMValueRef counter)
+            LLVMValueRef thread_data_ptr)
 {
    const struct util_format_description *zs_format_desc = NULL;
    const struct tgsi_token *tokens = shader->base.tokens;
@@ -431,9 +431,12 @@ generate_fs(struct gallivm_state *gallivm,
       }
    }
 
-   if (counter)
+   if (key->occlusion_count) {
+      LLVMValueRef counter = lp_jit_thread_data_counter(gallivm, thread_data_ptr);
+      lp_build_name(counter, "counter");
       lp_build_occlusion_count(gallivm, type,
                                lp_build_mask_value(&mask), counter);
+   }
 
    *pmask = lp_build_mask_end(&mask);
 }
@@ -457,7 +460,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
                  LLVMValueRef depth_ptr,
                  unsigned depth_bits,
                  LLVMValueRef facing,
-                 LLVMValueRef counter)
+                 LLVMValueRef thread_data_ptr)
 {
    const struct util_format_description *zs_format_desc = NULL;
    const struct tgsi_token *tokens = shader->base.tokens;
@@ -674,6 +677,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
    }
 
    if (key->occlusion_count) {
+      LLVMValueRef counter = lp_jit_thread_data_counter(gallivm, thread_data_ptr);
       lp_build_name(counter, "counter");
       lp_build_occlusion_count(gallivm, type,
                                lp_build_mask_value(&mask), counter);
@@ -1767,7 +1771,7 @@ generate_fragment(struct llvmpipe_context *lp,
    LLVMValueRef stride_ptr;
    LLVMValueRef depth_ptr;
    LLVMValueRef mask_input;
-   LLVMValueRef counter = NULL;
+   LLVMValueRef thread_data_ptr;
    LLVMBasicBlockRef block;
    LLVMBuilderRef builder;
    struct lp_build_sampler_soa *sampler;
@@ -1848,7 +1852,7 @@ generate_fragment(struct llvmpipe_context *lp,
    arg_types[7] = LLVMPointerType(LLVMPointerType(blend_vec_type, 0), 0);  /* color */
    arg_types[8] = LLVMPointerType(int8_type, 0);       /* depth */
    arg_types[9] = int32_type;                          /* mask_input */
-   arg_types[10] = LLVMPointerType(int32_type, 0);     /* counter */
+   arg_types[10] = variant->jit_thread_data_ptr_type;  /* per thread data */
    arg_types[11] = LLVMPointerType(int32_type, 0);     /* stride */
 
    func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context),
@@ -1876,6 +1880,7 @@ generate_fragment(struct llvmpipe_context *lp,
    color_ptr_ptr = LLVMGetParam(function, 7);
    depth_ptr    = LLVMGetParam(function, 8);
    mask_input   = LLVMGetParam(function, 9);
+   thread_data_ptr  = LLVMGetParam(function, 10);
    stride_ptr   = LLVMGetParam(function, 11);
 
    lp_build_name(context_ptr, "context");
@@ -1886,14 +1891,10 @@ generate_fragment(struct llvmpipe_context *lp,
    lp_build_name(dady_ptr, "dady");
    lp_build_name(color_ptr_ptr, "color_ptr_ptr");
    lp_build_name(depth_ptr, "depth");
+   lp_build_name(thread_data_ptr, "thread_data");
    lp_build_name(mask_input, "mask_input");
    lp_build_name(stride_ptr, "stride_ptr");
 
-   if (key->occlusion_count) {
-      counter = LLVMGetParam(function, 10);
-      lp_build_name(counter, "counter");
-   }
-
    /*
     * Function body
     */
@@ -1947,7 +1948,7 @@ generate_fragment(struct llvmpipe_context *lp,
                      facing,
                      partial_mask,
                      mask_input,
-                     counter);
+                     thread_data_ptr);
 
          for (cbuf = 0; cbuf < key->nr_cbufs; cbuf++)
             for (chan = 0; chan < TGSI_NUM_CHANNELS; ++chan)
@@ -2006,7 +2007,7 @@ generate_fragment(struct llvmpipe_context *lp,
                        depth_ptr,
                        depth_bits,
                        facing,
-                       counter);
+                       thread_data_ptr);
 
       for (i = 0; i < num_fs; i++) {
          LLVMValueRef indexi = lp_build_const_int32(gallivm, i);