gallivm: cleanup the gs interface
authorZack Rusin <zackr@vmware.com>
Wed, 27 Mar 2013 11:27:59 +0000 (04:27 -0700)
committerZack Rusin <zackr@vmware.com>
Wed, 3 Apr 2013 17:16:25 +0000 (10:16 -0700)
Instead of void pointers use a base interface.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c

index 3ce48d802c73fd5076fb0f84a136183b55c9c0db..4731c8cbd825f9918186f1d14740bf79fd150f98 100644 (file)
@@ -64,6 +64,19 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *var,
                    boolean elts);
 
 
+struct draw_gs_llvm_iface {
+   struct lp_build_tgsi_gs_iface base;
+
+   struct draw_gs_llvm_variant *variant;
+   LLVMValueRef input;
+};
+
+static INLINE const struct draw_gs_llvm_iface *
+draw_gs_llvm_iface(const struct lp_build_tgsi_gs_iface *iface)
+{
+   return (const struct draw_gs_llvm_iface *)iface;
+}
+
 /**
  * Create LLVM type for struct draw_jit_texture
  */
@@ -1237,14 +1250,37 @@ clipmask_booli32(struct gallivm_state *gallivm,
    return ret;
 }
 
+static LLVMValueRef
+draw_gs_llvm_fetch_input(const struct lp_build_tgsi_gs_iface *gs_iface,
+                         struct lp_build_tgsi_context * bld_base,
+                         LLVMValueRef vertex_index,
+                         LLVMValueRef attrib_index,
+                         LLVMValueRef swizzle_index)
+{
+   const struct draw_gs_llvm_iface *gs = draw_gs_llvm_iface(gs_iface);
+   struct gallivm_state *gallivm = bld_base->base.gallivm;
+   LLVMBuilderRef builder = gallivm->builder;
+   LLVMValueRef indices[3];
+   LLVMValueRef res;
+
+   indices[0] = vertex_index;
+   indices[1] = attrib_index;
+   indices[2] = swizzle_index;
+   
+   res = LLVMBuildGEP(builder, gs->input, indices, 3, "");
+   res = LLVMBuildLoad(builder, res, "");
+
+   return res;
+}
+
 static void
