[Mesa-dev] [PATCH 07/20] glsl: add double support

Pohjolainen, Topi topi.pohjolainen at intel.com
Fri Sep 5 00:31:07 PDT 2014


On Fri, Sep 05, 2014 at 10:25:52AM +0300, Pohjolainen, Topi wrote:
> On Thu, Sep 04, 2014 at 05:15:29AM +0100, Dave Airlie wrote:
> > This adds the guts of the fp64 implementation to the GLSL compiler.
> > 
> > - builtin double types
> > - double constant support
> > - lexer parsing for double types (lf, LF)
> > - enforcing flat on double fs inputs
> > - double operations (d2f,f2d, pack/unpack, frexp - in 2 parts)
> > - ir builder bits.
> > - double constant expression handling
> > 
> > v2:
> > add has_double check (Ian)
> > add d2i, i2d, d2u, u2d (Tapani + Ian)
> > remove extra ->type setting (Ian)
> > 
> > Signed-off-by: Dave Airlie <airlied at redhat.com>
> > ---
> >  src/glsl/ast.h                         |   2 +
> >  src/glsl/ast_function.cpp              |  32 +++++
> >  src/glsl/ast_to_hir.cpp                |  28 +++-
> >  src/glsl/builtin_type_macros.h         |  16 +++
> >  src/glsl/builtin_types.cpp             |  30 +++++
> >  src/glsl/glsl_lexer.ll                 |  42 +++++-
> >  src/glsl/glsl_parser.yy                |  33 ++++-
> >  src/glsl/glsl_parser_extras.cpp        |   4 +
> >  src/glsl/glsl_parser_extras.h          |   5 +
> >  src/glsl/glsl_types.cpp                |  74 +++++++++--
> >  src/glsl/glsl_types.h                  |  18 ++-
> >  src/glsl/ir.cpp                        |  97 +++++++++++++-
> >  src/glsl/ir.h                          |  21 +++
> >  src/glsl/ir_builder.cpp                |  11 ++
> >  src/glsl/ir_builder.h                  |   3 +
> >  src/glsl/ir_clone.cpp                  |   1 +
> >  src/glsl/ir_constant_expression.cpp    | 232 ++++++++++++++++++++++++++++-----
> >  src/glsl/ir_print_visitor.cpp          |  11 ++
> >  src/glsl/ir_set_program_inouts.cpp     |  24 +++-
> >  src/glsl/ir_validate.cpp               |  61 ++++++++-
> >  src/glsl/link_uniform_initializers.cpp |   4 +
> >  src/glsl/link_uniforms.cpp             |   2 +
> >  src/glsl/link_varyings.cpp             |   3 +-
> >  src/mesa/program/ir_to_mesa.cpp        |  10 ++
> >  24 files changed, 697 insertions(+), 67 deletions(-)
> > 
> > diff --git a/src/glsl/ast.h b/src/glsl/ast.h
> > index 15bf086..99274ed 100644
> > --- a/src/glsl/ast.h
> > +++ b/src/glsl/ast.h
> > @@ -189,6 +189,7 @@ enum ast_operators {
> >     ast_uint_constant,
> >     ast_float_constant,
> >     ast_bool_constant,
> > +   ast_double_constant,
> >  
> >     ast_sequence,
> >     ast_aggregate
> > @@ -236,6 +237,7 @@ public:
> >        float float_constant;
> >        unsigned uint_constant;
> >        int bool_constant;
> > +      double double_constant;
> >     } primary_expression;
> >  
> >  
> > diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
> > index 7130d61..6023d16 100644
> > --- a/src/glsl/ast_function.cpp
> > +++ b/src/glsl/ast_function.cpp
> > @@ -570,6 +570,9 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
> >  	 result = new(ctx) ir_expression(ir_unop_i2u,
> >  		  new(ctx) ir_expression(ir_unop_b2i, src));
> >  	 break;
> > +      case GLSL_TYPE_DOUBLE:
> > +	 result = new(ctx) ir_expression(ir_unop_d2u, src);
> > +	 break;
> >        }
> >        break;
> >     case GLSL_TYPE_INT:
> > @@ -583,6 +586,9 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
> >        case GLSL_TYPE_BOOL:
> >  	 result = new(ctx) ir_expression(ir_unop_b2i, src);
> >  	 break;
> > +      case GLSL_TYPE_DOUBLE:
> > +	 result = new(ctx) ir_expression(ir_unop_d2i, src);
> > +	 break;
> >        }
> >        break;
> >     case GLSL_TYPE_FLOAT:
> > @@ -596,6 +602,9 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
> >        case GLSL_TYPE_BOOL:
> >  	 result = new(ctx) ir_expression(ir_unop_b2f, desired_type, src, NULL);
> >  	 break;
> > +      case GLSL_TYPE_DOUBLE:
> > +	 result = new(ctx) ir_expression(ir_unop_d2f, desired_type, src, NULL);
> > +	 break;
> >        }
> >        break;
> >     case GLSL_TYPE_BOOL:
> > @@ -610,8 +619,28 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
> >        case GLSL_TYPE_FLOAT:
> >  	 result = new(ctx) ir_expression(ir_unop_f2b, desired_type, src, NULL);
> >  	 break;
> > +      case GLSL_TYPE_DOUBLE:
> > +	 result = new(ctx) ir_expression(ir_unop_f2b,
> > +                  new(ctx) ir_expression(ir_unop_d2f, src));
> > +	 break;
> >        }
> >        break;
> > +   case GLSL_TYPE_DOUBLE:
> > +      switch (b) {
> > +      case GLSL_TYPE_INT:
> > +         result = new(ctx) ir_expression(ir_unop_i2d, src);
> > +	 break;
> > +      case GLSL_TYPE_UINT:
> > +         result = new(ctx) ir_expression(ir_unop_u2d, src);
> > +	 break;
> > +      case GLSL_TYPE_BOOL:
> > +         result = new(ctx) ir_expression(ir_unop_f2d,
> > +                  new(ctx) ir_expression(ir_unop_b2f, src));
> > +	 break;
> > +      case GLSL_TYPE_FLOAT:
> > +	 result = new(ctx) ir_expression(ir_unop_f2d, desired_type, src, NULL);
> > +	 break;
> > +      }
> >     }
> >  
> >     assert(result != NULL);
> > @@ -1009,6 +1038,9 @@ emit_inline_vector_constructor(const glsl_type *type,
> >  	       case GLSL_TYPE_FLOAT:
> >  		  data.f[i + base_component] = c->get_float_component(i);
> >  		  break;
> > +	       case GLSL_TYPE_DOUBLE:
> > +		  data.d[i + base_component] = c->get_double_component(i);
> > +		  break;
> >  	       case GLSL_TYPE_BOOL:
> >  		  data.b[i + base_component] = c->get_bool_component(i);
> >  		  break;
> > diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> > index 897505c..6d79300 100644
> > --- a/src/glsl/ast_to_hir.cpp
> > +++ b/src/glsl/ast_to_hir.cpp
> > @@ -172,6 +172,7 @@ get_conversion_operation(const glsl_type *to, const glsl_type *from,
> >        switch (from->base_type) {
> >        case GLSL_TYPE_INT: return ir_unop_i2f;
> >        case GLSL_TYPE_UINT: return ir_unop_u2f;
> > +      case GLSL_TYPE_DOUBLE: return ir_unop_d2f;
> 
> I still think this is the wrong way around. The spec:
> 
>     "No implicit conversions are provided to convert from unsigned to
>      signed integer types, from floating-point to integer types, or from
>      higher-precision to lower-precision types."
> 
> And the way I read it, it is missing the conversion from float to double
> which is listed in the spec:
> 
>    Modify Section 4.1.10, Implicit Conversions, p. 27
> 
>     (modify table of implicit conversions)
> 
>                                 Can be implicitly
>         Type of expression        converted to
>         ---------------------   -------------------
>         int                     uint(*), float, double
>         ivec2                   uvec2(*), vec2, dvec2
>         ivec3                   uvec3(*), vec3, dvec3
>         ivec4                   uvec4(*), vec4, dvec4
> 
>         uint                    float, double
>         uvec2                   vec2, dvec2
>         uvec3                   vec3, dvec3
>         uvec4                   vec4, dvec4
> 
>         float                   double

Ah, right. There is the patch number thirteen. It looks to me it should
come before this patch, and we should drop this one-liner here?


More information about the mesa-dev mailing list