Module: Mesa
Branch: main
Commit: 1d22465362536d9f347790e7bc901e7036566602
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=1d22465362536d9f347790e7bc901e7036566602

Author: Jason Ekstrand <[email protected]>
Date:   Mon May  9 15:16:16 2022 -0500

nir/builder: Add a nir_resize_vector helper

We're about to use this a couple of places.

Reviewed-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16309>

---

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

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index ca07ea7f34b..928d7797f3f 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -1087,6 +1087,21 @@ nir_pad_vec4(nir_builder *b, nir_ssa_def *src)
    return nir_pad_vector(b, src, 4);
 }
 
+/**
+ * Resizes a vector by either trimming off components or adding undef
+ * components, as needed.  Only use this helper if it's actually what you
+ * need.  Prefer nir_pad_vector() or nir_trim_vector() instead if you know a
+ * priori which direction you're resizing.
+ */
+static inline nir_ssa_def *
+nir_resize_vector(nir_builder *b, nir_ssa_def *src, unsigned num_components)
+{
+   if (src->num_components < num_components)
+      return nir_pad_vector(b, src, num_components);
+   else
+      return nir_trim_vector(b, src, num_components);
+}
+
 nir_ssa_def *
 nir_ssa_for_src(nir_builder *build, nir_src src, int num_components);
 

Reply via email to