glsl2: Add a pass to convert exp and log to exp2 and log2.
Fixes ir_to_mesa handling of unop_log, which used the weird ARB_vp LOG opcode that doesn't do what we want. This also lets the multiplication coefficients in there get constant-folded, possibly. Fixes: glsl-fs-log
This commit is contained in:
@@ -41,6 +41,7 @@ CXX_SOURCES = \
|
|||||||
ir_dead_code_local.cpp \
|
ir_dead_code_local.cpp \
|
||||||
ir_dead_functions.cpp \
|
ir_dead_functions.cpp \
|
||||||
ir_div_to_mul_rcp.cpp \
|
ir_div_to_mul_rcp.cpp \
|
||||||
|
ir_explog_to_explog2.cpp \
|
||||||
ir_expression_flattening.cpp \
|
ir_expression_flattening.cpp \
|
||||||
ir_function_can_inline.cpp \
|
ir_function_can_inline.cpp \
|
||||||
ir_function.cpp \
|
ir_function.cpp \
|
||||||
|
@@ -593,8 +593,8 @@ enum ir_expression_operation {
|
|||||||
ir_unop_rcp,
|
ir_unop_rcp,
|
||||||
ir_unop_rsq,
|
ir_unop_rsq,
|
||||||
ir_unop_sqrt,
|
ir_unop_sqrt,
|
||||||
ir_unop_exp,
|
ir_unop_exp, /**< Log base e on gentype */
|
||||||
ir_unop_log,
|
ir_unop_log, /**< Natural log on gentype */
|
||||||
ir_unop_exp2,
|
ir_unop_exp2,
|
||||||
ir_unop_log2,
|
ir_unop_log2,
|
||||||
ir_unop_f2i, /**< Float-to-integer conversion. */
|
ir_unop_f2i, /**< Float-to-integer conversion. */
|
||||||
|
85
src/glsl/ir_explog_to_explog2.cpp
Normal file
85
src/glsl/ir_explog_to_explog2.cpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2010 Intel Corporation
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file ir_explog_to_explog2.cpp
|
||||||
|
*
|
||||||
|
* Many GPUs don't have a base e log or exponent instruction, but they
|
||||||
|
* do have base 2 versions, so this pass converts exp and log to exp2
|
||||||
|
* and log2 operations.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "ir.h"
|
||||||
|
#include "glsl_types.h"
|
||||||
|
|
||||||
|
class ir_explog_to_explog2_visitor : public ir_hierarchical_visitor {
|
||||||
|
public:
|
||||||
|
ir_explog_to_explog2_visitor()
|
||||||
|
{
|
||||||
|
this->progress = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ir_visitor_status visit_leave(ir_expression *);
|
||||||
|
|
||||||
|
bool progress;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
do_explog_to_explog2(exec_list *instructions)
|
||||||
|
{
|
||||||
|
ir_explog_to_explog2_visitor v;
|
||||||
|
|
||||||
|
visit_list_elements(&v, instructions);
|
||||||
|
return v.progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
ir_visitor_status
|
||||||
|
ir_explog_to_explog2_visitor::visit_leave(ir_expression *ir)
|
||||||
|
{
|
||||||
|
if (ir->operation == ir_unop_exp) {
|
||||||
|
void *mem_ctx = talloc_parent(ir);
|
||||||
|
ir_constant *log2_e = new(mem_ctx) ir_constant(log2f(M_E));
|
||||||
|
|
||||||
|
ir->operation = ir_unop_exp2;
|
||||||
|
ir->operands[0] = new(mem_ctx) ir_expression(ir_binop_mul,
|
||||||
|
ir->operands[0]->type,
|
||||||
|
ir->operands[0],
|
||||||
|
log2_e);
|
||||||
|
this->progress = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ir->operation == ir_unop_log) {
|
||||||
|
void *mem_ctx = talloc_parent(ir);
|
||||||
|
|
||||||
|
ir->operation = ir_binop_mul;
|
||||||
|
ir->operands[0] = new(mem_ctx) ir_expression(ir_unop_log2,
|
||||||
|
ir->operands[0]->type,
|
||||||
|
ir->operands[0],
|
||||||
|
NULL);
|
||||||
|
ir->operands[1] = new(mem_ctx) ir_constant(1.0f / log2f(M_E));
|
||||||
|
this->progress = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return visit_continue;
|
||||||
|
}
|
@@ -38,6 +38,7 @@ bool do_dead_code_local(exec_list *instructions);
|
|||||||
bool do_dead_code_unlinked(exec_list *instructions);
|
bool do_dead_code_unlinked(exec_list *instructions);
|
||||||
bool do_dead_functions(exec_list *instructions);
|
bool do_dead_functions(exec_list *instructions);
|
||||||
bool do_div_to_mul_rcp(exec_list *instructions);
|
bool do_div_to_mul_rcp(exec_list *instructions);
|
||||||
|
bool do_explog_to_explog2(exec_list *instructions);
|
||||||
bool do_function_inlining(exec_list *instructions);
|
bool do_function_inlining(exec_list *instructions);
|
||||||
bool do_if_return(exec_list *instructions);
|
bool do_if_return(exec_list *instructions);
|
||||||
bool do_if_simplification(exec_list *instructions);
|
bool do_if_simplification(exec_list *instructions);
|
||||||
|
@@ -183,10 +183,14 @@ ir_validate::visit_leave(ir_expression *ir)
|
|||||||
case ir_unop_rcp:
|
case ir_unop_rcp:
|
||||||
case ir_unop_rsq:
|
case ir_unop_rsq:
|
||||||
case ir_unop_sqrt:
|
case ir_unop_sqrt:
|
||||||
|
assert(ir->type == ir->operands[0]->type);
|
||||||
|
break;
|
||||||
|
|
||||||
case ir_unop_exp:
|
case ir_unop_exp:
|
||||||
case ir_unop_log:
|
case ir_unop_log:
|
||||||
case ir_unop_exp2:
|
case ir_unop_exp2:
|
||||||
case ir_unop_log2:
|
case ir_unop_log2:
|
||||||
|
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
|
||||||
assert(ir->type == ir->operands[0]->type);
|
assert(ir->type == ir->operands[0]->type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -1281,6 +1281,7 @@ link_shaders(struct gl_shader_program *prog)
|
|||||||
do_mat_op_to_vec(ir);
|
do_mat_op_to_vec(ir);
|
||||||
do_mod_to_fract(ir);
|
do_mod_to_fract(ir);
|
||||||
do_div_to_mul_rcp(ir);
|
do_div_to_mul_rcp(ir);
|
||||||
|
do_explog_to_explog2(ir);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
progress = false;
|
progress = false;
|
||||||
|
@@ -752,15 +752,12 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
|
|||||||
ir_to_mesa_emit_scalar_op1(ir, OPCODE_RCP, result_dst, op[0]);
|
ir_to_mesa_emit_scalar_op1(ir, OPCODE_RCP, result_dst, op[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ir_unop_exp:
|
|
||||||
ir_to_mesa_emit_scalar_op2(ir, OPCODE_POW, result_dst,
|
|
||||||
src_reg_for_float(M_E), op[0]);
|
|
||||||
break;
|
|
||||||
case ir_unop_exp2:
|
case ir_unop_exp2:
|
||||||
ir_to_mesa_emit_scalar_op1(ir, OPCODE_EX2, result_dst, op[0]);
|
ir_to_mesa_emit_scalar_op1(ir, OPCODE_EX2, result_dst, op[0]);
|
||||||
break;
|
break;
|
||||||
|
case ir_unop_exp:
|
||||||
case ir_unop_log:
|
case ir_unop_log:
|
||||||
ir_to_mesa_emit_scalar_op1(ir, OPCODE_LOG, result_dst, op[0]);
|
assert(!"not reached: should be handled by ir_explog_to_explog2");
|
||||||
break;
|
break;
|
||||||
case ir_unop_log2:
|
case ir_unop_log2:
|
||||||
ir_to_mesa_emit_scalar_op1(ir, OPCODE_LG2, result_dst, op[0]);
|
ir_to_mesa_emit_scalar_op1(ir, OPCODE_LG2, result_dst, op[0]);
|
||||||
|
Reference in New Issue
Block a user