v2: fix huge_val for 16-bit, it was mean't to be 2^14 not 10^14. --- src/compiler/spirv/vtn_glsl450.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c index 9cda80c5137..f05531dbad6 100644 --- a/src/compiler/spirv/vtn_glsl450.c +++ b/src/compiler/spirv/vtn_glsl450.c @@ -304,8 +304,11 @@ build_atan(nir_builder *b, nir_ssa_def *y_over_x) static nir_ssa_def * build_atan2(nir_builder *b, nir_ssa_def *y, nir_ssa_def *x) { - nir_ssa_def *zero = nir_imm_float(b, 0); - nir_ssa_def *one = nir_imm_float(b, 1); + assert(y->bit_size == x->bit_size); + const uint32_t bit_size = x->bit_size; + + nir_ssa_def *zero = nir_imm_floatN_t(b, 0, bit_size); + nir_ssa_def *one = nir_imm_floatN_t(b, 1, bit_size); /* If we're on the left half-plane rotate the coordinates π/2 clock-wise * for the y=0 discontinuity to end up aligned with the vertical @@ -335,9 +338,10 @@ build_atan2(nir_builder *b, nir_ssa_def *y, nir_ssa_def *x) * floating point representations with at least the dynamic range of ATI's * 24-bit representation. */ - nir_ssa_def *huge = nir_imm_float(b, 1e18f); + const double huge_val = bit_size >= 32 ? 1e18 : 16384; + nir_ssa_def *huge = nir_imm_floatN_t(b, huge_val, bit_size); nir_ssa_def *scale = nir_bcsel(b, nir_fge(b, nir_fabs(b, t), huge), - nir_imm_float(b, 0.25), one); + nir_imm_floatN_t(b, 0.25, bit_size), one); nir_ssa_def *rcp_scaled_t = nir_frcp(b, nir_fmul(b, t, scale)); nir_ssa_def *s_over_t = nir_fmul(b, nir_fmul(b, s, scale), rcp_scaled_t); @@ -364,9 +368,12 @@ build_atan2(nir_builder *b, nir_ssa_def *y, nir_ssa_def *x) /* Calculate the arctangent and fix up the result if we had flipped the * coordinate system. */ - nir_ssa_def *arc = nir_fadd(b, nir_fmul(b, nir_b2f(b, flip), - nir_imm_float(b, M_PI_2f)), - build_atan(b, tan)); + nir_ssa_def *b2f_flip = nir_b2f(b, flip); + b2f_flip->bit_size = bit_size; + nir_ssa_def *arc = + nir_fadd(b, nir_fmul(b, b2f_flip, + nir_imm_floatN_t(b, M_PI_2f, bit_size)), + build_atan(b, tan)); /* Rather convoluted calculation of the sign of the result. When x < 0 we * cannot use fsign because we need to be able to distinguish between -- 2.17.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev