[Mesa-dev] [PATCH 05/29] intel/isl: Add a helper for inverting swizzles
Pohjolainen, Topi
topi.pohjolainen at gmail.com
Thu Mar 1 14:49:50 UTC 2018
On Mon, Feb 26, 2018 at 08:42:42AM -0800, Jason Ekstrand wrote:
> On Mon, Feb 26, 2018 at 6:19 AM, Pohjolainen, Topi <
> topi.pohjolainen at gmail.com> wrote:
>
> > On Fri, Jan 26, 2018 at 05:59:34PM -0800, Jason Ekstrand wrote:
> > > ---
> > > src/intel/isl/isl.c | 30 ++++++++++++++++++++++++++++++
> > > src/intel/isl/isl.h | 2 ++
> > > 2 files changed, 32 insertions(+)
> > >
> > > diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c
> > > index a2d3ae6..420d387 100644
> > > --- a/src/intel/isl/isl.c
> > > +++ b/src/intel/isl/isl.c
> > > @@ -2379,3 +2379,33 @@ isl_swizzle_compose(struct isl_swizzle first,
> > struct isl_swizzle second)
> > > .a = swizzle_select(first.a, second),
> > > };
> > > }
> > > +
> > > +/**
> > > + * Returns a swizzle that is the pseudo-inverse of this swizzle.
> > > + */
> > > +struct isl_swizzle
> > > +isl_swizzle_invert(struct isl_swizzle swizzle)
> > > +{
> > > + /* Default to zero for channels which do not show up in the swizzle
> > */
> > > + enum isl_channel_select chans[4] = {
> > > + ISL_CHANNEL_SELECT_ZERO,
> > > + ISL_CHANNEL_SELECT_ZERO,
> > > + ISL_CHANNEL_SELECT_ZERO,
> > > + ISL_CHANNEL_SELECT_ZERO,
> > > + };
> > > +
> > > + /* We go in ABGR order so that, if there are any duplicates, the
> > first one
> > > + * is taken if you look at it in RGBA order. This is what Haswell
> > hardware
> > > + * does for render target swizzles.
> > > + */
> > > + if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
> > > + chans[swizzle.a - ISL_CHANNEL_SELECT_RED] =
> > ISL_CHANNEL_SELECT_ALPHA;
> > > + if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
> > > + chans[swizzle.b - ISL_CHANNEL_SELECT_RED] =
> > ISL_CHANNEL_SELECT_BLUE;
> > > + if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
> > > + chans[swizzle.g - ISL_CHANNEL_SELECT_RED] =
> > ISL_CHANNEL_SELECT_GREEN;
> > > + if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
> > > + chans[swizzle.r - ISL_CHANNEL_SELECT_RED] =
> > ISL_CHANNEL_SELECT_RED;
> > > +
> > > + return (struct isl_swizzle) { chans[0], chans[1], chans[2], chans[3]
> > };
> >
> > If given
> >
> > swizzle == { ISL_CHANNEL_SELECT_RED,
> > ISL_CHANNEL_SELECT_GREEN,
> > ISL_CHANNEL_SELECT_BLUE,
> > ISL_CHANNEL_SELECT_ALPHA },
> >
> > then
> > chans[ISL_CHANNEL_SELECT_ALPHA - ISL_CHANNEL_SELECT_RED] == chans[3] ==
> > ISL_CHANNEL_SELECT_ALPHA
> >
> > and so on, and the function returns the same swizzle as given?
>
>
> Yes, that is how the subtraction works.
I was expecting it to "invert" that, i.e., to return ABGR. But okay, if given
identity swizzle it returns identity.
In order to understand how it works I thought I read further the series to
find an example - there seems to be one in patch 12 and another in patch 16.
In case of 16 and destination format B4G4R4A4 the swizzle looks to be BGRA
(looking at anv_formats.c::main_formats).
In that case we get:
chans[ALPHA - RED] = chans[3] = ALPHA
chans[RED - RED] = chans[0] = BLUE
chans[GREEN - RED] = chans[1] = GREEN
chans[BLUE - RED] = chans[2] = RED
and as a swizzle BLUE, GREEN, RED, ALPHA. This is again the same as given.
What am I not understanding?
More information about the mesa-dev
mailing list