[Mesa-dev] [PATCH 48/51] glsl: HACK: Treat input varyings as 16-bits by conversion

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


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

diff --git a/src/compiler/glsl/lower_mediump.cpp b/src/compiler/glsl/lower_mediump.cpp
index 094ab4e743..45cf75b53c 100644
--- a/src/compiler/glsl/lower_mediump.cpp
+++ b/src/compiler/glsl/lower_mediump.cpp
@@ -92,6 +92,20 @@ refers_16_bit_float(const ir_rvalue *ir)
 }
 
 static bool
+defers_input_varying(const ir_rvalue *ir)
+{
+   ir_variable *var = ir->variable_referenced();
+   if (!var)
+      return false;
+
+   if (var->data.mode != ir_var_shader_in)
+      return false;
+
+   return var->data.precision == ast_precision_low ||
+          var->data.precision == ast_precision_medium;
+}
+
+static bool
 is_constant(const ir_rvalue *ir)
 {
    if (ir->ir_type == ir_type_constant)
@@ -152,6 +166,13 @@ lower_mediump_visitor::can_be_lowered(const ir_variable *var) const
    if (!var->type->get_scalar_type()->is_float())
       return false;
 
+   /* TODO: Intel compiler backend isn't prepared for interpolated 16-bit
+    *       varyings. Input varyings are instead converted to 16-bits before
+    *       use.
+    */
+   if (var->data.mode == ir_var_shader_in)
+      return false;
+
    return var->data.precision == ast_precision_low ||
           var->data.precision == ast_precision_medium;
 }
@@ -309,7 +330,8 @@ 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 if (!is_constant(ir->operands[i]))
+      else if (!is_constant(ir->operands[i]) &&
+               !defers_input_varying(ir->operands[i]))
          has_32_bit_src = true;
    }
 
@@ -324,6 +346,8 @@ lower_mediump_visitor::visit_leave(ir_expression *ir)
       for (unsigned i = 0; i < ir->num_operands; i++) {
          if (is_constant(ir->operands[i]))
             retype_to_float16(ir->operands[i]);
+         else if (defers_input_varying(ir->operands[i]))
+            ir->operands[i] = convert(ir->operands[i], ir_unop_f2h);
       }
 
       retype_to_float16(&ir->type);
-- 
2.11.0



More information about the mesa-dev mailing list