glsl: Add b2f16 and f162b conversion operations

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>
This commit is contained in:
Neil Roberts 2019-05-16 13:25:28 +02:00 committed by Marge Bot
parent 6b9f6caf06
commit 5d6b007da8
6 changed files with 21 additions and 0 deletions

View 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:

View 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);

View 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"

View 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());

View 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;

View 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()");