From 189755a9ac25b887765a920e6faeac4095254315 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 18 Jul 2022 11:30:31 +1000 Subject: [PATCH] util/pack_color: clamp depth values outside range for unorm formats. For unrestricted depth ranges, depth clear values for unorm buffers need to be explicitly clamped. However this has to happen in the driver when we know the depth buffer format, not at the API level. Just add clamps to the non-f32 cases and separate it out. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/util/u_pack_color.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h index a395fbc8054..8218e8a108c 100644 --- a/src/gallium/auxiliary/util/u_pack_color.h +++ b/src/gallium/auxiliary/util/u_pack_color.h @@ -529,30 +529,32 @@ util_pack_z(enum pipe_format format, double z) { union fi fui; - if (z == 0.0) + if (format == PIPE_FORMAT_Z32_FLOAT) { + fui.f = (float)z; + return fui.ui; + } + + if (z <= 0.0) return 0; switch (format) { case PIPE_FORMAT_Z16_UNORM: - if (z == 1.0) + if (z >= 1.0) return 0xffff; return (uint32_t) lrint(z * 0xffff); case PIPE_FORMAT_Z32_UNORM: /* special-case to avoid overflow */ - if (z == 1.0) + if (z >= 1.0) return 0xffffffff; return (uint32_t) llrint(z * 0xffffffff); - case PIPE_FORMAT_Z32_FLOAT: - fui.f = (float)z; - return fui.ui; case PIPE_FORMAT_Z24_UNORM_S8_UINT: case PIPE_FORMAT_Z24X8_UNORM: - if (z == 1.0) + if (z >= 1.0) return 0xffffff; return (uint32_t) lrint(z * 0xffffff); case PIPE_FORMAT_S8_UINT_Z24_UNORM: case PIPE_FORMAT_X8Z24_UNORM: - if (z == 1.0) + if (z >= 1.0) return 0xffffff00; return ((uint32_t) lrint(z * 0xffffff)) << 8; case PIPE_FORMAT_S8_UINT: