[Mesa-dev] [PATCH 16/59] glsl/ir: Add support for 64-bit integer conversions.

Ian Romanick idr at freedesktop.org
Wed Oct 26 00:59:22 UTC 2016


From: Dave Airlie <airlied at redhat.com>

This adds all the conversions in the world, I'm not 100% sure of all of
these are needed, but add all of them and we can cut them down later.

v2: fix issue with packing output types.

v3 (idr): Rebase on top of idr's series to generate
ir_expression_operation_constant.h.  Fix transposed ir_validate
assertions for ir_unop_u642i64 and ir_unop_i642u64.  Add missing
automatic type setup for ir_unop_u642i64 and ir_unop_i642u64.

Signed-off-by: Dave Airlie <airlied at redhat.com>
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com> [v2]
---
 src/compiler/glsl/ir.cpp                     |  57 ++++++++++++
 src/compiler/glsl/ir_expression_operation.py |  41 +++++++++
 src/compiler/glsl/ir_validate.cpp            | 124 +++++++++++++++++++++++++++
 3 files changed, 222 insertions(+)

diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index db25aaf..85b906a 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -261,6 +261,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_find_msb:
    case ir_unop_find_lsb:
    case ir_unop_subroutine_to_int:
+   case ir_unop_i642i:
+   case ir_unop_u642i:
       this->type = glsl_type::get_instance(GLSL_TYPE_INT,
 					   op0->type->vector_elements, 1);
       break;
@@ -271,6 +273,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_d2f:
    case ir_unop_bitcast_i2f:
    case ir_unop_bitcast_u2f:
+   case ir_unop_i642f:
+   case ir_unop_u642f:
       this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT,
 					   op0->type->vector_elements, 1);
       break;
@@ -278,6 +282,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_f2b:
    case ir_unop_i2b:
    case ir_unop_d2b:
+   case ir_unop_i642b:
+   case ir_unop_u642b:
       this->type = glsl_type::get_instance(GLSL_TYPE_BOOL,
 					   op0->type->vector_elements, 1);
       break;
@@ -285,6 +291,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_f2d:
    case ir_unop_i2d:
    case ir_unop_u2d:
+   case ir_unop_i642d:
+   case ir_unop_u642d:
       this->type = glsl_type::get_instance(GLSL_TYPE_DOUBLE,
 					   op0->type->vector_elements, 1);
       break;
@@ -293,18 +301,44 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_f2u:
    case ir_unop_d2u:
    case ir_unop_bitcast_f2u:
+   case ir_unop_i642u:
+   case ir_unop_u642u:
       this->type = glsl_type::get_instance(GLSL_TYPE_UINT,
 					   op0->type->vector_elements, 1);
       break;
 
+   case ir_unop_i2i64:
+   case ir_unop_u2i64:
+   case ir_unop_b2i64:
+   case ir_unop_f2i64:
+   case ir_unop_d2i64:
+   case ir_unop_u642i64:
+      this->type = glsl_type::get_instance(GLSL_TYPE_INT64,
+					   op0->type->vector_elements, 1);
+      break;
+
+   case ir_unop_i2u64:
+   case ir_unop_u2u64:
+   case ir_unop_b2u64:
+   case ir_unop_f2u64:
+   case ir_unop_d2u64:
+   case ir_unop_i642u64:
+      this->type = glsl_type::get_instance(GLSL_TYPE_UINT64,
+					   op0->type->vector_elements, 1);
+      break;
    case ir_unop_noise:
       this->type = glsl_type::float_type;
       break;
 
    case ir_unop_unpack_double_2x32:
+   case ir_unop_unpack_uint_2x32:
       this->type = glsl_type::uvec2_type;
       break;
 
+   case ir_unop_unpack_int_2x32:
+      this->type = glsl_type::ivec2_type;
+      break;
+
    case ir_unop_pack_snorm_2x16:
    case ir_unop_pack_snorm_4x8:
    case ir_unop_pack_unorm_2x16:
@@ -317,6 +351,14 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
       this->type = glsl_type::double_type;
       break;
 
+   case ir_unop_pack_int_2x32:
+      this->type = glsl_type::int64_t_type;
+      break;
+
+   case ir_unop_pack_uint_2x32:
+      this->type = glsl_type::uint64_t_type;
+      break;
+
    case ir_unop_unpack_snorm_2x16:
    case ir_unop_unpack_unorm_2x16:
    case ir_unop_unpack_half_2x16:
