[Mesa-dev] [PATCH 1/3] draw/llvm: move stuff to llvm cache struct

Frank Henigman fjhenigman at google.com
Sun Jun 16 10:59:03 PDT 2013


Move stuff out of draw_llvm_variant into a new struct llvm_cache_item
in preparation for caching it.  No functional change.
---
 src/gallium/auxiliary/draw/draw_llvm.c             | 106 +++++++++++++--------
 src/gallium/auxiliary/draw/draw_llvm.h             |  12 ++-
 .../draw/draw_pt_fetch_shade_pipeline_llvm.c       |   4 +-
 3 files changed, 77 insertions(+), 45 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 823a1ce..6225e53 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -460,7 +460,7 @@ create_jit_vertex_header(struct gallivm_state *gallivm, int data_elems)
 static void
 create_jit_types(struct draw_llvm_variant *variant)
 {
-   struct gallivm_state *gallivm = variant->gallivm;
+   struct gallivm_state *gallivm = variant->llvm_item->gallivm;
    LLVMTypeRef texture_type, sampler_type, context_type, buffer_type,
       vb_type;
 
@@ -551,6 +551,49 @@ draw_llvm_destroy(struct draw_llvm *llvm)
 }
 
 
+static struct llvm_cache_item *
+llvm_cache_item_create(struct draw_llvm_variant *variant, unsigned num_inputs)
+{
+   struct llvm_cache_item *item;
+   LLVMTypeRef vertex_header;
+
+   item = MALLOC(sizeof *item);
+   if (item == NULL)
+      return NULL;
+
+   variant->llvm_item = item;
+
+   item->gallivm = gallivm_create();
+
+   create_jit_types(variant);
+
+   vertex_header = create_jit_vertex_header(item->gallivm, num_inputs);
+
+   variant->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0);
+
+   draw_llvm_generate(variant->llvm, variant, FALSE);  /* linear */
+   draw_llvm_generate(variant->llvm, variant, TRUE);   /* elts */
+
+   gallivm_compile_module(item->gallivm);
+
+   item->jit_func = (draw_jit_vert_func)
+	 gallivm_jit_function(item->gallivm, variant->function);
+
+   item->jit_func_elts = (draw_jit_vert_func_elts)
+	 gallivm_jit_function(item->gallivm, variant->function_elts);
+
+   gallivm_free_function(item->gallivm,
+                         variant->function, item->jit_func);
+
+   gallivm_free_function(item->gallivm,
+                         variant->function_elts, item->jit_func_elts);
+
+   gallivm_teardown(item->gallivm);
+
+   return item;
+}
+
+
 /**
  * Create LLVM-generated code for a vertex shader.
  */
@@ -562,7 +605,6 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
    struct draw_llvm_variant *variant;
    struct llvm_vertex_shader *shader =
       llvm_vertex_shader(llvm->draw->vs.vertex_shader);
-   LLVMTypeRef vertex_header;
 
    variant = MALLOC(sizeof *variant +
                     shader->variant_key_size -
@@ -571,41 +613,19 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
       return NULL;
 
    variant->llvm = llvm;
-
-   variant->gallivm = gallivm_create();
-
-   create_jit_types(variant);
+   variant->shader = shader;
 
    memcpy(&variant->key, key, shader->variant_key_size);
 
-   vertex_header = create_jit_vertex_header(variant->gallivm, num_inputs);
-
-   variant->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0);
-
-   draw_llvm_generate(llvm, variant, FALSE);  /* linear */
-   draw_llvm_generate(llvm, variant, TRUE);   /* elts */
-
-   gallivm_compile_module(variant->gallivm);
-
-   variant->jit_func = (draw_jit_vert_func)
-         gallivm_jit_function(variant->gallivm, variant->function);
-
-   variant->jit_func_elts = (draw_jit_vert_func_elts)
-         gallivm_jit_function(variant->gallivm, variant->function_elts);
-
-   gallivm_free_function(variant->gallivm,
-                         variant->function, variant->jit_func);
-
-   gallivm_free_function(variant->gallivm,
-                         variant->function_elts, variant->jit_func_elts);
-
-   gallivm_teardown(variant->gallivm);
+   variant->llvm_item = llvm_cache_item_create(variant, num_inputs);
+   if (variant->llvm_item == NULL) {
+      FREE(variant);
+      return NULL;
+   }
 
-   variant->shader = shader;
    variant->list_item_global.base = variant;
    variant->list_item_local.base = variant;
    /*variant->no = */shader->variants_created++;
-   variant->list_item_global.base = variant;
 
    return variant;
 }
