From 5d6b007da8a36254e03e2ae9e83bd3330f528dc8 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 16 May 2019 13:25:28 +0200 Subject: [PATCH] glsl: Add b2f16 and f162b conversion operations MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 2 ++ src/compiler/glsl/ir.cpp | 2 ++ src/compiler/glsl/ir_expression_operation.py | 4 ++++ src/compiler/glsl/ir_validate.cpp | 9 +++++++++ src/mesa/program/ir_to_mesa.cpp | 2 ++ src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 ++ 6 files changed, 21 insertions(+) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 0ebba46db80..6d82fcae6d2 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -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: diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp index dc832a2b632..4df511fbf8d 100644 --- a/src/compiler/glsl/ir.cpp +++ b/src/compiler/glsl/ir.cpp @@ -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); diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index df6a21f2202..48fbc873e93 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -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" diff --git a/src/compiler/glsl/ir_validate.cpp b/src/compiler/glsl/ir_validate.cpp index f13bc6cd33d..02a5f3dec56 100644 --- a/src/compiler/glsl/ir_validate.cpp +++ b/src/compiler/glsl/ir_validate.cpp @@ -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()); diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 2f7b52c9d98..ee7741b8755 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -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; diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 4871eb97545..e53bed93f6b 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -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()"); -- 2.30.2