Module: Mesa
Branch: main
Commit: a6ed406d9fd044dafcd87ae45b1906a04edb325e
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a6ed406d9fd044dafcd87ae45b1906a04edb325e

Author: Erik Faye-Lund <[email protected]>
Date:   Tue Aug 23 11:33:57 2022 +0200

util/format: implement rgtc -> r8 / r8g8 unpack

Reviewed-by: Alyssa Rosenzweig <[email protected]>
Acked-by: Eric Engestrom <[email protected]>
Tested-by: Eric Engestrom <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18248>

---

 src/util/format/u_format_rgtc.c | 102 ++++++++++++++++++++++++++++++++++++++++
 src/util/format/u_format_rgtc.h |  12 +++++
 2 files changed, 114 insertions(+)

diff --git a/src/util/format/u_format_rgtc.c b/src/util/format/u_format_rgtc.c
index 63cb9f05396..49c37b4fb96 100644
--- a/src/util/format/u_format_rgtc.c
+++ b/src/util/format/u_format_rgtc.c
@@ -37,6 +37,30 @@ util_format_rgtc1_unorm_fetch_rgba_8unorm(uint8_t *restrict 
dst, const uint8_t *
    dst[3] = 255;
 }
 
+void
+util_format_rgtc1_unorm_unpack_r_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height)
+{
+   const unsigned bw = 4, bh = 4, comps = 1;
+   unsigned x, y, i, j;
+   unsigned block_size = 8;
+
+   for(y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+      const unsigned h = MIN2(height - y, bh);
+      for(x = 0; x < width; x += bw) {
+         const unsigned w = MIN2(width - x, bw);
+         for(j = 0; j < h; ++j) {
+            for(i = 0; i < w; ++i) {
+               uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + 
(x + i)*comps;
+               util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);
+            }
+         }
+         src += block_size;
+      }
+      src_row += src_stride;
+   }
+}
+
 void
 util_format_rgtc1_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height)
 {
@@ -163,6 +187,32 @@ util_format_rgtc1_snorm_unpack_rgba_8unorm(UNUSED uint8_t 
*restrict dst_row, UNU
    fprintf(stderr,"%s\n", __func__);
 }
 
+void
+util_format_rgtc1_snorm_unpack_r_8snorm(int8_t *restrict dst_row, unsigned 
dst_stride,
+                                        const uint8_t *restrict src_row, 
unsigned src_stride,
+                                        unsigned width, unsigned height)
+{
+   const unsigned bw = 4, bh = 4, comps = 1;
+   unsigned x, y, i, j;
+   unsigned block_size = 8;
+
+   for(y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+      const unsigned h = MIN2(height - y, bh);
+      for(x = 0; x < width; x += bw) {
+         const unsigned w = MIN2(width - x, bw);
+         for(j = 0; j < h; ++j) {
+            for(i = 0; i < w; ++i) {
+               int8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + 
(x + i)*comps;
+               util_format_signed_fetch_texel_rgtc(0, (const int8_t *)src, i, 
j, dst, 1);
+            }
+         }
+         src += block_size;
+      }
+      src_row += src_stride;
+   }
+}
+
 void
 util_format_rgtc1_snorm_pack_rgba_8unorm(UNUSED uint8_t *restrict dst_row, 
UNUSED unsigned dst_stride,
                                          UNUSED const uint8_t *restrict 
src_row, UNUSED unsigned src_stride,
@@ -242,6 +292,31 @@ util_format_rgtc2_unorm_fetch_rgba_8unorm(uint8_t 
*restrict dst, const uint8_t *
    dst[3] = 255;
 }
 
+void
+util_format_rgtc2_unorm_unpack_rg_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height)
+{
+   const unsigned bw = 4, bh = 4, comps = 2;
+   unsigned x, y, i, j;
+   unsigned block_size = 16;
+
+   for(y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+      const unsigned h = MIN2(height - y, bh);
+      for(x = 0; x < width; x += bw) {
+         const unsigned w = MIN2(width - x, bw);
+         for(j = 0; j < h; ++j) {
+            for(i = 0; i < w; ++i) {
+               uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + 
(x + i)*comps;
+               util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);
+               util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 
1, 2);
+            }
+         }
+         src += block_size;
+      }
+      src_row += src_stride;
+   }
+}
+
 void
 util_format_rgtc2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height)
 {
@@ -382,6 +457,33 @@ util_format_rgtc2_snorm_unpack_rgba_8unorm(UNUSED uint8_t 
*restrict dst_row, UNU
    fprintf(stderr,"%s\n", __func__);
 }
 
+void
+util_format_rgtc2_snorm_unpack_rg_8snorm(int8_t *restrict dst_row, unsigned 
dst_stride,
+                                         const uint8_t *restrict src_row, 
unsigned src_stride,
+                                         unsigned width, unsigned height)
+{
+   const unsigned bw = 4, bh = 4, comps = 2;
+   unsigned x, y, i, j;
+   unsigned block_size = 16;
+
+   for(y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+      const unsigned h = MIN2(height - y, bh);
+      for(x = 0; x < width; x += bw) {
+         const unsigned w = MIN2(width - x, bw);
+         for(j = 0; j < h; ++j) {
+            for(i = 0; i < w; ++i) {
+               int8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + 
(x + i)*comps;
+               util_format_signed_fetch_texel_rgtc(0, (const int8_t *)src, i, 
j, (int8_t *)dst, 2);
+               util_format_signed_fetch_texel_rgtc(0, (const int8_t *)src + 8, 
i, j, (int8_t *)dst + 1, 2);
+            }
+         }
+         src += block_size;
+      }
+      src_row += src_stride;
+   }
+}
+
 void
 util_format_rgtc2_snorm_pack_rgba_8unorm(UNUSED uint8_t *restrict dst_row, 
UNUSED unsigned dst_stride,
                                          UNUSED const uint8_t *restrict 
src_row, UNUSED unsigned src_stride,
diff --git a/src/util/format/u_format_rgtc.h b/src/util/format/u_format_rgtc.h
index c79e0197bae..dfcdfa0d3e1 100644
--- a/src/util/format/u_format_rgtc.h
+++ b/src/util/format/u_format_rgtc.h
@@ -33,6 +33,9 @@
 void
 util_format_rgtc1_unorm_fetch_rgba_8unorm(uint8_t *restrict dst, const uint8_t 
*restrict src, unsigned i, unsigned j);
 
+void
+util_format_rgtc1_unorm_unpack_r_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
+
 void
 util_format_rgtc1_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
 
@@ -56,6 +59,9 @@ util_format_rgtc1_snorm_fetch_rgba_8unorm(uint8_t *restrict 
dst, const uint8_t *
 void
 util_format_rgtc1_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
 
+void
+util_format_rgtc1_snorm_unpack_r_8snorm(int8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
+
 void
 util_format_rgtc1_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
 
@@ -72,6 +78,9 @@ util_format_rgtc1_snorm_fetch_rgba(void *restrict dst, const 
uint8_t *restrict s
 void
 util_format_rgtc2_unorm_fetch_rgba_8unorm(uint8_t *restrict dst, const uint8_t 
*restrict src, unsigned i, unsigned j);
 
+void
+util_format_rgtc2_unorm_unpack_rg_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
+
 void
 util_format_rgtc2_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
 
@@ -97,6 +106,9 @@ util_format_rgtc2_snorm_fetch_rgba_8unorm(uint8_t *restrict 
dst, const uint8_t *
 void
 util_format_rgtc2_snorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
 
+void
+util_format_rgtc2_snorm_unpack_rg_8snorm(int8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
+
 void
 util_format_rgtc2_snorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned 
dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned 
width, unsigned height);
 

Reply via email to