nir: introduce and use nir_component_mask

The BITFIELD_MASK() macro is intended for using with actual bitfields,
not with nir_component_mask_t. This means we do some extra work to
handle values that are invalid for nir_component_mask_t in the first
place.

This eliminates some warnings on Clang, where the compiler complains
about casting UINT32_MAX to UINT16_MAX.

Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15547>
This commit is contained in:
Erik Faye-Lund 2022-03-24 10:36:06 +01:00 committed by Marge Bot
parent be952e71a7
commit ff05137c2d
7 changed files with 15 additions and 8 deletions

View File

@ -125,6 +125,13 @@ nir_num_components_valid(unsigned num_components)
num_components == 16;
}
static inline nir_component_mask_t
nir_component_mask(unsigned num_components)
{
assert(nir_num_components_valid(num_components));
return (1u << num_components) - 1;
}
void
nir_process_debug_variable(void);

View File

@ -392,7 +392,7 @@ nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data)
blended = nir_color_mask(b, options->rt[rt].colormask, blended, dst);
if (src_num_comps != 4)
blended = nir_channels(b, blended, BITFIELD_MASK(src_num_comps));
blended = nir_channels(b, blended, nir_component_mask(src_num_comps));
/* Write out the final color instead of the input */
nir_instr_rewrite_src_ssa(instr, &intr->src[1], blended);

View File

@ -140,7 +140,7 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
if (tex->is_sparse) {
unsigned load_result_size = load->dest.ssa.num_components - 1;
unsigned load_result_mask = BITFIELD_MASK(load_result_size);
nir_component_mask_t load_result_mask = nir_component_mask(load_result_size);
nir_ssa_def *res = nir_channels(
&b, &tex->dest.ssa, load_result_mask | 0x10);

View File

@ -72,7 +72,7 @@ nu_handle_compare(const nir_lower_non_uniform_access_options *options,
nir_component_mask_t channel_mask = ~0;
if (options->callback)
channel_mask = options->callback(handle->src, options->callback_data);
channel_mask &= BITFIELD_MASK(handle->handle->num_components);
channel_mask &= nir_component_mask(handle->handle->num_components);
nir_ssa_def *channels[NIR_MAX_VEC_COMPONENTS];
for (unsigned i = 0; i < handle->handle->num_components; i++)

View File

@ -98,7 +98,7 @@ uint_to_ballot_type(nir_builder *b, nir_ssa_def *value,
* have enough ballot bits.
*/
if (value->num_components > num_components)
value = nir_channels(b, value, BITFIELD_MASK(num_components));
value = nir_channels(b, value, nir_component_mask(num_components));
return value;
}

View File

@ -192,7 +192,7 @@ gather_vars_written(struct copy_prop_var_state *state,
nir_src_as_deref(*nir_get_shader_call_payload_src(intrin));
nir_component_mask_t mask =
BITFIELD_MASK(glsl_get_vector_elements(payload->type));
nir_component_mask(glsl_get_vector_elements(payload->type));
struct hash_entry *ht_entry =
_mesa_hash_table_search(written->derefs, payload);
@ -1151,7 +1151,7 @@ copy_prop_vars_block(struct copy_prop_var_state *state,
nir_deref_and_path payload = {
nir_src_as_deref(*nir_get_shader_call_payload_src(intrin)), NULL};
nir_component_mask_t full_mask =
BITFIELD_MASK(glsl_get_vector_elements(payload.instr->type));
nir_component_mask(glsl_get_vector_elements(payload.instr->type));
kill_aliases(state, copies, &payload, full_mask);
break;
}

View File

@ -3157,7 +3157,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
unsigned result_size = glsl_get_vector_elements(ret_type->type);
dest->elems[0]->def = nir_channel(&b->nb, &instr->dest.ssa, result_size);
dest->elems[1]->def = nir_channels(&b->nb, &instr->dest.ssa,
BITFIELD_MASK(result_size));
nir_component_mask(result_size));
vtn_push_ssa_value(b, w[2], dest);
} else {
vtn_push_nir_ssa(b, w[2], &instr->dest.ssa);
@ -3580,7 +3580,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
if (intrin->dest.ssa.bit_size != 32)
dest->elems[0]->def = nir_u2u32(&b->nb, dest->elems[0]->def);
dest->elems[1]->def = nir_channels(&b->nb, result,
BITFIELD_MASK(res_type_size));
nir_component_mask(res_type_size));
vtn_push_ssa_value(b, w[2], dest);
} else {
vtn_push_nir_ssa(b, w[2], result);