nir/lower_subgroups: Pad ballot values before bitcasting

Otherwise, if we cast from a uint32_t to a uint64_t, the bitcast will
fail before we pad.  This happens on Intel.

Fixes: e4e79de2a4 "nir/subgroups: Support > 1 ballot components"
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5045
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11786>
This commit is contained in:
Jason Ekstrand 2021-07-08 14:36:15 -05:00 committed by Marge Bot
parent 439322ad4c
commit a195ef123e
1 changed files with 12 additions and 2 deletions

View File

@ -78,8 +78,18 @@ static nir_ssa_def *
uint_to_ballot_type(nir_builder *b, nir_ssa_def *value,
unsigned num_components, unsigned bit_size)
{
value = nir_bitcast_vector(b, value, bit_size);
return nir_pad_vector_imm_int(b, value, 0, num_components);
assert(util_is_power_of_two_nonzero(num_components));
assert(util_is_power_of_two_nonzero(value->num_components));
/* The ballot type must always have enough bits */
unsigned total_bits = bit_size * num_components;
assert(total_bits >= value->bit_size * value->num_components);
/* If the source doesn't have enough bits, zero-pad */
if (total_bits > value->bit_size * value->num_components)
value = nir_pad_vector_imm_int(b, value, 0, total_bits / value->bit_size);
return nir_bitcast_vector(b, value, bit_size);
}
static nir_ssa_def *