summaryrefslogtreecommitdiff
path: root/src/glsl/lower_instructions.cpp
diff options
context:
space:
mode:
authorRoland Scheidegger <sroland@vmware.com>2010-12-02 04:32:06 +0100
committerRoland Scheidegger <sroland@vmware.com>2010-12-02 04:32:06 +0100
commita45bd509014743d21a532194d7b658a1aeb00cb7 (patch)
treed5fc155ee50d2f41fa9e7d4a253a8f9c51bc9e51 /src/glsl/lower_instructions.cpp
parent1aeca287a827f29206078fa1204715a477072c08 (diff)
parent32e1e591467d9a28c2ac4d2e17af7be2dc429d43 (diff)
Merge remote branch 'origin/master' into gallium-array-texturesgallium-array-textures
Conflicts: src/gallium/drivers/i915/i915_resource_texture.c src/gallium/drivers/i915/i915_state_emit.c src/gallium/drivers/i915/i915_surface.c
Diffstat (limited to 'src/glsl/lower_instructions.cpp')
-rw-r--r--src/glsl/lower_instructions.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/glsl/lower_instructions.cpp b/src/glsl/lower_instructions.cpp
index d460ba1a97..a5f61f213d 100644
--- a/src/glsl/lower_instructions.cpp
+++ b/src/glsl/lower_instructions.cpp
@@ -33,6 +33,7 @@
* - SUB_TO_ADD_NEG
* - DIV_TO_MUL_RCP
* - EXP_TO_EXP2
+ * - POW_TO_EXP2
* - LOG_TO_LOG2
* - MOD_TO_FRACT
*
@@ -61,6 +62,11 @@
* do have base 2 versions, so this pass converts exp and log to exp2
* and log2 operations.
*
+ * POW_TO_EXP2:
+ * -----------
+ * Many older GPUs don't have an x**y instruction. For these GPUs, convert
+ * x**y to 2**(y * log2(x)).
+ *
* MOD_TO_FRACT:
* -------------
* Breaks an ir_unop_mod expression down to (op1 * fract(op0 / op1))
@@ -70,7 +76,7 @@
* opportunity to do things like constant fold the (1.0 / op1) easily.
*/
-#include "main/core.h" /* for M_E */
+#include "main/core.h" /* for M_LOG2E */
#include "glsl_types.h"
#include "ir.h"
#include "ir_optimization.h"
@@ -91,6 +97,7 @@ private:
void div_to_mul_rcp(ir_expression *);
void mod_to_fract(ir_expression *);
void exp_to_exp2(ir_expression *);
+ void pow_to_exp2(ir_expression *);
void log_to_log2(ir_expression *);
};
@@ -172,7 +179,7 @@ lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
void
lower_instructions_visitor::exp_to_exp2(ir_expression *ir)
{
- ir_constant *log2_e = new(ir) ir_constant(log2f(M_E));
+ ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E));
ir->operation = ir_unop_exp2;
ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type,
@@ -181,12 +188,26 @@ lower_instructions_visitor::exp_to_exp2(ir_expression *ir)
}
void
+lower_instructions_visitor::pow_to_exp2(ir_expression *ir)
+{
+ ir_expression *const log2_x =
+ new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
+ ir->operands[0]);
+
+ ir->operation = ir_unop_exp2;
+ ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[1]->type,
+ ir->operands[1], log2_x);
+ ir->operands[1] = NULL;
+ this->progress = true;
+}
+
+void
lower_instructions_visitor::log_to_log2(ir_expression *ir)
{
ir->operation = ir_binop_mul;
ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
ir->operands[0], NULL);
- ir->operands[1] = new(ir) ir_constant(1.0f / log2f(M_E));
+ ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E));
this->progress = true;
}
@@ -254,6 +275,11 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
mod_to_fract(ir);
break;
+ case ir_binop_pow:
+ if (lowering(POW_TO_EXP2))
+ pow_to_exp2(ir);
+ break;
+
default:
return visit_continue;
}