summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie Tournier <elie.tournier@collabora.com>2017-09-15 14:46:22 +0000
committerDave Airlie <airlied@redhat.com>2018-01-18 14:16:27 +1000
commitfef169dbd9271515c991611e8c3b68869b05f051 (patch)
tree07aec1ce923b029f24cba1df54bb90bdddfeac9a
parent25dff2b383d00725573df28d09ee1368616c37c0 (diff)
glsl: Add a lowering pass for 64-bit float rsq()
-rw-r--r--src/compiler/glsl/ir_optimization.h1
-rw-r--r--src/compiler/glsl/lower_instructions.cpp25
-rw-r--r--src/mesa/state_tracker/st_glsl_to_tgsi.cpp2
3 files changed, 27 insertions, 1 deletions
diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index fd1295f18b0..d72d88639cf 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -56,6 +56,7 @@
#define SQRT_TO_ABS_SQRT 0x200000
#define MIN_MAX_TO_LESS 0x400000
#define DOPS_TO_DTRUNC 0x800000
+#define DRSQ_TO_DRCP 0x1000000
/* Operations for lower_64bit_integer_instructions()
* and lower_64bit_double_instructions()
diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp
index 2dfaf05c3b9..5977675c688 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -45,6 +45,7 @@
* - DOPS_TO_DFRAC
* - MIN_MAX_TO_LESS
* - DOPS_TO_DTRUNC
+ * - DRSQ_TO_DRCP
*
* SUB_TO_ADD_NEG:
* ---------------
@@ -182,6 +183,7 @@ private:
void dfloor_to_dtrunc(ir_expression *ir);
void dceil_to_dtrunc(ir_expression *ir);
void dfrac_to_dtrunc(ir_expression *ir);
+ void drsq_to_drcp(ir_expression *ir);
ir_expression *_carry(operand a, operand b);
};
@@ -1768,6 +1770,22 @@ lower_instructions_visitor::dfrac_to_dtrunc(ir_expression *ir)
this->progress = true;
}
+void
+lower_instructions_visitor::drsq_to_drcp(ir_expression *ir)
+{
+ ir_expression *const sqrt_expr =
+ new(ir) ir_expression(ir_unop_sqrt,
+ ir->operands[0]->type, ir->operands[0]);
+ if (lowering(SQRT_TO_ABS_SQRT))
+ sqrt_to_abs_sqrt(sqrt_expr);
+
+ ir->operation = ir_unop_rcp;
+ ir->init_num_operands();
+ ir->operands[0] = sqrt_expr;
+
+ this->progress = true;
+}
+
ir_visitor_status
lower_instructions_visitor::visit_leave(ir_expression *ir)
{
@@ -1916,6 +1934,13 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
break;
case ir_unop_rsq:
+ if (lowering(DRSQ_TO_DRCP) &&
+ ir->type->is_double() && ir->type->is_scalar())
+ drsq_to_drcp(ir);
+ else if (lowering(SQRT_TO_ABS_SQRT))
+ sqrt_to_abs_sqrt(ir);
+ break;
+
case ir_unop_sqrt:
if (lowering(SQRT_TO_ABS_SQRT))
sqrt_to_abs_sqrt(ir);
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index ee097a2369c..96d708b73c0 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -7066,7 +7066,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
*/
if (!pscreen->get_param(pscreen, PIPE_CAP_DOUBLES) &&
ctx->Const.GLSLVersion >= 130) {
- lower_instructions(ir, MIN_MAX_TO_LESS | DOPS_TO_DTRUNC);
+ lower_instructions(ir, MIN_MAX_TO_LESS | DOPS_TO_DTRUNC | DRSQ_TO_DRCP);
unsigned lower_inst = ABS64 |
NEG64 |
SIGN64 |