glsl: Move exp/log-to-exp2/log2 lowering to glsl-to-NIR.

It's way more concise to write as nir_builder calls.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16823>
This commit is contained in:
Emma Anholt
2022-05-31 13:36:15 -07:00
committed by Marge Bot
parent d024eb6fab
commit 0fbd1b1f4c
4 changed files with 2 additions and 68 deletions

View File

@@ -1973,8 +1973,8 @@ nir_visitor::visit(ir_expression *ir)
case ir_unop_rcp: result = nir_frcp(&b, srcs[0]); break;
case ir_unop_rsq: result = nir_frsq(&b, srcs[0]); break;
case ir_unop_sqrt: result = nir_fsqrt(&b, srcs[0]); break;
case ir_unop_exp: unreachable("ir_unop_exp should have been lowered");
case ir_unop_log: unreachable("ir_unop_log should have been lowered");
case ir_unop_exp: result = nir_fexp2(&b, nir_fmul_imm(&b, srcs[0], M_LOG2E)); break;
case ir_unop_log: result = nir_fmul_imm(&b, nir_flog2(&b, srcs[0]), 1.0 / M_LOG2E); break;
case ir_unop_exp2: result = nir_fexp2(&b, srcs[0]); break;
case ir_unop_log2: result = nir_flog2(&b, srcs[0]); break;
case ir_unop_i2f:

View File

@@ -36,8 +36,6 @@ struct gl_shader_program;
/* Operations for lower_instructions() */
#define SUB_TO_ADD_NEG 0x01
#define FDIV_TO_MUL_RCP 0x02
#define EXP_TO_EXP2 0x04
#define LOG_TO_LOG2 0x10
#define INT_DIV_TO_MUL_RCP 0x40
#define LDEXP_TO_ARITH 0x80
#define CARRY_TO_ARITH 0x100

View File

@@ -33,8 +33,6 @@
* - SUB_TO_ADD_NEG
* - DIV_TO_MUL_RCP
* - INT_DIV_TO_MUL_RCP
* - EXP_TO_EXP2
* - LOG_TO_LOG2
* - LDEXP_TO_ARITH
* - CARRY_TO_ARITH
* - BORROW_TO_ARITH
@@ -66,12 +64,6 @@
* INT_DIV_TO_MUL_RCP handles the integer case, converting to and from floating
* point so that RCP is possible.
*
* EXP_TO_EXP2 and LOG_TO_LOG2:
* ----------------------------
* 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.
*
* LDEXP_TO_ARITH:
* -------------
* Converts ir_binop_ldexp to arithmetic and bit operations for float sources.
@@ -122,8 +114,6 @@ private:
void sub_to_add_neg(ir_expression *);
void div_to_mul_rcp(ir_expression *);
void int_div_to_mul_rcp(ir_expression *);
void exp_to_exp2(ir_expression *);
void log_to_log2(ir_expression *);
void ldexp_to_arith(ir_expression *);
void dldexp_to_arith(ir_expression *);
void dfrexp_sig_to_arith(ir_expression *);
@@ -250,29 +240,6 @@ lower_instructions_visitor::int_div_to_mul_rcp(ir_expression *ir)
this->progress = true;
}
void
lower_instructions_visitor::exp_to_exp2(ir_expression *ir)
{
ir_constant *log2_e = _imm_fp(ir, ir->type, M_LOG2E);
ir->operation = ir_unop_exp2;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type,
ir->operands[0], log2_e);
this->progress = true;
}
void
lower_instructions_visitor::log_to_log2(ir_expression *ir)
{
ir->operation = ir_binop_mul;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
ir->operands[0], NULL);
ir->operands[1] = _imm_fp(ir, ir->operands[0]->type, 1.0 / M_LOG2E);
this->progress = true;
}
void
lower_instructions_visitor::ldexp_to_arith(ir_expression *ir)
{
@@ -1411,25 +1378,6 @@ lower_instructions_visitor::_carry(operand a, operand b)
return carry(a, b);
}
ir_constant *
lower_instructions_visitor::_imm_fp(void *mem_ctx,
const glsl_type *type,
double f,
unsigned vector_elements)
{
switch (type->base_type) {
case GLSL_TYPE_FLOAT:
return new(mem_ctx) ir_constant((float) f, vector_elements);
case GLSL_TYPE_DOUBLE:
return new(mem_ctx) ir_constant((double) f, vector_elements);
case GLSL_TYPE_FLOAT16:
return new(mem_ctx) ir_constant(float16_t(f), vector_elements);
default:
assert(!"unknown float type for immediate");
return NULL;
}
}
void
lower_instructions_visitor::imul_high_to_mul(ir_expression *ir)
{
@@ -1607,16 +1555,6 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
div_to_mul_rcp(ir);
break;
case ir_unop_exp:
if (lowering(EXP_TO_EXP2))
exp_to_exp2(ir);
break;
case ir_unop_log:
if (lowering(LOG_TO_LOG2))
log_to_log2(ir);
break;
case ir_binop_ldexp:
if (lowering(LDEXP_TO_ARITH) && ir->type->is_float())
ldexp_to_arith(ir);

View File

@@ -104,8 +104,6 @@ link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
lower_instructions(ir,
FDIV_TO_MUL_RCP |
EXP_TO_EXP2 |
LOG_TO_LOG2 |
(have_ldexp ? 0 : LDEXP_TO_ARITH) |
(have_dfrexp ? 0 : DFREXP_DLDEXP_TO_ARITH) |
CARRY_TO_ARITH |