[Mesa-dev] [PATCH v2 13/25] nir: add nir_get_nir_type_for_glsl_type()

Samuel Iglesias Gonsálvez siglesias at igalia.com
Tue Jan 3 12:32:13 UTC 2017


On Mon, 2017-01-02 at 10:16 -0800, Jason Ekstrand wrote:
> On Fri, Dec 16, 2016 at 6:48 AM, Juan A. Suarez Romero <jasuarez at igal
> ia.com> wrote:
> > From: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
> > 
> > Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
> > ---
> >  src/compiler/nir/nir.h | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> > 
> > diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> > index 544d4ba..9310dab 100644
> > --- a/src/compiler/nir/nir.h
> > +++ b/src/compiler/nir/nir.h
> > @@ -670,6 +670,25 @@ nir_alu_type_get_base_type(nir_alu_type type)
> >     return type & NIR_ALU_TYPE_BASE_TYPE_MASK;
> >  }
> > 
> > +static inline nir_alu_type
> > +nir_get_nir_type_for_glsl_type(const struct glsl_type *type)
> > +{
> > +   unsigned bit_size = glsl_get_bit_size(type);
> > +   if (glsl_type_is_boolean(type))
> > +      return (nir_alu_type)(nir_type_bool | bit_size);
> > +
> > +   if (glsl_type_is_integer(type)) {
> > +      if (glsl_get_base_type(type) == GLSL_TYPE_UINT)
> > +         return (nir_alu_type)(nir_type_uint | bit_size);
> > +      else
> > +         return (nir_alu_type)(nir_type_int | bit_size);
> > +   }
> > +
> > +   if (glsl_type_is_float(type))
> > +      return (nir_alu_type)(nir_type_float | bit_size);
> 
> Wouldn't this be easier to implement as
> 
> switch (glsl_get_base_type(type)) {
> case GLSL_TYPE_BOOL:
>    return nir_type_bool32;
> case GLSL_TYPE_UINT:
>    return nir_type_uint32;
> /* etc. */
> }
> 
> Then you could drop the is_integer and is_float helpers.
>  

Right. My idea was to do it more generic by taking into account
bit_size. Hence, int64 and float16 support would not need to change
this function.

In any case, this can be done in a future patch. I will do your
approach.

Thanks,

Sam 

> > +   unreachable("unknown type");
> > +}
> > +
> >  typedef enum {
> >     NIR_OP_IS_COMMUTATIVE = (1 << 0),
> >     NIR_OP_IS_ASSOCIATIVE = (1 << 1),
> > --
> > 2.9.3
> > 
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> > 
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170103/9107d61e/attachment-0001.sig>


More information about the mesa-dev mailing list