From 322fa3d9dc478708a3795bff8df2bf652bf84e3a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 7 Nov 2019 13:51:15 -0800 Subject: [PATCH] util: Give a reasonable answer when unpacking z32unorm from floats. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We weren't clamping the float Z value, just multiplying it by a big float and casting that to int. This makes util/format's z unpacking match Mesa's. Reviewed-by: Marek Olšák Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/util/format/u_format_zs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/format/u_format_zs.c b/src/util/format/u_format_zs.c index 197e881dbc0..d941c37d22d 100644 --- a/src/util/format/u_format_zs.c +++ b/src/util/format/u_format_zs.c @@ -309,7 +309,8 @@ util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, uint32_t *dst = dst_row; const float *src = (const float *)src_row; for(x = 0; x < width; ++x) { - *dst++ = z32_float_to_z32_unorm(*src++); + float z = *src++; + *dst++ = z32_float_to_z32_unorm(CLAMP(z, 0.0f, 1.0f)); } src_row += src_stride/sizeof(*src_row); dst_row += dst_stride/sizeof(*dst_row); @@ -865,7 +866,7 @@ util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned ds uint32_t *dst = dst_row; const float *src = (const float *)src_row; for(x = 0; x < width; ++x) { - *dst = z32_float_to_z32_unorm(*src); + *dst = z32_float_to_z32_unorm(CLAMP(*src, 0.0f, 1.0f)); src += 2; dst += 1; }