Mesa (master): util: Give a reasonable answer when unpacking z32unorm from floats.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021
Module: Mesa
Branch: master
Commit: 322fa3d9dc478708a3795bff8df2bf652bf84e3a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=322fa3d9dc478708a3795bff8df2bf652bf84e3a
Author: Eric Anholt <eric at anholt.net>
Date: Thu Nov 7 13:51:15 2019 -0800
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 at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>
---
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;
}
More information about the mesa-commit
mailing list