util/pack_color: clamp depth values outside range for unorm formats.
authorDave Airlie <airlied@redhat.com>
Mon, 18 Jul 2022 01:30:31 +0000 (11:30 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 28 Jul 2022 00:35:04 +0000 (10:35 +1000)
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 <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17612>

src/gallium/auxiliary/util/u_pack_color.h

index a395fbc..8218e8a 100644 (file)
@@ -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: