glsl: Add ir_unop_f2fmp
authorNeil Roberts <nroberts@igalia.com>
Wed, 9 Oct 2019 11:07:40 +0000 (13:07 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 9 Mar 2020 16:31:08 +0000 (16:31 +0000)
This is the same as ir_unop_f2f16 except that it comes with a promise
that it is safe to optimise it out if the result is immediately
converted back to float32 again. Normally this would be a lossy
operation but it is safe to do if the conversion was generated as part
of the precision lowering pass.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.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 6d82fcae6d24ede4d293b361c177d98d35f90f99..d8fbc804ff032a82a55aac5ef7f3028b3adcd47e 100644 (file)
@@ -2079,6 +2079,11 @@ nir_visitor::visit(ir_expression *ir)
       break;
    }
 
+   case ir_unop_f2fmp: {
+      result = nir_build_alu(&b, nir_op_f2fmp, srcs[0], NULL, NULL, NULL);
+      break;
+   }
+
    case ir_unop_bitcast_i2f:
    case ir_unop_bitcast_f2i:
    case ir_unop_bitcast_u2f:
index 4df511fbf8d31d76e060a2a49adc1fb0665b77ed..4d4bc0fb957e32c88ffa8fb46549c57964fe2471 100644 (file)
@@ -293,6 +293,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
       break;
 
    case ir_unop_f2f16:
+   case ir_unop_f2fmp:
    case ir_unop_b2f16:
       this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT16,
                                           op0->type->vector_elements, 1);
index 48fbc873e9300309e68e09086b795442b95157dd..5fcc9ee9ab4da5f5af4ccac9d65d5c5b8b98b60f 100644 (file)
@@ -459,6 +459,7 @@ ir_expression_operation = [
    # 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("f2fmp", 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}"),
index 02a5f3dec56970f076650aa4956ce46e2765a01d..4c4948c30ca6c1952f0ae0339b78d80a9e6649a3 100644 (file)
@@ -593,6 +593,7 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->type->is_float());
       break;
    case ir_unop_f2f16:
+   case ir_unop_f2fmp:
       assert(ir->operands[0]->type->is_float());
       assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
       break;
index ee7741b8755ec6e7aaafcd9d75057a36e9c1e2fc..adb8720c622911a2d120f1d5cd57c8a09cf0f3d5 100644 (file)
@@ -1349,6 +1349,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
    case ir_unop_clz:
    case ir_unop_f162f:
    case ir_unop_f2f16:
+   case ir_unop_f2fmp:
    case ir_unop_f162b:
    case ir_unop_b2f16:
       assert(!"not supported");
index e53bed93f6b57614b419e1adbf8098cd60143b59..31ffa24958cbcb75a6fcab0849e16387e028e870 100644 (file)
@@ -2397,6 +2397,7 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
    case ir_binop_mul_32x16:
    case ir_unop_f162f:
    case ir_unop_f2f16:
+   case ir_unop_f2fmp:
    case ir_unop_f162b:
    case ir_unop_b2f16:
       /* This operation is not supported, or should have already been handled.