Mesa (master): mesa: Use a bunch of util functions for Z/S unpacking.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021


Module: Mesa
Branch: master
Commit: 85f237634c3a5bce2c58c525942353932051aee7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=85f237634c3a5bce2c58c525942353932051aee7

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Nov  7 13:22:21 2019 -0800

mesa: Use a bunch of util functions for Z/S unpacking.

Drops another 2k of text.

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/mesa/main/format_unpack.h  |  21 +++-
 src/mesa/main/format_unpack.py | 263 -----------------------------------------
 2 files changed, 15 insertions(+), 269 deletions(-)

diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h
index 8b2813fd675..06283c6bfa8 100644
--- a/src/mesa/main/format_unpack.h
+++ b/src/mesa/main/format_unpack.h
@@ -56,18 +56,27 @@ _mesa_unpack_rgba_block(mesa_format format,
                         float dst[][4], int32_t dstRowStride,
                         uint32_t x, uint32_t y, uint32_t width, uint32_t height);
 
-extern void
+static inline void
 _mesa_unpack_float_z_row(mesa_format format, uint32_t n,
-                         const void *src, float *dst);
+                         const void *src, float *dst)
+{
+   util_format_unpack_z_float((enum pipe_format)format, dst, src, n);
+}
 
 
-void
+static inline void
 _mesa_unpack_uint_z_row(mesa_format format, uint32_t n,
-                        const void *src, uint32_t *dst);
+                        const void *src, uint32_t *dst)
+{
+   util_format_unpack_z_32unorm((enum pipe_format)format, dst, src, n);
+}
 
-void
+static inline void
 _mesa_unpack_ubyte_stencil_row(mesa_format format, uint32_t n,
-                               const void *src, uint8_t *dst);
+                               const void *src, uint8_t *dst)
+{
+   util_format_unpack_s_8uint((enum pipe_format)format, dst, src, n);
+}
 
 void
 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, uint32_t n,
diff --git a/src/mesa/main/format_unpack.py b/src/mesa/main/format_unpack.py
index 2b3acf81819..878b81e152f 100644
--- a/src/mesa/main/format_unpack.py
+++ b/src/mesa/main/format_unpack.py
@@ -76,269 +76,6 @@ struct z32f_x24s8
    uint32_t x24s8;
 };
 
