Mesa (main): nir/opt_shrink_vectors: Round to supported vec size

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jul 10 18:50:03 UTC 2022


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

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Wed Jun 22 15:58:16 2022 -0400

nir/opt_shrink_vectors: Round to supported vec size

The set of supported vector sizes in NIR has holes in it. For example, we
support vec5 and vec8, but not vec6 or vec7. However, this pass did not take
that into account, and would happily shrink a vec8 down to a vec7, causing NIR
validation to fail. Instead, the pass should round up to the next supported
vector size.

Fixes NIR validation fail in OpenCL's test_basic hiloeo subtest.

v2: Clamp -> round rename.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17194>

---

 src/compiler/nir/nir_opt_shrink_vectors.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/compiler/nir/nir_opt_shrink_vectors.c b/src/compiler/nir/nir_opt_shrink_vectors.c
index 61d45462558..cc6e5add05e 100644
--- a/src/compiler/nir/nir_opt_shrink_vectors.c
+++ b/src/compiler/nir/nir_opt_shrink_vectors.c
@@ -45,6 +45,18 @@
 
 #include "nir.h"
 #include "nir_builder.h"
+#include "util/u_math.h"
+
+/*
+ * Round up a vector size to a vector size that's valid in NIR. At present, NIR
+ * supports only vec2-5, vec8, and vec16. Attempting to generate other sizes
+ * will fail validation.
+ */
+static unsigned
+round_up_components(unsigned n)
+{
+   return (n > 5) ? util_next_power_of_two(n) : n;
+}
 
 static bool
 shrink_dest_to_read_mask(nir_ssa_def *def)
@@ -66,6 +78,10 @@ shrink_dest_to_read_mask(nir_ssa_def *def)
    if (!mask)
       return false;
 
+   unsigned rounded = round_up_components(last_bit);
+   assert(rounded <= def->num_components);
+   last_bit = rounded;
+
    if (def->num_components > last_bit) {
       def->num_components = last_bit;
       return true;
@@ -179,6 +195,10 @@ opt_shrink_vectors_alu(nir_builder *b, nir_alu_instr *instr)
    unsigned last_bit = util_last_bit(mask);
    unsigned num_components = util_bitcount(mask);
 
+   unsigned rounded = round_up_components(num_components);
+   assert(rounded <= def->num_components);
+   num_components = rounded;
+
    /* return, if there is nothing to do */
    if (mask == 0 || num_components == def->num_components)
       return false;
@@ -293,6 +313,10 @@ opt_shrink_vectors_load_const(nir_load_const_instr *instr)
       }
    }
 
+   unsigned rounded = round_up_components(num_components);
+   assert(rounded <= def->num_components);
+   num_components = rounded;
+
    if (num_components == def->num_components)
       return false;
 



More information about the mesa-commit mailing list