util: Give a reasonable answer when unpacking z32unorm from floats.

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 <marek.olsak@amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>
This commit is contained in:
Eric Anholt 2019-11-07 13:51:15 -08:00 committed by Marge Bot
parent 6e6228f7f0
commit 322fa3d9dc

View file

@ -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;
}