-typedef void (*unpack_float_z_func)(uint32_t n, const void *src, float *dst);
-
-static void
-unpack_float_z_X8_UINT_Z24_UNORM(uint32_t n, const void *src, float *dst)
-{
-   /* only return Z, not stencil data */
-   const uint32_t *s = ((const uint32_t *) src);
-   const double scale = 1.0 / (double) 0xffffff;
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = (float) ((s[i] >> 8) * scale);
-      assert(dst[i] >= 0.0F);
-      assert(dst[i] <= 1.0F);
-   }
-}
-
-static void
-unpack_float_z_Z24_UNORM_X8_UINT(uint32_t n, const void *src, float *dst)
-{
-   /* only return Z, not stencil data */
-   const uint32_t *s = ((const uint32_t *) src);
-   const double scale = 1.0 / (double) 0xffffff;
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = (float) ((s[i] & 0x00ffffff) * scale);
-      assert(dst[i] >= 0.0F);
-      assert(dst[i] <= 1.0F);
-   }
-}
-
-static void
-unpack_float_Z_UNORM16(uint32_t n, const void *src, float *dst)
-{
-   const uint16_t *s = ((const uint16_t *) src);
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = s[i] * (1.0F / 65535.0F);
-   }
-}
-
-static void
-unpack_float_Z_UNORM32(uint32_t n, const void *src, float *dst)
-{
-   const uint32_t *s = ((const uint32_t *) src);
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = s[i] * (1.0F / 0xffffffff);
-   }
-}
-
-static void
-unpack_float_Z_FLOAT32(uint32_t n, const void *src, float *dst)
-{
-   memcpy(dst, src, n * sizeof(float));
-}
-
-static void
-unpack_float_z_Z32X24S8(uint32_t n, const void *src, float *dst)
-{
-   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = s[i].z;
-   }
-}
-
-
-
-void
-_mesa_unpack_float_z_row(mesa_format format, uint32_t n,
-                         const void *src, float *dst)
-{
-   unpack_float_z_func unpack;
-
-   switch (format) {
-   case MESA_FORMAT_S8_UINT_Z24_UNORM:
-   case MESA_FORMAT_X8_UINT_Z24_UNORM:
-      unpack = unpack_float_z_X8_UINT_Z24_UNORM;
-      break;
-   case MESA_FORMAT_Z24_UNORM_S8_UINT:
-   case MESA_FORMAT_Z24_UNORM_X8_UINT:
-      unpack = unpack_float_z_Z24_UNORM_X8_UINT;
-      break;
-   case MESA_FORMAT_Z_UNORM16:
-      unpack = unpack_float_Z_UNORM16;
-      break;
-   case MESA_FORMAT_Z_UNORM32:
-      unpack = unpack_float_Z_UNORM32;
-      break;
-   case MESA_FORMAT_Z_FLOAT32:
-      unpack = unpack_float_Z_FLOAT32;
-      break;
-   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-      unpack = unpack_float_z_Z32X24S8;
-      break;
-   default:
-      unreachable("bad format in _mesa_unpack_float_z_row");
-   }
-
-   unpack(n, src, dst);
-}
-
-
-
-typedef void (*unpack_uint_z_func)(const void *src, uint32_t *dst, uint32_t n);
-
-static void
-unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, uint32_t *dst, uint32_t n)
-{
-   /* only return Z, not stencil data */
-   const uint32_t *s = ((const uint32_t *) src);
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
-   }
-}
-
-static void
-unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, uint32_t *dst, uint32_t n)
-{
-   /* only return Z, not stencil data */
-   const uint32_t *s = ((const uint32_t *) src);
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
-   }
-}
-
-static void
-unpack_uint_Z_UNORM16(const void *src, uint32_t *dst, uint32_t n)
-{
-   const uint16_t *s = ((const uint16_t *)src);
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = (s[i] << 16) | s[i];
-   }
-}
-
-static void
-unpack_uint_Z_UNORM32(const void *src, uint32_t *dst, uint32_t n)
-{
-   memcpy(dst, src, n * sizeof(uint32_t));
-}
-
-static void
-unpack_uint_Z_FLOAT32(const void *src, uint32_t *dst, uint32_t n)
-{
-   const float *s = (const float *)src;
-   uint32_t i;
-   for (i = 0; i < n; i++) {
-      dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
-   }
-}
-
-static void
-unpack_uint_Z_FLOAT32_X24S8(const void *src, uint32_t *dst, uint32_t n)
-{
-   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
-   uint32_t i;
-
-   for (i = 0; i < n; i++) {
-      dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
-   }
-}
-
-
-/**
- * Unpack Z values.
- * The returned values will always be in the range [0, 0xffffffff].
- */
-void
-_mesa_unpack_uint_z_row(mesa_format format, uint32_t n,
-                        const void *src, uint32_t *dst)
-{
-   unpack_uint_z_func unpack;
-   const uint8_t *srcPtr = (uint8_t *) src;
-
-   switch (format) {
-   case MESA_FORMAT_S8_UINT_Z24_UNORM:
-   case MESA_FORMAT_X8_UINT_Z24_UNORM:
-      unpack = unpack_uint_z_X8_UINT_Z24_UNORM;
-      break;
-   case MESA_FORMAT_Z24_UNORM_S8_UINT:
-   case MESA_FORMAT_Z24_UNORM_X8_UINT:
-      unpack = unpack_uint_z_Z24_UNORM_X8_UINT;
-      break;
-   case MESA_FORMAT_Z_UNORM16:
-      unpack = unpack_uint_Z_UNORM16;
-      break;
-   case MESA_FORMAT_Z_UNORM32:
-      unpack = unpack_uint_Z_UNORM32;
-      break;
-   case MESA_FORMAT_Z_FLOAT32:
-      unpack = unpack_uint_Z_FLOAT32;
-      break;
-   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-      unpack = unpack_uint_Z_FLOAT32_X24S8;
-      break;
-   default:
-      unreachable("bad format %s in _mesa_unpack_uint_z_row");
-   }
-
-   unpack(srcPtr, dst, n);
-}
-
-
-static void
-unpack_ubyte_s_S_UINT8(const void *src, uint8_t *dst, uint32_t n)
-{
-   memcpy(dst, src, n);
-}
-
-static void
-unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, uint8_t *dst, uint32_t n)
-{
-   uint32_t i;
-   const uint32_t *src32 = src;
-
-   for (i = 0; i < n; i++)
-      dst[i] = src32[i] & 0xff;
-}
-
-static void
-unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, uint8_t *dst, uint32_t n)
-{
-   uint32_t i;
-   const uint32_t *src32 = src;
-
-   for (i = 0; i < n; i++)
-      dst[i] = src32[i] >> 24;
-}
-
-static void
-unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, uint8_t *dst, uint32_t n)
-{
-   uint32_t i;
-   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
-
-   for (i = 0; i < n; i++)
-      dst[i] = s[i].x24s8 & 0xff;
-}
-
-void
-_mesa_unpack_ubyte_stencil_row(mesa_format format, uint32_t n,
-			       const void *src, uint8_t *dst)
-{
-   switch (format) {
-   case MESA_FORMAT_S_UINT8:
-      unpack_ubyte_s_S_UINT8(src, dst, n);
-      break;
-   case MESA_FORMAT_S8_UINT_Z24_UNORM:
-      unpack_ubyte_s_S8_UINT_Z24_UNORM(src, dst, n);
-      break;
-   case MESA_FORMAT_Z24_UNORM_S8_UINT:
-      unpack_ubyte_s_Z24_UNORM_S8_UINT(src, dst, n);
-      break;
-   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-      unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
-      break;
-   default:
-      unreachable("bad format %s in _mesa_unpack_ubyte_s_row");
-   }
-}
 
 static void
 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const uint32_t *src, uint32_t *dst, uint32_t n)



More information about the mesa-commit mailing list