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:
Jason Ekstrand
2022-05-09 12:15:44 -05:00
committed by Marge Bot
parent 244b654de6
commit 352e32e5ba
9 changed files with 27 additions and 22 deletions

View File

@@ -100,7 +100,7 @@ image_address(nir_builder *b, const struct intel_device_info *devinfo,
nir_channel(b, coord, 1));
} else {
unsigned dims = glsl_get_sampler_coordinate_components(deref->type);
coord = nir_channels(b, coord, (1 << dims) - 1);
coord = nir_trim_vector(b, coord, dims);
}
nir_ssa_def *offset = load_image_param(b, deref, OFFSET);
@@ -457,7 +457,7 @@ convert_color_for_store(nir_builder *b, const struct intel_device_info *devinfo,
struct format_info image = get_format_info(image_fmt);
struct format_info lower = get_format_info(lower_fmt);
color = nir_channels(b, color, (1 << image.chans) - 1);
color = nir_trim_vector(b, color, image.chans);
if (image_fmt == lower_fmt)
return color;