From: Dave Airlie <airl...@redhat.com> This just adds the new operations and add 64-bit integer support to all the existing cases where it is needed.
Signed-off-by: Dave Airlie <airl...@redhat.com> --- src/compiler/glsl/ir_constant_expression.cpp | 324 +++++++++++++++++++++++++++ 1 file changed, 324 insertions(+) diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp index fbbf779..e6f5668 100644 --- a/src/compiler/glsl/ir_constant_expression.cpp +++ b/src/compiler/glsl/ir_constant_expression.cpp @@ -88,6 +88,42 @@ bitcast_f2u(float f) return u; } +static double +bitcast_u642d(uint64_t u) +{ + assert(sizeof(double) == sizeof(uint64_t)); + double d; + memcpy(&d, &u, sizeof(d)); + return d; +} + +static double +bitcast_i642d(int64_t i) +{ + assert(sizeof(double) == sizeof(int64_t)); + double d; + memcpy(&d, &i, sizeof(d)); + return d; +} + +static double +bitcast_d2u64(double d) +{ + assert(sizeof(double) == sizeof(uint64_t)); + uint64_t u; + memcpy(&u, &d, sizeof(d)); + return u; +} + +static double +bitcast_d2i64(double d) +{ + assert(sizeof(double) == sizeof(int64_t)); + int64_t i; + memcpy(&i, &d, sizeof(d)); + return i; +} + /** * Evaluate one component of a floating-point 4x8 unpacking function. */ @@ -690,6 +726,162 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) data.b[c] = op[0]->value.d[c] != 0.0; } break; + case ir_unop_bitcast_u642d: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.d[c] = bitcast_u642d(op[0]->value.u64[c]); + } + break; + case ir_unop_bitcast_i642d: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.d[c] = bitcast_i642d(op[0]->value.i64[c]); + } + break; + case ir_unop_bitcast_d2u64: + assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u64[c] = bitcast_d2u64(op[0]->value.d[c]); + } + break; + case ir_unop_bitcast_d2i64: + assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = bitcast_d2i64(op[0]->value.d[c]); + } + break; + case ir_unop_i642i: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i[c] = op[0]->value.i64[c]; + } + break; + case ir_unop_u642i: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i[c] = op[0]->value.u64[c]; + } + break; + case ir_unop_i642u: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u[c] = op[0]->value.i64[c]; + } + break; + case ir_unop_u642u: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u[c] = op[0]->value.u64[c]; + } + break; + case ir_unop_i642b: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.b[c] = op[0]->value.i64[c] != 0; + } + break; + case ir_unop_u642b: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.b[c] = op[0]->value.u64[c] != 0; + } + break; + case ir_unop_i642f: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = op[0]->value.i64[c]; + } + break; + case ir_unop_u642f: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = op[0]->value.u64[c]; + } + break; + case ir_unop_i642d: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.d[c] = op[0]->value.i64[c]; + } + break; + case ir_unop_u642d: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.d[c] = op[0]->value.u64[c]; + } + break; + case ir_unop_i2i64: + assert(op[0]->type->base_type == GLSL_TYPE_INT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.i[c]; + } + break; + case ir_unop_u2i64: + assert(op[0]->type->base_type == GLSL_TYPE_UINT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.u[c]; + } + break; + case ir_unop_b2i64: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.b[c]; + } + break; + case ir_unop_f2i64: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.f[c]; + } + break; + case ir_unop_d2i64: + assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.d[c]; + } + break; + case ir_unop_i2u64: + assert(op[0]->type->base_type == GLSL_TYPE_INT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.i[c]; + } + break; + case ir_unop_u2u64: + assert(op[0]->type->base_type == GLSL_TYPE_UINT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u64[c] = op[0]->value.u[c]; + } + break; + case ir_unop_b2u64: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u64[c] = op[0]->value.b[c]; + } + break; + case ir_unop_f2u64: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u64[c] = op[0]->value.f[c]; + } + break; + case ir_unop_d2u64: + assert(op[0]->type->base_type == GLSL_TYPE_DOUBLE); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u64[c] = op[0]->value.d[c]; + } + break; + case ir_unop_i642u64: + assert(op[0]->type->base_type == GLSL_TYPE_INT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u64[c] = op[0]->value.i64[c]; + } + break; + case ir_unop_u642i64: + assert(op[0]->type->base_type == GLSL_TYPE_UINT64); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i64[c] = op[0]->value.u64[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) @@ -776,6 +968,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = -op[0]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.u64[c] = -((int64_t)op[0]->value.u64[c]); + break; + case GLSL_TYPE_INT64: + data.i64[c] = -op[0]->value.i64[c]; + break; default: assert(0); } @@ -799,6 +997,14 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = fabs(op[0]->value.d[c]); break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c]; + if (data.i64[c] < 0) + data.i64[c] = -data.i64[c]; + break; default: assert(0); } @@ -820,6 +1026,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = double((op[0]->value.d[c] > 0)-(op[0]->value.d[c] < 0)); break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.i64[c] > 0; + break; + case GLSL_TYPE_INT64: + data.i64[c] = (op[0]->value.i64[c] > 0) - (op[0]->value.i64[c] < 0); + break; default: assert(0); } @@ -1006,6 +1218,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = MIN2(op[0]->value.d[c0], op[1]->value.d[c1]); break; + case GLSL_TYPE_UINT64: + data.u64[c] = MIN2(op[0]->value.u64[c0], op[1]->value.u64[c1]); + break; + case GLSL_TYPE_INT64: + data.i64[c] = MIN2(op[0]->value.i64[c0], op[1]->value.i64[c1]); + break; default: assert(0); } @@ -1031,6 +1249,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = MAX2(op[0]->value.d[c0], op[1]->value.d[c1]); break; + case GLSL_TYPE_UINT64: + data.u64[c] = MAX2(op[0]->value.u64[c0], op[1]->value.u64[c1]); + break; + case GLSL_TYPE_INT64: + data.i64[c] = MAX2(op[0]->value.i64[c0], op[1]->value.i64[c1]); + break; default: assert(0); } @@ -1056,6 +1280,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = op[0]->value.d[c0] + op[1]->value.d[c1]; break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c0] + op[1]->value.u64[c1]; + break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c0] + op[1]->value.i64[c1]; + break; default: assert(0); } @@ -1081,6 +1311,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = op[0]->value.d[c0] - op[1]->value.d[c1]; break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c0] - op[1]->value.u64[c1]; + break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c0] - op[1]->value.i64[c1]; + break; default: assert(0); } @@ -1108,6 +1344,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = op[0]->value.d[c0] * op[1]->value.d[c1]; break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c0] * op[1]->value.u64[c1]; + break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c0] * op[1]->value.i64[c1]; + break; default: assert(0); } @@ -1169,6 +1411,20 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.d[c] = op[0]->value.d[c0] / op[1]->value.d[c1]; break; + case GLSL_TYPE_UINT64: + if (op[1]->value.u64[c1] == 0) { + data.u64[c] = 0; + } else { + data.u64[c] = op[0]->value.u64[c0] / op[1]->value.u64[c1]; + } + break; + case GLSL_TYPE_INT64: + if (op[1]->value.i64[c1] == 0) { + data.i64[c] = 0; + } else { + data.i64[c] = op[0]->value.i64[c0] / op[1]->value.i64[c1]; + } + break; default: assert(0); } @@ -1211,6 +1467,20 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) 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; + case GLSL_TYPE_UINT64: + if (op[1]->value.u64[c1] == 0) { + data.u64[c] = 0; + } else { + data.u64[c] = op[0]->value.u64[c0] % op[1]->value.u64[c1]; + } + break; + case GLSL_TYPE_INT64: + if (op[1]->value.i64[c1] == 0) { + data.i64[c] = 0; + } else { + data.i64[c] = op[0]->value.i64[c0] % op[1]->value.i64[c1]; + } + break; default: assert(0); } @@ -1250,6 +1520,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.b[c] = op[0]->value.d[c] < op[1]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.b[c] = op[0]->value.u64[c] < op[1]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.b[c] = op[0]->value.i64[c] < op[1]->value.i64[c]; + break; default: assert(0); } @@ -1271,6 +1547,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.b[c] = op[0]->value.d[c] > op[1]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.b[c] = op[0]->value.u64[c] > op[1]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.b[c] = op[0]->value.i64[c] > op[1]->value.i64[c]; + break; default: assert(0); } @@ -1292,6 +1574,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.b[c] = op[0]->value.d[c] <= op[1]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.b[c] = op[0]->value.u64[c] <= op[1]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.b[c] = op[0]->value.i64[c] <= op[1]->value.i64[c]; + break; default: assert(0); } @@ -1313,6 +1601,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.b[c] = op[0]->value.d[c] >= op[1]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.b[c] = op[0]->value.u64[c] >= op[1]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.b[c] = op[0]->value.i64[c] >= op[1]->value.i64[c]; + break; default: assert(0); } @@ -1337,6 +1631,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.b[c] = op[0]->value.d[c] == op[1]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.b[c] = op[0]->value.u64[c] == op[1]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.b[c] = op[0]->value.i64[c] == op[1]->value.i64[c]; + break; default: assert(0); } @@ -1361,6 +1661,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_DOUBLE: data.b[c] = op[0]->value.d[c] != op[1]->value.d[c]; break; + case GLSL_TYPE_UINT64: + data.b[c] = op[0]->value.u64[c] != op[1]->value.u64[c]; + break; + case GLSL_TYPE_INT64: + data.b[c] = op[0]->value.i64[c] != op[1]->value.i64[c]; + break; default: assert(0); } @@ -1433,6 +1739,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] & op[1]->value.u[c1]; break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c0] & op[1]->value.i64[c1]; + break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c0] & op[1]->value.u64[c1]; + break; default: assert(0); } @@ -1451,6 +1763,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] | op[1]->value.u[c1]; break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c0] | op[1]->value.i64[c1]; + break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c0] | op[1]->value.u64[c1]; + break; default: assert(0); } @@ -1495,6 +1813,12 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] ^ op[1]->value.u[c1]; break; + case GLSL_TYPE_INT64: + data.i64[c] = op[0]->value.i64[c0] ^ op[1]->value.i64[c1]; + break; + case GLSL_TYPE_UINT64: + data.u64[c] = op[0]->value.u64[c0] ^ op[1]->value.u64[c1]; + break; default: assert(0); } -- 2.5.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev