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:

committed by
Marge Bot

parent
bd872e2aaa
commit
5f8addfd99
@@ -210,6 +210,19 @@ uif(uint32_t ui)
|
|||||||
return as_float(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
|
static inline uint16_t
|
||||||
_mesa_float_to_half(float f)
|
_mesa_float_to_half(float f)
|
||||||
{
|
{
|
||||||
|
@@ -119,7 +119,6 @@ util_bitpack_float_nonzero(float v)
|
|||||||
return util_bitpack_float(v);
|
return util_bitpack_float(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __OPENCL_VERSION__
|
|
||||||
ALWAYS_INLINE static uint64_t
|
ALWAYS_INLINE static uint64_t
|
||||||
util_bitpack_sfixed(float v, uint32_t start, uint32_t end,
|
util_bitpack_sfixed(float v, uint32_t start, uint32_t end,
|
||||||
uint32_t fract_bits)
|
uint32_t fract_bits)
|
||||||
@@ -211,6 +210,5 @@ util_bitpack_ufixed_nonzero(float v, uint32_t start, uint32_t end,
|
|||||||
assert(v != 0.0f);
|
assert(v != 0.0f);
|
||||||
return util_bitpack_ufixed(v, start, end, fract_bits);
|
return util_bitpack_ufixed(v, start, end, fract_bits);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* UTIL_BITPACK_HELPERS_H */
|
#endif /* UTIL_BITPACK_HELPERS_H */
|
||||||
|
Reference in New Issue
Block a user