@@ -347,6 +389,21 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
       this->type = glsl_type::bool_type;
       break;
 
+   case ir_unop_bitcast_i642d:
+   case ir_unop_bitcast_u642d:
+      this->type = glsl_type::get_instance(GLSL_TYPE_DOUBLE,
+                                           op0->type->vector_elements, 1);
+      break;
+
+   case ir_unop_bitcast_d2i64:
+      this->type = glsl_type::get_instance(GLSL_TYPE_INT64,
+                                           op0->type->vector_elements, 1);
+      break;
+   case ir_unop_bitcast_d2u64:
+      this->type = glsl_type::get_instance(GLSL_TYPE_UINT64,
+                                           op0->type->vector_elements, 1);
+      break;
+
    default:
       assert(!"not reached: missing automatic type setup for ir_expression");
       this->type = op0->type;
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py
index 58a585b..5e7aba6 100644
--- a/src/compiler/glsl/ir_expression_operation.py
+++ b/src/compiler/glsl/ir_expression_operation.py
@@ -80,6 +80,8 @@ class type_signature_iter(object):
 
 uint_type = type("unsigned", "u", "GLSL_TYPE_UINT")
 int_type = type("int", "i", "GLSL_TYPE_INT")
+uint64_type = type("uint64_t", "u64", "GLSL_TYPE_UINT64")
+int64_type = type("int64_t", "i64", "GLSL_TYPE_INT64")
 float_type = type("float", "f", "GLSL_TYPE_FLOAT")
 double_type = type("double", "d", "GLSL_TYPE_DOUBLE")
 bool_type = type("bool", "b", "GLSL_TYPE_BOOL")
