nir: Add nir_type_convert

Generalizes nir_convert_to_bit_size, which we implement as a
special-case.

v2: Take a sized dest type but allow unsized or sized source to address
Jason's feedback. Shorten name.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8339>
This commit is contained in:
Alyssa Rosenzweig
2021-01-05 14:42:10 -05:00
committed by Marge Bot
parent f280367a27
commit 6b19711645

View File

@@ -1663,19 +1663,30 @@ nir_scoped_memory_barrier(nir_builder *b,
nir_scoped_barrier(b, NIR_SCOPE_NONE, scope, semantics, modes);
}
static inline nir_ssa_def *
nir_type_convert(nir_builder *b,
nir_ssa_def *src,
nir_alu_type src_type,
nir_alu_type dest_type)
{
assert(nir_alu_type_get_type_size(src_type) == 0 ||
nir_alu_type_get_type_size(src_type) == src->bit_size);
src_type = (nir_alu_type) (src_type | src->bit_size);
nir_op opcode =
nir_type_conversion_op(src_type, dest_type, nir_rounding_mode_undef);
return nir_build_alu(b, opcode, src, NULL, NULL, NULL);
}
static inline nir_ssa_def *
nir_convert_to_bit_size(nir_builder *b,
nir_ssa_def *src,
nir_alu_type type,
unsigned bit_size)
{
nir_alu_type base_type = nir_alu_type_get_base_type(type);
nir_alu_type dst_type = (nir_alu_type)(bit_size | base_type);
nir_op opcode =
nir_type_conversion_op(type, dst_type, nir_rounding_mode_undef);
return nir_build_alu(b, opcode, src, NULL, NULL, NULL);
return nir_type_convert(b, src, type, (nir_alu_type) (type | bit_size));
}
static inline nir_ssa_def *