gallium: Add and use a helper for packing uc from a color_union.
authorEric Anholt <eric@anholt.net>
Fri, 8 Nov 2019 22:49:44 +0000 (14:49 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 4 Feb 2020 19:02:59 +0000 (19:02 +0000)
The same pattern kept coming up, and we don't need to hit
util_format_write_4* to do it when we have util_format_pack_rgba().

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

src/gallium/auxiliary/util/u_pack_color.h
src/gallium/auxiliary/util/u_surface.c
src/gallium/drivers/freedreno/a5xx/fd5_draw.c
src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/r600/r600_texture.c
src/gallium/drivers/radeonsi/si_clear.c

index 4bf1731da0b2a7892b9fe06401ad04432d6dcc69..7b59538461a8db60b9e092954f953a71b1f2832d 100644 (file)
@@ -433,7 +433,15 @@ util_pack_color(const float rgba[4], enum pipe_format format, union util_color *
       util_format_write_4f(format, rgba, 0, uc, 0, 0, 0, 1, 1);
    }
 }
+
+static inline void
+util_pack_color_union(enum pipe_format format,
+                      union util_color *dst,
+                      const union pipe_color_union *src)
+{
+   util_format_pack_rgba(format, dst, &src->ui, 1);
+}
+
 /* Integer versions of util_pack_z and util_pack_z_stencil - useful for
  * constructing clear masks.
  */
