[Mesa-dev] [PATCH v3 022/104] nir: Support deref instructions in lower_indirect_derefs

Caio Marcelo de Oliveira Filho caio.oliveira at intel.com
Fri Apr 6 21:23:38 UTC 2018


Hi,

> +static void
> +emit_load_store_deref(nir_builder *b, nir_intrinsic_instr *orig_instr,
> +                      nir_deref_instr *parent,
> +                      nir_deref_instr **deref_arr,
> +                      nir_ssa_def **dest, nir_ssa_def *src)
> +{
> +   for (; *deref_arr; deref_arr++) {
> +      nir_deref_instr *deref = *deref_arr;
> +      if (deref->deref_type == nir_deref_type_array &&
> +          nir_src_as_const_value(deref->arr.index) == NULL) {
> +         int length = glsl_get_length(parent->type);
> +
> +         emit_indirect_load_store_deref(b, orig_instr, parent, deref_arr,
> +                                        0, length, dest, src);

Side note: after reading the existing code (that goes from
-base_offset to length - base_offset, and later adds base_offset), I'm
kind of glad this goes from 0 to length.


> +static bool
> +lower_indirect_derefs_block(nir_block *block, nir_builder *b,
> +                            nir_variable_mode modes)
> +{

(...)

> +      nir_deref_instr *deref =
> +         nir_instr_as_deref(intrin->src[0].ssa->parent_instr);

Maybe use the helper 'nir_src_as_deref(intrin->src[0])'?

> +
> +      /* Walk the deref chain back to the base and look for indirects */
> +      bool has_indirect = false;
> +      nir_deref_instr *base = deref;
> +      while (base->deref_type != nir_deref_type_var) {
> +         if (base->deref_type == nir_deref_type_array &&
> +             nir_src_as_const_value(base->arr.index) == NULL)
> +            has_indirect = true;
> +
> +         base = nir_instr_as_deref(base->parent.ssa->parent_instr);

Maybe use the helper 'base = nir_deref_instr_parent(base);'?


Thanks,
Caio


More information about the mesa-dev mailing list