@@ -624,7 +644,7 @@ generate_vs(struct draw_llvm_variant *variant,
 {
    struct draw_llvm *llvm = variant->llvm;
    const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens;
-   LLVMValueRef consts_ptr = draw_jit_context_vs_constants(variant->gallivm, context_ptr);
+   LLVMValueRef consts_ptr = draw_jit_context_vs_constants(variant->llvm_item->gallivm, context_ptr);
    struct lp_build_sampler_soa *sampler = 0;
 
    if (gallivm_debug & (GALLIVM_DEBUG_TGSI | GALLIVM_DEBUG_IR)) {
@@ -635,7 +655,7 @@ generate_vs(struct draw_llvm_variant *variant,
    if (llvm->draw->num_sampler_views && llvm->draw->num_samplers)
       sampler = draw_sampler;
 
-   lp_build_tgsi_soa(variant->gallivm,
+   lp_build_tgsi_soa(variant->llvm_item->gallivm,
                      tokens,
                      vs_type,
                      NULL /*struct lp_build_mask_context *mask*/,
@@ -652,7 +672,7 @@ generate_vs(struct draw_llvm_variant *variant,
       unsigned chan, attrib;
       struct lp_build_context bld;
       struct tgsi_shader_info* info = &llvm->draw->vs.vertex_shader->info;
-      lp_build_context_init(&bld, variant->gallivm, vs_type);
+      lp_build_context_init(&bld, variant->llvm_item->gallivm, vs_type);
 
       for (attrib = 0; attrib < info->num_outputs; ++attrib) {
          for (chan = 0; chan < TGSI_NUM_CHANNELS; ++chan) {
@@ -1071,7 +1091,7 @@ generate_viewport(struct draw_llvm_variant *variant,
                   LLVMValueRef context_ptr)
 {
    int i;
-   struct gallivm_state *gallivm = variant->gallivm;
+   struct gallivm_state *gallivm = variant->llvm_item->gallivm;
    struct lp_type f32_type = vs_type;
    const unsigned pos = draw_current_shader_position_output(variant->llvm->draw);
    LLVMTypeRef vs_type_llvm = lp_build_vec_type(gallivm, vs_type);
@@ -1467,7 +1487,7 @@ static void
 draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant,
                    boolean elts)
 {
-   struct gallivm_state *gallivm = variant->gallivm;
+   struct gallivm_state *gallivm = variant->llvm_item->gallivm;
    LLVMContextRef context = gallivm->context;
    LLVMTypeRef int32_type = LLVMInt32TypeInContext(context);
    LLVMTypeRef arg_types[9];
@@ -1941,18 +1961,24 @@ draw_llvm_set_sampler_state(struct draw_context *draw,
 }
 
 
+static void
+llvm_cache_item_destroy(struct llvm_cache_item *item)
+{
+   gallivm_free_code(item->gallivm);
+   FREE(item->gallivm);
+   FREE(item);
+}
+
+
 void
 draw_llvm_destroy_variant(struct draw_llvm_variant *variant)
 {
-   struct draw_llvm *llvm = variant->llvm;
-
-   gallivm_free_code(variant->gallivm);
-   FREE(variant->gallivm);
+   llvm_cache_item_destroy(variant->llvm_item);
 
    remove_from_list(&variant->list_item_local);
    variant->shader->variants_cached--;
    remove_from_list(&variant->list_item_global);
-   llvm->nr_variants--;
+   variant->llvm->nr_variants--;
    FREE(variant);
 }
 
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 347fde2..d979dcf 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -372,10 +372,18 @@ struct draw_gs_llvm_variant_list_item
 };
 
 
-struct draw_llvm_variant
+struct llvm_cache_item
 {
    struct gallivm_state *gallivm;
 
+   draw_jit_vert_func jit_func;
+   draw_jit_vert_func_elts jit_func_elts;
+};
+
+struct draw_llvm_variant
+{
+   struct llvm_cache_item *llvm_item;
+
    /* LLVM JIT builder types */
    LLVMTypeRef context_ptr_type;
    LLVMTypeRef buffer_ptr_type;
@@ -384,8 +392,6 @@ struct draw_llvm_variant
 
    LLVMValueRef function;
    LLVMValueRef function_elts;
-   draw_jit_vert_func jit_func;
-   draw_jit_vert_func_elts jit_func_elts;
 
    struct llvm_vertex_shader *shader;
 
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 2e47fad..cbe0d86 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
@@ -346,7 +346,7 @@ llvm_pipeline_generic( struct draw_pt_middle_end *middle,
    }
 
    if (fetch_info->linear)
-      clipped = fpme->current_variant->jit_func( &fpme->llvm->jit_context,
+      clipped = fpme->current_variant->llvm_item->jit_func( &fpme->llvm->jit_context,
                                        llvm_vert_info.verts,
                                        draw->pt.user.vbuffer,
                                        fetch_info->start,
@@ -355,7 +355,7 @@ llvm_pipeline_generic( struct draw_pt_middle_end *middle,
                                        draw->pt.vertex_buffer,
                                        draw->instance_id);
    else
-      clipped = fpme->current_variant->jit_func_elts( &fpme->llvm->jit_context,
+      clipped = fpme->current_variant->llvm_item->jit_func_elts( &fpme->llvm->jit_context,
                                             llvm_vert_info.verts,
                                             draw->pt.user.vbuffer,
                                             fetch_info->elts,
-- 
1.8.3



More information about the mesa-dev mailing list