mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-21 09:20:12 +01:00
compiler/nir: move build_log helper into builtin-builder
Reviewed-by: Karol Herbst <kherbst@redhat.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4318>
This commit is contained in:
parent
f59ae68838
commit
c98e745e78
2 changed files with 13 additions and 16 deletions
|
|
@ -94,6 +94,12 @@ nir_fexp(nir_builder *b, nir_ssa_def *x)
|
||||||
return nir_fexp2(b, nir_fmul_imm(b, x, M_LOG2E));
|
return nir_fexp2(b, nir_fmul_imm(b, x, M_LOG2E));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline nir_ssa_def *
|
||||||
|
nir_flog(nir_builder *b, nir_ssa_def *x)
|
||||||
|
{
|
||||||
|
return nir_fmul_imm(b, nir_flog2(b, x), 1.0 / M_LOG2E);
|
||||||
|
}
|
||||||
|
|
||||||
static inline nir_ssa_def *
|
static inline nir_ssa_def *
|
||||||
nir_umul24(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
|
nir_umul24(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -171,15 +171,6 @@ matrix_inverse(struct vtn_builder *b, struct vtn_ssa_value *src)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return ln(x) - the natural logarithm of x.
|
|
||||||
*/
|
|
||||||
static nir_ssa_def *
|
|
||||||
build_log(nir_builder *b, nir_ssa_def *x)
|
|
||||||
{
|
|
||||||
return nir_fmul_imm(b, nir_flog2(b, x), 1.0 / M_LOG2E);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Approximate asin(x) by the formula:
|
* Approximate asin(x) by the formula:
|
||||||
* asin~(x) = sign(x) * (pi/2 - sqrt(1 - |x|) * (pi/2 + |x|(pi/4 - 1 + |x|(p0 + |x|p1))))
|
* asin~(x) = sign(x) * (pi/2 - sqrt(1 - |x|) * (pi/2 + |x|(pi/4 - 1 + |x|(p0 + |x|p1))))
|
||||||
|
|
@ -359,7 +350,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case GLSLstd450Log:
|
case GLSLstd450Log:
|
||||||
val->ssa->def = build_log(nb, src[0]);
|
val->ssa->def = nir_flog(nb, src[0]);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case GLSLstd450FClamp:
|
case GLSLstd450FClamp:
|
||||||
|
|
@ -472,19 +463,19 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
|
||||||
|
|
||||||
case GLSLstd450Asinh:
|
case GLSLstd450Asinh:
|
||||||
val->ssa->def = nir_fmul(nb, nir_fsign(nb, src[0]),
|
val->ssa->def = nir_fmul(nb, nir_fsign(nb, src[0]),
|
||||||
build_log(nb, nir_fadd(nb, nir_fabs(nb, src[0]),
|
nir_flog(nb, nir_fadd(nb, nir_fabs(nb, src[0]),
|
||||||
nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
|
nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
|
||||||
1.0f)))));
|
1.0f)))));
|
||||||
return;
|
return;
|
||||||
case GLSLstd450Acosh:
|
case GLSLstd450Acosh:
|
||||||
val->ssa->def = build_log(nb, nir_fadd(nb, src[0],
|
val->ssa->def = nir_flog(nb, nir_fadd(nb, src[0],
|
||||||
nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
|
nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
|
||||||
-1.0f))));
|
-1.0f))));
|
||||||
return;
|
return;
|
||||||
case GLSLstd450Atanh: {
|
case GLSLstd450Atanh: {
|
||||||
nir_ssa_def *one = nir_imm_floatN_t(nb, 1.0, src[0]->bit_size);
|
nir_ssa_def *one = nir_imm_floatN_t(nb, 1.0, src[0]->bit_size);
|
||||||
val->ssa->def =
|
val->ssa->def =
|
||||||
nir_fmul_imm(nb, build_log(nb, nir_fdiv(nb, nir_fadd(nb, src[0], one),
|
nir_fmul_imm(nb, nir_flog(nb, nir_fdiv(nb, nir_fadd(nb, src[0], one),
|
||||||
nir_fsub(nb, one, src[0]))),
|
nir_fsub(nb, one, src[0]))),
|
||||||
0.5f);
|
0.5f);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue