nir/print: Don't print extra swizzzle components
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 24 Mar 2015 01:20:21 +0000 (18:20 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 1 Apr 2015 19:49:49 +0000 (12:49 -0700)
Previously, NIR would just print 4 swizzle components if the swizzle was
anything other than foo.xyzw.  This creates lots of noise if, for example,
you have a one-component element with a swizzle of foo.xxxx.

Reviewed-by: Kenneth Grunke <kenneth@whitecape.org>
src/glsl/nir/nir_print.c

index fa11a312e51155c5f725551fdff7b7e11c6efc03..53fada8eb95caf064fe720845b98b8f649083fc4 100644 (file)
@@ -137,7 +137,7 @@ print_dest(nir_dest *dest, FILE *fp)
 }
 
 static void
-print_alu_src(nir_alu_src *src, FILE *fp)
+print_alu_src(nir_alu_src *src, uint8_t read_mask, FILE *fp)
 {
    if (src->negate)
       fprintf(fp, "-");
@@ -146,13 +146,25 @@ print_alu_src(nir_alu_src *src, FILE *fp)
 
    print_src(&src->src, fp);
 
-   if (src->swizzle[0] != 0 ||
-       src->swizzle[1] != 1 ||
-       src->swizzle[2] != 2 ||
-       src->swizzle[3] != 3) {
+   bool print_swizzle = false;
+   for (unsigned i = 0; i < 4; i++) {
+      if (read_mask >> i == 0)
+         break;
+
+      if (src->swizzle[i] != i) {
+         print_swizzle = true;
+         break;
+      }
+   }
+
+   if (print_swizzle) {
       fprintf(fp, ".");
-      for (unsigned i = 0; i < 4; i++)
+      for (unsigned i = 0; i < 4; i++) {
+         if (read_mask >> i == 0)
+            break;
+
          fprintf(fp, "%c", "xyzw"[src->swizzle[i]]);
+      }
    }
 
    if (src->abs)
@@ -189,7 +201,7 @@ print_alu_instr(nir_alu_instr *instr, FILE *fp)
       if (i != 0)
          fprintf(fp, ", ");
 
-      print_alu_src(&instr->src[i], fp);
+      print_alu_src(&instr->src[i], instr->dest.write_mask, fp);
    }
 }