Mesa (master): nir: Always print non-identity swizzles.

Matt Turner mattst88 at kemper.freedesktop.org
Tue Aug 9 00:55:32 UTC 2016


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

Author: Matt Turner <mattst88 at gmail.com>
Date:   Tue Sep 22 10:30:05 2015 -0700

nir: Always print non-identity swizzles.

Previously we would not print a swizzle on ssa_52 when only its .x
component is used (as seen in the definition of ssa_53):

   vec3 ssa_52 = fadd ssa_51, ssa_51
   vec1 ssa_53 = flog2 ssa_52
   vec1 ssa_54 = flog2 ssa_52.y
   vec1 ssa_55 = flog2 ssa_52.z

But this makes the interpretation of the RHS of the definition difficult
to understand and dependent on the size of the LHS. Just print swizzles
when they are not the identity swizzle, so the previous example is now
printed as:

   vec3 ssa_52 = fadd ssa_51.xyz, ssa_51.xyz
   vec1 ssa_53 = flog2 ssa_52.x
   vec1 ssa_54 = flog2 ssa_52.y
   vec1 ssa_55 = flog2 ssa_52.z

Reviewed-by: Timothy Arceri <timothy.arceri at collabora.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/compiler/nir/nir_print.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 3beb70a..9fa024e 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -186,17 +186,25 @@ print_alu_src(nir_alu_instr *instr, unsigned src, print_state *state)
    print_src(&instr->src[src].src, state);
 
    bool print_swizzle = false;
+   unsigned used_channels = 0;
+
    for (unsigned i = 0; i < 4; i++) {
       if (!nir_alu_instr_channel_used(instr, src, i))
          continue;
 
+      used_channels++;
+
       if (instr->src[src].swizzle[i] != i) {
          print_swizzle = true;
          break;
       }
    }
 
-   if (print_swizzle) {
+   unsigned live_channels = instr->src[src].src.is_ssa
+      ? instr->src[src].src.ssa->num_components
+      : instr->src[src].src.reg.reg->num_components;
+
+   if (print_swizzle || used_channels != live_channels) {
       fprintf(fp, ".");
       for (unsigned i = 0; i < 4; i++) {
          if (!nir_alu_instr_channel_used(instr, src, i))




More information about the mesa-commit mailing list