[Mesa-dev] [PATCH 07/13] glsl: add double support
Ilia Mirkin
imirkin at alum.mit.edu
Wed Feb 4 23:27:14 PST 2015
From: Dave Airlie <airlied at gmail.com>
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)
v3: include fixes from Tapani and Topi
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/glsl/ast.h | 2 +
src/glsl/ast_function.cpp | 67 ++++++++--
src/glsl/ast_to_hir.cpp | 38 +++++-
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 | 109 ++++++++++++---
src/glsl/glsl_types.h | 18 ++-
src/glsl/ir.cpp | 104 ++++++++++++++-
src/glsl/ir.h | 21 +++
src/glsl/ir_builder.cpp | 23 ++++
src/glsl/ir_builder.h | 5 +
src/glsl/ir_clone.cpp | 1 +
src/glsl/ir_constant_expression.cpp | 234 ++++++++++++++++++++++++++++-----
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 | 7 +-
src/glsl/link_uniforms.cpp | 8 +-
src/glsl/link_varyings.cpp | 3 +-
src/glsl/loop_controls.cpp | 19 ++-
src/glsl/lower_mat_op_to_vec.cpp | 2 +
src/glsl/lower_ubo_reference.cpp | 13 +-
src/glsl/opt_constant_propagation.cpp | 3 +
src/glsl/opt_minmax.cpp | 13 ++
src/mesa/program/ir_to_mesa.cpp | 10 ++
29 files changed, 825 insertions(+), 101 deletions(-)
diff --git a/src/glsl/ast.h b/src/glsl/ast.h
index 6995ae8..ef74e51 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 cbff9d8..b3dc861 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -573,6 +573,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:
@@ -586,6 +589,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:
@@ -599,6 +605,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:
@@ -613,8 +622,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);
@@ -711,9 +740,9 @@ process_vec_mat_constructor(exec_list *instructions,
/* Apply implicit conversions (not the scalar constructor rules!). See
* the spec quote above. */
- if (constructor_type->is_float()) {
+ if (constructor_type->base_type != result->type->base_type) {
const glsl_type *desired_type =
- glsl_type::get_instance(GLSL_TYPE_FLOAT,
+ glsl_type::get_instance(constructor_type->base_type,
ir->type->vector_elements,
ir->type->matrix_columns);
if (result->type->can_implicitly_convert_to(desired_type, state)) {
@@ -847,13 +876,17 @@ process_array_constructor(exec_list *instructions,
foreach_in_list_safe(ir_rvalue, ir, &actual_parameters) {
ir_rvalue *result = ir;
+ const glsl_base_type element_base_type =
+ constructor_type->element_type()->base_type;
+
/* Apply implicit conversions (not the scalar constructor rules!). See
* the spec quote above. */
- if (constructor_type->element_type()->is_float()) {
- const glsl_type *desired_type =
- glsl_type::get_instance(GLSL_TYPE_FLOAT,
- ir->type->vector_elements,
- ir->type->matrix_columns);
+ if (element_base_type != result->type->base_type) {
+ const glsl_type *desired_type =
+ glsl_type::get_instance(element_base_type,
+ ir->type->vector_elements,
+ ir->type->matrix_columns);
+
if (result->type->can_implicitly_convert_to(desired_type, state)) {
/* Even though convert_component() implements the constructor
* conversion rules (not the implicit conversion rules), its safe
@@ -1012,6 +1045,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;
@@ -1167,16 +1203,21 @@ emit_inline_matrix_constructor(const glsl_type *type,
/* Assign the scalar to the X component of a vec4, and fill the remaining
* components with zero.
*/
+ glsl_base_type param_base_type = first_param->type->base_type;
+ assert(param_base_type == GLSL_TYPE_FLOAT ||
+ param_base_type == GLSL_TYPE_DOUBLE);
ir_variable *rhs_var =
- new(ctx) ir_variable(glsl_type::vec4_type, "mat_ctor_vec",
- ir_var_temporary);
+ new(ctx) ir_variable(glsl_type::get_instance(param_base_type, 4, 1),
+ "mat_ctor_vec",
+ ir_var_temporary);
instructions->push_tail(rhs_var);
ir_constant_data zero;
- zero.f[0] = 0.0;
- zero.f[1] = 0.0;
- zero.f[2] = 0.0;
- zero.f[3] = 0.0;
+ for (unsigned i = 0; i < 4; i++)
+ if (param_base_type == GLSL_TYPE_FLOAT)
+ zero.f[i] = 0.0;
+ else
+ zero.d[i] = 0.0;
ir_instruction *inst =
new(ctx) ir_assignment(new(ctx) ir_dereference_variable(rhs_var),
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index ed0eb09..b2f9165 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;
default: return (ir_expression_operation)0;
}
@@ -183,6 +184,16 @@ get_conversion_operation(const glsl_type *to, const glsl_type *from,
default: return (ir_expression_operation)0;
}
+ case GLSL_TYPE_DOUBLE:
+ if (!state->has_double())
+ return (ir_expression_operation)0;
+ switch (from->base_type) {
+ case GLSL_TYPE_INT: return ir_unop_i2d;
+ case GLSL_TYPE_UINT: return ir_unop_u2d;
+ case GLSL_TYPE_FLOAT: return ir_unop_f2d;
+ default: return (ir_expression_operation)0;
+ }
+
default: return (ir_expression_operation)0;
}
}
@@ -340,8 +351,8 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* type of both operands must be float.
*/
assert(type_a->is_matrix() || type_b->is_matrix());
- assert(type_a->base_type == GLSL_TYPE_FLOAT);
- assert(type_b->base_type == GLSL_TYPE_FLOAT);
+ assert(type_a->base_type == GLSL_TYPE_FLOAT || type_a->base_type == GLSL_TYPE_DOUBLE);
+ assert(type_b->base_type == GLSL_TYPE_FLOAT || type_b->base_type == GLSL_TYPE_DOUBLE);
/* "* The operator is add (+), subtract (-), or divide (/), and the
* operands are matrices with the same number of rows and the same
@@ -959,6 +970,7 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_DOUBLE:
return new(mem_ctx) ir_expression(operation, op0, op1);
case GLSL_TYPE_ARRAY: {
@@ -1746,6 +1758,10 @@ ast_expression::do_hir(exec_list *instructions,
result = new(ctx) ir_constant(bool(this->primary_expression.bool_constant));
break;
+ case ast_double_constant:
+ result = new(ctx) ir_constant(this->primary_expression.double_constant);
+ break;
+
case ast_sequence: {
/* It should not be possible to generate a sequence in the AST without
* any expressions in it.
@@ -2560,6 +2576,12 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
_mesa_glsl_error(loc, state,
"varying variables may not be of type struct");
break;
+ case GLSL_TYPE_DOUBLE:
+ if (state->has_double())
+ break;
+ _mesa_glsl_error(loc, state,
+ "varying variables may not be of type double");
+ break;
default:
_mesa_glsl_error(loc, state, "illegal type for a varying variable");
break;
@@ -3645,6 +3667,18 @@ ast_declarator_list::hir(exec_list *instructions,
var_type);
}
+ /* Double fragment inputs must be qualified with 'flat'. */
+ if (state->has_double() &&
+ var->type->contains_double() &&
+ var->data.interpolation != INTERP_QUALIFIER_FLAT &&
+ ((state->stage == MESA_SHADER_FRAGMENT && var->data.mode == ir_var_shader_in)
+ )) {
+ const char *var_type = (state->stage == MESA_SHADER_VERTEX) ?
+ "vertex output" : "fragment input";
+ _mesa_glsl_error(&loc, state, "if a %s is (or contains) "
+ "a double, then it must be qualified with 'flat'",
+ var_type);
+ }
/* Interpolation qualifiers cannot be applied to 'centroid' and
* 'centroid varying'.
diff --git a/src/glsl/builtin_type_macros.h b/src/glsl/builtin_type_macros.h
index 236e1ce..bf74eb3 100644
--- a/src/glsl/builtin_type_macros.h
+++ b/src/glsl/builtin_type_macros.h
@@ -64,6 +64,22 @@ DECL_TYPE(mat3x4, GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3)
DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4)
DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4)
+DECL_TYPE(double, GL_DOUBLE, GLSL_TYPE_DOUBLE, 1, 1)
+DECL_TYPE(dvec2, GL_DOUBLE_VEC2, GLSL_TYPE_DOUBLE, 2, 1)
+DECL_TYPE(dvec3, GL_DOUBLE_VEC3, GLSL_TYPE_DOUBLE, 3, 1)
+DECL_TYPE(dvec4, GL_DOUBLE_VEC4, GLSL_TYPE_DOUBLE, 4, 1)
+
+DECL_TYPE(dmat2, GL_DOUBLE_MAT2, GLSL_TYPE_DOUBLE, 2, 2)
+DECL_TYPE(dmat3, GL_DOUBLE_MAT3, GLSL_TYPE_DOUBLE, 3, 3)
+DECL_TYPE(dmat4, GL_DOUBLE_MAT4, GLSL_TYPE_DOUBLE, 4, 4)
+
+DECL_TYPE(dmat2x3, GL_DOUBLE_MAT2x3, GLSL_TYPE_DOUBLE, 3, 2)
+DECL_TYPE(dmat2x4, GL_DOUBLE_MAT2x4, GLSL_TYPE_DOUBLE, 4, 2)
+DECL_TYPE(dmat3x2, GL_DOUBLE_MAT3x2, GLSL_TYPE_DOUBLE, 2, 3)
+DECL_TYPE(dmat3x4, GL_DOUBLE_MAT3x4, GLSL_TYPE_DOUBLE, 4, 3)
+DECL_TYPE(dmat4x2, GL_DOUBLE_MAT4x2, GLSL_TYPE_DOUBLE, 2, 4)
+DECL_TYPE(dmat4x3, GL_DOUBLE_MAT4x3, GLSL_TYPE_DOUBLE, 3, 4)
+
DECL_TYPE(sampler1D, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2D, GL_SAMPLER_2D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler3D, GL_SAMPLER_3D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT)
diff --git a/src/glsl/builtin_types.cpp b/src/glsl/builtin_types.cpp
index 10fac0f..fef86df 100644
--- a/src/glsl/builtin_types.cpp
+++ b/src/glsl/builtin_types.cpp
@@ -159,6 +159,20 @@ const static struct builtin_type_versions {
T(mat4x2, 120, 300)
T(mat4x3, 120, 300)
+ T(double, 400, 999)
+ T(dvec2, 400, 999)
+ T(dvec3, 400, 999)
+ T(dvec4, 400, 999)
+ T(dmat2, 400, 999)
+ T(dmat3, 400, 999)
+ T(dmat4, 400, 999)
+ T(dmat2x3, 400, 999)
+ T(dmat2x4, 400, 999)
+ T(dmat3x2, 400, 999)
+ T(dmat3x4, 400, 999)
+ T(dmat4x2, 400, 999)
+ T(dmat4x3, 400, 999)
+
T(sampler1D, 110, 999)
T(sampler2D, 110, 100)
T(sampler3D, 110, 300)
@@ -361,5 +375,21 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
if (state->ARB_shader_atomic_counters_enable) {
add_type(symbols, glsl_type::atomic_uint_type);
}
+
+ if (state->ARB_gpu_shader_fp64_enable) {
+ add_type(symbols, glsl_type::double_type);
+ add_type(symbols, glsl_type::dvec2_type);
+ add_type(symbols, glsl_type::dvec3_type);
+ add_type(symbols, glsl_type::dvec4_type);
+ add_type(symbols, glsl_type::dmat2_type);
+ add_type(symbols, glsl_type::dmat3_type);
+ add_type(symbols, glsl_type::dmat4_type);
+ add_type(symbols, glsl_type::dmat2x3_type);
+ add_type(symbols, glsl_type::dmat2x4_type);
+ add_type(symbols, glsl_type::dmat3x2_type);
+ add_type(symbols, glsl_type::dmat3x4_type);
+ add_type(symbols, glsl_type::dmat4x2_type);
+ add_type(symbols, glsl_type::dmat4x3_type);
+ }
}
/** @} */
diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
index 57c46be..de58e73 100644
--- a/src/glsl/glsl_lexer.ll
+++ b/src/glsl/glsl_lexer.ll
@@ -458,6 +458,27 @@ layout {
return FLOATCONSTANT;
}
+[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) {
+ yylval->dreal = _mesa_strtod(yytext, NULL);
+ return DOUBLECONSTANT;
+ }
+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) {
+ yylval->dreal = _mesa_strtod(yytext, NULL);
+ return DOUBLECONSTANT;
+ }
+[0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) {
+ yylval->dreal = _mesa_strtod(yytext, NULL);
+ return DOUBLECONSTANT;
+ }
+[0-9]+[eE][+-]?[0-9]+(lf|LF) {
+ yylval->dreal = _mesa_strtod(yytext, NULL);
+ return DOUBLECONSTANT;
+ }
+[0-9]+(lf|LF) {
+ yylval->dreal = _mesa_strtod(yytext, NULL);
+ return DOUBLECONSTANT;
+ }
+
true {
yylval->n = 1;
return BOOLCONSTANT;
@@ -489,7 +510,7 @@ external KEYWORD(110, 100, 0, 0, EXTERNAL);
interface KEYWORD(110, 100, 0, 0, INTERFACE);
long KEYWORD(110, 100, 0, 0, LONG_TOK);
short KEYWORD(110, 100, 0, 0, SHORT_TOK);
-double KEYWORD(110, 100, 400, 0, DOUBLE_TOK);
+double KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DOUBLE_TOK);
half KEYWORD(110, 100, 0, 0, HALF);
fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
unsigned KEYWORD(110, 100, 0, 0, UNSIGNED);
@@ -498,9 +519,22 @@ output KEYWORD(110, 100, 0, 0, OUTPUT);
hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
-dvec2 KEYWORD(110, 100, 400, 0, DVEC2);
-dvec3 KEYWORD(110, 100, 400, 0, DVEC3);
-dvec4 KEYWORD(110, 100, 400, 0, DVEC4);
+dvec2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC2);
+dvec3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC3);
+dvec4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC4);
+dmat2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
+dmat3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
+dmat4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
+dmat2x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
+dmat2x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X3);
+dmat2x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X4);
+dmat3x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X2);
+dmat3x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
+dmat3x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X4);
+dmat4x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X2);
+dmat4x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X3);
+dmat4x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
+
fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 7fb8c38..596e432 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -94,6 +94,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
%union {
int n;
float real;
+ double dreal;
const char *identifier;
struct ast_type_qualifier type_qualifier;
@@ -128,14 +129,17 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
} selection_rest_statement;
}
-%token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
+%token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
%token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
-%token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
+%token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
%token NOPERSPECTIVE FLAT SMOOTH
%token MAT2X2 MAT2X3 MAT2X4
%token MAT3X2 MAT3X3 MAT3X4
%token MAT4X2 MAT4X3 MAT4X4
+%token DMAT2X2 DMAT2X3 DMAT2X4
+%token DMAT3X2 DMAT3X3 DMAT3X4
+%token DMAT4X2 DMAT4X3 DMAT4X4
%token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
%token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
%token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
@@ -162,6 +166,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
%type <identifier> any_identifier
%type <interface_block> instance_name_opt
%token <real> FLOATCONSTANT
+%token <dreal> DOUBLECONSTANT
%token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
%token <identifier> FIELD_SELECTION
%token LEFT_OP RIGHT_OP
@@ -182,8 +187,8 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
*/
%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
%token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
-%token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
-%token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
+%token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
+%token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
%token SAMPLER3DRECT
%token SIZEOF CAST NAMESPACE USING
%token RESOURCE PATCH
@@ -434,6 +439,13 @@ primary_expression:
$$->set_location(@1);
$$->primary_expression.float_constant = $1;
}
+ | DOUBLECONSTANT
+ {
+ void *ctx = state;
+ $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
+ $$->set_location(@1);
+ $$->primary_expression.double_constant = $1;
+ }
| BOOLCONSTANT
{
void *ctx = state;
@@ -1864,6 +1876,7 @@ type_specifier_nonarray:
basic_type_specifier_nonarray:
VOID_TOK { $$ = "void"; }
| FLOAT_TOK { $$ = "float"; }
+ | DOUBLE_TOK { $$ = "double"; }
| INT_TOK { $$ = "int"; }
| UINT_TOK { $$ = "uint"; }
| BOOL_TOK { $$ = "bool"; }
@@ -1879,6 +1892,9 @@ basic_type_specifier_nonarray:
| UVEC2 { $$ = "uvec2"; }
| UVEC3 { $$ = "uvec3"; }
| UVEC4 { $$ = "uvec4"; }
+ | DVEC2 { $$ = "dvec2"; }
+ | DVEC3 { $$ = "dvec3"; }
+ | DVEC4 { $$ = "dvec4"; }
| MAT2X2 { $$ = "mat2"; }
| MAT2X3 { $$ = "mat2x3"; }
| MAT2X4 { $$ = "mat2x4"; }
@@ -1888,6 +1904,15 @@ basic_type_specifier_nonarray:
| MAT4X2 { $$ = "mat4x2"; }
| MAT4X3 { $$ = "mat4x3"; }
| MAT4X4 { $$ = "mat4"; }
+ | DMAT2X2 { $$ = "dmat2"; }
+ | DMAT2X3 { $$ = "dmat2x3"; }
+ | DMAT2X4 { $$ = "dmat2x4"; }
+ | DMAT3X2 { $$ = "dmat3x2"; }
+ | DMAT3X3 { $$ = "dmat3"; }
+ | DMAT3X4 { $$ = "dmat3x4"; }
+ | DMAT4X2 { $$ = "dmat4x2"; }
+ | DMAT4X3 { $$ = "dmat4x3"; }
+ | DMAT4X4 { $$ = "dmat4"; }
| SAMPLER1D { $$ = "sampler1D"; }
| SAMPLER2D { $$ = "sampler2D"; }
| SAMPLER2DRECT { $$ = "sampler2DRect"; }
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index cb19ce1..381c79d 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -962,6 +962,10 @@ ast_expression::print(void) const
printf("%f ", primary_expression.float_constant);
break;
+ case ast_double_constant:
+ printf("%lf ", primary_expression.double_constant);
+ break;
+
case ast_bool_constant:
printf("%s ",
primary_expression.bool_constant
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index dafee4e..ea53270 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -205,6 +205,11 @@ struct _mesa_glsl_parse_state {
|| EXT_separate_shader_objects_enable;
}
+ bool has_double() const
+ {
+ return ARB_gpu_shader_fp64_enable || is_version(400, 0);
+ }
+
void process_version_directive(YYLTYPE *locp, int version,
const char *ident);
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index b4223f4..7663d47 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -194,6 +194,22 @@ glsl_type::contains_integer() const
}
bool
+glsl_type::contains_double() const
+{
+ if (this->is_array()) {
+ return this->fields.array->contains_double();
+ } else if (this->is_record()) {
+ for (unsigned int i = 0; i < this->length; i++) {
+ if (this->fields.structure[i].type->contains_double())
+ return true;
+ }
+ return false;
+ } else {
+ return this->is_double();
+ }
+}
+
+bool
glsl_type::contains_opaque() const {
switch (base_type) {
case GLSL_TYPE_SAMPLER:
@@ -268,6 +284,8 @@ const glsl_type *glsl_type::get_base_type() const
return int_type;
case GLSL_TYPE_FLOAT:
return float_type;
+ case GLSL_TYPE_DOUBLE:
+ return double_type;
case GLSL_TYPE_BOOL:
return bool_type;
default:
@@ -292,6 +310,8 @@ const glsl_type *glsl_type::get_scalar_type() const
return int_type;
case GLSL_TYPE_FLOAT:
return float_type;
+ case GLSL_TYPE_DOUBLE:
+ return double_type;
case GLSL_TYPE_BOOL:
return bool_type;
default:
@@ -377,6 +397,17 @@ glsl_type::vec(unsigned components)
return ts[components - 1];
}
+const glsl_type *
+glsl_type::dvec(unsigned components)
+{
+ if (components == 0 || components > 4)
+ return error_type;
+
+ static const glsl_type *const ts[] = {
+ double_type, dvec2_type, dvec3_type, dvec4_type
+ };
+ return ts[components - 1];
+}
const glsl_type *
glsl_type::ivec(unsigned components)
@@ -436,13 +467,15 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
return ivec(rows);
case GLSL_TYPE_FLOAT:
return vec(rows);
+ case GLSL_TYPE_DOUBLE:
+ return dvec(rows);
case GLSL_TYPE_BOOL:
return bvec(rows);
default:
return error_type;
}
} else {
- if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
+ if ((base_type != GLSL_TYPE_FLOAT && base_type != GLSL_TYPE_DOUBLE) || (rows == 1))
return error_type;
/* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
@@ -456,17 +489,32 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
*/
#define IDX(c,r) (((c-1)*3) + (r-1))
- switch (IDX(columns, rows)) {
- case IDX(2,2): return mat2_type;
- case IDX(2,3): return mat2x3_type;
- case IDX(2,4): return mat2x4_type;
- case IDX(3,2): return mat3x2_type;
- case IDX(3,3): return mat3_type;
- case IDX(3,4): return mat3x4_type;
- case IDX(4,2): return mat4x2_type;
- case IDX(4,3): return mat4x3_type;
- case IDX(4,4): return mat4_type;
- default: return error_type;
+ if (base_type == GLSL_TYPE_DOUBLE) {
+ switch (IDX(columns, rows)) {
+ case IDX(2,2): return dmat2_type;
+ case IDX(2,3): return dmat2x3_type;
+ case IDX(2,4): return dmat2x4_type;
+ case IDX(3,2): return dmat3x2_type;
+ case IDX(3,3): return dmat3_type;
+ case IDX(3,4): return dmat3x4_type;
+ case IDX(4,2): return dmat4x2_type;
+ case IDX(4,3): return dmat4x3_type;
+ case IDX(4,4): return dmat4_type;
+ default: return error_type;
+ }
+ } else {
+ switch (IDX(columns, rows)) {
+ case IDX(2,2): return mat2_type;
+ case IDX(2,3): return mat2x3_type;
+ case IDX(2,4): return mat2x4_type;
+ case IDX(3,2): return mat3x2_type;
+ case IDX(3,3): return mat3_type;
+ case IDX(3,4): return mat3x4_type;
+ case IDX(4,2): return mat4x2_type;
+ case IDX(4,3): return mat4x3_type;
+ case IDX(4,4): return mat4_type;
+ default: return error_type;
+ }
}
}
@@ -815,6 +863,7 @@ glsl_type::component_slots() const
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
return this->components();
@@ -897,12 +946,26 @@ glsl_type::can_implicitly_convert_to(const glsl_type *desired,
desired->base_type == GLSL_TYPE_UINT && this->base_type == GLSL_TYPE_INT)
return true;
+ /* No implicit conversions from double. */
+ if ((!state || state->has_double()) && this->is_double())
+ return false;
+
+ /* Conversions from different types to double. */
+ if ((!state || state->has_double()) && desired->is_double()) {
+ if (this->is_float())
+ return true;
+ if (this->is_integer())
+ return true;
+ }
+
return false;
}
unsigned
glsl_type::std140_base_alignment(bool row_major) const
{
+ unsigned N = is_double() ? 8 : 4;
+
/* (1) If the member is a scalar consuming <N> basic machine units, the
* base alignment is <N>.
*
@@ -916,12 +979,12 @@ glsl_type::std140_base_alignment(bool row_major) const
if (this->is_scalar() || this->is_vector()) {
switch (this->vector_elements) {
case 1:
- return 4;
+ return N;
case 2:
- return 8;
+ return 2 * N;
case 3:
case 4:
- return 16;
+ return 4 * N;
}
}
@@ -970,10 +1033,10 @@ glsl_type::std140_base_alignment(bool row_major) const
int r = this->vector_elements;
if (row_major) {
- vec_type = get_instance(GLSL_TYPE_FLOAT, c, 1);
+ vec_type = get_instance(base_type, c, 1);
array_type = glsl_type::get_array_instance(vec_type, r);
} else {
- vec_type = get_instance(GLSL_TYPE_FLOAT, r, 1);
+ vec_type = get_instance(base_type, r, 1);
array_type = glsl_type::get_array_instance(vec_type, c);
}
@@ -1018,6 +1081,8 @@ glsl_type::std140_base_alignment(bool row_major) const
unsigned
glsl_type::std140_size(bool row_major) const
{
+ unsigned N = is_double() ? 8 : 4;
+
/* (1) If the member is a scalar consuming <N> basic machine units, the
* base alignment is <N>.
*
@@ -1029,7 +1094,7 @@ glsl_type::std140_size(bool row_major) const
* <N> basic machine units, the base alignment is 4<N>.
*/
if (this->is_scalar() || this->is_vector()) {
- return this->vector_elements * 4;
+ return this->vector_elements * N;
}
/* (5) If the member is a column-major matrix with <C> columns and
@@ -1064,11 +1129,12 @@ glsl_type::std140_size(bool row_major) const
}
if (row_major) {
- vec_type = get_instance(GLSL_TYPE_FLOAT,
- element_type->matrix_columns, 1);
+ vec_type = get_instance(base_type,
+ element_type->matrix_columns, 1);
+
array_len *= element_type->vector_elements;
} else {
- vec_type = get_instance(GLSL_TYPE_FLOAT,
+ vec_type = get_instance(base_type,
element_type->vector_elements, 1);
array_len *= element_type->matrix_columns;
}
@@ -1171,6 +1237,7 @@ glsl_type::count_attribute_slots() const
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_DOUBLE:
return this->matrix_columns;
case GLSL_TYPE_STRUCT:
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index f0d4ea8..e894e739 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -200,6 +200,7 @@ struct glsl_type {
* @{
*/
static const glsl_type *vec(unsigned components);
+ static const glsl_type *dvec(unsigned components);
static const glsl_type *ivec(unsigned components);
static const glsl_type *uvec(unsigned components);
static const glsl_type *bvec(unsigned components);
@@ -388,7 +389,7 @@ struct glsl_type {
bool is_matrix() const
{
/* GLSL only has float matrices. */
- return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT);
+ return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT || base_type == GLSL_TYPE_DOUBLE);
}
/**
@@ -396,7 +397,7 @@ struct glsl_type {
*/
bool is_numeric() const
{
- return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_FLOAT);
+ return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_DOUBLE);
}
/**
@@ -414,6 +415,12 @@ struct glsl_type {
bool contains_integer() const;
/**
+ * Query whether or not type is a double type, or for struct and array
+ * types, contains a double type.
+ */
+ bool contains_double() const;
+
+ /**
* Query whether or not a type is a float type
*/
bool is_float() const
@@ -422,6 +429,13 @@ struct glsl_type {
}
/**
+ * Query whether or not a type is a double type
+ */
+ bool is_double() const
+ {
+ return base_type == GLSL_TYPE_DOUBLE;
+ }
+ /**
* Query whether or not a type is a non-array boolean type
*/
bool is_boolean() const
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index fe5601a..9da4a44 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -257,6 +257,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
case ir_unop_f2i:
case ir_unop_b2i:
case ir_unop_u2i:
+ case ir_unop_d2i:
case ir_unop_bitcast_f2i:
case ir_unop_bit_count:
case ir_unop_find_msb:
@@ -268,6 +269,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
case ir_unop_b2f:
case ir_unop_i2f:
case ir_unop_u2f:
+ case ir_unop_d2f:
case ir_unop_bitcast_i2f:
case ir_unop_bitcast_u2f:
this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT,
@@ -280,8 +282,16 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
op0->type->vector_elements, 1);
break;
+ case ir_unop_f2d:
+ case ir_unop_i2d:
+ case ir_unop_u2d:
+ this->type = glsl_type::get_instance(GLSL_TYPE_DOUBLE,
+ op0->type->vector_elements, 1);
+ break;
+
case ir_unop_i2u:
case ir_unop_f2u:
+ case ir_unop_d2u:
case ir_unop_bitcast_f2u:
this->type = glsl_type::get_instance(GLSL_TYPE_UINT,
op0->type->vector_elements, 1);
@@ -293,6 +303,10 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
this->type = glsl_type::float_type;
break;
+ case ir_unop_unpack_double_2x32:
+ this->type = glsl_type::uvec2_type;
+ break;
+
case ir_unop_any:
this->type = glsl_type::bool_type;
break;
@@ -305,6 +319,10 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
this->type = glsl_type::uint_type;
break;
+ case ir_unop_pack_double_2x32:
+ this->type = glsl_type::double_type;
+ break;
+
case ir_unop_unpack_snorm_2x16:
case ir_unop_unpack_unorm_2x16:
case ir_unop_unpack_half_2x16:
@@ -316,6 +334,14 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
this->type = glsl_type::vec4_type;
break;
+ case ir_unop_frexp_sig:
+ this->type = op0->type;
+ break;
+ case ir_unop_frexp_exp:
+ this->type = glsl_type::get_instance(GLSL_TYPE_INT,
+ op0->type->vector_elements, 1);
+ break;
+
default:
assert(!"not reached: missing automatic type setup for ir_expression");
this->type = op0->type;
@@ -390,7 +416,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1)
break;
case ir_binop_dot:
- this->type = glsl_type::float_type;
+ this->type = op0->type->get_base_type();
break;
case ir_binop_pack_half_2x16_split:
@@ -499,6 +525,12 @@ static const char *const operator_strs[] = {
"bitcast_u2f",
"bitcast_f2u",
"any",
+ "d2f",
+ "f2d",
+ "d2i",
+ "i2d",
+ "d2u",
+ "u2d",
"trunc",
"ceil",
"floor",
@@ -531,6 +563,10 @@ static const char *const operator_strs[] = {
"find_msb",
"find_lsb",
"sat",
+ "packDouble2x32",
+ "unpackDouble2x32",
+ "frexp_sig",
+ "frexp_exp",
"noise",
"interpolate_at_centroid",
"+",
@@ -646,6 +682,19 @@ ir_constant::ir_constant(float f, unsigned vector_elements)
}
}
+ir_constant::ir_constant(double d, unsigned vector_elements)
+ : ir_rvalue(ir_type_constant)
+{
+ assert(vector_elements <= 4);
+ this->type = glsl_type::get_instance(GLSL_TYPE_DOUBLE, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.d[i] = d;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
+ this->value.d[i] = 0;
+ }
+}
+
ir_constant::ir_constant(unsigned int u, unsigned vector_elements)
: ir_rvalue(ir_type_constant)
{
@@ -746,9 +795,16 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
if (value->type->is_scalar() && value->next->is_tail_sentinel()) {
if (type->is_matrix()) {
/* Matrix - fill diagonal (rest is already set to 0) */
- assert(type->base_type == GLSL_TYPE_FLOAT);
- for (unsigned i = 0; i < type->matrix_columns; i++)
- this->value.f[i * type->vector_elements + i] = value->value.f[0];
+ assert(type->base_type == GLSL_TYPE_FLOAT ||
+ type->base_type == GLSL_TYPE_DOUBLE);
+ for (unsigned i = 0; i < type->matrix_columns; i++) {
+ if (type->base_type == GLSL_TYPE_FLOAT)
+ this->value.f[i * type->vector_elements + i] =
+ value->value.f[0];
+ else
+ this->value.d[i * type->vector_elements + i] =
+ value->value.d[0];
+ }
} else {
/* Vector or scalar - fill all components */
switch (type->base_type) {
@@ -761,6 +817,10 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
for (unsigned i = 0; i < type->components(); i++)
this->value.f[i] = value->value.f[0];
break;
+ case GLSL_TYPE_DOUBLE:
+ for (unsigned i = 0; i < type->components(); i++)
+ this->value.d[i] = value->value.d[0];
+ break;
case GLSL_TYPE_BOOL:
for (unsigned i = 0; i < type->components(); i++)
this->value.b[i] = value->value.b[0];
@@ -819,6 +879,9 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
case GLSL_TYPE_BOOL:
this->value.b[i] = value->get_bool_component(j);
break;
+ case GLSL_TYPE_DOUBLE:
+ this->value.d[i] = value->get_double_component(j);
+ break;
default:
/* FINISHME: What to do? Exceptions are not the answer.
*/
@@ -895,6 +958,24 @@ ir_constant::get_float_component(unsigned i) const
return 0.0;
}
+double
+ir_constant::get_double_component(unsigned i) const
+{
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT: return (double) this->value.u[i];
+ case GLSL_TYPE_INT: return (double) this->value.i[i];
+ case GLSL_TYPE_FLOAT: return (double) this->value.f[i];
+ case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
+ case GLSL_TYPE_DOUBLE: return this->value.d[i];
+ default: assert(!"Should not get here."); break;
+ }
+
+ /* Must return something to make the compiler happy. This is clearly an
+ * error case.
+ */
+ return 0.0;
+}
+
int
ir_constant::get_int_component(unsigned i) const
{
@@ -984,6 +1065,7 @@ ir_constant::copy_offset(ir_constant *src, int offset)
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL: {
unsigned int size = src->type->components();
assert (size <= this->type->components() - offset);
@@ -1001,6 +1083,9 @@ ir_constant::copy_offset(ir_constant *src, int offset)
case GLSL_TYPE_BOOL:
value.b[i+offset] = src->get_bool_component(i);
break;
+ case GLSL_TYPE_DOUBLE:
+ value.d[i+offset] = src->get_double_component(i);
+ break;
default: // Shut up the compiler
break;
}
@@ -1057,6 +1142,9 @@ ir_constant::copy_masked_offset(ir_constant *src, int offset, unsigned int mask)
case GLSL_TYPE_BOOL:
value.b[i+offset] = src->get_bool_component(id++);
break;
+ case GLSL_TYPE_DOUBLE:
+ value.d[i+offset] = src->get_double_component(id++);
+ break;
default:
assert(!"Should not get here.");
return;
@@ -1117,6 +1205,10 @@ ir_constant::has_value(const ir_constant *c) const
if (this->value.b[i] != c->value.b[i])
return false;
break;
+ case GLSL_TYPE_DOUBLE:
+ if (this->value.d[i] != c->value.d[i])
+ return false;
+ break;
default:
assert(!"Should not get here.");
return false;
@@ -1154,6 +1246,10 @@ ir_constant::is_value(float f, int i) const
if (this->value.b[c] != bool(i))
return false;
break;
+ case GLSL_TYPE_DOUBLE:
+ if (this->value.d[c] != double(i))
+ return false;
+ break;
default:
/* The only other base types are structures, arrays, and samplers.
* Samplers cannot be constants, and the others should have been
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index a0f48b2..6e7c654 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1275,6 +1275,13 @@ enum ir_expression_operation {
ir_unop_bitcast_f2u, /**< Bit-identical float-to-uint "conversion" */
ir_unop_any,
+ ir_unop_d2f, /**< Double-to-float conversion. */
+ ir_unop_f2d, /**< Float-to-double conversion. */
+ ir_unop_d2i, /**< Double-to-integer conversion. */
+ ir_unop_i2d, /**< Integer-to-double conversion. */
+ ir_unop_d2u, /**< Double-to-unsigned conversion. */
+ ir_unop_u2d, /**< Unsigned-to-double conversion. */
+
/**
* \name Unary floating-point rounding operations.
*/
@@ -1345,6 +1352,17 @@ enum ir_expression_operation {
/*@}*/
ir_unop_saturate,
+ /**
+ * \name Double packing, part of ARB_gpu_shader_fp64.
+ */
+ /*@{*/
+ ir_unop_pack_double_2x32,
+ ir_unop_unpack_double_2x32,
+ /*@}*/
+
+ ir_unop_frexp_sig,
+ ir_unop_frexp_exp,
+
ir_unop_noise,
/**
@@ -2153,6 +2171,7 @@ union ir_constant_data {
int i[16];
float f[16];
bool b[16];
+ double d[16];
};
@@ -2163,6 +2182,7 @@ public:
ir_constant(unsigned int u, unsigned vector_elements=1);
ir_constant(int i, unsigned vector_elements=1);
ir_constant(float f, unsigned vector_elements=1);
+ ir_constant(double d, unsigned vector_elements=1);
/**
* Construct an ir_constant from a list of ir_constant values
@@ -2209,6 +2229,7 @@ public:
/*@{*/
bool get_bool_component(unsigned i) const;
float get_float_component(unsigned i) const;
+ double get_double_component(unsigned i) const;
int get_int_component(unsigned i) const;
unsigned get_uint_component(unsigned i) const;
/*@}*/
diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp
index a2f6f29..37bbffa 100644
--- a/src/glsl/ir_builder.cpp
+++ b/src/glsl/ir_builder.cpp
@@ -251,6 +251,11 @@ ir_expression *round_even(operand a)
return expr(ir_unop_round_even, a);
}
+ir_expression *fract(operand a)
+{
+ return expr(ir_unop_fract, a);
+}
+
/* dot for vectors, mul for scalars */
ir_expression *dot(operand a, operand b)
{
@@ -515,6 +520,24 @@ interpolate_at_sample(operand a, operand b)
}
ir_expression *
+f2d(operand a)
+{
+ return expr(ir_unop_f2d, a);
+}
+
+ir_expression *
+i2d(operand a)
+{
+ return expr(ir_unop_i2d, a);
+}
+
+ir_expression *
+u2d(operand a)
+{
+ return expr(ir_unop_u2d, a);
+}
+
+ir_expression *
fma(operand a, operand b, operand c)
{
return expr(ir_triop_fma, a, b, c);
diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h
index 573596c..81571ef 100644
--- a/src/glsl/ir_builder.h
+++ b/src/glsl/ir_builder.h
@@ -138,6 +138,7 @@ ir_expression *div(operand a, operand b);
ir_expression *carry(operand a, operand b);
ir_expression *borrow(operand a, operand b);
ir_expression *round_even(operand a);
+ir_expression *fract(operand a);
ir_expression *dot(operand a, operand b);
ir_expression *clamp(operand a, operand b, operand c);
ir_expression *saturate(operand a);
@@ -183,6 +184,10 @@ ir_expression *i2b(operand a);
ir_expression *f2b(operand a);
ir_expression *b2f(operand a);
+ir_expression *f2d(operand a);
+ir_expression *i2d(operand a);
+ir_expression *u2d(operand a);
+
ir_expression *min2(operand a, operand b);
ir_expression *max2(operand a, operand b);
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index dffa578..5c7279c 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -327,6 +327,7 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
return new(mem_ctx) ir_constant(this->type, &this->value);
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 1e8b3a3..4387a51 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -60,7 +60,7 @@ static double copysign(double x, double y)
#endif
static float
-dot(ir_constant *op0, ir_constant *op1)
+dot_f(ir_constant *op0, ir_constant *op1)
{
assert(op0->type->is_float() && op1->type->is_float());
@@ -71,6 +71,18 @@ dot(ir_constant *op0, ir_constant *op1)
return result;
}
+static double
+dot_d(ir_constant *op0, ir_constant *op1)
+{
+ assert(op0->type->is_double() && op1->type->is_double());
+
+ double result = 0;
+ for (unsigned c = 0; c < op0->type->components(); c++)
+ result += op0->value.d[c] * op1->value.d[c];
+
+ return result;
+}
+
/* This method is the only one supported by gcc. Unions in particular
* are iffy, and read-through-converted-pointer is killed by strict
* aliasing. OTOH, the compiler sees through the memcpy, so the
@@ -667,32 +679,75 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
data.b[0] = true;
}
break;
-
- case ir_unop_trunc:
+ case ir_unop_d2f:
+ assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.f[c] = op[0]->value.d[c];
+ }
+ break;
+ case ir_unop_f2d:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = truncf(op[0]->value.f[c]);
+ data.d[c] = op[0]->value.f[c];
+ }
+ break;
+ case ir_unop_d2i:
+ assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.i[c] = op[0]->value.d[c];
+ }
+ break;
+ case ir_unop_i2d:
+ assert(op[0]->type->base_type == GLSL_TYPE_INT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.d[c] = op[0]->value.i[c];
+ }
+ break;
+ case ir_unop_d2u:
+ assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.u[c] = op[0]->value.d[c];
+ }
+ break;
+ case ir_unop_u2d:
+ assert(op[0]->type->base_type == GLSL_TYPE_UINT);
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ data.d[c] = op[0]->value.u[c];
+ }
+ break;
+ case ir_unop_trunc:
+ for (unsigned c = 0; c < op[0]->type->components(); c++) {
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = trunc(op[0]->value.d[c]);
+ else
+ data.f[c] = truncf(op[0]->value.f[c]);
}
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] = _mesa_round_to_even(op[0]->value.f[c]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = _mesa_round_to_even(op[0]->value.d[c]);
+ else
+ data.f[c] = _mesa_round_to_even(op[0]->value.f[c]);
}
break;
case ir_unop_ceil:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = ceilf(op[0]->value.f[c]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = ceil(op[0]->value.d[c]);
+ else
+ data.f[c] = ceilf(op[0]->value.f[c]);
}
break;
case ir_unop_floor:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = floorf(op[0]->value.f[c]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = floor(op[0]->value.d[c]);
+ else
+ data.f[c] = floorf(op[0]->value.f[c]);
}
break;
@@ -708,6 +763,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]);
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = op[0]->value.d[c] - floor(op[0]->value.d[c]);
+ break;
default:
assert(0);
}
@@ -742,6 +800,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = -op[0]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = -op[0]->value.d[c];
+ break;
default:
assert(0);
}
@@ -762,6 +823,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = fabs(op[0]->value.f[c]);
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = fabs(op[0]->value.d[c]);
+ break;
default:
assert(0);
}
@@ -780,6 +844,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = float((op[0]->value.f[c] > 0)-(op[0]->value.f[c] < 0));
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = double((op[0]->value.d[c] > 0)-(op[0]->value.d[c] < 0));
+ break;
default:
assert(0);
}
@@ -787,7 +854,6 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
break;
case ir_unop_rcp:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
switch (this->type->base_type) {
case GLSL_TYPE_UINT:
@@ -802,6 +868,10 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
if (op[0]->value.f[c] != 0.0)
data.f[c] = 1.0F / op[0]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ if (op[0]->value.d[c] != 0.0)
+ data.d[c] = 1.0 / op[0]->value.d[c];
+ break;
default:
assert(0);
}
@@ -809,16 +879,20 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
break;
case ir_unop_rsq:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = 1.0 / sqrt(op[0]->value.d[c]);
+ else
+ data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]);
}
break;
case ir_unop_sqrt:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
- data.f[c] = sqrtf(op[0]->value.f[c]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = sqrt(op[0]->value.d[c]);
+ else
+ data.f[c] = sqrtf(op[0]->value.f[c]);
}
break;
@@ -934,7 +1008,10 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
break;
case ir_binop_dot:
- data.f[0] = dot(op[0], op[1]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[0] = dot_d(op[0], op[1]);
+ else
+ data.f[0] = dot_f(op[0], op[1]);
break;
case ir_binop_min:
@@ -953,6 +1030,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]);
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = MIN2(op[0]->value.d[c0], op[1]->value.d[c1]);
+ break;
default:
assert(0);
}
@@ -975,6 +1055,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]);
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = MAX2(op[0]->value.d[c0], op[1]->value.d[c1]);
+ break;
default:
assert(0);
}
@@ -997,6 +1080,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = op[0]->value.d[c0] + op[1]->value.d[c1];
+ break;
default:
assert(0);
}
@@ -1019,6 +1105,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = op[0]->value.d[c0] - op[1]->value.d[c1];
+ break;
default:
assert(0);
}
@@ -1043,6 +1132,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = op[0]->value.d[c0] * op[1]->value.d[c1];
+ break;
default:
assert(0);
}
@@ -1066,7 +1158,10 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
for (unsigned j = 0; j < p; j++) {
for (unsigned i = 0; i < n; i++) {
for (unsigned k = 0; k < m; k++) {
- data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j];
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[i+n*j] += op[0]->value.d[i+n*k]*op[1]->value.d[k+m*j];
+ else
+ data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j];
}
}
}
@@ -1098,6 +1193,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = op[0]->value.d[c0] / op[1]->value.d[c1];
+ break;
default:
assert(0);
}
@@ -1133,6 +1231,13 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]
* floorf(op[0]->value.f[c0] / op[1]->value.f[c1]);
break;
+ case GLSL_TYPE_DOUBLE:
+ /* We don't use fmod because it rounds toward zero; GLSL specifies
+ * the use of floor.
+ */
+ data.d[c] = op[0]->value.d[c0] - op[1]->value.d[c1]
+ * floor(op[0]->value.d[c0] / op[1]->value.d[c1]);
+ break;
default:
assert(0);
}
@@ -1169,6 +1274,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.b[c] = op[0]->value.f[c] < op[1]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.b[c] = op[0]->value.d[c] < op[1]->value.d[c];
+ break;
default:
assert(0);
}
@@ -1187,6 +1295,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.b[c] = op[0]->value.f[c] > op[1]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.b[c] = op[0]->value.d[c] > op[1]->value.d[c];
+ break;
default:
assert(0);
}
@@ -1205,6 +1316,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.b[c] = op[0]->value.f[c] <= op[1]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.b[c] = op[0]->value.d[c] <= op[1]->value.d[c];
+ break;
default:
assert(0);
}
@@ -1223,6 +1337,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.b[c] = op[0]->value.f[c] >= op[1]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.b[c] = op[0]->value.d[c] >= op[1]->value.d[c];
+ break;
default:
assert(0);
}
@@ -1244,6 +1361,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_BOOL:
data.b[c] = op[0]->value.b[c] == op[1]->value.b[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.b[c] = op[0]->value.d[c] == op[1]->value.d[c];
+ break;
default:
assert(0);
}
@@ -1265,6 +1385,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_BOOL:
data.b[c] = op[0]->value.b[c] != op[1]->value.b[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.b[c] = op[0]->value.d[c] != op[1]->value.d[c];
+ break;
default:
assert(0);
}
@@ -1375,6 +1498,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[0] = op[0]->value.f[c];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[0] = op[0]->value.d[c];
+ break;
case GLSL_TYPE_BOOL:
data.b[0] = op[0]->value.b[c];
break;
@@ -1474,6 +1600,17 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
data.f[c] = CLAMP(op[0]->value.f[c], 0.0f, 1.0f);
}
break;
+ case ir_unop_pack_double_2x32: {
+ uint64_t temp;
+ temp = (uint64_t)op[0]->value.u[0] | ((uint64_t)op[0]->value.u[1] << 32);
+ data.d[0] = *(double *)&temp;
+
+ break;
+ }
+ case ir_unop_unpack_double_2x32:
+ data.u[0] = *(uint32_t *)&op[0]->value.d[0];
+ data.u[1] = *((uint32_t *)&op[0]->value.d[0] + 1);
+ break;
case ir_triop_bitfield_extract: {
int offset = op[1]->value.i[0];
@@ -1523,40 +1660,60 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case ir_binop_ldexp:
for (unsigned c = 0; c < components; c++) {
- data.f[c] = ldexp(op[0]->value.f[c], op[1]->value.i[c]);
- /* Flush subnormal values to zero. */
- if (!isnormal(data.f[c]))
- data.f[c] = copysign(0.0f, op[0]->value.f[c]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE) {
+ data.d[c] = ldexp(op[0]->value.d[c], op[1]->value.i[c]);
+ /* Flush subnormal values to zero. */
+ if (!isnormal(data.d[c]))
+ data.d[c] = copysign(0.0, op[0]->value.d[c]);
+
+ } else {
+ data.f[c] = ldexp(op[0]->value.f[c], op[1]->value.i[c]);
+ /* Flush subnormal values to zero. */
+ if (!isnormal(data.f[c]))
+ data.f[c] = copysign(0.0f, op[0]->value.f[c]);
+ }
}
break;
case ir_triop_fma:
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(op[1]->type->base_type == GLSL_TYPE_FLOAT);
- assert(op[2]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT || op[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(op[1]->type->base_type == GLSL_TYPE_FLOAT || op[1]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(op[2]->type->base_type == GLSL_TYPE_FLOAT || op[2]->type->base_type == GLSL_TYPE_DOUBLE);
for (unsigned c = 0; c < components; c++) {
- data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]
- + op[2]->value.f[c];
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = op[0]->value.d[c] * op[1]->value.d[c]
+ + op[2]->value.d[c];
+ else
+ data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]
+ + op[2]->value.f[c];
}
break;
case ir_triop_lrp: {
- assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- assert(op[1]->type->base_type == GLSL_TYPE_FLOAT);
- assert(op[2]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT || op[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(op[1]->type->base_type == GLSL_TYPE_FLOAT || op[1]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(op[2]->type->base_type == GLSL_TYPE_FLOAT || op[2]->type->base_type == GLSL_TYPE_DOUBLE);
unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) {
- data.f[c] = op[0]->value.f[c] * (1.0f - op[2]->value.f[c2]) +
- (op[1]->value.f[c] * op[2]->value.f[c2]);
+ if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = op[0]->value.d[c] * (1.0 - op[2]->value.d[c2]) +
+ (op[1]->value.d[c] * op[2]->value.d[c2]);
+ else
+ data.f[c] = op[0]->value.f[c] * (1.0f - op[2]->value.f[c2]) +
+ (op[1]->value.f[c] * op[2]->value.f[c2]);
}
break;
}
case ir_triop_csel:
for (unsigned c = 0; c < components; c++) {
- data.u[c] = op[0]->value.b[c] ? op[1]->value.u[c]
+ if (op[1]->type->base_type == GLSL_TYPE_DOUBLE)
+ data.d[c] = op[0]->value.b[c] ? op[1]->value.d[c]
+ : op[2]->value.d[c];
+ else
+ data.u[c] = op[0]->value.b[c] ? op[1]->value.u[c]
: op[2]->value.u[c];
}
break;
@@ -1579,6 +1736,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_BOOL:
data.b[idx] = op[1]->value.b[0];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[idx] = op[1]->value.d[0];
+ break;
default:
assert(!"Should not get here.");
break;
@@ -1625,6 +1785,9 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_FLOAT:
data.f[c] = op[c]->value.f[0];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[c] = op[c]->value.d[0];
+ break;
default:
assert(0);
}
@@ -1666,6 +1829,7 @@ ir_swizzle::constant_expression_value(struct hash_table *variable_context)
case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break;
case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break;
case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break;
+ case GLSL_TYPE_DOUBLE:data.d[i] = v->value.d[swiz_idx[i]]; break;
default: assert(!"Should not get here."); break;
}
}
@@ -1740,6 +1904,12 @@ ir_dereference_array::constant_expression_value(struct hash_table *variable_cont
break;
+ case GLSL_TYPE_DOUBLE:
+ for (unsigned i = 0; i < column_type->vector_elements; i++)
+ data.d[i] = array->value.d[mat_idx + i];
+
+ break;
+
default:
assert(!"Should not get here.");
break;
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index bd39805..3600827 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -436,6 +436,17 @@ void ir_print_visitor::visit(ir_constant *ir)
fprintf(f, "%f", ir->value.f[i]);
break;
case GLSL_TYPE_BOOL: fprintf(f, "%d", ir->value.b[i]); break;
+ case GLSL_TYPE_DOUBLE:
+ if (ir->value.d[i] == 0.0)
+ /* 0.0 == -0.0, so print with %f to get the proper sign. */
+ fprintf(f, "%.1f", ir->value.d[i]);
+ else if (fabs(ir->value.d[i]) < 0.000001)
+ fprintf(f, "%a", ir->value.f[i]);
+ else if (fabs(ir->value.d[i]) > 1000000.0)
+ fprintf(f, "%e", ir->value.d[i]);
+ else
+ fprintf(f, "%f", ir->value.d[i]);
+ break;
default: assert(0);
}
}
diff --git a/src/glsl/ir_set_program_inouts.cpp b/src/glsl/ir_set_program_inouts.cpp
index 97ead75..4aa402e 100644
--- a/src/glsl/ir_set_program_inouts.cpp
+++ b/src/glsl/ir_set_program_inouts.cpp
@@ -81,6 +81,17 @@ is_shader_inout(ir_variable *var)
var->data.mode == ir_var_system_value;
}
+static inline bool
+is_dvec34_inout(ir_variable *var)
+{
+ if (var->type == glsl_type::dvec4_type || var->type == glsl_type::dvec3_type)
+ return true;
+
+ if (var->type->is_array() && (var->type->element_type() == glsl_type::dvec4_type || var->type->element_type() == glsl_type::dvec3_type))
+ return true;
+ return false;
+}
+
static void
mark(struct gl_program *prog, ir_variable *var, int offset, int len,
bool is_fragment_shader)
@@ -94,19 +105,26 @@ mark(struct gl_program *prog, ir_variable *var, int offset, int len,
*/
for (int i = 0; i < len; i++) {
+ int idx = var->data.location + var->data.index + offset + i;
GLbitfield64 bitfield =
- BITFIELD64_BIT(var->data.location + var->data.index + offset + i);
+ BITFIELD64_BIT(idx);
+
+ if (is_dvec34_inout(var))
+ bitfield |= bitfield << 1;
if (var->data.mode == ir_var_shader_in) {
prog->InputsRead |= bitfield;
if (is_fragment_shader) {
gl_fragment_program *fprog = (gl_fragment_program *) prog;
- fprog->InterpQualifier[var->data.location +
- var->data.index + offset + i] =
+ fprog->InterpQualifier[idx] =
(glsl_interp_qualifier) var->data.interpolation;
if (var->data.centroid)
fprog->IsCentroid |= bitfield;
if (var->data.sample)
fprog->IsSample |= bitfield;
+
+ if (is_dvec34_inout(var))
+ fprog->InterpQualifier[idx + 1] =
+ (glsl_interp_qualifier) var->data.interpolation;
}
} else if (var->data.mode == ir_var_system_value) {
prog->SystemValuesRead |= bitfield;
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 6d56339..73a694c 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -313,6 +313,9 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_ceil:
case ir_unop_floor:
case ir_unop_fract:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(ir->operands[0]->type == ir->type);
+ break;
case ir_unop_sin:
case ir_unop_cos:
case ir_unop_sin_reduced:
@@ -340,6 +343,11 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->operands[0]->type == glsl_type::vec4_type);
break;
+ case ir_unop_pack_double_2x32:
+ assert(ir->type == glsl_type::double_type);
+ assert(ir->operands[0]->type == glsl_type::uvec2_type);
+ break;
+
case ir_unop_unpack_snorm_2x16:
case ir_unop_unpack_unorm_2x16:
case ir_unop_unpack_half_2x16:
@@ -359,6 +367,11 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->operands[0]->type == glsl_type::uint_type);
break;
+ case ir_unop_unpack_double_2x32:
+ assert(ir->type == glsl_type::uvec2_type);
+ assert(ir->operands[0]->type == glsl_type::double_type);
+ break;
+
case ir_unop_bitfield_reverse:
assert(ir->operands[0]->type == ir->type);
assert(ir->type->is_integer());
@@ -381,6 +394,41 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->operands[0]->type->is_float());
break;
+ case ir_unop_d2f:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+ break;
+ case ir_unop_f2d:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+ break;
+ case ir_unop_d2i:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(ir->type->base_type == GLSL_TYPE_INT);
+ break;
+ case ir_unop_i2d:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+ assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+ break;
+ case ir_unop_d2u:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(ir->type->base_type == GLSL_TYPE_UINT);
+ break;
+ case ir_unop_u2d:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
+ assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+ break;
+
+ case ir_unop_frexp_sig:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
+ ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+ break;
+ case ir_unop_frexp_exp:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
+ ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+ assert(ir->type->base_type == GLSL_TYPE_INT);
+ break;
case ir_binop_add:
case ir_binop_sub:
case ir_binop_mul:
@@ -481,8 +529,8 @@ ir_validate::visit_leave(ir_expression *ir)
break;
case ir_binop_dot:
- assert(ir->type == glsl_type::float_type);
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->type == glsl_type::float_type || ir->type == glsl_type::double_type);
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
assert(ir->operands[0]->type->is_vector());
assert(ir->operands[0]->type == ir->operands[1]->type);
break;
@@ -507,7 +555,8 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_binop_ldexp:
assert(ir->operands[0]->type == ir->type);
- assert(ir->operands[0]->type->is_float());
+ assert(ir->operands[0]->type->is_float() ||
+ ir->operands[0]->type->is_double());
assert(ir->operands[1]->type->base_type == GLSL_TYPE_INT);
assert(ir->operands[0]->type->components() ==
ir->operands[1]->type->components());
@@ -533,16 +582,16 @@ ir_validate::visit_leave(ir_expression *ir)
break;
case ir_triop_fma:
- assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT || ir->type->base_type == GLSL_TYPE_DOUBLE);
assert(ir->type == ir->operands[0]->type);
assert(ir->type == ir->operands[1]->type);
assert(ir->type == ir->operands[2]->type);
break;
case ir_triop_lrp:
- assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
assert(ir->operands[0]->type == ir->operands[1]->type);
- assert(ir->operands[2]->type == ir->operands[0]->type || ir->operands[2]->type == glsl_type::float_type);
+ assert(ir->operands[2]->type == ir->operands[0]->type || ir->operands[2]->type == glsl_type::float_type || ir->operands[2]->type == glsl_type::double_type);
break;
case ir_triop_csel:
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp
index f6a60bc..b4fb38f 100644
--- a/src/glsl/link_uniform_initializers.cpp
+++ b/src/glsl/link_uniform_initializers.cpp
@@ -75,6 +75,10 @@ copy_constant_to_storage(union gl_constant_value *storage,
case GLSL_TYPE_FLOAT:
storage[i].f = val->value.f[i];
break;
+ case GLSL_TYPE_DOUBLE:
+ storage[i * 2].u = *(uint32_t *)&val->value.d[i];
+ storage[i * 2 + 1].u = *(((uint32_t *)&val->value.d[i]) + 1);
+ break;
case GLSL_TYPE_BOOL:
storage[i].b = val->value.b[i] ? boolean_true : 0;
break;
@@ -200,6 +204,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
val->array_elements[0]->type->base_type;
const unsigned int elements = val->array_elements[0]->type->components();
unsigned int idx = 0;
+ unsigned dmul = (base_type == GLSL_TYPE_DOUBLE) ? 2 : 1;
assert(val->type->length >= storage->array_elements);
for (unsigned int i = 0; i < storage->array_elements; i++) {
@@ -209,7 +214,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
elements,
boolean_true);
- idx += elements;
+ idx += elements * dmul;
}
} else {
copy_constant_to_storage(storage->storage,
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index de2f6c9..0db70d5 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -51,6 +51,9 @@ values_for_type(const glsl_type *type)
return 1;
} else if (type->is_array() && type->fields.array->is_sampler()) {
return type->array_size();
+ } else if ((type->is_array() && type->fields.array->is_double()) ||
+ type->is_double()) {
+ return 2 * type->component_slots();
} else {
return type->component_slots();
}
@@ -608,8 +611,11 @@ private:
}
if (type->without_array()->is_matrix()) {
- this->uniforms[id].matrix_stride = 16;
+ unsigned N = type->base_type == GLSL_TYPE_DOUBLE ? 8 : 4;
+ unsigned items = row_major ? type->matrix_columns : type->vector_elements;
+ this->uniforms[id].matrix_stride = glsl_align(items * N, 16);
this->uniforms[id].row_major = row_major;
+
} else {
this->uniforms[id].matrix_stride = 0;
this->uniforms[id].row_major = false;
diff --git a/src/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp
index 2261799..213425c 100644
--- a/src/glsl/link_varyings.cpp
+++ b/src/glsl/link_varyings.cpp
@@ -868,8 +868,9 @@ varying_matches::record(ir_variable *producer_var, ir_variable *consumer_var)
: var->type->matrix_columns;
this->matches[this->num_matches].num_components = 4 * slots;
} else {
+ unsigned slot_mul = var->type->is_double() ? 2 : 1;
this->matches[this->num_matches].num_components
- = var->type->component_slots();
+ = var->type->component_slots() * slot_mul;
}
this->matches[this->num_matches].producer_var = producer_var;
this->matches[this->num_matches].consumer_var = consumer_var;
diff --git a/src/glsl/loop_controls.cpp b/src/glsl/loop_controls.cpp
index 1c1d34f..9a99c21 100644
--- a/src/glsl/loop_controls.cpp
+++ b/src/glsl/loop_controls.cpp
@@ -102,10 +102,18 @@ calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
return -1;
if (!iter->type->is_integer()) {
- ir_rvalue *cast =
- new(mem_ctx) ir_expression(ir_unop_f2i, glsl_type::int_type, iter,
- NULL);
-
+ ir_rvalue *cast = NULL;
+ if (iter->type->is_double()) {
+ ir_expression *d2f =
+ new(mem_ctx) ir_expression(ir_unop_d2f, glsl_type::float_type,
+ iter, NULL);
+ cast = new(mem_ctx) ir_expression(ir_unop_f2i, glsl_type::int_type,
+ (ir_rvalue*) d2f, NULL);
+ } else {
+ cast = new(mem_ctx) ir_expression(ir_unop_f2i, glsl_type::int_type, iter,
+ NULL);
+ }
+ assert(cast);
iter = cast->constant_expression_value();
}
@@ -134,6 +142,9 @@ calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
case GLSL_TYPE_FLOAT:
iter = new(mem_ctx) ir_constant(float(iter_value + bias[i]));
break;
+ case GLSL_TYPE_DOUBLE:
+ iter = new(mem_ctx) ir_constant(double(iter_value + bias[i]));
+ break;
default:
unreachable(!"Unsupported type for loop iterator.");
}
diff --git a/src/glsl/lower_mat_op_to_vec.cpp b/src/glsl/lower_mat_op_to_vec.cpp
index 105ee0d..dda754f 100644
--- a/src/glsl/lower_mat_op_to_vec.cpp
+++ b/src/glsl/lower_mat_op_to_vec.cpp
@@ -354,6 +354,8 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
/* OK, time to break down this matrix operation. */
switch (orig_expr->operation) {
+ case ir_unop_d2f:
+ case ir_unop_f2d:
case ir_unop_neg: {
/* Apply the operation to each column.*/
for (i = 0; i < matrix_columns; i++) {
diff --git a/src/glsl/lower_ubo_reference.cpp b/src/glsl/lower_ubo_reference.cpp
index 43dd067..e539491 100644
--- a/src/glsl/lower_ubo_reference.cpp
+++ b/src/glsl/lower_ubo_reference.cpp
@@ -510,16 +510,23 @@ lower_ubo_reference_visitor::emit_ubo_loads(ir_dereference *deref,
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
ubo_load(deref->type, offset)));
} else {
+
+ unsigned N = deref->type->is_double() ? 8 : 4;
+
/* We're dereffing a column out of a row-major matrix, so we
* gather the vector from each stored row.
*/
- assert(deref->type->base_type == GLSL_TYPE_FLOAT);
+ assert(deref->type->base_type == GLSL_TYPE_FLOAT ||
+ deref->type->base_type == GLSL_TYPE_DOUBLE);
/* Matrices, row_major or not, are stored as if they were
* arrays of vectors of the appropriate size in std140.
* Arrays have their strides rounded up to a vec4, so the
* matrix stride is always 16.
*/
- unsigned matrix_stride = 16;
+ unsigned matrix_stride = 4 * N;
+
+ const glsl_type *ubo_type = deref->type->base_type == GLSL_TYPE_FLOAT ?
+ glsl_type::float_type : glsl_type::double_type;
for (unsigned i = 0; i < deref->type->vector_elements; i++) {
ir_rvalue *chan_offset =
@@ -527,7 +534,7 @@ lower_ubo_reference_visitor::emit_ubo_loads(ir_dereference *deref,
new(mem_ctx) ir_constant(deref_offset + i * matrix_stride));
base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
- ubo_load(glsl_type::float_type,
+ ubo_load(ubo_type,
chan_offset),
(1U << i)));
}
diff --git a/src/glsl/opt_constant_propagation.cpp b/src/glsl/opt_constant_propagation.cpp
index c334e12..90cc0c8 100644
--- a/src/glsl/opt_constant_propagation.cpp
+++ b/src/glsl/opt_constant_propagation.cpp
@@ -194,6 +194,9 @@ ir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue)
case GLSL_TYPE_FLOAT:
data.f[i] = found->constant->value.f[rhs_channel];
break;
+ case GLSL_TYPE_DOUBLE:
+ data.d[i] = found->constant->value.d[rhs_channel];
+ break;
case GLSL_TYPE_INT:
data.i[i] = found->constant->value.i[rhs_channel];
break;
diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index 32fb2d7..23d0b10 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -133,6 +133,14 @@ compare_components(ir_constant *a, ir_constant *b)
else
foundequal = true;
break;
+ case GLSL_TYPE_DOUBLE:
+ if (a->value.d[c0] < b->value.d[c1])
+ foundless = true;
+ else if (a->value.d[c0] > b->value.d[c1])
+ foundgreater = true;
+ else
+ foundequal = true;
+ break;
default:
unreachable("not reached");
}
@@ -178,6 +186,11 @@ combine_constant(bool ismin, ir_constant *a, ir_constant *b)
(!ismin && b->value.f[i] > c->value.f[i]))
c->value.f[i] = b->value.f[i];
break;
+ case GLSL_TYPE_DOUBLE:
+ if ((ismin && b->value.d[i] < c->value.d[i]) ||
+ (!ismin && b->value.d[i] > c->value.d[i]))
+ c->value.d[i] = b->value.d[i];
+ break;
default:
assert(!"not reached");
}
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 54413cd..4bcdbc3 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -1356,6 +1356,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
case ir_unop_pack_unorm_2x16:
case ir_unop_pack_unorm_4x8:
case ir_unop_pack_half_2x16:
+ case ir_unop_pack_double_2x32:
case ir_unop_unpack_snorm_2x16:
case ir_unop_unpack_snorm_4x8:
case ir_unop_unpack_unorm_2x16:
@@ -1363,11 +1364,20 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
case ir_unop_unpack_half_2x16:
case ir_unop_unpack_half_2x16_split_x:
case ir_unop_unpack_half_2x16_split_y:
+ case ir_unop_unpack_double_2x32:
case ir_binop_pack_half_2x16_split:
case ir_unop_bitfield_reverse:
case ir_unop_bit_count:
case ir_unop_find_msb:
case ir_unop_find_lsb:
+ case ir_unop_d2f:
+ case ir_unop_f2d:
+ case ir_unop_d2i:
+ case ir_unop_i2d:
+ case ir_unop_d2u:
+ case ir_unop_u2d:
+ case ir_unop_frexp_sig:
+ case ir_unop_frexp_exp:
assert(!"not supported");
break;
case ir_binop_min:
--
2.0.5
More information about the mesa-dev
mailing list