[Mesa-dev] [PATCH 1/2] nir: Add a helper for adding texture instruction sources

Lionel Landwerlin lionel.g.landwerlin at intel.com
Tue Oct 17 10:27:38 UTC 2017


Thanks!

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>

On 17/10/17 02:09, Jason Ekstrand wrote:
> ---
>   src/compiler/nir/nir.c                           | 22 +++++++++++++++++++
>   src/compiler/nir/nir.h                           |  4 ++++
>   src/compiler/nir/nir_lower_samplers.c            | 27 ++----------------------
>   src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 19 +----------------
>   4 files changed, 29 insertions(+), 43 deletions(-)
>
> diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
> index afd4d1a..5bc07b7 100644
> --- a/src/compiler/nir/nir.c
> +++ b/src/compiler/nir/nir.c
> @@ -542,6 +542,28 @@ nir_tex_instr_create(nir_shader *shader, unsigned num_srcs)
>   }
>   
>   void
> +nir_tex_instr_add_src(nir_tex_instr *tex,
> +                      nir_tex_src_type src_type,
> +                      nir_src src)
> +{
> +   nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src,
> +                                         tex->num_srcs + 1);
> +
> +   for (unsigned i = 0; i < tex->num_srcs; i++) {
> +      new_srcs[i].src_type = tex->src[i].src_type;
> +      nir_instr_move_src(&tex->instr, &new_srcs[i].src,
> +                         &tex->src[i].src);
> +   }
> +
> +   ralloc_free(tex->src);
> +   tex->src = new_srcs;
> +
> +   tex->src[tex->num_srcs].src_type = src_type;
> +   nir_instr_rewrite_src(&tex->instr, &tex->src[tex->num_srcs].src, src);
> +   tex->num_srcs++;
> +}
> +
> +void
>   nir_tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx)
>   {
>      assert(src_idx < tex->num_srcs);
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index bd6035e..70c23c2 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1379,6 +1379,10 @@ nir_tex_instr_src_index(const nir_tex_instr *instr, nir_tex_src_type type)
>      return -1;
>   }
>   
> +void nir_tex_instr_add_src(nir_tex_instr *tex,
> +                           nir_tex_src_type src_type,
> +                           nir_src src);
> +
>   void nir_tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx);
>   
>   typedef struct {
> diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/nir/nir_lower_samplers.c
> index 0c4e91b..f75fb1a 100644
> --- a/src/compiler/nir/nir_lower_samplers.c
> +++ b/src/compiler/nir/nir_lower_samplers.c
> @@ -109,32 +109,9 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
>         assert(array_elements >= 1);
>         indirect = nir_umin(b, indirect, nir_imm_int(b, array_elements - 1));
>   
> -      /* First, we have to resize the array of texture sources */
> -      nir_tex_src *new_srcs = rzalloc_array(instr, nir_tex_src,
> -                                            instr->num_srcs + 2);
> -
> -      for (unsigned i = 0; i < instr->num_srcs; i++) {
> -         new_srcs[i].src_type = instr->src[i].src_type;
> -         nir_instr_move_src(&instr->instr, &new_srcs[i].src,
> -                            &instr->src[i].src);
> -      }
> -
> -      ralloc_free(instr->src);
> -      instr->src = new_srcs;
> -
> -      /* Now we can go ahead and move the source over to being a
> -       * first-class texture source.
> -       */
> -      instr->src[instr->num_srcs].src_type = nir_tex_src_texture_offset;
> -      instr->num_srcs++;
> -      nir_instr_rewrite_src(&instr->instr,
> -                            &instr->src[instr->num_srcs - 1].src,
> +      nir_tex_instr_add_src(instr, nir_tex_src_texture_offset,
>                               nir_src_for_ssa(indirect));
> -
> -      instr->src[instr->num_srcs].src_type = nir_tex_src_sampler_offset;
> -      instr->num_srcs++;
> -      nir_instr_rewrite_src(&instr->instr,
> -                            &instr->src[instr->num_srcs - 1].src,
> +      nir_tex_instr_add_src(instr, nir_tex_src_sampler_offset,
>                               nir_src_for_ssa(indirect));
>   
>         instr->texture_array_size = array_elements;
> diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
> index 26e7dcc..1c86513 100644
> --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
> +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
> @@ -157,24 +157,7 @@ lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref,
>            if (state->add_bounds_checks)
>               index = nir_umin(b, index, nir_imm_int(b, array_size - 1));
>   
> -         nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src,
> -                                               tex->num_srcs + 1);
> -
> -         for (unsigned i = 0; i < tex->num_srcs; i++) {
> -            new_srcs[i].src_type = tex->src[i].src_type;
> -            nir_instr_move_src(&tex->instr, &new_srcs[i].src, &tex->src[i].src);
> -         }
> -
> -         ralloc_free(tex->src);
> -         tex->src = new_srcs;
> -
> -         /* Now we can go ahead and move the source over to being a
> -          * first-class texture source.
> -          */
> -         tex->src[tex->num_srcs].src_type = src_type;
> -         nir_instr_rewrite_src(&tex->instr, &tex->src[tex->num_srcs].src,
> -                               nir_src_for_ssa(index));
> -         tex->num_srcs++;
> +         nir_tex_instr_add_src(tex, src_type, nir_src_for_ssa(index));
>         } else {
>            *const_index += MIN2(deref_array->base_offset, array_size - 1);
>         }




More information about the mesa-dev mailing list