index a146363ef49c7b57d91997f634a4d97925c0b737..847c00080798944757ae9f8c60e9d491087b4150 100644 (file)
@@ -338,21 +338,7 @@ util_clear_color_texture_helper(struct pipe_transfer *dst_trans,
 
    assert(dst_trans->stride > 0);
 
-   if (util_format_is_pure_integer(format)) {
-      /*
-       * We expect int/uint clear values here, though some APIs
-       * might disagree (but in any case util_pack_color()
-       * couldn't handle it)...
-       */
-      if (util_format_is_pure_sint(format)) {
-         util_format_write_4i(format, color->i, 0, &uc, 0, 0, 0, 1, 1);
-      } else {
-         assert(util_format_is_pure_uint(format));
-         util_format_write_4ui(format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
-      }
-   } else {
-      util_pack_color(color->f, format, &uc);
-   }
+   util_pack_color_union(format, &uc, color);
 
    util_fill_box(dst_map, format,
                  dst_trans->stride, dst_trans->layer_stride,
index eec4de98d943052ec044ec946c57bd26204894c5..579d1cdaf886798700310284a8459a7fb14199eb 100644 (file)
@@ -318,13 +318,7 @@ fd5_clear(struct fd_context *ctx, unsigned buffers,
                                break;
                        }
 
-                       if (util_format_is_pure_uint(pfmt)) {
-                               util_format_write_4ui(pfmt, swapped.ui, 0, &uc, 0, 0, 0, 1, 1);
-                       } else if (util_format_is_pure_sint(pfmt)) {
-                               util_format_write_4i(pfmt, swapped.i, 0, &uc, 0, 0, 0, 1, 1);
-                       } else {
-                               util_pack_color(swapped.f, pfmt, &uc);
-                       }
+                       util_pack_color_union(pfmt, &uc, &swapped);
 
                        OUT_PKT4(ring, REG_A5XX_RB_BLIT_CNTL, 1);
                        OUT_RING(ring, A5XX_RB_BLIT_CNTL_BUF(BLIT_MRT0 + i));
index b6f1d5f2281acff4b7aea1f12fb3ddb7abd0fff7..c28eff3c08223036dd2d7e2cb22214e8bd008856 100644 (file)
@@ -1052,13 +1052,7 @@ emit_clears(struct fd_batch *batch, struct fd_ringbuffer *ring)
                                break;
                        }
 
-                       if (util_format_is_pure_uint(pfmt)) {
-                               util_format_write_4ui(pfmt, swapped.ui, 0, &uc, 0, 0, 0, 1, 1);
-                       } else if (util_format_is_pure_sint(pfmt)) {
-                               util_format_write_4i(pfmt, swapped.i, 0, &uc, 0, 0, 0, 1, 1);
-                       } else {
-                               util_pack_color(swapped.f, pfmt, &uc);
-                       }
+                       util_pack_color_union(pfmt, &uc, &swapped);
 
                        OUT_PKT4(ring, REG_A6XX_RB_BLIT_DST_INFO, 1);
                        OUT_RING(ring, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR) |
index 002c8b8a25b6347ca02a004e302c33f2face2cb0..583c0bdba211cbab672e5c8b9a8ecaa0f09b8dba 100644 (file)
@@ -409,23 +409,7 @@ lp_setup_try_clear_color_buffer(struct lp_setup_context *setup,
 
    LP_DBG(DEBUG_SETUP, "%s state %d\n", __FUNCTION__, setup->state);
 
-   if (util_format_is_pure_integer(format)) {
-      /*
-       * We expect int/uint clear values here, though some APIs
-       * might disagree (but in any case util_pack_color()
-       * couldn't handle it)...
-       */
-      if (util_format_is_pure_sint(format)) {
-         util_format_write_4i(format, color->i, 0, &uc, 0, 0, 0, 1, 1);
-      }
-      else {
-         assert(util_format_is_pure_uint(format));
-         util_format_write_4ui(format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
-      }
-   }
-   else {
-      util_pack_color(color->f, format, &uc);
-   }
+   util_pack_color_union(format, &uc, color);
 
    if (setup->state == SETUP_ACTIVE) {
       struct lp_scene *scene = setup->scene;
index ad94c9fb0f04edda83eaf25270a5dbc28d681a15..5c8b9dd4af997a0b2d4b9d369f682decefc43a63 100644 (file)
@@ -1745,12 +1745,8 @@ static void evergreen_set_clear_color(struct r600_texture *rtex,
                       color->ui[0] == color->ui[2]);
                uc.ui[0] = color->ui[0];
                uc.ui[1] = color->ui[3];
-       } else if (util_format_is_pure_uint(surface_format)) {
-               util_format_write_4ui(surface_format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
-       } else if (util_format_is_pure_sint(surface_format)) {
-               util_format_write_4i(surface_format, color->i, 0, &uc, 0, 0, 0, 1, 1);
        } else {
-               util_pack_color(color->f, surface_format, &uc);
+               util_pack_color_union(surface_format, &uc, color);
        }
 
        memcpy(rtex->color_clear_value, &uc, 2 * sizeof(uint32_t));
index b1858fb42fe0777943cbc82579e52fa435c74d59..ef48b94a46dbc72246768ea00c13d54306e65ed5 100644 (file)
@@ -76,12 +76,8 @@ static bool si_set_clear_color(struct si_texture *tex,
                       color->ui[0] == color->ui[2]);
                uc.ui[0] = color->ui[0];
                uc.ui[1] = color->ui[3];
-       } else if (util_format_is_pure_uint(surface_format)) {
-               util_format_write_4ui(surface_format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
-       } else if (util_format_is_pure_sint(surface_format)) {
-               util_format_write_4i(surface_format, color->i, 0, &uc, 0, 0, 0, 1, 1);
        } else {
-               util_pack_color(color->f, surface_format, &uc);
+               util_pack_color_union(surface_format, &uc, color);
        }
 
        if (memcmp(tex->color_clear_value, &uc, 2 * sizeof(uint32_t)) == 0)
@@ -734,8 +730,6 @@ static void si_clear_texture(struct pipe_context *pipe,
        struct si_texture *stex = (struct si_texture*)tex;
        struct pipe_surface tmpl = {{0}};
        struct pipe_surface *sf;
-       const struct util_format_description *desc =
-               util_format_description(tex->format);
 
        tmpl.format = tex->format;
        tmpl.u.tex.first_layer = box->z;