Cutting more GLSL lowering pass in favor of nir builder.
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22083>
void adjust_sparse_variable(nir_deref_instr *var_deref, const glsl_type *type,
nir_ssa_def *dest);
+
+ const struct gl_constants *consts;
};
/*
nir_visitor::nir_visitor(const struct gl_constants *consts, nir_shader *shader)
{
+ this->consts = consts;
this->supports_std430 = consts->UseSTD430AsDefaultPacking;
this->shader = shader;
this->is_global = true;
: nir_isign(&b, srcs[0]);
break;
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_rsq:
+ if (consts->ForceGLSLAbsSqrt)
+ srcs[0] = nir_fabs(&b, srcs[0]);
+ result = nir_frsq(&b, srcs[0]);
+ break;
+
+ case ir_unop_sqrt:
+ if (consts->ForceGLSLAbsSqrt)
+ srcs[0] = nir_fabs(&b, srcs[0]);
+ result = nir_fsqrt(&b, srcs[0]);
+ break;
+
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;
void lower_discard_flow(exec_list *instructions);
bool lower_instructions(exec_list *instructions, bool have_ldexp,
bool have_dfrexp, bool have_dround,
- bool force_abs_sqrt, bool have_gpu_shader5);
+ bool have_gpu_shader5);
bool lower_clip_cull_distance(struct gl_shader_program *prog,
gl_linked_shader *shader);
bool lower_packing_builtins(exec_list *instructions,
#define FIND_LSB_TO_FLOAT_CAST 0x20000
#define FIND_MSB_TO_FLOAT_CAST 0x40000
#define IMUL_HIGH_TO_MUL 0x80000
-#define SQRT_TO_ABS_SQRT 0x200000
using namespace ir_builder;
void find_lsb_to_float_cast(ir_expression *ir);
void find_msb_to_float_cast(ir_expression *ir);
void imul_high_to_mul(ir_expression *ir);
- void sqrt_to_abs_sqrt(ir_expression *ir);
ir_expression *_carry(operand a, operand b);
bool
lower_instructions(exec_list *instructions, bool have_ldexp, bool have_dfrexp,
- bool have_dround, bool force_abs_sqrt,
- bool have_gpu_shader5)
+ bool have_dround, bool have_gpu_shader5)
{
unsigned what_to_lower =
(have_ldexp ? 0 : LDEXP_TO_ARITH) |
(have_dfrexp ? 0 : DFREXP_DLDEXP_TO_ARITH) |
(have_dround ? 0 : DOPS_TO_DFRAC) |
- (force_abs_sqrt ? SQRT_TO_ABS_SQRT : 0) |
/* Assume that if ARB_gpu_shader5 is not supported then all of the
* extended integer functions need lowering. It may be necessary to add
* some caps for individual instructions.
}
}
-void
-lower_instructions_visitor::sqrt_to_abs_sqrt(ir_expression *ir)
-{
- ir->operands[0] = new(ir) ir_expression(ir_unop_abs, ir->operands[0]);
- this->progress = true;
-}
-
ir_visitor_status
lower_instructions_visitor::visit_leave(ir_expression *ir)
{
imul_high_to_mul(ir);
break;
- case ir_unop_rsq:
- case ir_unop_sqrt:
- if (lowering(SQRT_TO_ABS_SQRT))
- sqrt_to_abs_sqrt(ir);
- break;
-
default:
return visit_continue;
}
return lower_discard(ir);
} else if (sscanf(optimization, "lower_instructions ( %d ) ",
&int_0) == 1) {
- return lower_instructions(ir, false, false, false, false, false);
+ return lower_instructions(ir, false, false, false, false);
} else {
printf("Unrecognized optimization %s\n", optimization);
exit(EXIT_FAILURE);
shader, ctx->Extensions.KHR_blend_equation_advanced_coherent);
lower_instructions(ir, have_ldexp, have_dfrexp, have_dround,
- ctx->Const.ForceGLSLAbsSqrt,
ctx->Extensions.ARB_gpu_shader5);
do_vec_index_to_cond_assign(ir);