mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-02 06:40:22 +01:00
nir/builder: Add a nir_trim_vector helper
This pattern pops up a bunch and the semantics of nir_channels() aren't very convenient much of the time. Let's add a nir_trim_vector() which matches nir_pad_vector(). Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16309>
This commit is contained in:
parent
23bcaaeaaa
commit
87e49ea977
1 changed files with 10 additions and 0 deletions
|
|
@ -1003,6 +1003,16 @@ nir_bitcast_vector(nir_builder *b, nir_ssa_def *src, unsigned dest_bit_size)
|
|||
return nir_extract_bits(b, &src, 1, 0, dest_num_components, dest_bit_size);
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_trim_vector(nir_builder *b, nir_ssa_def *src, unsigned num_components)
|
||||
{
|
||||
assert(src->num_components >= num_components);
|
||||
if (src->num_components == num_components)
|
||||
return src;
|
||||
|
||||
return nir_channels(b, src, nir_component_mask(num_components));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pad a value to N components with undefs of matching bit size.
|
||||
* If the value already contains >= num_components, it is returned without change.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue