[Mesa-dev] [PATCH 2/7] nir: add atomic lowering support for AoA

Jason Ekstrand jason at jlekstrand.net
Thu Oct 15 23:51:33 PDT 2015


On Oct 15, 2015 16:29, "Timothy Arceri" <t_arceri at yahoo.com.au> wrote:
>
> Cc: Francisco Jerez <currojerez at riseup.net>
> Cc: Jason Ekstrand <jason at jlekstrand.net>
> ---
>  src/glsl/nir/nir_lower_atomics.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/src/glsl/nir/nir_lower_atomics.c
b/src/glsl/nir/nir_lower_atomics.c
> index 6f9ecc0..46e1376 100644
> --- a/src/glsl/nir/nir_lower_atomics.c
> +++ b/src/glsl/nir/nir_lower_atomics.c
> @@ -72,20 +72,22 @@ lower_instr(nir_intrinsic_instr *instr,
nir_function_impl *impl)
>
>     nir_ssa_def *offset_def = &offset_const->def;
>
> -   if (instr->variables[0]->deref.child != NULL) {
> -      assert(instr->variables[0]->deref.child->deref_type ==
> -             nir_deref_type_array);
> -      nir_deref_array *deref_array =
> -         nir_deref_as_array(instr->variables[0]->deref.child);
> -      assert(deref_array->deref.child == NULL);
> +   nir_deref *tail = &instr->variables[0]->deref;
> +   while (tail->child != NULL) {
> +      assert(tail->child->deref_type == nir_deref_type_array);
> +      nir_deref_array *deref_array = nir_deref_as_array(tail->child);
> +      tail = tail->child;
>
> -      offset_const->value.u[0] +=
> -         deref_array->base_offset * ATOMIC_COUNTER_SIZE;
> +      unsigned child_array_elements = tail->child != NULL ?
> +         glsl_get_aoa_size(tail->type) : 1;
> +
> +      offset_const->value.u[0] += deref_array->base_offset *
> +         child_array_elements * ATOMIC_COUNTER_SIZE;

Another way to do this would be

offset_const->value.u[0] *= array_length;
offset_const->value.u[0] += base_offset;

Either way, this seems reasonable to me.

Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>

>        if (deref_array->deref_array_type ==
nir_deref_array_type_indirect) {
>           nir_load_const_instr *atomic_counter_size =
>                 nir_load_const_instr_create(mem_ctx, 1);
> -         atomic_counter_size->value.u[0] = ATOMIC_COUNTER_SIZE;
> +         atomic_counter_size->value.u[0] = child_array_elements *
ATOMIC_COUNTER_SIZE;
>           nir_instr_insert_before(&instr->instr,
&atomic_counter_size->instr);
>
>           nir_alu_instr *mul = nir_alu_instr_create(mem_ctx, nir_op_imul);
> @@ -102,7 +104,7 @@ lower_instr(nir_intrinsic_instr *instr,
nir_function_impl *impl)
>           add->src[0].src.is_ssa = true;
>           add->src[0].src.ssa = &mul->dest.dest.ssa;
>           add->src[1].src.is_ssa = true;
> -         add->src[1].src.ssa = &offset_const->def;
> +         add->src[1].src.ssa = offset_def;
>           nir_instr_insert_before(&instr->instr, &add->instr);
>
>           offset_def = &add->dest.dest.ssa;

As a side-note, we really should switch this over to using the builder some
time soon... Not that you need to do it or anything.

> --
> 2.4.3
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20151015/0c077f21/attachment-0001.html>


More information about the mesa-dev mailing list