glsl: Add b2f16 and f162b conversion operations
authorNeil Roberts <nroberts@igalia.com>
Thu, 16 May 2019 11:25:28 +0000 (13:25 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 9 Mar 2020 16:31:08 +0000 (16:31 +0000)
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 0ebba46db80660226006dcf83a2ae75b5f973176..6d82fcae6d24ede4d293b361c177d98d35f90f99 100644 (file)
@@ -2039,6 +2039,8 @@ nir_visitor::visit(ir_expression *ir)
    case ir_unop_f2d:
    case ir_unop_f162f:
    case ir_unop_f2f16:
+   case ir_unop_f162b:
+   case ir_unop_b2f16:
    case ir_unop_d2i:
    case ir_unop_d2u:
    case ir_unop_d2b:
index dc832a2b632c6075a326138f09ba74e3281f72db..4df511fbf8d31d76e060a2a49adc1fb0665b77ed 100644 (file)
@@ -293,6 +293,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
       break;
 
    case ir_unop_f2f16:
+   case ir_unop_b2f16:
       this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT16,
                                           op0->type->vector_elements, 1);
       break;
@@ -300,6 +301,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
    case ir_unop_f2b:
    case ir_unop_i2b:
    case ir_unop_d2b:
+   case ir_unop_f162b:
    case ir_unop_i642b:
       this->type = glsl_type::get_instance(GLSL_TYPE_BOOL,
                                           op0->type->vector_elements, 1);
index df6a21f22022a4e0a100d71dc8d4465c6c6e5f43..48fbc873e9300309e68e09086b795442b95157dd 100644 (file)
@@ -438,6 +438,8 @@ ir_expression_operation = [
    operation("f2b", 1, source_types=(float_type,), dest_type=bool_type, c_expression="{src0} != 0.0F ? true : false"),
    # Boolean-to-float conversion
    operation("b2f", 1, source_types=(bool_type,), dest_type=float_type, c_expression="{src0} ? 1.0F : 0.0F"),
+   # Boolean-to-float16 conversion
+   operation("b2f16", 1, source_types=(bool_type,), dest_type=float_type, c_expression="{src0} ? 1.0F : 0.0F"),
    # int-to-boolean conversion
    operation("i2b", 1, source_types=(uint_type, int_type), dest_type=bool_type, c_expression="{src0} ? true : false"),
    # Boolean-to-int conversion
@@ -468,6 +470,8 @@ ir_expression_operation = [
    operation("u2d", 1, source_types=(uint_type,), dest_type=double_type, c_expression="{src0}"),
    # Double-to-boolean conversion.
    operation("d2b", 1, source_types=(double_type,), dest_type=bool_type, c_expression="{src0} != 0.0"),
+   # Float16-to-boolean conversion.
+   operation("f162b", 1, source_types=(float_type,), dest_type=bool_type, c_expression="{src0} != 0.0"),
    # 'Bit-identical int-to-float "conversion"
    operation("bitcast_i2f", 1, source_types=(int_type,), dest_type=float_type, c_expression="bitcast_u2f({src0})"),
    # 'Bit-identical float-to-int "conversion"
index f13bc6cd33d84a79dbe759c5dae367694476fb27..02a5f3dec56970f076650aa4956ce46e2765a01d 100644 (file)
@@ -299,10 +299,19 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type->is_float());
       assert(ir->type->is_boolean());
       break;
+   case ir_unop_f162b:
+      assert(ir->operands[0]->type->base_type ==
+             GLSL_TYPE_FLOAT16);
+      assert(ir->type->is_boolean());
+      break;
    case ir_unop_b2f:
       assert(ir->operands[0]->type->is_boolean());
       assert(ir->type->is_float());
       break;
+   case ir_unop_b2f16:
+      assert(ir->operands[0]->type->is_boolean());
+      assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
+      break;
    case ir_unop_i2b:
       assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
       assert(ir->type->is_boolean());
index 2f7b52c9d98473003b49640e4ef8eb960b2ce9a3..ee7741b8755ec6e7aaafcd9d75057a36e9c1e2fc 100644 (file)
@@ -1349,6 +1349,8 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
    case ir_unop_clz:
    case ir_unop_f162f:
    case ir_unop_f2f16:
+   case ir_unop_f162b:
+   case ir_unop_b2f16:
       assert(!"not supported");
       break;
 
index 4871eb97545b7e2c349aaf32bb99c2056aa1b6b5..e53bed93f6b57614b419e1adbf8098cd60143b59 100644 (file)
@@ -2397,6 +2397,8 @@ 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_f162b:
+   case ir_unop_b2f16:
       /* This operation is not supported, or should have already been handled.
        */
       assert(!"Invalid ir opcode in glsl_to_tgsi_visitor::visit()");