[Mesa-dev] [PATCH 7/7] glsl: Add support for constant expression evaluation on round(), roundEven().

Eric Anholt eric at anholt.net
Wed Sep 28 10:35:39 PDT 2011


On Wed, 28 Sep 2011 01:06:14 -0700, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On 09/27/2011 03:08 PM, Eric Anholt wrote:
> > They're both implemented the same in GLSL IR (since round() has
> > undefined behavior for N.5).
> > 
> > Fixes glsl-1.30/compiler/built-in-functions/round*
> > ---
> >  src/glsl/ir_constant_expression.cpp |   10 ++++++++++
> >  1 files changed, 10 insertions(+), 0 deletions(-)
> > 
> > diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
> > index b3fe6cf..59a7e67 100644
> > --- a/src/glsl/ir_constant_expression.cpp
> > +++ b/src/glsl/ir_constant_expression.cpp
> > @@ -196,6 +196,13 @@ ir_expression::constant_expression_value()
> >        }
> >        break;
> >  
> > +   case ir_unop_round_even:
> > +      assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
> > +      for (unsigned c = 0; c < op[0]->type->components(); c++) {
> > +	 data.f[c] = rint(op[0]->value.f[c]);
> 
> It's not obvious to me that rint() rounds correctly.
> 
> From the GLSL 1.30 spec:
> "Returns a value equal to the nearest integer to x.  A fractional part
> of 0.5 will round toward the nearest even integer. (Both 3.5 and 4.5 for
> x will return 4.0.)"
> 
> rint() does nearest integer, but probably not the mandated behavior for
> 0.5.  At least, not unless we configure the rounding mode.  Which I
> don't think we have...

rint's manpage doesn't appear to mandate the behavior we want, but it
does appear to provide the behavior we want according to
spec/glsl-1.30/compiler/built-in-functions/roundEven-float.frag
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110928/2398a9a4/attachment.pgp>


More information about the mesa-dev mailing list