[Mesa-dev] [PATCH 08/51] glsl: Add more conversion ops to/from 16-bit floats
Topi Pohjolainen
topi.pohjolainen at gmail.com
Fri Nov 24 12:26:35 UTC 2017
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
src/compiler/glsl/glsl_to_nir.cpp | 6 ++++++
src/compiler/glsl/ir_expression_operation.py | 16 ++++++++++++++--
src/compiler/glsl/ir_validate.cpp | 24 ++++++++++++++++++++++++
src/mesa/program/ir_to_mesa.cpp | 6 ++++++
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 6 ++++++
5 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index 14c358465b..c0adf744e0 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -1563,6 +1563,12 @@ nir_visitor::visit(ir_expression *ir)
case ir_unop_u2d:
case ir_unop_h2f:
case ir_unop_f2h:
+ case ir_unop_h2u:
+ case ir_unop_u2h:
+ case ir_unop_h2i:
+ case ir_unop_i2h:
+ case ir_unop_h2b:
+ case ir_unop_b2h:
case ir_unop_i642i:
case ir_unop_i642u:
case ir_unop_i642f:
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py
index 3158533c02..0316d1a82d 100644
--- a/src/compiler/glsl/ir_expression_operation.py
+++ b/src/compiler/glsl/ir_expression_operation.py
@@ -461,10 +461,22 @@ 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"),
- # hafl-to-float conversion.
+ # half-to-float conversion.
operation("h2f", 1, source_types=(float16_t_type,), dest_type=float_type, c_expression="{src0}"),
- # hafl-to-float conversion.
+ # float-to-half conversion.
operation("f2h", 1, source_types=(float_type,), dest_type=float16_t_type, c_expression="{src0}"),
+ # half-to-unsigned conversion.
+ operation("h2u", 1, source_types=(float16_t_type,), dest_type=uint_type, c_expression="{src0}"),
+ # unsigned-to-half conversion.
+ operation("u2h", 1, source_types=(uint_type,), dest_type=float16_t_type, c_expression="{src0}"),
+ # half-to-integer conversion.
+ operation("h2i", 1, source_types=(float16_t_type,), dest_type=int_type, c_expression="{src0}"),
+ # integer-to-half conversion.
+ operation("i2h", 1, source_types=(int_type,), dest_type=float16_t_type, c_expression="{src0}"),
+ # half-to-boolean conversion.
+ operation("h2b", 1, source_types=(float16_t_type,), dest_type=bool_type, c_expression="{src0} != 0.0"),
+ # boolean-to-half conversion.
+ operation("b2h", 1, source_types=(bool_type,), dest_type=float16_t_type, c_expression="{src0} ? 1.0F : 0.0F"),
# '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 29e3cda865..a20f52e527 100644
--- a/src/compiler/glsl/ir_validate.cpp
+++ b/src/compiler/glsl/ir_validate.cpp
@@ -603,6 +603,30 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
break;
+ case ir_unop_h2u:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
+ assert(ir->type->base_type == GLSL_TYPE_UINT);
+ break;
+ case ir_unop_u2h:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
+ break;
+ case ir_unop_h2i:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
+ assert(ir->type->base_type == GLSL_TYPE_INT);
+ break;
+ case ir_unop_i2h:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
+ break;
+ case ir_unop_h2b:
+ assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
+ assert(ir->type->is_boolean());
+ break;
+ case ir_unop_b2h:
+ assert(ir->operands[0]->type->is_boolean());
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
+ break;
case ir_unop_frexp_sig:
assert(ir->operands[0]->type->is_float() ||
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index d57e50366e..286b9e07bf 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -1315,6 +1315,12 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
case ir_unop_d2b:
case ir_unop_h2f:
case ir_unop_f2h:
+ case ir_unop_h2u:
+ case ir_unop_u2h:
+ case ir_unop_h2i:
+ case ir_unop_i2h:
+ case ir_unop_h2b:
+ case ir_unop_b2h:
case ir_unop_frexp_sig:
case ir_unop_frexp_exp:
assert(!"not supported");
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index f8cb94c7dc..3ccccbe7bd 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1799,6 +1799,12 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
break;
case ir_unop_h2f:
case ir_unop_f2h:
+ case ir_unop_h2u:
+ case ir_unop_u2h:
+ case ir_unop_h2i:
+ case ir_unop_i2h:
+ case ir_unop_h2b:
+ case ir_unop_b2h:
unreachable("not implemented yet");
case ir_unop_bitcast_u642d:
case ir_unop_bitcast_i642d:
--
2.11.0
More information about the mesa-dev
mailing list