glsl: Add IR conversion ops for 16-bit float types
authorNeil Roberts <nroberts@igalia.com>
Fri, 19 Apr 2019 13:36:00 +0000 (15:36 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 9 Mar 2020 16:31:08 +0000 (16:31 +0000)
Adds ir_unop_f162f and ir_unop_f2f16.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3929>

src/compiler/glsl/glsl_to_nir.cpp
src/compiler/glsl/ir.cpp
src/compiler/glsl/ir_expression_operation.py
src/compiler/glsl/ir_validate.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 8f15cd55fcb9f243608da631faa48a29ab313209..0ebba46db80660226006dcf83a2ae75b5f973176 100644 (file)
@@ -2037,6 +2037,8 @@ nir_visitor::visit(ir_expression *ir)
    case ir_unop_b2i64:
    case ir_unop_d2f:
    case ir_unop_f2d:
+   case ir_unop_f162f:
+   case ir_unop_f2f16:
    case ir_unop_d2i:
    case ir_unop_d2u:
    case ir_unop_d2b:
index d9bc83501cd49a2d5f8d765aba218d31e80f1c4d..dc832a2b632c6075a326138f09ba74e3281f72db 100644 (file)
@@ -283,6 +283,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_i2f:
    case ir_unop_u2f:
    case ir_unop_d2f:
+   case ir_unop_f162f:
    case ir_unop_bitcast_i2f:
    case ir_unop_bitcast_u2f:
    case ir_unop_i642f:
@@ -291,6 +292,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
                                           op0->type->vector_elements, 1);
       break;
 
+   case ir_unop_f2f16:
+      this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT16,
+                                          op0->type->vector_elements, 1);
+      break;
+
    case ir_unop_f2b:
    case ir_unop_i2b:
    case ir_unop_d2b:
index d5c43e6e53a1d964bf1e05d7f0b066996d95ed67..df6a21f22022a4e0a100d71dc8d4465c6c6e5f43 100644 (file)
@@ -452,6 +452,12 @@ ir_expression_operation = [
    operation("d2f", 1, source_types=(double_type,), dest_type=float_type, c_expression="{src0}"),
    # Float-to-double conversion.
    operation("f2d", 1, source_types=(float_type,), dest_type=double_type, c_expression="{src0}"),
+   # Half-float conversions. These all operate on and return float types,
+   # since the framework expands half to full float before calling in.  We
+   # still have to handle them here so that we can constant propagate through
+   # them, but they are no-ops.
+   operation("f2f16", 1, source_types=(float_type,), dest_type=float_type, c_expression="{src0}"),
+   operation("f162f", 1, source_types=(float_type,), dest_type=float_type, c_expression="{src0}"),
    # Double-to-integer conversion.
    operation("d2i", 1, source_types=(double_type,), dest_type=int_type, c_expression="{src0}"),
    # Integer-to-double conversion.
index 80b0ce9efe1abd40afaaf685f0c38640ac20f1c3..f13bc6cd33d84a79dbe759c5dae367694476fb27 100644 (file)
@@ -579,6 +579,14 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type->is_float());
       assert(ir->type->is_double());
       break;
+   case ir_unop_f162f:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
+      assert(ir->type->is_float());
+      break;
+   case ir_unop_f2f16:
+      assert(ir->operands[0]->type->is_float());
+      assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
+      break;
    case ir_unop_d2i:
       assert(ir->operands[0]->type->is_double());
       assert(ir->type->base_type == GLSL_TYPE_INT);
index 4cd9abb9ce30e5e9a847315ec153d23a50e698e7..2f7b52c9d98473003b49640e4ef8eb960b2ce9a3 100644 (file)
@@ -1347,6 +1347,8 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
    case ir_unop_atan:
    case ir_binop_atan2:
    case ir_unop_clz:
+   case ir_unop_f162f:
+   case ir_unop_f2f16:
       assert(!"not supported");
       break;
 
index 6c531ca53652e85c24dc57773621c250669ad2d8..4871eb97545b7e2c349aaf32bb99c2056aa1b6b5 100644 (file)
@@ -2395,6 +2395,8 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
    case ir_binop_avg:
    case ir_binop_avg_round:
    case ir_binop_mul_32x16:
+   case ir_unop_f162f:
+   case ir_unop_f2f16:
       /* This operation is not supported, or should have already been handled.
        */
       assert(!"Invalid ir opcode in glsl_to_tgsi_visitor::visit()");