Mesa (staging/22.1): nir/builder: Add a nir_trim_vector helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 1 21:17:33 UTC 2022


Module: Mesa
Branch: staging/22.1
Commit: 7d230d3eba6833f91d4cf3dc518bd6777c1501e0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7d230d3eba6833f91d4cf3dc518bd6777c1501e0

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Mon May  9 12:15:44 2022 -0500

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 at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16309>

---

 src/compiler/nir/nir_builder.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 02abd9cd59d..c422eaf87d6 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -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.



More information about the mesa-commit mailing list