Re: [Mesa-dev] [PATCH] nir: make various getters take const pointers
Reviewed-by: Connor AbbottOn Tue, Jun 6, 2017 at 4:25 PM, Grazvydas Ignotas wrote: > This will allow to constify other things. > > Signed-off-by: Grazvydas Ignotas > --- > 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(>node)); > + return exec_node_is_head_sentinel(exec_node_get_prev_const(>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(>node)); > + return exec_node_is_tail_sentinel(exec_node_get_next_const(>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 = _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) >
Re: [Mesa-dev] [PATCH] nir: make various getters take const pointers
On Friday, 2017-06-09 20:23:04 +0300, Grazvydas Ignotas wrote: > Ping. Boring patch, should be easy to review or NAK. Don't know anything about NIR, so no clue if it's a good idea, but I personally like `const` (I think it should've been the default :P) and this patch looks good to me: Reviewed-by: Eric Engestrom> > On Wed, Jun 7, 2017 at 2:25 AM, Grazvydas Ignotas wrote: > > This will allow to constify other things. > > > > Signed-off-by: Grazvydas Ignotas > > --- > > 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(>node)); > > + return > > exec_node_is_head_sentinel(exec_node_get_prev_const(>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(>node)); > > + return > > exec_node_is_tail_sentinel(exec_node_get_next_const(>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 = > > _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
Re: [Mesa-dev] [PATCH] nir: make various getters take const pointers
Ping. Boring patch, should be easy to review or NAK. On Wed, Jun 7, 2017 at 2:25 AM, Grazvydas Ignotaswrote: > This will allow to constify other things. > > Signed-off-by: Grazvydas Ignotas > --- > 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(>node)); > + return exec_node_is_head_sentinel(exec_node_get_prev_const(>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(>node)); > + return exec_node_is_tail_sentinel(exec_node_get_next_const(>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 = _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) >
[Mesa-dev] [PATCH] nir: make various getters take const pointers
This will allow to constify other things. Signed-off-by: Grazvydas Ignotas--- 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(>node)); + return exec_node_is_head_sentinel(exec_node_get_prev_const(>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(>node)); + return exec_node_is_tail_sentinel(exec_node_get_next_const(>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 = _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);