Re: [Mesa-dev] [PATCH v4 120/129] ac/nir: Remove deref chain support.

2018-06-01 Thread Jason Ekstrand
On Fri, Jun 1, 2018 at 3:57 AM, Bas Nieuwenhuizen 
wrote:

> On Fri, Jun 1, 2018 at 7:07 AM, Jason Ekstrand 
> wrote:
> > From: Bas Nieuwenhuizen 
> >
> > ---
> >  src/amd/common/ac_nir_to_llvm.c | 404 +-
> --
> >  1 file changed, 50 insertions(+), 354 deletions(-)
> >
> > diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_
> llvm.c
> > index 60ac8c4..38d6b31 100644
> > --- a/src/amd/common/ac_nir_to_llvm.c
> > +++ b/src/amd/common/ac_nir_to_llvm.c
> > @@ -54,7 +54,6 @@ struct ac_nir_context {
> >  };
> >
> >  static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
> > -const nir_deref_var *deref,
> >  nir_deref_instr *deref_instr,
> >  enum ac_descriptor_type desc_type,
> >  const nir_tex_instr *instr,
> > @@ -1323,7 +1322,7 @@ static LLVMValueRef build_tex_intrinsic(struct
> ac_nir_context *ctx,
> >
> > if (instr->op == nir_texop_tg4 && ctx->ac.chip_class <= VI) {
> > nir_deref_instr *texture_deref_instr =
> get_tex_texture_deref(instr);
> > -   nir_variable *var = texture_deref_instr ?
> nir_deref_instr_get_variable(texture_deref_instr) : instr->texture->var;
> > +   nir_variable *var = nir_deref_instr_get_variable(
> texture_deref_instr);
> > enum glsl_base_type stype = glsl_get_sampler_result_type(
> var->type);
> > if (stype == GLSL_TYPE_UINT || stype == GLSL_TYPE_INT) {
> > return lower_gather4_integer(>ac, var,
> args, instr);
> > @@ -1629,10 +1628,10 @@ static LLVMValueRef visit_load_ubo_buffer(struct
> ac_nir_context *ctx,
> >  }
> >
> >  static void
> > -get_deref_instr_offset(struct ac_nir_context *ctx, nir_deref_instr
> *instr,
> > -  bool vs_in, unsigned *vertex_index_out,
> > -  LLVMValueRef *vertex_index_ref,
> > -  unsigned *const_out, LLVMValueRef *indir_out)
> > +get_deref_offset(struct ac_nir_context *ctx, nir_deref_instr *instr,
> > + bool vs_in, unsigned *vertex_index_out,
> > + LLVMValueRef *vertex_index_ref,
> > + unsigned *const_out, LLVMValueRef *indir_out)
> >  {
> > nir_variable *var = nir_deref_instr_get_variable(instr);
> > nir_deref_path path;
> > @@ -1697,124 +1696,6 @@ out:
> > *indir_out = offset;
> >  }
> >
> > -static void
> > -get_deref_offset(struct ac_nir_context *ctx, nir_deref_var *deref,
> > -bool vs_in, unsigned *vertex_index_out,
> > -LLVMValueRef *vertex_index_ref,
> > -unsigned *const_out, LLVMValueRef *indir_out)
> > -{
> > -   unsigned const_offset = 0;
> > -   nir_deref *tail = >deref;
> > -   LLVMValueRef offset = NULL;
> > -
> > -   if (vertex_index_out != NULL || vertex_index_ref != NULL) {
> > -   tail = tail->child;
> > -   nir_deref_array *deref_array = nir_deref_as_array(tail);
> > -   if (vertex_index_out)
> > -   *vertex_index_out = deref_array->base_offset;
> > -
> > -   if (vertex_index_ref) {
> > -   LLVMValueRef vtx = LLVMConstInt(ctx->ac.i32,
> deref_array->base_offset, false);
> > -   if (deref_array->deref_array_type ==
> nir_deref_array_type_indirect) {
> > -   vtx = LLVMBuildAdd(ctx->ac.builder, vtx,
> get_src(ctx, deref_array->indirect), "");
> > -   }
> > -   *vertex_index_ref = vtx;
> > -   }
> > -   }
> > -
> > -   if (deref->var->data.compact) {
> > -   assert(tail->child->deref_type == nir_deref_type_array);
> > -   assert(glsl_type_is_scalar(
> glsl_without_array(deref->var->type)));
> > -   nir_deref_array *deref_array = nir_deref_as_array(tail->
> child);
> > -   /* We always lower indirect dereferences for "compact"
> array vars. */
> > -   assert(deref_array->deref_array_type ==
> nir_deref_array_type_direct);
> > -
> > -   const_offset = deref_array->base_offset;
> > -   goto out;
> > -   }
> > -
> > -   while (tail->child != NULL) {
> > -   const struct glsl_type *parent_type = tail->type;
> > -   tail = tail->child;
> > -
> > -   if (tail->deref_type == nir_deref_type_array) {
> > -   nir_deref_array *deref_array =
> nir_deref_as_array(tail);
> > -   LLVMValueRef index, stride, local_offset;
> > -   unsigned size = 
> > glsl_count_attribute_slots(tail->type,
> vs_in);
> > -
> > -   const_offset += size * deref_array->base_offset;
> > -   if (deref_array->deref_array_type ==
> nir_deref_array_type_direct)
> > - 

Re: [Mesa-dev] [PATCH v4 120/129] ac/nir: Remove deref chain support.

2018-06-01 Thread Bas Nieuwenhuizen
On Fri, Jun 1, 2018 at 7:07 AM, Jason Ekstrand  wrote:
> From: Bas Nieuwenhuizen 
>
> ---
>  src/amd/common/ac_nir_to_llvm.c | 404 
> +---
>  1 file changed, 50 insertions(+), 354 deletions(-)
>
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index 60ac8c4..38d6b31 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -54,7 +54,6 @@ struct ac_nir_context {
>  };
>
>  static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
> -const nir_deref_var *deref,
>  nir_deref_instr *deref_instr,
>  enum ac_descriptor_type desc_type,
>  const nir_tex_instr *instr,
> @@ -1323,7 +1322,7 @@ static LLVMValueRef build_tex_intrinsic(struct 
> ac_nir_context *ctx,
>
> if (instr->op == nir_texop_tg4 && ctx->ac.chip_class <= VI) {
> nir_deref_instr *texture_deref_instr = 
> get_tex_texture_deref(instr);
> -   nir_variable *var = texture_deref_instr ? 
> nir_deref_instr_get_variable(texture_deref_instr) : instr->texture->var;
> +   nir_variable *var = 
> nir_deref_instr_get_variable(texture_deref_instr);
> enum glsl_base_type stype = 
> glsl_get_sampler_result_type(var->type);
> if (stype == GLSL_TYPE_UINT || stype == GLSL_TYPE_INT) {
> return lower_gather4_integer(>ac, var, args, 
> instr);
> @@ -1629,10 +1628,10 @@ static LLVMValueRef visit_load_ubo_buffer(struct 
> ac_nir_context *ctx,
>  }
>
>  static void
> -get_deref_instr_offset(struct ac_nir_context *ctx, nir_deref_instr *instr,
> -  bool vs_in, unsigned *vertex_index_out,
> -  LLVMValueRef *vertex_index_ref,
> -  unsigned *const_out, LLVMValueRef *indir_out)
> +get_deref_offset(struct ac_nir_context *ctx, nir_deref_instr *instr,
> + bool vs_in, unsigned *vertex_index_out,
> + LLVMValueRef *vertex_index_ref,
> + unsigned *const_out, LLVMValueRef *indir_out)
>  {
> nir_variable *var = nir_deref_instr_get_variable(instr);
> nir_deref_path path;
> @@ -1697,124 +1696,6 @@ out:
> *indir_out = offset;
>  }
>
> -static void
> -get_deref_offset(struct ac_nir_context *ctx, nir_deref_var *deref,
> -bool vs_in, unsigned *vertex_index_out,
> -LLVMValueRef *vertex_index_ref,
> -unsigned *const_out, LLVMValueRef *indir_out)
> -{
> -   unsigned const_offset = 0;
> -   nir_deref *tail = >deref;
> -   LLVMValueRef offset = NULL;
> -
> -   if (vertex_index_out != NULL || vertex_index_ref != NULL) {
> -   tail = tail->child;
> -   nir_deref_array *deref_array = nir_deref_as_array(tail);
> -   if (vertex_index_out)
> -   *vertex_index_out = deref_array->base_offset;
> -
> -   if (vertex_index_ref) {
> -   LLVMValueRef vtx = LLVMConstInt(ctx->ac.i32, 
> deref_array->base_offset, false);
> -   if (deref_array->deref_array_type == 
> nir_deref_array_type_indirect) {
> -   vtx = LLVMBuildAdd(ctx->ac.builder, vtx, 
> get_src(ctx, deref_array->indirect), "");
> -   }
> -   *vertex_index_ref = vtx;
> -   }
> -   }
> -
> -   if (deref->var->data.compact) {
> -   assert(tail->child->deref_type == nir_deref_type_array);
> -   
> assert(glsl_type_is_scalar(glsl_without_array(deref->var->type)));
> -   nir_deref_array *deref_array = 
> nir_deref_as_array(tail->child);
> -   /* We always lower indirect dereferences for "compact" array 
> vars. */
> -   assert(deref_array->deref_array_type == 
> nir_deref_array_type_direct);
> -
> -   const_offset = deref_array->base_offset;
> -   goto out;
> -   }
> -
> -   while (tail->child != NULL) {
> -   const struct glsl_type *parent_type = tail->type;
> -   tail = tail->child;
> -
> -   if (tail->deref_type == nir_deref_type_array) {
> -   nir_deref_array *deref_array = 
> nir_deref_as_array(tail);
> -   LLVMValueRef index, stride, local_offset;
> -   unsigned size = 
> glsl_count_attribute_slots(tail->type, vs_in);
> -
> -   const_offset += size * deref_array->base_offset;
> -   if (deref_array->deref_array_type == 
> nir_deref_array_type_direct)
> -   continue;
> -
> -   assert(deref_array->deref_array_type == 
> nir_deref_array_type_indirect);
> -   index = get_src(ctx, deref_array->indirect);
> -   

[Mesa-dev] [PATCH v4 120/129] ac/nir: Remove deref chain support.

2018-05-31 Thread Jason Ekstrand
From: Bas Nieuwenhuizen 

---
 src/amd/common/ac_nir_to_llvm.c | 404 +---
 1 file changed, 50 insertions(+), 354 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 60ac8c4..38d6b31 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -54,7 +54,6 @@ struct ac_nir_context {
 };
 
 static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
-const nir_deref_var *deref,
 nir_deref_instr *deref_instr,
 enum ac_descriptor_type desc_type,
 const nir_tex_instr *instr,
@@ -1323,7 +1322,7 @@ static LLVMValueRef build_tex_intrinsic(struct 
ac_nir_context *ctx,
 
if (instr->op == nir_texop_tg4 && ctx->ac.chip_class <= VI) {
nir_deref_instr *texture_deref_instr = 
get_tex_texture_deref(instr);
-   nir_variable *var = texture_deref_instr ? 
nir_deref_instr_get_variable(texture_deref_instr) : instr->texture->var;
+   nir_variable *var = 
nir_deref_instr_get_variable(texture_deref_instr);
enum glsl_base_type stype = 
glsl_get_sampler_result_type(var->type);
if (stype == GLSL_TYPE_UINT || stype == GLSL_TYPE_INT) {
return lower_gather4_integer(>ac, var, args, 
instr);
@@ -1629,10 +1628,10 @@ static LLVMValueRef visit_load_ubo_buffer(struct 
ac_nir_context *ctx,
 }
 
 static void
-get_deref_instr_offset(struct ac_nir_context *ctx, nir_deref_instr *instr,
-  bool vs_in, unsigned *vertex_index_out,
-  LLVMValueRef *vertex_index_ref,
-  unsigned *const_out, LLVMValueRef *indir_out)
+get_deref_offset(struct ac_nir_context *ctx, nir_deref_instr *instr,
+ bool vs_in, unsigned *vertex_index_out,
+ LLVMValueRef *vertex_index_ref,
+ unsigned *const_out, LLVMValueRef *indir_out)
 {
nir_variable *var = nir_deref_instr_get_variable(instr);
nir_deref_path path;
@@ -1697,124 +1696,6 @@ out:
*indir_out = offset;
 }
 
-static void
-get_deref_offset(struct ac_nir_context *ctx, nir_deref_var *deref,
-bool vs_in, unsigned *vertex_index_out,
-LLVMValueRef *vertex_index_ref,
-unsigned *const_out, LLVMValueRef *indir_out)
-{
-   unsigned const_offset = 0;
-   nir_deref *tail = >deref;
-   LLVMValueRef offset = NULL;
-
-   if (vertex_index_out != NULL || vertex_index_ref != NULL) {
-   tail = tail->child;
-   nir_deref_array *deref_array = nir_deref_as_array(tail);
-   if (vertex_index_out)
-   *vertex_index_out = deref_array->base_offset;
-
-   if (vertex_index_ref) {
-   LLVMValueRef vtx = LLVMConstInt(ctx->ac.i32, 
deref_array->base_offset, false);
-   if (deref_array->deref_array_type == 
nir_deref_array_type_indirect) {
-   vtx = LLVMBuildAdd(ctx->ac.builder, vtx, 
get_src(ctx, deref_array->indirect), "");
-   }
-   *vertex_index_ref = vtx;
-   }
-   }
-
-   if (deref->var->data.compact) {
-   assert(tail->child->deref_type == nir_deref_type_array);
-   
assert(glsl_type_is_scalar(glsl_without_array(deref->var->type)));
-   nir_deref_array *deref_array = nir_deref_as_array(tail->child);
-   /* We always lower indirect dereferences for "compact" array 
vars. */
-   assert(deref_array->deref_array_type == 
nir_deref_array_type_direct);
-
-   const_offset = deref_array->base_offset;
-   goto out;
-   }
-
-   while (tail->child != NULL) {
-   const struct glsl_type *parent_type = tail->type;
-   tail = tail->child;
-
-   if (tail->deref_type == nir_deref_type_array) {
-   nir_deref_array *deref_array = nir_deref_as_array(tail);
-   LLVMValueRef index, stride, local_offset;
-   unsigned size = glsl_count_attribute_slots(tail->type, 
vs_in);
-
-   const_offset += size * deref_array->base_offset;
-   if (deref_array->deref_array_type == 
nir_deref_array_type_direct)
-   continue;
-
-   assert(deref_array->deref_array_type == 
nir_deref_array_type_indirect);
-   index = get_src(ctx, deref_array->indirect);
-   stride = LLVMConstInt(ctx->ac.i32, size, 0);
-   local_offset = LLVMBuildMul(ctx->ac.builder, stride, 
index, "");
-
-   if (offset)
-   offset = LLVMBuildAdd(ctx->ac.builder, offset, 
local_offset, "");
-