[Mesa-dev] [PATCH 45/51] glsl: Use 16-bit constants if operation is otherwise 16-bit

Topi Pohjolainen topi.pohjolainen at gmail.com
Fri Nov 24 12:27:12 UTC 2017


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 src/compiler/glsl/lower_mediump.cpp | 43 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/lower_mediump.cpp b/src/compiler/glsl/lower_mediump.cpp
index 89eed8b294..0276e74d6e 100644
--- a/src/compiler/glsl/lower_mediump.cpp
+++ b/src/compiler/glsl/lower_mediump.cpp
@@ -67,6 +67,25 @@ refers_16_bit_float(const ir_rvalue *ir)
    return var->type->get_scalar_type()->base_type == GLSL_TYPE_FLOAT16;
 }
 
+static bool
+is_constant(const ir_rvalue *ir)
+{
+   if (ir->ir_type == ir_type_constant)
+      return true;
+
+   if (ir->ir_type != ir_type_expression)
+      return false;
+
+   const ir_expression *expr = (const ir_expression *)ir;
+
+   for (unsigned i = 0; i < expr->num_operands; i++) {
+      if (!is_constant(expr->operands[i]))
+         return false;
+   }
+
+   return true;
+}
+
 static ir_rvalue *
 convert(ir_rvalue *ir, enum ir_expression_operation op)
 {
@@ -99,6 +118,7 @@ private:
    bool can_be_lowered(const ir_variable *var) const;
 
    void retype_to_float16(const glsl_type **t);
+   void retype_to_float16(ir_rvalue *ir);
 };
 
 bool
@@ -119,6 +139,22 @@ lower_mediump_visitor::retype_to_float16(const glsl_type **t)
    *t = mediump;
 }
 
+void
+lower_mediump_visitor::retype_to_float16(ir_rvalue *ir)
+{
+   retype_to_float16(&ir->type);
+
+   if (ir->ir_type != ir_type_expression)
+      return;
+
+   const ir_expression *expr = (const ir_expression *)ir;
+
+   for (unsigned i = 0; i < expr->num_operands; i++) {
+      assert(is_constant(expr->operands[i]));
+      retype_to_float16(&expr->operands[i]->type);
+   }
+}
+
 ir_visitor_status
 lower_mediump_visitor::visit(ir_variable *ir)
 {
@@ -228,7 +264,7 @@ lower_mediump_visitor::visit_leave(ir_expression *ir)
    for (unsigned i = 0; i < ir->num_operands; i++) {
       if (is_16_bit(ir->operands[i]))
          has_16_bit_src = true;
-      else
+      else if (!is_constant(ir->operands[i]))
          has_32_bit_src = true;
    }
 
@@ -240,6 +276,11 @@ lower_mediump_visitor::visit_leave(ir_expression *ir)
     */
    if (!has_32_bit_src &&
        ir->operation != ir_triop_lrp) {
+      for (unsigned i = 0; i < ir->num_operands; i++) {
+         if (is_constant(ir->operands[i]))
+            retype_to_float16(ir->operands[i]);
+      }
+
       retype_to_float16(&ir->type);
       return visit_continue;
    }
-- 
2.11.0



More information about the mesa-dev mailing list