util: Merge util_format_read_4* functions.
authorEric Anholt <eric@anholt.net>
Wed, 1 Jul 2020 23:50:02 +0000 (16:50 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 7 Jul 2020 18:19:23 +0000 (18:19 +0000)
Everyone wants the same thing: unpack 4-bytes-per-channel data based on the
base type of the format.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5728>

src/gallium/auxiliary/util/u_tile.c
src/gallium/drivers/softpipe/sp_image.c
src/util/format/u_format.c
src/util/format/u_format.h
src/util/format/u_format_bptc.c

index 939943a1818375c1a3fae9d5c19c8f75705bdeb8..5677074903090175bf8f74d913a6dbcc236bd586 100644 (file)
@@ -436,22 +436,10 @@ pipe_get_tile_rgba(struct pipe_transfer *pt,
       x32_s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
       break;
    default:
-      if (util_format_is_pure_uint(format)) {
-         util_format_read_4ui(format,
-                              dst, dst_stride * sizeof(float),
-                              packed, util_format_get_stride(format, w),
-                              0, 0, w, h);
-      } else if (util_format_is_pure_sint(format)) {
-         util_format_read_4i(format,
-                             dst, dst_stride * sizeof(float),
-                             packed, util_format_get_stride(format, w),
-                             0, 0, w, h);
-      } else {
-            util_format_read_4f(format,
-                                dst, dst_stride * sizeof(float),
-                                packed, util_format_get_stride(format, w),
-                                0, 0, w, h);
-      }
+      util_format_read_4(format,
+                         dst, dst_stride * sizeof(float),
+                         packed, util_format_get_stride(format, w),
+                         0, 0, w, h);
    }
 
    FREE(packed);
index 9d244235fa4f9c231378c0e4c7d6a0cf462fbe48..b0240c952652c9142c36b68200ea3713a98c1da6 100644 (file)
@@ -262,32 +262,13 @@ sp_tgsi_load(const struct tgsi_image *image,
       offset = get_image_offset(spr, iview, params->format, r_coord);
       data_ptr = (char *)spr->data + offset;
 
-      if (util_format_is_pure_sint(params->format)) {
-         int32_t sdata[4];
-
-         util_format_read_4i(params->format,
-                             sdata, 0,
-                             data_ptr, stride,
-                             s_coord, t_coord, 1, 1);
-         for (c = 0; c < 4; c++)
-            ((int32_t *)rgba[c])[j] = sdata[c];
-      } else if (util_format_is_pure_uint(params->format)) {
-         uint32_t sdata[4];
-         util_format_read_4ui(params->format,
-                             sdata, 0,
-                             data_ptr, stride,
-                             s_coord, t_coord, 1, 1);
-         for (c = 0; c < 4; c++)
-            ((uint32_t *)rgba[c])[j] = sdata[c];
-      } else {
-         float sdata[4];
-         util_format_read_4f(params->format,
-                             sdata, 0,
-                             data_ptr, stride,
-                             s_coord, t_coord, 1, 1);
-         for (c = 0; c < 4; c++)
-            rgba[c][j] = sdata[c];
-      }
+      uint32_t sdata[4];
+      util_format_read_4(params->format,
+                         sdata, 0,
+                         data_ptr, stride,
+                         s_coord, t_coord, 1, 1);
+      for (c = 0; c < 4; c++)
+         ((uint32_t *)rgba[c])[j] = sdata[c];
    }
    return;
 fail_write_all_zero:
@@ -380,10 +361,10 @@ handle_op_uint(const struct pipe_image_view *iview,
    int nc = util_format_get_nr_components(params->format);
    unsigned sdata[4];
 
-   util_format_read_4ui(params->format,
-                        sdata, 0,
-                        data_ptr, stride,
-                        s, t, 1, 1);
+   util_format_read_4(params->format,
+                      sdata, 0,
+                      data_ptr, stride,
+                      s, t, 1, 1);
 
    if (just_read) {
       for (c = 0; c < nc; c++) {
@@ -496,10 +477,10 @@ handle_op_int(const struct pipe_image_view *iview,
    uint c;
    int nc = util_format_get_nr_components(params->format);
    int sdata[4];
-   util_format_read_4i(params->format,
-                       sdata, 0,
-                       data_ptr, stride,
-                       s, t, 1, 1);
+   util_format_read_4(params->format,
+                      sdata, 0,
+                      data_ptr, stride,
+                      s, t, 1, 1);
 
    if (just_read) {
       for (c = 0; c < nc; c++) {
@@ -609,10 +590,10 @@ handle_op_r32f_xchg(const struct pipe_image_view *iview,
    float sdata[4];
    uint c;
    int nc = 1;
-   util_format_read_4f(params->format,
-                       sdata, 0,
-                       data_ptr, stride,
-                       s, t, 1, 1);
+   util_format_read_4(params->format,
+                      sdata, 0,
+                      data_ptr, stride,
+                      s, t, 1, 1);
    if (just_read) {
       for (c = 0; c < nc; c++) {
          ((int32_t *)rgba[c])[qi] = sdata[c];
index 12af0ed65625c8460d2adb36288135bed957bdaa..5bb4b0fdb00618593f741b416d448e81f0e1bc10 100644 (file)
@@ -326,14 +326,13 @@ util_get_depth_format_mrd(const struct util_format_description *desc)
 
 
 void
-util_format_read_4f(enum pipe_format format,
-                    float *dst, unsigned dst_stride,
-                    const void *src, unsigned src_stride,
-                    unsigned x, unsigned y, unsigned w, unsigned h)
+util_format_read_4(enum pipe_format format,
+                   void *dst, unsigned dst_stride,
+                   const void *src, unsigned src_stride,
+                   unsigned x, unsigned y, unsigned w, unsigned h)
 {
    const struct util_format_description *format_desc;
    const uint8_t *src_row;
-   float *dst_row;
 
    format_desc = util_format_description(format);
 
@@ -341,9 +340,13 @@ util_format_read_4f(enum pipe_format format,
    assert(y % format_desc->block.height == 0);
 
    src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
-   dst_row = dst;
 
-   format_desc->unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h);
+   if (util_format_is_pure_uint(format))
+      format_desc->unpack_rgba_sint(dst, dst_stride, src_row, src_stride, w, h);
+   else if (util_format_is_pure_uint(format))
+      format_desc->unpack_rgba_uint(dst, dst_stride, src_row, src_stride, w, h);
+   else
+      format_desc->unpack_rgba_float(dst, dst_stride, src_row, src_stride, w, h);
 }
 
 
@@ -409,48 +412,6 @@ util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_
    format_desc->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
 }
 
-void
-util_format_read_4ui(enum pipe_format format,
-                     unsigned *dst, unsigned dst_stride,
-                     const void *src, unsigned src_stride,
-                     unsigned x, unsigned y, unsigned w, unsigned h)
-{
-   const struct util_format_description *format_desc;
-   const uint8_t *src_row;
-   uint32_t *dst_row;
-
-   format_desc = util_format_description(format);
-
-   assert(x % format_desc->block.width == 0);
-   assert(y % format_desc->block.height == 0);
-
-   src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
-   dst_row = dst;
-
-   format_desc->unpack_rgba_uint(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
-void
-util_format_read_4i(enum pipe_format format,
-                    int *dst, unsigned dst_stride,
-                    const void *src, unsigned src_stride,
-                    unsigned x, unsigned y, unsigned w, unsigned h)
-{
-   const struct util_format_description *format_desc;
-   const uint8_t *src_row;
-   int32_t *dst_row;
-
-   format_desc = util_format_description(format);
-
-   assert(x % format_desc->block.width == 0);
-   assert(y % format_desc->block.height == 0);
-
-   src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
-   dst_row = dst;
-
-   format_desc->unpack_rgba_sint(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
 /**
  * Check if we can safely memcopy from the source format to the dest format.
  * This basically covers the cases of a "used" channel copied to a typeless
index 961b0ac72b7aff1cc53d7ed70de54f77a1a6133f..4ce3b58bde22a262179b499e04b586a88adfd92e 100644 (file)
@@ -1551,10 +1551,10 @@ util_format_pack_rgba(enum pipe_format format, void *dst,
  */
 
 void
-util_format_read_4f(enum pipe_format format,
-                    float *dst, unsigned dst_stride, 
-                    const void *src, unsigned src_stride, 
-                    unsigned x, unsigned y, unsigned w, unsigned h);
+util_format_read_4(enum pipe_format format,
+                   void *dst, unsigned dst_stride,
+                   const void *src, unsigned src_stride,
+                   unsigned x, unsigned y, unsigned w, unsigned h);
 
 void
 util_format_write_4(enum pipe_format format,
@@ -1574,18 +1574,6 @@ util_format_write_4ub(enum pipe_format format,
                       void *dst, unsigned dst_stride, 
                       unsigned x, unsigned y, unsigned w, unsigned h);
 
-void
-util_format_read_4ui(enum pipe_format format,
-                     unsigned *dst, unsigned dst_stride,
-                     const void *src, unsigned src_stride,
-                     unsigned x, unsigned y, unsigned w, unsigned h);
-
-void
-util_format_read_4i(enum pipe_format format,
-                    int *dst, unsigned dst_stride,
-                    const void *src, unsigned src_stride,
-                    unsigned x, unsigned y, unsigned w, unsigned h);
-
 /*
  * Generic format conversion;
  */
index 2d02e11f48b0ce10d15895657c52ac3a4f461d03..60f789ce0e00203a34de947f734fa18869024d47 100644 (file)
@@ -61,10 +61,10 @@ util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_strid
    decompress_rgba_unorm(width, height,
                          src_row, src_stride,
                          temp_block, width * 4 * sizeof(uint8_t));
-   util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM,
-                       dst_row, dst_stride,
-                       temp_block, width * 4 * sizeof(uint8_t),
-                       0, 0, width, height);
+   util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM,
+                      dst_row, dst_stride,
+                      temp_block, width * 4 * sizeof(uint8_t),
+                      0, 0, width, height);
    free((void *) temp_block);
 }
 
@@ -94,10 +94,10 @@ util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
    fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16,
                                temp_block, (width % 4) + (height % 4) * 4);
 
-   util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM,
-                       dst, 4 * sizeof(float),
-                       temp_block, 4 * sizeof(uint8_t),
-                       0, 0, 1, 1);
+   util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM,
+                      dst, 4 * sizeof(float),
+                      temp_block, 4 * sizeof(uint8_t),
+                      0, 0, 1, 1);
 }
 
 void
@@ -130,10 +130,10 @@ util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride,
    decompress_rgba_unorm(width, height,
                          src_row, src_stride,
                          temp_block, width * 4 * sizeof(uint8_t));
-   util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB,
-                       dst_row, dst_stride,
-                       temp_block, width * 4 * sizeof(uint8_t),
-                       0, 0, width, height);
+   util_format_read_4(PIPE_FORMAT_R8G8B8A8_SRGB,
+                      dst_row, dst_stride,
+                      temp_block, width * 4 * sizeof(uint8_t),
+                      0, 0, width, height);
    free((void *) temp_block);
 }
 
@@ -156,10 +156,10 @@ util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src,
 
    fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16,
                                temp_block, (width % 4) + (height % 4) * 4);
-   util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB,
-                       dst, 4 * sizeof(float),
-                       temp_block, width * 4 * sizeof(uint8_t),
-                       0, 0, 1, 1);
+   util_format_read_4(PIPE_FORMAT_R8G8B8A8_SRGB,
+                      dst, 4 * sizeof(float),
+                      temp_block, width * 4 * sizeof(uint8_t),
+                      0, 0, 1, 1);
 }
 
 void