[Mesa-dev] Mesa (master): nir/print: Don't print extra swizzzle components

Jason Ekstrand jason at jlekstrand.net
Wed Apr 1 16:14:13 PDT 2015


On Wed, Apr 1, 2015 at 1:52 PM, Connor Abbott <cwabbott0 at gmail.com> wrote:
> On Wed, Apr 1, 2015 at 4:44 PM, Eric Anholt <eric at anholt.net> wrote:
>> Jason Ekstrand <jekstrand at kemper.freedesktop.org> writes:
>>
>>> Module: Mesa
>>> Branch: master
>>> Commit: 793a94d6b5fc589ca8d7475347def4e222cd3d7c
>>> URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=793a94d6b5fc589ca8d7475347def4e222cd3d7c
>>>
>>> Author: Jason Ekstrand <jason.ekstrand at intel.com>
>>> Date:   Mon Mar 23 18:20:21 2015 -0700
>>>
>>> nir/print: Don't print extra swizzzle components
>>>
>>> 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 at whitecape.org>
>>>
>>> ---
>>>
>>>  src/glsl/nir/nir_print.c |   26 +++++++++++++++++++-------
>>>  1 file changed, 19 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
>>> index fa11a31..53fada8 100644
>>> --- a/src/glsl/nir/nir_print.c
>>> +++ b/src/glsl/nir/nir_print.c
>>> @@ -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);
>>>     }
>>>  }
>>
>> Won't this skip printing the .yz part of a dp3's sources?

Yes, it will.  I'll send a patch to fix that.

> Yeah, this seems bogus for non-per-component sources... you need to
> use nir_alu_instr_channel_used().

Yup.

>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list