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

Jason Ekstrand jason at jlekstrand.net
Fri Jun 1 16:24:52 UTC 2018


On Fri, Jun 1, 2018 at 3:57 AM, Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
wrote:

> On Fri, Jun 1, 2018 at 7:07 AM, Jason Ekstrand <jason at jlekstrand.net>
> wrote:
> > From: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
> >
> > ---
> >  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(&ctx->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->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, "");
> > -                       else
> > -                               offset = local_offset;
> > -               } else if (tail->deref_type == nir_deref_type_struct) {
> > -                       nir_deref_struct *deref_struct =
> nir_deref_as_struct(tail);
> > -
> > -                       for (unsigned i = 0; i < deref_struct->index;
> i++) {
> > -                               const struct glsl_type *ft =
> glsl_get_struct_field(parent_type, i);
> > -                               const_offset +=
> glsl_count_attribute_slots(ft, vs_in);
> > -                       }
> > -               } else
> > -                       unreachable("unsupported deref type");
> > -
> > -       }
> > -out:
> > -       if (const_offset && offset)
> > -               offset = LLVMBuildAdd(ctx->ac.builder, offset,
> > -                                     LLVMConstInt(ctx->ac.i32,
> const_offset, 0),
> > -                                     "");
> > -
> > -       *const_out = const_offset;
> > -       *indir_out = offset;
> > -}
> > -
> > -static LLVMValueRef
> > -build_gep_for_deref(struct ac_nir_context *ctx,
> > -                   nir_deref_var *deref)
> > -{
> > -       struct hash_entry *entry = _mesa_hash_table_search(ctx->vars,
> deref->var);
> > -       assert(entry->data);
> > -       LLVMValueRef val = entry->data;
> > -       nir_deref *tail = deref->deref.child;
> > -       while (tail != NULL) {
> > -               LLVMValueRef offset;
> > -               switch (tail->deref_type) {
> > -               case nir_deref_type_array: {
> > -                       nir_deref_array *array =
> nir_deref_as_array(tail);
> > -                       offset = LLVMConstInt(ctx->ac.i32,
> array->base_offset, 0);
> > -                       if (array->deref_array_type ==
> > -                           nir_deref_array_type_indirect) {
> > -                               offset = LLVMBuildAdd(ctx->ac.builder,
> offset,
> > -                                                     get_src(ctx,
> > -
>  array->indirect),
> > -                                                     "");
> > -                       }
> > -                       break;
> > -               }
> > -               case nir_deref_type_struct: {
> > -                       nir_deref_struct *deref_struct =
> > -                               nir_deref_as_struct(tail);
> > -                       offset = LLVMConstInt(ctx->ac.i32,
> > -                                             deref_struct->index, 0);
> > -                       break;
> > -               }
> > -               default:
> > -                       unreachable("bad deref type");
> > -               }
> > -               val = ac_build_gep0(&ctx->ac, val, offset);
> > -               tail = tail->child;
> > -       }
> > -       return val;
> > -}
> > -
> >  static LLVMValueRef load_tess_varyings(struct ac_nir_context *ctx,
> >                                        nir_intrinsic_instr *instr,
> >                                        bool load_inputs)
> > @@ -1824,24 +1705,16 @@ static LLVMValueRef load_tess_varyings(struct
> ac_nir_context *ctx,
> >         LLVMValueRef indir_index = NULL;
> >         unsigned const_index = 0;
> >
> > -       bool uses_deref_chain = instr->intrinsic ==
> nir_intrinsic_load_var;
> > -       nir_variable *var = uses_deref_chain ? instr->variables[0]->var :
> > -                            nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> > +       nir_variable *var = nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> >
> >         unsigned location = var->data.location;
> >         unsigned driver_location = var->data.driver_location;
> >         const bool is_patch =  var->data.patch;
> >         const bool is_compact = var->data.compact;
> >
> > -       if (uses_deref_chain) {
> > -               get_deref_offset(ctx, instr->variables[0],
> > -                                false, NULL, is_patch ? NULL :
> &vertex_index,
> > -                                &const_index, &indir_index);
> > -       } else {
> > -               get_deref_instr_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> > -                                      false, NULL, is_patch ? NULL :
> &vertex_index,
> > -                                      &const_index, &indir_index);
> > -       }
> > +       get_deref_offset(ctx, nir_instr_as_deref(instr->src[
> 0].ssa->parent_instr),
> > +                        false, NULL, is_patch ? NULL : &vertex_index,
> > +                        &const_index, &indir_index);
> >
> >         LLVMTypeRef dest_type = get_def_type(ctx, &instr->dest.ssa);
> >
> > @@ -1863,9 +1736,7 @@ static LLVMValueRef load_tess_varyings(struct
> ac_nir_context *ctx,
> >  static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
> >                                    nir_intrinsic_instr *instr)
> >  {
> > -       bool uses_deref_chain = instr->intrinsic ==
> nir_intrinsic_load_var;
> > -       nir_variable *var = uses_deref_chain ? instr->variables[0]->var :
> > -                           nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> > +       nir_variable *var = nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> >
> >         LLVMValueRef values[8];
> >         int idx = var->data.driver_location;
> > @@ -1878,13 +1749,8 @@ static LLVMValueRef visit_load_var(struct
> ac_nir_context *ctx,
> >         bool vs_in = ctx->stage == MESA_SHADER_VERTEX &&
> >                      var->data.mode == nir_var_shader_in;
> >
> > -       if (uses_deref_chain) {
> > -               get_deref_offset(ctx, instr->variables[0], vs_in, NULL,
> NULL,
> > -                                &const_index, &indir_index);
> > -       } else {
> > -               get_deref_instr_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr), vs_in, NULL, NULL,
> > -                                      &const_index, &indir_index);
> > -       }
> > +       get_deref_offset(ctx, nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> vs_in, NULL, NULL,
> > +                        &const_index, &indir_index);
> >
> >         if (instr->dest.ssa.bit_size == 64)
> >                 ve *= 2;
> > @@ -1900,14 +1766,8 @@ static LLVMValueRef visit_load_var(struct
> ac_nir_context *ctx,
> >                         LLVMTypeRef type = LLVMIntTypeInContext(ctx->ac.context,
> instr->dest.ssa.bit_size);
> >                         LLVMValueRef indir_index;
> >                         unsigned const_index, vertex_index;
> > -                       if (uses_deref_chain) {
> > -                               get_deref_offset(ctx,
> instr->variables[0],
> > -                                                false, &vertex_index,
> NULL,
> > -                                                &const_index,
> &indir_index);
> > -                       } else {
> > -                               get_deref_instr_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> > -                                                      false,
> &vertex_index, NULL, &const_index, &indir_index);
> > -                       }
> > +                       get_deref_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> > +                                        false, &vertex_index, NULL,
> &const_index, &indir_index);
> >
> >                         return ctx->abi->load_inputs(ctx->abi,
> var->data.location,
> >
> var->data.driver_location,
> > @@ -1951,9 +1811,7 @@ static LLVMValueRef visit_load_var(struct
> ac_nir_context *ctx,
> >                 }
> >                 break;
> >         case nir_var_shared: {
> > -               LLVMValueRef address = uses_deref_chain ?
> > -                                          build_gep_for_deref(ctx,
> instr->variables[0])
> > -                                        : get_src(ctx, instr->src[0]);
> > +               LLVMValueRef address = get_src(ctx, instr->src[0]);
> >                 LLVMValueRef val = LLVMBuildLoad(ctx->ac.builder,
> address, "");
> >                 return LLVMBuildBitCast(ctx->ac.builder, val,
> >                                         get_def_type(ctx,
> &instr->dest.ssa),
> > @@ -1994,25 +1852,18 @@ static void
> >  visit_store_var(struct ac_nir_context *ctx,
> >                 nir_intrinsic_instr *instr)
> >  {
> > -        bool uses_deref_chain = instr->intrinsic ==
> nir_intrinsic_store_var;
> > -        nir_variable *var = uses_deref_chain ? instr->variables[0]->var
> :
> > -                            nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> > +        nir_variable *var = nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> >
> >         LLVMValueRef temp_ptr, value;
> >         int idx = var->data.driver_location;
> >         unsigned comp = var->data.location_frac;
> > -       LLVMValueRef src = ac_to_float(&ctx->ac, get_src(ctx,
> instr->src[uses_deref_chain ? 0 : 1]));
> > +       LLVMValueRef src = ac_to_float(&ctx->ac, get_src(ctx,
> instr->src[1]));
> >         int writemask = instr->const_index[0];
> >         LLVMValueRef indir_index;
> >         unsigned const_index;
> >
> > -       if (uses_deref_chain) {
> > -               get_deref_offset(ctx, instr->variables[0], false,
> > -                                NULL, NULL, &const_index, &indir_index);
> > -       } else {
> > -               get_deref_instr_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr), false,
> > -                                      NULL, NULL, &const_index,
> &indir_index);
> > -       }
> > +       get_deref_offset(ctx, nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> false,
> > +                        NULL, NULL, &const_index, &indir_index);
> >
> >         if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src)) == 64) {
> >
> > @@ -2034,15 +1885,9 @@ visit_store_var(struct ac_nir_context *ctx,
> >                         unsigned const_index = 0;
> >                         const bool is_patch = var->data.patch;
> >
> > -                       if (uses_deref_chain) {
> > -                               get_deref_offset(ctx,
> instr->variables[0],
> > -                                                false, NULL, is_patch ?
> NULL : &vertex_index,
> > -                                                &const_index,
> &indir_index);
> > -                       } else {
> > -                               get_deref_instr_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> > -                                                false, NULL, is_patch ?
> NULL : &vertex_index,
> > -                                                &const_index,
> &indir_index);
> > -                       }
> > +                       get_deref_offset(ctx,
> nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> > +                                        false, NULL, is_patch ? NULL :
> &vertex_index,
> > +                                        &const_index, &indir_index);
> >
> >                         ctx->abi->store_tcs_outputs(ctx->abi, var,
> >                                                     vertex_index,
> indir_index,
> > @@ -2106,10 +1951,8 @@ visit_store_var(struct ac_nir_context *ctx,
> >                 break;
> >         case nir_var_shared: {
> >                 int writemask = instr->const_index[0];
> > -               LLVMValueRef address = uses_deref_chain ?
> > -                                            build_gep_for_deref(ctx,
> instr->variables[0])
> > -                                          : get_src(ctx, instr->src[0]);
> > -               LLVMValueRef val = get_src(ctx,
> instr->src[uses_deref_chain ? 0 : 1]);
> > +               LLVMValueRef address = get_src(ctx, instr->src[0]);
> > +               LLVMValueRef val = get_src(ctx, instr->src[1]);
> >                 if (util_is_power_of_two_nonzero(writemask)) {
> >                         val = LLVMBuildBitCast(
> >                            ctx->ac.builder, val,
> > @@ -2236,32 +2079,8 @@ static LLVMValueRef adjust_sample_index_using_fmask(struct
> ac_llvm_context *ctx,
> >         return sample_index;
> >  }
> >
> > -static bool is_var_image_intrinsic(const nir_intrinsic_instr *instr)
> > -{
> > -       switch(instr->intrinsic) {
> > -       case nir_intrinsic_image_var_samples:
> > -       case nir_intrinsic_image_var_load:
> > -       case nir_intrinsic_image_var_store:
> > -       case nir_intrinsic_image_var_atomic_add:
> > -       case nir_intrinsic_image_var_atomic_min:
> > -       case nir_intrinsic_image_var_atomic_max:
> > -       case nir_intrinsic_image_var_atomic_and:
> > -       case nir_intrinsic_image_var_atomic_or:
> > -       case nir_intrinsic_image_var_atomic_xor:
> > -       case nir_intrinsic_image_var_atomic_exchange:
> > -       case nir_intrinsic_image_var_atomic_comp_swap:
> > -       case nir_intrinsic_image_var_size:
> > -               return true;
> > -       default:
> > -               return false;
> > -       }
> > -}
> > -
> >  static nir_variable *get_image_variable(const nir_intrinsic_instr
> *instr)
> >  {
> > -       if (is_var_image_intrinsic(instr))
> > -               return instr->variables[0]->var;
> > -
> >         assert(instr->src[0].is_ssa);
> >         return nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> >  }
> > @@ -2271,26 +2090,21 @@ static LLVMValueRef get_image_descriptor(struct
> ac_nir_context *ctx,
> >                                           enum ac_descriptor_type
> desc_type,
> >                                           bool write)
> >  {
> > -       if (is_var_image_intrinsic(instr))
> > -               return get_sampler_desc(ctx, instr->variables[0], NULL,
> desc_type, NULL, true, true);
> > -
> > -       return get_sampler_desc(ctx, NULL, nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> desc_type, NULL, true, true);
> > +       return get_sampler_desc(ctx, nir_instr_as_deref(instr->src[0].ssa->parent_instr),
> desc_type, NULL, true, true);
> >  }
> >
> >  static void get_image_coords(struct ac_nir_context *ctx,
> >                              const nir_intrinsic_instr *instr,
> >                              struct ac_image_args *args)
> >  {
> > -       /* As the deref instrinsics have the deref as src 0, everything
> is shifted. */
> > -       int src_shift = is_var_image_intrinsic(instr) ? 0 : 1;
> >         const struct glsl_type *type = glsl_without_array(get_image_
> variable(instr)->type);
> >
> > -       LLVMValueRef src0 = get_src(ctx, instr->src[src_shift]);
> > +       LLVMValueRef src0 = get_src(ctx, instr->src[1]);
> >         LLVMValueRef masks[] = {
> >                 LLVMConstInt(ctx->ac.i32, 0, false),
> LLVMConstInt(ctx->ac.i32, 1, false),
> >                 LLVMConstInt(ctx->ac.i32, 2, false),
> LLVMConstInt(ctx->ac.i32, 3, false),
> >         };
> > -       LLVMValueRef sample_index = ac_llvm_extract_elem(&ctx->ac,
> get_src(ctx, instr->src[src_shift + 1]), 0);
> > +       LLVMValueRef sample_index = ac_llvm_extract_elem(&ctx->ac,
> get_src(ctx, instr->src[2]), 0);
> >
> >         int count;
> >         enum glsl_sampler_dim dim = glsl_get_sampler_dim(type);
> > @@ -2328,7 +2142,7 @@ static void get_image_coords(struct ac_nir_context
> *ctx,
> >
> get_image_descriptor(ctx, instr, AC_DESC_FMASK, false));
> >         }
> >         if (count == 1 && !gfx9_1d) {
> > -               if (instr->src[src_shift].ssa->num_components)
> > +               if (instr->src[1].ssa->num_components)
> >                         args->coords[0] = LLVMBuildExtractElement(ctx->ac.builder,
> src0, masks[0], "");
> >                 else
> >                         args->coords[0] = src0;
> > @@ -2398,15 +2212,12 @@ static LLVMValueRef visit_image_load(struct
> ac_nir_context *ctx,
> >
> >         const enum glsl_sampler_dim dim = glsl_get_sampler_dim(type);
> >         if (dim == GLSL_SAMPLER_DIM_BUF) {
> > -               /* As the deref instrinsics have the deref as src 0,
> everything is shifted. */
> > -               int src_shift = is_var_image_intrinsic(instr) ? 0 : 1;
> > -
> >                 unsigned mask = nir_ssa_def_components_read(&
> instr->dest.ssa);
> >                 unsigned num_channels = util_last_bit(mask);
> >                 LLVMValueRef rsrc, vindex;
> >
> >                 rsrc = get_image_buffer_descriptor(ctx, instr, false);
> > -               vindex = LLVMBuildExtractElement(ctx->ac.builder,
> get_src(ctx, instr->src[src_shift]),
> > +               vindex = LLVMBuildExtractElement(ctx->ac.builder,
> get_src(ctx, instr->src[1]),
> >                                                  ctx->ac.i32_0, "");
> >
> >                 /* TODO: set "glc" and "can_speculate" when OpenGL needs
> it. */
> > @@ -2446,15 +2257,12 @@ static void visit_image_store(struct
> ac_nir_context *ctx,
> >         if (force_glc)
> >                 glc = ctx->ac.i1true;
> >
> > -       /* As the deref instrinsics have the deref as src 0, everything
> is shifted. */
> > -       int src_shift = is_var_image_intrinsic(instr) ? 0 : 1;
> > -
> >         if (dim == GLSL_SAMPLER_DIM_BUF) {
> >                 LLVMValueRef rsrc = get_image_buffer_descriptor(ctx,
> instr, true);
> >
> > -               params[0] = ac_to_float(&ctx->ac, get_src(ctx,
> instr->src[src_shift + 2])); /* data */
> > +               params[0] = ac_to_float(&ctx->ac, get_src(ctx,
> instr->src[3])); /* data */
> >                 params[1] = rsrc;
> > -               params[2] = LLVMBuildExtractElement(ctx->ac.builder,
> get_src(ctx, instr->src[src_shift]),
> > +               params[2] = LLVMBuildExtractElement(ctx->ac.builder,
> get_src(ctx, instr->src[1]),
> >                                                     ctx->ac.i32_0, "");
> /* vindex */
> >                 params[3] = ctx->ac.i32_0; /* voffset */
> >                 params[4] = glc;  /* glc */
> > @@ -2464,9 +2272,9 @@ static void visit_image_store(struct
> ac_nir_context *ctx,
> >         } else {
> >                 struct ac_image_args args = {};
> >                 args.opcode = ac_image_store;
> > -               args.data[0] = ac_to_float(&ctx->ac, get_src(ctx,
> instr->src[2]));
> > +               args.data[0] = ac_to_float(&ctx->ac, get_src(ctx,
> instr->src[3]));
> >                 get_image_coords(ctx, instr, &args);
> > -               args.resource = get_image_descriptor(ctx, instr,
> AC_DESC_IMAGE, true);;
> > +               args.resource = get_image_descriptor(ctx, instr,
> AC_DESC_IMAGE, true);
> >                 args.dim = get_ac_image_dim(&ctx->ac,
> glsl_get_sampler_dim(type),
> >                                             glsl_sampler_type_is_array(
> type));
> >                 args.dmask = 15;
> > @@ -2485,8 +2293,7 @@ static LLVMValueRef visit_image_atomic(struct
> ac_nir_context *ctx,
> >         int param_count = 0;
> >         const nir_variable *var = get_image_variable(instr);
> >
> > -       bool cmpswap = instr->intrinsic == nir_intrinsic_image_var_atomic_comp_swap
> ||
> > -                      instr->intrinsic == nir_intrinsic_image_deref_
> atomic_comp_swap;
> > +       bool cmpswap = instr->intrinsic == nir_intrinsic_image_deref_
> atomic_comp_swap;
> >         const char *atomic_name;
> >         char intrinsic_name[41];
> >         enum ac_atomic_op atomic_subop;
> > @@ -2496,42 +2303,34 @@ static LLVMValueRef visit_image_atomic(struct
> ac_nir_context *ctx,
> >         bool is_unsigned = glsl_get_sampler_result_type(type) ==
> GLSL_TYPE_UINT;
> >
> >         switch (instr->intrinsic) {
> > -       case nir_intrinsic_image_var_atomic_add:
> >         case nir_intrinsic_image_deref_atomic_add:
> >                 atomic_name = "add";
> >                 atomic_subop = ac_atomic_add;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_min:
> >         case nir_intrinsic_image_deref_atomic_min:
> >                 atomic_name = is_unsigned ? "umin" : "smin";
> >                 atomic_subop = is_unsigned ? ac_atomic_umin :
> ac_atomic_smin;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_max:
> >         case nir_intrinsic_image_deref_atomic_max:
> >                 atomic_name = is_unsigned ? "umax" : "smax";
> >                 atomic_subop = is_unsigned ? ac_atomic_umax :
> ac_atomic_smax;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_and:
> >         case nir_intrinsic_image_deref_atomic_and:
> >                 atomic_name = "and";
> >                 atomic_subop = ac_atomic_and;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_or:
> >         case nir_intrinsic_image_deref_atomic_or:
> >                 atomic_name = "or";
> >                 atomic_subop = ac_atomic_or;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_xor:
> >         case nir_intrinsic_image_deref_atomic_xor:
> >                 atomic_name = "xor";
> >                 atomic_subop = ac_atomic_xor;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_exchange:
> >         case nir_intrinsic_image_deref_atomic_exchange:
> >                 atomic_name = "swap";
> >                 atomic_subop = ac_atomic_swap;
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_comp_swap:
> >         case nir_intrinsic_image_deref_atomic_comp_swap:
> >                 atomic_name = "cmpswap";
> >                 atomic_subop = 0; /* not used */
> > @@ -2540,16 +2339,13 @@ static LLVMValueRef visit_image_atomic(struct
> ac_nir_context *ctx,
> >                 abort();
> >         }
> >
> > -       /* As the deref instrinsics have the deref as src 0, everything
> is shifted. */
> > -       int src_shift = is_var_image_intrinsic(instr) ? 0 : 1;
> > -
> >         if (cmpswap)
> > -               params[param_count++] = get_src(ctx,
> instr->src[src_shift + 3]);
> > -       params[param_count++] = get_src(ctx, instr->src[src_shift + 2]);
> > +               params[param_count++] = get_src(ctx, instr->src[4]);
> > +       params[param_count++] = get_src(ctx, instr->src[3]);
> >
> >         if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_BUF) {
> >                 params[param_count++] = get_image_buffer_descriptor(ctx,
> instr, true);
> > -               params[param_count++] = LLVMBuildExtractElement(ctx->ac.builder,
> get_src(ctx, instr->src[src_shift]),
> > +               params[param_count++] = LLVMBuildExtractElement(ctx->ac.builder,
> get_src(ctx, instr->src[1]),
> >
>  ctx->ac.i32_0, ""); /* vindex */
> >                 params[param_count++] = ctx->ac.i32_0; /* voffset */
> >                 params[param_count++] = ctx->ac.i1false;  /* slc */
> > @@ -2805,8 +2601,7 @@ static LLVMValueRef visit_var_atomic(struct
> ac_nir_context *ctx,
> >         LLVMValueRef result;
> >         LLVMValueRef src = get_src(ctx, instr->src[src_idx]);
> >
> > -       if (instr->intrinsic == nir_intrinsic_var_atomic_comp_swap ||
> > -           instr->intrinsic == nir_intrinsic_shared_atomic_comp_swap ||
> > +       if (instr->intrinsic == nir_intrinsic_shared_atomic_comp_swap ||
> >             instr->intrinsic == nir_intrinsic_deref_atomic_comp_swap) {
> >                 LLVMValueRef src1 = get_src(ctx, instr->src[src_idx +
> 1]);
> >                 result = LLVMBuildAtomicCmpXchg(ctx->ac.builder,
> > @@ -2818,47 +2613,38 @@ static LLVMValueRef visit_var_atomic(struct
> ac_nir_context *ctx,
> >         } else {
> >                 LLVMAtomicRMWBinOp op;
> >                 switch (instr->intrinsic) {
> > -               case nir_intrinsic_var_atomic_add:
> >                 case nir_intrinsic_shared_atomic_add:
> >                 case nir_intrinsic_deref_atomic_add:
> >                         op = LLVMAtomicRMWBinOpAdd;
> >                         break;
> > -               case nir_intrinsic_var_atomic_umin:
> >                 case nir_intrinsic_shared_atomic_umin:
> >                 case nir_intrinsic_deref_atomic_umin:
> >                         op = LLVMAtomicRMWBinOpUMin;
> >                         break;
> > -               case nir_intrinsic_var_atomic_umax:
> >                 case nir_intrinsic_shared_atomic_umax:
> >                 case nir_intrinsic_deref_atomic_umax:
> >                         op = LLVMAtomicRMWBinOpUMax;
> >                         break;
> > -               case nir_intrinsic_var_atomic_imin:
> >                 case nir_intrinsic_shared_atomic_imin:
> >                 case nir_intrinsic_deref_atomic_imin:
> >                         op = LLVMAtomicRMWBinOpMin;
> >                         break;
> > -               case nir_intrinsic_var_atomic_imax:
> >                 case nir_intrinsic_shared_atomic_imax:
> >                 case nir_intrinsic_deref_atomic_imax:
> >                         op = LLVMAtomicRMWBinOpMax;
> >                         break;
> > -               case nir_intrinsic_var_atomic_and:
> >                 case nir_intrinsic_shared_atomic_and:
> >                 case nir_intrinsic_deref_atomic_and:
> >                         op = LLVMAtomicRMWBinOpAnd;
> >                         break;
> > -               case nir_intrinsic_var_atomic_or:
> >                 case nir_intrinsic_shared_atomic_or:
> >                 case nir_intrinsic_deref_atomic_or:
> >                         op = LLVMAtomicRMWBinOpOr;
> >                         break;
> > -               case nir_intrinsic_var_atomic_xor:
> >                 case nir_intrinsic_shared_atomic_xor:
> >                 case nir_intrinsic_deref_atomic_xor:
> >                         op = LLVMAtomicRMWBinOpXor;
> >                         break;
> > -               case nir_intrinsic_var_atomic_exchange:
> >                 case nir_intrinsic_shared_atomic_exchange:
> >                 case nir_intrinsic_deref_atomic_exchange:
> >                         op = LLVMAtomicRMWBinOpXchg;
> > @@ -2897,42 +2683,26 @@ static LLVMValueRef visit_interp(struct
> ac_nir_context *ctx,
> >         LLVMValueRef src_c0 = NULL;
> >         LLVMValueRef src_c1 = NULL;
> >         LLVMValueRef src0 = NULL;
> > -       bool uses_deref_chain;
> > -       switch (instr->intrinsic) {
> > -       case nir_intrinsic_interp_var_at_centroid:
> > -       case nir_intrinsic_interp_var_at_sample:
> > -       case nir_intrinsic_interp_var_at_offset:
> > -               uses_deref_chain = true;
> > -               break;
> > -       default:
> > -               uses_deref_chain = false;
> > -               break;
> > -       }
> >
> > -       nir_variable *var = uses_deref_chain ? instr->variables[0]->var
> : nir_deref_instr_get_variable(nir_instr_as_deref(instr->src[
> 0].ssa->parent_instr));
> > +       nir_variable *var = nir_deref_instr_get_variable(
> nir_instr_as_deref(instr->src[0].ssa->parent_instr));
> >         int input_index = var->data.location - VARYING_SLOT_VAR0;
> >         switch (instr->intrinsic) {
> > -       case nir_intrinsic_interp_var_at_centroid:
> >         case nir_intrinsic_interp_deref_at_centroid:
> >                 location = INTERP_CENTROID;
> >                 break;
> > -       case nir_intrinsic_interp_var_at_sample:
> > -       case nir_intrinsic_interp_var_at_offset:
> >         case nir_intrinsic_interp_deref_at_sample:
> >         case nir_intrinsic_interp_deref_at_offset:
> >                 location = INTERP_CENTER;
> > -               src0 = get_src(ctx, instr->src[uses_deref_chain ? 0 :
> 1]);
> > +               src0 = get_src(ctx, instr->src[11]);
>
> Stupid mistake here, 11 -> 1
>
> Not sure why I did not catch this before :(
>

Fixed.  I also force-pushed the branch with the change.

--Jason


> >                 break;
> >         default:
> >                 break;
> >         }
> >
> > -       if (instr->intrinsic == nir_intrinsic_interp_var_at_offset ||
> > -           instr->intrinsic == nir_intrinsic_interp_deref_at_offset) {
> > +       if (instr->intrinsic == nir_intrinsic_interp_deref_at_offset) {
> >                 src_c0 = ac_to_float(&ctx->ac,
> LLVMBuildExtractElement(ctx->ac.builder, src0, ctx->ac.i32_0, ""));
> >                 src_c1 = ac_to_float(&ctx->ac,
> LLVMBuildExtractElement(ctx->ac.builder, src0, ctx->ac.i32_1, ""));
> > -       } else if (instr->intrinsic == nir_intrinsic_interp_var_at_sample
> ||
> > -                  instr->intrinsic == nir_intrinsic_interp_deref_at_sample)
> {
> > +       } else if (instr->intrinsic == nir_intrinsic_interp_deref_at_sample)
> {
> >                 LLVMValueRef sample_position;
> >                 LLVMValueRef halfval = LLVMConstReal(ctx->ac.f32, 0.5f);
> >
> > @@ -3168,11 +2938,9 @@ static void visit_intrinsic(struct ac_nir_context
> *ctx,
> >                 result = visit_get_buffer_size(ctx, instr);
> >                 break;
> >         case nir_intrinsic_load_deref:
> > -       case nir_intrinsic_load_var:
> >                 result = visit_load_var(ctx, instr);
> >                 break;
> >         case nir_intrinsic_store_deref:
> > -       case nir_intrinsic_store_var:
> >                 visit_store_var(ctx, instr);
> >                 break;
> >         case nir_intrinsic_load_shared:
> > @@ -3181,26 +2949,15 @@ static void visit_intrinsic(struct
> ac_nir_context *ctx,
> >         case nir_intrinsic_store_shared:
> >                 visit_store_shared(ctx, instr);
> >                 break;
> > -       case nir_intrinsic_image_var_samples:
> >         case nir_intrinsic_image_deref_samples:
> >                 result = visit_image_samples(ctx, instr);
> >                 break;
> > -       case nir_intrinsic_image_var_load:
> >         case nir_intrinsic_image_deref_load:
> >                 result = visit_image_load(ctx, instr);
> >                 break;
> > -       case nir_intrinsic_image_var_store:
> >         case nir_intrinsic_image_deref_store:
> >                 visit_image_store(ctx, instr);
> >                 break;
> > -       case nir_intrinsic_image_var_atomic_add:
> > -       case nir_intrinsic_image_var_atomic_min:
> > -       case nir_intrinsic_image_var_atomic_max:
> > -       case nir_intrinsic_image_var_atomic_and:
> > -       case nir_intrinsic_image_var_atomic_or:
> > -       case nir_intrinsic_image_var_atomic_xor:
> > -       case nir_intrinsic_image_var_atomic_exchange:
> > -       case nir_intrinsic_image_var_atomic_comp_swap:
> >         case nir_intrinsic_image_deref_atomic_add:
> >         case nir_intrinsic_image_deref_atomic_min:
> >         case nir_intrinsic_image_deref_atomic_max:
> > @@ -3211,7 +2968,6 @@ static void visit_intrinsic(struct ac_nir_context
> *ctx,
> >         case nir_intrinsic_image_deref_atomic_comp_swap:
> >                 result = visit_image_atomic(ctx, instr);
> >                 break;
> > -       case nir_intrinsic_image_var_size:
> >         case nir_intrinsic_image_deref_size:
> >                 result = visit_image_size(ctx, instr);
> >                 break;
> > @@ -3247,20 +3003,6 @@ static void visit_intrinsic(struct ac_nir_context
> *ctx,
> >                 result = visit_var_atomic(ctx, instr, ptr, 1);
> >                 break;
> >         }
> > -       case nir_intrinsic_var_atomic_add:
> > -       case nir_intrinsic_var_atomic_imin:
> > -       case nir_intrinsic_var_atomic_umin:
> > -       case nir_intrinsic_var_atomic_imax:
> > -       case nir_intrinsic_var_atomic_umax:
> > -       case nir_intrinsic_var_atomic_and:
> > -       case nir_intrinsic_var_atomic_or:
> > -       case nir_intrinsic_var_atomic_xor:
> > -       case nir_intrinsic_var_atomic_exchange:
> > -       case nir_intrinsic_var_atomic_comp_swap: {
> > -               LLVMValueRef ptr = build_gep_for_deref(ctx,
> instr->variables[0]);
> > -               result = visit_var_atomic(ctx, instr, ptr, 0);
> > -               break;
> > -       }
> >         case nir_intrinsic_deref_atomic_add:
> >         case nir_intrinsic_deref_atomic_imin:
> >         case nir_intrinsic_deref_atomic_umin:
> > @@ -3275,9 +3017,6 @@ static void visit_intrinsic(struct ac_nir_context
> *ctx,
> >                 result = visit_var_atomic(ctx, instr, ptr, 1);
> >                 break;
> >         }
> > -       case nir_intrinsic_interp_var_at_centroid:
> > -       case nir_intrinsic_interp_var_at_sample:
> > -       case nir_intrinsic_interp_var_at_offset:
> >         case nir_intrinsic_interp_deref_at_centroid:
> >         case nir_intrinsic_interp_deref_at_sample:
> >         case nir_intrinsic_interp_deref_at_offset:
> > @@ -3358,7 +3097,6 @@ static void visit_intrinsic(struct ac_nir_context
> *ctx,
> >  }
> >
> >  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 *tex_instr,
> > @@ -3370,11 +3108,11 @@ static LLVMValueRef get_sampler_desc(struct
> ac_nir_context *ctx,
> >         unsigned base_index;
> >         bool bindless = false;
> >
> > -       if (!deref && !deref_instr) {
> > +       if (!deref_instr) {
> >                 assert(tex_instr && !image);
> >                 descriptor_set = 0;
> >                 base_index = tex_instr->sampler_index;
> > -       } else if(deref_instr) {
> > +       } else {
> >                 while(deref_instr->deref_type != nir_deref_type_var) {
> >                         unsigned array_size =
> glsl_get_aoa_size(deref_instr->type);
> >                         if (!array_size)
> > @@ -3400,41 +3138,6 @@ static LLVMValueRef get_sampler_desc(struct
> ac_nir_context *ctx,
> >                 }
> >                 descriptor_set = deref_instr->var->data.descriptor_set;
> >                 base_index = deref_instr->var->data.binding;
> > -        } else {
> > -               const nir_deref *tail = &deref->deref;
> > -               while (tail->child) {
> > -                       const nir_deref_array *child =
> nir_deref_as_array(tail->child);
> > -                       unsigned array_size =
> glsl_get_aoa_size(tail->child->type);
> > -
> > -                       if (!array_size)
> > -                               array_size = 1;
> > -
> > -                       assert(child->deref_array_type !=
> nir_deref_array_type_wildcard);
> > -
> > -                       if (child->deref_array_type ==
> nir_deref_array_type_indirect) {
> > -                               LLVMValueRef indirect = get_src(ctx,
> child->indirect);
> > -
> > -                               indirect = LLVMBuildMul(ctx->ac.builder,
> indirect,
> > -                                       LLVMConstInt(ctx->ac.i32,
> array_size, false), "");
> > -
> > -                               if (!index)
> > -                                       index = indirect;
> > -                               else
> > -                                       index =
> LLVMBuildAdd(ctx->ac.builder, index, indirect, "");
> > -                       }
> > -
> > -                       constant_index += child->base_offset *
> array_size;
> > -
> > -                       tail = &child->deref;
> > -               }
> > -               descriptor_set = deref->var->data.descriptor_set;
> > -
> > -               if (deref->var->data.bindless) {
> > -                       bindless = deref->var->data.bindless;
> > -                       base_index = deref->var->data.driver_location;
> > -               } else {
> > -                       base_index = deref->var->data.binding;
> > -               }
> >         }
> >
> >         return ctx->abi->load_sampler_desc(ctx->abi,
> > @@ -3480,8 +3183,6 @@ static void tex_fetch_ptrs(struct ac_nir_context
> *ctx,
> >  {
> >         nir_deref_instr *texture_deref_instr = NULL;
> >         nir_deref_instr *sampler_deref_instr = NULL;
> > -       nir_deref_var *texture_deref_var = NULL;
> > -       nir_deref_var *sampler_deref_var = NULL;
> >
> >         for (unsigned i = 0; i < instr->num_srcs; i++) {
> >                 switch (instr->src[i].src_type) {
> > @@ -3499,23 +3200,18 @@ static void tex_fetch_ptrs(struct ac_nir_context
> *ctx,
> >         if (!sampler_deref_instr)
> >                 sampler_deref_instr = texture_deref_instr;
> >
> > -       if (!texture_deref_instr) {
> > -               texture_deref_var = instr->texture;
> > -               sampler_deref_var = instr->sampler ? instr->sampler :
> instr->texture;
> > -       }
> > -
> >         if (instr->sampler_dim  == GLSL_SAMPLER_DIM_BUF)
> > -               *res_ptr = get_sampler_desc(ctx, texture_deref_var,
> texture_deref_instr, AC_DESC_BUFFER, instr, false, false);
> > +               *res_ptr = get_sampler_desc(ctx, texture_deref_instr,
> AC_DESC_BUFFER, instr, false, false);
> >         else
> > -               *res_ptr = get_sampler_desc(ctx, texture_deref_var,
> texture_deref_instr, AC_DESC_IMAGE, instr, false, false);
> > +               *res_ptr = get_sampler_desc(ctx, texture_deref_instr,
> AC_DESC_IMAGE, instr, false, false);
> >         if (samp_ptr) {
> > -               *samp_ptr = get_sampler_desc(ctx, sampler_deref_var,
> sampler_deref_instr, AC_DESC_SAMPLER, instr, false, false);
> > +               *samp_ptr = get_sampler_desc(ctx, sampler_deref_instr,
> AC_DESC_SAMPLER, instr, false, false);
> >                 if (instr->sampler_dim < GLSL_SAMPLER_DIM_RECT)
> >                         *samp_ptr = sici_fix_sampler_aniso(ctx,
> *res_ptr, *samp_ptr);
> >         }
> > -       if (fmask_ptr && !instr->sampler && (instr->op ==
> nir_texop_txf_ms ||
> > -                                            instr->op ==
> nir_texop_samples_identical))
> > -               *fmask_ptr = get_sampler_desc(ctx, instr->texture,
> texture_deref_instr, AC_DESC_FMASK, instr, false, false);
> > +       if (fmask_ptr && (instr->op == nir_texop_txf_ms ||
> > +                         instr->op == nir_texop_samples_identical))
> > +               *fmask_ptr = get_sampler_desc(ctx, texture_deref_instr,
> AC_DESC_FMASK, instr, false, false);
> >  }
> >
> >  static LLVMValueRef apply_round_slice(struct ac_llvm_context *ctx,
> > --
> > 2.5.0.400.gff86faf
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180601/56952c14/attachment-0001.html>


More information about the mesa-dev mailing list