[Mesa-dev] [PATCH 4/5] gallivm: enable fetch for integer opcodes.

Jose Fonseca jfonseca at vmware.com
Mon Feb 6 11:43:04 PST 2012



----- Original Message -----
> From: Dave Airlie <airlied at redhat.com>
> 
> The infers the type of data required using the opcode,
> and casts the input to the appropriate type.
> 
> So far this only handles non-indirect constant and temporaries.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/gallium/auxiliary/gallivm/lp_bld_tgsi.c     |    4 +-
>  src/gallium/auxiliary/gallivm/lp_bld_tgsi.h     |    3 +-
>  src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c |    4 ++
>  src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c |   47
>  +++++++++++++++++++++--
>  4 files changed, 52 insertions(+), 6 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c
> b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c
> index 261301c..7b701f1 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c
> @@ -38,6 +38,7 @@
>  #include "tgsi/tgsi_parse.h"
>  #include "tgsi/tgsi_util.h"
>  #include "util/u_memory.h"
> +#include "util/u_format.h"
>  
>  /* The user is responsible for freeing list->instructions */
>  unsigned lp_bld_tgsi_list_init(struct lp_build_tgsi_context *
>  bld_base)
> @@ -298,6 +299,7 @@ lp_build_emit_fetch(
>     const struct tgsi_full_src_register *reg = &inst->Src[src_op];
>     unsigned swizzle;
>     LLVMValueRef res;
> +   enum util_format_type stype =
> tgsi_opcode_infer_src_type(inst->Instruction.Opcode);
>  
>     if (chan_index == LP_CHAN_ALL) {
>        swizzle = ~0;
> @@ -312,7 +314,7 @@ lp_build_emit_fetch(
>     assert(reg->Register.Index <=
>     bld_base->info->file_max[reg->Register.File]);
>  
>     if (bld_base->emit_fetch_funcs[reg->Register.File]) {
> -      res = bld_base->emit_fetch_funcs[reg->Register.File](bld_base,
> reg,
> +      res = bld_base->emit_fetch_funcs[reg->Register.File](bld_base,
> reg, stype,
>                                                             swizzle);
>     } else {
>        assert(0 && "invalid src register in emit_fetch()");
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> index a320d94..c620910 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
> @@ -273,7 +273,8 @@ struct lp_build_tgsi_context;
>  
>  typedef LLVMValueRef (*lp_build_emit_fetch_fn)(struct
>  lp_build_tgsi_context *,
>                                          const struct
>                                          tgsi_full_src_register *,
> -                                        unsigned);
> +                                        const unsigned,
> +                                        const unsigned);
>  
>  struct lp_build_tgsi_context
>  {
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
> b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
> index 0f98fa8..5e929b3 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
> @@ -101,6 +101,7 @@ static LLVMValueRef
>  emit_fetch_constant(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,

Please remove const keyword from scalar arguments, and use the appropriate enum type, so that gdb can use show symbolic names.

Otherwise looks good.

Jose

>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_aos_context * bld =
>     lp_aos_context(bld_base);
> @@ -171,6 +172,7 @@ static LLVMValueRef
>  emit_fetch_immediate(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_aos_context * bld =
>     lp_aos_context(bld_base);
> @@ -183,6 +185,7 @@ static LLVMValueRef
>  emit_fetch_input(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_aos_context * bld =
>     lp_aos_context(bld_base);
> @@ -196,6 +199,7 @@ static LLVMValueRef
>  emit_fetch_temporary(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_aos_context * bld =
>     lp_aos_context(bld_base);
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> index 45b0980..17c5d83 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> @@ -519,10 +519,31 @@ get_indirect_index(struct
> lp_build_tgsi_soa_context *bld,
>     return index;
>  }
>  
> +static struct lp_build_context *
> +stype_to_fetch(struct lp_build_tgsi_context * bld_base, const
> unsigned stype)
> +{
> +   struct lp_build_context *bld_fetch;
> +
> +   switch (stype) {
> +   case UTIL_FORMAT_TYPE_FLOAT:
> +   case UTIL_FORMAT_TYPE_VOID:
> +      bld_fetch = &bld_base->base;
> +      break;
> +   case UTIL_FORMAT_TYPE_UNSIGNED:
> +      bld_fetch = &bld_base->uintbld;
> +      break;
> +   case UTIL_FORMAT_TYPE_SIGNED:
> +      bld_fetch = &bld_base->intbld;
> +      break;
> +   }
> +   return bld_fetch;
> +}
> +
>  static LLVMValueRef
>  emit_fetch_constant(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_soa_context * bld =
>     lp_soa_context(bld_base);
> @@ -530,7 +551,8 @@ emit_fetch_constant(
>     LLVMBuilderRef builder = gallivm->builder;
>     struct lp_build_context *uint_bld = &bld->uint_bld;
>     LLVMValueRef indirect_index = NULL;
> -
> +   struct lp_build_context *fetch_bld = stype_to_fetch(bld_base,
> stype);
> +
>     /* XXX: Handle fetching xyzw components as a vector */
>     assert(swizzle != ~0);
>  
> @@ -561,9 +583,16 @@ emit_fetch_constant(
>  
>        scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr,
>                                     &index, 1, "");
> -      scalar = LLVMBuildLoad(builder, scalar_ptr, "");
>  
> -      return lp_build_broadcast_scalar(&bld->bld_base.base, scalar);
> +      if (stype != UTIL_FORMAT_TYPE_FLOAT && stype !=
> UTIL_FORMAT_TYPE_VOID) {
> +         LLVMTypeRef ivtype =
> LLVMPointerType(LLVMInt32TypeInContext(gallivm->context), 0);
> +         LLVMValueRef temp_ptr;
> +         temp_ptr = LLVMBuildBitCast(builder, scalar_ptr, ivtype,
> "");
> +         scalar = LLVMBuildLoad(builder, temp_ptr, "");
> +      } else
> +         scalar = LLVMBuildLoad(builder, scalar_ptr, "");
> +
> +      return lp_build_broadcast_scalar(fetch_bld, scalar);
>     }
>  }
>  
> @@ -571,6 +600,7 @@ static LLVMValueRef
>  emit_fetch_immediate(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_soa_context * bld =
>     lp_soa_context(bld_base);
> @@ -583,6 +613,7 @@ static LLVMValueRef
>  emit_fetch_input(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_soa_context * bld =
>     lp_soa_context(bld_base);
> @@ -640,6 +671,7 @@ static LLVMValueRef
>  emit_fetch_temporary(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_soa_context * bld =
>     lp_soa_context(bld_base);
> @@ -681,7 +713,13 @@ emit_fetch_temporary(
>     }
>     else {
>        LLVMValueRef temp_ptr;
> -      temp_ptr = lp_get_temp_ptr_soa(bld, reg->Register.Index,
> swizzle);
> +      if (stype != UTIL_FORMAT_TYPE_FLOAT && stype !=
> UTIL_FORMAT_TYPE_VOID) {
> +         LLVMTypeRef itype =
> LLVMPointerType(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context),
> 4), 0);
> +         LLVMValueRef tint_ptr = lp_get_temp_ptr_soa(bld,
> reg->Register.Index,
> +                                                     swizzle);
> +         temp_ptr = LLVMBuildBitCast(builder, tint_ptr, itype, "");
> +      } else
> +         temp_ptr = lp_get_temp_ptr_soa(bld, reg->Register.Index,
> swizzle);
>        res = LLVMBuildLoad(builder, temp_ptr, "");
>        if (!res)
>           return bld->bld_base.base.undef;
> @@ -694,6 +732,7 @@ static LLVMValueRef
>  emit_fetch_system_value(
>     struct lp_build_tgsi_context * bld_base,
>     const struct tgsi_full_src_register * reg,
> +   const unsigned stype,
>     const unsigned swizzle)
>  {
>     struct lp_build_tgsi_soa_context * bld =
>     lp_soa_context(bld_base);
> --
> 1.7.7.6
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 


More information about the mesa-dev mailing list