Mesa (master): gallium: Add and use a helper for packing uc from a color_union.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Feb 4 19:24:28 UTC 2020
Module: Mesa
Branch: master
Commit: ab081970e07d97c4218a68341d8534693d27e474
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ab081970e07d97c4218a68341d8534693d27e474
Author: Eric Anholt <eric at anholt.net>
Date: Fri Nov 8 14:49:44 2019 -0800
gallium: Add and use a helper for packing uc from a color_union.
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 at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2744>
---
src/gallium/auxiliary/util/u_pack_color.h | 10 +++++++++-
src/gallium/auxiliary/util/u_surface.c | 16 +---------------
src/gallium/drivers/freedreno/a5xx/fd5_draw.c | 8 +-------
src/gallium/drivers/freedreno/a6xx/fd6_gmem.c | 8 +-------
src/gallium/drivers/llvmpipe/lp_setup.c | 18 +-----------------
src/gallium/drivers/r600/r600_texture.c | 6 +-----
src/gallium/drivers/radeonsi/si_clear.c | 8 +-------
7 files changed, 15 insertions(+), 59 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h
index 4bf1731da0b..7b59538461a 100644
--- a/src/gallium/auxiliary/util/u_pack_color.h
+++ b/src/gallium/auxiliary/util/u_pack_color.h
@@ -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.
*/
diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index a146363ef49..847c0008079 100644
--- a/src/gallium/auxiliary/util/u_surface.c
+++ b/src/gallium/auxiliary/util/u_surface.c
@@ -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,
diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_draw.c b/src/gallium/drivers/freedreno/a5xx/fd5_draw.c
index eec4de98d94..579d1cdaf88 100644
--- a/src/gallium/drivers/freedreno/a5xx/fd5_draw.c
+++ b/src/gallium/drivers/freedreno/a5xx/fd5_draw.c
@@ -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));
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c b/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
index b6f1d5f2281..c28eff3c082 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
@@ -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) |
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index 002c8b8a25b..583c0bdba21 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -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;
diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c
index ad94c9fb0f0..5c8b9dd4af9 100644
--- a/src/gallium/drivers/r600/r600_texture.c
+++ b/src/gallium/drivers/r600/r600_texture.c
@@ -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));
diff --git a/src/gallium/drivers/radeonsi/si_clear.c b/src/gallium/drivers/radeonsi/si_clear.c
index b1858fb42fe..ef48b94a46d 100644
--- a/src/gallium/drivers/radeonsi/si_clear.c
+++ b/src/gallium/drivers/radeonsi/si_clear.c
@@ -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;
More information about the mesa-commit
mailing list