-draw_gs_llvm_emit_vertex(struct lp_build_tgsi_context * bld_base,
+draw_gs_llvm_emit_vertex(const struct lp_build_tgsi_gs_iface *gs_base,
+                         struct lp_build_tgsi_context * bld_base,
                          LLVMValueRef (*outputs)[4],
-                         LLVMValueRef emitted_vertices_vec,
-                         void *user_data)
+                         LLVMValueRef emitted_vertices_vec)
 {
-   struct draw_gs_llvm_variant *variant =
-      (struct draw_gs_llvm_variant *)user_data;
+   const struct draw_gs_llvm_iface *gs_iface = draw_gs_llvm_iface(gs_base);
+   struct draw_gs_llvm_variant *variant = gs_iface->variant;
    struct gallivm_state *gallivm = variant->gallivm;
    LLVMBuilderRef builder = gallivm->builder;
    struct lp_type gs_type = bld_base->base.type;
@@ -1272,13 +1308,13 @@ draw_gs_llvm_emit_vertex(struct lp_build_tgsi_context * bld_base,
 }
 
 static void
-draw_gs_llvm_end_primitive(struct lp_build_tgsi_context * bld_base,
+draw_gs_llvm_end_primitive(const struct lp_build_tgsi_gs_iface *gs_base,
+                           struct lp_build_tgsi_context * bld_base,
                            LLVMValueRef verts_per_prim_vec,
-                           LLVMValueRef emitted_prims_vec,
-                           void *user_data)
+                           LLVMValueRef emitted_prims_vec)
 {
-   struct draw_gs_llvm_variant *variant =
-      (struct draw_gs_llvm_variant *)user_data;
+   const struct draw_gs_llvm_iface *gs_iface = draw_gs_llvm_iface(gs_base);
+   struct draw_gs_llvm_variant *variant = gs_iface->variant;
    struct gallivm_state *gallivm = variant->gallivm;
    LLVMBuilderRef builder = gallivm->builder;
    LLVMValueRef prim_lengts_ptr =
@@ -1301,13 +1337,13 @@ draw_gs_llvm_end_primitive(struct lp_build_tgsi_context * bld_base,
 }
 
 static void
-draw_gs_llvm_epilogue(struct lp_build_tgsi_context * bld_base,
+draw_gs_llvm_epilogue(const struct lp_build_tgsi_gs_iface *gs_base,
+                      struct lp_build_tgsi_context * bld_base,
                       LLVMValueRef total_emitted_vertices_vec,
-                      LLVMValueRef emitted_prims_vec,
-                      void *user_data)
+                      LLVMValueRef emitted_prims_vec)
 {
-   struct draw_gs_llvm_variant *variant =
-      (struct draw_gs_llvm_variant *)user_data;
+   const struct draw_gs_llvm_iface *gs_iface = draw_gs_llvm_iface(gs_base);
+   struct draw_gs_llvm_variant *variant = gs_iface->variant;
    struct gallivm_state *gallivm = variant->gallivm;
    LLVMBuilderRef builder = gallivm->builder;
    LLVMValueRef emitted_verts_ptr =
@@ -1867,7 +1903,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
    struct lp_bld_tgsi_system_values system_values;
    struct lp_type gs_type;
    unsigned i;
-   struct lp_build_tgsi_gs_iface gs_iface;
+   struct draw_gs_llvm_iface gs_iface;
    const struct tgsi_token *tokens = variant->shader->base.state.tokens;
    LLVMValueRef consts_ptr;
    LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][TGSI_NUM_CHANNELS];
@@ -1912,11 +1948,12 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
    variant->io_ptr = io_ptr;
    variant->num_prims = num_prims;
 
+   gs_iface.base.fetch_input = draw_gs_llvm_fetch_input;
+   gs_iface.base.emit_vertex = draw_gs_llvm_emit_vertex;
+   gs_iface.base.end_primitive = draw_gs_llvm_end_primitive;
+   gs_iface.base.gs_epilogue = draw_gs_llvm_epilogue;
    gs_iface.input = input_array;
-   gs_iface.emit_vertex = draw_gs_llvm_emit_vertex;
-   gs_iface.end_primitive = draw_gs_llvm_end_primitive;
-   gs_iface.gs_epilogue = draw_gs_llvm_epilogue;
-   gs_iface.user_data = variant;
+   gs_iface.variant = variant;
 
    /*
     * Function body
@@ -1955,7 +1992,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
                      outputs,
                      sampler,
                      &llvm->draw->gs.geometry_shader->info,
-                     &gs_iface);
+                     (const struct lp_build_tgsi_gs_iface *)&gs_iface);
 
    sampler->destroy(sampler);
 
index fe4444edb1ad961f3cd09a7ec317c15aa29c0422..5764847acb5425cca2903fe209c541bf446d8080 100644 (file)
@@ -365,20 +365,23 @@ struct lp_build_tgsi_context
 
 struct lp_build_tgsi_gs_iface
 {
-   LLVMValueRef input;
-   void (*emit_vertex)(struct lp_build_tgsi_context * bld_base,
+   LLVMValueRef (*fetch_input)(const struct lp_build_tgsi_gs_iface *gs_iface,
+                               struct lp_build_tgsi_context * bld_base,
+                               LLVMValueRef vertex_index,
+                               LLVMValueRef attrib_index,
+                               LLVMValueRef swizzle_index);
+   void (*emit_vertex)(const struct lp_build_tgsi_gs_iface *gs_iface,
+                       struct lp_build_tgsi_context * bld_base,
                        LLVMValueRef (*outputs)[4],
-                       LLVMValueRef emitted_vertices_vec,
-                       void *user_data);
-   void (*end_primitive)(struct lp_build_tgsi_context * bld_base,
+                       LLVMValueRef emitted_vertices_vec);
+   void (*end_primitive)(const struct lp_build_tgsi_gs_iface *gs_iface,
+                         struct lp_build_tgsi_context * bld_base,
                          LLVMValueRef verts_per_prim_vec,
-                         LLVMValueRef emitted_prims_vec,
-                         void *user_data);
-   void (*gs_epilogue)(struct lp_build_tgsi_context * bld_base,
+                         LLVMValueRef emitted_prims_vec);
+   void (*gs_epilogue)(const struct lp_build_tgsi_gs_iface *gs_iface,
+                       struct lp_build_tgsi_context * bld_base,
                        LLVMValueRef total_emitted_vertices_vec,
-                       LLVMValueRef emitted_prims_vec,
-                       void *user_data);
-   void *user_data;
+                       LLVMValueRef emitted_prims_vec);
 };
 
 struct lp_build_tgsi_soa_context
index facfc824de201efe1b7a6510301b59ffb1077ec3..54f3fd9f8f80e0b6b49dc792eb18ef362add6a5b 100644 (file)
@@ -805,11 +805,9 @@ emit_fetch_gs_input(
    struct lp_build_tgsi_soa_context * bld = lp_soa_context(bld_base);
    struct gallivm_state *gallivm = bld->bld_base.base.gallivm;
    LLVMBuilderRef builder = gallivm->builder;
-   //struct lp_build_context *uint_bld = &bld_base->uint_bld;
    LLVMValueRef attrib_index = NULL;
    LLVMValueRef vertex_index = NULL;
    LLVMValueRef swizzle_index = lp_build_const_int32(gallivm, swizzle);
-   LLVMValueRef indices[3];
    LLVMValueRef res;
 
    if (reg->Register.Indirect) {
@@ -830,12 +828,10 @@ emit_fetch_gs_input(
       vertex_index = lp_build_const_int32(gallivm, reg->Dimension.Index);
    }
 
-   indices[0] = vertex_index;
-   indices[1] = attrib_index;
-   indices[2] = swizzle_index;
 
-   res = LLVMBuildGEP(builder, bld->gs_iface->input, indices, 3, "");
-   res = LLVMBuildLoad(builder, res, "");
+   res = bld->gs_iface->fetch_input(bld->gs_iface, bld_base,
+                                    vertex_index, attrib_index,
+                                    swizzle_index);
 
    assert(res);
 
@@ -2200,9 +2196,9 @@ emit_vertex(
    if (bld->gs_iface->emit_vertex) {
       LLVMValueRef masked_ones = mask_to_one_vec(bld_base);
       gather_outputs(bld);
-      bld->gs_iface->emit_vertex(&bld->bld_base, bld->outputs,
-                                bld->total_emitted_vertices_vec,
-                                bld->gs_iface->user_data);
+      bld->gs_iface->emit_vertex(bld->gs_iface, &bld->bld_base,
+                                 bld->outputs,
+                                 bld->total_emitted_vertices_vec);
       bld->emitted_vertices_vec =
          LLVMBuildAdd(builder, bld->emitted_vertices_vec, masked_ones, "");
       bld->total_emitted_vertices_vec =
@@ -2223,10 +2219,9 @@ end_primitive(
 
    if (bld->gs_iface->end_primitive) {
       LLVMValueRef masked_ones = mask_to_one_vec(bld_base);
-      bld->gs_iface->end_primitive(&bld->bld_base,
-                                  bld->emitted_vertices_vec,
-                                  bld->emitted_prims_vec,
-                                  bld->gs_iface->user_data);
+      bld->gs_iface->end_primitive(bld->gs_iface, &bld->bld_base,
+                                   bld->emitted_vertices_vec,
+                                   bld->emitted_prims_vec);
       bld->emitted_prims_vec =
          LLVMBuildAdd(builder, bld->emitted_prims_vec, masked_ones, "");
       bld->emitted_vertices_vec = bld_base->uint_bld.zero;
@@ -2544,10 +2539,10 @@ static void emit_epilogue(struct lp_build_tgsi_context * bld_base)
          bld->pending_end_primitive = FALSE;
       }
 
-      bld->gs_iface->gs_epilogue(&bld->bld_base,
-                                bld->total_emitted_vertices_vec,
-                                bld->emitted_prims_vec,
-                                bld->gs_iface->user_data);
+      bld->gs_iface->gs_epilogue(bld->gs_iface,
+                                 &bld->bld_base,
+                                 bld->total_emitted_vertices_vec,
+                                 bld->emitted_prims_vec);
    } else {
       gather_outputs(bld);
    }