util/bitpack_helpers: Make fixed packs CL safe

We emulate roundf and llroundf for compatibility.

Signed-off-by: Mary Guillemard <mary.guillemard@collabora.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32939>
This commit is contained in:
Mary Guillemard
2024-12-19 12:09:16 +01:00
committed by Marge Bot
parent bd872e2aaa
commit 5f8addfd99
2 changed files with 13 additions and 2 deletions

View File

@@ -210,6 +210,19 @@ uif(uint32_t ui)
return as_float(ui);
}
#define CL_FLT_EPSILON 1.1920928955078125e-7f
/* OpenCL C lacks roundf and llroundf, we can emulate it */
static inline float roundf(float x)
{
return trunc(x + copysign(0.5f - 0.25f * CL_FLT_EPSILON, x));
}
static inline long long llroundf(float x)
{
return roundf(x);
}
static inline uint16_t
_mesa_float_to_half(float f)
{

View File

@@ -119,7 +119,6 @@ util_bitpack_float_nonzero(float v)
return util_bitpack_float(v);
}
#ifndef __OPENCL_VERSION__
ALWAYS_INLINE static uint64_t
util_bitpack_sfixed(float v, uint32_t start, uint32_t end,
uint32_t fract_bits)
@@ -211,6 +210,5 @@ util_bitpack_ufixed_nonzero(float v, uint32_t start, uint32_t end,
assert(v != 0.0f);
return util_bitpack_ufixed(v, start, end, fract_bits);
}
#endif
#endif /* UTIL_BITPACK_HELPERS_H */