<p dir="ltr"><br>
On Oct 15, 2015 16:29, "Timothy Arceri" <<a href="mailto:t_arceri@yahoo.com.au">t_arceri@yahoo.com.au</a>> wrote:<br>
><br>
> Cc: Francisco Jerez <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>><br>
> Cc: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
> ---<br>
> src/glsl/nir/nir_lower_atomics.c | 22 ++++++++++++----------<br>
> 1 file changed, 12 insertions(+), 10 deletions(-)<br>
><br>
> diff --git a/src/glsl/nir/nir_lower_atomics.c b/src/glsl/nir/nir_lower_atomics.c<br>
> index 6f9ecc0..46e1376 100644<br>
> --- a/src/glsl/nir/nir_lower_atomics.c<br>
> +++ b/src/glsl/nir/nir_lower_atomics.c<br>
> @@ -72,20 +72,22 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)<br>
><br>
> nir_ssa_def *offset_def = &offset_const->def;<br>
><br>
> - if (instr->variables[0]->deref.child != NULL) {<br>
> - assert(instr->variables[0]->deref.child->deref_type ==<br>
> - nir_deref_type_array);<br>
> - nir_deref_array *deref_array =<br>
> - nir_deref_as_array(instr->variables[0]->deref.child);<br>
> - assert(deref_array->deref.child == NULL);<br>
> + nir_deref *tail = &instr->variables[0]->deref;<br>
> + while (tail->child != NULL) {<br>
> + assert(tail->child->deref_type == nir_deref_type_array);<br>
> + nir_deref_array *deref_array = nir_deref_as_array(tail->child);<br>
> + tail = tail->child;<br>
><br>
> - offset_const->value.u[0] +=<br>
> - deref_array->base_offset * ATOMIC_COUNTER_SIZE;<br>
> + unsigned child_array_elements = tail->child != NULL ?<br>
> + glsl_get_aoa_size(tail->type) : 1;<br>
> +<br>
> + offset_const->value.u[0] += deref_array->base_offset *<br>
> + child_array_elements * ATOMIC_COUNTER_SIZE;</p>
<p dir="ltr">Another way to do this would be</p>
<p dir="ltr">offset_const->value.u[0] *= array_length;<br>
offset_const->value.u[0] += base_offset;</p>
<p dir="ltr">Either way, this seems reasonable to me.</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>></p>
<p dir="ltr">> if (deref_array->deref_array_type == nir_deref_array_type_indirect) {<br>
> nir_load_const_instr *atomic_counter_size =<br>
> nir_load_const_instr_create(mem_ctx, 1);<br>
> - atomic_counter_size->value.u[0] = ATOMIC_COUNTER_SIZE;<br>
> + atomic_counter_size->value.u[0] = child_array_elements * ATOMIC_COUNTER_SIZE;<br>
> nir_instr_insert_before(&instr->instr, &atomic_counter_size->instr);<br>
><br>
> nir_alu_instr *mul = nir_alu_instr_create(mem_ctx, nir_op_imul);<br>
> @@ -102,7 +104,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)<br>
> add->src[0].src.is_ssa = true;<br>
> add->src[0].src.ssa = &mul->dest.dest.ssa;<br>
> add->src[1].src.is_ssa = true;<br>
> - add->src[1].src.ssa = &offset_const->def;<br>
> + add->src[1].src.ssa = offset_def;<br>
> nir_instr_insert_before(&instr->instr, &add->instr);<br>
><br>
> offset_def = &add->dest.dest.ssa;</p>
<p dir="ltr">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.</p>
<p dir="ltr">> --<br>
> 2.4.3<br>
><br>
</p>