Mesa (main): nir/lower_alu_to_scalar: don't skip gaps in write_mask

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 26 09:59:25 UTC 2021


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

Author: Daniel Schürmann <daniel at schuermann.dev>
Date:   Thu Jul 22 10:25:52 2021 +0200

nir/lower_alu_to_scalar: don't skip gaps in write_mask

Otherwise, this may lead to segmentation faults.

Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11411>

---

 src/compiler/nir/nir_lower_alu_to_scalar.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir_lower_alu_to_scalar.c b/src/compiler/nir/nir_lower_alu_to_scalar.c
index 023cecefca0..2833774c621 100644
--- a/src/compiler/nir/nir_lower_alu_to_scalar.c
+++ b/src/compiler/nir/nir_lower_alu_to_scalar.c
@@ -274,10 +274,7 @@ lower_alu_instr_scalar(nir_builder *b, nir_instr *instr, void *_data)
    unsigned num_components = alu->dest.dest.ssa.num_components;
    nir_ssa_def *comps[NIR_MAX_VEC_COMPONENTS] = { NULL };
 
-   for (chan = 0; chan < NIR_MAX_VEC_COMPONENTS; chan++) {
-      if (!(alu->dest.write_mask & (1 << chan)))
-         continue;
-
+   for (chan = 0; chan < num_components; chan++) {
       nir_alu_instr *lower = nir_alu_instr_create(b->shader, alu->op);
       for (i = 0; i < num_src; i++) {
          /* We only handle same-size-as-dest (input_sizes[] == 0) or scalar
@@ -289,7 +286,8 @@ lower_alu_instr_scalar(nir_builder *b, nir_instr *instr, void *_data)
 
          nir_alu_src_copy(&lower->src[i], &alu->src[i], lower);
          for (int j = 0; j < NIR_MAX_VEC_COMPONENTS; j++)
-            lower->src[i].swizzle[j] = alu->src[i].swizzle[src_chan];
+            lower->src[i].swizzle[j] = alu->dest.write_mask & (1 << chan) ?
+                                       alu->src[i].swizzle[src_chan] : 0;
       }
 
       nir_alu_ssa_dest_init(lower, 1, alu->dest.dest.ssa.bit_size);



More information about the mesa-commit mailing list