util/format: add some ZS helpers for vallium
authorDave Airlie <airlied@redhat.com>
Fri, 19 Jun 2020 06:44:09 +0000 (16:44 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 17 Aug 2020 04:30:50 +0000 (14:30 +1000)
The vallium layer has a requirement to insert and extra the 24-bit
unorm value as a unorm value (not as a float etc). Add helpers
to facilitate that.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6082>

src/util/format/u_format_zs.c
src/util/format/u_format_zs.h

index bbd7e02e563273a8a03e86c844e5d952bf66715a..197e881dbc0a44d70c3c1cd38f9918042fc6f89a 100644 (file)
@@ -419,6 +419,46 @@ util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *dst_row, unsigned dst_stride
    }
 }
 
+
+void
+util_format_z24_unorm_s8_uint_unpack_z24(uint8_t *dst_row, unsigned dst_stride,
+                                         const uint8_t *src_row, unsigned src_stride,
+                                         unsigned width, unsigned height)
+{
+   unsigned x, y;
+   for(y = 0; y < height; ++y) {
+      uint32_t *dst = (uint32_t *)dst_row;
+      const uint32_t *src = (const uint32_t *)src_row;
+      for(x = 0; x < width; ++x) {
+         uint32_t value =  util_cpu_to_le32(*src++);
+         *dst++ = (value & 0xffffff);
+      }
+      src_row += src_stride/sizeof(*src_row);
+      dst_row += dst_stride/sizeof(*dst_row);
+   }
+}
+
+void
+util_format_z24_unorm_s8_uint_pack_z24(uint8_t *dst_row, unsigned dst_stride,
+                                       const uint8_t *src_row, unsigned src_stride,
+                                       unsigned width, unsigned height)
+{
+   unsigned x, y;
+   for(y = 0; y < height; ++y) {
+      const uint32_t *src = (const uint32_t *)src_row;
+      uint32_t *dst = (uint32_t *)dst_row;
+      for(x = 0; x < width; ++x) {
+         uint32_t value = util_le32_to_cpu(*dst);
+         value &= 0xff000000;
+         value |= *src & 0xffffff;
+         src++;
+         *dst++ = util_cpu_to_le32(value);
+      }
+      dst_row += dst_stride/sizeof(*dst_row);
+      src_row += src_stride/sizeof(*src_row);
+   }
+}
+
 void
 util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride,
                                                   const uint8_t *src_row, unsigned src_stride,
index 61fb960f9c1d444e8078b98e82e6e967263b931c..87df7a4ff587f00390616d64cd088fc612eccc69 100644 (file)
@@ -115,6 +115,12 @@ util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *dst_row, unsigned dst_stride
 void
 util_format_z24_unorm_s8_uint_pack_separate(uint8_t *dst_row, unsigned dst_stride, const uint32_t *z_src_row, unsigned z_src_stride, const uint8_t *s_src_row, unsigned s_src_stride, unsigned width, unsigned height);
 
+void
+util_format_z24_unorm_s8_uint_unpack_z24(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_z24_unorm_s8_uint_pack_z24(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
 void
 util_format_s8_uint_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);