[Mesa-dev] [PATCH] nir: make various getters take const pointers

Connor Abbott cwabbott0 at gmail.com
Fri Jun 9 18:02:32 UTC 2017


Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>

On Tue, Jun 6, 2017 at 4:25 PM, Grazvydas Ignotas <notasas at gmail.com> wrote:
> This will allow to constify other things.
>
> Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
> ---
>  src/compiler/nir/nir.h          | 25 +++++++++++++------------
>  src/compiler/nir/nir_lower_io.c |  2 +-
>  2 files changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index 3b827bf..ab7ba14 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -436,19 +436,19 @@ nir_instr_prev(nir_instr *instr)
>     else
>        return exec_node_data(nir_instr, prev, node);
>  }
>
>  static inline bool
> -nir_instr_is_first(nir_instr *instr)
> +nir_instr_is_first(const nir_instr *instr)
>  {
> -   return exec_node_is_head_sentinel(exec_node_get_prev(&instr->node));
> +   return exec_node_is_head_sentinel(exec_node_get_prev_const(&instr->node));
>  }
>
>  static inline bool
> -nir_instr_is_last(nir_instr *instr)
> +nir_instr_is_last(const nir_instr *instr)
>  {
> -   return exec_node_is_tail_sentinel(exec_node_get_next(&instr->node));
> +   return exec_node_is_tail_sentinel(exec_node_get_next_const(&instr->node));
>  }
>
>  typedef struct nir_ssa_def {
>     /** for debugging only, can be NULL */
>     const char* name;
> @@ -802,11 +802,12 @@ void nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src,
>  void nir_alu_dest_copy(nir_alu_dest *dest, const nir_alu_dest *src,
>                         nir_alu_instr *instr);
>
>  /* is this source channel used? */
>  static inline bool
> -nir_alu_instr_channel_used(nir_alu_instr *instr, unsigned src, unsigned channel)
> +nir_alu_instr_channel_used(const nir_alu_instr *instr, unsigned src,
> +                           unsigned channel)
>  {
>     if (nir_op_infos[instr->op].input_sizes[src] > 0)
>        return channel < nir_op_infos[instr->op].input_sizes[src];
>
>     return (instr->dest.write_mask >> channel) & 1;
> @@ -1085,11 +1086,11 @@ typedef struct {
>  extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
>
>
>  #define INTRINSIC_IDX_ACCESSORS(name, flag, type)                             \
>  static inline type                                                            \
> -nir_intrinsic_##name(nir_intrinsic_instr *instr)                              \
> +nir_intrinsic_##name(const nir_intrinsic_instr *instr)                        \
>  {                                                                             \
>     const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];   \
>     assert(info->index_map[NIR_INTRINSIC_##flag] > 0);                         \
>     return instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1];      \
>  }                                                                             \
> @@ -1219,11 +1220,11 @@ typedef struct {
>      */
>     nir_deref_var *sampler;
>  } nir_tex_instr;
>
>  static inline unsigned
> -nir_tex_instr_dest_size(nir_tex_instr *instr)
> +nir_tex_instr_dest_size(const nir_tex_instr *instr)
>  {
>     switch (instr->op) {
>     case nir_texop_txs: {
>        unsigned ret;
>        switch (instr->sampler_dim) {
> @@ -1268,11 +1269,11 @@ nir_tex_instr_dest_size(nir_tex_instr *instr)
>
>  /* Returns true if this texture operation queries something about the texture
>   * rather than actually sampling it.
>   */
>  static inline bool
> -nir_tex_instr_is_query(nir_tex_instr *instr)
> +nir_tex_instr_is_query(const nir_tex_instr *instr)
>  {
>     switch (instr->op) {
>     case nir_texop_txs:
>     case nir_texop_lod:
>     case nir_texop_texture_samples:
> @@ -1291,11 +1292,11 @@ nir_tex_instr_is_query(nir_tex_instr *instr)
>        unreachable("Invalid texture opcode");
>     }
>  }
>
>  static inline nir_alu_type
> -nir_tex_instr_src_type(nir_tex_instr *instr, unsigned src)
> +nir_tex_instr_src_type(const nir_tex_instr *instr, unsigned src)
>  {
>     switch (instr->src[src].src_type) {
>     case nir_tex_src_coord:
>        switch (instr->op) {
>        case nir_texop_txf:
> @@ -1335,11 +1336,11 @@ nir_tex_instr_src_type(nir_tex_instr *instr, unsigned src)
>        unreachable("Invalid texture source type");
>     }
>  }
>
>  static inline unsigned
> -nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)
> +nir_tex_instr_src_size(const nir_tex_instr *instr, unsigned src)
>  {
>     if (instr->src[src].src_type == nir_tex_src_coord)
>        return instr->coord_components;
>
>     /* The MCS value is expected to be a vec4 returned by a txf_ms_mcs */
> @@ -1357,11 +1358,11 @@ nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)
>
>     return 1;
>  }
>
>  static inline int
> -nir_tex_instr_src_index(nir_tex_instr *instr, nir_tex_src_type type)
> +nir_tex_instr_src_index(const nir_tex_instr *instr, nir_tex_src_type type)
>  {
>     for (unsigned i = 0; i < instr->num_srcs; i++)
>        if (instr->src[i].src_type == type)
>           return (int) i;
>
> @@ -2392,11 +2393,11 @@ bool nir_lower_io(nir_shader *shader,
>                    int (*type_size)(const struct glsl_type *),
>                    nir_lower_io_options);
>  nir_src *nir_get_io_offset_src(nir_intrinsic_instr *instr);
>  nir_src *nir_get_io_vertex_index_src(nir_intrinsic_instr *instr);
>
> -bool nir_is_per_vertex_io(nir_variable *var, gl_shader_stage stage);
> +bool nir_is_per_vertex_io(const nir_variable *var, gl_shader_stage stage);
>
>  void nir_lower_io_types(nir_shader *shader);
>  bool nir_lower_regs_to_ssa_impl(nir_function_impl *impl);
>  bool nir_lower_regs_to_ssa(nir_shader *shader);
>  bool nir_lower_vars_to_ssa(nir_shader *shader);
> diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
> index 1ae2cc7..bb1cdec 100644
> --- a/src/compiler/nir/nir_lower_io.c
> +++ b/src/compiler/nir/nir_lower_io.c
> @@ -66,11 +66,11 @@ nir_assign_var_locations(struct exec_list *var_list, unsigned *size,
>  /**
>   * Return true if the given variable is a per-vertex input/output array.
>   * (such as geometry shader inputs).
>   */
>  bool
> -nir_is_per_vertex_io(nir_variable *var, gl_shader_stage stage)
> +nir_is_per_vertex_io(const nir_variable *var, gl_shader_stage stage)
>  {
>     if (var->data.patch || !glsl_type_is_array(var->type))
>        return false;
>
>     if (var->data.mode == nir_var_shader_in)
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list