[Mesa-dev] [PATCH 06/22] nir/format_convert: Add vec mask and sign-extend helpers

Jason Ekstrand jason at jlekstrand.net
Mon Aug 20 18:49:24 UTC 2018


On Mon, Aug 20, 2018 at 2:42 AM Kenneth Graunke <kenneth at whitecape.org>
wrote:

> On Friday, August 17, 2018 1:06:12 PM PDT Jason Ekstrand wrote:
> > ---
> >  src/compiler/nir/nir_format_convert.h | 35 +++++++++++++++++++++------
> >  1 file changed, 27 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/compiler/nir/nir_format_convert.h
> b/src/compiler/nir/nir_format_convert.h
> > index b1345f7263b..305273cdfdd 100644
> > --- a/src/compiler/nir/nir_format_convert.h
> > +++ b/src/compiler/nir/nir_format_convert.h
> > @@ -50,6 +50,32 @@ nir_mask_shift_or(struct nir_builder *b, nir_ssa_def
> *dst, nir_ssa_def *src,
> >     return nir_ior(b, nir_mask_shift(b, src, src_mask, src_left_shift),
> dst);
> >  }
> >
> > +static inline nir_ssa_def *
> > +nir_format_mask_uvec(nir_builder *b, nir_ssa_def *src,
> > +                     const unsigned *bits)
> > +{
> > +   nir_const_value mask;
> > +   for (unsigned i = 0; i < src->num_components; i++) {
> > +      assert(bits[i] < 32);
> > +      mask.u32[i] = (1u << bits[i]) - 1;
> > +   }
> > +   return nir_iand(b, src, nir_build_imm(b, src->num_components, 32,
> mask));
> > +}
> > +
> > +static inline nir_ssa_def *
> > +nir_format_sign_extend_ivec(nir_builder *b, nir_ssa_def *src,
> > +                            const unsigned *bits)
> > +{
> > +   assert(src->num_components <= 4);
> > +   nir_ssa_def *comps[4];
> > +   for (unsigned i = 0; i < src->num_components; i++) {
> > +      nir_ssa_def *shift = nir_imm_int(b, src->bit_size - bits[i]);
> > +      comps[i] = nir_ishr(b, nir_ishl(b, nir_channel(b, src, i),
> shift), shift);
> > +   }
> > +   return nir_vec(b, comps, src->num_components);
> > +}
> > +
> > +
> >  static inline nir_ssa_def *
> >  nir_format_unpack_int(nir_builder *b, nir_ssa_def *packed,
> >                        const unsigned *bits, unsigned num_components,
> > @@ -117,14 +143,7 @@ static inline nir_ssa_def *
> >  nir_format_pack_uint(nir_builder *b, nir_ssa_def *color,
> >                       const unsigned *bits, unsigned num_components)
> >  {
> > -   nir_const_value mask;
> > -   for (unsigned i = 0; i < num_components; i++) {
>
> This used to operate on the num_components parameter to
> nir_format_pack_uint, but now it operates on color->num_components
> instead.  That's probably OK...do we even need the parameter?
>

RE masking, yes the new masking helper doesn't take a number of
components.  If the number of components in the source SSA def is too
small, you're toast; if it's too large, the optimizer will eventually throw
away the unneeded instructions.

For the packing, however, the number of components is needed since it
controls how much of the bits array you read and how much you try to cram
into the resulting uint32.

--Jason


> Nothing actually uses this function in master today AFAICT...
>
> Patches 1-3 (with Bas's fixes) and 5-7 are:
> Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
>
> > -      assert(bits[i] < 32);
> > -      mask.u32[i] = (1u << bits[i]) - 1;
> > -   }
> > -   nir_ssa_def *mask_imm = nir_build_imm(b, num_components, 32, mask);
> > -
> > -   return nir_format_pack_uint_unmasked(b, nir_iand(b, color, mask_imm),
> > +   return nir_format_pack_uint_unmasked(b, nir_format_mask_uvec(b,
> color, bits),
> >                                          bits, num_components);
> >  }
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180820/31bc5c0d/attachment.html>


More information about the mesa-dev mailing list