@@ -470,6 +472,39 @@ ir_expression_operation = [
    operation("bitcast_u2f", 1, source_types=(uint_type,), dest_type=float_type, c_expression="bitcast_u2f({src0})"),
    # 'Bit-identical float-to-uint "conversion"
    operation("bitcast_f2u", 1, source_types=(float_type,), dest_type=uint_type, c_expression="bitcast_f2u({src0})"),
+   # Bit-identical u64-to-double "conversion"
+   operation("bitcast_u642d", 1, source_types=(uint64_type,), dest_type=double_type),
+   # Bit-identical i64-to-double "conversion"
+   operation("bitcast_i642d", 1, source_types=(int64_type,), dest_type=double_type),
+   # Bit-identical double-to_u64 "conversion"
+   operation("bitcast_d2u64", 1, source_types=(double_type,), dest_type=uint64_type),
+   # Bit-identical double-to-i64 "conversion"
+   operation("bitcast_d2i64", 1, source_types=(double_type,), dest_type=int64_type),
+   # i64-to-i32 conversion
+   operation("i642i", 1, source_types=(int64_type,), dest_type=int_type),
+   # ui64-to-i32 conversion
+   operation("u642i", 1, source_types=(uint64_type,), dest_type=int_type),
+   operation("i642u", 1, source_types=(int64_type,), dest_type=uint_type),
+   operation("u642u", 1, source_types=(uint64_type,), dest_type=uint_type),
+   operation("i642b", 1, source_types=(int64_type,), dest_type=bool_type),
+   operation("u642b", 1, source_types=(uint64_type,), dest_type=bool_type),
+   operation("i642f", 1, source_types=(int64_type,), dest_type=float_type),
+   operation("u642f", 1, source_types=(uint64_type,), dest_type=float_type),
+   operation("i642d", 1, source_types=(int64_type,), dest_type=double_type),
+   operation("u642d", 1, source_types=(uint64_type,), dest_type=double_type),
+   operation("i2i64", 1, source_types=(int_type,), dest_type=int64_type),
+   operation("u2i64", 1, source_types=(uint_type,), dest_type=int64_type),
+   operation("b2i64", 1, source_types=(bool_type,), dest_type=int64_type),
+   operation("f2i64", 1, source_types=(float_type,), dest_type=int64_type),
+   operation("d2i64", 1, source_types=(double_type,), dest_type=int64_type),
+   operation("i2u64", 1, source_types=(int_type,), dest_type=uint64_type),
+   operation("u2u64", 1, source_types=(uint_type,), dest_type=uint64_type),
+   operation("b2u64", 1, source_types=(bool_type,), dest_type=uint64_type),
+   operation("f2u64", 1, source_types=(float_type,), dest_type=uint64_type),
+   operation("d2u64", 1, source_types=(double_type,), dest_type=uint64_type),
+   operation("u642i64", 1, source_types=(uint_type,), dest_type=int64_type),
+   operation("i642u64", 1, source_types=(int_type,), dest_type=uint64_type),
+
 
    # Unary floating-point rounding operations.
    operation("trunc", 1, source_types=real_types, c_expression={'f': "truncf({src0})", 'd': "trunc({src0})"}),
@@ -543,6 +578,12 @@ ir_expression_operation = [
    operation("vote_all", 1),
    operation("vote_eq", 1),
 
+   # 64-bit integer packing ops.
+   operation("pack_int_2x32", 1, printable_name="packInt2x32", source_types=(int_type,), dest_type=int64_type, flags=frozenset((horizontal_operation, non_assign_operation))),
+   operation("pack_uint_2x32", 1, printable_name="packUint2x32", source_types=(uint_type,), dest_type=uint64_type, flags=frozenset((horizontal_operation, non_assign_operation))),
+   operation("unpack_int_2x32", 1, printable_name="unpackInt2x32", source_types=(int64_type,), dest_type=int_type, flags=frozenset((horizontal_operation, non_assign_operation))),
+   operation("unpack_uint_2x32", 1, printable_name="unpackUint2x32", source_types=(uint64_type,), dest_type=uint_type, flags=frozenset((horizontal_operation, non_assign_operation))),
+
    operation("add", 2, printable_name="+", source_types=numeric_types, c_expression="{src0} + {src1}", flags=vector_scalar_operation),
    operation("sub", 2, printable_name="-", source_types=numeric_types, c_expression="{src0} - {src1}", flags=vector_scalar_operation),
    # "Floating-point or low 32-bit integer multiply."
diff --git a/src/compiler/glsl/ir_validate.cpp b/src/compiler/glsl/ir_validate.cpp
index 7e294f9..8b340d1 100644
--- a/src/compiler/glsl/ir_validate.cpp
+++ b/src/compiler/glsl/ir_validate.cpp
@@ -331,6 +331,110 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->type->base_type == GLSL_TYPE_UINT);
       break;
 
+   case ir_unop_bitcast_u642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      break;
+   case ir_unop_bitcast_i642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      break;
+   case ir_unop_bitcast_d2u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_bitcast_d2i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_i642i:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_INT);
+      break;
+   case ir_unop_u642i:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_INT);
+      break;
+   case ir_unop_i642u:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_UINT);
+      break;
+   case ir_unop_u642u:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_UINT);
+      break;
+   case ir_unop_i642b:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_BOOL);
+      break;
+   case ir_unop_u642b:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_BOOL);
+      break;
+   case ir_unop_i642f:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+      break;
+   case ir_unop_u642f:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+      break;
+   case ir_unop_i642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      break;
+   case ir_unop_u642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      break;
+   case ir_unop_i2i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_u2i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_b2i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_f2i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_d2i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_i2u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_u2u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_b2u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_f2u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_d2u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_u642i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_i642u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
    case ir_unop_trunc:
    case ir_unop_round_even:
    case ir_unop_ceil:
@@ -370,6 +474,16 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type == glsl_type::uvec2_type);
       break;
 
+   case ir_unop_pack_int_2x32:
+      assert(ir->type == glsl_type::int64_t_type);
+      assert(ir->operands[0]->type == glsl_type::ivec2_type);
+      break;
+
+   case ir_unop_pack_uint_2x32:
+      assert(ir->type == glsl_type::uint64_t_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:
@@ -388,6 +502,16 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type == glsl_type::double_type);
       break;
 
+   case ir_unop_unpack_int_2x32:
+      assert(ir->type == glsl_type::ivec2_type);
+      assert(ir->operands[0]->type == glsl_type::int64_t_type);
+      break;
+
+   case ir_unop_unpack_uint_2x32:
+      assert(ir->type == glsl_type::uvec2_type);
+      assert(ir->operands[0]->type == glsl_type::uint64_t_type);
+      break;
+
    case ir_unop_bitfield_reverse:
       assert(ir->operands[0]->type == ir->type);
       assert(ir->type->is_integer());
-- 
2.5.5



More information about the mesa-dev mailing list