[Mesa-dev] [PATCH 06/15] gallivm: Allow user to configure behavior of emit_fetch() -> soa

Tom Stellard tstellar at gmail.com
Fri Dec 9 14:15:58 PST 2011


 In lp_bld_tgsi_soa.c, emit_fetch() the switch statement is
 replaced by a call to to a function pointer, which has been added
 as a field of struct lp_build_tgsi_aos_context.
---
 src/gallium/auxiliary/gallivm/lp_bld_tgsi.h     |    4 ++
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c |   46 ++++++++++++++--------
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
index 2698e29..cabf907 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -303,6 +303,10 @@ struct lp_build_tgsi_soa_context
 
    struct tgsi_full_instruction *instructions;
    uint max_instructions;
+
+   LLVMValueRef (*emit_fetch_switch_file_fn)(struct lp_build_tgsi_soa_context *,
+                                         const struct tgsi_full_src_register *,
+                                         const unsigned);
 };
 
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 67592ee..3b06c87 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -532,30 +532,18 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
    return index;
 }
 
-
-/**
- * Register fetch.
- */
 static LLVMValueRef
-emit_fetch(
+emit_fetch_switch_file(
    struct lp_build_tgsi_soa_context *bld,
-   const struct tgsi_full_instruction *inst,
-   unsigned src_op,
-   const unsigned chan_index )
+   const struct tgsi_full_src_register *reg,
+   const unsigned swizzle)
+
 {
    struct gallivm_state *gallivm = bld->base.gallivm;
    LLVMBuilderRef builder = gallivm->builder;
    struct lp_build_context *uint_bld = &bld->uint_bld;
-   const struct tgsi_full_src_register *reg = &inst->Src[src_op];
-   const unsigned swizzle =
-      tgsi_util_get_full_src_register_swizzle(reg, chan_index);
-   LLVMValueRef res;
    LLVMValueRef indirect_index = NULL;
-
-   if (swizzle > 3) {
-      assert(0 && "invalid swizzle in emit_fetch()");
-      return bld->base.undef;
-   }
+   LLVMValueRef res;
 
    if (reg->Register.Indirect) {
       indirect_index = get_indirect_index(bld,
@@ -690,6 +678,29 @@ emit_fetch(
       assert(0 && "invalid src register in emit_fetch()");
       return bld->base.undef;
    }
+   return res;
+}
+/**
+ * Register fetch.
+ */
+static LLVMValueRef
+emit_fetch(
+   struct lp_build_tgsi_soa_context *bld,
+   const struct tgsi_full_instruction *inst,
+   unsigned src_op,
+   const unsigned chan_index )
+{
+   const struct tgsi_full_src_register *reg = &inst->Src[src_op];
+   const unsigned swizzle =
+      tgsi_util_get_full_src_register_swizzle(reg, chan_index);
+   LLVMValueRef res;
+
+   if (swizzle > 3) {
+      assert(0 && "invalid swizzle in emit_fetch()");
+      return bld->base.undef;
+   }
+
+   res = bld->emit_fetch_switch_file_fn(bld, reg, swizzle);
 
    if (reg->Register.Absolute) {
       res = lp_build_abs( &bld->base, res );
@@ -2282,6 +2293,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
    bld.sampler = sampler;
    bld.info = info;
    bld.indirect_files = info->indirect_files;
+   bld.emit_fetch_switch_file_fn = emit_fetch_switch_file;
    bld.instructions = (struct tgsi_full_instruction *)
                       MALLOC( LP_MAX_INSTRUCTIONS * sizeof(struct tgsi_full_instruction) );
    bld.max_instructions = LP_MAX_INSTRUCTIONS;
-- 
1.7.6.4



More information about the mesa-dev mailing list