glsl: Move ForceGLSLAbsSqrt handling to glsl-to-nir.
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>
This commit is contained in:
@@ -122,6 +122,8 @@ private:
|
||||
|
||||
void adjust_sparse_variable(nir_deref_instr *var_deref, const glsl_type *type,
|
||||
nir_ssa_def *dest);
|
||||
|
||||
const struct gl_constants *consts;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -283,6 +285,7 @@ glsl_to_nir(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;
|
||||
@@ -2034,8 +2037,19 @@ nir_visitor::visit(ir_expression *ir)
|
||||
: 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;
|
||||
|
@@ -61,7 +61,7 @@ bool lower_discard(exec_list *instructions);
|
||||
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,
|
||||
|
@@ -63,7 +63,6 @@
|
||||
#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;
|
||||
|
||||
@@ -95,7 +94,6 @@ private:
|
||||
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);
|
||||
|
||||
@@ -114,14 +112,12 @@ private:
|
||||
|
||||
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.
|
||||
@@ -1090,13 +1086,6 @@ lower_instructions_visitor::imul_high_to_mul(ir_expression *ir)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -1167,12 +1156,6 @@ 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;
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ do_optimization(struct exec_list *ir, const char *optimization,
|
||||
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);
|
||||
|
@@ -82,7 +82,6 @@ link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
|
||||
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);
|
||||
|
Reference in New Issue
Block a user