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 4bf1731..7b59538 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 a146363..847c000 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 eec4de9..579d1cd 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 b6f1d5f..c28eff3 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 002c8b8..583c0bd 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 ad94c9f..5c8b9dd 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 b1858fb..ef48b94 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;