<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 1, 2018 at 6:49 AM, Pohjolainen, Topi <span dir="ltr"><<a href="mailto:topi.pohjolainen@gmail.com" target="_blank">topi.pohjolainen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Feb 26, 2018 at 08:42:42AM -0800, Jason Ekstrand wrote:<br>
> On Mon, Feb 26, 2018 at 6:19 AM, Pohjolainen, Topi <<br>
> <a href="mailto:topi.pohjolainen@gmail.com">topi.pohjolainen@gmail.com</a>> wrote:<br>
><br>
> > On Fri, Jan 26, 2018 at 05:59:34PM -0800, Jason Ekstrand wrote:<br>
> > > ---<br>
> > >  src/intel/isl/isl.c | 30 ++++++++++++++++++++++++++++++<br>
> > >  src/intel/isl/isl.h |  2 ++<br>
> > >  2 files changed, 32 insertions(+)<br>
> > ><br>
> > > diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c<br>
> > > index a2d3ae6..420d387 100644<br>
> > > --- a/src/intel/isl/isl.c<br>
> > > +++ b/src/intel/isl/isl.c<br>
> > > @@ -2379,3 +2379,33 @@ isl_swizzle_compose(struct isl_swizzle first,<br>
> > struct isl_swizzle second)<br>
> > >        .a = swizzle_select(first.a, second),<br>
> > >     };<br>
> > >  }<br>
> > > +<br>
> > > +/**<br>
> > > + * Returns a swizzle that is the pseudo-inverse of this swizzle.<br>
> > > + */<br>
> > > +struct isl_swizzle<br>
> > > +isl_swizzle_invert(struct isl_swizzle swizzle)<br>
> > > +{<br>
> > > +   /* Default to zero for channels which do not show up in the swizzle<br>
> > */<br>
> > > +   enum isl_channel_select chans[4] = {<br>
> > > +      ISL_CHANNEL_SELECT_ZERO,<br>
> > > +      ISL_CHANNEL_SELECT_ZERO,<br>
> > > +      ISL_CHANNEL_SELECT_ZERO,<br>
> > > +      ISL_CHANNEL_SELECT_ZERO,<br>
> > > +   };<br>
> > > +<br>
> > > +   /* We go in ABGR order so that, if there are any duplicates, the<br>
> > first one<br>
> > > +    * is taken if you look at it in RGBA order.  This is what Haswell<br>
> > hardware<br>
> > > +    * does for render target swizzles.<br>
> > > +    */<br>
> > > +   if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)<br>
> > > +      chans[swizzle.a - ISL_CHANNEL_SELECT_RED] =<br>
> > ISL_CHANNEL_SELECT_ALPHA;<br>
> > > +   if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)<br>
> > > +      chans[swizzle.b - ISL_CHANNEL_SELECT_RED] =<br>
> > ISL_CHANNEL_SELECT_BLUE;<br>
> > > +   if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)<br>
> > > +      chans[swizzle.g - ISL_CHANNEL_SELECT_RED] =<br>
> > ISL_CHANNEL_SELECT_GREEN;<br>
> > > +   if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)<br>
> > > +      chans[swizzle.r - ISL_CHANNEL_SELECT_RED] =<br>
> > ISL_CHANNEL_SELECT_RED;<br>
> > > +<br>
> > > +   return (struct isl_swizzle) { chans[0], chans[1], chans[2], chans[3]<br>
> > };<br>
> ><br>
> > If given<br>
> ><br>
> >     swizzle == { ISL_CHANNEL_SELECT_RED,<br>
> >                  ISL_CHANNEL_SELECT_GREEN,<br>
> >                  ISL_CHANNEL_SELECT_BLUE,<br>
> >                  ISL_CHANNEL_SELECT_ALPHA },<br>
> ><br>
> > then<br>
> >     chans[ISL_CHANNEL_SELECT_ALPHA - ISL_CHANNEL_SELECT_RED] == chans[3] ==<br>
> >     ISL_CHANNEL_SELECT_ALPHA<br>
> ><br>
> > and so on, and the function returns the same swizzle as given?<br>
><br>
><br>
> Yes, that is how the subtraction works.<br>
<br>
</div></div>I was expecting it to "invert" that, i.e., to return ABGR. But okay, if given<br>
identity swizzle it returns identity.<br>
<br>
In order to understand how it works I thought I read further the series to<br>
find an example - there seems to be one in patch 12 and another in patch 16.<br>
In case of 16 and destination format B4G4R4A4 the swizzle looks to be BGRA<br>
(looking at anv_formats.c::main_formats).<br>
<br>
In that case we get:<br>
<br>
   chans[ALPHA - RED] = chans[3] = ALPHA<br>
   chans[RED   - RED] = chans[0] = BLUE<br>
   chans[GREEN - RED] = chans[1] = GREEN<br>
   chans[BLUE  - RED] = chans[2] = RED<br>
<br>
and as a swizzle BLUE, GREEN, RED, ALPHA. This is again the same as given.<br>
What am I not understanding?<br>
</blockquote></div><br></div><div class="gmail_extra">I think the confusion is what "invert" means.  It doesn't mean we reverse the channels or anything like that.  It's an inverse in the sense that when you compose a swizzle with it's inverse, you get the identity back out.  The inverse of BGRA is BGRA because if you apply the BGRA swizzle twice, you get RGBA again.  If you start with ARGB, you get<br><br></div><div class="gmail_extra">chans[BLUE - RED] = chans[2] = ALPHA<br></div><div class="gmail_extra">chans[GREEN - RED] = chans[1] = BLUE<br></div><div class="gmail_extra">chans[RED - RED] = chans[0] = GREEN<br></div><div class="gmail_extra">chans[ALPHA - RED] = chans[3] = RED<br><br></div><div class="gmail_extra">This gives an inverse swizzle of GBAR which is certainly a weird swizzle.  However, if you apply ARGB and then GBAR, you get back to identity since one is a left rotate and one is a right rotate.  Does that make a bit more sense?<br></div></div>