[Mesa-dev] [PATCH] glsl: Allow implicit int -> uint conversions for the % operator.

Kenneth Graunke kenneth at whitecape.org
Thu Nov 12 15:20:01 PST 2015


On Thursday, November 12, 2015 02:48:34 PM Ian Romanick wrote:
> On 11/12/2015 02:25 PM, Kenneth Graunke wrote:
> > GLSL 4.00 and GL_ARB_gpu_shader5 introduced a new int -> uint implicit
> > conversion rule and updated the rules for modulus to use them.  (In
> > earlier languages, none of the implicit conversion rules did anything
> > relevant, so there was no point in applying them.)
> > 
> > This allows expressions such as:
> > 
> >    int foo;
> >    uint bar;
> >    uint mod = foo % bar;
> > 
> > Cc: mesa-stable at lists.freedesktop.org
> > Cc: idr at freedesktop.org
> > Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> > ---
> >  src/glsl/ast_to_hir.cpp | 36 +++++++++++++++++++++++++++---------
> >  1 file changed, 27 insertions(+), 9 deletions(-)
> > 
> > diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> > index 9d341e8..0ef6d46 100644
> > --- a/src/glsl/ast_to_hir.cpp
> > +++ b/src/glsl/ast_to_hir.cpp
> > @@ -538,18 +538,19 @@ bit_logic_result_type(const struct glsl_type *type_a,
> >  }
> >  
> >  static const struct glsl_type *
> > -modulus_result_type(const struct glsl_type *type_a,
> > -                    const struct glsl_type *type_b,
> > +modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
> >                      struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
> >  {
> > +   const glsl_type *type_a = value_a->type;
> > +   const glsl_type *type_b = value_b->type;
> > +
> >     if (!state->check_version(130, 300, loc, "operator '%%' is reserved")) {
> >        return glsl_type::error_type;
> >     }
> >  
> > -   /* From GLSL 1.50 spec, page 56:
> > +   /* From the GLSL 4.00 specification, page 64:
> 
> Since the pages change (even in spec updates), I'd like to change this
> to the canonical "Section ... (blah blah) of the GLSL 4.00 specification
> says:"

Good call.  I've changed it to

   /* Section 5.9 (Expressions) of the GLSL 4.00 specification says:
    *
    *    "The operator modulus (%) operates on signed or unsigned integers or

> 
> Other than that, this patch looks about how I would expect it to.
> 
> Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
> 
> Do we have piglit tests for any of these?

Sadly...no.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20151112/581cccff/attachment.sig>


More information about the mesa-dev mailing list