[Mesa-dev] [PATCH 06/11] nir/lower_vec_to_movs: Add a state struct

Eduardo Lima Mitev elima at igalia.com
Thu Sep 10 09:00:01 PDT 2015


Looks good.

Reviewed-by: Eduardo Lima Mitev <elima at igalia.com>

On 09/10/2015 02:50 AM, Jason Ekstrand wrote:
> While we're here, we also fix up a couple of potential ralloc-parenting
> bugs.  In particular, we were calling nir_src_copy with the shader as the
> mem context instead of the instruction.
> ---
>  src/glsl/nir/nir_lower_vec_to_movs.c | 22 ++++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/src/glsl/nir/nir_lower_vec_to_movs.c b/src/glsl/nir/nir_lower_vec_to_movs.c
> index b7f096d..e297cb8 100644
> --- a/src/glsl/nir/nir_lower_vec_to_movs.c
> +++ b/src/glsl/nir/nir_lower_vec_to_movs.c
> @@ -32,6 +32,10 @@
>   * moves with partial writes.
>   */
>  
> +struct vec_to_movs_state {
> +   nir_shader *shader;
> +};
> +
>  static bool
>  src_matches_dest_reg(nir_dest *dest, nir_src *src)
>  {
> @@ -54,12 +58,12 @@ src_matches_dest_reg(nir_dest *dest, nir_src *src)
>   */
>  static unsigned
>  insert_mov(nir_alu_instr *vec, unsigned start_channel,
> -            unsigned start_src_idx, void *mem_ctx)
> +            unsigned start_src_idx, nir_shader *shader)
>  {
>     unsigned src_idx = start_src_idx;
>     assert(src_idx < nir_op_infos[vec->op].num_inputs);
>  
> -   nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov);
> +   nir_alu_instr *mov = nir_alu_instr_create(shader, nir_op_imov);
>     nir_alu_src_copy(&mov->src[0], &vec->src[src_idx], mov);
>     nir_alu_dest_copy(&mov->dest, &vec->dest, mov);
>  
> @@ -84,8 +88,10 @@ insert_mov(nir_alu_instr *vec, unsigned start_channel,
>  }
>  
>  static bool
> -lower_vec_to_movs_block(nir_block *block, void *mem_ctx)
> +lower_vec_to_movs_block(nir_block *block, void *void_state)
>  {
> +   struct vec_to_movs_state *state = void_state;
> +
>     nir_foreach_instr_safe(block, instr) {
>        if (instr->type != nir_instr_type_alu)
>           continue;
> @@ -115,7 +121,7 @@ lower_vec_to_movs_block(nir_block *block, void *mem_ctx)
>              continue;
>  
>           if (src_matches_dest_reg(&vec->dest.dest, &vec->src[src_idx].src)) {
> -            finished_write_mask |= insert_mov(vec, i, src_idx, mem_ctx);
> +            finished_write_mask |= insert_mov(vec, i, src_idx, state->shader);
>              break;
>           }
>           src_idx++;
> @@ -127,7 +133,7 @@ lower_vec_to_movs_block(nir_block *block, void *mem_ctx)
>              continue;
>  
>           if (!(finished_write_mask & (1 << i)))
> -            finished_write_mask |= insert_mov(vec, i, src_idx, mem_ctx);
> +            finished_write_mask |= insert_mov(vec, i, src_idx, state->shader);
>  
>           src_idx++;
>        }
> @@ -142,7 +148,11 @@ lower_vec_to_movs_block(nir_block *block, void *mem_ctx)
>  static void
>  nir_lower_vec_to_movs_impl(nir_function_impl *impl)
>  {
> -   nir_foreach_block(impl, lower_vec_to_movs_block, ralloc_parent(impl));
> +   struct vec_to_movs_state state;
> +
> +   state.shader = impl->overload->function->shader;
> +
> +   nir_foreach_block(impl, lower_vec_to_movs_block, &state);
>  }
>  
>  void
> 



More information about the mesa-dev mailing list