[Mesa-dev] [PATCH 28/47] glsl: Add a lowering pass for 64-bit float u2d()

Elie Tournier tournier.elie at gmail.com
Wed Aug 23 11:07:58 UTC 2017


Handle non 64bit sources (airlied)

Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
 src/compiler/glsl/ir_optimization.h        |  1 +
 src/compiler/glsl/lower_64bit.cpp          | 49 ++++++++++++++++++++++++------
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  3 +-
 3 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index aa71dfdb39..5d1118d0cf 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -69,6 +69,7 @@
 #define LT64                      (1U << 8)
 #define ADD64                     (1U << 9)
 #define D2U                       (1U << 10)
+#define U2D                       (1U << 11)
 
 /**
  * \see class lower_packing_builtins_visitor
diff --git a/src/compiler/glsl/lower_64bit.cpp b/src/compiler/glsl/lower_64bit.cpp
index 0b9d466b9d..38b0420baa 100644
--- a/src/compiler/glsl/lower_64bit.cpp
+++ b/src/compiler/glsl/lower_64bit.cpp
@@ -52,7 +52,7 @@ using namespace ir_builder;
 
 namespace lower_64bit {
 void expand_source(ir_factory &, ir_rvalue *val, ir_variable **expanded_src);
-
+void extract_source(ir_factory &, ir_rvalue *val, ir_variable **extracted_src);
 ir_dereference_variable *compact_destination(ir_factory &,
                                              const glsl_type *type,
                                              ir_variable *result[4]);
@@ -124,7 +124,7 @@ private:
    ir_factory added_functions;
 
    ir_rvalue *handle_op(ir_expression *ir, const char *function_name,
-                        function_generator generator);
+                        function_generator generator, bool conv_to_double = false);
 };
 
 } /* anonymous namespace */
@@ -245,6 +245,25 @@ lower_64bit::expand_source(ir_factory &body,
       expanded_src[i] = expanded_src[0];
 }
 
+void
+lower_64bit::extract_source(ir_factory &body,
+                            ir_rvalue *val,
+                            ir_variable **extracted_src)
+{
+   ir_variable *const temp = body.make_temp(val->type, "tmp");
+
+   body.emit(assign(temp, val));
+   unsigned i;
+   for (i = 0; i < val->type->vector_elements; i++) {
+      extracted_src[i] = body.make_temp(val->type->get_scalar_type(), "extracted_source");
+
+      body.emit(assign(extracted_src[i], swizzle(temp, i, 1)));
+   }
+
+   for (/* empty */; i < 4; i++)
+      extracted_src[i] = extracted_src[0];
+}
+
 /**
  * Convert a series of uvec2 results into a single 64-bit integer vector
  */
@@ -315,7 +334,10 @@ lower_64bit::lower_op_to_function_call(ir_instruction *base_ir,
    ir_factory body(&instructions, mem_ctx);
 
    for (unsigned i = 0; i < num_operands; i++) {
-      expand_source(body, ir->operands[i], src[i]);
+      if (ir->operands[i]->type->is_64bit())
+         expand_source(body, ir->operands[i], src[i]);
+      else
+         extract_source(body, ir->operands[i], src[i]);
 
       if (ir->operands[i]->type->vector_elements > source_components)
          source_components = ir->operands[i]->type->vector_elements;
@@ -365,13 +387,15 @@ lower_64bit::lower_op_to_function_call(ir_instruction *base_ir,
 ir_rvalue *
 lower_64bit_visitor::handle_op(ir_expression *ir,
                                const char *function_name,
-                               function_generator generator)
+                               function_generator generator,
+                               bool conv_to_double)
 {
-   for (unsigned i = 0; i < ir->get_num_operands(); i++)
-      if (!ir->operands[i]->type->is_integer_64() &&
-          !ir->operands[i]->type->is_double())
-         return ir;
-
+   if (conv_to_double == false) {
+      for (unsigned i = 0; i < ir->num_operands; i++)
+         if (!ir->operands[i]->type->is_integer_64() &&
+             !ir->operands[i]->type->is_double())
+            return ir;
+   }
    /* Get a handle to the correct ir_function_signature for the core
     * operation.
     */
@@ -435,6 +459,13 @@ lower_64bit_visitor::handle_rvalue(ir_rvalue **rvalue)
       }
       break;
 
+   case ir_unop_u2d:
+      if (lowering(U2D)) {
+         if (ir->type->base_type == GLSL_TYPE_DOUBLE)
+            *rvalue = handle_op(ir, "__builtin_uint_to_fp64", generate_ir::uint_to_fp64, true);
+      }
+      break;
+
    case ir_binop_add:
       if (lowering(ADD64)) {
          if (ir->type->base_type == GLSL_TYPE_DOUBLE)
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index de5a499f8d..df815a86d1 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -7066,7 +7066,8 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
                                LT64 |
                                ADD64 |
                                MUL64 |
-                               D2U;
+                               D2U |
+                               U2D;
          lower_64bit_double_instructions(ir, lower_inst);
       }
 
-- 
2.14.1



More information about the mesa-dev mailing list